使用soundtouch-js在多声道模式下音高移位

时间:2017-07-13 11:08:47

标签: javascript soundtouch

我正在使用https://github.com/jakubfiala/soundtouch-js soundtouch库对音频文件进行一些音高变换。 lib可以正常工作,但我不知道如何控制音频文件的通道来打开/关闭它们。

我正在关注此笔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;
        }
    };

任何帮助?

1 个答案:

答案 0 :(得分:0)

首先,我有一个slightly more modernized version of SoundTouchJs in my GitHub。可能会使黑客更容易些。

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