Javascript limitation issue in JavaScript

I have a bit of a problem limiting the duration of this oscillator to about 10 seconds using audiolib.js. When I used the dsp.js library, I limited the duration to using bufferSize, but I absolutely do not know how to do this using the audiolib.js library ... Any help would be great! While I am in this, can anyone tell me the maximum and minimum frequency and amplitude?

$(document).ready(function () { //var context = new webkitAudioContext(); var playing; var dev = audioLib.AudioDevice(audioCallback, 2); var osc = audioLib.Oscillator(dev.sampleRate, 440); //var bfo = audioLib.Oscillator(dev.sampleRate, 1.0); //osc.addAutomation('frequency', bfo, 0.5, 'modulation'); osc.waveShape = 'pulse'; function audioCallback(buffer, channelCount) { if (playing) { //bfo.generateBuffer(buffer.length / channelCount); osc.append(buffer, channelCount); //remove the audiocallback function } } $('#playButton').click(function () { playing = true; }); }); 

Hooray!

+4
source share
1 answer

The sampling rate is the number of samples per second, so you can calculate the number of reproduced samples by multiplying the sampling rate of 10 seconds:

 var maxSamples = dev.sampleRate * 10; 

Then you can use it as follows:

 $(document).ready(function () { var playing; var dev = audioLib.AudioDevice(audioCallback, 2); var osc = audioLib.Oscillator(dev.sampleRate, 440); var maxSamples = dev.SampleRate * 10; var totalSamples = 0; osc.waveShape = 'pulse'; function audioCallback(buffer, channelCount) { if (playing) { osc.append(buffer, channelCount); totalSamples += buffer.length / channelCount; if (totalSamples >= maxSamples) { // remove audioCallback dev.kill(); } } } $('#playButton').click(function () { playing = true; }); }); 
+1
source

Source: https://habr.com/ru/post/1399189/


All Articles