本文整理汇总了C++中Mix_QuerySpec函数的典型用法代码示例。如果您正苦于以下问题:C++ Mix_QuerySpec函数的具体用法?C++ Mix_QuerySpec怎么用?C++ Mix_QuerySpec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Mix_QuerySpec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
/**\brief Audio system shutdown.
*/
bool Audio::Shutdown( void ){
/* This is the cleaning up part */
this->HaltAll();
#if defined(SDL_MIXER_MAJOR_VERSION) && (SDL_MIXER_MAJOR_VERSION>1) \
&& (SDL_MIXER_MINOR_VERSON>2) && (SDL_MIXER_PATCHLEVEL>=10)
// Free every library loaded
const SDL_version *mix_version=Mix_Linked_Version();
if( (mix_version->major>=1) && (mix_version->minor>=2) && (mix_version->patch>=10) ){
while(Mix_Init(0))
Mix_Quit();
}
#endif // SDL_Mixer version requirements
// Query number of times audio device was opened (should be 1)
int freq, chan, ntimes;
Uint16 format;
if ( (ntimes = Mix_QuerySpec( &freq, &format, &chan )) != 1 )
LogMsg(WARN,"Audio was initialized multiple times.");
// Close as many times as opened.
for ( int i = 0; i < ntimes; i++ )
Mix_CloseAudio();
return true;
}
示例2: Audio
AudioSDLMixer::AudioSDLMixer(AudioConfig &sc)
: Audio(sc), audio_open(0), music(NULL), oldPlaying(false)
{
if ( SDL_InitSubSystem(SDL_INIT_AUDIO) < 0 )
throw std::runtime_error(std::string("Couldn't initialize SDL: ")+SDL_GetError());
/* Open the audio device */
int audio_rate = m_sc.srate;
Uint16 audio_format=AUDIO_S8;
if (m_sc.sbits==16)
audio_format=AUDIO_S16;
int audio_channels=1;
if (m_sc.stereo) audio_channels=2;
int audio_buffers = m_sc.sbuffers;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
throw std::runtime_error(std::string("Couldn't open audio: ")+SDL_GetError());
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
/* printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
(audio_format&0xFF),
(audio_channels > 1) ? "stereo" : "mono",
audio_buffers ); */
}
audio_open = 1;
/* Set the external music player, if any */
// TODO: perhaps we should not use this for security reasons
Mix_SetMusicCMD(getenv("MUSIC_CMD"));
}
示例3: sound_mix_load
/**
* @brief Loads a sound into the sound_list.
*
* @param filename Name fo the file to load.
* @return The SDL_Mixer of the loaded chunk.
*
* @sa sound_makeList
*/
int sound_mix_load( alSound *s, const char *filename )
{
SDL_RWops *rw;
int freq, bytes, channels;
Uint16 format;
/* get the file data buffer from packfile */
rw = ndata_rwops( filename );
/* bind to buffer */
s->u.mix.buf = Mix_LoadWAV_RW(rw,1);
if (s->u.mix.buf == NULL) {
DEBUG("Unable to load sound '%s': %s", filename, Mix_GetError());
return -1;
}
/* Get spec. */
Mix_QuerySpec( &freq, &format, &channels );
switch (format) {
case AUDIO_U8:
case AUDIO_S8:
bytes = 1;
break;
default:
bytes = 2;
break;
}
/* Set length. */
s->length = (double)s->u.mix.buf->alen / (double)(freq*bytes*channels);
return 0;
}
示例4: print_MixerVersion
/**
* @brief Prints the current and compiled SDL_Mixer versions.
*/
static void print_MixerVersion (void)
{
int frequency;
Uint16 format;
int channels;
SDL_version compiled;
const SDL_version *linked;
char device[PATH_MAX];
/* Query stuff. */
Mix_QuerySpec(&frequency, &format, &channels);
MIX_VERSION(&compiled);
linked = Mix_Linked_Version();
SDL_AudioDriverName(device, PATH_MAX);
/* Version itself. */
DEBUG("SDL_Mixer Started: %d Hz %s", frequency,
(channels == 2) ? "Stereo" : "Mono" );
/* Check if major/minor version differ. */
if ((linked->major*100 + linked->minor) > compiled.major*100 + compiled.minor)
WARN("SDL_Mixer is newer than compiled version");
if ((linked->major*100 + linked->minor) < compiled.major*100 + compiled.minor)
WARN("SDL_Mixer is older than compiled version.");
/* Print other debug info. */
DEBUG("Renderer: %s",device);
DEBUG("Version: %d.%d.%d [compiled: %d.%d.%d]",
compiled.major, compiled.minor, compiled.patch,
linked->major, linked->minor, linked->patch);
DEBUG();
}
示例5: initSound
void initSound() {
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
if ( SDL_InitSubSystem(SDL_INIT_AUDIO) < 0 ) {
fprintf(stderr, "Unable to initialize SDL_AUDIO: %s\n", SDL_GetError());
return;
}
audio_rate = 44100;
audio_format = AUDIO_S16;
audio_channels = 1;
audio_buffers = 4096;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
return;
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
}
useAudio = 1;
loadSounds();
}
示例6: SDLIsInitialized
static dboolean SDLIsInitialized(void)
{
int freq, channels;
Uint16 format;
return (!!Mix_QuerySpec(&freq, &format, &channels));
}
示例7: LogMsg
/**\brief Audio system initialization.
*/
bool Audio::Initialize( void ) {
if( initialized ) {
return false;
}
if(OPTION(bool, "options/sound/disable-audio")) {
LogMsg(INFO, "Not initializing audio as it is disabled.");
return true; // audio is disabled
}
if(SDL_Init(SDL_INIT_AUDIO) < 0) {
LogMsg(ERR, "SDL could not initialize audio: %s", SDL_GetError());
return false;
}
if(Mix_OpenAudio(this->audio_rate, this->audio_format, this->audio_channels, this->audio_buffers)) {
LogMsg(ERR, "Audio initialization failed!: %s", Mix_GetError());
return false;
}
Mix_QuerySpec(&this->audio_rate, &this->audio_format, &this->audio_channels);
LogMsg(DEBUG, "SDL_mixer gave us rate %d, format %d, channels %d", this->audio_rate, this->audio_format, this->audio_channels);
// Load MOD and OGG libraries
Mix_Init( MIX_INIT_MOD | MIX_INIT_OGG );
// Allocate channels
Mix_AllocateChannels( this->max_chan);
assert( this->max_chan == static_cast<unsigned int>(this->GetTotalChannels()) );
return true;
}
示例8: Mix_HaltChannel
/**\brief Audio system shutdown.
*/
bool Audio::Shutdown( void ) {
if(OPTION(bool, "options/sound/disable-audio")) {
return true; // audio is disabled
}
/* Halt all currently playing sounds */
Mix_HaltChannel( -1 );
// Free every library loaded
while(Mix_Init(0)) {
Mix_Quit();
}
// Query number of times audio device was opened (should be 1)
int freq, chan, ntimes;
Uint16 format;
ntimes = Mix_QuerySpec( &freq, &format, &chan );
LogMsg(DEBUG, "Audio Query: %d Frequencies, Format: %d, Channels: %s.", freq, format, (chan==2?"Stereo":"Mono"));
if(ntimes != 1 ) {
LogMsg(WARN, "Audio was initialized %d times.", ntimes);
}
// Close only if open
if( ntimes ) {
Mix_CloseAudio();
}
return true;
}
示例9: start_sound_engine
static bool start_sound_engine()
{
/* This is where we open up our audio device. Mix_OpenAudio takes
as its parameters the audio format we'd /like/ to have. */
if(Mix_OpenAudio(info.rate, info.format, info.channels, info.buffers))
{
GB.Error("Unable to open audio");
return TRUE;
}
if (pipe(_ch_pipe))
{
GB.Error("Unable to initialize channel pipe");
return TRUE;
}
Mix_QuerySpec(&info.rate, &info.format, &info.channels);
//fprintf(stderr, "Mix_QuerySpec: %d %d %d\n", info.rate, info.format, info.channels);
channel_count = Mix_AllocateChannels(-1);
Mix_ChannelFinished(channel_finished);
return FALSE;
}
示例10: Mix_QuerySpec
void SoundManager::ShutdownMix()
{
// for each Mix_OpenAudio call, there must be corresponding Mix_CloseAudio call
int numOpen = Mix_QuerySpec(nullptr, nullptr, nullptr);
for (int i = 0; i < numOpen; ++i)
Mix_CloseAudio();
}
示例11: defined
/**\brief Audio system shutdown.
*/
bool Audio::Shutdown( void ){
/* This is the cleaning up part */
this->HaltAll();
#if defined(SDL_MIXER_MAJOR_VERSION) && (SDL_MIXER_MAJOR_VERSION>1) \
&& (SDL_MIXER_MINOR_VERSON>2) && (SDL_MIXER_PATCHLEVEL>=10)
// Free every library loaded
const SDL_version *mix_version=Mix_Linked_Version();
if( (mix_version->major>=1) && (mix_version->minor>=2) && (mix_version->patch>=10) ){
while(Mix_Init(0))
Mix_Quit();
}
#endif // SDL_Mixer version requirements
// Query number of times audio device was opened (should be 1)
int freq, chan, ntimes;
Uint16 format;
ntimes = Mix_QuerySpec( &freq, &format, &chan );
LogMsg(INFO,"Audio Query: %d Frequencies, Format: %d, Channels: %s.", freq, format, (chan==2?"Stereo":"Mono"));
if(ntimes != 1 ) {
LogMsg(WARN,"Audio was initialized %d times.", ntimes);
}
// Close only if open
if( ntimes ) {
Mix_CloseAudio();
}
return true;
}
示例12: S_Init
/*
* S_Init
*/
void S_Init(void) {
int freq, channels;
unsigned short format;
memset(&s_env, 0, sizeof(s_env));
if (Cvar_GetValue("s_disable")) {
Com_Warn("Sound disabled.\n");
return;
}
Com_Print("Sound initialization...\n");
s_rate = Cvar_Get("s_rate", "44100", CVAR_ARCHIVE | CVAR_S_DEVICE,
"Sound sampling rate in Hz.");
s_reverse = Cvar_Get("s_reverse", "0", CVAR_ARCHIVE,
"Reverse left and right channels.");
s_volume = Cvar_Get("s_volume", "1.0", CVAR_ARCHIVE,
"Global sound volume level.");
Cmd_AddCommand("s_restart", S_Restart_f, "Restart the sound subsystem");
Cmd_AddCommand("s_play", S_Play_f, NULL);
Cmd_AddCommand("s_stop", S_Stop_f, NULL);
Cmd_AddCommand("s_list", S_List_f, NULL);
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
Com_Warn("S_Init: %s.\n", SDL_GetError());
return;
}
} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
Com_Warn("S_Init: %s.\n", SDL_GetError());
return;
}
}
if (Mix_OpenAudio(s_rate->integer, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
Com_Warn("S_Init: %s\n", Mix_GetError());
return;
}
if (Mix_QuerySpec(&freq, &format, &channels) == 0) {
Com_Warn("S_Init: %s\n", Mix_GetError());
return;
}
if (Mix_AllocateChannels(MAX_CHANNELS) != MAX_CHANNELS) {
Com_Warn("S_Init: %s\n", Mix_GetError());
return;
}
Mix_ChannelFinished(S_FreeChannel);
Com_Print("Sound initialized %dKHz %d channels.\n", freq, channels);
s_env.initialized = true;
S_InitMusic();
}
示例13: Mix_OpenAudio
bool AudioDevice::init(Log* _debugLog) {
debugLog = _debugLog;
if (debugLog != NULL) {
debugLog->printf("Initializing audio system with default settings\n");
}
int audioRate = MIX_DEFAULT_FREQUENCY;
uint16 audioFormat = MIX_DEFAULT_FORMAT;
int audioChannels = 2; // stereo
bool ret = Mix_OpenAudio(audioRate, audioFormat, audioChannels, 4096) >= 0;
if (debugLog != NULL) {
if (ret) {
debugLog->println("Audio initalization Ok");
} else {
debugLog->println("Audio initalization FAIL");
debugLog->printf("Couldn't open audio: %s\n", SDL_GetError());
}
}
if (ret) {
Mix_QuerySpec(&audioRate, &audioFormat, &audioChannels);
}
return ret;
}
示例14: close_sound
void close_sound()
{
int numtimesopened, frequency, channels;
Uint16 format;
if (mix_ok) {
stop_bell();
stop_UI_sound();
stop_sound();
sound_cache.clear();
stop_music();
mix_ok = false;
numtimesopened = Mix_QuerySpec(&frequency, &format, &channels);
if(numtimesopened == 0) {
ERR_AUDIO << "Error closing audio device: " << Mix_GetError() << "\n";
}
while (numtimesopened) {
Mix_CloseAudio();
--numtimesopened;
}
}
if (SDL_WasInit(SDL_INIT_AUDIO) != 0) {
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
LOG_AUDIO << "Audio device released.\n";
}
示例15: SDLIsInitialized
static int SDLIsInitialized(void)
{
int freq, channels;
Uint16 format;
return Mix_QuerySpec(&freq, &format, &channels);
}