本文整理汇总了C++中Mix_OpenAudio函数的典型用法代码示例。如果您正苦于以下问题:C++ Mix_OpenAudio函数的具体用法?C++ Mix_OpenAudio怎么用?C++ Mix_OpenAudio使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Mix_OpenAudio函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: SDL_Log
bool Game::Init()
{
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
{
SDL_Log("Failed to initialize SDL.");
return false;
}
// Initialize Renderer
if (!mRenderer.Init(1024, 768))
{
SDL_Log("Failed to initialize renderer.");
return false;
}
// Initialize SDL Mixer
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048))
{
SDL_Log("Failed to Initizlie SDL Mixer");
return false;
}
// Initialize RNG
Random::Init();
// Start frame timer
mTimer.Start();
//Map all actions and inputs
AddInputMappings();
// Run any code at game start
StartGame();
return true;
}
开发者ID:jimmychenn,项目名称:Games,代码行数:37,代码来源:Game.cpp
示例2: music_play
void music_play (const char *file,
const char *alias,
uint32_t rate)
{
int audio_format = MIX_DEFAULT_FORMAT;
int audio_channels = 2;
int audio_buffers = 4096;
if (!music_init_done) {
if (Mix_OpenAudio(rate,
audio_format,
audio_channels,
audio_buffers) != 0) {
MSG_BOX("Mix_OpenAudio fail: %s %s",
Mix_GetError(), SDL_GetError());
SDL_ClearError();
}
music_init_done = true;
}
musicp music = music_load(file, alias);
music_update_volume();
static int sound_loaded;
if (!sound_loaded) {
sound_loaded = true;
sound_load_all();
}
if (Mix_FadeInMusicPos(music->music, -1, 2000, 0) == -1) {
// if (Mix_PlayMusic(music->music, -1) == -1) {
WARN("cannot play music %s: %s", music->tree.key, Mix_GetError());
}
}
开发者ID:goblinhack,项目名称:adventurine,代码行数:37,代码来源:music.c
示例3: printf
SoundManager::SoundManager(){
cout << "Initializing sound Manager\n";
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2,1024)==-1) {
printf("Mix_OpenAudio: %s\n", Mix_GetError());
exit(2);
} else {
cout << "opened audio" << "\n";
cout << "Allocated " << Mix_AllocateChannels(m_totalChannels);
cout << " channels of audio\n";
cout << "opened audio" << endl;
cout << "Allocated " << Mix_AllocateChannels(m_totalChannels)
<< " channels of audio\n";
}
int flags=MIX_INIT_OGG;
int initted = Mix_Init(flags);
if((initted & flags) != flags) {
printf("Mix_Init: Failed to init required ogg and mod support!\n");
printf("Mix_Init: %s\n", Mix_GetError());
// handle error
} else {
cout << "mix init success\n";
}
//Mix_VolumeMusic(100);
Mix_Volume(0, 50);
Mix_Volume(1, 50);
Mix_Volume(2, 50);
m_eventHandler.registerHandler();
m_eventHandler.registerEvent("play_sound");
m_eventHandler.registerEvent("play_song");
m_eventHandler.registerEvent("song_volume");
}
开发者ID:iiechapman,项目名称:Sandman2D,代码行数:37,代码来源:SoundManager.cpp
示例4: Mix_OpenAudio
void Splash::show(void)
{
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
music = Mix_LoadMUS("data/muzika/music.wav");
Mix_PlayMusic(music, -1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glOrtho(0, this->wWidth, 0, this->wHeight, -1, 1);
// Begin render
glColor4ub(255, 255, 255, 255); // White color
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(this->wWidth, 0);
glVertex2f(this->wWidth, this->wHeight);
glVertex2f(0, wHeight);
glEnd();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, this->texture);
glBegin(GL_QUADS);
glTexCoord2d(0, 1); glVertex2f(this->x, this->y);
glTexCoord2d(1, 1); glVertex2f(this->x + this->width, this->y);
glTexCoord2d(1, 0); glVertex2f(this->x + this->width, this->y + this->height);
glTexCoord2d(0, 0); glVertex2f(this->x, this->y + this->height);
glEnd();
glDisable(GL_TEXTURE_2D);
// End render
glPopMatrix();
SDL_GL_SwapBuffers();
SDL_Delay(time);
Mix_FreeMusic(music);
}
开发者ID:zivlakmilos,项目名称:Parmecium,代码行数:37,代码来源:splash.cpp
示例5: main
main(int argc, char *argv[]) {
/* Initialize the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(2);
}
atexit(SDL_Quit);
/* Open the audio device */
if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) {
fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
}
if (loadSounds()) {
while (1) {
playSound();
}
freeSounds();
}
Mix_CloseAudio();
exit(0);
}
开发者ID:MarkMielke,项目名称:netrek-client-cow,代码行数:24,代码来源:sdl_test.c
示例6: init_everything
/*------------------------------------------------------------------------------------------------------------------
-- FUNCTION: init_everything
--
-- DATE: April 15, 2009
--
-- DESIGNER: Alin Albu
--
-- PROGRAMMER: Alin Albu
--
-- INTERFACE: bool init_everything(SDL_Surface* screen)
--
-- RETURNS: true if SDLinitialization succeeds, false otherwise
--
-- NOTES:
-- initialises the libraries, as well as the screen and sets screen size and window caption.
----------------------------------------------------------------------------------------------------------------------*/
bool init_everything(SDL_Surface **screen) {
printf("Init everything Started");
//Initialize all SDL subsystems
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
printf("Init everything Failed\n");
return false;
}
printf("...");
//Set up the screen
*screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF);
//If there was an error in setting up the screen
if (*screen == NULL) {
printf("Init SCREEN Failed\n");
return false;
}
printf("...");
//Initialize SDL_ttf
if (TTF_Init() == -1) {
printf("Init TTF Failed\n");
return false;
}
printf("...");
//Initialize SDL_mixer
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1) {
printf("Init AUDIO Failed\n");
return false;
}
printf("...");
//Set the window caption
SDL_WM_SetCaption("Tux Bomber", NULL);
printf("...");
SDL_ShowCursor(SDL_ENABLE);
//If everything initialized fine
printf("Init everything Done\n");
return true;
}
开发者ID:AshuDassanRepo,项目名称:bcit-courses,代码行数:52,代码来源:Funcs.cpp
示例7: End
bool JukeBox::OpenDevice()
{
if (m_init)
return true;
Config* cfg = Config::GetInstance();
if (!cfg->GetSoundEffects() && !cfg->GetSoundMusic()) {
End();
return false;
}
/* Initialize the SDL library */
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
std::cerr << "* Couldn't initialize SDL: "<< SDL_GetError() << std::endl;
return false;
}
m_init = true;
Uint16 audio_format = MIX_DEFAULT_FORMAT;
int audio_buffer = 1024;
/* Open the audio device */
if (Mix_OpenAudio(cfg->GetSoundFrequency(), audio_format, channels, audio_buffer) < 0) {
std::cerr << "* Couldn't open audio: " << SDL_GetError() << std::endl;
End();
return false;
} else {
int frequency;
Mix_QuerySpec(&frequency, &audio_format, &channels);
std::cout << Format(_("o Opened audio at %d Hz %d bit"),
frequency, (audio_format&0xFF)) << std::endl;
cfg->SetSoundFrequency(frequency);
}
Mix_ChannelFinished(JukeBox::EndChunk);
Mix_HookMusicFinished(JukeBox::EndMusic);
return true;
}
开发者ID:Arnaud474,项目名称:Warmux,代码行数:36,代码来源:jukebox.cpp
示例8: setupResources
//---------------------------------------------------------------------------
bool BaseApplication::setup(void)
{
mRoot = new Ogre::Root(mPluginsCfg);
setupResources();
bool carryOn = configure();
if (!carryOn) return false;
chooseSceneManager();
createCamera();
createViewports();
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Create any resource listeners (for loading screens)
createResourceListener();
// Load resources
loadResources();
// Create the scene
createScene();
createFrameListener();
SDL_Init(SDL_INIT_EVERYTHING);
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);
music = Mix_LoadMUS("game_music.mp3");
Mix_PlayMusic(music,-1);
Mix_Volume(-1, 40);
createGUI();
return true;
};
开发者ID:chjk122,项目名称:cs354R_project2,代码行数:37,代码来源:BaseApplication.cpp
示例9: init
bool init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
return false;
}
//Iniciando SDL_Mixer
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Press an Arrow Key", NULL );
//If everything initialized fine
return true;
}
开发者ID:Turupawn,项目名称:PersonajesYPolimorfismo,代码行数:36,代码来源:RunningJuego.cpp
示例10: SDL_GetError
CSDL2Renderer::CSDL2Renderer() {
if ( SDL_Init( SDL_INIT_EVERYTHING ) != 0 ) {
std::cout << "Something went wrong: " << SDL_GetError() << std::endl;
}
IMG_Init(IMG_INIT_PNG);
mWindow = SDL_CreateWindow( "BlockyFalls",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640,
480,
SDL_WINDOW_SHOWN );
if ( mWindow == nullptr ) {
std::cout << "Could not create a Window.";
std::cout << SDL_GetError() << std::endl;
SDL_Quit();
return;
}
mRenderer = SDL_CreateRenderer( mWindow, -1, 0 );
if ( mRenderer == nullptr ) {
std::cout << "Could not create renderer: ";
std::cout << SDL_GetError() << std::endl;
SDL_Quit();
return;
}
TTF_Init();
if ( Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1 ) {
std::cout << "coudlnt init mixer" << std::endl;
}
}
开发者ID:TheFakeMontyOnTheRun,项目名称:blocky-falls,代码行数:36,代码来源:CSDL2Renderer.cpp
示例11: InitAndQuit
InitAndQuit(bool shadersOn)
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
{
std::ostringstream error;
error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
throw std::runtime_error(error.str());
}
graphics::setupGraphics(shadersOn);
SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
{
SDL_Quit();
std::ostringstream error;
error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
throw std::runtime_error(error.str());
}
std::srand(time(NULL));
Mix_ChannelFinished(doChangedNotes); // set callback function
startTiming();
}
开发者ID:da-woods,项目名称:sousaphone-hero,代码行数:24,代码来源:main.cpp
示例12: showDebugInfo
void Window::initialize()
{
showDebugInfo();
fprintf(stdout, "Initializing SDL system\r\n");
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) != 0)
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
fprintf(stdout, "Initializing font system\r\n");
if(TTF_Init() == -1)
{
fprintf(stderr, "Unable to init SDL_ttf: %s\n", TTF_GetError());
exit(2);
}
fprintf(stdout, "Initializing audio system\r\n");
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0)
{
fprintf(stderr, "Unable to open audio channel: %s\n", Mix_GetError());
exit(3);
}
}
开发者ID:karim090,项目名称:openhelbreath,代码行数:24,代码来源:Window.cpp
示例13: System
Audio::Audio(const std::string& name) : System(name) {
sound_count = 0;
music_count = 0;
if (SDL_Init(SDL_INIT_AUDIO) != 0) {
std::cerr << "ERROR: Failed to initialize SDL AUDIO!" << std::endl;
std::cerr << SDL_GetError() << std::endl;
return;
}
atexit(SDL_Quit);
#define AUDIO_RATE ((int)22050)
#define AUDIO_FORMAT ((unsigned short)AUDIO_S16)
#define AUDIO_CHANNELS ((int)2)
#define AUDIO_BUFFERS ((int)4096)
if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS)) {
std::cerr << "ERROR: Failed to open SDL AUDIO!" << std::endl;
std::cerr << SDL_GetError() << std::endl;
return;
}
}
开发者ID:eddiecorrigall,项目名称:GraphicsEngine,代码行数:24,代码来源:Audio.cpp
示例14: SDL_Init
void SoundManager::sound_init()
{
Larp::CustomConfigurationLoader* config = Larp::CustomConfigurationLoader::load_configurations("sound.cfg");
_music_volume = std::stof(config->get_configuration("music_volume"));
_effect_volume = std::stof(config->get_configuration("sound_volume"));
SDL_Init(SDL_INIT_EVERYTHING);
srand(time(NULL));
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 4096);
/*Load sound effects here */
_background_music = Mix_LoadMUS("assets/sound/Neotantra.mp3");
_sound_effects.emplace("shotgun", Mix_LoadWAV("assets/sound/shotgun.wav"));
_sound_effects.emplace("rocket_fire", Mix_LoadWAV("assets/sound/rocket_fire.wav"));
_sound_effects.emplace("chaingun", Mix_LoadWAV("assets/sound/chaingun.wav"));
_sound_effects.emplace("jump", Mix_LoadWAV("assets/sound/jump.wav"));
_sound_effects.emplace("walk0", Mix_LoadWAV("assets/sound/walking0.wav"));
_sound_effects.emplace("walk1", Mix_LoadWAV("assets/sound/walking1.wav"));
Mix_VolumeMusic(MIX_MAX_VOLUME * _music_volume);
Mix_Volume(-1, MIX_MAX_VOLUME * _effect_volume);
}
开发者ID:phoenixbishea,项目名称:cs354r-final-game-project,代码行数:24,代码来源:SoundManager.cpp
示例15: init
bool init() {
//Init video, audio
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL could not initialize Video or Audio! Error: %s\n", SDL_GetError());
return false;
}
//Init image loader
if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) {
printf("SDL could not initialize Image loader! Error: %s\n", IMG_GetError());
return false;
}
//Init SDL_mixer
if (Mix_OpenAudio(HIGH_FREQUENCY, MIX_DEFAULT_FORMAT, STEREO, CHUNKS) < 0) {
printf("SDL_Mixer could not initialze! Error: %s\n", Mix_GetError());
return false;
}
window = SDL_CreateWindow("Sound effect", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if (window == NULL) {
printf("SDL_Window could not be created! Error: %s\n", SDL_GetError());
return false;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == NULL) {
printf("Renderer could not be created! Error: %s\n", SDL_GetError());
return false;
}
texture = new MyTexture(renderer);
return true;
}
开发者ID:nguyenchiemminhvu,项目名称:OpenGL_Learning,代码行数:36,代码来源:main.cpp
示例16: kernel_Init_Audio
int kernel_Init_Audio(void)
{
if(flag_Check(&kernel_Main.SDL_Init_Flags, SDL_INIT_AUDIO) == 0)
{
file_Log(ker_Log(), 1, "No sound device loaded.\n");
/*Initialise sound manager with it not accepting any sounds*/
sound_Init(0, 0, 0, 0);
return 0;
}
printf("Opening audio device\n\n");
if(Mix_OpenAudio(kernel_Main.sound_Frequency, kernel_Main.sound_Format, kernel_Main.sound_Channels, kernel_Main.sound_Chunksize) == -1)
{
return -1;
}
printf("Initalising sound manager\n");
sound_Init(16, 32, 50, 1);
ker_ReportAudio();
return 0;
}
开发者ID:sigt44,项目名称:ventifact,代码行数:24,代码来源:Kernel.c
示例17: volume
SoundManager::SoundManager() :
volume(SDL_MIX_MAXVOLUME),
currentSound(-1),
music(NULL),
audioBuffers(4096),
sounds(),
channels(),
throwWaitTime(500),
throwLastPlayed(0),
stepWaitTime(500),
stepLastPlayed(0)
{
if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 4, audioBuffers))
{
std::cerr << "audio open" << std::endl;
throw std::string("Unable to open audio");
}
music = Mix_LoadMUS("resources/sounds/freezeezy.wav");
if(!music) {
std::cerr << "freez" << std::endl;
throw std::string(Mix_GetError());
}
startMusic();
Mix_Chunk *check=NULL;
sounds.push_back( check = Mix_LoadWAV("resources/sounds/snowstep.wav"));
if(!check) {
std::cerr << "step" << std::endl;
throw std::string(Mix_GetError());
}
sounds.push_back( check = Mix_LoadWAV("resources/sounds/snowthrow.wav"));
if(!check) {
std::cerr << "throw" << std::endl;
throw std::string(Mix_GetError());
}
for(unsigned int i=0; i< sounds.size(); ++i) channels.push_back(i);
}
开发者ID:Buhndabah,项目名称:ShiverMeTimbers,代码行数:36,代码来源:soundManager.cpp
示例18: Mix_OpenAudio
void Sound::init()
{
// Don't initialize sound engine twice
if (mInstalled)
return;
logger->log("Sound::init() Initializing sound...");
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
{
logger->log("Sound::init() Failed to initialize audio subsystem");
return;
}
const size_t audioBuffer = 4096;
const int res = Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
MIX_DEFAULT_CHANNELS, audioBuffer);
if (res < 0)
{
logger->log("Sound::init Could not initialize audio: %s",
Mix_GetError());
return;
}
Mix_AllocateChannels(16);
Mix_VolumeMusic(mMusicVolume);
Mix_Volume(-1, mSfxVolume);
info();
mInstalled = true;
if (!mCurrentMusicFile.empty())
playMusic(mCurrentMusicFile);
}
开发者ID:Ablu,项目名称:invertika,代码行数:36,代码来源:sound.cpp
示例19: eir_snd_api_init
void eir_snd_api_init()
{
SDL_version compile_version;
const SDL_version * link_version = Mix_Linked_Version();
SDL_MIXER_VERSION(&compile_version);
EIR_KER_LOG_MESSAGE(
"SDL mixer compile vers: %d.%d.%d",
compile_version.major,
compile_version.minor,
compile_version.patch
);
EIR_KER_LOG_MESSAGE(
"SDL mixer link vers: %d.%d.%d",
link_version->major,
link_version->minor,
link_version->patch
);
if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
{
EIR_KER_LOG_ERROR("SDL mixer open audio init failed: %s", Mix_GetError());
}
}
开发者ID:aadarshasubedi,项目名称:Eir,代码行数:24,代码来源:eir_snd_api_func_sdl.c
示例20: MP3_Load
int MP3_Load (const char *name)
{
/* Initialize variables */
audio_rate = 22050;
audio_format = AUDIO_S16;
audio_channels = 2;
audio_buffers = 4096;
/* Open the audio device */
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
return(2);
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
/*printf("Opened audio at %d Hz %d bit %s (%s), %d bytes audio buffer\n", audio_rate,
(audio_format&0xFF),
(audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono",
(audio_format&0x1000) ? "BE" : "LE",
audio_buffers );*/
}
audio_open = 1;
/* Set the music volume */
Mix_VolumeMusic(audio_volume);
/* Set the external music player, if any */
Mix_SetMusicCMD(getenv("MUSIC_CMD"));
music = Mix_LoadMUS(name);
if ( music == NULL ) {
fprintf(stderr, "Couldn't load %s,%s\n",name, SDL_GetError());
CleanUp();
exit(0);
}
return 1;
}
开发者ID:eickegao,项目名称:avgscript,代码行数:36,代码来源:play_mp3_win.cpp
注:本文中的Mix_OpenAudio函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论