crunker icon indicating copy to clipboard operation
crunker copied to clipboard

getting a single channel output from a stereo audio source

Open praveenpuglia opened this issue 5 years ago • 5 comments

My source audio is stereo but once I merge I only get sound from single channel. The other channel is lost.

I am guessing this is because concat / merge methods only take channel 0 into account ?

praveenpuglia avatar May 06 '19 14:05 praveenpuglia

Yes that is currently how it works, I'm sure there is a way to get stereo output if you'd like to investigate. But i recall spending time on this previously with no solution.

jaggad avatar May 06 '19 22:05 jaggad

I wish I had known more about WebAudio API to be of any help. Wondering if this would be of any help to you. https://developer.mozilla.org/en-US/docs/Web/API/AudioNode/channelInterpretation

praveenpuglia avatar May 08 '19 05:05 praveenpuglia

Two channels can be merged.

guest271314 avatar Mar 21 '21 16:03 guest271314

I got stereo channels to export when I swapped the default _interleave method with this one

private _interleaveStereo(input: AudioBuffer): Float32Array {
  const [left, right] = [input.getChannelData(0), input.getChannelData(1)];
  const result = new Float32Array(left.length + right.length);

  for (let src = 0, dst = 0; src < left.length; src++, dst += 2) {
    result[dst] = left[src];
    result[dst + 1] = right[src];
  }
  return result;
}

When I find some time I'll try submitting a PR

spajo avatar Apr 02 '22 14:04 spajo

Very interesting. Nice work @spajo, would be appreciated whenever you can 👍

jaggad avatar Apr 03 '22 05:04 jaggad

@praveenpuglia @jaggad I made a PR (linked above) that should fix this issue. The problem was indeed with the exporting, the merge/concat worked fine with stereo.

MikeyZat avatar Sep 02 '22 06:09 MikeyZat

Good timing. I just left a review.

jaggad avatar Sep 02 '22 06:09 jaggad

I was taken aback when I received a notification for this repo. I was like wow this is still active! Appreciate it! <3 Fun fact, I left the company where I actually needed it over a year ago! :D I have lost the context too.

Thanks @MikeyZat @jaggad for your work.

praveenpuglia avatar Sep 02 '22 16:09 praveenpuglia