Author: derek Date: Thu Nov 9 23:17:11 2006 New Revision: 169 Modified: sofaswitch/trunk/sound/audio.cxx sofaswitch/trunk/sound/audio.h Log: Adjust so that if the queue does not supply the requried number of bytes, we make it up prior to writing to the speaker. Modified: sofaswitch/trunk/sound/audio.cxx ============================================================================== --- sofaswitch/trunk/sound/audio.cxx (original) +++ sofaswitch/trunk/sound/audio.cxx Thu Nov 9 23:17:11 2006 @@ -133,17 +133,31 @@ void TestAudioWrite::QueueToSpeakerMain(PThread &, INT) { - char silenceBuffer[480]; - char audioBuffer[480]; - memset(silenceBuffer, 0, 480); +#define BUFFER_SIZE 1000 + silenceData.SetSize(480); + memset(silenceData.GetPointer(), 0, 480); + incomingData.SetSize(BUFFER_SIZE); + memset(incomingData.GetPointer(), 0, BUFFER_SIZE); + + PINDEX storedCount = 0; while(keepGoing) { - if (audioQueue->Read(audioBuffer, 480)) { + if (audioQueue->Read(incomingData.GetPointer() + storedCount, 240)) { PINDEX count = audioQueue->GetLastReadCount(); - sound.Write(audioBuffer, count); + PTRACE(6, "Read " << count << "bytes from PQueueChannel. to have a total of " << (storedCount + count)); + if ((storedCount + count) > 480) { + sound.Write(incomingData.GetPointer(), 480); + PTRACE(6, "Play 480 bytes to the speaker "); + memcpy(incomingData.GetPointer(), incomingData.GetPointer() + 480, (storedCount + count) - 480); + storedCount = (storedCount + count) - 480; + } else + storedCount += count; + PTRACE(6, "Have " << storedCount << " byte waiting to be played"); } else { - sound.Write(silenceBuffer, 480); + sound.Write(silenceData.GetPointer(), 480); } } + + PTRACE(4, "End of queue to speaker main thread "); } Modified: sofaswitch/trunk/sound/audio.h ============================================================================== --- sofaswitch/trunk/sound/audio.h (original) +++ sofaswitch/trunk/sound/audio.h Thu Nov 9 23:17:11 2006 @@ -120,6 +120,12 @@ in blocks of 160, 240, 320, 480, or other bytes) and glues them together to give one nice stream of 480 byte blocks. */ PQueueChannel *audioQueue; + + /**The buffer of data we use to collect incoming data into */ + PBYTEArray incomingData; + + /**The data we send to the speaker when it is silence time */ + PBYTEArray silenceData; };
participants (1)
-
SofaSWITCH SVN