0
0

Hi, I am writing the code for playing streaming incoming audio data.
I use pcmreadcallback to consume the data in the buffer, which is named sp2_sound_buffer_bank.

before the data is go into the pcmreadcallback, I do a check

[code:16himp18]
if( isPreload == true && isBuffering == false && isPlaying == false && write_count – read_count >= 0 )
{
FMOD_CREATESOUNDEXINFO exinfo;
memset( &exinfo, 0, sizeof( FMOD_CREATESOUNDEXINFO ) );
exinfo.cbsize = sizeof( FMOD_CREATESOUNDEXINFO );

    exinfo.length           =  sp2_sound_buffer_length; //cksize;
    exinfo.pcmreadcallback   = pcmreadcallback; // datalen = exinfo.decodebuffersize * 2;     
    exinfo.format           = FMOD_SOUND_FORMAT_PCM16; 
    exinfo.decodebuffersize  = decode_buffer_size;  
    exinfo.defaultfrequency = 16000;
    exinfo.numchannels      = 1;

    FMOD_MODE mode = FMOD_3D | FMOD_OPENUSER | FMOD_SOFTWARE | FMOD_OPENMEMORY | FMOD_CREATESTREAM;
    result = system->createSound( 0, mode , &exinfo, &sound );

    result = system->playSound( FMOD_CHANNEL_FREE, sound, false, &mChannel );        
    ERRCHECK( result );
}

[/code:16himp18]

the following is my callback function.
[code:16himp18]
const int memcpy_length = 6400;

static FMOD_RESULT F_CALLBACK pcmreadcallback( FMOD_SOUND *sound, void *data, unsigned int datalen )
{
if( write_count – read_count <= 0 )
{
char * wa = (char *)data;
memcpy( wa, (char *)&sp2_sound_buffer_blank[0], memcpy_length );
return FMOD_OK;
}

char * wa = (char *)data;
if( isBuffering == true )
{
    memcpy( wa, (char *)&amp;sp2_sound_buffer_blank[0], memcpy_length );
}
else
{
    memcpy( wa, (char *)&amp;sp2_sound_buffer_bank[rfp], memcpy_length );
}

read_count += 20; 
rfp += memcpy_length;
if( rfp &gt;= sp2_sound_buffer_length )
{
    rfp = 0;
    rfp_round++;
}

return FMOD_OK;

}
[/code:16himp18]

if I don’t check isPlaying == false, the pcmreadcallback will not cause any delay but you can merely hear anything; but if I do the check, the pcmreadcallback will cause add 20 unit data length delay per buffer cycle. Could anyone help me to solve this delay problem if I have to check isPlaying == false ?

I also found a weird thing, memcpy_length is a global const integer, datalen is the passed value by pcmreadcallback function.
If i replace all the memcpy_length to datalen in the pcmreadcallback function, there will be no delay even if I don’t check isPlaying == false before the program runs to pcmreadcallback.

  • You must to post comments
0
0

[quote:2v5kvfy1]If i replace all the memcpy_length to datalen in the pcmreadcallback function, there will be no delay even if I don’t check isPlaying == false before the program runs to pcmreadcallback.[/quote:2v5kvfy1]
I’m not sure why you’re using the "memcpy_length" in your callback. The ‘datalen’ parameter is the size of the data, you must write that many samples to the data array otherwise there will be gaps.

-Pete

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.