Play one beep (beep.js)

I am trying to create a "generative score" using beep.js based on some map data that I have. I use new Beep.Voice as a placeholder for notes related to specific data types (7 votes total). When displaying data, a voice should be played. I have been doing brute force stuff so far, and I would like it to be cleaner:

 // in the data processing function voice = voices[datavoice] voice.play() setTimeout(function(){killVoice(voice)}, 20) // and the killvoice: function killVoice(voice) { voice.pause() } 

I would just like to β€œplay” the voice, assuming that it will have a duration of, say, 20 ms (basically, just an audio signal). I saw the duration property of voices, but could not get them to work.

code here (uses grunt / node / coffeescript):

https://github.com/mgiraldo/inspectorviz/blob/master/app/scripts/main.coffee

this is how it looks:

https://vimeo.com/126519613

+5
source share
2 answers

Forget everything I said;)

Inspired by your request - and the old request for Sam's attempt - I just completed the big step of ADSR, which includes support for Voice duration. So, now with the latest Beep.js, getting a quick "chiptune-y" chirp can be done as follows:

 var voice = new Beep.Voice( '4Dβ™­' ) .setOscillatorType( 'square' ) .setAttackDuration( 0 ) .setDecayDuration( 0 ) .setSustainDuration( 0.002 ) .setReleaseDuration( 0 ) .play() 

Ive even included an ASCII-art ADSR diagram in the new Beep.Voice.js file for easier reference. Hope this helps!

+2
source

The reason Beep.Voice.duration documented in READ ME because it is not finished yet !;) Theres a line in the source code that literally says "Now they are not doing anything, just here, as a stand for the future." This applies to .duration , .attack , etc. Theres requires a request to implement some of these functions here , but I had to do some important things since this request was submitted; You will need to take a closer look as soon as Ive finished fixing some of the larger structural problems. (I promise!)

Your approach, meanwhile, seems right for the money. Ive reduced it a bit and made it 200 milliseconds, not 20, so I could do a little more here:

 var voice = new Beep.Voice('4Dβ™­') voice.play() setTimeout( function(){ voice.pause() }, 200 ) 

I saw that you used rather small notes in your code example, for example, β€œ1A ♭”. If you just test this on regular laptop speakers - this is the place I go to often, you may find that the tone is too low for your speakers; You will hear a ticking or dead silence. So don’t worry: this is not a mistake, just a hardware problem :)

+3
source

All Articles