Hello!
I want to fade between two audio channels. First, a sound is applied to the first channel. Then, when a second sound is attached, the first channel should fade out, and the other fade in. Then, it might be, that another sound is added. In this case channel 2 should fade out, and channel 1 should fade in (and so on).
Here is a code snipped that I produced:
Somewhere is an error, but I don't get it. Can someone please help me?Code:// Membervariables FMOD::Channel * m_pSoundChannel, *m_pSoundChannel2; FMOD::Sound* m_CurSound; float m_SoundOrgFrequ; float m_SoundCurSampleSpeed; int m_fadeInOut[2]; bool m_fadeInFirstChannel; std::vector<FMOD::Sound*> m_sounds; while (...) { //... // fade if (m_fadeInFirstChannel && m_fadeInOut[0] < 256) { // fade in channel 1 m_fadeInOut[0]++; if (m_fadeInOut[1] > 0) m_fadeInOut[1]--; else if (m_pSoundChannel2) { CSoundManager::ERRCHECK(m_pSoundChannel2->stop()); m_pSoundChannel2 = 0; } } else if (m_fadeInOut[1] < 256 && !m_fadeInFirstChannel) { m_fadeInOut[1]++; if (m_fadeInOut[0] > 0) m_fadeInOut[0]--; else if (m_pSoundChannel) { CSoundManager::ERRCHECK(m_pSoundChannel->stop()); m_pSoundChannel = 0; } } // Loading of soundfiles if (m_the_car.rpm < 2000 && m_CurSound != m_sounds[0]) { CSoundManager::PlaySound(m_sounds[0],false,m_fadeInFirstChannel ? &m_pSoundChannel : &m_pSoundChannel2); CSoundManager::ERRCHECK((m_fadeInFirstChannel ? m_pSoundChannel : m_pSoundChannel2)->getFrequency(&m_SoundOrgFrequ)); m_fadeInFirstChannel = !m_fadeInFirstChannel; m_CurSound = m_sounds[0]; } else if (m_the_car.rpm >= 2000 && m_the_car.rpm < 3000 && m_CurSound != m_sounds[1]) { CSoundManager::PlaySound(m_sounds[1],false,m_fadeInFirstChannel ? &m_pSoundChannel : &m_pSoundChannel2); CSoundManager::ERRCHECK((m_fadeInFirstChannel ? m_pSoundChannel : m_pSoundChannel2)->getFrequency(&m_SoundOrgFrequ)); m_fadeInFirstChannel = !m_fadeInFirstChannel; m_CurSound = m_sounds[1]; } if (m_pSoundChannel) { m_pSoundChannel->setVolume(m_fadeInOut[0]); } if (m_pSoundChannel2) { m_pSoundChannel2->setVolume(m_fadeInOut[1]); } } // while
thank you,



LinkBack URL
About LinkBacks


