MCPcopy Create free account
hub / github.com/bspaans/python-mingus / find_melody

Function find_melody

mingus/extra/fft.py:173–195  ·  view source on GitHub ↗

Cut the sample into chunks and analyze each chunk. Return a list [(Note, chunks)] where chunks is the number of chunks where that note is the most dominant. If two consequent chunks turn out to return the same Note they are grouped together. This is an experimental function.

(file="440_480_clean.wav", chunksize=512)

Source from the content-addressed store, hash-verified

171
172
173def find_melody(file="440_480_clean.wav", chunksize=512):
174 """Cut the sample into chunks and analyze each chunk.
175
176 Return a list [(Note, chunks)] where chunks is the number of chunks
177 where that note is the most dominant.
178
179 If two consequent chunks turn out to return the same Note they are
180 grouped together.
181
182 This is an experimental function.
183 """
184 (data, freq, bits) = data_from_file(file)
185 res = []
186 for d in analyze_chunks(data, freq, bits, chunksize):
187 if res != []:
188 if res[-1][0] == d:
189 val = res[-1][1]
190 res[-1] = (d, val + 1)
191 else:
192 res.append((d, 1))
193 else:
194 res.append((d, 1))
195 return [(x, freq) for (x, freq) in res]

Callers

nothing calls this directly

Calls 2

data_from_fileFunction · 0.85
analyze_chunksFunction · 0.85

Tested by

no test coverage detected