Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

void Audio::Main (  ) [virtual]

User override function for the main execution routine of the thread. A descendent class must provide the code that will be executed in the thread within this function.

Note that the correct way for a thread to terminate is to return from this function.

Implements PThread.

Definition at line 47 of file audio.cxx.

References PTrace::Blocks, PTrace::ClearOptions(), PChannel::Close(), PTrace::FileAndLine, PSoundChannel::GetDefaultDevice(), PArgList::GetOptionCount(), PArgList::GetOptionString(), PSoundChannel::GetVolume(), PArgList::HasOption(), PTrace::Initialise(), PSoundChannel::Open(), PArgList::Parse(), PTrace::SetLevel(), PTrace::Thread, and PTrace::Timestamp.

{
  PArgList & args = GetArguments();
  args.Parse("r.    "
       "f.    "
       "h.    "
#if PTRACING
             "o-output:"             "-no-output."
             "t-trace."              "-no-trace."
#endif
       "v.    "
       "s:    ");
 
  if (args.HasOption('h')) {
    cout << "usage: audio " 
         << endl
         << "     -r        : report available sound devices" << endl
         << "     -f.       : do a full duplex sound test on a sound device" << endl
         << "     -s  dev   : use this device in full duplex test " << endl
         << "     -h        : get help on usage " << endl
         << "     -v        : report program version " << endl
#if PTRACING
         << "  -t --trace   : Enable trace, use multiple times for more detail" << endl
         << "  -o --output  : File for trace output, default is stderr" << endl
#endif
         << endl;
    return;
  }


  PTrace::Initialise(args.GetOptionCount('t'),
                     args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
         PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);

  if (args.HasOption('v')) {
    cout << endl
         << "Product Name: " <<  (const char *)GetName() << endl
         << "Manufacturer: " <<  (const char *)GetManufacturer() << endl
         << "Version     : " <<  (const char *)GetVersion(TRUE) << endl
         << "System      : " <<  (const char *)GetOSName() << '-'
         <<  (const char *)GetOSHardware() << ' '
         <<  (const char *)GetOSVersion() << endl
         << endl;
    return;
  }
  

  cout << "Audio Test Program\n";

  PSoundChannel::Directions dir;
  PStringArray namesPlay, namesRecord;

  cout << "\n";
  cout << "List of play devices\n";

  dir = PSoundChannel::Player;
  namesPlay = PSoundChannel::GetDeviceNames(dir);
  for (PINDEX i = 0; i < namesPlay.GetSize(); i++)
    cout << "  \"" << namesPlay[i] << "\"\n";

  cout << "The default play device is \"" << PSoundChannel::GetDefaultDevice(dir) << "\"\n";


  cout << "\n";
  cout << "List of Record devices\n";

  dir = PSoundChannel::Recorder;
  namesRecord = PSoundChannel::GetDeviceNames(dir);
  for (PINDEX i = 0; i < namesRecord.GetSize(); i++)
    cout << "  \"" << namesRecord[i] << "\"\n";

  cout << "The default record device is \"" << PSoundChannel::GetDefaultDevice(dir) << "\"\n";

  cout << "\n";


  // Display the mixer settings for the default devices
  PSoundChannel sound;
  dir = PSoundChannel::Player;
  sound.Open(PSoundChannel::GetDefaultDevice(dir),dir);

  unsigned int vol;
  if (sound.GetVolume(vol))
    cout << "Play volume is (for the default play device)" << vol << endl;
  else
    cout << "Play volume cannot be obtained" << endl;

  sound.Close();

  dir = PSoundChannel::Recorder;
  sound.Open(PSoundChannel::GetDefaultDevice(dir),dir);
  
  if (sound.GetVolume(vol))
    cout << "Record volume is (for the default record device)" << vol << endl;
  else
    cout << "Record volume cannot be obtained" << endl;

  sound.Close();


  if (args.HasOption('f')) {
    devName = args.GetOptionString('s');
    if (devName.IsEmpty())
      devName = PSoundChannel::GetDefaultDevice(PSoundChannel::Player);

    if (namesPlay.GetStringsIndex(devName) == P_MAX_INDEX) {
      cout << "could not find " << devName << " in list of available play devices - abort test" << endl;
      return;
    }

    if (namesRecord.GetStringsIndex(devName) == P_MAX_INDEX) {
      cout << "could not find " << devName << " in list of available record devices - abort test" << endl;
      return;
    }

    PTRACE(3, "Audio\tTest device " << devName);
    
    TestAudioDevice device;
    device.Test();
      return;
  }

#if PTRACING
  if (args.GetOptionCount('t') > 0) {
    PTrace::ClearOptions(0);
    PTrace::SetLevel(0);
  }
#endif

}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index