Skip to content
This repository has been archived by the owner on Feb 14, 2019. It is now read-only.

AudioFile changed to ndarray #5

Open
scaubrey opened this issue Jan 29, 2014 · 10 comments
Open

AudioFile changed to ndarray #5

scaubrey opened this issue Jan 29, 2014 · 10 comments

Comments

@scaubrey
Copy link

I'm using this library to analyze some audio and it appears that when zero padding in the Frame.frames(), numpy.append() returns a ndarray rather than an AudioFile. Attempting to call spectrum() on this ndarray throws an exception.

@jsawruk
Copy link
Owner

jsawruk commented Jan 30, 2014

Since numpy.append() returns an ndarray, and Frame is a subclass of ndarray, wouldn't it be possible to cast the result of the zero padding to a Frame?

In Frame.py, frames() method, try replacing the zero padding code with this:

diff = len(window) - len(frame)
frame = numpy.append(frame, [0] * diff)
frame = frame.view(Frame)

@scaubrey
Copy link
Author

Thanks for the reply. I my case it should be cast as an AudioFile since the sample rate is NoneType using Frame. I've tried frame.view(self.class), but this doesn't quite do it. Any other ideas?

On Jan 29, 2014, at 8:00 PM, jsawruk [email protected] wrote:

Since numpy.append() returns an ndarray, and Frame is a subclass of ndarray, wouldn't it be possible to cast the result of the zero padding to a Frame?

In Frame.py, frames() method, try replacing the zero padding code with this:

diff = len(window) - len(frame)
frame = numpy.append(frame, [0] * diff)
frame = frame.view(Frame)


Reply to this email directly or view it on GitHub.

@jsawruk
Copy link
Owner

jsawruk commented Jan 30, 2014

Try: frame.view(self.__class__.__name__)

@scaubrey
Copy link
Author

Tried that too, but it doesn't work either…

Thanks for the quick responses and for the library!

On Jan 29, 2014, at 8:48 PM, jsawruk [email protected] wrote:

Try: frame.view(self.class.name)


Reply to this email directly or view it on GitHub.

@jsawruk
Copy link
Owner

jsawruk commented Jan 30, 2014

It probably doesn't work that way because it's returning a string, though there must be a generic way to do this. A naive way to approach this would be to have a switch statement based on the class name, then cast the view to the appropriate type (if class = Frame, view Frame. if class = AudioFile, view AudioFile etc.)

Just out of curiosity, what are you using the library for? It was just something that I put together for myself based on things I had learned about MIR, but if it's useful to others, that's great!

@scaubrey
Copy link
Author

Yeah, casting as AudioFile returns a data type error as well. I agree that there should be a generic way of handling. Searching for a work around.

I'm analyzing audio for sound quality analysis of musical instruments. I am a research assistant at Georgia Tech in the Center for Music Technology and and usually do my MIR stuff in C++ or Matlab. Wanted to check out tools available for Python and your came up in Google.

On Jan 29, 2014, at 8:56 PM, jsawruk [email protected] wrote:

It probably doesn't work that way because it's returning a string, though there must be a generic way to do this. A naive way to approach this would be to have a switch statement based on the class name, then cast the view to the appropriate type (if class = Frame, view Frame. if class = AudioFile, view AudioFile etc.)

Just out of curiosity, what are you using the library for? It was just something that I put together for myself based on things I had learned about MIR, but if it's useful to others, that's great!


Reply to this email directly or view it on GitHub.

@jsawruk
Copy link
Owner

jsawruk commented Feb 1, 2014

Please try the latest commit.

@scaubrey
Copy link
Author

scaubrey commented Feb 1, 2014

Bummer, no dice. Error below. I looked into it a little bit, and it looks like when casting as AudioFile in the frames() function looses the info extracted from the AudioFile.open(), in the case of the below error the sample rate.

File "./analyzeTrumpet.py", line 52, in calculateFeatures
spreadArray = [n.spread() for n in spectra]
File "/Library/Python/2.7/site-packages/pymir/Spectrum.py", line 195, in spread
centroid = self.centroid()
File "/Library/Python/2.7/site-packages/pymir/Spectrum.py", line 83, in centroid
f = (self.sampleRate / 2.0) / len(self)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

On Jan 31, 2014, at 7:21 PM, jsawruk [email protected] wrote:

Please try the latest commit.


Reply to this email directly or view it on GitHub.

@jsawruk
Copy link
Owner

jsawruk commented Feb 1, 2014

I have changed the zero padding code to restore these properties.

@scaubrey
Copy link
Author

scaubrey commented Feb 1, 2014

That seemed to do it. Thanks for helping!

On Feb 1, 2014, at 9:36 AM, jsawruk [email protected] wrote:

I have changed the zero padding code to restore these properties.


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants