void I_InitTimidityConfig(void) { char *env_string; boolean success; temp_timidity_cfg = M_TempFile("timidity.cfg"); if (snd_musicdevice == SNDDEVICE_GUS) { success = GUS_WriteConfig(temp_timidity_cfg); } else { success = WriteWrapperTimidityConfig(temp_timidity_cfg); } // Set the TIMIDITY_CFG environment variable to point to the temporary // config file. if (success) { env_string = M_StringJoin("TIMIDITY_CFG=", temp_timidity_cfg, NULL); putenv(env_string); } else { free(temp_timidity_cfg); temp_timidity_cfg = NULL; } }
// Initialize music subsystem dboolean I_InitMusic(void) { // If SDL_mixer is not initialized, we have to initialize it // and have the responsibility to shut it down later on. if (!SDLIsInitialized()) if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) I_Error("Unable to set up sound: %s", SDL_GetError()); else if (Mix_OpenAudio(snd_samplerate, MIX_DEFAULT_FORMAT, CHANNELS, SAMPLECOUNT * snd_samplerate / 11025) < 0) { SDL_QuitSubSystem(SDL_INIT_AUDIO); I_Error("Error initializing SDL2_mixer: %s", Mix_GetError()); } SDL_PauseAudio(0); tempmusicfilename = M_TempFile(PACKAGE".mid"); sdl_was_initialized = true; music_initialized = true; // Once initialization is complete, the temporary Timidity config // file can be removed. RemoveTimidityConfig(); return music_initialized; }
void I_InitTimidityConfig(void) { dboolean success; temp_timidity_cfg = M_TempFile("timidity.cfg"); success = WriteWrapperTimidityConfig(temp_timidity_cfg); // Set the TIMIDITY_CFG environment variable to point to the temporary // config file. if (success) putenv(M_StringJoin("TIMIDITY_CFG=", temp_timidity_cfg, NULL)); else { free(temp_timidity_cfg); temp_timidity_cfg = NULL; } }
static void *I_SDL_RegisterSong(void *data, int len) { char *filename; Mix_Music *music; if (!music_initialized) { return NULL; } // MUS files begin with "MUS" // Reject anything which doesnt have this signature filename = M_TempFile("doom"); // [crispy] generic filename // [crispy] Reverse Choco's logic from "if (MIDI)" to "if (not MUS)" // MUS is the only format that requires conversion, // let SDL_Mixer figure out the others /* if (IsMid(data, len) && len < MAXMIDLENGTH) */ if (len < 4 || memcmp(data, "MUS\x1a", 4)) // [crispy] MUS_HEADER_MAGIC { M_WriteFile(filename, data, len); } else { // Assume a MUS file and try to convert ConvertMus(data, len, filename); } // Load the MIDI. In an ideal world we'd be using Mix_LoadMUS_RW() // by now, but Mix_SetMusicCMD() only works with Mix_LoadMUS(), so // we have to generate a temporary file. #if defined(_WIN32) // [AM] If we do not have an external music command defined, play // music with the MIDI server. if (midi_server_initialized) { music = NULL; if (!I_MidiPipe_RegisterSong(filename)) { fprintf(stderr, "Error loading midi: %s\n", "Could not communicate with midiproc."); } } else #endif { music = Mix_LoadMUS(filename); if (music == NULL) { // Failed to load fprintf(stderr, "Error loading midi: %s\n", Mix_GetError()); } // Remove the temporary MIDI file; however, when using an external // MIDI program we can't delete the file. Otherwise, the program // won't find the file to play. This means we leave a mess on // disk :( if (strlen(snd_musiccmd) == 0) { remove(filename); } } free(filename); return music; }