audiojs / contributing

Discussion and guidelines for contributing
2 stars 0 forks source link

audio-format module #41

Closed dy closed 5 years ago

dy commented 7 years ago

In pcm-convert stumbled upon pretty useful and easy to read/write format notation, that turns out also to be pretty performant. That can be extended to any audio-* component and solve the problem of indicating desired data input/output format.

That is just a plain string with tags, like so:

'interleaved uint8 le stereo 44100'
'stereo audiobuffer 96000'

Note how natural they are to read.

To parse that, we just split by \s+ and match keywords. For sample rate we can use sample-rate package. For custom formats, like 5 channels, we can use an old-school object {channels: 5, ...}.

That allows to shrink API of many components to just:

createOscillator({
type: 'sine',
frequency: (t) => t + 440,
format: 'float32 mono 44100'
})

With that can easily use all audio-* components with any thinkable audio data type.

jamen commented 7 years ago

I saw that in your package and I thought it was really cool! I also had thought about a hypothetical atype package today because of that, but I figured you'd say something about it. Great idea. :smile:

dy commented 7 years ago

@jamen I guess we may need audio-convert package then, to be able to convert AudioBuffer ←→ *, like pcm-convert extended to AudioBuffers, channels remixing and resampling (todo).

dy commented 7 years ago

Alright, audio-format package. Hope it will be as useful as good the idea.