Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Audio library : left and right channel output control?

  1. #1

    Audio library : left and right channel output control?

    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.

  2. #2
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    Quote Originally Posted by Blitter View Post
    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

  3. #3
    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?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,238
    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.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,238
    Like this:

    Click image for larger version. 

Name:	2wav.png 
Views:	102 
Size:	11.5 KB 
ID:	4710

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,238
    Or like this (which I think is the same as MXXX suggested):

    Click image for larger version. 

Name:	2wav2.png 
Views:	99 
Size:	14.5 KB 
ID:	4711

  7. #7
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    Quote Originally Posted by Blitter View Post
    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:

    Click image for larger version. 

Name:	pan.jpg 
Views:	109 
Size:	32.5 KB 
ID:	4715

    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

  8. #8
    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!

  9. #9
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    as an aside / speaking of gui tools. this looks pretty neat, too: https://enzienaudio.com/ ... (another reason to look forward to teensy 3++, i suppose.)

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,238
    Quote Originally Posted by Blitter View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •