Audio library : left and right channel output control?

Status
Not open for further replies.

Blitter

Member
I have two WAVs (each in full stereo), and a fully functioning Audio Adaptor board. I'd like one WAV to play only in the left ear, and the other to play only in the right.

I know I can just alter the WAV file in Audacity, and shift it 100% right, or 100% left, but I'd like to do it programatically in the Teensy.

Does any class in the Audio library support Left/Right lineout and headphone control? I checked the mixer class, but didn't see it.
 
I have two WAVs (each in full stereo), and a fully functioning Audio Adaptor board. I'd like one WAV to play only in the left ear, and the other to play only in the right.

I know I can just alter the WAV file in Audacity, and shift it 100% right, or 100% left, but I'd like to do it programatically in the Teensy.

Does any class in the Audio library support Left/Right lineout and headphone control? I checked the mixer class, but didn't see it.

basically i guess you'd just have to mix down the left and right channels with a mixer object. then hard pan left/right. somewhat like so?


Code:
// GUItool: begin automatically generated code
AudioPlaySdWav           playWav1;       //xy=163,131
AudioPlaySdWav           playWav2;       //xy=164,246
AudioMixer4              mixer1;         //xy=373,144
AudioMixer4              mixer2;         //xy=382,259
AudioOutputI2S           i2s1;           //xy=556,223
AudioConnection          patchCord1(playWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playWav1, 1, mixer1, 1);
AudioConnection          patchCord3(playWav2, 0, mixer2, 0);
AudioConnection          patchCord4(playWav2, 1, mixer2, 1);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code
 
Thanks for the help, mxxx. I understand the mixing, but I am unaware of a pan function. When you say "hard pan left/right", how do you suggest this be done?
 
I'd like one WAV to play only in the left ear, and the other to play only in the right.

Well, that's very easy. You don't need a special panning object.

Just create 2 wav players. Connect the left (1st) output from one to the left (1st) input of the I2S object, and the left (1st) output of the other wav player to the right (2nd) input of the I2S object.
 
Like this:

2wav.png
 
Thanks for the help, mxxx. I understand the mixing, but I am unaware of a pan function. When you say "hard pan left/right", how do you suggest this be done?

by 'hard pan' i simply meant one mixer object goes to the left channel output, the other to right one -- as in paul's second picture (or the exported code above). the mixers are because you said you were using stereo files. you don't need them for mono.

as for panning, there's no pan object per se but the mixer object comes with a function called gain(channel, level);

so i guess you could do something like:

pan.jpg

Code:
// left ch
mixer1.gain(0, 1.0f);
mixer2.gain(0, 0.0f);
// right ch
mixer1.gain(1, 0.0f);
mixer2.gain(1, 1.0f);

and then play with 'level'. i guess a special pan object would still be nice eventually, ie one which could be fed a LFO or some other signal. it's probably not too difficult to come up with one based on the existing mixer object
 
Bingo! Thanks for the help, guys.

I hadn't thought to mix both stereo channels of each WAV into a single channel with a mixer, and then feed that into the I2S In separate channels.

On a related note, while I think the audio designer tool is darned clever, if the inputs and outputs of the stereo-enabled objects were marked with little "L"s and "R"s, that would sure help us newbies!
 
On a related note, while I think the audio designer tool is darned clever, if the inputs and outputs of the stereo-enabled objects were marked with little "L"s and "R"s, that would sure help us newbies!

That would be nice. The javascript source is here, if anyone wants to try adding it:

https://github.com/PaulStoffregen/Audio/tree/master/gui

At the very least, you might open a feature request on the issue tracker. That's not likely to cause it to happen anytime soon, but at least it'll be remembered with the audio libr code, instead of lost in an old forum thread.

https://github.com/PaulStoffregen/Audio/issues
 
Status
Not open for further replies.
Back
Top