in torchaudio/csrc/ffmpeg/prototype.cpp [124:156]
std::string get_afilter_desc(
const c10::optional<int64_t>& sample_rate,
const c10::optional<c10::ScalarType>& dtype) {
std::vector<std::string> components;
if (sample_rate) {
// TODO: test float sample rate
components.emplace_back(
string_format("aresample=%d", static_cast<int>(sample_rate.value())));
}
if (dtype) {
AVSampleFormat fmt = [&]() {
switch (dtype.value()) {
case c10::ScalarType::Byte:
return AV_SAMPLE_FMT_U8P;
case c10::ScalarType::Short:
return AV_SAMPLE_FMT_S16P;
case c10::ScalarType::Int:
return AV_SAMPLE_FMT_S32P;
case c10::ScalarType::Long:
return AV_SAMPLE_FMT_S64P;
case c10::ScalarType::Float:
return AV_SAMPLE_FMT_FLTP;
case c10::ScalarType::Double:
return AV_SAMPLE_FMT_DBLP;
default:
throw std::runtime_error("Unexpected dtype.");
}
}();
components.emplace_back(
string_format("aformat=sample_fmts=%s", av_get_sample_fmt_name(fmt)));
}
return join(components, ",");
}