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
12 changes: 6 additions & 6 deletions torchaudio/csrc/sox/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ std::tuple<torch::Tensor, int64_t> apply_effects_tensor(
std::tuple<torch::Tensor, int64_t> apply_effects_file(
const std::string path,
std::vector<std::vector<std::string>> effects,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format) {
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format) {
// Open input file
SoxFormat sf(sox_open_read(
path.c_str(),
Expand Down Expand Up @@ -161,9 +161,9 @@ std::tuple<torch::Tensor, int64_t> apply_effects_file(
std::tuple<torch::Tensor, int64_t> apply_effects_fileobj(
py::object fileobj,
std::vector<std::vector<std::string>> effects,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format) {
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format) {
// Prepare the buffer used throughout the lifecycle of SoxEffectChain.
//
// For certain format (such as FLAC), libsox keeps reading the content at
Expand Down
12 changes: 6 additions & 6 deletions torchaudio/csrc/sox/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ std::tuple<torch::Tensor, int64_t> apply_effects_tensor(
std::tuple<torch::Tensor, int64_t> apply_effects_file(
const std::string path,
std::vector<std::vector<std::string>> effects,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format);
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format);

#ifdef TORCH_API_INCLUDE_EXTENSION_H

std::tuple<torch::Tensor, int64_t> apply_effects_fileobj(
py::object fileobj,
std::vector<std::vector<std::string>> effects,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format);
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format);

#endif // TORCH_API_INCLUDE_EXTENSION_H

Expand Down
44 changes: 22 additions & 22 deletions torchaudio/csrc/sox/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::string get_encoding(sox_encoding_t encoding) {

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path,
c10::optional<std::string>& format) {
c10::optional<std::string> format) {
SoxFormat sf(sox_open_read(
path.c_str(),
/*signal=*/nullptr,
Expand All @@ -69,8 +69,8 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
namespace {

std::vector<std::vector<std::string>> get_effects(
c10::optional<int64_t>& frame_offset,
c10::optional<int64_t>& num_frames) {
c10::optional<int64_t> frame_offset,
c10::optional<int64_t> num_frames) {
const auto offset = frame_offset.value_or(0);
if (offset < 0) {
throw std::runtime_error(
Expand Down Expand Up @@ -101,11 +101,11 @@ std::vector<std::vector<std::string>> get_effects(

std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path,
c10::optional<int64_t>& frame_offset,
c10::optional<int64_t>& num_frames,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format) {
c10::optional<int64_t> frame_offset,
c10::optional<int64_t> num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format) {
auto effects = get_effects(frame_offset, num_frames);
return torchaudio::sox_effects::apply_effects_file(
path, effects, normalize, channels_first, format);
Expand All @@ -116,10 +116,10 @@ void save_audio_file(
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double>& compression,
c10::optional<std::string>& format,
c10::optional<std::string>& encoding,
c10::optional<int64_t>& bits_per_sample) {
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample) {
validate_input_tensor(tensor);

const auto filetype = [&]() {
Expand Down Expand Up @@ -162,7 +162,7 @@ void save_audio_file(

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_fileobj(
py::object fileobj,
c10::optional<std::string>& format) {
c10::optional<std::string> format) {
// Prepare in-memory file object
// When libsox opens a file, it also reads the header.
// When opening a file there are two functions that might touch FILE* (and the
Expand Down Expand Up @@ -213,11 +213,11 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_fileobj(

std::tuple<torch::Tensor, int64_t> load_audio_fileobj(
py::object fileobj,
c10::optional<int64_t>& frame_offset,
c10::optional<int64_t>& num_frames,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format) {
c10::optional<int64_t> frame_offset,
c10::optional<int64_t> num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format) {
auto effects = get_effects(frame_offset, num_frames);
return torchaudio::sox_effects::apply_effects_fileobj(
fileobj, effects, normalize, channels_first, format);
Expand Down Expand Up @@ -250,10 +250,10 @@ void save_audio_fileobj(
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double>& compression,
c10::optional<std::string>& format,
c10::optional<std::string>& encoding,
c10::optional<int64_t>& bits_per_sample) {
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample) {
validate_input_tensor(tensor);

if (!format.has_value()) {
Expand Down
40 changes: 20 additions & 20 deletions torchaudio/csrc/sox/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,49 @@ namespace sox_io {

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path,
c10::optional<std::string>& format);
c10::optional<std::string> format);

std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path,
c10::optional<int64_t>& frame_offset,
c10::optional<int64_t>& num_frames,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format);
c10::optional<int64_t> frame_offset,
c10::optional<int64_t> num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format);

void save_audio_file(
const std::string& path,
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double>& compression,
c10::optional<std::string>& format,
c10::optional<std::string>& encoding,
c10::optional<int64_t>& bits_per_sample);
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample);

#ifdef TORCH_API_INCLUDE_EXTENSION_H

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_fileobj(
py::object fileobj,
c10::optional<std::string>& format);
c10::optional<std::string> format);

std::tuple<torch::Tensor, int64_t> load_audio_fileobj(
py::object fileobj,
c10::optional<int64_t>& frame_offset,
c10::optional<int64_t>& num_frames,
c10::optional<bool>& normalize,
c10::optional<bool>& channels_first,
c10::optional<std::string>& format);
c10::optional<int64_t> frame_offset,
c10::optional<int64_t> num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
c10::optional<std::string> format);

void save_audio_fileobj(
py::object fileobj,
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double>& compression,
c10::optional<std::string>& format,
c10::optional<std::string>& encoding,
c10::optional<int64_t>& bits_per_sample);
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample);

#endif // TORCH_API_INCLUDE_EXTENSION_H

Expand Down
4 changes: 2 additions & 2 deletions torchaudio/csrc/sox/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::string to_string(Encoding v) {
}
}

Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) {
Encoding get_encoding_from_option(const c10::optional<std::string> encoding) {
if (!encoding.has_value())
return Encoding::NOT_PROVIDED;
std::string v = encoding.value();
Expand All @@ -77,7 +77,7 @@ Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) {
throw std::runtime_error(stream.str());
}

BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth) {
BitDepth get_bit_depth_from_option(const c10::optional<int64_t> bit_depth) {
if (!bit_depth.has_value())
return BitDepth::NOT_PROVIDED;
int64_t v = bit_depth.value();
Expand Down
4 changes: 2 additions & 2 deletions torchaudio/csrc/sox/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum class Encoding {
};

std::string to_string(Encoding v);
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding);
Encoding get_encoding_from_option(const c10::optional<std::string> encoding);

enum class BitDepth : unsigned {
NOT_PROVIDED = 0,
Expand All @@ -48,7 +48,7 @@ enum class BitDepth : unsigned {
B64 = 64,
};

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

} // namespace sox_utils
} // namespace torchaudio
Expand Down
10 changes: 5 additions & 5 deletions torchaudio/csrc/sox/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding_for_wav(
std::tuple<sox_encoding_t, unsigned> get_save_encoding(
const std::string& format,
const caffe2::TypeMeta dtype,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) {
const c10::optional<std::string> encoding,
const c10::optional<int64_t> bits_per_sample) {
const Format fmt = get_format_from_string(format);
const Encoding enc = get_encoding_from_option(encoding);
const BitDepth bps = get_bit_depth_from_option(bits_per_sample);
Expand Down Expand Up @@ -479,9 +479,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(caffe2::TypeMeta dtype) {
sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format,
const caffe2::TypeMeta dtype,
const c10::optional<double>& compression,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) {
const c10::optional<double> compression,
const c10::optional<std::string> encoding,
const c10::optional<int64_t> bits_per_sample) {
auto enc = get_save_encoding(format, dtype, encoding, bits_per_sample);
return sox_encodinginfo_t{
/*encoding=*/std::get<0>(enc),
Expand Down
6 changes: 3 additions & 3 deletions torchaudio/csrc/sox/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(const caffe2::TypeMeta dtype);
sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format,
const caffe2::TypeMeta dtype,
const c10::optional<double>& compression,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample);
const c10::optional<double> compression,
const c10::optional<std::string> encoding,
const c10::optional<int64_t> bits_per_sample);

#ifdef TORCH_API_INCLUDE_EXTENSION_H

Expand Down