本文整理汇总了C++中Mix_OpenAudio函数的典型用法代码示例。如果您正苦于以下问题:C++ Mix_OpenAudio函数的具体用法?C++ Mix_OpenAudio怎么用?C++ Mix_OpenAudio使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Mix_OpenAudio函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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());
}
}
示例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");
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
};
示例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;
}
示例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;
}
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}