PDA

View Full Version : Cross Fade Issue?



Lo Ryuken
04-08-2016, 06:01 AM
I'm trying to cross fade using two AudioEffectFades and an AudioMixer4.

When I try the cross fade, the second sound begins playing at full volume even though it should just fade in.

I tried explicitly fading out the second fader initially, but its sound still comes in at full volume.



#include <Audio.h>
#include <SerialFlash.h>

AudioPlaySerialflashRaw sound1;
AudioPlaySerialflashRaw sound2;

AudioEffectFade fader1;
AudioEffectFade fader2;

AudioMixer4 mix;
AudioOutputI2S headphones;

AudioConnection patchCord1( sound1, 0, fader1, 0 );
AudioConnection patchCord2( sound2, 0, fader2, 0 );

AudioConnection patchCord3( fader1, 0, mix, 0 );
AudioConnection patchCord4( fader2, 0, mix, 1 );

AudioConnection patchCord5( mix, 0, headphones, 0 );
AudioConnection patchCord6( mix, 0, headphones, 1 );

AudioControlSGTL5000 sgtl5000;


void loop()
{
}


void setup()
{
AudioMemory( 32 );

SPI.setMOSI( 7 ); // MOSI_PIN for audio board
SPI.setSCK( 14 ); // SCK_PIN for audio board

if ( !SerialFlash.begin() )
Serial.println( "Unable to access SPI Flash chip" );

sgtl5000.enable();
sgtl5000.volume( .1 );

// Play the first sound
sound1.play( "SOUND.RAW" );

// Wait a bit
delay( 3000 );

// Initialize fader2 to 0 volume
fader2.fadeOut( 1 );

// Setup the cross fade
fader1.fadeOut( 1000 );
fader2.fadeIn( 1000 );

// Play the second sound
sound2.play( "SOUND.RAW" );
}

Lo Ryuken
04-08-2016, 10:51 PM
My initial example code was convoluted so I've simplified the original post.

The new code should create a simple cross fade, but I still seem to be doing something wrong.

Lo Ryuken
04-08-2016, 11:15 PM
I was able to implement the desired cross fade using audio envelopes:

http://www.pjrc.com/teensy/gui/?info=AudioEffectEnvelope

Still no luck using two AudioEffectFades though.


#include <Audio.h>
#include <SerialFlash.h>

AudioPlaySerialflashRaw sound1;
AudioPlaySerialflashRaw sound2;

AudioEffectEnvelope envelope1;
AudioEffectEnvelope envelope2;

AudioMixer4 mix;
AudioOutputI2S headphones;

AudioConnection patchCord1( sound1, 0, envelope1, 0 );
AudioConnection patchCord2( sound2, 0, envelope2, 0 );

AudioConnection patchCord3( envelope1, 0, mix, 0 );
AudioConnection patchCord4( envelope2, 0, mix, 1 );

AudioConnection patchCord5( mix, 0, headphones, 0 );
AudioConnection patchCord6( mix, 0, headphones, 1 );

AudioControlSGTL5000 sgtl5000;


void loop()
{
}


void setup()
{
AudioMemory( 32 );

SPI.setMOSI( 7 ); // MOSI_PIN for audio board
SPI.setSCK( 14 ); // SCK_PIN for audio board

if ( !SerialFlash.begin() )
Serial.println( "Unable to access SPI Flash chip" );

sgtl5000.enable();
sgtl5000.volume( .1 );

envelope1.attack( 0 );
envelope1.hold( 0 );
envelope1.decay( 0 );
envelope1.sustain( 1 );
envelope1.release( 1000 );

envelope2.attack( 1000 );
envelope2.hold( 0 );
envelope2.decay( 0 );
envelope2.sustain( 1 );
envelope2.release( 1000 );

// Play the first sound
sound1.play( "SOUND.RAW" );
envelope1.noteOn();

// Wait a bit
delay( 3000 );

// Begin the fade out (release=1000)
envelope1.noteOff();

// Play the second sound
sound2.play( "SOUND.RAW" );

// Begin the fade in (attack=1000)
envelope2.noteOn();
}