mohayonao / timbre.js Goto Github PK
View Code? Open in Web Editor NEWJavaScript library for objective sound programming
Home Page: http://mohayonao.github.io/timbre.js/
License: MIT License
JavaScript library for objective sound programming
Home Page: http://mohayonao.github.io/timbre.js/
License: MIT License
timbre.js looks broken on iOS devices.
It looks broken since 199775c .
I used code below and checked with git bisect start master 4df0821
.
c858ad1 plays sin wave, but 199775c doesn't play in iOS simulator.
<html>
<body>
<h1>Click me</h1>
<script src="timbre.dev.js"></script>
<script>document.querySelector('h1').onclick=function() { console.log('click'); T("sin").play(); }</script>
timeout looks broken since 199775c .
c858ad1 displays ended, but 199775c doesn't display ended.
<html>
<body>
<h1>Click me</h1>
<script src="timbre.dev.js"></script>
<script>
document.querySelector("h1").onclick=function() {
document.write("<h1>Just wait...</h1>");
T("timeout", {timeout:500}).on("ended", function() { document.write("<h1>ended</h1>"); }).start();
};
</script>
Hello !
Is there a special software|encoding you're using to encode the demo .wav ?
I tried all the encoding combinations in Audacity, but Timbre stays silent when reading any .wav I make, though it works when I use yours.
I can work the rest of timbre alright, but I can't use even the simplest audio example. Any idea whats going wrong?
<script>
function playT(){
var src = window.getDraggedFile() || "amen.wav";
T("audio").loadthis(src, function() {
this.plot({target:canvas}).play();
}).on("ended", function() {
this.pause();
});}
function oscD(){
var freq = T("param", {value:100}).to(200, "BPM140 L2", -4);
T("pulse", {freq:freq, mul:0.3}).play();
}
</script>
<!-- start gui -->
<button style="background-color:#05a36c;"class="button" onclick="playT();"></button>
<button style="background-color:#06bb7c;"class="button" onclick="oscD();"></button>
Hello,
First of all, thanks for all the hard work. I really like timbre.js.
The issue:
Am I missing something?, some physics class maybe?, I think they should cancel out, but they don't.
Thanks,
Cheers.
I tried this T("sin", {freq:880, mul:0.0}).play(); but it kept on playing so I had to exit the browser. How do I stop the sound and how can I control how long the sound plays?
Is there a plugin or extension to permit firefox to use timbre.js - right now the examples play silently with no informative error messages in the web console.
Is there a way to dynamically adjust ADSR or other synth parameters to add expression to notes as they play? I've trawled the documentation and Google and can only find someone who had the same problem as me; being unable to find the answer.
As a simple example, I'll have a synth setup like so with noteOn
used to trigger a note:
var env = T("adsr", {a:50,d:300,s:0,r:200});
var synth = T("OscGen", {fwave:"sin", mul:0.5, env:self.env}).play();
Now, I'd expect the following to work:
synth.set({a:300});
or
synth.set({attackTime:300)}
But it has no effect.
Am I missing something, or is it impossible to adjust the envelope without replacing the entire OscGen object?
when i use npm install timbre
it appear following error message
CC(target) Release/obj.target/output/deps/mpg123/src/output/alsa.o
../deps/mpg123/src/output/alsa.c:19:28: fatal error: alsa/asoundlib.h: No such file or directory
#include <alsa/asoundlib.h>
^
compilation terminated.
(i have tried to install other lib, and it run successfully.)
is there anything i miss?
I'm writing a wrapper to connect Timbre.js synth to my own library.
Is there a way to obtain Timbre.js version from the script?
Thanks!
I do not see example of chords played using soundfont mp3 at below link
http://mohayonao.github.io/timbre.js/soundfont.html
Is it possible to do that? a code sample will be great help.
hi, recently we want to add your lib on https://cdnjs.com
is timbre.dev.js
fine to be hosted on cdnjs?
or is there any way to get timbre.js
, such as website download link?
thank you very much!
Hi there,
Running this simple code on raspberry PI gives choppy sound output and works fine on OSX. Any idea what i'm doing wrong ?
Playing ogg files on the rpi works correctly though.
thanks !
var T = require("timbre");
var PulseGenerator = function() {
this.freq = 440;
this.interval = 1000;
};
PulseGenerator.prototype.play = function() {
this.tone = T("sin", {
freq: this.freq
});
this.pulse = T('+pulse', {
freq: this.interval + 'ms'
});
var sound = T('*', this.tone, this.pulse).play();
};
PulseGenerator.prototype.setFrequency = function(freq) {
this.tone.set('freq', freq);
};
PulseGenerator.prototype.setInterval = function(ms) {
this.pulse.set('freq', ms + 'ms');
};
var p = new PulseGenerator();
p.play();
I tested to mp3 decode on this page on Chrome 32 linux and Safari 7 on iOS but it doesn’t play the sound. Is it a known issue? Is there a workaround? I am trying to avoid .wav files. Thanks for your amazing work.
Awesome project!
Is it possible to generate a sample and have access to the raw audio data?
For example, if I have this non-looping sample:
var sin = T('sin', {freq:440, mul:0.5});
var perc = T('perc', {r: 1000}, sin).bang();
How would I get the resulting audio buffer data?
When you try to require('timbre') it throws the following error.
Warning: Cannot find module 'lame' from '/Users/jorgesilva/Sites/2014/clickOnJorge/node_modules/timbre' Use --force to continue.
This seems to be because this package is not listed as a dependency in the package.json.
Should be as simple as:
npm install lame --save
I'm sure I'm missing something super obvious, but what do I need to do to keep replaying a sound? This only plays once.
var T = require("timbre");
var audio_src = T("audio", {}).loadthis("cicada_2.wav");
setInterval(function(){
console.log("trigger");
audio_src.play();
}, 2000);
Really what I need is some kind of sampler where I can load and trigger a bunch of clips as needed. Maybe I'm missing that, too?
Thanks!
You mention in the install to use the timbre.js
file. This file doesn't exist. This also affects package managers like http://bower.io from being able to infer the package name.
I should fix it.
Hi,
I've been using Timbre for a couple months now in an effort to develop an entirely javascript beetmachine / sequencer modeled after the Native Instruments: Maschine line. The app is here — it's mostly built out to support sequencing, multi-pattern and multi-group samples (effects like reverb, chorus, eq used to work through the UI, but I recently broke :[ ) and eventually I'd like to build a sampling feature to be able to cut the uploaded (drag and drop onto a pad) samples into pieces and save separately.
I've been loving timbre so far. It's phenomenal how much effort and consideration appears to have gone into it.
I had one recent issue, though. Which is extremely simple. I had been using timbre in a require.js environment, loading modules through the browser with require, but recently switched to browserify, which bundles all code into one nice minified file while using a node-like require() syntax to "load" module dependencies into a module's scope. (CommonJS pattern).
When using browserify, it defines module, exports and require so that they're used within the bundled application javascript. This tricks Timbre into believing it's in the Node environment and as such, T.envtype
will equal "node"
.
I'm just monkey-patching it in my local file by reversing the ternary conditions to check for window
before checking for module.exports
.
Checking for window should be a surefire way to determine if we're in a browser environment, right?
ex:
var _envtype = (typeof window !== "undefined") ? "browser" :
(typeof module !== "undefined" && module.exports) ? "node" : "unknown";
Doing so, however, causes a second issue here
Because browserify is expecting timbre to export itself through module.exports, but in the browser env it is only attaching to the window. I think a safer bet would be to attach to module exports if its defined at all. That way you cover all bases. Basically if module && module.exports
, attach to it—regardless of attaching to the window global.
Does that make sense?
I discorver this project last night, and I have a question
Here is my source code:
var tempo = 120;
function metroBeatsSeconds(seconds) {
tempo = seconds;
timbre.bpm = seconds;
}
/**
* Created by manuel on 13-03-16.
*/
function freqSon(ecartTon)
{
var BaseLa4 = 440;
var factTon = Math.pow(2,1/6);
return BaseLa4 * Math.pow(factTon, ecartTon);
}
function note(param, length)
{
var fre = freqSon(noteTrans(param, length));
console.log("Note" + param, " \nDurée (en temps de mesure): " + (length * 1000 / partFractDenominateur()) + "ms (" + (length / timbre.bpm / 60 * 1000) + "ms\n");
T("sin", {freq: fre, mul: 100, timeout: "" + (length * 1000 / timbre.bpm) + "ms"}).play();
}
/***
* ex; do4 , 1
* ex: so4 , 1
*/
function noteTrans(note, length) {
switch(note.substring(0, 2))
{
case "do":
param = 0;
break;
case "re":
param = 1;
break;
case "mi":
param = 2;
break;
case "fa":
param = 2.5;
break;
case "so":
param = 3.5;
break;
case "la":
param = 4.5;
break;
case "si":
param = 5.5;
break;
}
octave = note.substring(2,3);
var ecart = param+6*octave - 4.5 + 6 * 4; //ParRapprtLa440 en tons + -> aigu - -> grave
return ecart;
}
function silence(length)
{
}
//And the "score" file:
function part1() {
metroBeatsSeconds(120);
note("do4", 1);
note("re4", 1);
note("mi4", 1);
note("fa4", 1);
note("sol4", 1);
note("la4", 1);
note("si4", 1);
note("do5", 1);
}
function partFractDenominateur() {
return 4;
}
function partFractNumerateur() {
return 2;
}
function part1_stop() {
T.stop();
}
I really want to get involved in this project. I have a question 💯 Do you have Javascript code generator?
the flash player links on http://mohayonao.github.com/timbre.js/ aren't working. The link to TimbreFlashPlayer.js links to http://mohayonao.github.com/timbre.js/libs/typedarray.js, as does TimbreFlashPlayer.swf
Has anyone attempted to use this with Titanium Studio. I have tried but keep getting a Float32 declaration error using the simple example. Any suggestions would be appreciated.
# define the pitch env
pitch_env = T("env", {table:[ 320, [160, 20], [80, 40], [80, 100] ]});
# define the osc
VCO = T("sin", {freq: pitch_env, mul:1})
# define an amp env AND add the osc to it. (different than adding a pitchenv?)
amp_env = T("env", {table:[0,[1, 1], [0.9, 90], [0, 100] ]}, VCO)
# stop synth on end amp env
amp_env.on("ended", function(){
VCO.pause()
})
# start the amp env (why not start the synth?)
amp_env.bang().play()
in this case it ignores the pitch envelope and only uses the amp envelope. how can i trigger the pitch and the amp envelope? thx
Hi
Here is the reference song (French song : "Sur le pont d'Avignon" BTW)
c4c4c4rd4d4d4re4r8f8g8r8c8r8c8r8d8r8<g4
c4c4c4rd4d4d4re4r8f8g8r8c8r8d8r8r8c2
if we play this with timbre.js we can notice than both "<b8" are played on the upper octave wherease it should be played on the lower one.
Am I doing something wrong?
I'am digging into it and I'll try to fix this (maybe a pull request) but that part of the code is really hard to get into ;).
A little help from you would be really appreciated
Regards,
Olivier.
When trying to press "Play" button in http://mohayonao.github.io/timbre/ or type examples in developer console, receiving an error:
Uncaught TypeError: this.ctx.createJavaScriptNode is not a function
Stack trace:
on @ timbre.min.js:6
c.on @ timbre.min.js:3
b.on @ timbre.min.js:3
a @ timbre.min.js:3
b.fn.h.dac.on @ timbre.min.js:3
b.fn.a.TimbreBasePrototype.h.play @ timbre.min.js:3
window.play @ index.js:16
(anonymous function) @ VM535:1
Posting this to help out anyone else, who stumbles upon this problem. I don't really know how to properly implement this, but here's a diff of a solution that helped me.
Breakage seems to have been caused by a changing in the web audio API.
--- a/timbre.dev.js
+++ b/timbre.dev.js
@@ -3527,34 +3527,39 @@
var buffer;
try {
- buffer = ctx.createBuffer(data.buffer, false);
+ buffer = ctx.decodeAudioData(data.buffer).then(success, failure);
} catch (e) {
return onloadedmetadata(false);
}
- samplerate = ctx.sampleRate;
- channels = buffer.numberOfChannels;
- if (channels === 2) {
- bufferL = buffer.getChannelData(0);
- bufferR = buffer.getChannelData(1);
- } else {
- bufferL = bufferR = buffer.getChannelData(0);
- }
- duration = bufferL.length / samplerate;
+ function success(buffer){
+ samplerate = ctx.sampleRate;
+ channels = buffer.numberOfChannels;
+ if (channels === 2) {
+ bufferL = buffer.getChannelData(0);
+ bufferR = buffer.getChannelData(1);
+ } else {
+ bufferL = bufferR = buffer.getChannelData(0);
+ }
+ duration = bufferL.length / samplerate;
- var mixdown = new Float32Array(bufferL);
- for (var i = 0, imax = mixdown.length; i < imax; ++i) {
- mixdown[i] = (mixdown[i] + bufferR[i]) * 0.5;
- }
+ var mixdown = new Float32Array(bufferL);
+ for (var i = 0, imax = mixdown.length; i < imax; ++i) {
+ mixdown[i] = (mixdown[i] + bufferR[i]) * 0.5;
+ }
- onloadedmetadata({
- samplerate: samplerate,
- channels : channels,
- buffer : [mixdown, bufferL, bufferR],
- duration : duration
- });
+ onloadedmetadata({
+ samplerate: samplerate,
+ channels : channels,
+ buffer : [mixdown, bufferL, bufferR],
+ duration : duration
+ });
- onloadeddata();
+ onloadeddata();
+ }
+ function failure(){
+ onloadedmetadata(false);
+ }
};
return function(src, onloadedmetadata, onloadeddata) {
How to record the whole example at http://mohayonao.github.io/timbre.js/beatbox.html including synth and pattern?
Hi,
Thanks for your work. I'm doing a mml gui of my own and I discovered your library. Great job !
I just noticed that the event 'ended' was raise even if the song is not finished.
So the song continue to play but the event is raised...
Maybe that's not a bug, but I had to ask.
Here is a part of my code to enlight you:
function _play(mmlPartition) {
playBtn.html('Pause');
var player = T("mml", {mml: mmlPartition}, gen);
//Subscribtions to every events
gen.on('ended', function () {
playBtn.html('Play');
_displayStatus('ended');
//$('#play_button').html('Play');
gen.stop();
gen.reset(T);
T.stop();
});
gen.on('pause', function () {
_displayStatus('pause');
playBtn.html('Resume');
});
......
player.start();
gen.play(mmlPartition);
}
hi, would you please update the tags to the latest version so that we can add your lib to https://cdnjs.com with git auto-update.
thank you very much!
cdnjs/cdnjs#6110
I have a synthDef, on which is called noteOn
and noteOff
. I am also hackishly changing the volume of the gen, by calling .set({mul: value})
.
I notice that this causes a disruption, which is very obvious when changed at a fast rate. E.g., if I update the mul
every 16ms, then it is more clicks and white noise than a continuous function.
Is there a more correct way of doing this?
Thanks!
Edit, here's a good way to test, where list[0]
is a synthGen:
i = 0; setInterval(function(){
i++; list[0].set({mul: 1000000 * 0.5 * (Math.sin(i / Math.PI / 2) ) })
}, 16)
I tried creating a html5 musical keyboard using timbre.js and noticed significant latency between touch and audio only on android chrome. There is no perceptible latency on iOS (iphone, ipad) and windows touchscreen devices.
I've filed a bug against chrome. ( https://code.google.com/p/chromium/issues/detail?id=312502 )
The latency seems to be in audio and not in touch response.
Since I'm using timbre.js, I thought of reporting the issue here too.
I tried to time the code execution using chrome console, using the following few lines of code.
Notice that s.play() consumes 10ms on android wheres on macosx it is less than 2ms.
c = function(){console.log(window.performance.now())};
s=T('sin');
c(); s.play(); c()
chrome 30.0.1599.105 on android 4.4
174774.38400000392
174784.88199999993
chrome 31.0.1650.57 on macosx 10.9
28419.46000000098
28421.132999999827
Any idea as to how I would implement brown noise? I see you've got pink and white - I'd love to add brown and then pass it through various filters.
I was having trouble setting the osc
on an OscGen
object doing something like this: T('OscGen', {osc: T('osc', {wave: 'saw'})}
but the wave still sounded like a sin
. I then noticed that there is an undocumented wave
setting that can be set to a string. So in order to achieve what I was looking for I would need to do: T('OscGen', {wave: 'saw'})
Shouldn't the OscGen
wave
reflect the wave
of the osc
?
It is difficult to update this project. A cool project has some useful tasks for development. But this project doesn't have them. So, I should renew development tools.
While trying to set the freq of a simple synth within a NoUiSlider function, timbre is printing a 'T("undefined") is not defined' error printed to the console.
When setting the freq explicitly as the below commented out line, there is no issue.
var value = 0;
$(function(){
$('.slider').noUiSlider({
start: 40,
range: {
'min': 0,
'max': 500
}
});
});
$('.slider').on({
slide: function(){
value = $('#slider').val();
synth1.set({freq:value});
// synth1.set({freq:500});
}
});
This may or may not be an issue with timbre.js. Please accept my apologies if not.
Thank you for a wonderful library thus far.
hi, i'm developing a 3d app that involves live sound synthesis, and we would like to use timbre.js for the awesome range of programming affordances it offers. But we've found that simple sound synthesis with timbre.js is interrupted by noise when we do any manipulation of our 3d model.
We've tried a range of other (less capable) libraries wrapping the Web Audio API, and have not had this same problem with them, but we'd much prefer to use timbre.js if we can solve this noise problem!
Our animation rendering is run by recursive calls to requestAnimationFrame(); running the app in Chrome 37.0.2062.0 dev. The 3d code is using three.js, with WebGL rendering.
my simple synthesis test, triggered by a mouse click is:
var sine1 = T("sin", {freq:vcs(x), mul:0.2});
var sine2 = T("sin", {freq:vcs(y), mul:0.2});
var sine3 = T("sin", {freq:vcs(z), mul:0.2});
T("perc", {r:900}, sine1, sine2, sine3).on("ended", function() {
this.pause();
}).bang().play();
Hello,
I'm working on a drum machine using wav files. I would like to know if it's possible to change the output level of a T('audio') object without redefining the audio file.
For example i have this :
var audio1 = T("audio").load("audio/kick.wav");
and i would like to do something like :
audio1.mul = 0.3
instead of writing this :
audio1 = T("audio", {mul : 0.3}).load("audio/kick.wav");
This is because the audio file can change and it would save me some code!
Thanks a lot!
I'm having trouble figuring out what's possible with soundfonts. Can I shape the duration of the note, its envelope, etc.?
Hi!
The event "ended" is not working when using frequencies array.
var freqs = T(function(count) {
return [440,800,900,1000][count % 4];
});
var osc = T("square", {freq:freqs});
When I append the on.("ended") to an interval method or osc itself, the callback seems to be never reached. Any thoughts about this issue? I appreciate any reply.
Figuring out how to properly register and unregister listeners that use the .listen method is unclear to me. If I create a spectrum object for instance:
var saw = T("pink", {mul:0.15}).play();
var fft = T("spectrum", {size:512, interval:100}).on("data", function() {
fft.plot({target:canvas});
}).listen(saw);
Is this removable through calling fft.removeAllListeners()
, or saw.removeAllListeners()
, or is this completely separate? If so, could somebody add documentation for the listen and unlisten methods (or point me to it if I have missed it).
Hi,
I installed timbre.js through bower and I was trying to reproduce some examples from the website.
I run through some warnings like :
T("ndict.key") is not defined
T("keyboard") is not defined
Using the file available for download on the website of the project doesn't fix the issue. Am I missing something ?
Hi, I have to say that i like the library and it's really useful.
Can I ask if there is any documentation.
I would appriciate just a simple list of all possible options. In example I see here a demo:
T("perc",
{r:500}, sine1, sine2).on("ended", function() {
But I don't know what means 'perc' as same I don't know what else can be called instead of 'sin', 'saw', 'perc', 'pulse'.
I'm not skilled in synths and electronic sound processing in general and I understand that you have just implemented something that already exists. Maybe that is my trouble.
Best regards
Tom
The mohayonao timbre.js contains very promising examples, but they do not show the complete code that can be copy/pasted in to a text file and tried out by itself. Need have such code and more user friendly documentation.
Hi,
maybe it is implemented and/or in the documentation - but is there a way to save a (finite) T Object as a wave (or any other format) file to my hard disk?
Thanks,
Dirk
PS: awesome project!
The following code causes the title message to be raised in Firefox and loads the flashobject in IE11. This happens with the dev and master branches. No other api call are made prior to this code, only the inclusion of the script.
var pluckString = T("pluck", { freq: this.data('NOTE').FREQUENCY , mul: 0.3 }).bang().play();
T("timeout", { timeout: 750 }).on("ended",
function () {
this.stop();
}
).set({ buddies: pluckString }).start();
I am having trouble getting any audio using timbre on my ipad despite it working fine on android & desktop.
Are there any specific settings for the ipad?
Tried it with T("PluckGen"), T("OscGen"), T("SynthDef") on several browsers Windows and Mac.
Here is a sample file:
PluckGen
OscGen
SynthDef
Is there any way for get the stream (pipe function) for input and for output?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.