Chapter 4. Using some DSP units together

Table of Contents

Playing a pitched sound
Playing with the connections

Playing a pitched sound

In this example, we show how easy it is to play an OGG file with a pitching effect applied to it.

Figure 4.1. Playing a pitched sound - DSP chain

Playing a pitched sound - DSP chain
void pitchplay()
{
  // Init
  try
  {
    OssOutput oss;
    OggFileDecoder decoder("track.ogg");
    Pitch pitch(0.75);
  }
  catch (IzSoundException &err)
  {
    cout << err.what() << endl;
    return;
  }

  // Connection
  decoder.connect(&pitch, 0, 0);
  pitch.connect(&oss, 0, 0);

  // Let's play
  while (!decoder.isEndReached())
  {
    decoder.run();
  }

  // We ensure that we flush all the data that can still be in the chain
  for (int i = 0; i < 10; ++i)
  {
    decoder.run(); 
  }
}