Stereo fx, code suggestion

Status
Not open for further replies.

urbanspaceman

Well-known member
Hi, I noticed that the effects are all mono, so if I wanted to create a stereo chain to process a stereo wave file, should I proceed like this?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=90,294
AudioMixer4              Mixer_left;         //xy=272,215
AudioMixer4              Mixer_right;         //xy=273,428
AudioEffectBitcrusher    Bitcrusher_right; //xy=513,427.75
AudioEffectBitcrusher    Bitcrusher_left;    //xy=517,213
AudioEffectDelay         Delay_left;         //xy=703.4285430908203,165.8571548461914
AudioEffectDelay         Delay_right;    //xy=708.1428489685059,468.4285697937012
AudioMixer4              mixer3;         //xy=1134,135
AudioMixer4              mixer4;         //xy=1134,188
AudioMixer4              mixer5;         //xy=1136,440
AudioMixer4              mixer6;         //xy=1136,492
AudioMixer4              mixer7;         //xy=1325.7143287658691,137.1428565979004
AudioMixer4              Mix_right;      //xy=1326.7142639160156,464.6428413391113
AudioEffectReverb        reverb1;        //xy=1484.2856750488281,205.71427726745605
AudioEffectReverb        reverb2;        //xy=1489.9999237060547,408.57144355773926
AudioOutputI2S           i2s1;           //xy=1725.1429176330566,314.49998569488525
AudioConnection          patchCord1(playSdWav1, 0, Mixer_left, 0);
AudioConnection          patchCord2(playSdWav1, 1, Mixer_right, 0);
AudioConnection          patchCord3(Mixer_left, bitcrusher1);
AudioConnection          patchCord4(Mixer_right, Bitcrusher_right);
AudioConnection          patchCord5(Bitcrusher_right, Delay_right);
AudioConnection          patchCord6(Bitcrusher_left, delay1);
AudioConnection          patchCord7(Delay_left, 0, mixer3, 0);
AudioConnection          patchCord8(Delay_left, 1, mixer3, 1);
AudioConnection          patchCord9(Delay_left, 2, mixer3, 2);
AudioConnection          patchCord10(Delay_left, 3, mixer3, 3);
AudioConnection          patchCord11(Delay_left, 4, mixer4, 0);
AudioConnection          patchCord12(Delay_left, 5, mixer4, 1);
AudioConnection          patchCord13(Delay_left, 6, mixer4, 2);
AudioConnection          patchCord14(Delay_left, 7, mixer4, 3);
AudioConnection          patchCord15(Delay_right, 0, mixer5, 0);
AudioConnection          patchCord16(Delay_right, 1, mixer5, 1);
AudioConnection          patchCord17(Delay_right, 2, mixer5, 2);
AudioConnection          patchCord18(Delay_right, 3, mixer5, 3);
AudioConnection          patchCord19(Delay_right, 4, mixer6, 0);
AudioConnection          patchCord20(Delay_right, 5, mixer6, 1);
AudioConnection          patchCord21(Delay_right, 6, mixer6, 2);
AudioConnection          patchCord22(Delay_right, 7, mixer6, 3);
AudioConnection          patchCord23(mixer3, 0, mixer7, 0);
AudioConnection          patchCord24(mixer4, 0, mixer7, 1);
AudioConnection          patchCord25(mixer5, 0, Mix_right, 0);
AudioConnection          patchCord26(mixer6, 0, Mix_right, 1);
AudioConnection          patchCord27(mixer7, reverb1);
AudioConnection          patchCord28(Mix_right, reverb2);
AudioConnection          patchCord29(reverb1, 0, i2s1, 0);
AudioConnection          patchCord30(reverb2, 0, i2s1, 1);
// GUItool: end automatically generated code
 
That looks almost OK except that there are a few patches missing in the left channel:
Code:
AudioConnection          patchCord3(Mixer_left, bitcrusher1);
AudioConnection          patchCord4(Mixer_right, Bitcrusher_right);
The left channel doesn't match the way the right channel is set up. bitcrusher1 isn't defined and a few other problems exist. If you import the audio definitions that you posted into the audio design tool, you'll see a couple of missing connections.

Pete
 
Yes, with mono effects you just use 2 of them if you want stereo.

Someday I hope to implement a mono-input, stereo (or many channel) output reverb. But most of the effects are only meaningful as single channel and will always be used in pairs for stereo.
 
As a matter of design philosophy, the audio library has conflicting goals ease of use & convenience versus user awareness of allocating the very limited resources of a single chip microcontroller.

The objects and design tool lack stereo & multi-channel connections on purpose. The idea is drawing (or typing) 2 of everything is "easy", but makes the fact you're using double the amount of resources very clear.
 
Thank you Paul, very clear explanation.
this means, for example, that a potentiometer will control two parameters simultaneously, correct?
 
Sure. There are scenarios where you might wish to have the analog reading from a pot control more than 2 audio lib parameters. For an example, click File > Examples > Audio > Tutorial > Part_2_02_Mixers. This code uses 1 reading with simple math to control 4 mixer gain settings, to achieve stereo cross fading. It's explained on page 13 of the tutorial PDF, and you can watch a demo starting at 10:26 in the video.

https://www.pjrc.com/store/audio_tutorial_kit.html
 
Status
Not open for further replies.
Back
Top