PLM Software Multimedia Tools and Games
PLMBase

PLMBase Component : Audio


Overview

This component is quite simple, since it only contains two classes. The first one represents the hardware output device (mixer) and the other one a sound buffer to play with the first.

Classes


  • PLMMixer : this class gives access to audio hardware, allow the user to set up a given format and frequency, then to play different sound buffers and mix them together. Each channel has its own volume and panning setting.
  • PLMSound : represents one audio buffer. Can load data from WAV files. Can be converted to match the current mixer format.

Examples


This first example shows how to initialise a mixer with 4 channels (default) :

  PLMMixer *mixer = PLMMixer::GetInstance ();
  ASSERT(mixer);
  // format      = 16 bit, signed
  // frequency   = 22050 Hz
  // buffer size = 2048
  // stereo      = true
  // channels    = 5, 4 for sounds, 1 for music
  if (! mixer->Init (AUDIO_S16, 22050, 2048, true))
    {
      cerr << "Can't initialise mixer.\n";
      exit(1);
    }
  cout << ("Mixer initialized.\n");
  mixer->Unpause();

Do not forget to delete the mixer object when you do not need it any more.

Then let's see how to load a sound from a file and play it with the mixer :

  // load the sound from file intro.wav
  PLMSound sound ("intro.wav");
  // convert sound format into mixer's format
  sound.MixerFormat ();
  // play the sound on the left speaker, and loop for ever
  int channel = mixer->PlaySound (&sound, 120, PLMMixer::LOOP_INF, -120);
  // "move" the sound from left to right speaker
  PLMTimer timer;
  for (int i = -120; i < 128; i += 10)
    {
      mixer->SetSoundPan (channel, i);
      timer.Wait (100);  // wait 100ms
    }

Copyright 2001-2004 PLMSoft All rights reserved. (last mod.: 15 Oct 2004)