Colored¶
MgAudioProcessor ¶
MgAudioProcessor(filename, n_fft, fmin, fmax=None, window_function=np.hanning)
Bases: object
The MgAudioProcessor class inherits from the MgAudio class for processing chunks of audio and calculating the spectral centroid and the peak samples in each chunk of audio.
Adapted from https://github.com/endolith/freesound-thumbnailer/blob/master/processing.py
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the audio file. |
required |
n_fft
|
int
|
Length of the FFT window. |
required |
fmin
|
int
|
Minimum frequency for computing spectral centroid. |
required |
fmax
|
int
|
Maximum frequency for computing spectral centroid. Defaults to None. |
None
|
window_function
|
int
|
Type of window to apply on chunks of audio. Defaults to np.hanning. |
hanning
|
Source code in musicalgestures/_colored.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
read_samples ¶
read_samples(start, size, resize_if_less=False)
Read size samples starting at start, if resize_if_less is True and less than size samples are read, resize the array to size and fill with zeros
Source code in musicalgestures/_colored.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
spectral_centroid ¶
spectral_centroid(seek_point)
Starting at seek_point to read n_fft samples and calculate the spectral centroid
Source code in musicalgestures/_colored.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
peaks ¶
peaks(start_seek, end_seek, block_size=1024)
Read all samples between start_seek and end_seek, then find the minimum and maximum peak in that range. Returns that pair in the order they were found. So if min was found first, it returns (min, max) else the other way around.
Source code in musicalgestures/_colored.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
MgWaveformImage ¶
MgWaveformImage(image_width=2500, image_height=500, cmap='freesound')
Bases: object
Given peaks and spectral centroids from the MgAudioProcessor class, the MgWaveformImage class will construct a wavefile image using OpenCV.
Adapted from https://github.com/endolith/freesound-thumbnailer/blob/master/processing.py
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_width
|
int
|
Number of pixels for the image width. Defaults to 2500. |
2500
|
image_height
|
int
|
Number of pixels for the image height. Defaults to 500. |
500
|
cmap
|
str
|
Colormap used for coloring the waveform, all colormaps included with matplotlib can be used. Defaults to 'freesound'. |
'freesound'
|
Source code in musicalgestures/_colored.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
draw_peaks ¶
draw_peaks(x, peaks, spectral_centroid)
Draw 2 peaks at x using the spectral_centroid for color
Source code in musicalgestures/_colored.py
194 195 196 197 198 199 200 201 202 203 | |
interpolate_colors ¶
interpolate_colors(colors, flat=False, num_colors=256)
Given a list of colors, create a larger list of colors linearly interpolating the first one. If flatten is True a list of numbers will be returned. If False, a list of (r,g,b) tuples. num_colors is the number of colors wanted in the final list
Source code in musicalgestures/_colored.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |