Cross Fade Issue?

Status
Not open for further replies.

Lo Ryuken

Active member
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.


Code:
#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" );
  }
 
Last edited:
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.
 
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.

Code:
#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();
  }
 
Status
Not open for further replies.
Back
Top