Author: derek
Date: Tue Jan 2 22:35:49 2007
New Revision: 219
Modified:
sofaswitch/trunk/sound/audio.cxx
sofaswitch/trunk/sound/audio.h
sofaswitch/trunk/sound/main.cxx
Log:
Big tidy up. Remove surplus code, and make it more "manageable".
Make the flow of execution in the code much much tidier.
Modified: sofaswitch/trunk/sound/audio.cxx
==============================================================================
--- sofaswitch/trunk/sound/audio.cxx (original)
+++ sofaswitch/trunk/sound/audio.cxx Tue Jan 2 22:35:49 2007
@@ -32,39 +32,32 @@
void TestAudioRead::Main()
{
- if (!OpenAudio(PSoundChannel::Recorder)) {
- PTRACE(1, "TestAudioRead\tFAILED to open read device");
- return;
- }
-
PTRACE(3, "TestAudioRead\tSound device is now open, start running");
+ PBYTEArray data;
+ data.SetSize(oneChunk);
+
while (keepGoing) {
- PBYTEArray data;
- data.SetSize(480);
- sound.Read(data.GetPointer(), data.GetSize());
-
- if (!socket.IsOpen()) {
- PTRACE(3, "Detected the closure of our udp socket, so end");
- keepGoing = FALSE;
- break;;
- }
+ PTRACE(6, "TestAudioRead\tREAD. Pre. Get " << oneChunk << " bytes");
- PINDEX lastReadCount = sound.GetLastReadCount();
- data.SetSize(lastReadCount);
- PTRACE(6, "TestAudioRead\tREAD. send one frame to the remote node "
- << data.GetSize() << " bytes");
- socket.Write(data.GetPointer(), data.GetSize());
- countPackets++;
- }
+ sound.Read(data.GetPointer(), oneChunk);
+ PTRACE(6, "TestAudioRead\tREAD. Post. Send " << oneChunk << " bytes");
- if (!keepGoing) {
- PTRACE(3, "keepgoing is false");
- }
-
- PTRACE(3, "End audio read thread");
+ if (socket.IsOpen()) {
+ socket.Write(data.GetPointer(), oneChunk);
+ countPackets++;
+ } else {
+ PTRACE(3, "Detected the closure of our udp socket, so end");
+ keepGoing = FALSE;
+ }
+
+ if (!keepGoing) {
+ PTRACE(3, "keepgoing is false");
+ }
+ }
+ PTRACE(3, "End audio READ thread");
}
-
+
//////////////////////////////////////////////////////////////////////
TestAudioWrite::TestAudioWrite(PUDPSocket &_socket, PSoundChannel &_sound)
@@ -85,13 +78,9 @@
void TestAudioWrite::Main()
{
- if (!OpenAudio(PSoundChannel::Player)) {
- PTRACE(1, "TestAudioWrite\tFAILED to open play device");
- return;
- }
PTRACE(3, "TestAudioWrite\tSound device is now open, start running");
- PString threadName = PString("QueueToSpeaker");
+ PString threadName = PString("QuToSpeaker");
PThread *q2s = PThread::Create(PCREATE_NOTIFIER(QueueToSpeakerMain), 30000,
PThread::NoAutoDeleteThread,
PThread::NormalPriority,
@@ -99,18 +88,20 @@
PBYTEArray data;
- data.SetSize(4800);
+ data.SetSize(oneChunk * 10); //Make it huge, to have enough space to read it all in.
while (keepGoing) {
socket.Read(data.GetPointer(), data.GetSize());
+ PINDEX readSize = socket.GetLastReadCount();
+
PTRACE(6, "Post Read of data from the socket. have "
- << socket.GetLastReadCount() << " bytes");
+ << readSize << " bytes");
if (!socket.IsOpen()) {
PTRACE(3, "Detected the closure of our udp socket, so end");
keepGoing = FALSE;
continue;
}
- PINDEX readSize = socket.GetLastReadCount();
+
PWaitAndSignal m(accessMutex);
if ((writeIndex + readSize) < buildSize) {
memcpy (buffer + writeIndex, data.GetPointer(), readSize);
@@ -122,7 +113,7 @@
memcpy(buffer, data.GetPointer() + firstHalf, secondHalf);
writeIndex = secondHalf;
}
- PTRACE(6, "postWRITE of " << data.GetSize() << " bytes to sound device");
+ PTRACE(6, "postWRITE of " << readSize << " bytes to sound device");
countPackets++;
}
@@ -139,7 +130,8 @@
void TestAudioWrite::QueueToSpeakerMain(PThread &, INT)
{
- while(keepGoing) {
+ while(keepGoing)
+ {
{
PWaitAndSignal m(accessMutex);
PINDEX available;
@@ -164,7 +156,7 @@
sound.Write(soundBuffer, oneChunk);
PTRACE(6, "Play " << oneChunk << " bytes to the speaker ");
}
-
+
PTRACE(4, "End of queue to speaker main thread ");
}
@@ -194,12 +186,6 @@
socket.Close();
}
-BOOL TestAudio::OpenAudio(enum PSoundChannel::Directions dir)
-{
- return TRUE;
-}
-
-
void TestAudio::RaiseVolume()
{
if ((currentVolume + 5) < 101)
Modified: sofaswitch/trunk/sound/audio.h
==============================================================================
--- sofaswitch/trunk/sound/audio.h (original)
+++ sofaswitch/trunk/sound/audio.h Tue Jan 2 22:35:49 2007
@@ -51,9 +51,6 @@
/**Name of our direction - read or write */
PString name;
- /**Call that causes the audio device to open */
- BOOL OpenAudio(enum PSoundChannel::Directions dir);
-
/**The current volume, which is 0..100(max) */
PINDEX currentVolume;
@@ -63,6 +60,15 @@
/** A count of the number of packets that have passed by */
PINDEX countPackets;
+
+ /**The number of bytes we write/read from the sound system each time. We
+ only work in 480 byte blcoks, or 30ms sampels */
+ enum {
+ /**30 ms of audio */
+ oneChunk = 480
+ };
+
+
};
/////////////////////////////////////////////////////////////////////////////
@@ -110,9 +116,7 @@
enum {
/** 5000 is 0.3125 of a second of audio data, which is heaps. Such a
large number saves us from wrapping round the end too often.*/
- buildSize= 5000,
- /**30 ms of audio */
- oneChunk = 480
+ buildSize= 5000
};
/**The mutex which protects access to the buffer and buffer variables */
Modified: sofaswitch/trunk/sound/main.cxx
==============================================================================
--- sofaswitch/trunk/sound/main.cxx (original)
+++ sofaswitch/trunk/sound/main.cxx Tue Jan 2 22:35:49 2007
@@ -305,7 +305,7 @@
if (!sound.Open(devName,
dir,
1, 8000, 16)) {
- cerr << "TestAudioRead:: Failed to open sound Playing/Recording device. Exit" << endl;
+ cerr << "TestAudio:: Failed to open sound Playing/Recording device. Exit" << endl;
PTRACE(3, "TestAudio\tFailed to open device for " << name << " and device name of " << devName);
return FALSE;