newbie struggling to get stereo synthesis out of audio shield

Status
Not open for further replies.

colorado_hick

Well-known member
Based on my research, I understand that the 0 and 1 channels on a AudioOutputI2S would be the right and left audio output.

This is a teensy 3.6 board with the audio shield

However my experiment is suggesting otherwise, this code beeps in both 'ears' each time instead of alternating. I also tried it using different frequencies, still no luck. any ideas?

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

AudioSynthWaveform    waveform[2];
AudioOutputI2S        i2s1;
AudioControlSGTL5000  sgtl5000_1;
AudioConnection       patchCord1(waveform[0], 0, i2s1, 1);
AudioConnection       patchCord2(waveform[1], 0, i2s1, 0);

void setup() {
  // put your setup code here, to run once:
  // get up control buttons
  while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }
    Serial.println("startin up....");  

  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.3);
  waveform[0].begin(WAVEFORM_SINE);
  waveform[0].frequency(440);
  waveform[1].begin(WAVEFORM_SINE);
  waveform[1].frequency(440);

}


void loop() {
  waveform[0].amplitude(.5);
  delay(200);
  waveform[0].amplitude(0);
  delay(2000);
  waveform[1].amplitude(.5);
  delay(200);
  waveform[1].amplitude(0);
 
}
 
Add one more delay at the end of loop(). Like this:

Code:
void loop() {
  waveform[0].amplitude(.5);
  delay(200);
  waveform[0].amplitude(0);
  delay(2000);
  waveform[1].amplitude(.5);
  delay(200);
  waveform[1].amplitude(0);
  delay(2000);
}

Your code is working, but without this delay the two beeps play in rapid succession (400 ms of sound, separated by 2000 ms of silence). The stereo effect is very subtle. I can hear it when listening with good headphones, but even then the reality of human hearing is just not good at perceiving stereo effects when the 2 sounds happen together so rapidly.

With this extra delay at the end, I'm sure you will easily hear your program is indeed working.
 
Hey Paul I caught that also. I fixed it and even changed the frequency on one of the wave forms. What is happening is
1) via the embedded headphone jack on the audio shield I get each channel of the i2s1 equally in both ears. In other words it is a mono signal
2) Via the Line out pins on the audio board I am only getting a single on the right side that is associated with the i2s1 channel 0 frequency. I am not hearing the i2s1 channel 1 frequency at all and I am not getting anything on the left channel.

Did I solder it up wrong? I am on the side row with the middle as a ground, I am not sure what the R/L pins on the outside row are for.

It is possible I would have messed something up if my iron was to hot?

audio small.jpg
New code version, easier to distinguish the waveforms:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

AudioSynthWaveform    waveform[2];
AudioOutputI2S        i2s1;
AudioControlSGTL5000  sgtl5000_1;
AudioConnection       patchCord1(waveform[0], 0, i2s1, 0);
AudioConnection       patchCord2(waveform[1], 0, i2s1, 1);

int current_waveform = WAVEFORM_TRIANGLE;

void setup() {
  // put your setup code here, to run once:
  // get up control buttons

  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.3);
  waveform[0].begin(WAVEFORM_SINE);
  waveform[0].frequency(220);
  waveform[1].begin(WAVEFORM_SINE);
  waveform[1].frequency(440);
  
}


void loop() {
  waveform[0].amplitude(.5);
  delay(500);
  waveform[0].amplitude(0);
  delay(2000);
  waveform[1].amplitude(.5);
  delay(200);
  waveform[1].amplitude(0);
 delay(2000);
}
 
1) via the embedded headphone jack on the audio shield I get each channel of the i2s1 equally in both ears. In other words it is a mono signal

Maybe your headphones are defective, or the stereo plug isn't lining up properly?

I ran your code (msg #3) and listed with good headphones. The sounds absolutely is stereo with my headphones. Something is definitely wrong with your hardware if you're not hearing the sounds separately in each ear!
 
OK, I tried some different headphones and I was able to isolate the different channels. There must have been something getting summed in the first pair.

But I am still unable to get anything out of the left LINE OUT.


If the LINE OUT pinout on the audio shield is labeled like this:

L P1 P2

G P3

R P4 P5

The only signal I get is the Right (i2s1 channel 0) when I run from P3 to P4.

I have tried all of the other combinations and I can not seem to get anything from the Left channel. When I tap into the headphone pins between 'L' and 'VGND' pins along the edge I do get the left channel so I know the signal is there....
 
Status
Not open for further replies.
Back
Top