Playing audio data

There are two ways to play audio data: use a TSound convenience player or create and connect player and speaker components explicitly using TAudioPlayer and TSpeaker. To use TSound, see "Audio concepts" on page 305.

To play a sequence with an audio player:

  1. Create an audio player for the sequence.
    To create an audio player for an audio sequence, you can create a default audio player with the sequence.
  2. Create a default speaker object.
  3. Connect the player to the speaker.
    A connection represents a single audio channel; use two connections to support stereo, one for the left channel and one for the right channel. By convention, the left channel is used for monophonic player connections.
    1. Create an output port surrogate for the player.
    2. Create an input port surrogate for the speaker.
    3. Connect the player to the speaker.
  4. Call the Play function on the player.
    You can use WaitUntilComplete to block the thread until the sound is finished playing; the Play function returns immediately.
      // Playing a sine wave
      
      // Set up the sine wave, the player, and a speaker.
      TSineWave*  aSine= new TSineWave(440.,TMilliseconds(500));
      TAudioPlayer*   aPlayer = 
      TAudioPlayer::CreateDefaultAudioPlayer(aSine,
      TAudioType::GetLinear16Bit44KHz()); TSpeaker* aSpeaker =
      TSpeaker::CreateDefaultSpeaker(TAudioType::GetLinear16Bit44KHz()); // Connect the player to the speaker. TAudioOutputPortSurrogate* aPlayerOut = aPlayer->CreateLeftOutput(); TAudioInputPortSurrogate* aSpeakerIn = aSpeaker->CreateInput(); aPlayerOut->ConnectTo(*aSpeakerIn); // Play the sound from the current position. aPlayer->Play(); aPlayer->WaitUntilComplete();

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker