Skip to content

Commit 77d5bd2

Browse files
committed
Temporary Final Commit of Audio Overhaul
Look at below for more information about this commit - #57
1 parent db8c964 commit 77d5bd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+7804
-1503
lines changed

.gitmodules

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,13 @@
7575
path = project/lib/hashlink
7676
url = https://github.com/HaxeFoundation/hashlink
7777
shallow = true
78+
[submodule "project/lib/dr_libs"]
79+
path = project/lib/dr_libs
80+
url = https://github.com/mackron/dr_libs
81+
shallow = true
82+
[submodule "project/lib/opusfile"]
83+
path = project/lib/opusfile
84+
url = https://github.com/xiph/opusfile
85+
[submodule "project/lib/opus"]
86+
path = project/lib/opus
87+
url = https://github.com/xiph/opus

NOTICE.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This product bundles cairo 1.15.2, which is available under an
1010
This product bundles libcurl 7.56.1, which is available under an
1111
"MIT/X derivate" license. For details, see [project/lib/curl/](project/lib).
1212

13+
This product bundles dr_libs (dr_flac 0.13.3, dr_mp3 0.7.4, dr_wav 0.14.5), which is available under an
14+
"MIT No Attribution" license. For details, see [project/lib/dr_libs/](project/lib).
15+
1316
This product bundles efsw, which is available under an
1417
"MIT" license. For details, see [project/lib/efsw/](project/lib).
1518

@@ -29,14 +32,20 @@ This product bundles libogg 1.3.0, which is available under a
2932
"BSD" license. For details, see [project/lib/ogg/](project/lib).
3033

3134
This product bundles LZMA SDK 4.65, which is available under
32-
public domain. For details, see [project/lib/lzma/](project/lzma).
35+
public domain. For details, see [project/lib/lzma/](project/lib).
3336

3437
This product bundles mbedTLS 2.6.0, which is available under an
3538
"Apache 2.0" license. For details, see [project/lib/mbedtls/](project/lib).
3639

3740
This product bundles OpenAL-Soft 1.25.1, which is available under an
3841
"LGPLv2" license. For details, see [project/lib/openal/](project/lib).
3942

43+
This product bundles opus, which is available under a
44+
"BSD" license. For details, see [project/lib/opus/](project/lib).
45+
46+
This product bundles opusfile, which is available under a
47+
"BSD" license. For details, see [project/lib/opusfile/](project/lib).
48+
4049
This product bundles pixman 0.32.8, which is available under an
4150
"MIT" license. For details, see [project/lib/pixman/](project/lib).
4251

dependencies/howler.js

Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
self._preload = (typeof o.preload === 'boolean' || o.preload === 'metadata') ? o.preload : true;
639639
self._rate = o.rate || 1;
640640
self._sprite = o.sprite || {};
641-
self._src = (typeof o.src !== 'string') ? o.src : [o.src];
641+
self._src = (o.src instanceof Array) ? o.src : [o.src];
642642
self._volume = o.volume !== undefined ? o.volume : 1;
643643
self._xhr = {
644644
method: o.xhr && o.xhr.method ? o.xhr.method : 'GET',
@@ -706,6 +706,12 @@
706706
load: function() {
707707
var self = this;
708708
var url = null;
709+
var arraybuffer = null;
710+
var audiobuffer = null;
711+
712+
if (self._state === 'loaded' || self._state === 'loading') {
713+
return;
714+
}
709715

710716
// If no audio is available, quit immediately.
711717
if (Howler.noAudio) {
@@ -714,34 +720,45 @@
714720
}
715721

716722
// Make sure our source is in an array.
717-
if (typeof self._src === 'string') {
723+
if (!(self._src instanceof Array)) {
718724
self._src = [self._src];
719725
}
720726

721727
// Loop through the sources and pick the first one that is compatible.
722728
for (var i=0; i<self._src.length; i++) {
723-
var ext, str;
729+
var src = self._src[i];
730+
var ext;
731+
732+
var srcIsString = typeof src === 'string';
733+
if (!srcIsString) {
734+
if (ArrayBuffer.isView(src)) {
735+
arraybuffer = src.buffer;
736+
break;
737+
} else if (src instanceof ArrayBuffer) {
738+
arraybuffer = src;
739+
break;
740+
} else if (src instanceof AudioBuffer) {
741+
audiobuffer = src;
742+
break;
743+
}
744+
}
724745

725746
if (self._format && self._format[i]) {
726747
// If an extension was specified, use that instead.
727748
ext = self._format[i];
728-
} else {
729-
// Make sure the source is a string.
730-
str = self._src[i];
731-
if (typeof str !== 'string') {
732-
self._emit('loaderror', null, 'Non-string found in selected audio sources - ignoring.');
733-
continue;
734-
}
735-
749+
} else if (srcIsString) {
736750
// Extract the file extension from the URL or base64 data URI.
737-
ext = /^data:audio\/([^;,]+);/i.exec(str);
751+
ext = /^data:audio\/([^;,]+);/i.exec(src);
738752
if (!ext) {
739-
ext = /\.([^.]+)$/.exec(str.split('?', 1)[0]);
753+
ext = /\.([^.]+)$/.exec(src.split('?', 1)[0]);
740754
}
741755

742756
if (ext) {
743757
ext = ext[1].toLowerCase();
744758
}
759+
} else {
760+
self._emit('loaderror', null, 'Non-string found in selected audio sources - ignoring.');
761+
continue;
745762
}
746763

747764
// Log a warning if no extension was found.
@@ -756,29 +773,39 @@
756773
}
757774
}
758775

759-
if (!url) {
760-
self._emit('loaderror', null, 'No codec support for selected audio sources.');
761-
return;
776+
if (url) {
777+
self._src = url;
778+
} else {
779+
if (!self._webAudio) {
780+
self._emit('loaderror', null, 'AudioBuffer or ArrayBuffer is incompatible with html5 audio.');
781+
return;
782+
} else if (arraybuffer) {
783+
self._src = arraybuffer;
784+
} else if (audiobuffer) {
785+
self._src = audiobuffer;
786+
} else {
787+
self._emit('loaderror', null, 'No codec support for selected audio sources.');
788+
return;
789+
}
762790
}
763791

764-
self._src = url;
765792
self._state = 'loading';
766793

767794
// If the hosting page is HTTPS and the source isn't,
768795
// drop down to HTML5 Audio to avoid Mixed Content errors.
769-
if (window.location.protocol === 'https:' && url.slice(0, 5) === 'http:') {
796+
if (window.location.protocol === 'https:' && url && url.slice(0, 5) === 'http:') {
770797
self._html5 = true;
771798
self._webAudio = false;
772799
}
773800

774-
// Create a new sound object and add it to the pool.
775-
new Sound(self);
776-
777801
// Load and decode the audio data for playback.
778802
if (self._webAudio) {
779-
loadBuffer(self);
803+
loadBuffer(self);
780804
}
781805

806+
// Create a new sound object and add it to the pool.
807+
new Sound(self);
808+
782809
return self;
783810
},
784811

@@ -1285,7 +1312,9 @@
12851312

12861313
// Update the volume or return the current volume.
12871314
var sound;
1288-
if (typeof vol !== 'undefined' && vol >= 0 && vol <= 1) {
1315+
if (typeof vol !== 'undefined') {
1316+
vol = Math.max(vol, 0);
1317+
12891318
// If the sound hasn't loaded, add it to the load queue to change volume when capable.
12901319
if (self._state !== 'loaded'|| self._playLock) {
12911320
self._queue.push({
@@ -1508,6 +1537,26 @@
15081537
} else if (args.length === 2) {
15091538
loop = args[0];
15101539
id = parseInt(args[1], 10);
1540+
} else if (args.length === 3) {
1541+
id = parseInt(args[2], 10);
1542+
sound = self._soundById(id);
1543+
if (sound) {
1544+
sound._loop = true;
1545+
sound._start = parseFloat(args[0]) || 0;
1546+
sound._stop = parseFloat(args[1]) || self._duration;
1547+
if (self._webAudio && sound._node && sound._node.bufferSource) {
1548+
sound._node.bufferSource.loop = true;
1549+
sound._node.bufferSource.loopStart = sound._start;
1550+
sound._node.bufferSource.loopEnd = sound._stop;
1551+
1552+
// If playing, restart playback to ensure looping updates.
1553+
if (self.playing(id)) {
1554+
self.pause(id, true);
1555+
self.play(id, true);
1556+
}
1557+
}
1558+
}
1559+
return;
15111560
}
15121561

15131562
// If no id is passed, get all ID's to be looped.
@@ -1835,7 +1884,7 @@
18351884
// Delete this sound from the cache (if no other Howl is using it).
18361885
var remCache = true;
18371886
for (i=0; i<Howler._howls.length; i++) {
1838-
if (Howler._howls[i]._src === self._src || self._src.indexOf(Howler._howls[i]._src) >= 0) {
1887+
if (Howler._howls[i]._src === self._src || (typeof self._src === 'string' && self._src.indexOf(Howler._howls[i]._src) >= 0)) {
18391888
remCache = false;
18401889
break;
18411890
}
@@ -2188,7 +2237,7 @@
21882237

21892238
// Setup the buffer source for playback.
21902239
sound._node.bufferSource = Howler.ctx.createBufferSource();
2191-
sound._node.bufferSource.buffer = cache[self._src];
2240+
sound._node.bufferSource.buffer = self._buffer;
21922241

21932242
// Connect to the correct node.
21942243
if (sound._panner) {
@@ -2431,22 +2480,27 @@
24312480
* @param {Howl} self
24322481
*/
24332482
var loadBuffer = function(self) {
2434-
var url = self._src;
2435-
2436-
// Check if the buffer has already been cached and use it instead.
2437-
if (cache[url]) {
2438-
// Set the duration from the cache.
2439-
self._duration = cache[url].duration;
2483+
var src = self._src;
24402484

2441-
// Load the sound into this Howl.
2442-
loadSound(self);
2485+
// Check if the src is arraybuffer or audiobuffer.
2486+
// Disable caching if its not a url.
2487+
if (src instanceof ArrayBuffer) {
2488+
decodeAudioData(src, self);
2489+
return;
2490+
} else if (src instanceof AudioBuffer) {
2491+
loadSound(self, src);
2492+
return;
2493+
}
24432494

2495+
// Check if the buffer has already been cached and use it instead.
2496+
if (cache[src]) {
2497+
loadSound(self, cache[src]);
24442498
return;
24452499
}
24462500

2447-
if (/^data:[^;]+;base64,/.test(url)) {
2501+
if (/^data:[^;]+;base64,/.test(src)) {
24482502
// Decode the base64 data URI without XHR, since some browsers don't support it.
2449-
var data = atob(url.split(',')[1]);
2503+
var data = atob(src.split(',')[1]);
24502504
var dataView = new Uint8Array(data.length);
24512505
for (var i=0; i<data.length; ++i) {
24522506
dataView[i] = data.charCodeAt(i);
@@ -2456,7 +2510,7 @@
24562510
} else {
24572511
// Load the buffer from the URL.
24582512
var xhr = new XMLHttpRequest();
2459-
xhr.open(self._xhr.method, url, true);
2513+
xhr.open(self._xhr.method, src, true);
24602514
xhr.withCredentials = self._xhr.withCredentials;
24612515
xhr.responseType = 'arraybuffer';
24622516

@@ -2483,7 +2537,7 @@
24832537
self._html5 = true;
24842538
self._webAudio = false;
24852539
self._sounds = [];
2486-
delete cache[url];
2540+
//delete cache[src];
24872541
self.load();
24882542
}
24892543
};
@@ -2516,7 +2570,7 @@
25162570

25172571
// Load the sound on success.
25182572
var success = function(buffer) {
2519-
if (buffer && self._sounds.length > 0) {
2573+
if (buffer) {
25202574
cache[self._src] = buffer;
25212575
loadSound(self, buffer);
25222576
} else {
@@ -2539,7 +2593,8 @@
25392593
*/
25402594
var loadSound = function(self, buffer) {
25412595
// Set the duration.
2542-
if (buffer && !self._duration) {
2596+
if (buffer) {
2597+
self._buffer = buffer;
25432598
self._duration = buffer.duration;
25442599
}
25452600

include.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<log error="Lime ${lime} requires Haxe 4 to target HashLink (version ${haxe} found)" if="hl ${${haxe} < 4.0}" />
77

88
<set name="lime" />
9+
<define name="lime-funkin" />
910

1011
<define name="native" if="cpp || neko || nodejs || cs || java || hl" />
1112
<define name="howlerjs" if="html5" />
@@ -15,13 +16,15 @@
1516
<define name="lime-cffi" if="native" />
1617
<define name="lime-curl" unless="lime-console || lime-switch || emscripten || flash || html5" />
1718
<define name="lime-dom" if="html5" />
19+
<define name="lime-drlibs" if="native" />
1820
<define name="lime-harfbuzz" if="native" />
1921
<define name="lime-howlerjs" if="html5" />
2022
<define name="lime-html5" if="html5" />
2123
<define name="lime-native" if="native" />
2224
<define name="lime-openal" unless="lime-console || flash || html5" />
2325
<define name="lime-opengl" if="desktop" unless="html5" />
2426
<define name="lime-opengles" if="emscripten || mobile" />
27+
<define name="lime-opus" if="native" />
2528
<define name="lime-vorbis" if="native" />
2629
<define name="lime-webgl" if="html5" />
2730

0 commit comments

Comments
 (0)