@@ -16,38 +16,20 @@ namespace facebook::torchcodec {
1616// Audio conversion building block: turns a decoded frame's samples, in the
1717// codec's own sample type, into normalized float32 ones - optionally at another
1818// sample rate, and with another channel count.
19- //
20- // Unlike ColorConverter this is a stream processor, not a function of its
21- // input, because resampling is an interpolation filter: the sample it emits at
22- // a given instant is a weighted sum of input samples on both sides of it. So
23- // swresample holds the tail of each frame back until the next one arrives,
24- // which means convert() emits fewer samples than it was given (sometimes none),
25- // drain() is needed to get the last ones out, and frames must be fed in order.
26- // reset() drops that state, and is what a caller must do after seeking.
27- //
19+
2820// Not thread-safe.
2921class FORCE_PUBLIC_VISIBILITY AudioConverter {
3022 public:
31- // Both default to the source's own value, i.e. to no conversion. Note that
32- // the sample *type* is always converted, to float32.
3323 explicit AudioConverter (
3424 std::optional<int > sample_rate = std::nullopt ,
3525 std::optional<int > num_channels = std::nullopt );
3626
37- // `samples` is a contiguous [num_channels, num_samples] tensor in the
38- // source's own sample type, i.e. exactly what audio_samples() produces.
39- // Returns the samples that are now computable, as float32
40- // [out_num_channels, N] - and N may well be 0.
4127 torch::stable::Tensor convert (
4228 const torch::stable::Tensor& samples,
4329 int sample_rate);
4430
45- // The samples swresample was still holding on to. Callers who skip this lose
46- // the tail of the stream.
4731 torch::stable::Tensor drain ();
4832
49- // Drop the resampler's buffered state and start over, so that the next
50- // convert() call reconfigures from the samples it is given.
5133 void reset ();
5234
5335 bool has_converted_samples () const {
0 commit comments