#ifndef AUDIOPLAYER_SDL_H #define AUDIOPLAYER_SDL_H #include "audioplayer.h" #include class InternalPlayer { public: InternalPlayer(int hz = 44100) : quit(false) { init(); } InternalPlayer(std::function cb, int hz = 44100) : callback(cb), quit(false) { init(); } void init() { //LOGD("Opening audio"); uint16_t bufSize = 32768/16; SDL_AudioSpec wanted = { 44100, AUDIO_S16, 2, 0, bufSize, 0, 0, fill_audio, this }; if(SDL_OpenAudio(&wanted, NULL) < 0 ) { //fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); throw audio_exception("Could not open audio"); } else SDL_PauseAudio(0); //callback(fifo.ptr(), fifo.size()/2); //fifo.putBytes(nullptr, fifo.size()); } void pause(bool on) { SDL_PauseAudio(on ? 1 : 0); } static void fill_audio(void *udata, Uint8 *stream, int len) { auto *iplayer = (InternalPlayer*)udata; iplayer->callback((int16_t*)stream, len/2); } int get_delay() const { return 1; } ~InternalPlayer() { SDL_CloseAudio(); } void writeAudio(int16_t *samples, int sampleCount) { } std::function callback; bool quit; //Fifo fifo; }; #endif // AUDIOPLAYER_SDL_H