├── README.md └── buffaudio.js /README.md: -------------------------------------------------------------------------------- 1 | #BuffAudio.js 2 | 3 | BuffAudio.js is a wrapper around some of the HTML5 Web Audio API that lets you work easily with an AudioBuffer. The primary goals are to enable play, pause, stop, seek, and volume control. 4 | 5 | Here are some helpful docs from Mozilla on the Web Audio API: 6 | 7 | * [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer) 8 | * [AudioContext](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) 9 | * [AudioBufferSourceNode](https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode) 10 | * [AudioNode](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode) 11 | 12 | ##Usage: 13 | 14 | // audioContext is an AudioContext object: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext 15 | // buffer is an AudioBuffer object: https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer 16 | var buffAudio = new BuffAudio(audioContext, buffer); 17 | buffAudio.play(); 18 | buffAudio.pause(); 19 | buffAudio.play(); 20 | buffAudio.seek(5); // seconds 21 | buffAudio.stop(); 22 | 23 | buffAudio.initNewBuffer(buffer2); 24 | buffAudio.play(); 25 | 26 | ##Documentation: 27 | __initNewBuffer(buffer)__ 28 | Sets a new `buffer` (AudioBuffer). Will replace any existing AudioBuffer. 29 | 30 | __play()__ 31 | Plays the current buffer. If playback was paused (`pause()`) previously, it will resume where it left off. If playback was stopped (`stop()`) or played the entire AudioBuffer, playback will start from the beginning. 32 | 33 | __pause()__ 34 | Pauses playback and keeps track of time. 35 | 36 | __seek(time)__ 37 | Moves the current playback time to the `time` (in seconds) passed in. `seek` does not alter the current playback state, i.e. if the buffer is playing, it will continue playing from the new point, and if it is not playing it will not start playing. 38 | 39 | __stop()__ 40 | Stops playback. Playback time is set to the beginning of the buffer. 41 | 42 | 43 | __setVolume()__ 44 | UNIMPLEMENTED. Might add some gain nodes or something... 45 | 46 | 47 | 48 | ## Contribute 49 | Please contribute using pull requests. Feel free to email me with questions/critiques/etc. ernie.park@gmail.com 50 | 51 | ## Issues 52 | Submit issues through GitHub. 53 | 54 | __Length issue__ The current version of the spec states: 55 | 56 | >This interface represents a memory-resident audio asset (for one-shot sounds and other short audio clips). Its format is non-interleaved IEEE 32-bit linear PCM with a nominal range of -1 -> +1. It can contain one or more channels. Typically, it would be expected that the length of the PCM data would be fairly short (usually somewhat less than a minute). For longer sounds, such as music soundtracks, streaming should be used with the audio element and MediaElementAudioSourceNode. 57 | 58 | I want to use BuffAudio/AudioBuffers for longer form content that is recorded directly in the browser. It does not seem like MediaElementSourceNode would work very well for this case since I'd have to convert the AudioBuffer I recorded into a format compatible with the