-
Notifications
You must be signed in to change notification settings - Fork 12
feat: replace scipy.wavfile with soundfile for WAV handling #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ ipython_log.py | |
| dist/ | ||
| tests/ | ||
| music/singing/ecantorix/ | ||
| .vscode/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| """ | ||
|
|
||
| import numpy as np | ||
| from scipy.io import wavfile | ||
| import soundfile as sf | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not convinced we should move from scipy.io.wavfile to soundfile. I understand it is more flexible, but do we need it? I am open to discuss it here or even in a call.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me get back to you in a day or two. I'm in the middle of a project, but thank you for the response and reviewing this! |
||
| from .functions import normalize_mono, normalize_stereo | ||
| from .filters import adsr, adsr_stereo | ||
|
|
||
|
|
@@ -25,14 +25,17 @@ def read_wav(filename: str): | |
| NDArray | ||
| Values of the WAV file | ||
| """ | ||
| s = wavfile.read(filename) | ||
| print(type(s[1] / 2 ** 15)) | ||
| if s[1].dtype != 'int16': | ||
| # Read integer PCM data (dtype=int16) | ||
| data, sr = sf.read(filename, dtype='int16') | ||
| print(type(data / 2 ** 15)) | ||
| if data.dtype != 'int16': | ||
| print('implement non 16bit samples!') | ||
| return np.array(None) | ||
| if len(s[1].shape) == 2: | ||
| return np.array(s[1].transpose() / 2 ** 15) | ||
| return s[1] / 2 ** 15 | ||
| # data: shape (nsamples,) or (nsamples, channels) | ||
| if data.ndim == 2: | ||
| # convert to (channels, nsamples) | ||
| return np.array(data.T / 2 ** 15) | ||
| return data / 2 ** 15 | ||
|
|
||
|
|
||
| def write_wav_mono(sonic_vector=SONIC_VECTOR_MONO, filename="asound.wav", | ||
|
|
@@ -79,7 +82,8 @@ def write_wav_mono(sonic_vector=SONIC_VECTOR_MONO, filename="asound.wav", | |
| print(f"File {filename} not written") | ||
| nn = eval("np.int" + str(bit_depth)) | ||
| result = nn(result) | ||
| wavfile.write(filename, sample_rate, result) | ||
| # Write to WAV using SoundFile | ||
| sf.write(filename, result, sample_rate) | ||
|
|
||
|
|
||
| def write_wav_stereo(sonic_vector=SONIC_VECTOR_STEREO, filename="asound.wav", | ||
|
|
@@ -126,4 +130,5 @@ def write_wav_stereo(sonic_vector=SONIC_VECTOR_STEREO, filename="asound.wav", | |
| print(f"File {filename} not written") | ||
| nn = eval("np.int" + str(bit_depth)) | ||
| result = nn(result) | ||
| wavfile.write(filename, sample_rate, result.T) | ||
| # Write to WAV using SoundFile | ||
| sf.write(filename, result.T, sample_rate) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you would move it to the music folder? So that it will be inside the package itself whenever we
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can do that. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there URLs you gave don't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will double check and fix. Thanks.