Ejemplo n.º 1
0
def createSnareFft():
	# read in the snare drum sample
	files = glob.glob('./snare_samples/*.wav')
	matrix = numpy.array([])
	for filename in files:
		print filename
		rate, data = wave_reader.readWav(filename)
		data = wave_reader.stereoToMono(data)
		features = analyzer.getFrequencies(data)
		matrix = build_data.addToFeatureMatrix(matrix, features[0:2000])
	build_data.saveFile('snaredata.csv', matrix)
Ejemplo n.º 2
0
def analyzeSong(filename):
	# generate the average fourier transform of a kick
	snare = numpy.genfromtxt('snaredata.csv', delimiter=",")
	kick = numpy.genfromtxt('kickdata.csv', delimiter=",")
	meanSnare, covar = analyzeSoundType(snare)
	meanKick, covar = analyzeSoundType(kick)
	dataMat = readSong(filename)
	matrix = numpy.array([])
	for i in range(0, len(dataMat), 5):
		dist = numpy.zeros(len(dataMat))
		for j in range(0, 4):
			dist[j] = numpy.dot(meanVec, dataMat[i + j])
		minDistIndex = numpy.argmin(dist)
		matrix = build_data.addToFeatureMatrix(matrix, dataMat[i + minDistIndex])
	build_data.saveFile(filename + '.csv', matrix)
Ejemplo n.º 3
0
def readSong(filename, segTime = 0.05):
	# read in the input song
	rate, data = wave_reader.readWav(filename)
	data = wave_reader.stereoToMono(data)
	# sample every 0.1 seconds by default
	segSize = segTime * rate
	matrix = numpy.array([])
	print 'reading in song...'
	start = 0
	end = segSize
	for i in range(0, int(math.floor(len(data)/segSize))):
		data_seg = data[start:end]
		start += segSize
		end += segSize
		features = analyzer.getFrequencies(data_seg)
		matrix = build_data.addToFeatureMatrix(matrix, features[0:2000])
	outfile = os.path.splitext(filename)[0] + '.csv'
	build_data.saveFile(outfile, matrix)
	return matrix
Ejemplo n.º 4
0
def extractFeatures(track, div):
    rate, data = wavfile.read(track + '.wav')
    if data.ndim > 1:
        data = stereoToMono(data)
    matrix = numpy.array([])
    vmatrix = numpy.array([])

    segSize = rate / div
    start = 0
    end = segSize
    for i in range(0, data.size / segSize):
        data_seg = data[start:end]
        start += segSize
        end += segSize
        features = analyzer.getFrequencies(data_seg)[0:5000]
        matrix = build_data.addToFeatureMatrix(matrix, features)
        vmatrix = build_data.addToFeatureMatrix(vmatrix,
                             numpy.array([numpy.argmax(features)]))
    build_data.saveFile(track + '_seg.csv', matrix)
    build_data.saveFile(track + '_volume.csv', vmatrix)