@@ -13,7 +13,10 @@ torch::Tensor validateSamples(torch::Tensor samples) {
1313 samples.dtype () == torch::kFloat32 ,
1414 " samples must have float32 dtype, got " ,
1515 samples.dtype ());
16- TORCH_CHECK (samples.dim () == 2 , " samples must have 2 dimensions, got " , samples.dim ());
16+ TORCH_CHECK (
17+ samples.dim () == 2 ,
18+ " samples must have 2 dimensions, got " ,
19+ samples.dim ());
1720
1821 // We enforce this, but if we get user reports we should investigate whether
1922 // that's actually needed.
@@ -102,7 +105,7 @@ AudioEncoder::AudioEncoder(
102105 int sampleRate,
103106 std::string_view fileName,
104107 const AudioStreamOptions& audioStreamOptions)
105- : samples_(validateSamples(samples)) {
108+ : samples_(validateSamples(samples)) {
106109 setFFmpegLogLevel ();
107110 AVFormatContext* avFormatContext = nullptr ;
108111 int status = avformat_alloc_output_context2 (
@@ -134,7 +137,8 @@ AudioEncoder::AudioEncoder(
134137 std::string_view formatName,
135138 std::unique_ptr<AVIOToTensorContext> avioContextHolder,
136139 const AudioStreamOptions& audioStreamOptions)
137- : samples_(validateSamples(samples)), avioContextHolder_(std::move(avioContextHolder)) {
140+ : samples_(validateSamples(samples)),
141+ avioContextHolder_ (std::move(avioContextHolder)) {
138142 setFFmpegLogLevel ();
139143 AVFormatContext* avFormatContext = nullptr ;
140144 int status = avformat_alloc_output_context2 (
@@ -175,8 +179,9 @@ void AudioEncoder::initializeEncoder(
175179 // bit_rate=None defaults to 0, which is what the FFmpeg CLI seems to use as
176180 // well when "-b:a" isn't specified.
177181 avCodecContext_->bit_rate = desiredBitRate.value_or (0 );
178- outNumChannels_ =
179- static_cast <int >(audioStreamOptions.numChannels .value_or (samples_.sizes ()[0 ]));
182+
183+ outNumChannels_ = static_cast <int >(
184+ audioStreamOptions.numChannels .value_or (samples_.sizes ()[0 ]));
180185 validateNumChannels (*avCodec, outNumChannels_);
181186 // The avCodecContext layout defines the layout of the encoded output, it's
182187 // not related to the input sampes.
@@ -186,11 +191,12 @@ void AudioEncoder::initializeEncoder(
186191 avCodecContext_->sample_rate = sampleRate;
187192
188193 // Input samples are expected to be FLTP. Not all encoders support FLTP, so we
189- // may need to convert the samples into a supported output sample format, which is
190- // what the `.sample_fmt` defines.
194+ // may need to convert the samples into a supported output sample format,
195+ // which is what the `.sample_fmt` defines.
191196 avCodecContext_->sample_fmt = findBestOutputSampleFormat (*avCodec);
192197
193- setDefaultChannelLayout (avCodecContext_, static_cast <int >(samples_.sizes ()[0 ]));
198+ setDefaultChannelLayout (
199+ avCodecContext_, static_cast <int >(samples_.sizes ()[0 ]));
194200
195201 int status = avcodec_open2 (avCodecContext_.get (), avCodec, nullptr );
196202 TORCH_CHECK (
@@ -273,7 +279,9 @@ void AudioEncoder::encode() {
273279
274280 for (int ch = 0 ; ch < samples_.sizes ()[0 ]; ch++) {
275281 std::memcpy (
276- avFrame->data [ch], psamples + ch * numBytesPerChannel, numBytesToEncode);
282+ avFrame->data [ch],
283+ psamples + ch * numBytesPerChannel,
284+ numBytesToEncode);
277285 }
278286 psamples += numBytesToEncode;
279287
0 commit comments