long playSound(FSOUND_SAMPLE *handle, bool loop) { long result; result = FSOUND_PlaySound(FSOUND_FREE, handle); FSOUND_SetVolume(result, DEF_VOLUME); if (loop) FSOUND_SetLoopMode(result, FSOUND_LOOP_NORMAL); else FSOUND_SetLoopMode(result, FSOUND_LOOP_OFF); return result; }
VOID CSoundSourceFMod::Play(VOID) { //停止 Stop(); //播放 if(_Sample) { CSoundBufferFMod* bufFMod= static_cast<CSoundBufferFMod*>(_Sample); _State= source_playing; //以暂停模式开始播放声音 if(bufFMod->m_pFModSample) _FModChannel= FSOUND_PlaySoundEx(FSOUND_FREE, bufFMod->m_pFModSample, NULL, true); //在Channel播放 if(_FModChannel!=-1) { FSOUND_SetLoopMode(_FModChannel, _Loop?FSOUND_LOOP_NORMAL:FSOUND_LOOP_OFF); //音量 UpdateVolume(); //开始播放 FSOUND_SetPaused(_FModChannel, false); } } }
// Lecture des sons. Ils sont lu par streaming c'est à dire qu'ils sont chargés pendant la lecture. void CSoundManager::Jouer ( std::string const & Filename, ECanaux Canal, bool bLoop ) { if (!m_bCanauxJeu && Canal != CANAL_MUSIQUE) return; if (m_pSon[Canal]) FSOUND_Stream_Close (m_pSon[Canal]); // Si bLoop == true alors le son boucle. if (bLoop) { FSOUND_SetLoopMode (0, FSOUND_LOOP_NORMAL); m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_LOOP_NORMAL, 0, 0); FSOUND_SetVolume (Canal, 64); FSOUND_SetVolumeAbsolute (Canal, 64); } // Sinon il est jouer une seule fois. else { m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_NORMAL, 0, 0); FSOUND_SetVolume (Canal, 255); FSOUND_SetVolumeAbsolute (Canal, 255); } FSOUND_Stream_Play (Canal, m_pSon[Canal]); }
void CSoundSourceFMod::SetLooping( BOOL loop ) { if(_Loop!=loop) { _Loop = loop; if(_FModChannel!=-1) { //首先暂停 FSOUND_SetPaused(_FModChannel, true); FSOUND_SetLoopMode(_FModChannel, _Loop?FSOUND_LOOP_NORMAL:FSOUND_LOOP_OFF); FSOUND_SetPaused(_FModChannel, false); } } }
int CSound::Loopsound(int soundnum) { for(int i =1;i< int(FSOUND_GetMaxChannels);i++) { if(!FSOUND_IsPlaying(i)) { FSOUND_PlaySound(i,FSOUND_Sample_Get(soundnum)); FSOUND_SetLoopMode(i,FSOUND_LOOP_NORMAL); return i; } } return 0; }
bool LLAudioChannelFMOD::updateBuffer() { if (LLAudioChannel::updateBuffer()) { // Base class update returned true, which means that we need to actually // set up the channel for a different buffer. LLAudioBufferFMOD *bufferp = (LLAudioBufferFMOD *)mCurrentSourcep->getCurrentBuffer(); // Grab the FMOD sample associated with the buffer FSOUND_SAMPLE *samplep = bufferp->getSample(); if (!samplep) { // This is bad, there should ALWAYS be a sample associated with a legit // buffer. llerrs << "No FMOD sample!" << llendl; return false; } // Actually play the sound. Start it off paused so we can do all the necessary // setup. mChannelID = FSOUND_PlaySoundEx(FSOUND_FREE, samplep, FSOUND_DSP_GetSFXUnit(), true); //llinfos << "Setting up channel " << std::hex << mChannelID << std::dec << llendl; } // If we have a source for the channel, we need to update its gain. if (mCurrentSourcep) { // SJB: warnings can spam and hurt framerate, disabling if (!FSOUND_SetVolume(mChannelID, llround(getSecondaryGain() * mCurrentSourcep->getGain() * 255.0f))) { // llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl; } if (!FSOUND_SetLoopMode(mChannelID, mCurrentSourcep->isLoop() ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF)) { // llwarns << "Channel " << mChannelID << "Source ID: " << mCurrentSourcep->getID() // << " at " << mCurrentSourcep->getPositionGlobal() << llendl; // llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl; } } return true; }