Coder Social home page Coder Social logo

audiolib.js's People

Contributors

charlieroberts avatar crackofdusk avatar davidgovea avatar jussi-kalliokoski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audiolib.js's Issues

Multiple Oscillator Instances

Multiple oscillator objects seem to output uneven sound.

I wanted to create a one octave bass synth using one oscillator instance for each note, which is playable via a MIDI keyboard. This would allow me to pass a frequency to an oscillator when a note-on message is received and then a null frequency to the same oscillator object when a note-off message is received.

From playing with the code it seems to start bugging out after I introduce more than one oscillator. It seems that pulling bytes from more than one oscillator at the same time is a little too much. The more oscillators there is the crazier the sound output is, so using 12 is not going to work.

Help! Somethings trouncing me buffers!

Hi there.

Been using your lib and in particular your Pluck plugin. Everything was going swimmingly. Then I started making a few mods to Pluck and all was well for a bit. Suddenly I'm getting nowt but pops! (distortion, clipping, no semblance of a 'note') . So I thought, oh dear I've made a booboo somewhere. Tried loads of stuff. To no avail. I went back to original untouched Pluck. Same!

Something is trouncing the buffer after the 'note' function finishes (it'll be all full of 8.1253612 or similar i.e NOT audio)

Now here's the funny thing. If I put a breakpoint (in Chrome) right at the end of the 'note' function. I can hear my note! (after the breakpoint is hit, that is, well at least to my perceptions). So with this breakpoint in place, the buffer survives. Without it: scary speaker pops.

Any ideas?

Oscillator performance problems

The generate function takes most processor usage of all the audiolib.js functionality. This should be fixed, as it's a fairly used feature.

What should be done:

  • Remove the fm arguments from generate() [ also to comply with the new spec ]. Move these into a single .fm property.
  • Move to using wave shape names instead of meaningless numbers. To prevent from breaking the backwards compatibility, preserve the old syntax as well.
  • Create a way of creating custom combination wave shapes to the prototype, to reduce the amount of redundant oscillators needed in the code.
  • Create a performance test for Oscillator.

Envelope problem

Hi. I'm having some problems getting the adsr envelope to work. The attack portion is working but only on the first key press. Any subsequent key press the envelope does not work.

Could you shed any light on where I am going wrong please. Cheers.

var 
    osc1,osc2, 
    lfo1,noise,
    dev1, sampleRate, fx, j, volENV, currentNote,currentNote2, noteOnName, noteOffName;
var pressed = [];
var released = [];
var attack;
var decay;
var sustain;
var release;
var velocity = 127;
var time, feedback, lfospeed;


function fillBuffer(buffer, channelCount)
{
    var l   = buffer.length, env,
        smpl1, smpl2, 
        i, n, 
    for (i=0; i<l; i+=channelCount){
        volENV.generate();

        lfo1.generate();//LFO generated
        lfo1.frequency = lfospeed;
        noise.generate();

        osc1.fm = lfo1.getMix() * 0.2;
        osc1.generate();

        smpl1 = osc1.getMix();  
        smpl1 = smpl1 * volENV.getMix();


        for (n=0; n<channelCount; n++){
            buffer[i + n] = fx.pushSample(smpl1 * 0.5) ;
        }
    }
}


window.addEventListener('load', function() {
    dev1            = audioLib.AudioDevice(fillBuffer, 2);
    sampleRate      = dev1.sampleRate;

    volENV = new audioLib.ADSREnvelope(sampleRate, 200, 50, 1, 500, 250, 0);
    //volENV.triggerGate(true);

    fx          = (new audioLib.LP12Filter(sampleRate, 200, 2), new audioLib.Delay(sampleRate, 75, .1));

    lfo1            = new audioLib.Oscillator(sampleRate);
    lfo1.waveShape = 'triangle';

    osc1            = new audioLib.Oscillator(sampleRate, null);

    midiBridge.init({
        connectAllInputs : true,
        ready : function(msg) {
            content.innerHTML = "<h1>loaded</h1><br/>";
        },
        error : function(msg) {
            console.log(msg);
        },
        data : function(midiEvent) {
            if(midiEvent.status == midiBridge.NOTE_ON) {
                        volENV.triggerGate(true);
                        noteOnName = midiEvent.noteName;
                        pressed.unshift(noteOnName);
                        console.log(noteOnName +" on");
                        console.log(pressed);
                osc1 = new audioLib.generators.Note(sampleRate, noteOnName);
                    osc1.waveShape = document.getElementById("waveform").value;
                        osc1.mix = osc1.mix * midiEvent.data2 / 127;
                        currentNote = noteOnName; 
            }
            if(midiEvent.status == midiBridge.NOTE_OFF){// && currentNote == 0){
                        volENV.triggerGate(false);
                        noteOffName = midiEvent.noteName;                       
                        if(pressed.slice(0,1) == noteOffName){
                            osc1 = new audioLib.Oscillator(sampleRate, null);
                    }
                    else{
                            console.log("do nothing");
                    }
            }
        }
    });    
},false);
}

Need more tests!

Test cases, demos and especially unit tests would be very much appreciated!

Sampler.loadWav performance

I'm seeing some very slow load times when Sampler.loadWav is called on larger wave file samples. In my specific case I have 2-channel 44.1khz samples ranging from 128 KB in size to 844 KB. The 128kb sample takes about 4-5 seconds to load during loadWav(). My 844kb sample takes a very long time - more than a minute at least. Are the included codecs just not capable of dealing with larger samples?

Mobile Safari support?

Is anyone aware of a technique for getting audiolib.js to work in mobile safari (iOS)?

replace fft.js

fft.js is a completely broken mess:

  • It only works with the default buffer size, otherwise it will go all NaN with you.
  • audiolib.js uses it as if it were an RFFT while it's not
  • spectrums are calculated including the DC term
  • a lot of other problems

It needs to be replaced with JensNockert/fft.js. The new version supports arbitrary buffer sizes, has optimizations for RFFT, is a whole lot faster and more.

I'll do this as soon as the RFFT part is working.

Include a build please

Hello,

I don't want to mess with grunt, it fails on windows anyways. Please commit a build file, it is not such a big deal.

Thanks.

Problem automating two oscillators, one for each channel

I'm having trouble getting an LFO to work on two oscillators. I'm automating the frequency of the oscillators. I'm writing the samples of one oscillator to the left channel and the samples of the other oscillator to the right channel.

The code below results in two oscillators generating normally with no apparent LFO automation. Any ideas?

function buildAudio() {
    audioDevice = audioLib.AudioDevice(audioCallback, channelCount);
    oscillator1 = audioLib.Oscillator(audioDevice.sampleRate, 440);
    oscillator2 = audioLib.Oscillator(audioDevice.sampleRate, 441);
    lfo1 = audioLib.Oscillator(audioDevice.sampleRate, 1);
    lfo2 = audioLib.Oscillator(audioDevice.sampleRate, 2);
    oscillator1.addAutomation('frequency', lfo1, .25, 'additiveModulation');
    oscillator2.addAutomation('frequency', lfo2, .55, 'additiveModulation');
}

function audioCallback(buffer, channelCount) {
    var l = buffer.length, current;

    for (current = 0; current < l; current += channelCount) {
        lfo1.generate();
        lfo2.generate();
        oscillator1.generate();
        oscillator2.generate();
        buffer[current] = oscillator1.getMix();
        buffer[current + 1] = oscillator2.getMix();
    }
}

Error in \audiolib\tests\node-record.js

ReferenceError: window is not defined
at Function.doInterval (d:\Server\node.js\audiolib\lib\audiolib.js:2416:20)

This line (audiolib.js:2416):
var BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.OBlobBuilder || window.BlobBuilder,
timer, id, prev;

node.js 0.5.6 binary for Windows OS

making contributions

Hi Jussi,

I have some code I'd like to contribute... a Karplus-Strong implementation, a Flanger, a soft-clip etc. What's the best way to do this? Giving them to you as plug-ins would be most convenient for me... but I'm not sure how you're defining what a plugin is vs. should be included in the audiolib.js file.

Also, if you have specific requirements regarding tests or docs let me know.

  • Charlie

Implement Note Sequencer

The ability to easily sequence notes would be excellent. I'm working on a Tracker class in my fork, but there might be a better way. Different from the existing StepSequencer (basically just a gate).

Could tie in with the new generator.append(noteBuffer) style.

Should support:

  • Sequencing notes
  • Callback after note completed

Change volume of osc?

Hi There,

First off, I'm loving this project I think you have done some amazing work. I'd love to help document things a little better as a newbie coming into the project, and I can't find how to decrease the output volume of the osc tones. The volume is VERY loud compared to anything else. I tried playing around with the Compressor and GainController but I was not able to have much luck. I'm sure I'm doing something stupid but I've searched with no luck.

Thanks!

GC & CC hurting performance with audiolib.js

The GC and CC are taking huge amounts of time with audiolib.js, especially on Firefox, so maybe some premature optimization is in place. I've already made some improvements (it's about 20% faster now), but more can't hurt.

Plugin API

Feature request - Plugin API

It would be great to have an easy to use way to load plugins.

Features

  • The ability to inherit the proper generator/effect properties
  • The ability to specify a prototype and have it's properties merged with any extras (like what currently happens to effects/gens)
  • Plugins can be loaded from separate .js files (plugin function is externally available)

For example:
audioLib.extend(name, class, prototype, type) //where type is "Generator", "Effect", null

Load mp3 into sampler?

Me again :).. was reading some posts saying that this may happen in the future. Just wanted to know if this is possible now or if you would like help to make it happen. I think being able to load up smaller files would be a big win. Even short one off wavs are 100-150k, and increase in size when turned into a base64 string.

Creating Float32Array from existing data [#,#,#]

Hello,

Sorry to file this as an issue, but I'm unsure of where else to get the information. I have a JS array of floating point numbers between -1 and 1 that I'd like to play back. How do I format this as a Float32Array to do so?

Thanks

P.S. I looked to no avail, but is there a mailing list where we can ask more general questions?

Build on Windows fails

Thanks to Gregory Ruskin for reporting.

The makefile is likely incompatible with Windows. Will need to try this.

Timing of Automation

Hi,

First, thank you for this library. Every time I think I need to add something to it I dig a little bit deeper and it's already in there. Really spectacular work.

I'm having problems with the timing of Automation objects. If I use a StepSequencer as the source for an Automation, and then apply that Automation to the frequency of an oscillator the timing has a lot of jitter to it. If I use preProcessing to do roughly the same thing, the timing is great and I don't hear any jitter.

I like the syntax of the Automation class and want to use it... I'm curious if I'm doing anything wrong or if anyone can back up my findings. Here's a simple script to test, just change the USE_AUTOMATION flag to hear the sequence with it on and off.

Thanks for any help! - Charlie

<html>
    <head>
        <script src="js/audiolib.js"></script>
        <script>
        window.onload = function(){
            window.USE_AUTOMATION = true;

            dev = audioLib.AudioDevice(audioProcess, 2),

            window.osc = new audioLib.Oscillator(dev.sampleRate, 220);
            window.osc.waveShape = 'square';
            window.osc.mix = .1;

            window.mod = new audioLib.StepSequencer(dev.sampleRate, 250,  [120, 240, 120, 360], 0.0);

            if(USE_AUTOMATION) {
                window.osc.addAutomation("frequency", mod, 1, "assignment");
            }else{
                window.osc.addPreProcessing(preProcess);
            }
        }

        function preProcess() {
            window.mod.generate();
            this.frequency = window.mod.getMix();
        }

        function audioProcess(buffer, channelCount){
            if(window.USE_AUTOMATION) {
                window.mod.generateBuffer(buffer.length, channelCount);
            }
            window.osc.append(buffer, channelCount);
        };

        </script>
    </head>
    <body>  
    </body>
</html>```

Using in Firefox Addon SDK as a module?

Is it possible to use audiolib.js as a module in Firefox Addon SDK (I am using Addon Builder) so that I can call it from an extension script, e.g. using require("....") from main.js? Normally if it works for Node, I assume that should work as well, but could not figure out which files to put in which location. Any help on this would be appreciated.

best way to stop playing audio

What is the best way to stop (either temporarily or permanently) playing audio? So far in my code I've used something like this:

var callback = audioCallback(buffer, channels) {
    if (playing) {
        osc.append(buffer, channels);
    }
};

$(button).click(function () { playing = !playing; }

Is there a better or more formal way to stop the audio? With this method, audioCallback will always be called - the implementation is just bypassed.

npm installation failed on Ubuntu

Node version 0.8.6

$ npm install audiolib
...
...
File "lib/audiolib.js" created.

Done, without errors.
npm http GET https://registry.npmjs.org/cubeb
npm http 304 https://registry.npmjs.org/cubeb

[email protected] install /home/nhq/development/barn/node_modules/audiolib/node_modules/cubeb
node-gyp rebuild

make: Entering directory /home/nhq/development/barn/node_modules/audiolib/node_modules/cubeb/build' CXX(target) Release/obj.target/node-cubeb/src/common.o CXX(target) Release/obj.target/node-cubeb/src/constants.o ../src/constants.cpp:4:25: fatal error: cubeb/cubeb.h: No such file or directory compilation terminated. make: *** [Release/obj.target/node-cubeb/src/constants.o] Error 1 make: Leaving directory/home/nhq/development/barn/node_modules/audiolib/node_modules/cubeb/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:215:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:91:17)
gyp ERR! stack at Process._handle.onexit (child_process.js:674:10)
gyp ERR! System Linux 3.2.0-32-generic-pae
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/nhq/development/barn/node_modules/audiolib/node_modules/cubeb
gyp ERR! node -v v0.8.6
gyp ERR! node-gyp -v v0.6.3
gyp ERR! not ok
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! sh "-c" "node-gyp rebuild" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the cubeb package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls cubeb
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-32-generic-pae
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "audiolib"
npm ERR! cwd /home/nhq/development/barn
npm ERR! node -v v0.8.6
npm ERR! npm -v 1.1.48
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/nhq/development/barn/npm-debug.log
npm ERR! not ok code 0

problems under os x

I updated some system software this morning and am suddenly experiencing problems in Chrome 20.0.1105.0 dev under OS X 10.6.8. When I ran an older version of audiolib.js (not too old... maybe 2.5 weeks) I get an error upon initialization saying "No audio sink available". When I update audiolib.js to use the new sink.js changes, audio starts but clicks every half second or so and has a low level of noise throughout, whenever a sink is created.

There are also some problems in Firefox with erratic behavior after the most recent sink.js update.

Anyone else on OS X who is experiencing problems? Or who is running the most recent changes and is -not- experiencing problems? Thanks! - Charlie

Use grunt instead of make

This would make it easier to do the build tasks on Windows as well, plus you can install it via npm.

More specs & review

Currently there is only a spec for CODEC plugins, more specs should be created (and implemented, if not already). Also the existing specs are somewhat vague. This would make it much easier for people to learn to use, adopt and develop for audiolib.js.

Install it on Mac OS X

Hi,

I've tried installing this using

npm install audiolib

on my Mac, but it fails when installing cubeb. I've tried installing cubeb, but I can't seem to get it working.
Can someone give me more instructions on how to do this?

Thx

Not enough people!

The project has escalated in such a manner, that I could really use a hand here and there, and hear from people who are using audiolib.js, what they like, what they'd change, if they've already changed it and want to merge. I'm swamped, please help me out, people! :P

Demo

Hey, I have a synth I put together using audiolib that I'd like to add to Github. It's not hosted anywhere at the moment but will be soon. I'm new to Github so do I just add it and put a link to the audiolib page in the about section?

As soon as it is hosted somewhere, I will send you a link to add it to the demo section. It's not the tidiest code at the moment and comments still have to be added.

License: MIT -> BSD

As BSD has been chosen as the preferred license for Official.fm Labs projects, this change will be enforced after this month (on 1st of March 2012), unless contributors have any objections.

Guides

I think that if you're planning 0.5.0 to be a major release, some guides should be written for at least basic functionality.

Audiolet has some such guides, which are actually why I started working with Audiolet first. It would definitely encourage some more to hack along!

I can write a guide or two this week.. here are some general topics that come to mind:

  • Simple sound generation with fillBuffer and writeBuffer(generated) methods
  • Loading PCM data, sampling/resampling
  • Automation techniques
  • Applying envelopes, creating notes & chords: maybe a quick one-row-keyboard-piano guide?
  • 8-step sequencer/drum machine creation (I plan to do this once the tracker is in place)

The usage of new is too complicated

This should be made simpler.

Currently with audioLib.Sink the new is optional, but for most of the effects it's not, and with effect.createBufferBased() you must not use it. So maybe a good idea would be to make it optional everywhere, so that the recommendation would be not to use it at all.

This should however be done in the library architecture side, not affecting the actual effects code with some weird cruft.

Static ADSR Envelope generation

While using buffer generation synthesis techniques, it would be handy to be able to generate static ADSR envelopes without having to trigger the gate open/closed. Does that make it an ADR envelope? :P

The current implementation is more geared toward live interaction like Orbisyn

Maybe the Envelope class could be an effect, using .append to apply an envelope to a buffer. On the other hand, .generate could be used.. osc.addPreProcessing(function(){ adsr.generate(); this.mix = adsr.getMix(); })

webkit audio not detected correctly?

i'm not sure if this relates to the comment here but i was wondering why chrome canary (20.0.1125.0) is leaking so much memory (at least 500MB after a while) and realized that its falling back to base64 wave generation. it doesn't happen on chrome 18.

i could get grunt to build audiolib (keeps saying that grunt.js is not found), so i'm using the latest version found under the downloads section. (side qn: could we have the latest build file in git too?:)

Buffer features for generative effects

An architecture needs to be designed for this, something similar to what is with effects that behave as sinks.

Maybe something like generator.append(buffer, channelCount)

Recording with buffers?

I'm just wondering if it is possible to record linear PCM audio constantly with the output going to a callback function as a buffer array?

I haven't seen much in the documentation about recording. There is a small section which mentions add(buffer) method, but this doesn't sound right and there isn't much detail on it.

Thanks,

  • Tom

performance decrease since last tar.gz upload

Has much changed in the basics of how audiolib.js runs or is used since about two months ago? I've been building demos and have been learning with the downloadable library in the tar.gz that was posted about two months ago. I just built audiolib.js from source today and updated the audiolib.js files in my demos - and have noticed a considerable amount of new latency or dropouts that I didn't experience before. After rolling back to my previous copies of audiolib.js the latency and dropouts go away.

I admit I haven't been a contributor to this project and honestly a lot of the code is beyond my skill level. Thus, I don't really have a good understanding of what has changed in the last two months or what may be causing the performance issues.

I guess I'm just curious if I'm doing something fundamentally wrong in my apps or if performance issues have actually been creeping in to the source over the last couple of months. I'd be glad to take a look and try to make some fixes if there are any known issues that need help.

-Mike

Invalid syntax in the Makefile

The Makefile is using undocumented syntactical features of *nix commands (flags should be specified before targets). This might cause build to fail on Windows and/or some Unixes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.