* Processes the audio and generates the waveform. * * @param {sampleRate} sampleRate - The rate we should sample the audio. * @param {arraybuffer} buffer - The Web Audio API * @param {array} peaks - The peaks in the audio.
(sampleRate, buffer, peaks)
| 170 | * @param {array} peaks - The peaks in the audio. |
| 171 | */ |
| 172 | function process(sampleRate, buffer, peaks) { |
| 173 | /* |
| 174 | If we have a buffer, we find the peaks in the audio. |
| 175 | */ |
| 176 | if (buffer) { |
| 177 | /* |
| 178 | Get the total peaks in the song. |
| 179 | */ |
| 180 | let totalPeaks = peaks.length; |
| 181 | |
| 182 | /* |
| 183 | Figure out the depth of the peak. |
| 184 | */ |
| 185 | let d = ""; |
| 186 | for (let peakNumber = 0; peakNumber < totalPeaks; peakNumber++) { |
| 187 | if (peakNumber % 2 === 0) { |
| 188 | d += ` M${~~(peakNumber / 2)}, ${peaks.shift()}`; |
| 189 | } else { |
| 190 | d += ` L${~~(peakNumber / 2)}, ${peaks.shift()}`; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | Add the waveform to the built waveforms array. |
| 196 | */ |
| 197 | config.waveforms.built[ |
| 198 | Math.abs( |
| 199 | config.audio.src.split("").reduce(function(a, b) { |
| 200 | a = (a << 5) - a + b.charCodeAt(0); |
| 201 | return a & a; |
| 202 | }, 0) |
| 203 | ) |
| 204 | ] = d; |
| 205 | |
| 206 | /* |
| 207 | Display the waveform. |
| 208 | */ |
| 209 | displayWaveForms( |
| 210 | config.waveforms.built[ |
| 211 | Math.abs( |
| 212 | config.audio.src.split("").reduce(function(a, b) { |
| 213 | a = (a << 5) - a + b.charCodeAt(0); |
| 214 | return a & a; |
| 215 | }, 0) |
| 216 | ) |
| 217 | ] |
| 218 | ); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Get the peaks of the audio for the waveform. |
no test coverage detected