Multiple sources for AudioContext() - javascript

I have two one-second audio sources as follows:
var context = system.AudioContext();
var source = context.createBufferSource();
var audioBuffer1 = context.createBuffer(1, float32Array_1.length, context.sampleRate);
audioBuffer1.getChannelData(0).set(float32Array_1);
var audioBuffer2 = context.createBuffer(1, float32Array_2.length, context.sampleRate);
audioBuffer2.getChannelData(0).set(float32Array_2);
Now I want to play these two audio sources with no delay between them. For a single source I can play the audio with the following code:
source.buffer = audioBuffer1;
source.connect(context.destination);
source.start(0);
How can I attach the second source such that there would be no delay between them.

var context = system.AudioContext();
var source = context.createBufferSource();
var source2 = context.createBufferSource();
var audioBuffer1 = context.createBuffer(1, float32Array_1.length, context.sampleRate);
audioBuffer1.getChannelData(0).set(float32Array_1);
var audioBuffer2 = context.createBuffer(1, float32Array_2.length, context.sampleRate);
audioBuffer2.getChannelData(0).set(float32Array_2);
source.buffer = audioBuffer1;
source.connect(context.destination);
source2.buffer = audioBuffer2;
source2.connect(context.destination);
var time = context.currentTime;
source.start(time);
source2.start(time+audioBuffer1.duration);

Related

I get an error when trying to save a sine wave audio as a .wav file

What I'm trying to do here is play and record a simple sinusoidal wave for a few seconds and save it as a .wav file when the recording is stopped. But, I'm getting this error and the .wav file is empty.
ERR_REQUEST_RANGE_NOT_SATISFIABLE
ERROR MESSAGE:
Here is my full code.
FULL CODE:
<button onclick="play();">PLAY</button>
<button onclick="r.stop();">STOP</button>
<ul id="recordingslist"></ul>
<script type="text/javascript">
const context = new AudioContext();
const stream = context.createMediaStreamDestination();
let o = null,
g = null,
r = null;
function play(){
o = context.createOscillator();
g = context.createGain();
r = new MediaRecorder(stream.stream);
o.type = "sine";
o.connect(g);
o.connect(context.destination);
o.start();
r.start();
r.ondataavailable = function(e) {
var url = window.URL.createObjectURL(e.data);
var li = document.createElement('li');
var au = document.createElement('audio');
var hf = document.createElement('a');
au.controls = true;
au.src = url;
hf.href = url;
hf.download = new Date().toISOString() + '.wav';
hf.innerHTML = hf.download;
li.appendChild(au);
li.appendChild(hf);
document.getElementById('recordingslist').appendChild(li);
o.stop();
};
}
</script>
A few things here.
Regarding the MediaRecorder part, the dataavailable event may fire at any time the browser deems necessary, it may even fire with no data at all.
If you want to record a fixed duration of time, then listen for the stop event to build your download link, and use the dataavailable one only to push the chunks of data the browser will have output during that time:
Regarding the AudioContext part,
you can think of the link connection as a [guitar - pedal(s) - pre-amp - ampli] setup. Each connect being a new wire between two nodes.
In your setup, you did create a gain node, and did connect your oscillator to it, you now need to connect your gain node (g) to the MediaStreamDestinationNode (stream) if you want to record it. Failing to do so, nothing will get passed to the recorder since the stream-destination node will not be connected to anything.
const context = new AudioContext();
const stream = context.createMediaStreamDestination();
document.getElementById('btn').onclick = play;
function play() {
const o = context.createOscillator();
const g = context.createGain();
const r = new MediaRecorder(stream.stream);
o.type = "sine";
g.gain.value = 0.5;
o.connect(g);
// you want to connect the gainNode to the stream-dest
g.connect(stream);
// and to the context's dest (speakers)
g.connect(context.destination);
o.start(0);
// we need an Array to store all the chunks
const chunks = [];
// in dataavailable we only push the new chunks
r.ondataavailable = function(e) {
chunks.push(e.data);
};
// we wait until the recorder has been stopped to build the final media
r.onstop = function(e) {
// concatenate all the chunks in a single Blob
const blob = new Blob(chunks);
const url = window.URL.createObjectURL(blob);
const li = document.createElement('li');
const au = document.createElement('audio');
const hf = document.createElement('a');
au.controls = true;
au.src = url;
hf.href = url;
// setting the filename's extension won't make it a wav file
// what you have here is an ogg-vorbis audio file.
hf.download = new Date().toISOString() + '.oga';
hf.innerHTML = hf.download;
li.appendChild(au);
li.appendChild(hf);
document.getElementById('recordingslist').appendChild(li);
o.stop();
};
r.start();
// stop the recording in 3s
setTimeout(() => {
r.stop();
}, 3000);
}
<button id="btn">start</button>
<ul id="recordingslist"></ul>

How to reconstruct audio blob from a base64 encoded String?

I am capturing audio data via JavaScript and intend to send it as a base64 encoded String. Before I even send it, I'm just testing to see if I can reconstruct it and play it, and I'm not having much luck.
In the console, the blob looks like this:
How can I retrieve the initial audioBlob object from the base64 encoded data produced by reader.readAsDataURL(audioBlob) so that I can play it in its correct form?
mediaRecorder.addEventListener("dataavailable", function(event) {
audioChunks.push(event.data);
var audioBlob = new Blob(audioChunks);
// PLAYBACK WORKS HERE!
var audioUrl = URL.createObjectURL(audioBlob);
var audio = new Audio(audioUrl);
audio.play();
var reader = new FileReader();
reader.onload = function(event){
var audioData = event.target.result;
// extracting and decoding just the bas64 data, attempting to reconstruct audioBlob
var base64 = audioData.substr(audioData.lastIndexOf(',') + 1);
var decoded = atob(base64);
var reconstructedAudioBlob = new Blob([decoded], {type: "audio/webm;codecs=opus"});
// PLAYBACK FAILS HERE!
var reconstructedAudioUrl = URL.createObjectURL(reconstructedAudioBlob);
var reconstructedAudio = new Audio(reconstructedAudioUrl);
reconstructedAudio.play();
};
reader.readAsDataURL(audioBlob);
});
This results in a console error: Uncaught (in promise) DOMException
The data for event.target.result (if you manage to decode it and play it, enjoy!) is as follows:
data:application/octet-stream;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFhyclHzqvN7GDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgSAfQ7Z1Af/////////ngQCjQYaBAACA+4OzXnuBgl3yyb73GghmlCLmSdXgQI06MTtujZRqPyATqeUwfvNvGcyG294bqH2N0pn9suUh0Isrnb+78cMVsv3mrXfgvINYLCWNse+9ZdGNrhK7p+ueu++U0fuF9PT1U1C3EJ9vGtZdrExDWxkSdBqe2bVXeRN4UmR/PwuoGqKhZyOrqv4dAiLQWOb57aehbFKajj0G1OJCohFYWMurToiKnWuyC9KnMug1XaIhWBwy0/xYspbtXi5Z1KmTaxUdk6UFCSjZ3lxZzuUZc/O+llp74d4Fygx8HBfXDACq2QuEwAIR+rOm3o70e6i8D7h4dr+Vk1B3e8sN5ne8aPNZzjR0hKdKkPz9hW8GMPll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3LyLSkmyseVRwt8QwMKIQTham1V7Hskt+fKQLH87S1amlxBrRGV26uDMP3EeNbj2CmW1XTotpGJGLo+5yDehRBPtwWqnfC/6CMnwwQQFpH8ErQN+blyAf+m6I/4oNc2ndwlPDiPtKmKxU7R2Zx2wz1mH4pBPoycVtRteCOH7uNxEgLaf/uSp4pVIP/rpt45/vHLFvyodBAJyZv4E8u8S2vDJwB5hBG+IPoNowADNXLoFz52DaL3kYRM+QBdspBFqd5pbz3Cq9DW0qjIHOC2ULqvEx8he29NO2+Dh1D2pejK5ntirU9Jw7h8Nj5HXWkwLL3uFzWFTMhHsXD1MbSn6GDaVy01nEutHz040Og2WiTcBEXCaMNcfzRVL9AA6zCJ9/KYKpVFGNUT8CbmjZC88jIriZTV5Wwio0/Dl/f0Ujpq7WaUNQ3eawlgGm2VbY1Sqt7bk+obq42gnBIq2/iG4Kh3A2z3b89ZjVSlZRoeuEqtcnj7fUV0fcP3DwQnIEBM/bUCLgFKUy6P6ewlmK3Ig2N+KQjG7iOKSo=
You're on the right track. I would create a function that converts the URI to pure binary by removing the base64 headers, and then setting that as the audio source. Using your data, this should do the trick:
function convertURIToBinary(dataURI) {
let BASE64_MARKER = ';base64,';
let base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
let base64 = dataURI.substring(base64Index);
let raw = window.atob(base64);
let rawLength = raw.length;
let arr = new Uint8Array(new ArrayBuffer(rawLength));
for (let i = 0; i < rawLength; i++) {
arr[i] = raw.charCodeAt(i);
}
return arr;
}
let binary = convertURIToBinary(data);
let blob = new Blob([binary], {
type: 'audio/ogg'
});
let blobUrl = URL.createObjectURL(blob);
$("#source").attr("src", blobUrl);
$("#audio")[0].load();
$("#audio")[0].oncanplaythrough = $("#audio")[0].play();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<audio id="audio" controls>
<source id="source" src="" type="audio/ogg" />
</audio>
<script>
let data = "data:application/octet-stream;base64,GkXfo59ChoEBQ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FKUy6P6ewlmK3Ig2N+KQjG7iOKSo=";
</script>

how to Convert ByteArray to AudioBuffer and play in Javascript

I want to decode an bytearray to audiobuffer and play my wav file in browser using JS.
Here the code i am using but while clicking on play button i am getting an exception i.e. "Unable to decode audio Data".
{
if (!window.AudioContext){
if (!window.webkitAudioContext){
alert("Your browser does not support any AudioContext and cannot play back this audio.");
return;
}
}
var context = new AudioContext();
var arr = me.queueStore.getAt(0).data.ByteAudio;
var arrayBuffer = new ArrayBuffer(arr.length);
var bufferView = new Uint8Array(arrayBuffer);
for (i = 0; i < arr.length; i++) {
bufferView[i] = arr[i];
}
context.decodeAudioData(bufferView, function (buffer) {
var source = context.createBufferSource(); // creates a sound source
source.buffer = buffer; // tell the source which sound to play
source.connect(context.destination);
source.start(0);
});
}
Got the answer , here the solution for this : Use 64bit string to play media files instead converting to audio buffer :
me.fileString = "data:audio/wav;base64," + data.tonebyteArray;
var audio = new Audio(fileString);
audio.play();

BinaryJs + Audio API schedule array buffers

I have a node.js server streaming some ArrayBuffers:
var BinaryServer = require('binaryjs').BinaryServer;
var fs = require('fs');
var server = BinaryServer({port: 2000});
server.on('connection', function(client){
var file = fs.createReadStream(__dirname + '/music/02 Enter Sandman.mp3');
client.send(file);
});
On the client, I'm listening to those chunks and trying to play them one after another:
var client = new BinaryClient('ws://localhost:2000');
var context = new AudioContext();
var source = context.createBufferSource();
source.connect(context.destination);
var audioStart = 0;
var audioStop = 0;
client.on('stream', function(stream, meta)
{
stream.on('data', function(data)
{
var audio = new Float32Array(data);
var audioBuffer = context.createBuffer(1, audio.length, 44100);
audioBuffer.getChannelData(0).set(audio);
audioBuffer = context.createBuffer(data, true);
audioStop += audioBuffer.duration;
source = context.createBufferSource();
source.connect(context.destination);
source.buffer = audioBuffer;
source.start(audioStart);
//source.stop(audioStop);
console.log(audioStart + " - " + audioStop);
audioStart += audioBuffer.duration;
});
});
I'm constantly getting this error: Uncaught InvalidStateError: Failed to execute 'start' on 'AudioBufferSourceNode': cannot call start more than once.
Only the first chunk plays
Could someone explain me how this supposed to work?
Thanks!
The problem come with Web Audio API, you can't load two or more sources in the same channel.
You can disconnect source with: source.disconnect();
and reconnect him with: source.connect(context.destination);
More information here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

OfflineAudioContext FFT analysis with chrome

i'm trying to build a waveform generator that get audiofile amplitudes values and display them to a canvas as quick as possible (faster than realtime) in javascript. so i use the OfflineAudioContext / webkitOfflineAudioContext , load the file and start the analyse.
the waveform is to fill a wide canvas.
i analyse buffer in a processor.onaudioprocess function. (i guess it's the way it works ?)
it works fine in firefox but i've got an issue in chrome : it seems it "jumps" over much analyse to finish it works as soon as possible and only returns a few coordinates (something like 16).
here is the jsfiddle :
http://jsfiddle.net/bestiole/95EBf/
// create the audio context
if (! window.OfflineAudioContext) {
if (! window.webkitOfflineAudioContext) {
$('#output').append('failed : no audiocontext found, change browser');
}
window.OfflineAudioContext = window.webkitOfflineAudioContext;
}
//var context = new AudioContext();
var length = 15241583;
var samplerate = 44100;
var fftSamples = 2048;
var waveformWidth = 1920;
var context = new OfflineAudioContext(1,length,samplerate);
var source;
var splitter;
var analyser;
var processor;
var i=0;
var average;
var max;
var coord;
processor = context.createScriptProcessor(fftSamples, 1, 1);
processor.connect(context.destination);
analyser = context.createAnalyser();
analyser.smoothingTimeConstant = 0;
analyser.fftSize = fftSamples;
source = context.createBufferSource();
splitter = context.createChannelSplitter();
source.connect(splitter);
splitter.connect(analyser,0,0);
analyser.connect(processor);
context.oncomplete = function(){
$('#output').append('<br />complete');
}
var request = new XMLHttpRequest();
request.open('GET', "http://www.mindthepressure.org/bounce.ogg", true);
request.responseType = 'arraybuffer';
request.onload = function(){
$('#output').append('loaded ! ');
context.decodeAudioData(request.response, function(buffer) {
$('#output').append('starting analysis<br />');
processor.onaudioprocess = function(e){
var data = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(data);
average = getAverageVolume(data);
max = Math.max.apply(Math, data);
coord = Math.min(average*2,255);
coord = Math.round((max+coord)/2);
ctx.fillStyle=gradient;
ctx.fillRect(i,255-coord,1,255);
console.log(i+' -> '+coord);
i++;
}
source.buffer = buffer;
source.start(0);
context.startRendering();
}, onError);
}
request.send();
function onError(e) {
$('#output').append('error, check the console');
console.log(e);
}
function getAverageVolume(array) {
var values = 0;
var average;
var length = array.length;
for (var k = 0; k < length; k++) {
values += array[k];
}
average = values / length;
return average;
}
(here is another version that forces waveform to fit in 1920px wide and generate a waveform data for who is interested : http://jsfiddle.net/bestiole/E3rSx/ )
i really dont get the point, how doesn't chrome treat every part of the audio file ?
thanks for any help !
Chrome has a bug in script processors in offline mode.

Categories

Resources