Skip to content

Commit 4b3e905

Browse files
authored
Remove frames_per_chunk argument from save (#780)
In #779, we plan to remove `frames_per_chunk` parameter from `save` function, but it will take some time before we can land #779, so we go ahead and remove the parameter first to reduce the conflict caused by interface change.
1 parent f6dc2f6 commit 4b3e905

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

torchaudio/backend/sox_io_backend.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def save(
8787
sample_rate: int,
8888
channels_first: bool = True,
8989
compression: Optional[float] = None,
90-
frames_per_chunk: int = 65536,
9190
):
9291
"""Save audio data to file.
9392
@@ -115,8 +114,6 @@ def save(
115114
``8`` is default and highest compression.
116115
- OGG/VORBIS: number from -1 to 10; -1 is the highest compression and lowest
117116
quality. Default: ``3``.
118-
frames_per_chunk: The number of frames to process (convert to ``int32`` internally
119-
then write to file) at a time.
120117
"""
121118
if compression is None:
122119
ext = str(filepath)[-3:].lower()
@@ -131,7 +128,7 @@ def save(
131128
else:
132129
raise RuntimeError(f'Unsupported file type: "{ext}"')
133130
signal = torch.classes.torchaudio.TensorSignal(tensor, sample_rate, channels_first)
134-
torch.ops.torchaudio.sox_io_save_audio_file(filepath, signal, compression, frames_per_chunk)
131+
torch.ops.torchaudio.sox_io_save_audio_file(filepath, signal, compression)
135132

136133

137134
load_wav = load

torchaudio/csrc/register.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static auto registerLoadAudioFile = torch::RegisterOperators().op(
4444
static auto registerSaveAudioFile = torch::RegisterOperators().op(
4545
torch::RegisterOperators::options()
4646
.schema(
47-
"torchaudio::sox_io_save_audio_file(str path, __torch__.torch.classes.torchaudio.TensorSignal signal, float compression, int frames_per_chunk) -> ()")
47+
"torchaudio::sox_io_save_audio_file(str path, __torch__.torch.classes.torchaudio.TensorSignal signal, float compression) -> ()")
4848
.catchAllKernel<
4949
decltype(sox_io::save_audio_file),
5050
&sox_io::save_audio_file>());

torchaudio/csrc/sox_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ c10::intrusive_ptr<TensorSignal> load_audio_file(
123123
void save_audio_file(
124124
const std::string& file_name,
125125
const c10::intrusive_ptr<TensorSignal>& signal,
126-
const double compression,
127-
const int64_t frames_per_chunk) {
126+
const double compression) {
128127
const auto tensor = signal->getTensor();
129128
const auto sample_rate = signal->getSampleRate();
130129
const auto channels_first = signal->getChannelsFirst();
@@ -154,6 +153,7 @@ void save_audio_file(
154153
tensor_ = tensor_.t();
155154
}
156155

156+
const int64_t frames_per_chunk = 65536;
157157
for (int64_t i = 0; i < tensor_.size(0); i += frames_per_chunk) {
158158
auto chunk = tensor_.index({Slice(i, i + frames_per_chunk), Slice()});
159159
chunk = unnormalize_wav(chunk).contiguous();

torchaudio/csrc/sox_io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ c10::intrusive_ptr<torchaudio::sox_utils::TensorSignal> load_audio_file(
3333
void save_audio_file(
3434
const std::string& file_name,
3535
const c10::intrusive_ptr<torchaudio::sox_utils::TensorSignal>& signal,
36-
const double compression = 0.,
37-
const int64_t frames_per_chunk = 65536);
36+
const double compression = 0.);
37+
3838
} // namespace sox_io
3939
} // namespace torchaudio
4040

0 commit comments

Comments
 (0)