We are about to switch to a new forum software. Until then we have removed the registration on this forum.
If I had code like:
var sampleRate = 44100;
function soundWave(x) {
return sin(x*700)*exp(-x);
}
var duration = 10; //In seconds
var data = [];
for (var i=0;i<sampleRate*duration;i++) {
data[i] = soundWave(i/sampleRate);
}
How should I able to play the sound?
Answers
not sure it'll work this way
please google sound library minim
ugens within minim
http://code.compartmental.net/minim/waves_field_sine.html
http://code.compartmental.net/tools/minim/
@Chrisir: check the category before replying ;)
@ Anastasia_Dunbar: you need the p5js sound library, which includes an [oscillator]
@Chrisir I tried minim for Java but I never found a way to generate my own sounds.
@blindfish Where can I read about buffers?
oh, sorry, minim is not for p5
@Anastasia_Dunbar : can you be more specific. What kind of buffers? WHat does that have to do with your original question? Have you checked the sound library documentation and searched for oscillator?
@blindfish To make a (16/32 bit) buffer made out of soundWave(), buffers can be played as sounds right? I don't wanna use oscillators. Check out this for example or even this.
the oscillators are probably using buffers behind the scenes...
anyway, look at the source of that example you posted and you can see what he uses for playing generated samples
<script src="http://www.js.do/sound/js/riffwave.js"></script>
and his draw_and_play() function
@Anastasia_Dunbar The thread has been stopped for a while, but I have been trying something similar recently. I think sample-by-sample synthesis or processing is not possible with the current version of the p5.audio library. Perhaps you should use the "Web Audio API". I have not tried it yet, so I'm not sure, though.