Author: derek Date: Wed Jan 3 22:52:52 2007 New Revision: 220 Modified: sofaswitch/trunk/sound/audio.cxx sofaswitch/trunk/sound/audio.h sofaswitch/trunk/sound/comms.cxx sofaswitch/trunk/sound/comms.h sofaswitch/trunk/sound/main.cxx Log: Add ability to control volume while it runs. Remove surplus code, some minor tidyups. Modified: sofaswitch/trunk/sound/audio.cxx ============================================================================== --- sofaswitch/trunk/sound/audio.cxx (original) +++ sofaswitch/trunk/sound/audio.cxx Wed Jan 3 22:52:52 2007 @@ -191,8 +191,7 @@ if ((currentVolume + 5) < 101) currentVolume += 5; sound.SetVolume(currentVolume); - cout << name << " volume is " << currentVolume << endl; - PTRACE(3, "TestAudio\tRaise volume for " << name << " to " << currentVolume); + PTRACE(3, "TestAudio\tRaise volume for " << GetDeviceDirName() << " to " << currentVolume); } void TestAudio::LowerVolume() @@ -200,9 +199,16 @@ if ((currentVolume - 5) >= 0) currentVolume -= 5; sound.SetVolume(currentVolume); - cout << name << " volume is " << currentVolume << endl; - PTRACE(3, "TestAudio\tLower volume for " << name << " to " << currentVolume); + PTRACE(3, "TestAudio\tLower volume for " << GetDeviceDirName() << " to " << currentVolume); } + +PString TestAudio::GetVolumeString() +{ + PStringStream answer; + answer << name << " volume is " << currentVolume << endl; + return answer; +} + //////////////////////////////////////////////////////////////////////////////// Modified: sofaswitch/trunk/sound/audio.h ============================================================================== --- sofaswitch/trunk/sound/audio.h (original) +++ sofaswitch/trunk/sound/audio.h Wed Jan 3 22:52:52 2007 @@ -40,6 +40,12 @@ /**Reporting function */ PINDEX GetCountPackets() { return countPackets; } + /**Report the current volume */ + PString GetVolumeString(); + + /**Report the direction of this device as a string */ + virtual PString GetDeviceDirName() { return " Undefined direction "; } + protected: /**the socket that we do comms over */ PUDPSocket &socket; @@ -83,6 +89,9 @@ /**the main entry point, where this thread starts */ void Main(); + + /**Report the direction of this device as a string */ + virtual PString GetDeviceDirName() { return PString("Recorder"); } }; ///////////////////////////////////////////////////////////////////////////// @@ -100,6 +109,8 @@ /**the main entry point, where this thread starts */ void Main(); + /**Report the direction of this device as a string */ + virtual PString GetDeviceDirName() { return PString("Player"); } protected: Modified: sofaswitch/trunk/sound/comms.cxx ============================================================================== --- sofaswitch/trunk/sound/comms.cxx (original) +++ sofaswitch/trunk/sound/comms.cxx Wed Jan 3 22:52:52 2007 @@ -112,6 +112,28 @@ MessageFrame::WaitForTermination(); } +PString Comms::AlterVolume(PSoundChannel::Directions dir, BOOL doRaise) +{ + PString newVolume; + + PWaitAndSignal m(lockReaderWriter); + TestAudio *ta; + + if (dir == PSoundChannel::Player) + ta = taw; + else + ta = tar; + + if (ta != NULL) { + if (doRaise) + ta->RaiseVolume(); + else + ta->LowerVolume(); + return ta->GetDeviceDirName() + PString(" ") + ta->GetVolumeString(); + } + return PString("No current sound device"); +} + void Comms::SilentlyEndAll() { Modified: sofaswitch/trunk/sound/comms.h ============================================================================== --- sofaswitch/trunk/sound/comms.h (original) +++ sofaswitch/trunk/sound/comms.h Wed Jan 3 22:52:52 2007 @@ -80,9 +80,21 @@ are two sources of a status query - the remote controller or the keybaord */ void GetStatusInformation(PString & statusInfo); - + + /**Raise the volume for the specified sound device. Return a + string describing the new volume */ + PString RaiseVolume(PSoundChannel::Directions dir) + { return AlterVolume(dir, TRUE); } + + /**Lower the volume for the specified sound device. Return a + string describing the new volume */ + PString LowerVolume(PSoundChannel::Directions dir) + { return AlterVolume(dir, FALSE); } + protected: - + /**Increase or decrease the volume on the specified device */ + PString AlterVolume(PSoundChannel::Directions dir, BOOL doRaise); + /**We have a DTMF string from our current master. Display this DTMF on the console. We always return TRUE, cause we can always do this right. */ virtual BOOL SendDtmf(const PString & dtmfVals); Modified: sofaswitch/trunk/sound/main.cxx ============================================================================== --- sofaswitch/trunk/sound/main.cxx (original) +++ sofaswitch/trunk/sound/main.cxx Wed Jan 3 22:52:52 2007 @@ -50,6 +50,8 @@ PStringStream help; help << "Press : " << endl + << " [ ] to raise or lower the play volume" << endl + << " { } to raise or lower the record volume" << endl << " H or ? help on this interface" << endl << " D dtmf Send dtmf message text to the controller" << endl << " S Report the status of this device" << endl @@ -65,31 +67,54 @@ break; switch (tolower(ch)) { - case 'd' : { - PString message; - console >> message; - comms.DtmfReceivedFromTheWorld(message); - cout << "Command ? " << flush; - } - break; - case 'x' : - case 'q' : { - endNow = TRUE; - PTRACE(3, "End this program now "); - } - break; - case 's' : { - PString status; - comms.GetStatusInformation(status); - cout << status << endl; - } - break; - case '?' : - case 'h' : - cout << help << endl; - cout << "Command ? " << flush; - default: - break; + case '[' : { + cout << comms.LowerVolume(PSoundChannel::Player) << endl; + cout << "Command ? " << flush; + } + break; + case '{' : { + cout << comms.LowerVolume(PSoundChannel::Recorder) << endl; + cout << "Command ? " << flush; + } + break; + + + case ']' : { + cout << comms.RaiseVolume(PSoundChannel::Player) << endl; + cout << "Command ? " << flush; + } + break; + case '}' : { + cout << comms.RaiseVolume(PSoundChannel::Recorder) << endl; + cout << "Command ? " << flush; + } + break; + + case 'd' : { + PString message; + console >> message; + comms.DtmfReceivedFromTheWorld(message); + cout << "Command ? " << flush; + } + break; + case 'x' : + case 'q' : { + endNow = TRUE; + PTRACE(3, "End this program now "); + } + break; + case 's' : { + PString status; + comms.GetStatusInformation(status); + cout << status << endl; + } + break; + case '?' : + case 'h' : + cout << help << endl; + cout << "Command ? " << flush; + default: + break; } // end switch } // end for @@ -110,9 +135,9 @@ } -PCREATE_PROCESS(Audio) +PCREATE_PROCESS(Audio); - void Audio::Main() +void Audio::Main() { PArgList & args = GetArguments(); args.Parse( @@ -247,7 +272,6 @@ LaunchNewId lid(ourId, ourPassword); Comms c(lid); - c.Resume(); PTRACE(3, "Constructed the comms device "); @@ -278,7 +302,9 @@ PTRACE(3, "Failed to construct a writer for the audio. Exit now "); return; } - + + c.Resume(); //Get the coms to start working + PThread::Sleep(200); //Wait for the comms to work UserInterface ui(c, soundPlayer, soundRecorder); c.WaitForTermination();
participants (1)
-
SofaSWITCH SVN