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

python3 compat; pep8 linting #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions bregman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
__license__ = "GPL Version 2.0 or Higher"
__email__ = '[email protected]'

__all__ = ["features", "segment", "audiodb", "testsignal", "psychoacoustics", "tuning", "sound", "plca", "distance", "classifier", "error", "beat", "suite"]
__all__ = ["features", "segment", "audiodb", "testsignal", "psychoacoustics", "tuning", "sound", "plca", "distance", "classifier", "error", "beat", "suite", "sparseapprox"]

# import the bregman modules
import suite
import features
import segment
import audiodb
import testsignal
import psychoacoustics
import tuning
import sound
import plca
import distance
import classifier
import error
import beat
from . import suite
from . import features
from . import segment
from . import audiodb
from . import testsignal
from . import psychoacoustics
from . import tuning
from . import sound
from . import plca
from . import distance
from . import classifier
from . import error
from . import beat
from . import sparseapprox


44 changes: 22 additions & 22 deletions bregman/audiodb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

# AudioDB libraries
import glob
import pylab
from scipy.signal import resample
from . import error
from . import features

# AudioDB - routines for audio database I/O, searching, and manipulation
# Bregman - python toolkit for music information retrieval

Expand All @@ -7,19 +15,11 @@
__license__ = "GPL Version 2.0 or Higher"
__email__ = '[email protected]'


# AudioDB libraries
import glob
import error
import pylab
import features

try:
import pyadb
except ImportError:
pass
from scipy.signal import resample
import pdb


class adb:
"""
Expand All @@ -44,7 +44,7 @@ def read(fname, dtype='<f8'):
data = data.reshape(-1,dim)
return data
except IOError:
print "IOError: Cannot open %s for reading." %(fname)
print ("IOError: Cannot open %s for reading." %(fname))
raise IOError
finally:
if fd:
Expand All @@ -65,7 +65,7 @@ def write(fname,data, dtype='<f8'):
data = pylab.np.array(data,dtype=dtype)
data.tofile(fd)
except IOError:
print "IOError: Cannot open %s for writing." %(fname)
print ("IOError: Cannot open %s for writing." %(fname))
raise IOError
finally:
if fd:
Expand Down Expand Up @@ -288,8 +288,8 @@ def search(db, Key):
returns sorted list of results
"""
if not db.configCheck():
print "Failed configCheck in query spec."
print db.configQuery
print ("Failed configCheck in query spec.")
print (db.configQuery)
return None
res = db.query(Key)
res_resorted = adb.sort_search_result(res.rawData)
Expand All @@ -304,8 +304,8 @@ def tempo_search(db, Key, tempo):
Returns search results for query resampled over a range of tempos.
"""
if not db.configCheck():
print "Failed configCheck in query spec."
print db.configQuery
print ("Failed configCheck in query spec.")
print (db.configQuery)
return None
prop = 1./tempo # the proportion of original samples required for new tempo
qconf = db.configQuery.copy()
Expand Down Expand Up @@ -335,7 +335,7 @@ def sort_search_result(res):
"""
if not res or res==None:
return None
a,b,c,d = zip(*res)
a,b,c,d = list(zip(*res))
u = adb.uniquify(a)
i = 0
j = 0
Expand Down Expand Up @@ -388,7 +388,7 @@ def insert_audio_files(fileList, dbName, chroma=True, mfcc=False, cqft=False, pr
"""
db = adb.get(dbName, "w")
if not db:
print "Could not open database: %s" %dbName
print ("Could not open database: %s" %dbName)
return False
del db # commit the changes by closing the header
db = adb.get(dbName) # re-open for writing data
Expand All @@ -397,7 +397,7 @@ def insert_audio_files(fileList, dbName, chroma=True, mfcc=False, cqft=False, pr
for a, i in enumerate(fileList):
if progress:
progress((a+0.5)/float(len(fileList)),i) # frac, fname
print "Processing file: %s" %i
print ("Processing file: %s" %i)
F = features.Features(i)
if chroma: F.feature_params['feature']='chroma'
elif mfcc: F.feature_params['feature']='mfcc'
Expand Down Expand Up @@ -426,12 +426,12 @@ def insert_feature_files(featureList, powerList, keyList, dbName, delta_time=Non
db = adb.get(dbName,"w")

if not db:
print "Could not open database: %s" %dbName
print ("Could not open database: %s" %dbName)
return False
# FIXME: need to test if KEY (%i) already exists in db
# Support for removing keys via include/exclude keys
for feat,pwr,key in zip(featureList, powerList, keyList):
print "Processing features: %s" %key
print ("Processing features: %s" %key)
F = adb.read(feat)
P = adb.read(pwr)
a,b = F.shape
Expand All @@ -442,14 +442,14 @@ def insert_feature_files(featureList, powerList, keyList, dbName, delta_time=Non
if(len(P.shape)==1):
c = P.shape[0]
else:
print "Error: powers have incorrect shape={0}".format(P.shape)
print ("Error: powers have incorrect shape={0}".format(P.shape))
return None

if a != c:
F=F.T
a,b = F.shape
if a != c:
print "Error: powers and features different lengths powers={0}*, features={1},{2}*".format(c, a, b)
print ("Error: powers and features different lengths powers={0}*, features={1},{2}*".format(c, a, b))
return None
# raw features, power in Bels, and key
if undo_log10:
Expand Down
2 changes: 1 addition & 1 deletion bregman/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def beat_track(x, feature=LogFrequencySpectrum, **kwargs):
frame_rate = F.sample_rate / float(F.nhop)
D = diff(F.X, axis=1)
D[where(D < 0)] = 0
tempos = range(40, 200, 4)
tempos = list(range(40, 200, 4))
z = zeros((len(tempos), D.shape[0]))
for i, bpm in enumerate(tempos): # loop over tempos to test
t = int(round(frame_rate * 60. / bpm)) # num frames per beat
Expand Down
Loading