2

我正在使用https://github.com/jakubfiala/soundtouch-js soundtouch 库对音频文件进行一些音调转换。该库可以很好地进行音调转换,但我不知道如何控制音频文件的通道来打开/关闭它们。

我正在关注这支笔https://codepen.io/ezzatly/pen/LLqOgJ?editors=1010

var source = {
        extract: function (target, numFrames, position) {
            $("#current-time").html(minsSecs(position / (context.sampleRate)));
            console.log('width: ', 100 * position / (bufferDuration * context.sampleRate));
            $("#progress").width(100 * position / (bufferDuration * context.sampleRate) + "%");
            if (Math.round(100 * position / (bufferDuration * context.sampleRate)) == 100 && is_playing) {
                //stop recorder
                recorder && recorder.stop();
                __log('Recording complete.');

                // create WAV download link using audio data blob
                createDownloadLink();

                if (typeof recorder != "undefined") {
                    recorder.clear();
                }
                is_playing = false;
            }
            var l = buffer.getChannelData(0);
            if (buffer.numberofChannels > 1) {
                var r = buffer.getChannelData(1);
            } else {
                var r = buffer.getChannelData(0);
            }
            for (var i = 0; i < numFrames; i++) {
                target[i * 2] = l[i + position];
                target[i * 2 + 1] = r[i + position];
            }
            return Math.min(numFrames, l.length - position);
        }
    };






node.onaudioprocess = function (e) {
        if (buffer.getChannelData) {
            pos += BUFFER_SIZE / context.sampleRate;
            console.log('position: ', pos);
            var l = e.outputBuffer.getChannelData(0);
            var r = e.outputBuffer.getChannelData(1);
            var framesExtracted = f.extract(samples, BUFFER_SIZE);
            if (framesExtracted == 0) {
                node.disconnect();
            }
            for (var i = 0; i < framesExtracted; i++) {
                l[i] = samples[i * 2];
                r[i] = samples[i * 2 + 1];
            }

            leftchannel.push(new Float32Array(l));
            rightchannel.push(new Float32Array(r));
            recordingLength += BUFFER_SIZE;
        }
    };

有什么帮助吗?

4

1 回答 1

3

首先,我的GitHub 中有一个稍微现代化的 SoundTouchJs 版本。可能会使破解稍微容易一些。

其次,您可能希望将ChannelSplitterNode附加到连接的音频上下文。我没有玩过这个,但我认为这就是你需要独立控制每个通道的增益。再说一次,我猜,但希望这能把你推向正确的方向。

于 2019-08-16T12:26:17.110 回答