Convert audio data into a frequency-amplitude table using fast fourier transformation. Return a list of tuples (frequency, amplitude). Data should only contain one channel of audio.
(data, freq=44100, bits=16)
| 88 | |
| 89 | |
| 90 | def find_frequencies(data, freq=44100, bits=16): |
| 91 | """Convert audio data into a frequency-amplitude table using fast fourier |
| 92 | transformation. |
| 93 | |
| 94 | Return a list of tuples (frequency, amplitude). |
| 95 | |
| 96 | Data should only contain one channel of audio. |
| 97 | """ |
| 98 | # Fast fourier transform |
| 99 | n = len(data) |
| 100 | p = _fft(data) |
| 101 | uniquePts = math.ceil((n + 1) / 2.0) |
| 102 | |
| 103 | # Scale by the length (n) and square the value to get the amplitude |
| 104 | p = [(abs(x) / float(n)) ** 2 * 2 for x in p[0:uniquePts]] |
| 105 | p[0] = p[0] / 2 |
| 106 | if n % 2 == 0: |
| 107 | p[-1] = p[-1] / 2 |
| 108 | |
| 109 | # Generate the frequencies and zip with the amplitudes |
| 110 | s = freq / float(n) |
| 111 | freqArray = numpy.arange(0, uniquePts * s, s) |
| 112 | return list(zip(freqArray, p)) |
| 113 | |
| 114 | |
| 115 | def find_notes(freqTable, maxNote=100): |
no outgoing calls
no test coverage detected