Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Audio Class Reference

This is an abstract interface for accessing the sound hardware. More...

#include <Audio.h>

Inheritance diagram for Audio

Inheritance graph
[legend]
List of all members.

Public Types

typedef int Volume
typedef int Velocity
typedef int Frequency
enum  Result { SUCCESS = 0, FAILURE, NOT_AVAILABLE }
enum  {
  MAX_VOLUME = 128, MIN_VOLUME = 0, MAX_VELOCITY, MIN_VELOCITY,
  MAX_FREQUENCY, MIN_FREQUENCY, PAN_LEFT = -127, PAN_CENTER = 0,
  PAN_RIGHT = 128, VOICE_UNALLOCATED = -1
}

Public Methods

virtual ~Audio ()
virtual Result Record (Sample& sample)
 Record to memory buffer -- not all sound devices can record
Parameters:
sample   A buffer for the recorded sound.
Returns:
NOT_AVAILABLE if not overrided.


virtual Result Play (Sample& sample) = 0
 Play the given sample.

virtual Result PlayNoWait (Sample& sample, int& NewChanelID, int& NewVoice) = 0
 Play the sample and return without waiting for it to finish.

virtual Result WaitForVoiceToFinish (int voice, int ChannelID) = 0
 do as it says.

virtual int AllocateVoice (const Sample& sample, int voice = VOICE_UNALLOCATED) = 0
 Allocates a voice for a sound which will be mixed into the buffer. More...

virtual Result DeleteVoice (int voice) = 0
 Remove the given voice from the Audio manager.

virtual Result DeleteVoice (Sample& sample)
virtual int VoicesAllocated () const = 0
 Return the number of current voices allocated.

virtual ChannelAllocateChannel () = 0
 Create a new Channel.

virtual void DeleteChannel (Channel *& channel) = 0
 Delete the given Channel.

virtual Result SetLocation (int x, int y, int z, int channel) = 0
virtual Result SetX (int x, int channel) = 0
virtual Result SetY (int y, int channel) = 0
virtual Result SetZ (int z, int channel) = 0
virtual Result GetLocation (int& x, int& y, int& z, int channel) = 0
virtual Result GetX (int& x, int channel) = 0
virtual Result GetY (int& y, int channel) = 0
virtual Result GetZ (int& z, int channel) = 0
virtual Result SetVolume (Volume volume, int channel) = 0
 volume.

virtual Volume GetVolume (int channel) = 0
virtual Result SetVelocity (Velocity velocity, int channel) = 0
 velocity -- how hard the key was pressed -- is this useful?

virtual Velocity GetVelocity (int channel) = 0
virtual Result SetFrequency (Frequency frequency, int channel) = 0
 frequency.

virtual Frequency GetFrequency (int channel) = 0
virtual Result SetPosition (unsigned long position, int channel) = 0
 position.

virtual unsigned long GetPosition (int channel) = 0
virtual Result SetVoice (int voice, int channel) = 0
 Set the voice for the given channel.

virtual int GetVoice (int channel) = 0
 get the voice that has been assigned to the channel.

virtual int NextChannel () = 0
 return the channel id for the next channel.

virtual void Start (int channel) = 0
 Start the channel playing.

virtual void Stop (int channel) = 0
 Stop the channel from making any noise.

virtual long GetPlaybackRate () = 0
virtual void SetTimeout (long milliseconds) = 0
virtual void StartTimeout () = 0
virtual void StopTimeout () = 0
virtual void WaitForTimeout () = 0
virtual bool IsStreamable () const
virtual Result StreamBuffer (const unsigned char* buffer, unsigned long length, int bits = 16, int channels = 2)
void Wait (long milliseconds)
 
Parameters:
milliseconds   The number of milliseconds to wait.



Static Public Methods

Audio* Create (int id = -1, int rate = 44100, int bits = 16, bool stereo = true, bool threaded = true)
 A factory method for creating the concrete instances.
Parameters:
id   The id for the type of Audio to create. -1 signifies the default.
rate   The playback rate.
bits   The bit width of the audio output.
stereo   Output in stereo or mono?
threaded   Whether the software mixer should be threaded.


Audio* CreateStreamable (int rate = 44100, int bits = 16, bool stereo = true, bool threaded = true)
 A factory method for creating the concrete instances of Audio that can stream data.
Parameters:
id   The id for the type of Audio to create. -1 signifies the default.
rate   The playback rate.
bits   The bit width of the audio output.
stereo   Output in stereo or mono?
threaded   Whether the software mixer should be threaded.


void RegisterDefaultDrivers (int rate, int bits, bool stereo, bool threaded)
const char* GetDescription (int id)

Detailed Description

This is an abstract interface for accessing the sound hardware.

To create a concrete instance of this class use:

    Audio* a = Audio::Create();
    
The concrete instance may be an interface to a wavetable sound card using /dev/sequencer or it may be an interface to a software mixing implementation.

This class has been modeled on the abilities of wavetable sound cards. ie soundcards that mix samples in hardware. Inspiration was taken from the opensound /dev/sequencer api.

Since software can be modified easily, unlike hardware, it is possible to interface the software mixing soundcards using the same api as the wavetable soundcards. The reverse is not always true.


Member Function Documentation

int Audio::AllocateVoice ( const Sample & sample,
int voice = VOICE_UNALLOCATED ) [pure virtual]
 

Allocates a voice for a sound which will be mixed into the buffer.

It returns number corresponding to it's place in the array of samples (voices.)

this should make a copy of the sample structure or at least not rely on the reference to Sample given always being valid it will assign the voice to the number "voice" or if voice is -1 then it will get the next free voice number and return it.

Reimplemented in AudioToFile, and Sequencer.


The documentation for this class was generated from the following files:
Generated at Mon Nov 27 01:46:37 2000 for LibPenguinPlay by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000