Audio library - being redesigned
Audio - Option 1
Files: Sound.cpp, Sound.h
Requires: Util.cpp
Example Program: programming\c++\polylib\soundtest
InitSound();
PlayMusic("Music.ogg");
ExitSound();
CSound - Quick and Simple
BOOL Load(const char *File, int Dummy);
BOOL Play(float Gain=1.0f, float Frequency=1.0f);
CSoundSource - for more complex playing
Audio - Option 2
class CAudioController;
CAudioController Audio
Audio.Init();
int SoundHandle=Audio.LoadOGG(const char *File);
Audio.Play(SoundHandle); //Plays on default source(1)
int Source=Audio.NewSource();
Audio.SetPosition(Source, 10,10,10);
Audio.Play(SoundHandle, Source);
Audio.Clear();
How I use sound
- Play music, play another song, stop
- Play a menu sound
- Attach a sound to a part of an object
- Loop a sound on an object, turn it off later
- Place a sound and dont want to know about it ever again
- I tend to use the same settings for each buffer
- Sometimes it might be nice to hold a single position for multiple sounds; for example, a gun in shipgame?
Conclusions
- A sound is very unlikly to be played in the same spot twice
- The audio controller should hold the sources and fill them with data as necessary for every sound played
- I rarly care about a sound once it is placed
- CAudio should return a handle which autoinvalidates. This way an object can modify the sound later but does not have to delete.
- Sounds that loops will never autodelete.
Design based on Conclusions
- Sound buffers should be loaded with sounds, yay
- you get a handle to a source when you ask CAudio to play it
- If the sound is not looping, the handle will automaticly be invalid after a certain period of time
- There will be a limit of about 32 sim sounds
- Music is independant of sound and can only be played or stopped
- You can feed a handle into CAudio to control its gain, position, velocity, pitch
- Two sound buffers should referance the same sound if it is loaded twice
- Handle->Source should be very fast
- For backwards compatibility a CSoundSource class can be made that holds a sound position and calls the CAudio functions
SoundBuffer -> Sound
SoundSource -> internally stored in CAudio
Copyright 2004 © Polyart. All rights reserved.