Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use a two channel script processor even for mono recordings #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ccampbell
Copy link

This is a difficult thing to explain, but basically if you have an interface containing multiple input channels and you record in stereo on only one of the channels, the script processor node will mix down the channels to mono, and the resulting signal level will be cut in half.

In order to reproduce you have to

  • Use a recording interface with separate input channels for left and right
  • Call navigator.getUserMedia with echoCancellation: false constraint
  • Plug a microphone or instrument into only the left channel of your interface

I thought this was a browser bug and put together a demo here
https://craig.is/demoing/web-audio-script-processor-bug

It turns out this is the expected behavior though. When your input is stereo with sound only coming into one channel and you pass to a mono ScriptProcessorNode, it sums the left and right channels to a single mono channel and the resulting recording ends up half the level you recorded it at.

This change should be backwards compatible, because all of the other checks are still checking the numChannels so the only difference is how the ScriptProcessorNode deals with the input audio

This is a difficult thing to explain, but basically if you have an
interface containing multiple input channels and you record in stereo
on only one of the channels, the script processor node will mix down
the channels to mono, and the resulting signal level will be cut in
half.
@ccampbell
Copy link
Author

Also wanted to ping @agrueneberg since he was the one who added the mono code that introduced this change to begin with.

@agrueneberg
Copy link
Contributor

To be honest I didn't have much chance to record in mono since I had to put the project I was working on back then on ice—but you're right: I also noticed that mono recordings are less loud. Summing up both channels makes sense, and I don't know why I even used numChannels for the number of input channels.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants