Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/torchaudio_unittest/backend/sox_io/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,21 @@ def test_alaw(self):
assert info.bits_per_sample == 8
assert info.encoding == "ALAW"

def test_gsm(self):
"""`sox_io_backend.info` can check gsm file correctly"""
duration = 1
num_channels = 1
sample_rate = 8000
path = self.get_temp_path('data.gsm')
sox_utils.gen_audio_file(
path, sample_rate=sample_rate, num_channels=num_channels,
duration=duration)
info = sox_io_backend.info(path)
assert info.sample_rate == sample_rate
assert info.num_channels == num_channels
assert info.bits_per_sample == 0
assert info.encoding == "GSM"


@skipIfNoExtension
class TestInfoOpus(PytorchTestCase):
Expand Down
37 changes: 1 addition & 36 deletions torchaudio/csrc/sox/io.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <sox.h>
#include <torchaudio/csrc/sox/effects.h>
#include <torchaudio/csrc/sox/effects_chain.h>
#include <torchaudio/csrc/sox/io.h>
#include <torchaudio/csrc/sox/types.h>
#include <torchaudio/csrc/sox/utils.h>

using namespace torch::indexing;
Expand All @@ -10,41 +10,6 @@ using namespace torchaudio::sox_utils;
namespace torchaudio {
namespace sox_io {

namespace {

std::string get_encoding(sox_encoding_t encoding) {
switch (encoding) {
case SOX_ENCODING_UNKNOWN:
return "UNKNOWN";
case SOX_ENCODING_SIGN2:
return "PCM_S";
case SOX_ENCODING_UNSIGNED:
return "PCM_U";
case SOX_ENCODING_FLOAT:
return "PCM_F";
case SOX_ENCODING_FLAC:
return "FLAC";
case SOX_ENCODING_ULAW:
return "ULAW";
case SOX_ENCODING_ALAW:
return "ALAW";
case SOX_ENCODING_MP3:
return "MP3";
case SOX_ENCODING_VORBIS:
return "VORBIS";
case SOX_ENCODING_AMR_WB:
return "AMR_WB";
case SOX_ENCODING_AMR_NB:
return "AMR_NB";
case SOX_ENCODING_OPUS:
return "OPUS";
default:
return "UNKNOWN";
}
}

} // namespace

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path,
c10::optional<std::string>& format) {
Expand Down
33 changes: 33 additions & 0 deletions torchaudio/csrc/sox/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,38 @@ BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth) {
}
}

std::string get_encoding(sox_encoding_t encoding) {
switch (encoding) {
case SOX_ENCODING_UNKNOWN:
return "UNKNOWN";
case SOX_ENCODING_SIGN2:
return "PCM_S";
case SOX_ENCODING_UNSIGNED:
return "PCM_U";
case SOX_ENCODING_FLOAT:
return "PCM_F";
case SOX_ENCODING_FLAC:
return "FLAC";
case SOX_ENCODING_ULAW:
return "ULAW";
case SOX_ENCODING_ALAW:
return "ALAW";
case SOX_ENCODING_MP3:
return "MP3";
case SOX_ENCODING_VORBIS:
return "VORBIS";
case SOX_ENCODING_AMR_WB:
return "AMR_WB";
case SOX_ENCODING_AMR_NB:
return "AMR_NB";
case SOX_ENCODING_OPUS:
return "OPUS";
case SOX_ENCODING_GSM:
return "GSM";
default:
return "UNKNOWN";
}
}

} // namespace sox_utils
} // namespace torchaudio
3 changes: 3 additions & 0 deletions torchaudio/csrc/sox/types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TORCHAUDIO_SOX_TYPES_H
#define TORCHAUDIO_SOX_TYPES_H

#include <sox.h>
#include <torch/script.h>

namespace torchaudio {
Expand Down Expand Up @@ -50,6 +51,8 @@ enum class BitDepth : unsigned {

BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth);

std::string get_encoding(sox_encoding_t encoding);

} // namespace sox_utils
} // namespace torchaudio

Expand Down