Skip to content

Commit

Permalink
Remove multiple definitions of SoxEffect. (pytorch#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored May 13, 2020
1 parent 3a4f356 commit 0c04667
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def check_env_flag(name, default=''):
'_torch_sox',
['torchaudio/torch_sox.cpp'],
libraries=libraries,
include_dirs=include_dirs,
include_dirs=include_dirs + [cwd],
extra_compile_args=eca,
extra_objects=extra_objects,
extra_link_args=ela),
Expand Down
10 changes: 3 additions & 7 deletions torchaudio/torch_sox.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <torchaudio/torch_sox.h>

#include <torch/extension.h>

#include <sox.h>
Expand Down Expand Up @@ -70,12 +72,6 @@ void read_audio(
}
} // namespace

struct SoxEffect {
SoxEffect() : ename(""), eopts({""}) { }
std::string ename;
std::vector<std::string> eopts;
};

std::tuple<sox_signalinfo_t, sox_encodinginfo_t> get_info(
const std::string& file_name
) {
Expand Down Expand Up @@ -195,7 +191,7 @@ void write_audio_file(
}

int initialize_sox() {
/* Initializion for sox effects. Only initialize once */
/* Initialization for sox effects. Only initialize once */
return sox_init();
}

Expand Down
18 changes: 12 additions & 6 deletions torchaudio/torch_sox.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <sox.h>

#include <string>
#include <tuple>
#include <vector>

#include <torch/extension.h>

namespace at {
struct Tensor;
Expand All @@ -9,7 +15,7 @@ namespace torch { namespace audio {
/// Reads an audio file from the given `path` into the `output` `Tensor` and
/// returns the sample rate of the audio file.
/// Throws `std::runtime_error` if the audio file could not be opened, or an
/// error ocurred during reading of the audio data.
/// error occurred during reading of the audio data.
int read_audio_file(
const std::string& file_name,
at::Tensor output,
Expand All @@ -18,24 +24,24 @@ int read_audio_file(
int64_t offset,
sox_signalinfo_t* si,
sox_encodinginfo_t* ei,
const char* ft)
const char* ft);

/// Writes the data of a `Tensor` into an audio file at the given `path`, with
/// a certain extension (e.g. `wav`or `mp3`) and sample rate.
/// Throws `std::runtime_error` when the audio file could not be opened for
/// writing, or an error ocurred during writing of the audio data.
/// writing, or an error occurred during writing of the audio data.
void write_audio_file(
const std::string& file_name,
at::Tensor& tensor,
const at::Tensor& tensor,
sox_signalinfo_t* si,
sox_encodinginfo_t* ei,
const char* file_type)
const char* file_type);

/// Reads an audio file from the given `path` and returns a tuple of
/// sox_signalinfo_t and sox_encodinginfo_t, which contain information about
/// the audio file such as sample rate, length, bit precision, encoding and more.
/// Throws `std::runtime_error` if the audio file could not be opened, or an
/// error ocurred during reading of the audio data.
/// error occurred during reading of the audio data.
std::tuple<sox_signalinfo_t, sox_encodinginfo_t> get_info(
const std::string& file_name);

Expand Down

0 comments on commit 0c04667

Please sign in to comment.