jaggad / crunker

Simple way to merge or concatenate audio files with the Web Audio API.
https://jaggad.github.io/crunker/examples/client/
MIT License
433 stars 59 forks source link

getting a single channel output from a stereo audio source #21

Closed praveenpuglia closed 2 years ago

praveenpuglia commented 5 years ago

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 ?

jaggad commented 5 years ago

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.

praveenpuglia commented 5 years ago

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

guest271314 commented 3 years ago

Two channels can be merged.

spajo commented 2 years ago

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

jaggad commented 2 years ago

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

MikeyZat commented 2 years ago

@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.

jaggad commented 2 years ago

Good timing. I just left a review.

praveenpuglia commented 2 years ago

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.