I want to make a game which lets the user record little snippets of audio which will then be used as sound effects. For example, there’ll be a simple tanks minigame but your gunshot sound will be you making a pew noise, and if your pew noise was loud and deep it will be a slow and powerful shot whereas if your pew noise was fast and high pitched it will be a fast but less powerful shot.
I’ve got a hello world project set up using CPAL to record audio samples in f32 format into a vector, analyse the pitch, volume and length of the recording, and then play the recording back. Now I’m looking to see how I could turn the vector of samples into an audio source.
I’ve checked the Amethyst documentation for an Audio Source, and it says that the data is stored as a vector of bytes (unsigned 8bit int). This doesn’t tell me what format the data itself is supposed to be in, do I convert the floating point numbers into bytes or do I need to convert the samples into u16 or i16 format first? Is there a set channel number and sample rate and if so what is it?
I assume that once I have the answers to these questions and I have converted the data into the correct format I can use loader.load_from_data(). Is this correct?
Hey guys, I’m still looking for help with this.
I dug into the Amethyst Audio code and found that we’re using the Rodio library, which I thought was a good thing because I could create a Rodio source quite easily. However, in the sink.rs file I saw that we don’t actually use Rodio sources we use the Rodio decoder to try and ascertain that stuff automatically, which is frustrating.
I decided to push on, hoping that the raw bytes would be similar enough to a WAV file format that Rodio would be able to work with it, so I set about turning the Vector of samples into a Vector of bytes. I started by making a ‘Source’ with these bytes inside, but I don’t think I can just create a Source and get a Handle to it without using the asset loader. I tried using the asset loader by using the load_from_data function but that requires that I pass in an AudioData struct, and I can’t create an AudioData struct because amethyst::audio::formats is private.
So as far as I can tell this is impossible in the current version of Amethyst. Am I correct? I’d really like some input on this.
I may take a look at this, but can’t give any promises! It would be nice for amethyst to have this either for game replays or speaking in multiplayer games (and taking screenshots as well ).
As far as I could see rodio doesn’t directly supply anything input realted, but something could get done via the cpal crate, which is rodio built upon.