• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Mix_GetError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: runtime_error

SoundPlayer::SoundPlayer()
{
	if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 0, 1024) < 0)
		throw std::runtime_error(Mix_GetError());
}
开发者ID:purpleKarrot,项目名称:wowmapview,代码行数:5,代码来源:SoundPlayer.cpp


示例17: main

int main(int argc, char *argv[]) {
    /* Declare some variables */
    SNDFILE *music_file = NULL;
    SF_INFO sfinfo;
    sfinfo.format = 0;

    printf("Audio visualizer for Comp 467\n");
    printf("By: Jorenz Paragas, Carlos Henriquez, Joshua Licudo\n");
    printf("----\n");

    /* Check if the user provided a .wav file */
    if (argc < 2) {
        fprintf(stderr, "Error: a .wav file was not provided.\n");
        fprintf(stderr, "Usage: %s input.wav\n", argv[0]);
        return EXIT_FAILURE;
    }

    /* Open the .wav file */
    music_file = sf_open(argv[1], SFM_READ, &sfinfo);
    if (music_file == NULL) {
        fprintf(stderr, "Cannot open .wav file: %s\n", argv[1]);
        return EXIT_FAILURE;
    }

    printf("Name of file: %s\n", argv[1]);
    printf("Sample rate: %d\n", sfinfo.samplerate);
    printf("Channels: %d\n", sfinfo.channels);

    /* The buffer size for libsndfile must be as large as the product of
     * the number of channels and the number of samples to be read */ 
    const int buffer_size = SAMPLE_COUNT * sfinfo.channels;

    /* For a real-to-complex transform, according to the FFTW docs,
     * the expected size of the array is n / 2 + 1 */
    const int out_buffer_size = buffer_size / 2 + 1;

    /* Declare the two buffers to hold the data and tell
     * FFTW how to calculate the frequencies */
    double samples[buffer_size];
    memset(&samples, 0, buffer_size);

    fftw_complex output[out_buffer_size];
    fftw_plan plan = fftw_plan_dft_r2c_1d(buffer_size, samples, 
        output, FFTW_ESTIMATE);

    if (plan == NULL) {
        fprintf(stderr, "Plan cannot be created.\n");
        sf_close(music_file);
        return EXIT_FAILURE;
    }

    /* Start SDL */
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr, "SDL_Init error: %s\n", SDL_GetError());
        return EXIT_FAILURE;
    }
    atexit(SDL_Quit);

    /* Create the window */
    SDL_Window *window = SDL_CreateWindow("Comp 467 Project", 10, 10, 
        WINDOW_WIDTH, WINDOW_HEIGHT, 0);
    if (window == NULL) {
        fprintf(stderr, "SDL_CreateWindow error: %s\n", SDL_GetError());
        return EXIT_FAILURE;
    }
    
    /* Get the window's surface */
    SDL_Surface *surface = SDL_GetWindowSurface(window);
    
    /* Initialize the random number generator */
    srand(time(NULL));

    /* Open the music file */
    Mix_OpenAudio(sfinfo.samplerate, MIX_DEFAULT_FORMAT, 
        sfinfo.channels, 4096);
    Mix_Music *music = Mix_LoadMUS(argv[1]);
    if (music == NULL) {
        fprintf(stderr, "Mix_LoadMUS error: %s\n", Mix_GetError());
    }
    
    /* Start playing it */
    Mix_PlayMusic(music, 0);

    /* Timer-related variables */
    unsigned int start_time = SDL_GetTicks();
    unsigned int last_time = start_time;
    unsigned int current_time = start_time;

    /* The main loop */
    bool running = true;
    while (running) {
        /* Obtain any user input */
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = false;
            }
        }

        /* Based on the sample rate and the current time,
//.........这里部分代码省略.........
开发者ID:Jjp137,项目名称:comp467-audiocomp,代码行数:101,代码来源:visualizer.c


示例18: PrintLog

int CMidi::PlaySong (char* pszSong, char* melodicBank, char* drumBank, int bLoop, int bD1Song)
{
#if (defined (_WIN32) || USE_SDL_MIXER)
	int	bCustom;

PrintLog ("DigiPlayMidiSong (%s)\n", pszSong);
audio.StopCurrentSong ();
if (!(pszSong && *pszSong))
	return 0;
if (m_nVolume < 1)
	return 0;

bCustom = ((strstr (pszSong, ".mp3") != NULL) || (strstr (pszSong, ".ogg") != NULL));
if (bCustom) {
	if (audio.Format () != AUDIO_S16LSB) {
		audio.Shutdown ();
		audio.Setup (1, AUDIO_S16LSB);
		}
	}
else if (!(m_hmp = hmp_open (pszSong, bD1Song)))
	return 0;

#	if USE_SDL_MIXER
if (gameOpts->sound.bUseSDLMixer) {
	char	fnSong [FILENAME_LEN], *pfnSong;

	if (bCustom) {
		pfnSong = pszSong;
		if (strstr (pszSong, ".mp3") && !songManager.MP3 ()) {
			audio.Shutdown ();
			songManager.SetMP3 (1);
			audio.Setup (1);
			}
		}
	else {
		if (!strstr (pszSong, ".mp3") && songManager.MP3 ()) {
			audio.Shutdown ();
			songManager.SetMP3 (0);
			audio.Setup (1);
			}
#if defined (_WIN32)
		sprintf (fnSong, "%s/d2x-temp.mid", *gameFolders.szCacheDir ? gameFolders.szCacheDir : gameFolders.szHomeDir);
#else
		sprintf (fnSong, "%s/d2x-temp.mid", *gameFolders.szCacheDir ? gameFolders.szCacheDir : gameFolders.szHomeDir);
#endif
		if (!hmp_to_midi (m_hmp, fnSong)) {
			PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
			return 0;
			}
		pfnSong = fnSong;
		}
	if (!(m_music = Mix_LoadMUS (pfnSong))) {
		PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
		return 0;
		}
	if (-1 == Mix_FadeInMusicPos (m_music, bLoop ? -1 : 1, songManager.Pos () ? 1000 : 1500, (double) songManager.Pos () / 1000.0)) {
		PrintLog ("SDL_mixer cannot play %s\n(%s)\n", pszSong, Mix_GetError ());
		songManager.SetPos (0);
		return 0;
		}
	PrintLog ("SDL_mixer playing %s\n", pszSong);
	if (songManager.Pos ())
		songManager.SetPos (0);
	else
		songManager.SetStart (SDL_GetTicks ());
	
	songManager.SetPlaying (1);
	SetVolume (m_nVolume);
	return 1;
	}
#	endif
#	if defined (_WIN32)
if (bCustom) {
	PrintLog ("Cannot play %s - enable SDL_mixer\n", pszSong);
	return 0;
	}
hmp_play (m_hmp, bLoop);
songManager.SetPlaying (1);
SetVolume (m_nVolume);
#	endif
#endif
return 1;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:83,代码来源:midi.cpp


示例19: init

/*
--------------------------------------------------------------------------------
                                      INIT
--------------------------------------------------------------------------------
 *  Master init function.  Being a game made in SDL2, SDL2 and its subsystems
 *  are obviously critical to the functionality of the program.  Also, their
 *  initialization is kept here because it's tidier.
*/
bool init( void )
{
    /*  Init SDL */
    if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
    {
        printf("ERROR:  Could not init SDL.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }

    /*  Init SDL_image */
    if( ( IMG_Init( IMG_INIT_PNG ) & IMG_INIT_PNG ) == false )
    {
        printf("ERROR:  Could not init SDL_image.  IMG Error:  %s\n",
                IMG_GetError() );
        return( false );
    }

    /*  Init SDL_mixer */
    if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
    {
        printf("ERROR:  Could not init SDL_mixer.  Mix Error:  %s\n",
                Mix_GetError() );
        return( false );
    }


    /*  Init SDL_ttf */
    if( TTF_Init() == -1 )
    {
        printf("ERROR:  Could not init SDL_ttf.  TTF Error:  %s\n",
                TTF_GetError() );
        return( false );
    }


    /*  Create our window */
    gWindow = SDL_CreateWindow( "BELTED (working title)",
            SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
            WWIDTH, WHEIGHT, SDL_WINDOW_SHOWN );
    if( gWindow == NULL )
    {
        printf("ERROR:  Could not create window.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }

    /*
     *  Create the renderer
     *
     *  We check for the limiting of FPS as a futureproofing thing.  Also,
     *  theoretically a bug-solving or performance thing.
     */

    /*  If they want to limit FPS, don't vsync */
    if( limitFPS )
        gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );

    /*  Otherwise, use vsync */
    else
    {
        gRenderer = SDL_CreateRenderer( gWindow, -1,
                SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    }
    if( gRenderer == NULL )
    {
        printf("ERROR:  Could not create renderer.  SDL Error:  %s\n",
                SDL_GetError() );
        return( false );
    }


    /*  Just for shits and giggles, we'll seed random here */
    srand( (unsigned int)time(NULL) );

    /*  Init boundary dimensions */
    BWIDTH = WWIDTH;
    BHEIGHT = WHEIGHT - 100;

    /*  Init colors */
    init_colors();

    /*  Init blend mode */
    SDL_SetRenderDrawBlendMode( gRenderer, SDL_BLENDMODE_BLEND );

    /*  Init transitions */
    init_transition();


    /*  If we made it this far, we're golden */
    return( true );
}
开发者ID:jahendrie,项目名称:belted,代码行数:100,代码来源:init.cpp


示例20: M_Start

/**
 * @sa M_Stop
 */
static void M_Start (const char* file)
{
	if (Q_strnull(file))
		return;

	if (!s_env.initialized) {
		Com_Printf("M_Start: No sound started!\n");
		return;
	}

	if (music.playingStream || !music.playing)
		return;

	char name[MAX_QPATH];
	Com_StripExtension(file, name, sizeof(name));
	const size_t len = strlen(name);
	if (len + 4 >= MAX_QPATH) {
		Com_Printf("M_Start: MAX_QPATH exceeded: " UFO_SIZE_T "\n", len + 4);
		return;
	}

	/* we are already playing that track */
	if (Q_streq(name, music.currentTrack) && music.data && Mix_PlayingMusic())
		return;

	/* we are still playing some background track - fade it out */
	if (music.data && Mix_PlayingMusic()) {
		if (!Mix_FadeOutMusic(1500))
			M_Stop();
		Q_strncpyz(music.nextTrack, name, sizeof(music.nextTrack));
		return;
	}

	/* make really sure the last track is closed and freed */
	M_Stop();

	/* load it in */
	byte* musicBuf;
	const int size = FS_LoadFile(va("music/%s.ogg", name), &musicBuf);
	if (size == -1) {
		Com_Printf("M_Start: Could not load '%s' background track!\n", name);
		return;
	}

	SDL_RWops* rw = SDL_RWFromMem(musicBuf, size);
	if (!rw) {
		Com_Printf("M_Start: Could not load music: 'music/%s'!\n", name);
		FS_FreeFile(musicBuf);
		return;
	}
#if SDL_VERSION_ATLEAST(2,0,0)
	music.data = Mix_LoadMUS_RW(rw, 1);
#else
	music.data = Mix_LoadMUS_RW(rw);
#endif
	if (!music.data) {
		Com_Printf("M_Start: Could not load music: 'music/%s' (%s)!\n", name, Mix_GetError());
		SDL_FreeRW(rw);
		FS_FreeFile(musicBuf);
		return;
	}

	Q_strncpyz(music.currentTrack, name, sizeof(music.currentTrack));
	music.buffer = musicBuf;
	if (Mix_FadeInMusic(music.data, 1, 1500) == -1)
		Com_Printf("M_Start: Could not play music: 'music/%s' ( 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Mix_HaltChannel函数代码示例发布时间:2022-05-30
下一篇:
C++ Mix_FreeMusic函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap