-
Notifications
You must be signed in to change notification settings - Fork 33
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
How to apply deformations from annotated jams file? #62
Comments
The problem here is that you're using Otherwise, your example looks fine. |
If I had to manually instantiate the deformer classes, then what is the point of reading the jams files which already has a history of deformations written in it? |
Sorry, I think I didn't understand what exactly you want to do. Is the problem that you only have deformed jams files, and want to recreate the corresponding audio?
Generally speaking, the deformation history is stored for logging purposes, not direct reconstruction.
There is an issue out for fully automated reconstruction #31 , but nobody's had the time to sit down and implement it. It's not a difficult thing to implement, but it does require some pretty detailed knowledge of how muda objects work. Here's a quick sketch of how that might work # Assume your unmodified audio/jams has been pre-loaded as `jam_in`
# And the deformed jams you want to reconstruct is loaded as `jam_out`
jam_re = jam_in
for step in jam_out.sandbox.muda.history:
defclass = step['transformer']['__class__']
params = step['transformer']['params']
deformer = getattr(muda.deformers, defclass)(**params)
state = step['state']
jam_re = deformer._transform(jam_re, state)
# jam_re should now match jam_out, but including audio In the initial design, reproducibility was intended to be achieved by serializing the deformer/pipeline objects separately, and then re-running the full deformation computation. I hadn't considered the use-case where someone would distribute jams output without the audio, but it makes sense. You're likely to encounter snags with the above code when reconstructing background noise transformers, eg, here. The problem is that those (necessarily) include paths to augmenting noise data files. If those files don't exist in your environment at the same location, the reconstruction will not work. I don't have a great solution for that at present; you might just have to detect when this happens and transform filenames on the fly. I hope that helps. |
Thank you @bmcfee for such a detailed answer. I have been going over the code base, documentation for more than a day trying to reconstruct the deformations.
I think you should mention it in your documentation.
pitch_shifts = [-2, -1, 1, 2]
deformers = [muda.deformers.PitchShift(n_semitones=i) for i in pitch_shifts]
union = muda.Union(steps=[\
('pitch_shift_{}'.format(pitch_shifts[i]), pitch_shift) \
for i, pitch_shift in enumerate(deformers)])
for fn in glob.glob(os.path.join(sounds_parent_dir, fold, file_ext)):
j_orig = muda.load_jam_audio(jams_parent_dir, fn)
for i, j_new in enumerate(union.transform(j_orig)):
num_deformers = len(deformers)
audio_dict = j_new.sandbox.muda._audio
# 'audio' holds the deformed audio data
audio, sr = audio_dict['y'], audio_dict['sr']
filename, ext = os.path.basename(fn).split('.')
output_filename = '{}_{}{}.{}'.format(filename, 'pitch', i % num_deformers, ext)
output_path = os.path.join(output_dir, fold, output_filename)
# librosa.output.write_wav(output_path, audio, sr)
scipy.io.wavfile.write(output_path, sr, audio)
print(output_path)
Nevermind, the audio files can be played back with sounddevice. |
Yeah, saving the audio can be a pain. I recommend pysoundfile for this. |
Thank you @bmcfee for all your help. Your suggestions helped me immensely. Edit: Your code snippet is working perfectly. If you want I can implement the feature based on your snippet. |
Reopening this, just to keep tabs on it until we put reconstruction in the library proper. |
I am trying to use these (https://github.com/justinsalamon/UrbanSound8K-JAMS) jams files to deform sound files.
I am trying to use BaseTransformer after creating the jams object from the jams file and the corresponding sound file. Like this,
But when I do this I am getting
NotImplementedError
.If I had to create deformations by creating objects from
muda.deformers.*
classes. Then what is the point of loading annotated jams files? Please help me understand the process.The text was updated successfully, but these errors were encountered: