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

Function data_from_file

mingus/extra/fft.py:129–150  ·  view source on GitHub ↗

Return (first channel data, sample frequency, sample width) from a .wav file.

(file)

Source from the content-addressed store, hash-verified

127
128
129def data_from_file(file):
130 """Return (first channel data, sample frequency, sample width) from a .wav
131 file."""
132 fp = wave.open(file, "rb")
133 data = fp.readframes(fp.getnframes())
134 channels = fp.getnchannels()
135 freq = fp.getframerate()
136 bits = fp.getsampwidth()
137
138 # Unpack bytes -- warning currently only tested with 16 bit wavefiles. 32
139 # bit not supported.
140 data = struct.unpack(("%sh" % fp.getnframes()) * channels, data)
141
142 # Only use first channel
143 channel1 = []
144 n = 0
145 for d in data:
146 if n % channels == 0:
147 channel1.append(d)
148 n += 1
149 fp.close()
150 return (channel1, freq, bits)
151
152
153def find_Note(data, freq, bits):

Callers 1

find_melodyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected