Fading between audio-channels

This is a discussion on Fading between audio-channels within the C++ Programming forums, part of the General Programming Boards category; Hello! I want to fade between two audio channels. First, a sound is applied to the first channel. Then, when ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    19

    Fading between audio-channels

    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:
    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
    Somewhere is an error, but I don't get it. Can someone please help me?

    thank you,

  2. #2
    #define WORLD "sad place" LinuxCoder's Avatar
    Join Date
    Mar 2006
    Location
    Portugal
    Posts
    89
    It would be nicer to have some concrete error messages or behaviors to go through that piece of code, if that's possible.

    Cheers

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    19
    Quote Originally Posted by LinuxCoder
    It would be nicer to have some concrete error messages or behaviors to go through that piece of code, if that's possible.

    Cheers
    ok. at the beginning there aren't any errors but sounds do not stop (so there is just noise, because sounds are added to each other).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bits and bytes- Please help.
    By chakra in forum C Programming
    Replies: 85
    Last Post: 05-30-2009, 11:22 PM
  2. Producing a "beeep!" as simply as possible
    By mutandis in forum C Programming
    Replies: 10
    Last Post: 12-13-2008, 12:30 AM
  3. Audio Programming
    By dwalters in forum Tech Board
    Replies: 0
    Last Post: 02-07-2008, 03:20 PM
  4. audio programming (from scratch)
    By simpleid in forum C Programming
    Replies: 6
    Last Post: 07-26-2006, 09:32 AM
  5. Port Audio
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 12-07-2005, 10:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21