Skip to content
Browse files

Fixed error when importing monophonicc wav files

  • Loading branch information...
1 parent 8674c1b commit 08910b205e12ebe3f5ed8da3764709a7db4fd0f3 @jsawruk committed Dec 17, 2012
Showing with 11 additions and 10 deletions.
  1. +2 −1 pymir/AudioFile.py
  2. +6 −6 pymir/MFCC.py
  3. +3 −3 pymir/Spectrum.py
View
3 pymir/AudioFile.py
@@ -100,7 +100,8 @@ def open(filename, sampleRate=44100):
samples = samples.astype('float32') / 32767.0
# Get left channel
- samples = samples[:, 0]
+ if len(samples.shape) > 1:
+ samples = samples[:, 0]
audioFile = samples.view(AudioFile)
audioFile.sampleRate = sampleRate
View
12 pymir/MFCC.py
@@ -1,7 +1,7 @@
"""
MFCC methods
Compute Mel-Frequency Cepstral Coefficients
-Last updated: 15 December 2012
+Last updated: 17 December 2012
"""
from __future__ import division
@@ -14,22 +14,22 @@
import scipy
from scipy.fftpack import *
-def mfcc2(spectrum):
+def mfcc2(spectrum, numFilters = 32):
"""
Alternative (and vectorized) MFCC computation from Steve Tjoa
"""
- fb = filterbank(spectrum, spectrum.sampleRate)
+ fb = filterbank(spectrum, spectrum.sampleRate, numFilters)
coeff = scipy.fftpack.dct(scipy.log(fb), type = 2, norm = 'ortho')
return coeff
-def filterbank(x, fs):
+def filterbank(x, fs, numFilters):
n = len(x)
m = 2 ** (1.0 / 6)
f2 = 110.0
f1 = f2 / m
f3 = f2 * m
- fb = scipy.array(scipy.zeros(32))
- for i in range(32):
+ fb = scipy.array(scipy.zeros(numFilters))
+ for i in range(numFilters):
fb[i] = numpy.absolute(fbwin(x, fs, f1, f2, f3))
f1 = f2
f2 = f3
View
6 pymir/Spectrum.py
@@ -1,7 +1,7 @@
"""
Spectrum class
ndarray subclass for spectral data
-Last updated: 9 December 2012
+Last updated: 17 December 2012
"""
from __future__ import division
@@ -148,11 +148,11 @@ def mfcc(self, m, NumFilters = 48):
"""
return MFCC.mfcc(self, m, NumFilters)
- def mfcc2(self):
+ def mfcc2(self, numFilters = 32):
"""
Vectorized MFCC implementation
"""
- return MFCC.mfcc2(self)
+ return MFCC.mfcc2(self, numFilters)
def plot(self):
"""

0 comments on commit 08910b2

Please sign in to comment.
Something went wrong with that request. Please try again.