/* Initialise audio */ int digi_mixer_init() { digi_sample_rate = SAMPLE_RATE_44K; if (MIX_DIGI_DEBUG) con_printf(CON_DEBUG,"digi_init %d (SDL_Mixer)\n", MAX_SOUNDS); if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) Error("SDL audio initialisation failed: %s.", SDL_GetError()); if (Mix_OpenAudio(digi_sample_rate, MIX_OUTPUT_FORMAT, MIX_OUTPUT_CHANNELS, SOUND_BUFFER_SIZE)) { //edited on 10/05/98 by Matt Mueller - should keep running, just with no sound. con_printf(CON_URGENT,"\nError: Couldn't open audio: %s\n", SDL_GetError()); GameArg.SndNoSound = 1; return 1; } Mix_AllocateChannels(digi_max_channels); Mix_Pause(0); // Attempt to load jukebox jukebox_load(); //jukebox_list(); digi_initialised = 1; oplmus_init(); return 0; }
void digi_mixer_play_midi_song(char * filename, char * melodic_bank, char * drum_bank, int loop ) { if (!digi_initialised) return; if (GameArg.SndNoMusic) return; mix_set_music_volume(midi_volume); oplmus_play(filename, melodic_bank, drum_bank, loop); #if 0 jukebox_load(); // update jukebox state // quick hack to check if filename begins with "game" -- MD2211 if (jukebox_is_loaded() && strstr(filename, "game") == filename) { // use jukebox jukebox_play(loop); } else { // standard song playback #ifdef _WIN32 if (!GameArg.SndExternalMusic) { if ((hmp = hmp_open(filename))) { hmp_play(hmp,loop); digi_midi_song_playing = 1; digi_set_midi_volume(midi_volume); } } else #endif mix_play_music(filename, loop); } #endif }
// Set up everything for our music // NOTE: you might think this is done once per runtime but it's not! It's done for EACH song so that each mission can have it's own descent.sng structure. We COULD optimize that by only doing this once per mission. void songs_init() { int i = 0; char inputline[80+1]; PHYSFS_file * fp = NULL; char sng_file[PATH_MAX]; Songs_initialized = 0; if (BIMSongs != NULL) d_free(BIMSongs); memset(sng_file, '\0', sizeof(sng_file)); if (Current_mission != NULL) // try MISSION_NAME.sngdxx - might be rarely used but handy if you want a songfile for a specific mission outside of the mission hog file. use special extension to not crash with other ports of the game { snprintf(sng_file, strlen(Current_mission_filename)+8, "%s.sngdxx", Current_mission_filename); fp = PHYSFSX_openReadBuffered(sng_file); } if (fp == NULL) // try descent.sngdxx - a songfile specifically for dxx which level authors CAN use (dxx does not care if descent.sng contains MP3/OGG/etc. as well) besides the normal descent.sng containing files other versions of the game cannot play. this way a mission can contain a DOS-Descent compatible OST (hmp files) as well as a OST using MP3, OGG, etc. fp = PHYSFSX_openReadBuffered( "descent.sngdxx" ); if (fp == NULL) // try to open regular descent.sng fp = PHYSFSX_openReadBuffered( "descent.sng" ); if ( fp == NULL ) // No descent.sng available. Define a default song-set { int predef=30; // define 30 songs - period MALLOC(BIMSongs, bim_song_info, predef); if (!BIMSongs) return; strncpy(BIMSongs[SONG_TITLE].filename, "descent.hmp",sizeof(BIMSongs[SONG_TITLE].filename)); strncpy(BIMSongs[SONG_BRIEFING].filename, "briefing.hmp",sizeof(BIMSongs[SONG_BRIEFING].filename)); strncpy(BIMSongs[SONG_CREDITS].filename, "credits.hmp",sizeof(BIMSongs[SONG_CREDITS].filename)); strncpy(BIMSongs[SONG_ENDLEVEL].filename, "endlevel.hmp",sizeof(BIMSongs[SONG_ENDLEVEL].filename)); // can't find it? give a warning strncpy(BIMSongs[SONG_ENDGAME].filename, "endgame.hmp",sizeof(BIMSongs[SONG_ENDGAME].filename)); // ditto for (i = SONG_FIRST_LEVEL_SONG; i < predef; i++) { snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i - SONG_FIRST_LEVEL_SONG + 1); if (!PHYSFSX_exists(BIMSongs[i].filename,1)) snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%d.hmp", i - SONG_FIRST_LEVEL_SONG); if (!PHYSFSX_exists(BIMSongs[i].filename,1)) { memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename)); // music not available break; } } } else { while (!PHYSFS_eof(fp)) { PHYSFSX_fgets(inputline, 80, fp ); if ( strlen( inputline ) ) { BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+1)); memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename)); sscanf( inputline, "%15s", BIMSongs[i].filename ); if (strrchr(BIMSongs[i].filename, '.')) if (!stricmp(strrchr(BIMSongs[i].filename, '.'), ".hmp") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mp3") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".ogg") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".aif") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mid") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".flac") ) i++; } } // HACK: If Descent.hog is patched from 1.0 to 1.5, descent.sng is turncated. So let's patch it up here if (i==12 && PHYSFSX_fsize("descent.sng")==422) { BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+15)); for (i = 12; i <= 26; i++) snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i-4); } } Num_bim_songs = i; Songs_initialized = 1; if (fp != NULL) PHYSFS_close(fp); if (GameArg.SndNoMusic) GameCfg.MusicType = MUSIC_TYPE_NONE; // If SDL_Mixer is not supported (or deactivated), switch to no-music type if SDL_mixer-related music type was selected #ifdef USE_SDLMIXER if (GameArg.SndDisableSdlMixer) #else if (1) #endif { #ifndef _WIN32 if (GameCfg.MusicType == MUSIC_TYPE_BUILTIN) GameCfg.MusicType = MUSIC_TYPE_NONE; #endif if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM) GameCfg.MusicType = MUSIC_TYPE_NONE; } if (GameCfg.MusicType == MUSIC_TYPE_REDBOOK) RBAInit(); #ifdef USE_SDLMIXER else if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM) jukebox_load(); #endif songs_set_volume(GameCfg.MusicVolume); }