0
0

this is some code from a old post. I was wandering how to stop the partial play back. the record part works but when I feed the stream it still only plays the beginning part of the recorded voice.

FSOUND_SAMPLE * Voice;

signed char F_CALLBACKAPI streamcallback(FSOUND_STREAM stream, void *buff, int len, void *param)
{
unsigned int count = len / sizeof(signed short);
signed short
soundBuffer = (signed short*) buff;
queue<signed short> * pQueue = (queue<signed short> *) param;

// JUST SILENCE IF NO DATA IS PRESENT
if(pQueue &amp;&amp; pQueue-&gt;empty())
{
    memset(soundBuffer, 0, len);
    return true;
}

for(; count &gt; 0 &amp;&amp; !pQueue-&gt;empty(); count--)
{
    *soundBuffer++ = pQueue-&gt;front();
    pQueue-&gt;pop();
}
return true;

}

void main()
{
// Initilize
FSOUND_SetMinHardwareChannels(96);
if( FSOUND_Init(44100,96,0) == FALSE )
{
cout << "FSOUND_Init failed\n";
return;
}
char t = FSOUND_Record_SetDriver(0);

// allocate samples
Voice = FSOUND_Sample_Alloc(FSOUND_UNMANAGED, RECORDLENGTH, FSOUND_NORMAL | FSOUND_STEREO | FSOUND_16BITS | FSOUND_LOOP_NORMAL, 44100, 250, 127, 1);

queue&lt;signed short&gt; soundQueue;
// record
cout &lt;&lt; &quot;Recording\n&quot;;
cout &lt;&lt; FSOUND_Record_GetPosition() &lt;&lt; '\n';
char z = FSOUND_Record_StartSample(Voice,true);
do
{
    int recordpos, diff;
    static int oldrecordpos = 0;
    recordpos = FSOUND_Record_GetPosition();
    diff = recordpos - oldrecordpos; 

    if(recordpos != oldrecordpos)
    { 
        void* pRaw1 = NULL;
        void* pRaw2 = NULL;
        unsigned int iLen1, iLen2;

        // FETCH RAW SOUND DATA
        FSOUND_Sample_Lock(Voice, oldrecordpos * sizeof(signed short), diff * sizeof(signed short), &amp;pRaw1, &amp;pRaw2, &amp;iLen1, &amp;iLen2); 

        if(pRaw1 &amp;&amp; iLen1)
        {
            signed short* pData = (signed short*) pRaw1;
            unsigned int iChunkSize = iLen1 / sizeof(signed short);

            // PUSH CHUNKS OF SOUND DATA INTO A QUEUE
            for(int i = iChunkSize; i &gt; 0; i--)
                soundQueue.push(*pData++);
        }

        if(pRaw2 &amp;&amp; iLen2)
        {
            signed short* pData = (signed short*) pRaw2;
            unsigned int iChunkSize = iLen2 / sizeof(signed short);      

            // PUSH CHUNKS OF SOUND DATA INTO A QUEUE
            for(int i = iChunkSize; i &gt; 0; i--)
                soundQueue.push(*pData++);
        }
        FSOUND_Sample_Unlock(Voice, pRaw1, pRaw2, iLen1, iLen2);
    }

    oldrecordpos = recordpos;
    Sleep(10); 
}while(!kbhit());
FSOUND_Record_Stop();


FSOUND_STREAM *stream;
    stream = FSOUND_Stream_Create(streamcallback, 44100, FSOUND_LOOP_NORMAL | FSOUND_NORMAL | FSOUND_16BITS | FSOUND_STEREO, 44100, (void *) &amp;soundQueue); 
FSOUND_Stream_Play(0, stream);

Any help would be very much appreciated. thanks for your time. 😀

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.