0
0

I guess this is a two part question:

I need to write all the audio data that users create using multiple Sound instances to a file that I can convert to .wav. If I’m not mistaken this means that I need to create a DSP that receives every buffer and store it, then write it out later. Is this the best way to save a mix of sounds?

In the event that it is, I’ve done that and have noticed a few things that I’m confused by. The length returned is always 512, but the buffer itself is 1024 (b/c of 2 channels I’m guessing) but when I write the song out it’s the right pitch but exactly 1/2 the length of the sound the user creates. Here’s my DSP to create and write out FMOD_SOUND_FORMAT_PCM16:

[code:2nbw47ja]
FMOD_RESULT F_CALLBACK dspCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels) {
short *tmp = new short[1024];

if(isPlaying) {

    int a;
    for (a=0;a<length*2;a++) 
    {
        int v=(int)(inbuffer[a]*32768);
        if (v>32767) v=32767;
        else if (v<-32768) v=-32768;
        tmp[a]=(short) v;
    }
    wavData.push(tmp);
}
unsigned int count;
int count2;
for (count = 0; count < length; count++)
{
    outbuffer[(count * outchannels)] = inbuffer[(count * inchannels)];
    outbuffer[(count * outchannels)+1] = inbuffer[(count * inchannels)+1];
}
return FMOD_OK;

}[/code:2nbw47ja]

How am I missing 1/2 my samples? I’ve tried using this with floats and the wav header as FMOD_SOUND_FORMAT_PCMFLOAT and haven’t had any luck. Not knowing a ton about DSP and audio I’m guessing I’m doing something rudimentary wrong. Any advice is greatly appreciated, thanks!

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.