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

BOOL PSoundChannelSunAudio::SetFormat ( unsigned  numChannels,
unsigned  sampleRate,
unsigned  bitsPerSample 
) [virtual]

Set the format for play/record. Note that linear PCM data is the only one supported at this time.

Note that if the PlayFile() function is used, this may be overridden by information in the file being played.

Returns:
TRUE if the format is valid.

Reimplemented from PSoundChannel.

Definition at line 183 of file sound_sunaudio.cxx.

References PChannel::os_handle.

                                                     {
  PAssert(numChannels >= 1 && numChannels <= 2, PInvalidParameter);
  PAssert(bitsPerSample == 8 || bitsPerSample == 16, PInvalidParameter);

  audio_info_t audio_info;
  int err;

  // Change only the values needed below
  AUDIO_INITINFO(&audio_info);      
  if (direction == Player){
    // sett parameters for playing sound
    mSampleRate = audio_info.play.sample_rate = sampleRate; 
    mNumChannels = audio_info.play.channels = numChannels;
    mBitsPerSample = audio_info.play.precision = bitsPerSample;
    audio_info.play.encoding = AUDIO_ENCODING_LINEAR; 

  } else {                    
    // set parameters for recording sound
    audio_info.record.sample_rate = mSampleRate = sampleRate;     
    audio_info.record.channels = mNumChannels = numChannels;
    audio_info.record.precision = mBitsPerSample = bitsPerSample;
    audio_info.record.encoding = AUDIO_ENCODING_LINEAR;
  }

  // The actual setting of the parameters
  err=::ioctl(os_handle,AUDIO_SETINFO,&audio_info);   
  if (err==EINVAL || err==EBUSY)
    return FALSE;

  // Let's recheck the configuration...
  AUDIO_INITINFO(&audio_info);      
  err = ::ioctl(os_handle, AUDIO_GETINFO, &audio_info);     
  actualSampleRate =  (direction == Player) ? audio_info.play.sample_rate : audio_info.record.sample_rate;

  return TRUE;
}

Generated by  Doxygen 1.6.0   Back to index