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


C++ Mix_GetError函数代码示例

本文整理汇总了C++中Mix_GetError函数的典型用法代码示例。如果您正苦于以下问题:C++ Mix_GetError函数的具体用法?C++ Mix_GetError怎么用?C++ Mix_GetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Mix_GetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

int init()
{
    SDL_DisplayMode mode;

    // Initialize SDL itself
    printf("SDL_Init()\n");
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
    {
        printf("SDL_Init error: %s\n", SDL_GetError());

        return 0;
    }

    // Get the current display mode
    printf("SDL_GetCurrentDisplayMode()\n");
    if(SDL_GetCurrentDisplayMode( 0, &mode ) != 0)
    {
        printf("SDL_GetCurrentDisplayMode error: %s\n", SDL_GetError());

        SDL_Quit();

        return 0;
    }

    rect_screen.w = mode.w;
    rect_screen.h = mode.h;

    //Create a new full-screen window
    printf("SDL_CreateWindow()\n");
    window = SDL_CreateWindow("Multiplatform Base Application",
                              SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              rect_screen.w,
                              rect_screen.h,
                              SDL_WINDOW_SHOWN);
    if(!window)
    {
        printf("SDL_CreateWindow error: %s\n", SDL_GetError());

        SDL_Quit();

        return 0;
    }

    // Create a renderer
    printf("SDL_CreateRenderer()\n");
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if(!renderer)
    {
        printf("SDL_CreateRenderer error: %s\n", SDL_GetError());

        SDL_DestroyWindow(window);
        SDL_Quit();

        return 0;
    }

    // Init audio
    printf("Mix_Init()\n");
    if(Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG)
    {
        printf("Mix_Init error: %s\n", Mix_GetError());

        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();

        return 0;
    }

    // Open audio device
    printf("Mix_OpenAudio()\n");
    if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) != 0)
    {
        printf("Mix_OpenAudio error: %s\n", Mix_GetError());

        Mix_Quit();
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();

        return 0;
    }

    return 1;
}
开发者ID:Sturmflut,项目名称:sdl2-multiplatform-base,代码行数:86,代码来源:main.c

示例2: LibInit

/* should just simplify all this:                                      */
void LibInit(Uint32 lib_flags)
{
  LOG( "LibInit():\n-About to init SDL Library\n" );

  /* Initialize video: */
  if (SDL_Init(SDL_INIT_VIDEO) < 0)
  {
    fprintf(stderr, "Couldn't initialize SDL: %s\n",
    SDL_GetError());
    exit(2);
  }
  /* Initialize audio if desired: */
  if (settings.sys_sound)
  {
    if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
    {
      fprintf(stderr, "Couldn't initialize SDL Sound: %s\n",
              SDL_GetError());
      settings.sys_sound = 0;
    }
    else
      LOG("SDL_InitSubSystem(SDL_INIT_AUDIO) succeeded\n");
  }

// atexit(SDL_Quit); // fire and forget... 

  LOG( "-SDL Library init'd successfully\n" );

  DEBUGCODE
  { fprintf(stderr, "settings.sys_sound = %d\n", settings.sys_sound); }

  /* FIXME should read settings before we do this: */ 
  if (settings.sys_sound) //can be turned off with "--nosound" runtime flag
  {
    int initted = 1;

    /* For SDL_mixer 1.2.10 and later, we must call Mix_Init() before any */
    /* other SDL_mixer functions. We can see what types of audio files    */
    /* are supported at this time (ogg and mod are required):             */

#ifdef HAVE_MIX_INIT
    int flags = MIX_INIT_OGG | MIX_INIT_MP3 | MIX_INIT_MOD | MIX_INIT_FLAC;
    initted = Mix_Init(flags);

    /* Just give warnings if MP3 or FLAC not supported: */
    if((initted & MIX_INIT_MP3) != MIX_INIT_MP3)
      LOG("NOTE - MP3 playback not supported\n");
    if((initted & MIX_INIT_FLAC) != MIX_INIT_FLAC)
      LOG("NOTE - MP3 playback not supported\n");

    /* We must have Ogg and Mod support to have sound: */
    if((initted & (MIX_INIT_OGG | MIX_INIT_MOD)) != (MIX_INIT_OGG | MIX_INIT_MOD))
    {
      fprintf(stderr, "Mix_Init: Failed to init required ogg and mod support!\n");
      fprintf(stderr, "Mix_Init: %s\n", Mix_GetError());
      settings.sys_sound = 0;
      initted = 0;
    }
    else
      LOG("Mix_Init() succeeded\n");
#endif

    DOUT(initted);

    /* If Mix_Init() succeeded (or wasn't required), set audio parameters: */
    if(initted)
    {
      LOG("About to call Mix_OpenAudio():\n");
//    if (Mix_OpenAudio(22050, AUDIO_S16, 1, 2048) == -1)
      if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 1, 2048) ==
		      -1)
      {
        fprintf(stderr, "Warning: Mix_OpenAudio() failed\n - Reasons: %s\n", SDL_GetError());
        settings.sys_sound = 0;
      }
      else
        LOG("Mix_OpenAudio() successful\n");
    }
  }

  LOG( "-about to init SDL text library (SDL_ttf or SDL_Pango\n" );

  if (!Setup_SDL_Text())
  {
    fprintf( stderr, "Couldn't initialize desired SDL text library\n" );
    exit(2);
  }
//	atexit(TTF_Quit);

  LOG( "LibInit():END\n" );
}
开发者ID:EvertonMelo,项目名称:tux4sample,代码行数:92,代码来源:setup.c

示例3: return

/**
 *  Läd ein Musikstück.
 *
 *  @param[in] type Typ der Daten
 *  @param[in] data Datenblock
 *  @param[in] size Größe des Datenblocks
 *
 *  @return Sounddeskriptor bei Erfolg, @p NULL bei Fehler
 *
 *  @author FloSoft
 */
Sound* AudioSDL::LoadMusic(unsigned int data_type, unsigned char* data, unsigned long size)
{
    SoundSDL_Music* sd = new SoundSDL_Music;

    char file[512];
    if (!tempname(file, 512))
        return(NULL);

    switch(data_type)
    {
        default:
            return(NULL);

        case AudioDriver::AD_MIDI:
        {
            strncat(file, ".mid", 512);
        } break;

        case AudioDriver::AD_WAVE:
        {
            strncat(file, ".wav", 512);
        } break;

        case AudioDriver::AD_OTHER:
        {
            const char* header = (const char*)data;
            if(strncmp(header, "OggS", 4) == 0)
                strncat(file, ".ogg", 512);
            else if (strncmp(header, "ID3", 3) == 0 || ((unsigned char)header[0] == 0xFF && (unsigned char)header[1] == 0xFB) )
                strncat(file, ".mp3", 512);
            else
                strncat(file, ".tmp", 512);
        } break;

        /// @todo Alle Formate die SDL mit LoadMUS laden kann angeben
    }

    FILE* dat = fopen(file, "wb");
    if (!dat)
        return(NULL);

    if (fwrite(data, 1, size, dat) != size)
        return(NULL);

    fclose(dat);

    sd->music = Mix_LoadMUS(file);

    unlink(file);

    if(sd->music == NULL)
    {
        fprintf(stderr, "%s\n", Mix_GetError());
        delete sd;
        return(NULL);
    }

    sd->SetNr((int)sounds.size());
    sounds.push_back(sd);

    return sd;
}
开发者ID:lweberk,项目名称:s25client,代码行数:73,代码来源:SDL.cpp

示例4: main


//.........这里部分代码省略.........
		if ( strcmp(argv[i], "-l") == 0 ) {
			loops = -1;
		} else
		if ( strcmp(argv[i], "-8") == 0 ) {
			audio_format = AUDIO_U8;
		} else
		if ( strcmp(argv[i], "-f") == 0 ) { /* rcg06122001 flip stereo */
			reverse_stereo = 1;
		} else
		if ( strcmp(argv[i], "-F") == 0 ) { /* rcg06172001 flip sample */
			reverse_sample = 1;
		} else {
			Usage(argv[0]);
			return(1);
		}
	}
	if ( ! argv[i] ) {
		Usage(argv[0]);
		return(1);
	}

	/* Initialize the SDL library */
	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(255);
	}
	signal(SIGINT, CleanUp);
	signal(SIGTERM, CleanUp);

	/* Open the audio device */
	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
		CleanUp(2);
	} else {
		Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
		printf("Opened audio at %d Hz %d bit %s", audio_rate,
			(audio_format&0xFF),
			(audio_channels > 2) ? "surround" :
			(audio_channels > 1) ? "stereo" : "mono");
		if ( loops ) {
		  printf(" (looping)\n");
		} else {
		  putchar('\n');
		}
	}
	audio_open = 1;

#if (defined TEST_MIX_VERSIONS)
    test_versions();
#endif

	/* Load the requested wave file */
	wave = Mix_LoadWAV(argv[i]);
	if ( wave == NULL ) {
		fprintf(stderr, "Couldn't load %s: %s\n",
						argv[i], SDL_GetError());
		CleanUp(2);
	}

	if (reverse_sample) {
		flip_sample(wave);
	}

#ifdef TEST_MIX_CHANNELFINISHED  /* rcg06072001 */
	Mix_ChannelFinished(channel_complete_callback);
#endif

	if ( (!Mix_SetReverseStereo(MIX_CHANNEL_POST, reverse_stereo)) &&
		 (reverse_stereo) )
	{
		printf("Failed to set up reverse stereo effect!\n");
		printf("Reason: [%s].\n", Mix_GetError());
	}

	/* Play and then exit */
	Mix_PlayChannel(0, wave, loops);

	while (still_playing()) {

#if (defined TEST_MIX_PANNING)  /* rcg06132001 */
		do_panning_update();
#endif

#if (defined TEST_MIX_DISTANCE) /* rcg06192001 */
		do_distance_update();
#endif

#if (defined TEST_MIX_POSITION) /* rcg06202001 */
		do_position_update();
#endif

		SDL_Delay(1);

	} /* while still_playing() loop... */

	CleanUp(0);

	/* Not reached, but fixes compiler warnings */
	return 0;
}
开发者ID:Oibaf66,项目名称:gcSDL,代码行数:101,代码来源:playwave.c

示例5: main

//the massive main function
int main(int argc, char* args[]) // Gets command line input
{
	bool quit = false, playing = true, falling = true, held = false, paused = false, cheating = false; // All our miscellaneous bools to keep track of game states.
	
	int level = 0, lines = 0, score = 0, choice = 0, cheatseq = 0;
	
	Scores scores("gfx"); // Opens the uber camoflaged gfx file for getting highscores. Tricksy, eh?
	
	Uint32 start = 0; // A REALLY big int for keeping track of time
	
	srand(SDL_GetTicks()); // seeding the random... seed
	
	if( init() == false ) // Initialize SDL
	{
		cout << "Init fail" << endl;
		return 1; //ERR !!!!
	}
	
	block = load_image( "blocks.png" ); // load blocks
	
	if(block == NULL) 
	{
		cout << "Error loading blocks.png" << endl;
		return 1; //ERR!
	}
	
	back = load_image( "back.png" ); // load background
	
	if(back == NULL)
	{
		cout << "Error loading back.png" << endl;
		return 1; //ERR!
	}
	
	smallblock = load_image( "smallblocks.png" ); // small blocks for next and hold
	
	if(smallblock == NULL)
	{
		cout << "Error loading smallblocks.png" << endl;
		return 1; //ERR!
	}
	
	title = load_image( "title.png" ); // title
	
	if(title == NULL)
	{
		cout << "Error loading title.png" << endl;
		return 1; //ERR!
	}
	
	cursor = load_image( "cursor.png" ); // cursor in menu
	
	if(cursor == NULL)
	{
		cout << "Error loading cursor.png" << endl;
		return 1; //ERR!
	}
	
	font = TTF_OpenFont("ProggyClean.ttf", FONTSIZE); // our font
	
	if(font == NULL)
	{
		cout << "Error loading ProggyClean.ttf" << endl;
		return 1; //Yup. Didn't load.
	}
	
	effect = Mix_LoadWAV( "pause.wav" ); // dee doo sound
	
	if(effect == NULL)
	{
		cout << "Mix_LoadWAV: " << Mix_GetError() << endl;
	}
	
	while(playing) // while the user hasn't quit
	{
		score = 0;
		quit = false;
		Mix_FadeOutMusic(100); // fades out the music (if playing) for menu.
		
		Mix_FreeMusic(music); // gets rid of any music we might have loaded
		
		if(XM == true) // load title music
		{
			music = Mix_LoadMUS("title.xm");
		}
		else
		{
			music = Mix_LoadMUS("title.mp3");
		}
		
		if(!music)
		{
	   		cout << "Mix_LoadMUS(\"title.mp3\"): %s\n" << Mix_GetError() << endl;
	   		// music didn't load...
		}
		
		Mix_PlayMusic(music, -1); // play it til the user can't stand it no mo'.

		for(int i = 600; i>=100; i--) // slowly bring up the title
//.........这里部分代码省略.........
开发者ID:Acedio,项目名称:graphtet,代码行数:101,代码来源:tet.cpp

示例6: main

int main(int argc, char** argv) {
	srand(1707801);

	Server* server = NULL;
	Client* lan = NULL;
	if (argc > 1) {
		try {
			if (argv[1][0] == 's') {
				server = new Server();
				server->correr();
			}
		} catch ( ConnectionProblem &e ) { return -1; }
	}

	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
		return -1;
	} else if (server == NULL) {
		TTF_Init();

		//Inicializo el Mixer:
		if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
			printf ("Error al inicializar SDL_mixer. Error: %s\n", Mix_GetError());
			SDL_Quit();
			IMG_Quit();
			TTF_Quit();
			return -1;
		}

		EstadoFinVentana estado = OK;
		VentanaEspera *ventanaEspera = NULL;
		ObjetivoEscenario modoDeJuego = MODO_DEFAULT;

		if (argc > 1) {
			try {
				if (argv[1][0] == 'c') {
					//ventanaEspera = new VentanaEspera(std::pair<int,int>(640,800)); // hardcode sabroso
					//estado = ventanaEspera->run();

					lan = new Client();	// Se conecta.
					modoDeJuego = Proxy::clienteEsperarComienzoYModoDeJuego(lan); // Espera comienzo de juego.
				}
			} catch ( ConnectionProblem &e ) { return -1; }
		}

		Controller *controller = new Controller(lan, modoDeJuego);	// Carga el juego (modelo)

		delete ventanaEspera;

		if (estado == OK){

			if (estado == OK){
				VentanaJuego *ventanaJuego = new VentanaJuego(controller);	// Carga y mantiene la vista.
				estado = ventanaJuego->run();
				delete ventanaJuego;
			}

			// Meter una ventana de resultado de la partida (GANADO - PERDIDO)
		}

		delete controller;
		Mix_Quit();
		TTF_Quit();
		IMG_Quit();
		SDL_Quit();
	}
	delete server;
	delete lan;

	return 0;
}
开发者ID:PabloFederico,项目名称:Taller-2015,代码行数:70,代码来源:TP.cpp

示例7: main


//.........这里部分代码省略.........
    if(!blinky){
        printf("Blinky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        exit(EXIT_FAILURE);
    }
    printf("Blinky found !\n");

    Ghost *inky = searchAndCreateGhost(INKY);
    if(!inky){
        printf("Inky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        freeGhost(blinky);
        exit(EXIT_FAILURE);
    }
    printf("Inky found !\n");

    Ghost *pinky = searchAndCreateGhost(PINKY);
    if(!pinky){
        printf("Pinky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        freeGhost(blinky);
        freeGhost(inky);
        exit(EXIT_FAILURE);
    }
    printf("Pinky found !\n");
    printf("SDL initialisation\n");



    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1){
        printf("%s", Mix_GetError());
    }

    Mix_Music *music = NULL;
    music = Mix_LoadMUS("../projec/pacman.wav");
    if(!music){
        printf("Erreur de chargement de la musique %s \n", Mix_GetError());
    }else{
        Mix_VolumeMusic(MIX_MAX_VOLUME);
        Mix_PlayMusic(music, -1);
    }

    if(TTF_Init() == -1){
        printf("Error during TTF initialization : %s\n", TTF_GetError());
    }

    TTF_Font *police = NULL;

    police = TTF_OpenFont("../projec/monof.ttf", 65);
    if(!police){
        printf("Error during font load : %s\n", TTF_GetError());
    }
    SDL_Color color = { 255, 255, 255, 255};



    //Create the window
    window = SDL_CreateWindow("Pacman", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, TILE_SIZE * map->col, TILE_SIZE * map->row + TILE_SIZE, SDL_WINDOW_SHOWN);

    //If there is an error
    if(window == 0){
        printf("Error during window creation : %s \n", SDL_GetError());
        SDL_Quit();
开发者ID:Sehsyha,项目名称:ProjetC,代码行数:67,代码来源:main.c

示例8: Mix_LoadWAV

bool CSoundEffect::Load()
{
    if (m_Chunk != nullptr)
        return false;

    m_Chunk = Mix_LoadWAV(m_Path.c_str());

    if (!m_Chunk)
    {
        CCoreEngine::Instance().GetLogManager().LogOutput(LOG_ERROR, LOGSUB_SOUND, "CSoundEffect::Load Error: %s", Mix_GetError());

        return false;
    }

    return true;
}
开发者ID:roig,项目名称:Endavant,代码行数:16,代码来源:CSoundEffect.cpp

示例9: main

int main(int argc, char *argv[])
{
	//Set the window title
	std::string title = "Sky Zone Omega";

	//Set the window and target resolutions
	C_Vec2 targetRes = C_Vec2(1080, 608);
	C_Vec2 windowRes = C_Vec2(1080, 608);

	//Initialise SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		//Failed initialisation
		C_Utilities::logE("SDL failed to initialise: " + std::string(SDL_GetError()));
		return -1;
	}

	//Initialise SDL_ttf
	if (TTF_Init() < 0)
	{
		//Failed initialisation
		C_Utilities::logE("SDL_ttf failed to initialise: " + std::string(TTF_GetError()));
		return -1;
	}

	//Initialise SDL_mixer
	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
	{
		C_Utilities::logE("SDL_mixer failed to initialise: " + std::string(Mix_GetError()));
		return -1;
	}

	//Time Check
	unsigned int lastTime = SDL_GetTicks();


#if !defined(_DEBUG)

	//Create Window
	C_Vec2 windowPos = C_Vec2(100, 100);
	SDL_Window *window = SDL_CreateWindow(title.c_str(),
		(int)windowPos.x, (int)windowPos.y,
		(int)windowRes.x, (int)windowRes.y,
		SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP);

#else

	//Create Window
	C_Vec2 windowPos = C_Vec2(100, 100);
	SDL_Window *window = SDL_CreateWindow(title.c_str(),
		(int)windowPos.x, (int)windowPos.y,
		(int)windowRes.x, (int)windowRes.y,
		SDL_WINDOW_SHOWN);

#endif	

	//Create Renderer from the window
	SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

	//Set the renderer to work out the render at this resolution and then scale it up the 
	//closest resolution it can to the windows resolution (adds bars of the render colour)
	SDL_RenderSetLogicalSize(renderer, (int)targetRes.x, (int)targetRes.y);

	//The background music
	C_Music* backgroundMusic = new C_Music("Assets/Audio/gameplayLoop.ogg");

	//Setup state manager and initial state
	S_StateManager * stateManager = new S_StateManager();
	stateManager->addState(new S_Splash(stateManager, renderer, targetRes, backgroundMusic));

	//Start Game Loop
	bool go = true;
	while (go)
	{
		//Time Check
		unsigned int current = SDL_GetTicks();
		float deltaTime = (float)(current - lastTime) / 1000.0f;
		lastTime = current;

		//Handle the current state inputs
		go = stateManager->input();

		//Update the current state
		stateManager->update(deltaTime);

		//set draw colour to black
		SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);

		//Clear the entire screen to the set colour
		SDL_RenderClear(renderer);

		//Draw the states
		stateManager->draw();

		//display renderer
		SDL_RenderPresent(renderer);

		//Time Limiter
		if (deltaTime < (1.0f / 50.0f))
		{
//.........这里部分代码省略.........
开发者ID:JSlowgrove,项目名称:Sky-Zone-Omega-PC,代码行数:101,代码来源:main.cpp

示例10: fatalError

	void SoundEffect::play(int loops) {
		const int defaultChannel{ -1 };
		if (Mix_PlayChannel(defaultChannel, m_chunk, loops) == -1) {
			fatalError("Mix_PlayChannel error:" + std::string(Mix_GetError()));
		}
	}
开发者ID:Weenkus,项目名称:GTEngine,代码行数:6,代码来源:AudioEngine.cpp

示例11: Stop

void CSoundEffect::Play()
{
    // If sound is not pre-loaded, Load it
    if (m_Chunk == nullptr)
        if ( !Load() )
            return;

    // Stop sound in case this is playing
    Stop();

    // Play sound in an available channel
    m_Channel = Mix_PlayChannel( -1, m_Chunk, 0 );
    if (m_Channel == -1)
        CCoreEngine::Instance().GetLogManager().LogOutput(LOG_ERROR, LOGSUB_SOUND, "CSoundEffect::Play Mix_PlayChannel: %s", Mix_GetError());

}
开发者ID:roig,项目名称:Endavant,代码行数:16,代码来源:CSoundEffect.cpp

示例12: Mix_HaltMusic

void soundLib::load_boss_music(string music_file) {
	string filename;

	if (boss_music != NULL) {
		Mix_HaltMusic();
		Mix_FreeMusic(boss_music);
        boss_music = NULL;
	}
	filename = FILEPATH + "data/music/" + music_file;
	//std::cout << "soundLib::load_boss_music - filename: " << filename << std::endl;
	boss_music = Mix_LoadMUS(filename.c_str());
	if (!boss_music) {
        std::cout << "Error in soundLib::load_boss_music::Mix_LoadMUS('" << filename << "': '" << Mix_GetError() << "'\n";
        std::fflush(stdout);
		exit(-1);
	}
}
开发者ID:DavidKnight247,项目名称:Rockbot-GCW0-port,代码行数:17,代码来源:soundlib.cpp

示例13: unload_music

void soundLib::load_music(std::string music_file) {
	string filename;

	unload_music();
	filename = FILEPATH + "data/music/" + music_file;
    //std::cout << "soundLib::load_music - filename: " << filename << std::endl;
	music = Mix_LoadMUS(filename.c_str());
	if (!music) {
        std::cout << "Error in soundLib::load_music::Mix_LoadMUS('" << filename << "': '" << Mix_GetError() << "'\n";
        std::fflush(stdout);
		exit(-1);
	}
}
开发者ID:DavidKnight247,项目名称:Rockbot-GCW0-port,代码行数:13,代码来源:soundlib.cpp

示例14: strrchr

/* Load a music file */
Mix_Music *Mix_LoadMUS(const char *file)
{
    SDL_RWops *src;
    Mix_Music *music;
    Mix_MusicType type;
    char *ext = strrchr(file, '.');

#ifdef CMD_MUSIC
    if ( music_cmd ) {
        /* Allocate memory for the music structure */
        music = (Mix_Music *)SDL_malloc(sizeof(Mix_Music));
        if ( music == NULL ) {
            Mix_SetError("Out of memory");
            return(NULL);
        }
        music->error = 0;
        music->type = MUS_CMD;
        music->data.cmd = MusicCMD_LoadSong(music_cmd, file);
        if ( music->data.cmd == NULL ) {
            SDL_free(music);
            music = NULL;
        }
        return music;
    }
#endif

    src = SDL_RWFromFile(file, "rb");
    if ( src == NULL ) {
        Mix_SetError("Couldn't open '%s'", file);
        return NULL;
    }

    /* Use the extension as a first guess on the file type */
    type = MUS_NONE;
    ext = strrchr(file, '.');
    /* No need to guard these with #ifdef *_MUSIC stuff,
     * since we simply call Mix_LoadMUSType_RW() later */
    if ( ext ) {
        ++ext; /* skip the dot in the extension */
        if ( MIX_string_equals(ext, "WAV") ) {
            type = MUS_WAV;
        } else if ( MIX_string_equals(ext, "MID") ||
                    MIX_string_equals(ext, "MIDI") ||
                    MIX_string_equals(ext, "KAR") ) {
            type = MUS_MID;
        } else if ( MIX_string_equals(ext, "OGG") ) {
            type = MUS_OGG;
        } else if ( MIX_string_equals(ext, "FLAC") ) {
            type = MUS_FLAC;
        } else  if ( MIX_string_equals(ext, "MPG") ||
                     MIX_string_equals(ext, "MPEG") ||
                     MIX_string_equals(ext, "MP3") ||
                     MIX_string_equals(ext, "MAD") ) {
            type = MUS_MP3;
        }
    }
    if ( type == MUS_NONE ) {
        type = detect_music_type(src);
    }

    /* We need to know if a specific error occurs; if not, we'll set a
     * generic one, so we clear the current one. */
    Mix_SetError("");
    music = Mix_LoadMUSType_RW(src, type, SDL_TRUE);
    if ( music == NULL && Mix_GetError()[0] == '\0' ) {
        Mix_SetError("Unrecognized music format");
    }
    return music;
}
开发者ID:langresser,项目名称:SDLWP8,代码行数:70,代码来源:music.c

示例15: Init_Sound


//.........这里部分代码省略.........
	if (err == SFX_ERR_NO_PORTS_AVAIL) {
		(void) fprintf(stderr, "No audio ports available.\n");
		sound_init = 0;
		sound_toggle = 0;
		return;
	}
	if (err == SFX_ERR_NO_SPROC) {
		(void) fprintf(stderr, "Unable to execute sound process.\n");
		sound_init = 0;
		sound_toggle = 0;
		return;
	}
	if (err == SFX_ERR_NO_MEM) {
		(void) fprintf(stderr, "No memory available for sound data.\n");
		sound_init = 0;
		sound_toggle = 0;
		return;
	}
	if (err > 0) {				/* load mandatory sounds f we got at least one audio port */
		sounds[FIRE_TORP_WAV] = sfxLoad("fire_torp.aiff");
		sounds[PHASER_WAV] = sfxLoad("phaser.aiff");
		sounds[FIRE_PLASMA_WAV] = sfxLoad("fire_plasma.aiff");
		sounds[EXPLOSION_WAV] = sfxLoad("explosion.aiff");
		sounds[FIRE_TORP_OTHER_WAV] = sfxLoad("fire_torp_other.aiff");
		sounds[PHASER_OTHER_WAV] = sfxLoad("phaser_other.aiff");
		sounds[FIRE_PLASMA_OTHER_WAV] = sfxLoad("fire_plasma_other.aiff");
		sounds[EXPLOSION_OTHER_WAV] = sfxLoad("explosion_other.aiff");
		sounds[PLASMA_HIT_WAV] = sfxLoad("plasma_hit.aiff");
		sounds[TORP_HIT_WAV] = sfxLoad("torp_hit.aiff");

		if (err > 1) {			/* load optional sounds only if we got two audio ports */
			sounds[CLOAK_WAV] = sfxLoad("cloak.aiff");
			sounds[UNCLOAK_WAV] = sfxLoad("cloak.aiff");
			sounds[SHIELD_DOWN_WAV] = sfxLoad("shield_down.aiff");
			sounds[SHIELD_UP_WAV] = sfxLoad("shield_up.aiff");
			sounds[REDALERT_WAV] = sfxLoad("klaxon.aiff");
			sounds[INTRO_WAV] = sfxLoad("paradise.aiff");
			sounds[MESSAGE_WAV] = sfxLoad("message.aiff");

			/* load sound loops only if we got three audio ports */
			if (err > 2) {
				sounds[THERMAL_WAV] = sfxLoad("thermal_warn.aiff");
				sounds[ENTER_SHIP_WAV] = sfxLoad("enter_ship.aiff");
				sounds[SELF_DESTRUCT_WAV] = sfxLoad("self_destruct.aiff");

				if ((sounds[ENGINE_WAV] = sfxLoad("bridge.aiff")) != NULL) {
					sfxLoop(sounds[ENGINE_WAV]);
					sfxPitchBend(sounds[ENGINE_WAV], 0.0f, 1.0f, 1.0f, 2.0f, 1.1f, 20);
				}
			}
		}
		sfxPlay(sounds[INTRO_WAV]);
	}

#elif defined(HAVE_SDL)
#ifdef DEBUG
	printf("Init_Sound using SDL\n");
#endif

	/* Initialize the SDL library */
	if (SDL_Init(SDL_INIT_AUDIO) < 0) {
	  fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
	}
	atexit(SDL_Quit);

	/* Open the audio device at 8000 Hz 8 bit Microsoft PCM */
	if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) {
	  fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
	  sound_init = 0;
	}

        Mix_AllocateChannels(16);

	/* If we successfully loaded the wav files, so shut-off
	   sound_init and play the introduction */
	if (loadSounds()) {
	  if (sounds[INTRO_WAV])
	    if (Mix_PlayChannel(-1, sounds[INTRO_WAV], 0) < 0) {
	      fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
	    }
	}
#else
	if (InitSound() == -1) {
	  sound_toggle = 0;
	  sound_init = 0;
	} else {
	  sound_init = 1;
	  sound_toggle = 1;
	}

	strcpy(sound_prefix, sounddir);
	strcat(sound_prefix, "/");

	if (sound_toggle) {
	  strcpy(buf, sounddir);
	  strcat(buf, "/nt_intro");
	  StartSound(buf);
	}
#endif
}
开发者ID:MarkMielke,项目名称:netrek-client-cow,代码行数:101,代码来源:sound.c


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