当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_PauseAudioDevice函数代码示例

本文整理汇总了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");
}
开发者ID:BitPuffin,项目名称:NeoEditor,代码行数:53,代码来源:testmultiaudio2.c

示例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);
}
开发者ID:joolswills,项目名称:mgba,代码行数:52,代码来源:sdl-audio.c

示例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);
		}
	}
}
开发者ID:bstreiff,项目名称:quake2,代码行数:23,代码来源:snd_sdl.c

示例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);
}
开发者ID:leiradel,项目名称:mgba,代码行数:49,代码来源:sdl-audio.c

示例5: audio_pause

void audio_pause() {
	// Pause the SDL audio device
	if (conf.audio_api == 0) { // SDL
		SDL_PauseAudioDevice(dev, 1);
	}
	paused = true;
}
开发者ID:TaylanUB,项目名称:nestopia,代码行数:7,代码来源:audio.cpp

示例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);
    }
}
开发者ID:OrangeKnife,项目名称:lobster,代码行数:35,代码来源:sdlaudiosfxr.cpp

示例7: SDL_PauseAudioDevice

void SoundSDL::resume()
{
	if (!_initialized)
		return;

	SDL_PauseAudioDevice(_dev, 0);
}
开发者ID:ElementW,项目名称:visualboyadvance-m,代码行数:7,代码来源:SoundSDL.cpp

示例8: audio_unpause

void audio_unpause() {
	// Unpause the SDL audio device
	if (conf.audio_api == 0) { // SDL
		SDL_PauseAudioDevice(dev, 0);
	}
	paused = false;
}
开发者ID:TaylanUB,项目名称:nestopia,代码行数:7,代码来源:audio.cpp

示例9: SDL_PauseAudioDevice

void SdlAudioSink::Stop()
{
	if (this->state == Audio::State::STOPPED) return;

	SDL_PauseAudioDevice(this->device, 1);
	this->state = Audio::State::STOPPED;
}
开发者ID:UniversityRadioYork,项目名称:ury-playd,代码行数:7,代码来源:audio_sink.cpp

示例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);
}
开发者ID:1337Noob1337,项目名称:OpenRCT2,代码行数:29,代码来源:mixer.cpp

示例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);
        }
    }
}
开发者ID:03050903,项目名称:Torque3D,代码行数:30,代码来源:testaudiohotplug.c

示例12: SDL_PauseAudioDevice

void Audio::pause_audio()
{
    if (sound_enabled)
    {
        SDL_PauseAudioDevice(dev,1);
    }
}
开发者ID:djyt,项目名称:cannonball,代码行数:7,代码来源:audio.cpp

示例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;
}
开发者ID:weinkym,项目名称:src_miao,代码行数:34,代码来源:zwvideothread.cpp

示例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);
}
开发者ID:Kloen,项目名称:citra,代码行数:30,代码来源:sdl2_sink.cpp

示例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);
  }
}
开发者ID:suppertails66,项目名称:luncheon,代码行数:8,代码来源:SDL2SoundCore.cpp


注:本文中的SDL_PauseAudioDevice函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。