2

I am using https://github.com/jakubfiala/soundtouch-js soundtouch library to do some pitch shifting on audio files. the lib works fine with pitch shifting but I don't know how to control the audio file's channels to switch them on/off.

I am following this pen 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;
        }
    };

any help?

1 Answers1

3

First, I have a slightly more modernized version of SoundTouchJs in my GitHub. Might make it slightly easier to hack around.

Second, you probably want to attach a ChannelSplitterNode to your connected audio context. I haven't played with this, but I would think that's what you would need to independently control the gain on each channel. Again, I'm guessing, but hopefully that'll push you in the right direction.

Steve -Cutter- Blades
  • 5,057
  • 2
  • 26
  • 40