webaudio Не получается второй раз по кнопке подмешивать шум к непрерывному генератору, как решить?
демо тут: https://codepen.io/uxjzbmxq-the-sans/pen/KwdGJLm?editors=1111
интернет отсылает меня сюда https://developer.chrome.com/blog/web-audio-faq Но там по ссылке вообще не по теме моей.
<body>
<button id='start' class="b1" onclick='WebaudioEnable()'>enable WEBAUDIO </button>
<button id='Pause' class="b1"onclick='Pause()'>Pause</button>
<button id='play'class="b1" onclick='Play()'>Play</button>
<button id='GetFromBuffer'class="b1" onclick='GetFromBuffer()'>Play noise from bufer</button>
<script>
function WebaudioEnable()
{ auCtx.resume()
};
var auCtx = new AudioContext();
var source = auCtx.createBufferSource();
var gain = auCtx.createGain();
var osc = auCtx.createOscillator();
var dest = auCtx.destination;
function GetFromBuffer()
{
const frameCount = auCtx.sampleRate * 1.0;
if (1)
{
var buffer = new AudioBuffer
(
{
numberOfChannels: 1,
length: frameCount,
sampleRate: auCtx.sampleRate,
}
);
}
//noise generate.....
for (let channel = 0; channel < 1; channel++)
{
const nowBuffering = buffer.getChannelData(channel);
for (let i = 0; i < frameCount; i++)
{
nowBuffering[i] = Math.random() * 2 - 1;
}
}
source.buffer = buffer;
source.start();
source.onended = () =>
{
console.log("White noise finished.");
};
};
//connect nodes
osc.connect(gain);
source.connect(gain);
gain.connect(dest);
osc.start();
//end connect nodes
//buttons set reaction
function Pause()
{
gain.gain.value = 0;
}
function Play()
{
gain.gain.value = 1;
}
//end buttons set reaction
</script>
</body>