audiojs / audio

Class for high-level audio manipulations [NOT MAINTAINED]
MIT License
240 stars 9 forks source link

Change writing to use iteration. #13

Closed jamen closed 8 years ago

jamen commented 8 years ago

Iteration will be VERY helpful for writing multi-channel data.

For example, the use of generators would make it easy to write two dynamic channels at once:

const { PI, sin } = Math;

// Write sine waves
audio.write(function* (t, self) {
  // Channel 1 (first iteration)
  yield self.max * sin(2 * PI / 440 * t);

  // Channel 2 (second iteration)
  yield (self.max - 20) * sin(2 * PI / 1000 * 2);
});

With this, you could also use arrays to write static multi-channel data:

audio.write([12, 13]);

Then you could have single integers like 3 expand to [3, 3]

audio.write(3);
// Equivalent to
audio.write([3, 3]);
jamen commented 8 years ago

Notes to self:

vectrixdevelops commented 8 years ago

Could you expand multiple integers for more than two channels in your last example?

jamen commented 8 years ago

Yeah, it doesn't literally "expand" I guess. It would use some system behind the scenes with audio.channels, and write the number howmany ever times over based on that.

jamen commented 8 years ago

I'm going to close this until I have a better idea of how I want to structure data things.