#include #include #include #include #include #include "physfsrwops.h" #include //#include "wavestream2.h" class SoundDevice { public: SoundDevice(); ~SoundDevice(); void close(); void open(); void open(int r, Uint16 f, int c, int bs); const char* getCardName() { return cardName; } private: char cardName[50]; int rate; int channels; int bufSize; Uint16 format; int _status; }; SoundDevice::SoundDevice() { memset(cardName, 0, sizeof(cardName)); rate = 44100; channels = 2; bufSize = 4096; format = AUDIO_S16; _status = 0; } SoundDevice::~SoundDevice() { Mix_HaltGroup(-1); Mix_HaltMusic(); close(); } void SoundDevice::close() { if (!_status) return; Mix_CloseAudio(); } void SoundDevice::open() { if (_status) close(); if (Mix_OpenAudio(rate, format, channels, bufSize)) throw std::string(SDL_GetError()); SDL_AudioDriverName (cardName, sizeof (cardName)); Mix_QuerySpec(&rate, &format, &channels); fprintf (stderr, "opened %s at %d Hz %d bit %s (%i), %d bytes audio buffer\n", cardName, rate, format & 0xFF, channels > 1 ? "stereo" : "mono", channels, bufSize); _status = 1; } void SoundDevice::open(int r, Uint16 f, int c, int bs) { rate = r; format = f; channels = c; bufSize = bs; open(); } #if 0 void myMusicPlayer(void *udata, Uint8 *stream, int len) { int i,act=0; Sint16 *ptr2; if (stream == 0) throw std::string("Zero music stream :-("); ptr2=(Sint16 *)stream; if (playing_music) { while(actflags&SOUND_SAMPLEFLAG_EOF)) { /* End of file: */ if (music_loops!=-1) { current_music_loop++; if (current_music_loop>music_loops) { playing_music=false; if (music_sound!=0) Sound_FreeSample(music_sound); music_sound=0; } else { Sound_Rewind(music_sound); } /* if */ } else { Sound_Rewind(music_sound); } /* if */ } else { /* In the middle of the file: */ int decoded=0; Sint16 *ptr; Sound_SetBufferSize(music_sound, len-act); decoded=Sound_Decode(music_sound); ptr=(Sint16 *)music_sound->buffer; for(i=0;i