Schmavery / reprocessing

ReasonML graphics library inspired by Processing
https://schmavery.github.io/reprocessing/
MIT License
679 stars 24 forks source link

Mic + camera input? #126

Open imeckler opened 5 years ago

imeckler commented 5 years ago

Are there any plans to have microphone or camera input at some point? Would also be happy to try contributing this, I guess (copying from processing) the interface should be something like

module Audio: {
  module Input: {
    type t;

    let create: (~channel: int=?, unit) => t;

    let play: t => unit;

    let start: t => unit;
  };

  module Analyzer: {
    type t('k);

    let amplitude: Input.t => t(float);

    let fft: Input.t => t((~bands: int) => array(float));

    let analyze: t('k) => 'k;
  };
};

module Video: {
  module Camera: {
    type t;

    let to_string: t => string;

    let list: unit => list(t);
  };

  module Capture: {
    type t;
    let create:
      (
        ~width: int=?,
        ~height: int=?,
        ~frame_rate: int=?,
        ~camera: Camera.t=?
      ) =>
      t;

    let available: t => bool;

    let start: t => unit;
    let stop: t => unit;

    let read: t => array(array(colorT)); /* Or something like this */
  };
};
Schmavery commented 5 years ago

Hey @imeckler, I didn't have any plans to do this, but feel free to mess around. The current support for playing audio files is very rough (especially in the native implementation) and could stand to be reworked at some point too. I originally added audio playback in a couple days before some game jam where we wanted sound. Most of the tricky changes here will be in https://github.com/bsansouci/reasongl, probably, with just a bit of wiring up to do in reprocessing itself.

I haven't used these functionalities in Processing before but I'd imagine you want to be able to pass any kind of sound (mic or prerecorded) into the analyze functions ideally...

As a style note, I think we've had a little bit of success in avoiding nesting modules too deeply to keep functions and other values easier to find (no searching through multiple nested modules), and then using types with a name other than t. Not too picky here for now though, just a heads up as to what the rest of the code looks like.

Thanks for checking in :)