bool TForm_Main::OpenFile() { // STOP!!! c_Button_Stop->Click(); // Let go... if (m_hSample) { AIL_release_sample_handle(m_hSample); m_hSample = NULL; } // Get rid of the buffer if it's already been loaded if (m_pFileBuffer) { AIL_mem_free_lock(m_pFileBuffer); m_pFileBuffer = NULL; } // Remember the file name m_CurFile = c_Edit_FileName->Text; // Er, don't load if it doesn't exist... if (!FileExists(m_CurFile)) { m_CurFile = ""; return false; } m_hSample = AIL_allocate_sample_handle(m_hDigDriver); if (!m_hSample) { ChangeStatus("Error allocating sample handle"); m_CurFile = ""; return false; } char *pFileName = m_CurFile.c_str(); // Bind to the file m_pFileBuffer = AIL_file_read(pFileName, NULL); if (!m_pFileBuffer) { ChangeStatus("Error opening " + m_CurFile + " (" + IntToStr(AIL_file_error()) + ")"); m_CurFile = ""; return false; } // Get the file size m_iFileSize = AIL_file_size(pFileName); AIL_init_sample(m_hSample); AIL_set_named_sample_file(m_hSample, pFileName, m_pFileBuffer, m_iFileSize, 0); AIL_set_sample_loop_count(m_hSample, 0); AIL_set_sample_volume(m_hSample, 127); AIL_set_sample_processor(m_hSample, DP_FILTER, m_hCurFilter); ChangeStatus("Loaded " + m_CurFile); return true; }
// // Play2D // // Play a record as a 2D sample (TRUE if actually started) // Bool Play2D ( Effect *e, Record *r, S32 vol, U32 owner, F32 priority, S32 loop, S32 pan ) { ASSERT(e); ASSERT(r); // Request a 2D voice Voice *voice = Request(priority, FALSE, e->GetVoiceIndex()); if (!voice) { return (FALSE); } // Request the cache data Cache::Item *item = Cache::Request(r); if (!item) { // Unable to load data return (FALSE); } // Stop any sounds from this owner if (owner != NO_OWNER) { Output::StopByOwner(owner); } // The current time U32 time = AIL_ms_count(); // Are we under the minimum repeat time if ((time - r->lastUse) < MIN_REPEATTIME) { return (FALSE); } // Save info about this use r->lastUse = time; // Initialise the voice AIL_init_sample(voice->handle2D); // Initialise the sound effect data if (!AIL_set_sample_file(voice->handle2D, item->data, 0)) { LOG_WARN(("Ignoring possibly corrupted file '%s'", r->Name())); r->valid = FALSE; return (FALSE); } // Setup the voice voice->effect = e; voice->record = r; voice->owner = owner; voice->priority = priority; // Set the volume AIL_set_sample_volume(voice->handle2D, vol); // Set the stereo panning AIL_set_sample_pan(voice->handle2D, pan); // Set the loop count for this voice AIL_set_sample_loop_count(voice->handle2D, loop); // Start the sample playing AIL_start_sample(voice->handle2D); return (TRUE); }
/* * PlayMusicFile: Play given MIDI file and notify given window when done. * If background music had been playing, it picks up where it left off. * Returns 0 if successful, MCI error code otherwise. */ DWORD PlayMusicFile(HWND hWndNotify, char *fname) { if (!has_midi) return 0; #ifdef M59_MSS char *ext; // If a sequence was paused, resume it if (music_pos != 0) { UnpauseMusic(); return 0; } // free memory from previous background music if (pMIDIBackground) AIL_mem_free_lock(pMIDIBackground); // First try MP3 file ext = strstr( _strlwr( fname ), ".mid" ); if( ext != NULL ) strcpy( ext, ".mp3" ); // load the file pMIDIBackground = (BYTE *) AIL_file_read( fname, NULL ); if( !pMIDIBackground ) { // Next try xmi file ext = strstr(fname, ".mp3" ); if( ext != NULL ) strcpy( ext, ".xmi" ); pMIDIBackground = (BYTE *) AIL_file_read( fname, NULL ); if( !pMIDIBackground ) { debug(( "Failed to load music file %s.\n", fname )); return 0; } } // initialize the sequence if (!AIL_set_named_sample_file(hseqBackground, fname, pMIDIBackground, AIL_file_size(fname), 0 ) ) { debug(( "Failed to init music sequence %s.\n", fname )); return 0; } // set to loop indefinitely AIL_set_sample_loop_count( hseqBackground, 0 ); // Set volume float vol = ((float) config.music_volume) / CONFIG_MAX_VOLUME; AIL_set_sample_volume_levels(hseqBackground, vol, vol ); // start playing AIL_start_sample( hseqBackground ); debug(( "Playing music file %s.\n", fname )); playing_music = True; return 0; #else DWORD dwReturn; MCI_PLAY_PARMS mciPlayParms; char temp[81]; if ((dwReturn = OpenMidiFile(fname)) != 0) { debug(("OpenMidiFile error code = %d\n", dwReturn)); mciGetErrorString(dwReturn, temp, 80); debug((temp)); return dwReturn; } /* If already playing music, pick up where we left off */ if (music_pos != 0) UnpauseMusic(); /* * Begin playback. The window procedure function * for the parent window is notified with an * MM_MCINOTIFY message when playback is complete. * The window procedure then closes the device. */ mciPlayParms.dwCallback = (DWORD) hWndNotify; if (dwReturn = mciSendCommand(midi_element, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms)) { mciGetErrorString(dwReturn, temp, 80); debug((temp)); mciSendCommand(midi_element, MCI_CLOSE, 0, 0); return dwReturn; } debug(("Playing music file, element = %d\n", midi_element)); ResetMusicVolume(); playing_music = True; return 0; #endif }