torchaudio 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -47
- data/lib/torchaudio/transforms/mel_spectrogram.rb +12 -4
- data/lib/torchaudio/transforms/spectrogram.rb +11 -4
- data/lib/torchaudio/version.rb +1 -1
- data/lib/torchaudio.rb +113 -99
- metadata +5 -35
- data/ext/torchaudio/csrc/register.cpp +0 -65
- data/ext/torchaudio/csrc/sox.cpp +0 -361
- data/ext/torchaudio/csrc/sox.h +0 -71
- data/ext/torchaudio/csrc/sox_effects.cpp +0 -54
- data/ext/torchaudio/csrc/sox_effects.h +0 -18
- data/ext/torchaudio/csrc/sox_io.cpp +0 -170
- data/ext/torchaudio/csrc/sox_io.h +0 -41
- data/ext/torchaudio/csrc/sox_utils.cpp +0 -245
- data/ext/torchaudio/csrc/sox_utils.h +0 -100
- data/ext/torchaudio/ext.cpp +0 -33
- data/ext/torchaudio/extconf.rb +0 -79
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
#ifndef TORCHAUDIO_SOX_IO_H
|
|
2
|
-
#define TORCHAUDIO_SOX_IO_H
|
|
3
|
-
|
|
4
|
-
#include <torch/script.h>
|
|
5
|
-
#include <torchaudio/csrc/sox_utils.h>
|
|
6
|
-
|
|
7
|
-
namespace torchaudio {
|
|
8
|
-
namespace sox_io {
|
|
9
|
-
|
|
10
|
-
struct SignalInfo : torch::CustomClassHolder {
|
|
11
|
-
int64_t sample_rate;
|
|
12
|
-
int64_t num_channels;
|
|
13
|
-
int64_t num_frames;
|
|
14
|
-
|
|
15
|
-
SignalInfo(
|
|
16
|
-
const int64_t sample_rate_,
|
|
17
|
-
const int64_t num_channels_,
|
|
18
|
-
const int64_t num_frames_);
|
|
19
|
-
int64_t getSampleRate() const;
|
|
20
|
-
int64_t getNumChannels() const;
|
|
21
|
-
int64_t getNumFrames() const;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
c10::intrusive_ptr<SignalInfo> get_info(const std::string& path);
|
|
25
|
-
|
|
26
|
-
c10::intrusive_ptr<torchaudio::sox_utils::TensorSignal> load_audio_file(
|
|
27
|
-
const std::string& path,
|
|
28
|
-
const int64_t frame_offset = 0,
|
|
29
|
-
const int64_t num_frames = -1,
|
|
30
|
-
const bool normalize = true,
|
|
31
|
-
const bool channels_first = true);
|
|
32
|
-
|
|
33
|
-
void save_audio_file(
|
|
34
|
-
const std::string& file_name,
|
|
35
|
-
const c10::intrusive_ptr<torchaudio::sox_utils::TensorSignal>& signal,
|
|
36
|
-
const double compression = 0.);
|
|
37
|
-
|
|
38
|
-
} // namespace sox_io
|
|
39
|
-
} // namespace torchaudio
|
|
40
|
-
|
|
41
|
-
#endif
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
#include <c10/core/ScalarType.h>
|
|
2
|
-
#include <sox.h>
|
|
3
|
-
#include <torchaudio/csrc/sox_utils.h>
|
|
4
|
-
|
|
5
|
-
namespace torchaudio {
|
|
6
|
-
namespace sox_utils {
|
|
7
|
-
|
|
8
|
-
TensorSignal::TensorSignal(
|
|
9
|
-
torch::Tensor tensor_,
|
|
10
|
-
int64_t sample_rate_,
|
|
11
|
-
bool channels_first_)
|
|
12
|
-
: tensor(tensor_),
|
|
13
|
-
sample_rate(sample_rate_),
|
|
14
|
-
channels_first(channels_first_){};
|
|
15
|
-
|
|
16
|
-
torch::Tensor TensorSignal::getTensor() const {
|
|
17
|
-
return tensor;
|
|
18
|
-
}
|
|
19
|
-
int64_t TensorSignal::getSampleRate() const {
|
|
20
|
-
return sample_rate;
|
|
21
|
-
}
|
|
22
|
-
bool TensorSignal::getChannelsFirst() const {
|
|
23
|
-
return channels_first;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
SoxFormat::SoxFormat(sox_format_t* fd) noexcept : fd_(fd) {}
|
|
27
|
-
SoxFormat::~SoxFormat() {
|
|
28
|
-
if (fd_ != nullptr) {
|
|
29
|
-
sox_close(fd_);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
sox_format_t* SoxFormat::operator->() const noexcept {
|
|
33
|
-
return fd_;
|
|
34
|
-
}
|
|
35
|
-
SoxFormat::operator sox_format_t*() const noexcept {
|
|
36
|
-
return fd_;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
void validate_input_file(const SoxFormat& sf) {
|
|
40
|
-
if (static_cast<sox_format_t*>(sf) == nullptr) {
|
|
41
|
-
throw std::runtime_error("Error loading audio file: failed to open file.");
|
|
42
|
-
}
|
|
43
|
-
if (sf->encoding.encoding == SOX_ENCODING_UNKNOWN) {
|
|
44
|
-
throw std::runtime_error("Error loading audio file: unknown encoding.");
|
|
45
|
-
}
|
|
46
|
-
if (sf->signal.length == 0) {
|
|
47
|
-
throw std::runtime_error("Error reading audio file: unkown length.");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void validate_input_tensor(const torch::Tensor tensor) {
|
|
52
|
-
if (!tensor.device().is_cpu()) {
|
|
53
|
-
throw std::runtime_error("Input tensor has to be on CPU.");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (tensor.ndimension() != 2) {
|
|
57
|
-
throw std::runtime_error("Input tensor has to be 2D.");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const auto dtype = tensor.dtype();
|
|
61
|
-
if (!(dtype == torch::kFloat32 || dtype == torch::kInt32 ||
|
|
62
|
-
dtype == torch::kInt16 || dtype == torch::kUInt8)) {
|
|
63
|
-
throw std::runtime_error(
|
|
64
|
-
"Input tensor has to be one of float32, int32, int16 or uint8 type.");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
caffe2::TypeMeta get_dtype(
|
|
69
|
-
const sox_encoding_t encoding,
|
|
70
|
-
const unsigned precision) {
|
|
71
|
-
const auto dtype = [&]() {
|
|
72
|
-
switch (encoding) {
|
|
73
|
-
case SOX_ENCODING_UNSIGNED: // 8-bit PCM WAV
|
|
74
|
-
return torch::kUInt8;
|
|
75
|
-
case SOX_ENCODING_SIGN2: // 16-bit or 32-bit PCM WAV
|
|
76
|
-
switch (precision) {
|
|
77
|
-
case 16:
|
|
78
|
-
return torch::kInt16;
|
|
79
|
-
case 32:
|
|
80
|
-
return torch::kInt32;
|
|
81
|
-
default:
|
|
82
|
-
throw std::runtime_error(
|
|
83
|
-
"Only 16 and 32 bits are supported for signed PCM.");
|
|
84
|
-
}
|
|
85
|
-
default:
|
|
86
|
-
// default to float32 for the other formats, including
|
|
87
|
-
// 32-bit flaoting-point WAV,
|
|
88
|
-
// MP3,
|
|
89
|
-
// FLAC,
|
|
90
|
-
// VORBIS etc...
|
|
91
|
-
return torch::kFloat32;
|
|
92
|
-
}
|
|
93
|
-
}();
|
|
94
|
-
return c10::scalarTypeToTypeMeta(dtype);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
torch::Tensor convert_to_tensor(
|
|
98
|
-
sox_sample_t* buffer,
|
|
99
|
-
const int32_t num_samples,
|
|
100
|
-
const int32_t num_channels,
|
|
101
|
-
const caffe2::TypeMeta dtype,
|
|
102
|
-
const bool normalize,
|
|
103
|
-
const bool channels_first) {
|
|
104
|
-
auto t = torch::from_blob(
|
|
105
|
-
buffer, {num_samples / num_channels, num_channels}, torch::kInt32);
|
|
106
|
-
// Note: Tensor created from_blob does not own data but borrwos
|
|
107
|
-
// So make sure to create a new copy after processing samples.
|
|
108
|
-
if (normalize || dtype == torch::kFloat32) {
|
|
109
|
-
t = t.to(torch::kFloat32);
|
|
110
|
-
t *= (t > 0) / 2147483647. + (t < 0) / 2147483648.;
|
|
111
|
-
} else if (dtype == torch::kInt32) {
|
|
112
|
-
t = t.clone();
|
|
113
|
-
} else if (dtype == torch::kInt16) {
|
|
114
|
-
t.floor_divide_(1 << 16);
|
|
115
|
-
t = t.to(torch::kInt16);
|
|
116
|
-
} else if (dtype == torch::kUInt8) {
|
|
117
|
-
t.floor_divide_(1 << 24);
|
|
118
|
-
t += 128;
|
|
119
|
-
t = t.to(torch::kUInt8);
|
|
120
|
-
} else {
|
|
121
|
-
throw std::runtime_error("Unsupported dtype.");
|
|
122
|
-
}
|
|
123
|
-
if (channels_first) {
|
|
124
|
-
t = t.transpose(1, 0);
|
|
125
|
-
}
|
|
126
|
-
return t.contiguous();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
torch::Tensor unnormalize_wav(const torch::Tensor input_tensor) {
|
|
130
|
-
const auto dtype = input_tensor.dtype();
|
|
131
|
-
auto tensor = input_tensor;
|
|
132
|
-
if (dtype == torch::kFloat32) {
|
|
133
|
-
double multi_pos = 2147483647.;
|
|
134
|
-
double multi_neg = -2147483648.;
|
|
135
|
-
auto mult = (tensor > 0) * multi_pos - (tensor < 0) * multi_neg;
|
|
136
|
-
tensor = tensor.to(torch::dtype(torch::kFloat64));
|
|
137
|
-
tensor *= mult;
|
|
138
|
-
tensor.clamp_(multi_neg, multi_pos);
|
|
139
|
-
tensor = tensor.to(torch::dtype(torch::kInt32));
|
|
140
|
-
} else if (dtype == torch::kInt32) {
|
|
141
|
-
// already denormalized
|
|
142
|
-
} else if (dtype == torch::kInt16) {
|
|
143
|
-
tensor = tensor.to(torch::dtype(torch::kInt32));
|
|
144
|
-
tensor *= ((tensor != 0) * 65536);
|
|
145
|
-
} else if (dtype == torch::kUInt8) {
|
|
146
|
-
tensor = tensor.to(torch::dtype(torch::kInt32));
|
|
147
|
-
tensor -= 128;
|
|
148
|
-
tensor *= 16777216;
|
|
149
|
-
} else {
|
|
150
|
-
throw std::runtime_error("Unexpected dtype.");
|
|
151
|
-
}
|
|
152
|
-
return tensor;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const std::string get_filetype(const std::string path) {
|
|
156
|
-
std::string ext = path.substr(path.find_last_of(".") + 1);
|
|
157
|
-
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
|
158
|
-
return ext;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
sox_encoding_t get_encoding(
|
|
162
|
-
const std::string filetype,
|
|
163
|
-
const caffe2::TypeMeta dtype) {
|
|
164
|
-
if (filetype == "mp3")
|
|
165
|
-
return SOX_ENCODING_MP3;
|
|
166
|
-
if (filetype == "flac")
|
|
167
|
-
return SOX_ENCODING_FLAC;
|
|
168
|
-
if (filetype == "ogg" || filetype == "vorbis")
|
|
169
|
-
return SOX_ENCODING_VORBIS;
|
|
170
|
-
if (filetype == "wav") {
|
|
171
|
-
if (dtype == torch::kUInt8)
|
|
172
|
-
return SOX_ENCODING_UNSIGNED;
|
|
173
|
-
if (dtype == torch::kInt16)
|
|
174
|
-
return SOX_ENCODING_SIGN2;
|
|
175
|
-
if (dtype == torch::kInt32)
|
|
176
|
-
return SOX_ENCODING_SIGN2;
|
|
177
|
-
if (dtype == torch::kFloat32)
|
|
178
|
-
return SOX_ENCODING_FLOAT;
|
|
179
|
-
throw std::runtime_error("Unsupported dtype.");
|
|
180
|
-
}
|
|
181
|
-
throw std::runtime_error("Unsupported file type.");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
unsigned get_precision(
|
|
185
|
-
const std::string filetype,
|
|
186
|
-
const caffe2::TypeMeta dtype) {
|
|
187
|
-
if (filetype == "mp3")
|
|
188
|
-
return SOX_UNSPEC;
|
|
189
|
-
if (filetype == "flac")
|
|
190
|
-
return 24;
|
|
191
|
-
if (filetype == "ogg" || filetype == "vorbis")
|
|
192
|
-
return SOX_UNSPEC;
|
|
193
|
-
if (filetype == "wav") {
|
|
194
|
-
if (dtype == torch::kUInt8)
|
|
195
|
-
return 8;
|
|
196
|
-
if (dtype == torch::kInt16)
|
|
197
|
-
return 16;
|
|
198
|
-
if (dtype == torch::kInt32)
|
|
199
|
-
return 32;
|
|
200
|
-
if (dtype == torch::kFloat32)
|
|
201
|
-
return 32;
|
|
202
|
-
throw std::runtime_error("Unsupported dtype.");
|
|
203
|
-
}
|
|
204
|
-
throw std::runtime_error("Unsupported file type.");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
sox_signalinfo_t get_signalinfo(
|
|
208
|
-
const torch::Tensor& tensor,
|
|
209
|
-
const int64_t sample_rate,
|
|
210
|
-
const bool channels_first,
|
|
211
|
-
const std::string filetype) {
|
|
212
|
-
return sox_signalinfo_t{
|
|
213
|
-
/*rate=*/static_cast<sox_rate_t>(sample_rate),
|
|
214
|
-
/*channels=*/static_cast<unsigned>(tensor.size(channels_first ? 0 : 1)),
|
|
215
|
-
/*precision=*/get_precision(filetype, tensor.dtype()),
|
|
216
|
-
/*length=*/static_cast<uint64_t>(tensor.numel())};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
sox_encodinginfo_t get_encodinginfo(
|
|
220
|
-
const std::string filetype,
|
|
221
|
-
const caffe2::TypeMeta dtype,
|
|
222
|
-
const double compression) {
|
|
223
|
-
const double compression_ = [&]() {
|
|
224
|
-
if (filetype == "mp3")
|
|
225
|
-
return compression;
|
|
226
|
-
if (filetype == "flac")
|
|
227
|
-
return compression;
|
|
228
|
-
if (filetype == "ogg" || filetype == "vorbis")
|
|
229
|
-
return compression;
|
|
230
|
-
if (filetype == "wav")
|
|
231
|
-
return 0.;
|
|
232
|
-
throw std::runtime_error("Unsupported file type.");
|
|
233
|
-
}();
|
|
234
|
-
|
|
235
|
-
return sox_encodinginfo_t{/*encoding=*/get_encoding(filetype, dtype),
|
|
236
|
-
/*bits_per_sample=*/get_precision(filetype, dtype),
|
|
237
|
-
/*compression=*/compression_,
|
|
238
|
-
/*reverse_bytes=*/sox_option_default,
|
|
239
|
-
/*reverse_nibbles=*/sox_option_default,
|
|
240
|
-
/*reverse_bits=*/sox_option_default,
|
|
241
|
-
/*opposite_endian=*/sox_false};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
} // namespace sox_utils
|
|
245
|
-
} // namespace torchaudio
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#ifndef TORCHAUDIO_SOX_UTILS_H
|
|
2
|
-
#define TORCHAUDIO_SOX_UTILS_H
|
|
3
|
-
|
|
4
|
-
#include <sox.h>
|
|
5
|
-
#include <torch/script.h>
|
|
6
|
-
|
|
7
|
-
namespace torchaudio {
|
|
8
|
-
namespace sox_utils {
|
|
9
|
-
|
|
10
|
-
struct TensorSignal : torch::CustomClassHolder {
|
|
11
|
-
torch::Tensor tensor;
|
|
12
|
-
int64_t sample_rate;
|
|
13
|
-
bool channels_first;
|
|
14
|
-
|
|
15
|
-
TensorSignal(
|
|
16
|
-
torch::Tensor tensor_,
|
|
17
|
-
int64_t sample_rate_,
|
|
18
|
-
bool channels_first_);
|
|
19
|
-
|
|
20
|
-
torch::Tensor getTensor() const;
|
|
21
|
-
int64_t getSampleRate() const;
|
|
22
|
-
bool getChannelsFirst() const;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/// helper class to automatically close sox_format_t*
|
|
26
|
-
struct SoxFormat {
|
|
27
|
-
explicit SoxFormat(sox_format_t* fd) noexcept;
|
|
28
|
-
SoxFormat(const SoxFormat& other) = delete;
|
|
29
|
-
SoxFormat(SoxFormat&& other) = delete;
|
|
30
|
-
SoxFormat& operator=(const SoxFormat& other) = delete;
|
|
31
|
-
SoxFormat& operator=(SoxFormat&& other) = delete;
|
|
32
|
-
~SoxFormat();
|
|
33
|
-
sox_format_t* operator->() const noexcept;
|
|
34
|
-
operator sox_format_t*() const noexcept;
|
|
35
|
-
|
|
36
|
-
private:
|
|
37
|
-
sox_format_t* fd_;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
///
|
|
41
|
-
/// Verify that input file is found, has known encoding, and not empty
|
|
42
|
-
void validate_input_file(const SoxFormat& sf);
|
|
43
|
-
|
|
44
|
-
///
|
|
45
|
-
/// Verify that input Tensor is 2D, CPU and either uin8, int16, int32 or float32
|
|
46
|
-
void validate_input_tensor(const torch::Tensor);
|
|
47
|
-
|
|
48
|
-
///
|
|
49
|
-
/// Get target dtype for the given encoding and precision.
|
|
50
|
-
caffe2::TypeMeta get_dtype(
|
|
51
|
-
const sox_encoding_t encoding,
|
|
52
|
-
const unsigned precision);
|
|
53
|
-
|
|
54
|
-
///
|
|
55
|
-
/// Convert sox_sample_t buffer to uint8/int16/int32/float32 Tensor
|
|
56
|
-
/// NOTE: This function might modify the values in the input buffer to
|
|
57
|
-
/// reduce the number of memory copy.
|
|
58
|
-
/// @param buffer Pointer to buffer that contains audio data.
|
|
59
|
-
/// @param num_samples The number of samples to read.
|
|
60
|
-
/// @param num_channels The number of channels. Used to reshape the resulting
|
|
61
|
-
/// Tensor.
|
|
62
|
-
/// @param dtype Target dtype. Determines the output dtype and value range in
|
|
63
|
-
/// conjunction with normalization.
|
|
64
|
-
/// @param noramlize Perform normalization. Only effective when dtype is not
|
|
65
|
-
/// kFloat32. When effective, the output tensor is kFloat32 type and value range
|
|
66
|
-
/// is [-1.0, 1.0]
|
|
67
|
-
/// @param channels_first When True, output Tensor has shape of [num_channels,
|
|
68
|
-
/// num_frames].
|
|
69
|
-
torch::Tensor convert_to_tensor(
|
|
70
|
-
sox_sample_t* buffer,
|
|
71
|
-
const int32_t num_samples,
|
|
72
|
-
const int32_t num_channels,
|
|
73
|
-
const caffe2::TypeMeta dtype,
|
|
74
|
-
const bool normalize,
|
|
75
|
-
const bool channels_first);
|
|
76
|
-
|
|
77
|
-
///
|
|
78
|
-
/// Convert float32/int32/int16/uint8 Tensor to int32 for Torch -> Sox
|
|
79
|
-
/// conversion.
|
|
80
|
-
torch::Tensor unnormalize_wav(const torch::Tensor);
|
|
81
|
-
|
|
82
|
-
/// Extract extension from file path
|
|
83
|
-
const std::string get_filetype(const std::string path);
|
|
84
|
-
|
|
85
|
-
/// Get sox_signalinfo_t for passing a torch::Tensor object.
|
|
86
|
-
sox_signalinfo_t get_signalinfo(
|
|
87
|
-
const torch::Tensor& tensor,
|
|
88
|
-
const int64_t sample_rate,
|
|
89
|
-
const bool channels_first,
|
|
90
|
-
const std::string filetype);
|
|
91
|
-
|
|
92
|
-
/// Get sox_encofinginfo_t for saving audoi file
|
|
93
|
-
sox_encodinginfo_t get_encodinginfo(
|
|
94
|
-
const std::string filetype,
|
|
95
|
-
const caffe2::TypeMeta dtype,
|
|
96
|
-
const double compression);
|
|
97
|
-
|
|
98
|
-
} // namespace sox_utils
|
|
99
|
-
} // namespace torchaudio
|
|
100
|
-
#endif
|
data/ext/torchaudio/ext.cpp
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#include <torchaudio/csrc/sox.h>
|
|
2
|
-
|
|
3
|
-
#include <rice/rice.hpp>
|
|
4
|
-
#include <rice/stl.hpp>
|
|
5
|
-
|
|
6
|
-
extern "C"
|
|
7
|
-
void Init_ext()
|
|
8
|
-
{
|
|
9
|
-
auto rb_mTorchAudio = Rice::define_module("TorchAudio");
|
|
10
|
-
|
|
11
|
-
auto rb_mExt = Rice::define_module_under(rb_mTorchAudio, "Ext")
|
|
12
|
-
.define_singleton_function(
|
|
13
|
-
"read_audio_file",
|
|
14
|
-
[](const std::string& file_name, at::Tensor output, bool ch_first, int64_t nframes, int64_t offset, sox_signalinfo_t* si, sox_encodinginfo_t* ei, const char* ft) {
|
|
15
|
-
return torch::audio::read_audio_file(file_name, output, ch_first, nframes, offset, si, ei, ft);
|
|
16
|
-
})
|
|
17
|
-
.define_singleton_function(
|
|
18
|
-
"write_audio_file",
|
|
19
|
-
[](const std::string& file_name, const at::Tensor& tensor, sox_signalinfo_t* si, sox_encodinginfo_t* ei, const char* file_type) {
|
|
20
|
-
return torch::audio::write_audio_file(file_name, tensor, si, ei, file_type);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
auto rb_cSignalInfo = Rice::define_class_under<sox_signalinfo_t>(rb_mExt, "SignalInfo")
|
|
24
|
-
.define_constructor(Rice::Constructor<sox_signalinfo_t>())
|
|
25
|
-
.define_method("rate", [](sox_signalinfo_t& self) { return self.rate; })
|
|
26
|
-
.define_method("channels", [](sox_signalinfo_t& self) { return self.channels; })
|
|
27
|
-
.define_method("precision", [](sox_signalinfo_t& self) { return self.precision; })
|
|
28
|
-
.define_method("length", [](sox_signalinfo_t& self) { return self.length; })
|
|
29
|
-
.define_method("rate=", [](sox_signalinfo_t& self, sox_rate_t rate) { self.rate = rate; })
|
|
30
|
-
.define_method("channels=", [](sox_signalinfo_t& self, unsigned channels) { self.channels = channels; })
|
|
31
|
-
.define_method("precision=", [](sox_signalinfo_t& self, unsigned precision) { self.precision = precision; })
|
|
32
|
-
.define_method("length=", [](sox_signalinfo_t& self, sox_uint64_t length) { self.length = length; });
|
|
33
|
-
}
|
data/ext/torchaudio/extconf.rb
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
require "mkmf-rice"
|
|
2
|
-
|
|
3
|
-
$CXXFLAGS += " -std=c++17 $(optflags)"
|
|
4
|
-
|
|
5
|
-
ext = File.expand_path(".", __dir__)
|
|
6
|
-
csrc = File.expand_path("csrc", __dir__)
|
|
7
|
-
|
|
8
|
-
$srcs = Dir["{#{ext},#{csrc}}/*.cpp"]
|
|
9
|
-
$INCFLAGS << " -I#{File.expand_path("..", __dir__)}"
|
|
10
|
-
$VPATH << csrc
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# keep rest synced with Torch
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
# change to 0 for Linux pre-cxx11 ABI version
|
|
17
|
-
$CXXFLAGS += " -D_GLIBCXX_USE_CXX11_ABI=1"
|
|
18
|
-
|
|
19
|
-
apple_clang = RbConfig::CONFIG["CC_VERSION_MESSAGE"] =~ /apple clang/i
|
|
20
|
-
|
|
21
|
-
if apple_clang
|
|
22
|
-
# silence torch warnings
|
|
23
|
-
$CXXFLAGS += " -Wno-deprecated-declarations"
|
|
24
|
-
else
|
|
25
|
-
# silence rice warnings
|
|
26
|
-
$CXXFLAGS += " -Wno-noexcept-type"
|
|
27
|
-
|
|
28
|
-
# silence torch warnings
|
|
29
|
-
$CXXFLAGS += " -Wno-duplicated-cond -Wno-suggest-attribute=noreturn"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
paths = [
|
|
33
|
-
"/usr/local",
|
|
34
|
-
"/opt/homebrew",
|
|
35
|
-
"/home/linuxbrew/.linuxbrew"
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
inc, lib = dir_config("torch")
|
|
39
|
-
inc ||= paths.map { |v| "#{v}/include" }.find { |v| Dir.exist?("#{v}/torch") }
|
|
40
|
-
lib ||= paths.map { |v| "#{v}/lib" }.find { |v| Dir["#{v}/*torch_cpu*"].any? }
|
|
41
|
-
|
|
42
|
-
unless inc && lib
|
|
43
|
-
abort "LibTorch not found"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
cuda_inc, cuda_lib = dir_config("cuda")
|
|
47
|
-
cuda_inc ||= "/usr/local/cuda/include"
|
|
48
|
-
cuda_lib ||= "/usr/local/cuda/lib64"
|
|
49
|
-
|
|
50
|
-
$LDFLAGS += " -L#{lib}" if Dir.exist?(lib)
|
|
51
|
-
abort "LibTorch not found" unless have_library("torch")
|
|
52
|
-
|
|
53
|
-
have_library("mkldnn")
|
|
54
|
-
have_library("nnpack")
|
|
55
|
-
|
|
56
|
-
with_cuda = false
|
|
57
|
-
if Dir["#{lib}/*torch_cuda*"].any?
|
|
58
|
-
$LDFLAGS += " -L#{cuda_lib}" if Dir.exist?(cuda_lib)
|
|
59
|
-
with_cuda = have_library("cuda") && have_library("cudnn")
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
$INCFLAGS += " -I#{inc}"
|
|
63
|
-
$INCFLAGS += " -I#{inc}/torch/csrc/api/include"
|
|
64
|
-
|
|
65
|
-
$LDFLAGS += " -Wl,-rpath,#{lib}"
|
|
66
|
-
$LDFLAGS += ":#{cuda_lib}/stubs:#{cuda_lib}" if with_cuda
|
|
67
|
-
|
|
68
|
-
# https://github.com/pytorch/pytorch/blob/v1.5.0/torch/utils/cpp_extension.py#L1232-L1238
|
|
69
|
-
$LDFLAGS += " -lc10 -ltorch_cpu -ltorch"
|
|
70
|
-
if with_cuda
|
|
71
|
-
$LDFLAGS += " -lcuda -lnvrtc -lnvToolsExt -lcudart -lc10_cuda -ltorch_cuda -lcufft -lcurand -lcublas -lcudnn"
|
|
72
|
-
# TODO figure out why this is needed
|
|
73
|
-
$LDFLAGS += " -Wl,--no-as-needed,#{lib}/libtorch.so"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
abort "SoX not found" unless have_library("sox")
|
|
77
|
-
|
|
78
|
-
# create makefile
|
|
79
|
-
create_makefile("torchaudio/ext")
|