예제 #1
0
파일: sdl_snd.c 프로젝트: MAN-AT-ARMS/ioq3
/*
===============
SNDDMA_Shutdown
===============
*/
void SNDDMA_Shutdown(void)
{
	if (sdlPlaybackDevice != 0)
	{
		Com_Printf("Closing SDL audio playback device...\n");
		SDL_CloseAudioDevice(sdlPlaybackDevice);
		Com_Printf("SDL audio playback device closed.\n");
		sdlPlaybackDevice = 0;
	}

#ifdef USE_SDL_AUDIO_CAPTURE
	if (sdlCaptureDevice)
	{
		Com_Printf("Closing SDL audio capture device...\n");
		SDL_CloseAudioDevice(sdlCaptureDevice);
		Com_Printf("SDL audio capture device closed.\n");
		sdlCaptureDevice = 0;
	}
#endif

	SDL_QuitSubSystem(SDL_INIT_AUDIO);
	free(dma.buffer);
	dma.buffer = NULL;
	dmapos = dmasize = 0;
	snd_inited = qfalse;
	Com_Printf("SDL audio shut down.\n");
}
예제 #2
0
static int S_CaptureDriverInit (int sampleRate)
{
	SDL_AudioDeviceID inputdevid = 0;
	SDL_AudioSpec desired, obtained;
	int ret = 0;
	const char *requested_device = NULL;

	if (SDL_WasInit (SDL_INIT_AUDIO) == 0)
		ret = SDL_InitSubSystem (SDL_INIT_AUDIO);

	if (ret == -1) {
		Con_Printf ("Couldn't initialize SDL audio: %s\n", SDL_GetError ());
		return false;
	}

	memset (&desired, 0, sizeof (desired));
	desired.freq = sampleRate;
	desired.samples = 64;
	desired.format = AUDIO_S16LSB;
	desired.channels = 1;

	/* Make audiodevice list start from index 1 so that 0 can be system default */
	if (s_inputdevice.integer > 0) {
		requested_device = SDL_GetAudioDeviceName (s_inputdevice.integer - 1, 0);
	}

	if ((inputdevid = SDL_OpenAudioDevice (requested_device, 1, &desired, &obtained, 0)) <= 0) {
		Com_Printf ("sound: couldn't open SDL audio: %s\n", SDL_GetError ());
		if (requested_device != NULL) {
			Com_Printf ("sound: retrying with default audio device\n");
			if ((inputdevid = SDL_OpenAudioDevice (NULL, 1, &desired, &obtained, 0)) <= 0) {
				Com_Printf ("sound: failure again, aborting...\n");
				return 0;
			}
			Cvar_LatchedSet (&s_inputdevice, "0");
		}
	}

	if (obtained.format != AUDIO_S16LSB) {
		Com_Printf ("SDL audio format %d unsupported.\n", obtained.format);
		SDL_CloseAudioDevice (inputdevid);
		inputdevid = 0;
		return 0;
	}

	if (obtained.channels != 1 && obtained.channels != 2) {
		Com_Printf ("SDL audio channels %d unsupported.\n", obtained.channels);
		SDL_CloseAudioDevice (inputdevid);
		inputdevid = 0;
		return 0;
	}

	Com_Printf ("Using SDL audio capture driver: %s @ %d Hz (samplerate %d)\n", SDL_GetCurrentAudioDriver (), obtained.freq, obtained.samples);
	SDL_PauseAudioDevice (inputdevid, 0);

	return inputdevid;
}
예제 #3
0
SoundSDL::~SoundSDL()
{
	if (!_initialized)
		return;

	SDL_mutexP(_mutex);
	int iSave = emulating;
	emulating = 0;
	SDL_SemPost(_semBufferFull);
	SDL_SemPost(_semBufferEmpty);
	SDL_mutexV(_mutex);

	SDL_DestroySemaphore(_semBufferFull);
	SDL_DestroySemaphore(_semBufferEmpty);
	_semBufferFull = NULL;
	_semBufferEmpty = NULL;

	SDL_DestroyMutex(_mutex);
	_mutex = NULL;

	SDL_CloseAudioDevice(_dev);

	emulating = iSave;

	_initialized = false;
}
예제 #4
0
static bool initAudio() {
	if (audioDev) {
		SDL_CloseAudioDevice(audioDev);
		audioDev = 0;
	}

	if (audioEnabled) {
		SDL_AudioSpec desired = {}, actual = {};
		// We want 48 KHz stereo f32 to match opusfile output
		desired.freq = 48000;
		desired.channels = 2;
		desired.format = AUDIO_F32;
		desired.samples = 4096; // TODO: user-configurable buffer size?
		desired.callback = audioCallback;

		audioDev = SDL_OpenAudioDevice(NULL, 0, &desired, &actual, 0);
		if (!audioDev) {
			narf::console->println("Could not open default audio device: " + std::string(SDL_GetError()));
			audioEnabled = false;
			return false;
		}

		SDL_PauseAudioDevice(audioDev, 0);

		narf::console->println("Audio initialized: " + std::to_string(actual.freq) + " Hz, " + std::to_string(actual.channels) + " channels");
	}

	return true;
}
예제 #5
0
void Mixer::Close()
{
	Lock();
	while (channels.begin() != channels.end()) {
		delete *(channels.begin());
		channels.erase(channels.begin());
	}
	Unlock();
	SDL_CloseAudioDevice(deviceid);
	for (size_t i = 0; i < Util::CountOf(css1sources); i++) {
		if (css1sources[i] && css1sources[i] != &source_null) {
			delete css1sources[i];
			css1sources[i] = 0;
		}
	}
	for (size_t i = 0; i < Util::CountOf(musicsources); i++) {
		if (musicsources[i] && musicsources[i] != &source_null) {
			delete musicsources[i];
			musicsources[i] = 0;
		}
	}
	if (effectbuffer) {
		delete[] effectbuffer;
		effectbuffer = 0;
	}
}
예제 #6
0
static void
iteration()
{
    SDL_Event e;
    SDL_AudioDeviceID dev;
    while (SDL_PollEvent(&e)) {
        if (e.type == SDL_QUIT) {
            done = 1;
        } else if (e.type == SDL_AUDIODEVICEADDED) {
            const char *name = SDL_GetAudioDeviceName(e.adevice.which, 0);
            SDL_Log("New %s audio device: %s\n", e.adevice.iscapture ? "capture" : "output", name);
            if (!e.adevice.iscapture) {
                positions[posindex] = 0;
                spec.userdata = &positions[posindex++];
                spec.callback = fillerup;
                dev = SDL_OpenAudioDevice(name, 0, &spec, NULL, 0);
                if (!dev) {
                    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError());
                } else {
                    SDL_Log("Opened '%s' as %u\n", name, (unsigned int) dev);
                    SDL_PauseAudioDevice(dev, 0);
                }
            }
        } else if (e.type == SDL_AUDIODEVICEREMOVED) {
            dev = (SDL_AudioDeviceID) e.adevice.which;
            SDL_Log("%s device %u removed.\n", e.adevice.iscapture ? "capture" : "output", (unsigned int) dev);
            SDL_CloseAudioDevice(dev);
        }
    }
}
예제 #7
0
/* Close the mixer, halting all playing audio */
void Mix_CloseAudio(void)
{
    int i;

    if ( audio_opened ) {
        if ( audio_opened == 1 ) {
            for (i = 0; i < num_channels; i++) {
                Mix_UnregisterAllEffects(i);
            }
            Mix_UnregisterAllEffects(MIX_CHANNEL_POST);
            close_music();
            Mix_HaltChannel(-1);
            _Mix_DeinitEffects();
            SDL_CloseAudioDevice(audio_device);
            audio_device = 0;
            SDL_free(mix_channel);
            mix_channel = NULL;

            /* rcg06042009 report available decoders at runtime. */
            SDL_free((void *)chunk_decoders);
            chunk_decoders = NULL;
            num_decoders = 0;
        }
        --audio_opened;
    }
}
예제 #8
0
SdlAudioSink::~SdlAudioSink()
{
	if (this->device == 0) return;

	// Silence any currently playing audio.
	SDL_PauseAudioDevice(this->device, SDL_TRUE);
	SDL_CloseAudioDevice(this->device);
}
예제 #9
0
static void close_sdl() {
    SDL_DestroyTexture(texture);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_CloseAudioDevice(sdlAudioDevice);
    SDL_Quit();
    return;
}
예제 #10
0
SDL2SoundCore::~SDL2SoundCore() {
  // Pause and close the audio device (allowing
  // loaded sounds to be freed)
  if (device != 0) {
    SDL_PauseAudioDevice(device, 1);
    SDL_CloseAudioDevice(device);
  }
}
예제 #11
0
static void S_CaptureDriverShutdown (void *ctx)
{
	SDL_AudioDeviceID inputdevid = (SDL_AudioDeviceID)ctx;

	if (inputdevid) {
		SDL_CloseAudioDevice (inputdevid);
	}
}
예제 #12
0
		void StringSynth::Stop() {
			SDL_PauseAudioDevice(device_ID, 1);
			SDL_CloseAudioDevice(device_ID);
			stopped = true;
			paused = false;
			time_elapsed = -1.0f;
			distance_struck = 0.0f;
			initial_offset = 0.0f;
		}
예제 #13
0
void AUD_FreeWav(AUD_Sound* sound) {
    if (sound) {
        if (sound->buf) {
            SDL_FreeWAV(sound->buf);
        }
        SDL_CloseAudioDevice(sound->dev);
        free(sound);
    }
}
예제 #14
0
int main(int argc, char** argv) {
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
        SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
        return 1;
    }

    SDL_Window* win = SDL_CreateWindow("Bytebeat Visualizer", 0, 0, 800, 600, 0);
    SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);

    SDL_AudioSpec want, have;
    SDL_AudioDeviceID dev;
    SDL_zero(want); SDL_zero(have);
    want.freq = 8000;
    want.format = AUDIO_U8;
    want.channels = 1;
    want.samples = 4096;
    want.callback = audio_callback;
    // save the current time
    want.userdata = malloc(sizeof(unsigned int));
    memset(want.userdata, 0, sizeof(unsigned int));
    // and save the pointer for further use
    unsigned int* t = want.userdata;
    dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);

    SDL_PauseAudioDevice(dev, 0);
    int running = 1;
    while (running) {
        SDL_Event e;
        while (SDL_PollEvent(&e)) {
            switch (e.type) {
                case SDL_QUIT:
                running = 0;
                break;
            }
        }

        SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
        SDL_RenderClear(ren);
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
        unsigned int i = (*t);
        i -= 8000;
        for (; i < *t; i++) {
            int x = 0;
            int sample_width = 1;
            SDL_RenderDrawLine(ren, x, 0, x + sample_width, 200);
            x++;
        }
        SDL_RenderPresent(ren);
    }

    SDL_CloseAudioDevice(dev);
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
    SDL_Quit();
    return 0;
}
예제 #15
0
/**
 * \brief Locks and unlocks open audio device.
 *
 * \sa https://wiki.libsdl.org/SDL_LockAudioDevice
 * \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice
 */
int audio_lockUnlockOpenAudioDevice()
{
   int i;
   int count;
   char *device;
   SDL_AudioDeviceID id;
   SDL_AudioSpec desired, obtained;

   /* Get number of devices. */
   count = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   if (count > 0) {
     for (i = 0; i < count; i++) {
       /* Get device name */
       device = (char *)SDL_GetAudioDeviceName(i, 0);
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
       if (device == NULL) return TEST_ABORTED;

       /* Set standard desired spec */
       desired.freq=22050;
       desired.format=AUDIO_S16SYS;
       desired.channels=2;
       desired.samples=4096;
       desired.callback=_audio_testCallback;
       desired.userdata=NULL;

       /* Open device */
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
       if (id > 1) {
         /* Lock to protect callback */
         SDL_LockAudioDevice(id);
         SDLTest_AssertPass("SDL_LockAudioDevice(%i)", id);

         /* Simulate callback processing */
         SDL_Delay(10);
         SDLTest_Log("Simulate callback processing - delay");

         /* Unlock again */
         SDL_UnlockAudioDevice(id);
         SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);

         /* Close device again */
         SDL_CloseAudioDevice(id);
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
       }
     }
   } else {
     SDLTest_Log("No devices to test with");
   }

   return TEST_COMPLETED;
}
예제 #16
0
void Mixer::Close()
{
	Lock();
	while (channels.begin() != channels.end()) {
		delete *(channels.begin());
		channels.erase(channels.begin());
	}
	Unlock();
	SDL_CloseAudioDevice(deviceid);
	delete[] effectbuffer;
}
예제 #17
0
파일: snd_sdl.c 프로젝트: PGGB/NullQuake
void SNDDMA_Shutdown(void)
{
    if (shm) {
		SDL_CloseAudioDevice(dev);
		if (shm->buffer) {
			free(shm->buffer);
        }
		shm->buffer = NULL;
		shm = NULL;
	}
}
예제 #18
0
/**
 * \brief Opens, checks current connected status, and closes a device.
 *
 * \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
 */
int audio_openCloseAudioDeviceConnected()
{
   int result = -1;
   int i;
   int count;
   char *device;
   SDL_AudioDeviceID id;
   SDL_AudioSpec desired, obtained;

   /* Get number of devices. */
   count = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   if (count > 0) {
     for (i = 0; i < count; i++) {
       /* Get device name */
       device = (char *)SDL_GetAudioDeviceName(i, 0);
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
       if (device == NULL) return TEST_ABORTED;

       /* Set standard desired spec */
       desired.freq=22050;
       desired.format=AUDIO_S16SYS;
       desired.channels=2;
       desired.samples=4096;
       desired.callback=_audio_testCallback;
       desired.userdata=NULL;

       /* Open device */
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
       if (id > 1) {

/* TODO: enable test code when function is available in SDL2 */

#ifdef AUDIODEVICECONNECTED_DEFINED
         /* Get connected status */
         result = SDL_AudioDeviceConnected(id);
         SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
#endif
         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);

         /* Close device again */
         SDL_CloseAudioDevice(id);
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
       }
     }
   } else {
     SDLTest_Log("No devices to test with");
   }

   return TEST_COMPLETED;
}
예제 #19
0
파일: snd_sdl.c 프로젝트: bstreiff/quake2
/*
==============
SNDDMA_Shutdown

Reset the sound device for exiting
===============
*/
void SNDDMA_Shutdown(void)
{
	Com_DPrintf("Shutting down sound system\n");

	if (audio_device)
	{
		SDL_CloseAudioDevice(audio_device);
	}

	snd_init = false;
}
예제 #20
0
static void
test_multi_audio()
{
    int keep_going = 1;
    int i;

    if (devcount > 64) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
                devcount);
        devcount = 64;
    }

    spec.callback = play_through_once;

    SDL_memset(cbd, '\0', sizeof(cbd));
    SDL_Log("playing on all devices...\n");
    for (i = 0; i < devcount; i++) {
        const char *devname = SDL_GetAudioDeviceName(i, 0);
        spec.userdata = &cbd[i];
        cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
        if (cbd[i].dev == 0) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError());
        }
    }

    for (i = 0; i < devcount; i++) {
        if (cbd[i].dev) {
            SDL_PauseAudioDevice(cbd[i].dev, 0);
        }
    }

#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop(loop, 0, 1);
#else
    while (keep_going) {
        keep_going = 0;
        for (i = 0; i < devcount; i++) {
            if ((cbd[i].dev) && (!cbd[i].done)) {
                keep_going = 1;
            }
        }
        SDL_Delay(100);
    }
#endif
    for (i = 0; i < devcount; i++) {
        if (cbd[i].dev) {
            SDL_PauseAudioDevice(cbd[i].dev, 1);
            SDL_CloseAudioDevice(cbd[i].dev);
        }
    }

    SDL_Log("All done!\n");
}
예제 #21
0
void deinit_sdl() {
	SDL_DestroyRenderer(renderer); // Also destroys the texture
	SDL_DestroyWindow(screen);

	SDL_DestroyMutex(event_lock);

	SDL_DestroyMutex(frame_lock);
	SDL_DestroyCond(frame_available_cond);

	SDL_CloseAudioDevice(audio_device_id); // Prolly not needed, but play it safe
	SDL_Quit();
}
예제 #22
0
파일: sdl-audio.c 프로젝트: joolswills/mgba
bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContext) {
	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
		GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system: %s", SDL_GetError());
		return false;
	}

	context->desiredSpec.freq = 44100;
	context->desiredSpec.format = AUDIO_S16SYS;
	context->desiredSpec.channels = 2;
	context->desiredSpec.samples = context->samples;
	context->desiredSpec.callback = _GBASDLAudioCallback;
	context->desiredSpec.userdata = context;
#if RESAMPLE_LIBRARY == RESAMPLE_NN
	context->drift = 0.f;
#endif

#if SDL_VERSION_ATLEAST(2, 0, 0)
	context->deviceId = SDL_OpenAudioDevice(0, 0, &context->desiredSpec, &context->obtainedSpec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
	if (context->deviceId == 0) {
#else
	if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) {
#endif
		GBALog(0, GBA_LOG_ERROR, "Could not open SDL sound system");
		return false;
	}
	context->thread = threadContext;
	context->samples = context->obtainedSpec.samples;
	float ratio = GBAAudioCalculateRatio(0x8000, threadContext->fpsTarget, 44100);
	threadContext->audioBuffers = context->samples / ratio;
	if (context->samples > threadContext->audioBuffers) {
		threadContext->audioBuffers = context->samples * 2;
	}

#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_PauseAudioDevice(context->deviceId, 0);
#else
	SDL_PauseAudio(0);
#endif
	return true;
}

void GBASDLDeinitAudio(struct GBASDLAudio* context) {
	UNUSED(context);
#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_PauseAudioDevice(context->deviceId, 1);
	SDL_CloseAudioDevice(context->deviceId);
#else
	SDL_PauseAudio(1);
	SDL_CloseAudio();
#endif
	SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
예제 #23
0
/**
 * \brief Opens, checks current audio status, and closes a device.
 *
 * \sa https://wiki.libsdl.org/SDL_GetAudioStatus
 */
int audio_openCloseAndGetAudioStatus()
{
   SDL_AudioStatus result;
   int i;
   int count;
   char *device;
   SDL_AudioDeviceID id;
   SDL_AudioSpec desired, obtained;

   /* Get number of devices. */
   count = SDL_GetNumAudioDevices(0);
   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
   if (count > 0) {
     for (i = 0; i < count; i++) {
       /* Get device name */
       device = (char *)SDL_GetAudioDeviceName(i, 0);
       SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
       SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
       if (device == NULL) return TEST_ABORTED;

       /* Set standard desired spec */
       desired.freq=22050;
       desired.format=AUDIO_S16SYS;
       desired.channels=2;
       desired.samples=4096;
       desired.callback=_audio_testCallback;
       desired.userdata=NULL;

       /* Open device */
       id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
       SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
       if (id > 1) {

         /* Check device audio status */
         result = SDL_GetAudioDeviceStatus(id);
         SDLTest_AssertPass("Call to SDL_GetAudioDeviceStatus()");
         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);

         /* Close device again */
         SDL_CloseAudioDevice(id);
         SDLTest_AssertPass("Call to SDL_CloseAudioDevice()");
       }
     }
   } else {
     SDLTest_Log("No devices to test with");
   }

   return TEST_COMPLETED;
}
예제 #24
0
파일: audio.cpp 프로젝트: TaylanUB/nestopia
void audio_deinit() {
	// Deinitialize audio
	
	if (conf.audio_api == 0) { // SDL
		SDL_CloseAudioDevice(dev);
	}
#ifndef _MINGW
	else if (conf.audio_api == 1) { // libao
		ao_close(aodevice);
		ao_shutdown();
	}
#endif
}
예제 #25
0
void
loop()
{
    if(cbd[0].done) {
#ifdef __EMSCRIPTEN__
        emscripten_cancel_main_loop();
#endif
        SDL_PauseAudioDevice(cbd[0].dev, 1);
        SDL_CloseAudioDevice(cbd[0].dev);
        SDL_FreeWAV(sound);
        SDL_Quit();
    }
}
예제 #26
0
파일: APU.cpp 프로젝트: 123vipulj/GameLad
APU::~APU()
{
    for (int index = CHANNEL1; index <= CHANNEL4; index++)
    {
        if (m_Initialized[index])
        {
            SDL_PauseAudioDevice(m_DeviceChannel[index], 1);
            SDL_CloseAudioDevice(m_DeviceChannel[index]);
        }
    }

    SDL_Quit();
}
예제 #27
0
void
loop()
{
    for (int i = 0; i < devcount; i++) {
      if ((!cbd[i].dev) || (cbd[i].done)) {
        emscripten_cancel_main_loop();
        SDL_PauseAudioDevice(cbd[0].dev, 1);
        SDL_CloseAudioDevice(cbd[0].dev);
        SDL_FreeWAV(sound);
        SDL_Quit();
      }
    }
}
예제 #28
0
파일: audio.cpp 프로젝트: djyt/cannonball
void Audio::stop_audio()
{
    if (sound_enabled)
    {
        sound_enabled = false;

        SDL_PauseAudioDevice(dev,1);
        SDL_CloseAudioDevice(dev);

        delete[] dsp_buffer;
        delete[] mix_buffer;
    }
}
예제 #29
0
파일: snd_sdl.c 프로젝트: PGGB/NullQuake
qboolean SNDDMA_Init(void)
{
	SDL_AudioSpec desired, obtained;
    SDL_zero(desired);

    desired.freq        = 11025;
    desired.format      = loadas8bit.value ? AUDIO_U8 : AUDIO_S16SYS;
    desired.channels    = 2;
    desired.samples     = 512;
    desired.callback    = audioCallback;

    dev = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
    if (dev == 0) {
        Con_Printf("SDL_OpenAudioDevice error: %s\n", SDL_GetError());
        return false;
    }

	shm = &sn;

    // SDL_AudioFormat layout
    //    +----------------------sample is signed if set
    //    |
    //    |        +----------sample is bigendian if set
    //    |        |
    //    |        |           +--sample is float if set
    //    |        |           |
    //    |        |           |  +--sample bit size---+
    //    |        |           |  |                    |
    //   15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
    shm->samplebits         = obtained.format & 0xFF;
    shm->speed              = obtained.freq;
    shm->channels           = obtained.channels;
    shm->samples            = obtained.samples * obtained.channels * 8;
    shm->submission_chunk   = 1;
    shm->samplepos          = 0;

	bufferSize = shm->samples * (shm->samplebits / 8);

	shm->buffer = (unsigned char *) calloc(1, bufferSize);
	if (shm->buffer == NULL) {
        Con_Printf("Couldn't allocate sound buffer\n");
		SDL_CloseAudioDevice(dev);
		shm = NULL;
		return false;
	}
    
	SDL_PauseAudioDevice(dev, 0);
    
	return true;
}
예제 #30
0
void snd_CleanUp( )
{
	snd_StopStreamingAllBut( -1 );
	if( workingBuffer != NULL ) {
		SDL_LockAudioDevice( devID ); {
			sb_Release( sbStreamWorkingBuffer );
			mem_Release( workingBuffer );
			workingBuffer = NULL;
		} SDL_UnlockAudioDevice( devID );
	}

	if( devID == 0 ) return;
	SDL_CloseAudioDevice( devID );
}