Last active
December 17, 2015 00:59
-
-
Save rc1/5524825 to your computer and use it in GitHub Desktop.
Make file for creating an mp3 audio sprite with an info JSON file for Howler.js. Input files maybe audio or video of any format supported by FFMPEG.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| loadAudioSpritesObj("/sounds/audiosprite.json", function (sprites) { | |
| console.log(sprites); | |
| }); | |
| function loadAudioSpritesObj(filenane, callback) { | |
| $.getJSON(filenane, function(json) { | |
| var sprites = {}; | |
| var lastPositionMS = 0; | |
| for (var i=0;i<json.length;i+=2) { | |
| var spriteEndTime = json[i] + lastPositionMS; | |
| sprites[json[i+1]] = [lastPositionMS, spriteEndTime]; | |
| lastPositionMS = spriteEndTime; | |
| } | |
| callback(sprites); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Makefile for creating the audio samples | |
| # Requires mp3info, mediainfo, mp3val | |
| SRC = LED_glitch.mov LEDpulse.mov apavilion.mov backfade_drum.mov green_record.mov light_down.mov light_up.mov pulse_ambient_LED.mov radio_bulb.mov silver_record.mov the_light.mp4 waterfall2.mp4 | |
| OUTPUT_FILE = audiosprite | |
| createaudio: | |
| $(foreach var, $(SRC), ffmpeg -i $(var) -ab 160k -ac 1 -ar 44100 -vn $(var).mp3;) | |
| mergeaudio: | |
| cat $(foreach var, $(SRC), $(var).mp3 > $(OUTPUT_FILE).mp3); | |
| mp3val $(OUTPUT_FILE).mp3 -f -nb | |
| mp3info -d $(OUTPUT_FILE).mp3 | |
| echo "[" > temp_$(OUTPUT_FILE).json | |
| $(foreach var, $(SRC), echo '' >> temp_$(OUTPUT_FILE).json; \ | |
| mediainfo --Output="General;%Duration%" $(var).mp3 \ | |
| >> temp_$(OUTPUT_FILE).json; \ | |
| echo ',"' >> temp_$(OUTPUT_FILE).json; \ | |
| echo $(var).mp3 >> temp_$(OUTPUT_FILE).json; \ | |
| echo '",' >> temp_$(OUTPUT_FILE).json;) | |
| echo '"terminator"]' >> temp_$(OUTPUT_FILE).json | |
| tr -d ' \t\n\r\f' <temp_$(OUTPUT_FILE).json >$(OUTPUT_FILE).json | |
| # on Linux the below first '' would be ommitted | |
| sed -i '' 's/,"terminator"//g' $(OUTPUT_FILE).json | |
| rm temp_$(OUTPUT_FILE).json | |
| all: createaudio mergeaudio | |
| .PHONY: all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment