| #include "SDL.h" #include "MixBox.h" int main(int argc, char* argv[]) { using namespace MB; // MixBox's namespace // Get the MixBox for future use MixBox& mixer = MixBox::instance(); // Open the mixer mixer.openMixer(); // Load a sound SoundID hit = mixer.loadSound("hit.wav"); if(hit.isBad()) printf("Error loading sound file.\n"); // Play the sound hit.play(); while(mixer.isPlaying()) { SDL_Delay(1); } // Close the mixer mixer.closeMixer(); // Delete the sound mixer.freeSounds(); // All done SDL_Quit(); return 0; } |
|
static MixBox&
instance(); - Returns the singleton MixBox. void setAudioFormat(Uint16 format); void setAudioRate(unsigned int rate); void setNumOutputs(unsigned int num); - Sets the number of output (not mixing) channels (e.g. 1 for mono, 2 for stereo) void setBufferSize(unsigned int size); unsigned int setNumChannels(unsigned int numChannels); - Sets the number of mixing channels bool openMixer(); void closeMixer(); |
| SoundID
loadSound(const char* filename); MusicID loadMusic(const char* filename); void freeSounds(); void free(const SoundID& id); void freeMusic(); void free(const MusicID& id); |
| bool
swapStereo(); ChannelID play(const SoundID& id, int loops = 0); void stop(); ChannelID playPan2D(const SoundID& id, float x, float y, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y) is from (0, 0). ChannelID playPan3D(const SoundID& id, float x, float y, float z, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y, z) is from (0, 0, 0). bool isPlaying() const; - Tells you if any channel is playing a sound. There are other functions that work with specific channels. |
| void
play(const MusicID& id, int loops = -1); bool isMusicPlaying() const; void stopMusic(); void pauseMusic(); bool isMusicPaused() const; void rewindMusic(); void resumeMusic(); bool skipMusic(double position); bool fadeInMusic(const MusicID& id, unsigned int milliseconds, double skipPosition = 0, int loops = -1); bool fadeOutMusic(unsigned int milliseconds); |
|
bool isBad() const; - Tells you if the sound loaded incorrectly. void setVolume(float volume = 1.0f); float getVolume() const; ChannelID play(int loops = 0); ChannelID playPan2D(float x, float y, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y) is from (0, 0). ChannelID playPan3D(float x, float y, float z, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y, z) is from (0, 0, 0). |
|
bool isBad() const; - Tells you if the music loaded incorrectly. void setVolume(float volume = 1.0f); float getVolume() const; void play(int loops = -1); |
|
bool isBad() const; - Tells you if the ID represents a viable channel. void setVolume(float volume = 1.0f); float getVolume() const; bool isPlaying() const; void play(const SoundID& sound, int loops = 0); void stop(); void pause(); bool isPaused() const; void resume(); void playPan2D(const SoundID& id, float x, float y, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y) is from (0, 0). void playPan3D(const SoundID& id, float x, float y, float z, float maxRange, int loops = 0); - Plays a sound with stereo panning and volume that depend on how far (x, y, z) is from (0, 0, 0). |