@@ -17,10 +17,19 @@ Encoder::Encoder(
1717 int sampleRate,
1818 std::string_view fileName)
1919 : wf_(wf), sampleRate_(sampleRate) {
20+ TORCH_CHECK (
21+ wf_.dtype () == torch::kFloat32 ,
22+ " waveform must have float32 dtype, got " ,
23+ wf_.dtype ());
24+ TORCH_CHECK (
25+ wf_.dim () == 2 , " waveform must have 2 dimensions, got " , wf_.dim ());
2026 AVFormatContext* avFormatContext = nullptr ;
2127 avformat_alloc_output_context2 (
2228 &avFormatContext, nullptr , nullptr , fileName.data ());
23- TORCH_CHECK (avFormatContext != nullptr , " Couldn't allocate AVFormatContext." );
29+ TORCH_CHECK (
30+ avFormatContext != nullptr ,
31+ " Couldn't allocate AVFormatContext. " ,
32+ " Check the desired extension?" );
2433 avFormatContext_.reset (avFormatContext);
2534
2635 // TODO-ENCODING: Should also support encoding into bytes (use
@@ -51,8 +60,6 @@ Encoder::Encoder(
5160 // TODO-ENCODING Should also let user choose for compressed formats like mp3.
5261 avCodecContext_->bit_rate = 0 ;
5362
54- // FFmpeg will raise a reasonably informative error if the desired sample rate
55- // isn't supported by the encoder.
5663 avCodecContext_->sample_rate = sampleRate_;
5764
5865 // Note: This is the format of the **input** waveform. This doesn't determine
0 commit comments