0
0

hello,
i’m trying to program a key sound generator ( actually i’d like to make an organ ) with FMOD but after have relying on the "usercreatedsound" example, and changing the code so i can modify the frequency, i have a lag time between when i press the touch and when the note change, i also have trouble with silence, when i send 0 to the buffer the note don’t stop. here is my code for the callback ( if you need more just ask) :
[b:qw3ne2yn]
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)
{

if(*pfmyNote != 0.00f) { // if there's a note
    unsigned int  uicount;
    static float  sft1 = 0;        // time

    signed short *stereo16bitbuffer = (signed short *)data;

    for (uicount=0; uicount<datalen>>2; uicount++)        // >>2 = 16bit stereo (4 bytes per sample)
    {
        //sound generation with fourier series
        *stereo16bitbuffer++ = (signed short)( sin(sft1 / 2.00f) * 800 + sin(sft1) * 6000.0f + sin(sft1 * 2.00f) * 3500 + sin(sft1 * 4.00f) * 2500 + sin(sft1 * 8.00f) * 1000 + sin(sft1 * 12.00f) * 600);    // left channel
        *stereo16bitbuffer++ = (signed short)( sin(sft1 / 2.00f) * 800 + sin(sft1) * 6000.0f + sin(sft1 * 2.00f) * 3500 + sin(sft1 * 4.00f) * 2500 + sin(sft1 * 8.00f) * 1000 + sin(sft1 * 12.00f) * 600);// right channel

        //temporalisation
            sft1 += 1.00f / *pfmyNote;

    }

}
else {      //else, send 0 to the sound buffer
    unsigned int  uicount;
    static float  sft1 = 0;        // time

    signed short *stereo16bitbuffer = (signed short *)data;

    for (uicount=0; uicount<datalen>>2; uicount++)        // >>2 = 16bit stereo (4 bytes per sample)
    {
        //sending 0
            *stereo16bitbuffer++ = *stereo16bitbuffer++ = 0.00f;

        //temporalisation
            sft1 += 1.00f / *pfmyNote;

    }
}


return FMOD_OK;

}[/b:qw3ne2yn]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.