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)
| 171 | |
| 172 | |
| 173 | def 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] |
nothing calls this directly
no test coverage detected