kbumsik / opus-media-recorder

MediaRecorder polyfill for Opus recording using WebAssembly
http://kbumsik.io/opus-media-recorder/
Other
308 stars 39 forks source link

Channel Count always 2? #70

Open dalisalvador opened 1 year ago

dalisalvador commented 1 year ago

The number of channels on dataavailable ALWAYS seems to be 2(stereo). No matter the source stream, the output stream always has 2 channels.

I need to get a mono output but I can't accomplish this.

Is there any way to achieve this?

Thanks


recorder = new OpusMediaRecorder(dest.stream <<=== MONO, { mimeType: 'audio/ogg; codecs=opus' }, workerOptions)
recorder.addEventListener('dataavailable', async function (e) {
    if (e.data.size > 0) {
        const offlineAudioContext = new OfflineAudioContext({
            length: 1,
            sampleRate: 48000
        })
        const audioBuffer = await offlineAudioContext.decodeAudioData(await e.data.arrayBuffer())
        console.log(audioBuffer.numberOfChannels) <<< 2!!!              }
    })
dalisalvador commented 1 year ago

I think I found the problem.

The source stream is actually a stereo stream that is processed, converted to mono, and then sent to a destination.

For some reason, only happening in chrome (I think there's an open issue/bug) the getSettings().channelCount will always return 2 even though it was previously changed to 1. This will ultimately affect the line below (see OpusMediaRecorder.js)

this.channelCount = tracks[0].getSettings().channelCount || 1;

I think that the constructor should have the optional channelCount... if it's ok I could create a PR