I would like to ask if someone could help me with ring modulation using javascript
Here is my code. I am not sure if I am doing this right. On start button it only plays a oscillator with gain. No mix with audio file.
I tried do something like this GitHub source
Thanks
function audioFileLoader(fileDirectory, impulseFileDirectory) {
var audioContext = new AudioContext();
var soundObj = [];
soundObj.fileDirectory = fileDirectory;
soundObj.impulseFileDirectory = impulseFileDirectory;
// buffer loader code
var getSound = new XMLHttpRequest();
getSound.open("GET", soundObj.fileDirectory, true);
getSound.responseType = "arraybuffer";
getSound.onload = function() {
audioContext.decodeAudioData(getSound.response, function(buffer) {
soundObj.soundToPlay = buffer;
});
}
getSound.send();
soundObj.play = function() {
var source = audioContext.createBufferSource();
source.buffer = soundObj.soundToPlay;
var oscillator = audioContext.createOscillator();
oscillator.type = 'sine';
oscillator.frequency.value = 500;
var gainNode = audioContext.createGain();
gainNode.gain.value = 0.5;
oscillator.connect(gainNode);
source.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.start(audioContext.currentTime);
};
return soundObj;
};
var example = audioFileLoader("audio/AcGtr.wav");
document.getElementById('ringmodulation').addEventListener("click", example.play,
false);
Your code never plays the buffer source, it's missing source.start(). Also var soundObj = [] should be var soundObj = {}.