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

Function find_frequencies

mingus/extra/fft.py:90–112  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

88
89
90def 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
115def find_notes(freqTable, maxNote=100):

Callers 2

find_NoteFunction · 0.85
analyze_chunksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected