From 3f9b51715dee47af9b28f494bc73959d0e318e31 Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:53:12 -0700 Subject: [PATCH] Fix save INT16 sox backend (#3524) Summary: When passing int16 type tensor to `save(backend="sox")`, the resulting file should be 16-bit signed PCM, but instead is 32-bit signed PCM. Resolves https://github.com/pytorch/audio/issues/3304 Pull Request resolved: https://github.com/pytorch/audio/pull/3524 Reviewed By: huangruizhe Differential Revision: D47941090 Pulled By: mthrok fbshipit-source-id: 2622b31eb1cbf03969f67ab2b2adec6e2ba677c4 --- torchaudio/csrc/sox/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchaudio/csrc/sox/utils.cpp b/torchaudio/csrc/sox/utils.cpp index 5b662bd6ff..4bb0a0e6e7 100644 --- a/torchaudio/csrc/sox/utils.cpp +++ b/torchaudio/csrc/sox/utils.cpp @@ -222,7 +222,7 @@ std::tuple get_save_encoding_for_wav( case Encoding::PCM_SIGNED: switch (bits_per_sample) { case BitDepth::NOT_PROVIDED: - return std::make_tuple<>(SOX_ENCODING_SIGN2, 32); + return std::make_tuple<>(SOX_ENCODING_SIGN2, 16); case BitDepth::B8: TORCH_CHECK( false, format, " does not support 8-bit signed PCM encoding.");