Mercurial > hg > smacpy
changeset 9:7adab9621caa
ability to handle non-mono audio files
author | Dan Stowell <danstowell@users.sourceforge.net> |
---|---|
date | Thu, 29 Nov 2012 13:12:05 +0000 |
parents | 6cafb481a1e5 |
children | 9f2626d226ca |
files | smacpy.py |
diffstat | 1 files changed, 3 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/smacpy.py Thu Nov 29 11:17:45 2012 +0000 +++ b/smacpy.py Thu Nov 29 13:12:05 2012 +0000 @@ -110,7 +110,7 @@ if verbose: print("Reading %s" % wavpath) if not os.path.isfile(wavpath): raise ValueError("path %s not found" % path) sf = Sndfile(wavpath, "r") - if sf.channels != 1: raise ValueError("sound file has multiple channels (%i) - mono audio required." % sf.channels) + if sf.channels != 1: print(" Sound file has multiple channels (%i) - channels will be mixed to mono." % sf.channels) if sf.samplerate != fs: raise ValueError("wanted sample rate %g - got %g." % (fs, sf.samplerate)) window = np.hamming(framelen) features = [] @@ -120,6 +120,8 @@ if len(chunk) != framelen: print("Not read sufficient samples - returning") break + if sf.channels != 1: + chunk = np.mean(chunk, 1) # mixdown framespectrum = np.fft.fft(window * chunk) magspec = abs(framespectrum[:framelen/2])