Skip to content
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

Division by NoneType in TimeStretch #34

Closed
slychief opened this issue Aug 19, 2016 · 1 comment · Fixed by #35
Closed

Division by NoneType in TimeStretch #34

slychief opened this issue Aug 19, 2016 · 1 comment · Fixed by #35
Assignees
Labels
Milestone

Comments

@slychief
Copy link

slychief commented Aug 19, 2016

The attempt to produce a time stretch transformation to an audio file raises a type error exception due to a division by a None type.

import jams
import muda

audiofile = "D:/temp/test.mp3"

jam = jams.JAMS()
jam = muda.jam_pack(jam)

jam = muda.core.load_jam_audio(jam, audiofile)

# this works
P = muda.deformers.PitchShift(n_semitones=5)
out_jams = list(P.transform(jam))

# this not
T = muda.deformers.TimeStretch(rate=2.0)
out_jams = list(T.transform(jam))

produces the following error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-603bfe0e77bc> in <module>()
     13 
     14 T = muda.deformers.TimeStretch(rate=2.0)
---> 15 out_jams = list(T.transform(jam))

C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\base.pyc in transform(self, jam)
    141 
    142         for state in self.states(jam):
--> 143             yield self._transform(jam, state)
    144 
    145     @property

C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\base.pyc in _transform(self, jam, state)
    112 
    113         if hasattr(self, 'metadata'):
--> 114             self.metadata(jam_w.file_metadata, state)
    115 
    116         # Walk over the list of deformers

C:\Anaconda\lib\site-packages\muda-0.1.1-py2.7.egg\muda\deformers\time.pyc in metadata(metadata, state)
     40     def metadata(metadata, state):
     41         # Deform the metadata
---> 42         metadata.duration /= state['rate']
     43 
     44     @staticmethod

TypeError: unsupported operand type(s) for /=: 'NoneType' and 'float'
@bmcfee
Copy link
Owner

bmcfee commented Aug 19, 2016

Aha, good catch.

It looks like the file_metadata.duration field is not getting initialized in load_jam_audio. This is an easy fix.

In the meantime, you can patch around this by setting the duration field manually after loading:

jam = muda.jam_pack(jam)

jam = muda.core.load_jam_audio(jam, audiofile)

jam.file_metadata.duration = librosa.get_duration(filename=audiofile)

# proceed as before

@bmcfee bmcfee added the bug label Aug 19, 2016
@bmcfee bmcfee self-assigned this Aug 19, 2016
@bmcfee bmcfee added this to the 0.1.2 milestone Aug 19, 2016
bmcfee added a commit that referenced this issue Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants