jussi-kalliokoski / audiolib.js

audiolib.js is a powerful audio tools library for javascript.
http://audiolibjs.org/
672 stars 58 forks source link

Recording with buffers? #38

Closed hoddez closed 12 years ago

hoddez commented 12 years ago

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,

jussi-kalliokoski commented 12 years ago

Hey Tom!

To make sure I understand, you want to write to the Sink, and get that caught by the callback interface (for effects or something?)?

First of all, you'd have to format the PCM audio into a Float32Array, let me know if that's a trouble.

Then, an example would be

/* Create Sink */
var sink = Sink(function(buffer){
  /* The buffers should already contain the data you're writing to the sink. */
});

/* When you get more data to write, wherever you're getting it from, write it to the sink, for example an empty Float32Array */
Sink.write(new Float32Array);

/* Then, to start a recording */
var rec = sink.record();

/* And later, to stop it */
rec.stop();

For a more detailed example on recording and more on what to do with the recordings, see tests/recording.html.

Feel free to ask further questions, if something was left uncovered! ^^

Cheers, Jussi

hoddez commented 12 years ago

thanks for the response but sorry i think there's some confusion here. I am talking about recording from a microphone and reading (not writing) the data as it comes in to be processed in real time. it appears that audiolibjs does not support any type of microphone recording i guess. is there any chance of this feature in the near future?

gregjopa commented 12 years ago

Hey Tom,

I don't think you can record input from a microphone with audiolib.js. Actually, I don't think its possible (yet) to access external devices like a mic with just javascript. You could use Java or Flash to do this and then pass that pcm data to audiolib.js to process with fft or add effects to. In the Audiolib.js Orbisyn midi keyboard demo (http://niiden.com/orbisyn/) I think Jussi uses Java to access the external midi keyboard and then synthesizes each note with audiolib.js. If your looking to just record sound from a mic I think you need to use a plugin like Java, Flash, or Silverlight.

Cheers, Greg

jussi-kalliokoski commented 12 years ago

Hey Tom!

Sorry I misunderstood your question.

Like Greg said, accessing input devices is still impossible without the help of a plugin. Hence, audiolib.js doesn't support such features, yet, as I intend to keep the codebase clean of any dependencies to external plugins. However, I plan to include such features as soon as the Device API allows for this.

Meanwhile, I'd point you to following resources:

Cheers, Jussi

jussi-kalliokoski commented 12 years ago

Closing for now.