本文整理汇总了C++中SDL_PauseAudioDevice函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_PauseAudioDevice函数的具体用法?C++ SDL_PauseAudioDevice怎么用?C++ SDL_PauseAudioDevice使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_PauseAudioDevice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_multi_audio
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");
}
示例2: GBASDLInitAudio
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);
}
示例3: S_Activate
/*
===========
S_Activate
Called when the main window gains or loses focus.
The window have been destroyed and recreated
between a deactivate and an activate.
===========
*/
void S_Activate (qboolean active)
{
if (snd_init)
{
if ( active )
{
SDL_PauseAudioDevice(audio_device, 0);
}
else
{
SDL_PauseAudioDevice(audio_device, 1);
}
}
}
示例4: mSDLInitAudio
bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread* threadContext) {
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
mLOG(SDL_AUDIO, ERROR, "Could not initialize SDL sound system: %s", SDL_GetError());
return false;
}
context->desiredSpec.freq = context->sampleRate;
context->desiredSpec.format = AUDIO_S16SYS;
context->desiredSpec.channels = 2;
context->desiredSpec.samples = context->samples;
context->desiredSpec.callback = _mSDLAudioCallback;
context->desiredSpec.userdata = context;
#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
mLOG(SDL_AUDIO, ERROR, "Could not open SDL sound system");
return false;
}
context->core = 0;
if (threadContext) {
context->core = threadContext->core;
context->sync = &threadContext->impl->sync;
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_PauseAudioDevice(context->deviceId, 0);
#else
SDL_PauseAudio(0);
#endif
}
return true;
}
void mSDLDeinitAudio(struct mSDLAudio* 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);
}
示例5: audio_pause
void audio_pause() {
// Pause the SDL audio device
if (conf.audio_api == 0) { // SDL
SDL_PauseAudioDevice(dev, 1);
}
paused = true;
}
示例6: SDLAudioCallback
static void SDLAudioCallback(void * /*userdata*/, Uint8 *stream, int len)
{
if (playing_sample)
{
if (cursnd.sfxr)
{
uint l = len/2;
float *fbuf = new float[l];
memset(fbuf, 0, sizeof(float)*l);
SynthSample(l, fbuf, nullptr);
while (l--)
{
float f = fbuf[l];
if (f < -1.0) f = -1.0;
if (f > 1.0) f = 1.0;
((Sint16*)stream)[l] = (Sint16)(f * 32767);
}
delete[] fbuf;
}
else
{
size_t amount = min((size_t)len, cursnd.len - (cursndpos - cursnd.buf));
memcpy(stream, cursndpos, amount);
memset(stream + amount, 0, len - amount);
cursndpos += amount;
if (cursndpos == cursnd.buf + cursnd.len)
playing_sample = false;
}
}
else
{
memset(stream, 0, len);
SDL_PauseAudioDevice(audioid, 1);
}
}
示例7: SDL_PauseAudioDevice
void SoundSDL::resume()
{
if (!_initialized)
return;
SDL_PauseAudioDevice(_dev, 0);
}
示例8: audio_unpause
void audio_unpause() {
// Unpause the SDL audio device
if (conf.audio_api == 0) { // SDL
SDL_PauseAudioDevice(dev, 0);
}
paused = false;
}
示例9: SDL_PauseAudioDevice
void SdlAudioSink::Stop()
{
if (this->state == Audio::State::STOPPED) return;
SDL_PauseAudioDevice(this->device, 1);
this->state = Audio::State::STOPPED;
}
示例10: Close
void Mixer::Init(const char* device)
{
Close();
SDL_AudioSpec want, have;
SDL_zero(want);
want.freq = 44100;
want.format = AUDIO_S16SYS;
want.channels = 2;
want.samples = 1024;
want.callback = Callback;
want.userdata = this;
deviceid = SDL_OpenAudioDevice(device, 0, &want, &have, 0);
format.format = have.format;
format.channels = have.channels;
format.freq = have.freq;
const char* filename = get_file_path(PATH_ID_CSS1);
for (size_t i = 0; i < Util::CountOf(css1sources); i++) {
Source_Sample* source_sample = new Source_Sample;
if (source_sample->LoadCSS1(filename, i)) {
source_sample->Convert(format); // convert to audio output format, saves some cpu usage but requires a bit more memory, optional
css1sources[i] = source_sample;
} else {
css1sources[i] = &source_null;
delete source_sample;
}
}
effectbuffer = new uint8[(have.samples * format.BytesPerSample() * format.channels)];
SDL_PauseAudioDevice(deviceid, 0);
}
示例11: iteration
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);
}
}
}
示例12: SDL_PauseAudioDevice
void Audio::pause_audio()
{
if (sound_enabled)
{
SDL_PauseAudioDevice(dev,1);
}
}
示例13: sig_StateChanged
bool ZWVideoThread::stop(bool isWait)
{
if (mPlayerState == Stop)
{
return false;
}
mVideoState.quit = 1;
mPlayerState = Stop;
emit sig_StateChanged(Stop);
if (isWait)
{
while(!mVideoState.readThreadFinished || !mVideoState.videoThreadFinished)
{
SDL_Delay(10);
}
}
///关闭SDL音频播放设备
if (mVideoState.audioID != 0)
{
SDL_LockAudio();
SDL_PauseAudioDevice(mVideoState.audioID,1);
SDL_UnlockAudio();
mVideoState.audioID = 0;
}
return true;
}
示例14: impl
SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
LOG_CRITICAL(Audio_Sink, "SDL_Init(SDL_INIT_AUDIO) failed");
impl->audio_device_id = 0;
return;
}
SDL_AudioSpec desired_audiospec;
SDL_zero(desired_audiospec);
desired_audiospec.format = AUDIO_S16;
desired_audiospec.channels = 2;
desired_audiospec.freq = native_sample_rate;
desired_audiospec.samples = 1024;
desired_audiospec.userdata = impl.get();
desired_audiospec.callback = &Impl::Callback;
SDL_AudioSpec obtained_audiospec;
SDL_zero(obtained_audiospec);
impl->audio_device_id = SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, 0);
if (impl->audio_device_id <= 0) {
LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed");
return;
}
impl->sample_rate = obtained_audiospec.freq;
// SDL2 audio devices start out paused, unpause it:
SDL_PauseAudioDevice(impl->audio_device_id, 0);
}
示例15: SDL_PauseAudioDevice
SDL2SoundCore::~SDL2SoundCore() {
// Pause and close the audio device (allowing
// loaded sounds to be freed)
if (device != 0) {
SDL_PauseAudioDevice(device, 1);
SDL_CloseAudioDevice(device);
}
}