* Builds each waveform for the page.
()
| 76 | * Builds each waveform for the page. |
| 77 | */ |
| 78 | function build() { |
| 79 | if (config.web_audio_api_available) { |
| 80 | /* |
| 81 | If we don't have the wave form built, we need to build the waveform by loading |
| 82 | the src with an array buffer. |
| 83 | */ |
| 84 | if ( |
| 85 | config.waveforms.built[ |
| 86 | Math.abs( |
| 87 | config.audio.src.split("").reduce(function(a, b) { |
| 88 | a = (a << 5) - a + b.charCodeAt(0); |
| 89 | return a & a; |
| 90 | }, 0) |
| 91 | ) |
| 92 | ] == undefined |
| 93 | ) { |
| 94 | /* |
| 95 | Initializes a new XML Http Request. |
| 96 | */ |
| 97 | var req = new XMLHttpRequest(); |
| 98 | |
| 99 | /* |
| 100 | Opens the src parameter for the audio file to read in. |
| 101 | */ |
| 102 | req.open("GET", config.audio.src, true); |
| 103 | req.responseType = "arraybuffer"; |
| 104 | |
| 105 | /* |
| 106 | When the ready state changes, check to see if we can render the |
| 107 | wave form. |
| 108 | */ |
| 109 | req.onreadystatechange = function(e) { |
| 110 | /* |
| 111 | When the request is complete, then we begin decoding the |
| 112 | audio to build the waveform. |
| 113 | */ |
| 114 | if (req.readyState == 4) { |
| 115 | /* |
| 116 | If the status is 200 means the response is a success and |
| 117 | we decode the audio data. |
| 118 | */ |
| 119 | if (req.status == 200) { |
| 120 | /* |
| 121 | Decode the audio data and process the waveform. |
| 122 | */ |
| 123 | config.context.decodeAudioData(req.response, function( |
| 124 | bufferedAudio |
| 125 | ) { |
| 126 | /* |
| 127 | Set the buffer to the audio returned. |
| 128 | */ |
| 129 | buffer = bufferedAudio; |
| 130 | |
| 131 | /* |
| 132 | Get the peaks in the audio. |
| 133 | */ |
| 134 | peaks = getPeaks(sampleRate, buffer); |
| 135 |
nothing calls this directly
no test coverage detected