hi all,
I’m trying to see if I can replicate a vocal removal effect I found and implemented in JavaScript with SDL audio
and am having some trouble (but I think it should be possible?).
Here’s the relevant JavaScript code I’m trying to implement with SDL_Audio:
var audioData = [];
var leftChan = buffer.getChannelData(0);
var rightChan = buffer.getChannelData(1);
for(var i=0;i<leftChan.length;i++){
var currentSample = (leftChan[i] - rightChan[i])/2; //this is what causes the vocal removal
audioData.push(currentSample);
}
audioToKaraoke = audioCtx.createBuffer(1, buffer.length, buffer.sampleRate);
audioToKaraoke.getChannelData(0).set(audioData);
You can try it here: https://syncopika.github.io/misc/karaokeget.html
As far as I understand, Web Audio uses Float32Arrays to store audio data.
For example, when I load a particular WAV sample, I get these data for the first few entries in the left and right
channel buffer with the JavaScript code:
left: 0 right: 0
left:-0.00003051757 right:-0.00003051757
left: 0.000061037 right: 0.000061037
left:-0.000061035 right:-0.000061035
left: 0.000061037 right: 0.0000305185
left:-0.000061035 right: 0
…
In SDL after I load my WAV sample (the same one used to generate the values above) to an AudioSpec, I checked the properties and it shows that I have 2 channels, with the format being AUDIO_S16LSB (32784 was printed). When I printed the first few values of the audio data, I got:
0
0
0
0
255
255
255
255
2
0
2
0
254
255
254
255
2
0
1
0
Based on the documentation I read, since my sample is in stereo with 2 channels, each byte belongs to either the left or right channel. So I think the left channel’s bytes would be [0, 0, 255, 255, 2, 2, 254, 254, …], and the right would be [0, 0, 255, 255, 0, 0, 255, 255, …].
But I’m not sure how to proceed from here.
One thing I tried was using the LoadWAV function to get the Uint8 audio data, separate the data into channel buffers, create a float vector to store the result after doing some math on each left and right channel data, copy the bytes of the float vector data to a new Uint8 buffer, and then pass that new buffer to an AudioSpec with 1 channel, but that didn’t work.
Thanks for reading!