void ModMp3::run() { SDL_AudioSpec desired, obtained, hardwareSpec; // setting the audio format desired.freq = 22050; desired.format = AUDIO_S16; desired.channels = 2; desired.samples = 1024; desired.callback = playBuffer; desired.userdata = NULL; SDL_Init(SDL_INIT_AUDIO); SDL_OpenAudio(&desired, &obtained); hardwareSpec = obtained; // Initialize madxlib madx_init(out_buffer, &mxhouse); // open the files in_file = fopen( m_fileToPlay.toAscii().data(), "rb"); out_file = fopen("/test.pcm", "wb"); SDL_PauseAudio( 0 ); while ( (false == m_haveToStop) && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) ) SDL_Delay(1000); // clean-up madx_deinit( &mxhouse ); fclose( in_file ); fclose( out_file ); SDL_CloseAudio(); SDL_Quit(); }
int main(int argc, char *argv[]) { char name[32]; /* Load the SDL library */ if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return(1); } if ( argv[1] == NULL ) { argv[1] = "sample.wav"; } /* Load the wave file into memory */ if ( SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL ) { fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); quit(1); } wave.spec.callback = fillerup; #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Initialize fillerup() variables */ if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } SDL_PauseAudio(0); /* Let the audio run */ printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32)); while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) ) #ifdef __amigaos4__ { // __check_abort(); #endif SDL_Delay(1000); #ifdef __amigaos4__ } #endif /* Clean up on signal */ SDL_CloseAudio(); SDL_FreeWAV(wave.sound); SDL_Quit(); return(0); }
void systemWriteDataToSoundBuffer() { if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) { SDL_PauseAudio(0); } bool bWait = true; while (bWait && ! speedup && GUI()->iGetThrottle() == 0) { SDL_mutexP(pstSoundMutex); if (iSoundLen < iSoundTotalLen) { bWait = false; } SDL_mutexV(pstSoundMutex); } int iLen = soundBufferLen; int iCopied = 0; if (iSoundLen + iLen >= iSoundTotalLen) { iCopied = iSoundTotalLen - iSoundLen; memcpy(&auiSoundBuffer[iSoundLen], soundFinalWave, iCopied); iSoundLen = iSoundTotalLen; SDL_CondSignal(pstSoundCond); bWait = true; if (! speedup && GUI()->iGetThrottle() == 0) { while(bWait) { SDL_mutexP(pstSoundMutex); if (iSoundLen < iSoundTotalLen) { bWait = false; } SDL_mutexV(pstSoundMutex); } memcpy(auiSoundBuffer, ((u8 *)soundFinalWave) + iCopied, soundBufferLen - iCopied); iSoundLen = soundBufferLen - iCopied; } else { memcpy(auiSoundBuffer, ((u8 *)soundFinalWave) + iCopied, soundBufferLen); } } else { memcpy(&auiSoundBuffer[iSoundLen], soundFinalWave, soundBufferLen); iSoundLen += soundBufferLen; } }
unsigned int audio_device::sound_get_bitrate() { if (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) { return (mp3->header.bitrate / 1000); } return 0; }
void AudioSdl::stopProcessing() { if( SDL_GetAudioStatus() == SDL_AUDIO_PLAYING ) { SDL_LockAudio(); m_stopped = true; SDL_PauseAudio( 1 ); SDL_UnlockAudio(); } }
void AudioSdl::stopProcessing() { if( SDL_GetAudioStatus() == SDL_AUDIO_PLAYING ) { m_stopSemaphore.acquire(); SDL_LockAudio(); SDL_PauseAudio( 1 ); SDL_UnlockAudio(); } }
void es_getAudioStatus(sdl_data *sd, int len, char *buff) { int sendlen; char *bp, *start; SDL_audiostatus s; s = SDL_GetAudioStatus(); start = bp = sdl_getbuff(sd, 1); put8(bp, s); sendlen = (int) (bp - start); sdl_send(sd, sendlen); }
/** * \brief Checks current audio status. * * \sa https://wiki.libsdl.org/SDL_GetAudioStatus */ int audio_getAudioStatus() { SDL_AudioStatus result; /* Check current audio status */ result = SDL_GetAudioStatus(); SDLTest_AssertPass("Call to SDL_GetAudioStatus()"); SDLTest_AssertCheck(result == SDL_AUDIO_STOPPED || result == SDL_AUDIO_PLAYING || result == SDL_AUDIO_PAUSED, "Verify returned value; expected: STOPPED (%i) | PLAYING (%i) | PAUSED (%i), got: %i", SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED, result); return TEST_COMPLETED; }
void SoundSDL::write(u16 * finalWave, int length) { if (!_initialized) return; #if !JS // XXX if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) SDL_PauseAudio(0); SDL_mutexP(_mutex); #endif unsigned int samples = length / 4; std::size_t avail; while ((avail = _rbuf.avail() / 2) < samples) { bool lock = (emulating && !speedup) ? true : false; _rbuf.write(finalWave, avail * 2); finalWave += avail * 2; samples -= avail; #if !JS SDL_mutexV(_mutex); SDL_SemPost(_semBufferFull); if (lock) { SDL_SemWait(_semBufferEmpty); } else { // Drop the remaining of the audio data return; } SDL_mutexP(_mutex); #endif } _rbuf.write(finalWave, samples * 2); #if !JS SDL_mutexV(_mutex); #endif }
void SoundSDL::write(u16 * finalWave, int length) { if (!_initialized) return; if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING){ SDL_PauseAudio(0); printf("SDLPauseAudio\n"); } SDL_mutexP(_mutex); //printf("RLM: length = %d\n", length); unsigned int samples = length / 4; // printf("RLM: length / 4 = %d\n", samples); std::size_t avail; while ((avail = _rbuf.avail() / 2) < samples) { _rbuf.write(finalWave, avail * 2); finalWave += avail * 2; samples -= avail; // If emulating and not in speed up mode, synchronize to audio // by waiting till there is enough room in the buffer if (emulating && !speedup) { //printf("SDL_CondWait\n"); SDL_CondWait(_cond,_mutex); } else { // Drop the remainder of the audio data printf("RLM: Drop samples!\n"); SDL_mutexV(_mutex); return; } } _rbuf.write(finalWave, samples * 2); //printf("RLM: writing %d samples\n", samples); SDL_mutexV(_mutex); }
/* ------------------------------------------------ * stop_audio * ------------------------------------------------ */ static void stop_audio() { AudioPlaybackThreadUserData *usrPtr; usrPtr = getUsrPtr(); if (usrPtr != NULL) { SDL_LockAudio(); if(SDL_GetAudioStatus() != SDL_AUDIO_STOPPED) { SDL_CloseAudio(); } SDL_UnlockAudio(); } } /* end stop_audio */
void fillonce (void *unused, Uint8 *stream, int len) { Uint8 *waveptr; int waveleft; waveleft = wave->soundlen - wave->soundpos; if (waveleft <= len) { if (SDL_GetAudioStatus () == SDL_AUDIO_PLAYING) { SDL_PauseAudio (0); } return; } waveptr = wave->sound + wave->soundpos; SDL_MixAudio (stream, waveptr, len, SDL_MIX_MAXVOLUME); wave->soundpos += len; }
static void sound_sdl_write(SoundDriver *driver, guint16 * finalWave, int length) { g_assert(driver != NULL); DriverData *data = (DriverData *)driver->driverData; if (!data->_initialized) return; if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) SDL_PauseAudio(0); SDL_LockMutex(data->_mutex); unsigned int samples = length / 4; int avail; while ((avail = ring_buffer_avail(data->_rbuf) / 4) < samples) { ring_buffer_write(data->_rbuf, finalWave, avail * 4); finalWave += avail * 2; samples -= avail; // If emulating and not in speed up mode, synchronize to audio // by waiting till there is enough room in the buffer if (data->sync) { SDL_CondWait(data->_cond, data->_mutex); } else { // Drop the remaining of the audio data SDL_UnlockMutex(data->_mutex); return; } } ring_buffer_write(data->_rbuf, finalWave, samples * 4); SDL_UnlockMutex(data->_mutex); }
void loop() { #ifdef __EMSCRIPTEN__ if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) { emscripten_cancel_main_loop(); } else #endif { /* The device from SDL_OpenAudio() is always device #1. */ const Uint32 queued = SDL_GetQueuedAudioSize(1); SDL_Log("Device has %u bytes queued.\n", (unsigned int) queued); if (queued <= 8192) { /* time to requeue the whole thing? */ if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) { SDL_Log("Device queued %u more bytes.\n", (unsigned int) wave.soundlen); } else { SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int) wave.soundlen, SDL_GetError()); } } } }
void playBuffer( void *udata, Uint8 *stream, int len ) { // only play if we have data left if ( audio_len == 0 ) qApp->exit(1); mxsig = madx_read( in_buffer, out_buffer, &mxhouse, &mxstat ); // if we got a critical error if( ERROR_OCCURED == mxsig ) qApp->exit(1); // fill buffer else if( MORE_INPUT == mxsig ) { if( mxstat.buffstart ) // Fill partial buffer { a = fread(mxstat.buffstart, 1, mxstat.readsize, in_file); if( feof(in_file) ) { mxstat.is_eof = 1; mxstat.readsize = a; } } else // Read full buffer { fread(in_buffer, 1, mxstat.readsize, in_file); if( feof(out_file) ) { mxstat.is_eof = 1; mxstat.readsize = a; } } } // output to file else if ( FLUSH_BUFFER == mxsig ) { //if( mxstat.write_size == fwrite(out_buffer, 1, mxstat.write_size, out_file) ) // Logger::getInstance()->addInfo( "Writing buffer", MODMP3 ); //else // Logger::getInstance()->addError( "Writing buffer error", MODMP3 ); // waiting to finish playing //obtained.size = mxstat.write_size; obtained.userdata = out_buffer; SDL_PauseAudio( 0 ); while ( (false == m_haveToStop) && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) ) SDL_Delay(1000); } // input file EOF else if( EOF_REACHED == mxsig ) { //a = fwrite(out_buffer,1,mxstat.write_size,out_file); //if( mxstat.write_size != a ) // Logger::getInstance()->addError( "Error with final write", MODMP3 ); //else // Logger::getInstance()->addInfo( "Finished.", MODMP3 ); //obtained.size = mxstat.write_size; obtained.userdata = out_buffer; } // mix as much data as possible len = ( len > audio_len ? audio_len : len ); SDL_MixAudio( stream, audio_pos, len, SDL_MIX_MAXVOLUME ); audio_pos += len; audio_len -= len; }
/* ------------------------------------------------ * start_audio * ------------------------------------------------ * init SDL audio with new (pending) setings and (re)start audio playback * from prepared position "start_at_sample" * (e.g. from begin in case gap_sdl_start_sample was not called before) * * in case audio is already playing stop it, and restart with the new settings. */ static int start_audio() { AudioPlaybackThreadUserData *usrPtr; int ii; usrPtr = getUsrPtr(); if (usrPtr == NULL) { return (1); } SDL_LockAudio(); if(SDL_GetAudioStatus() != SDL_AUDIO_STOPPED) { SDL_CloseAudio(); } for (ii=0; ii < NUM_SOUNDSLOTS; ii++) { if (usrPtr->sounds[ii].data == NULL) { if (usrPtr->sounds[ii].fpWav == NULL) { usrPtr->sounds[ii].fpWav = gap_audio_wav_open_seek_data(usrPtr->sounds[ii].wav_filename); } if (usrPtr->sounds[ii].fpWav != NULL) { long seekPosition; seekPosition = usrPtr->sounds[ii].offset_to_first_sample + (usrPtr->sounds[ii].start_at_sample * usrPtr->frame_size); fseek(usrPtr->sounds[ii].fpWav, seekPosition, SEEK_SET); } } else { usrPtr->sounds[ii].dpos = usrPtr->sounds[ii].start_at_sample * usrPtr->frame_size; if (usrPtr->sounds[ii].dpos >= usrPtr->sounds[ii].dlen) { /* reset to begin on illegal start position */ usrPtr->sounds[ii].dpos = 0; } } } /* load sdlAudioSpec (relevant for playback) from prepared values */ usrPtr->sdlAudioSpec.freq = usrPtr->samplerate; usrPtr->sdlAudioSpec.format = usrPtr->format; usrPtr->sdlAudioSpec.channels = usrPtr->channels; usrPtr->sdlAudioSpec.samples = AUDIO_BUFFER_SIZE_IN_SAMPLES; /* audio buffer size (512 upto 8192 recommanded) */ SDL_UnlockAudio(); if ( SDL_OpenAudio(&usrPtr->sdlAudioSpec, NULL) < 0 ) { /* Unable to open audio use SDL_GetError() to query reason */ return(2); } SDL_PauseAudio(0); /* pause value 0 triggers playback start */ return (0); /* OK */ } /* end start_audio */
int main(int argc, char *argv[]) { int i; char filename[4096]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } if (argc > 1) { SDL_strlcpy(filename, argv[1], sizeof(filename)); } else { SDL_strlcpy(filename, "sample.wav", sizeof(filename)); } /* Load the wave file into memory */ if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } wave.spec.callback = fillerup; #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Show the list of available drivers */ SDL_Log("Available audio drivers:"); for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { SDL_Log("%i: %s", i, SDL_GetAudioDriver(i)); } /* Initialize fillerup() variables */ if (SDL_OpenAudio(&wave.spec, NULL) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); /* Let the audio run */ SDL_PauseAudio(0); while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) SDL_Delay(1000); /* Clean up on signal */ SDL_CloseAudio(); SDL_FreeWAV(wave.sound); SDL_Quit(); return (0); }
int audio_device::sound_status() { return SDL_GetAudioStatus(); }
/* ------------------------------------- * gap_sdl_cmd * ------------------------------------- * perform simple audio_player command . * Note: some of the commands do not make sense * in this SDL based implementation * and are just dummies for compatibility with the * API (that was designed base on the older wavplay client functions) */ int gap_sdl_cmd(int cmd,int flags,GapSdlErrFunc erf) { static char *sdl_no_error_available = ""; char *sdl_error; int rc = 1; AudioPlaybackThreadUserData *usrPtr; sdl_error = sdl_no_error_available; usrPtr = getUsrPtr(); if (usrPtr != NULL) { if(gap_debug) { printf("gap_sdl_cmd cmd:%d (%s) flags:%d SdlAudioStatus:%d\n" , cmd , msg_name(cmd) , flags , (int)SDL_GetAudioStatus() ); } switch(cmd) { case GAP_SDL_CMD_Bye: stop_audio(); close_files(); rc = 0; /* OK */ break; case GAP_SDL_CMD_Play: rc = start_audio(); sdl_error = SDL_GetError(); /* SDL_GetError uses sttically allocated message that must NOT be freed */ break; case GAP_SDL_CMD_Pause: stop_audio(); rc = 0; /* OK */ break; case GAP_SDL_CMD_Stop: stop_audio(); close_files(); rc = 0; /* OK */ break; case GAP_SDL_CMD_Restore: stop_audio(); rc = 0; /* OK */ break; case GAP_SDL_CMD_SemReset: rc = 0; /* OK */ break; } } if ((rc != 0) && (erf != NULL )) { call_errfunc(erf, "%s: Sending cmd%d to audio_player failed (rc:%d) err:%s", msg_name(cmd), cmd, sdl_error, rc); } if(gap_debug) { printf("gap_sdl_cmd cmd:%d (%s) flags:%d retcode:%d\n", cmd, msg_name(cmd), flags, rc); } return rc; /* Zero indicates success */ } /* end gap_sdl_cmd */
static int lua_SDL_GetAudioStatus(lutok::state& state){ state.push_integer(SDL_GetAudioStatus()); return 1; }
int pcm_out_sdl_state_get(void) { return (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING); }
void sandbox_sdl_audio_stop(void) { if(SDL_GetAudioStatus() != SDL_AUDIO_PAUSED) SDL_PauseAudio(1); }
void sandbox_sdl_audio_start(void) { if(SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) SDL_PauseAudio(0); }
int main(int argc, char *argv[]) { int i; char filename[4096]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } if (argc > 1) { SDL_strlcpy(filename, argv[1], sizeof(filename)); } else { SDL_strlcpy(filename, "sample.wav", sizeof(filename)); } /* Load the wave file into memory */ if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } wave.spec.callback = NULL; /* we'll push audio. */ #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Initialize fillerup() variables */ if (SDL_OpenAudio(&wave.spec, NULL) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } /*static x[99999]; SDL_QueueAudio(1, x, sizeof (x));*/ /* Let the audio run */ SDL_PauseAudio(0); /* Note that we stuff the entire audio buffer into the queue in one shot. Most apps would want to feed it a little at a time, as it plays, but we're going for simplicity here. */ while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) { /* The device from SDL_OpenAudio() is always device #1. */ const Uint32 queued = SDL_GetQueuedAudioSize(1); SDL_Log("Device has %u bytes queued.\n", (unsigned int) queued); if (queued <= 8192) { /* time to requeue the whole thing? */ if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) { SDL_Log("Device queued %u more bytes.\n", (unsigned int) wave.soundlen); } else { SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int) wave.soundlen, SDL_GetError()); } } SDL_Delay(100); /* let it play for awhile. */ } /* Clean up on signal */ SDL_CloseAudio(); SDL_FreeWAV(wave.sound); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { char filename[4096]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } if (argc > 1) { SDL_strlcpy(filename, argv[1], sizeof(filename)); } else { SDL_strlcpy(filename, "sample.wav", sizeof(filename)); } /* Load the wave file into memory */ if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } wave.spec.callback = NULL; /* we'll push audio. */ #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Initialize fillerup() variables */ if (SDL_OpenAudio(&wave.spec, NULL) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } /*static x[99999]; SDL_QueueAudio(1, x, sizeof (x));*/ /* Let the audio run */ SDL_PauseAudio(0); done = 0; /* Note that we stuff the entire audio buffer into the queue in one shot. Most apps would want to feed it a little at a time, as it plays, but we're going for simplicity here. */ #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) { loop(); SDL_Delay(100); /* let it play for awhile. */ } #endif /* Clean up on signal */ SDL_CloseAudio(); SDL_FreeWAV(wave.sound); SDL_Quit(); return 0; }
bool SDLAudioDev::getPlay() { SDL_audiostatus status = SDL_GetAudioStatus(); return status==SDL_AUDIO_PLAYING; }