w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
1.01k stars 137 forks source link

copyTo from planar to interleave should copy / convert all channels #819

Open padenot opened 4 months ago

padenot commented 4 months ago

It is useful to copy all frames of an AudioData containing planar data to a buffer containing interleaved data, in one go. However, planeIndex is required in copyTo AudioDatacopyToOptions, so one has to write:

    let data = new AudioData({ ... });
    let destInterleaved = new Int16Array(...);
    data.copyTo(destInterleaved, {planeIndex: 0, format: "s16"});

and this appears to copy all channels in Chrome (and soon, Firefox), despite the planeIndex:0 bit. I think it's good behaviour and we should clarify this in the spec.

chrisguttandin commented 4 months ago

I think that's possibly already written down. The description of an interleaved buffer in 9.3.1. Arrangement of audio buffer says ...

The AudioData has a single plane, that contains a number of elements therefore equal to [[number of frames]] * [[number of channels]].

But planeIndex: 0 could maybe be optional since 0 is the only valid value when copying as an interleaved buffer.

padenot commented 4 months ago

planeIndex:0 is about the source, not the destination. We're copying from a planar buffer into an interleaved buffer here.

It could be made optional in this case, clearly indicating intent.