webruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/webruby/rake/mruby.rake +1 -0
- data/modules/emscripten/AUTHORS +7 -0
- data/modules/emscripten/LICENSE +26 -0
- data/modules/emscripten/emcc +58 -20
- data/modules/emscripten/emlink.py +2 -265
- data/modules/emscripten/emscripten.py +38 -18
- data/modules/emscripten/scons-tools/emscripten.py +11 -6
- data/modules/emscripten/scons-tools/llvm.py +4 -3
- data/modules/emscripten/src/analyzer.js +32 -13
- data/modules/emscripten/src/embind/embind.js +13 -13
- data/modules/emscripten/src/embind/emval.js +8 -7
- data/modules/emscripten/src/intertyper.js +10 -0
- data/modules/emscripten/src/jsifier.js +28 -6
- data/modules/emscripten/src/library.js +2949 -1322
- data/modules/emscripten/src/library_browser.js +27 -23
- data/modules/emscripten/src/library_egl.js +7 -2
- data/modules/emscripten/src/library_gl.js +15 -2
- data/modules/emscripten/src/library_glut.js +1 -1
- data/modules/emscripten/src/library_jansson.js +1 -1
- data/modules/emscripten/src/library_openal.js +464 -132
- data/modules/emscripten/src/library_path.js +134 -0
- data/modules/emscripten/src/library_sdl.js +222 -50
- data/modules/emscripten/src/modules.js +22 -5
- data/modules/emscripten/src/parseTools.js +13 -2
- data/modules/emscripten/src/postamble.js +60 -34
- data/modules/emscripten/src/preamble.js +67 -18
- data/modules/emscripten/src/relooper/Relooper.cpp +1 -1
- data/modules/emscripten/src/runtime.js +12 -2
- data/modules/emscripten/src/settings.js +869 -826
- data/modules/emscripten/src/shell.js +63 -51
- data/modules/emscripten/src/utility.js +6 -0
- data/modules/emscripten/system/include/bsd/sys/mman.h +1 -1
- data/modules/emscripten/system/include/emscripten/bind.h +28 -28
- data/modules/emscripten/system/include/libc/math.h +8 -0
- data/modules/emscripten/system/include/libc/sys/signal.h +3 -1
- data/modules/emscripten/system/include/libc/sys/stat.h +2 -1
- data/modules/emscripten/system/include/libc/sys/types.h +4 -0
- data/modules/emscripten/system/include/libcxx/CREDITS.TXT +24 -0
- data/modules/emscripten/system/include/libcxx/__bit_reference +27 -8
- data/modules/emscripten/system/include/libcxx/__config +62 -15
- data/modules/emscripten/system/include/libcxx/__debug +5 -1
- data/modules/emscripten/system/include/libcxx/__functional_03 +24 -24
- data/modules/emscripten/system/include/libcxx/__functional_base +22 -4
- data/modules/emscripten/system/include/libcxx/__hash_table +566 -54
- data/modules/emscripten/system/include/libcxx/__locale +11 -3
- data/modules/emscripten/system/include/libcxx/__split_buffer +6 -6
- data/modules/emscripten/system/include/libcxx/__std_stream +58 -30
- data/modules/emscripten/system/include/libcxx/__tree +58 -51
- data/modules/emscripten/system/include/libcxx/__tuple +9 -9
- data/modules/emscripten/system/include/libcxx/algorithm +223 -13
- data/modules/emscripten/system/include/libcxx/array +18 -17
- data/modules/emscripten/system/include/libcxx/atomic +15 -5
- data/modules/emscripten/system/include/libcxx/cctype +2 -2
- data/modules/emscripten/system/include/libcxx/chrono +131 -36
- data/modules/emscripten/system/include/libcxx/cmath +41 -36
- data/modules/emscripten/system/include/libcxx/complex +49 -49
- data/modules/emscripten/system/include/libcxx/cstdio +2 -2
- data/modules/emscripten/system/include/libcxx/cstdlib +5 -5
- data/modules/emscripten/system/include/libcxx/cstring +2 -2
- data/modules/emscripten/system/include/libcxx/cwchar +22 -13
- data/modules/emscripten/system/include/libcxx/deque +27 -14
- data/modules/emscripten/system/include/libcxx/forward_list +36 -35
- data/modules/emscripten/system/include/libcxx/fstream +16 -0
- data/modules/emscripten/system/include/libcxx/functional +348 -23
- data/modules/emscripten/system/include/libcxx/future +66 -0
- data/modules/emscripten/system/include/libcxx/ios +27 -0
- data/modules/emscripten/system/include/libcxx/istream +2 -4
- data/modules/emscripten/system/include/libcxx/iterator +17 -9
- data/modules/emscripten/system/include/libcxx/limits +2 -2
- data/modules/emscripten/system/include/libcxx/list +165 -105
- data/modules/emscripten/system/include/libcxx/locale +154 -43
- data/modules/emscripten/system/include/libcxx/map +165 -224
- data/modules/emscripten/system/include/libcxx/memory +113 -54
- data/modules/emscripten/system/include/libcxx/random +2 -29
- data/modules/emscripten/system/include/libcxx/readme.txt +1 -1
- data/modules/emscripten/system/include/libcxx/regex +60 -15
- data/modules/emscripten/system/include/libcxx/sstream +124 -40
- data/modules/emscripten/system/include/libcxx/string +345 -182
- data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +3 -3
- data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +15 -2
- data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +3 -3
- data/modules/emscripten/system/include/libcxx/support/win32/support.h +10 -11
- data/modules/emscripten/system/include/libcxx/thread +2 -2
- data/modules/emscripten/system/include/libcxx/tuple +134 -65
- data/modules/emscripten/system/include/libcxx/type_traits +232 -24
- data/modules/emscripten/system/include/libcxx/unordered_map +314 -161
- data/modules/emscripten/system/include/libcxx/unordered_set +160 -2
- data/modules/emscripten/system/include/libcxx/utility +225 -40
- data/modules/emscripten/system/include/libcxx/vector +52 -57
- data/modules/emscripten/system/include/net/if.h +20 -1
- data/modules/emscripten/system/include/net/netinet/in.h +69 -5
- data/modules/emscripten/system/include/netdb.h +36 -0
- data/modules/emscripten/system/include/sys/ioctl.h +55 -3
- data/modules/emscripten/system/include/sys/select.h +2 -0
- data/modules/emscripten/system/include/sys/sendfile.h +16 -0
- data/modules/emscripten/system/include/sys/socket.h +181 -35
- data/modules/emscripten/system/lib/dlmalloc.c +10 -12
- data/modules/emscripten/system/lib/libc/musl/src/stdlib/ecvt.c +19 -0
- data/modules/emscripten/system/lib/libc/musl/src/stdlib/fcvt.c +25 -0
- data/modules/emscripten/system/lib/libc/musl/src/stdlib/gcvt.c +8 -0
- data/modules/emscripten/system/lib/libcextra.symbols +3 -0
- data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +24 -0
- data/modules/emscripten/system/lib/libcxx/debug.cpp +11 -9
- data/modules/emscripten/system/lib/libcxx/exception.cpp +9 -0
- data/modules/emscripten/system/lib/libcxx/hash.cpp +6 -0
- data/modules/emscripten/system/lib/libcxx/iostream.cpp +4 -4
- data/modules/emscripten/system/lib/libcxx/locale.cpp +91 -42
- data/modules/emscripten/system/lib/libcxx/readme.txt +1 -1
- data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +1 -1
- data/modules/emscripten/system/lib/libcxx/string.cpp +332 -491
- data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +4 -2
- data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +140 -41
- data/modules/emscripten/system/lib/libcxx/symbols +9 -256
- data/modules/emscripten/system/lib/libcxx/system_error.cpp +3 -0
- data/modules/emscripten/system/lib/libcxx/thread.cpp +16 -3
- data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +12 -2
- data/modules/emscripten/third_party/stb_image.c +4673 -0
- data/modules/emscripten/tools/asm_module.py +273 -0
- data/modules/emscripten/tools/exec_llvm.py +2 -2
- data/modules/emscripten/tools/file_packager.py +36 -16
- data/modules/emscripten/tools/find_bigfuncs.py +9 -9
- data/modules/emscripten/tools/js-optimizer.js +485 -131
- data/modules/emscripten/tools/js_optimizer.py +22 -15
- data/modules/emscripten/tools/merge_asm.py +26 -0
- data/modules/emscripten/tools/nativize_llvm.py +2 -2
- data/modules/emscripten/tools/settings_template_readonly.py +1 -1
- data/modules/emscripten/tools/shared.py +63 -20
- data/modules/emscripten/tools/split_asm.py +30 -0
- data/modules/emscripten/tools/test-js-optimizer-asm-outline1-output.js +686 -0
- data/modules/emscripten/tools/test-js-optimizer-asm-outline1.js +263 -0
- data/modules/emscripten/tools/test-js-optimizer-asm-outline2-output.js +747 -0
- data/modules/emscripten/tools/{test-js-optimizer-asm-outline.js → test-js-optimizer-asm-outline2.js} +1 -1
- data/modules/emscripten/tools/test-js-optimizer-asm-outline3-output.js +28 -0
- data/modules/emscripten/tools/test-js-optimizer-asm-outline3.js +30 -0
- data/modules/emscripten/tools/test-js-optimizer-asm-pre-output.js +4 -4
- data/modules/mruby/AUTHORS +1 -0
- data/modules/mruby/README.md +4 -2
- data/modules/mruby/build_config.rb +6 -6
- data/modules/mruby/doc/mrbgems/README.md +4 -4
- data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake +1 -1
- data/modules/mruby/examples/mrbgems/c_extension_example/mrbgem.rake +1 -1
- data/modules/mruby/examples/mrbgems/ruby_extension_example/mrbgem.rake +1 -1
- data/modules/mruby/include/mrbconf.h +3 -0
- data/modules/mruby/include/mruby/array.h +2 -2
- data/modules/mruby/include/mruby/class.h +4 -4
- data/modules/mruby/include/mruby/compile.h +1 -0
- data/modules/mruby/include/mruby/data.h +1 -1
- data/modules/mruby/include/mruby/hash.h +2 -2
- data/modules/mruby/include/mruby/irep.h +3 -2
- data/modules/mruby/include/mruby/proc.h +1 -1
- data/modules/mruby/include/mruby/range.h +1 -1
- data/modules/mruby/include/mruby/string.h +2 -2
- data/modules/mruby/include/mruby/value.h +43 -26
- data/modules/mruby/include/mruby.h +10 -2
- data/modules/mruby/minirake +2 -2
- data/modules/mruby/mrbgems/mruby-array-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +4 -1
- data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +32 -0
- data/modules/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +13 -5
- data/modules/mruby/mrbgems/mruby-enum-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-enum-ext/test/enum.rb +10 -11
- data/modules/mruby/mrbgems/mruby-eval/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-exit/mrbgem.rake +4 -0
- data/modules/mruby/mrbgems/mruby-exit/src/mruby-exit.c +24 -0
- data/modules/mruby/mrbgems/mruby-fiber/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +4 -2
- data/modules/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-hash-ext/test/hash.rb +5 -7
- data/modules/mruby/mrbgems/mruby-math/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-numeric-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +2 -2
- data/modules/mruby/mrbgems/mruby-object-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-object-ext/src/object.c +3 -3
- data/modules/mruby/mrbgems/mruby-object-ext/test/nil.rb +3 -3
- data/modules/mruby/mrbgems/mruby-object-ext/test/object.rb +1 -1
- data/modules/mruby/mrbgems/mruby-objectspace/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +36 -37
- data/modules/mruby/mrbgems/mruby-print/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-proc-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-proc-ext/test/proc.rb +8 -8
- data/modules/mruby/mrbgems/mruby-random/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-range-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-range-ext/test/range.rb +6 -6
- data/modules/mruby/mrbgems/mruby-sprintf/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-string-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-string-ext/test/string.rb +6 -6
- data/modules/mruby/mrbgems/mruby-struct/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-symbol-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +2 -2
- data/modules/mruby/mrbgems/mruby-time/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-time/src/time.c +2 -8
- data/modules/mruby/mrbgems/mruby-toplevel-ext/mrbgem.rake +1 -1
- data/modules/mruby/mrbgems/mruby-toplevel-ext/test/toplevel.rb +10 -10
- data/modules/mruby/mrblib/class.rb +15 -9
- data/modules/mruby/mrblib/string.rb +12 -0
- data/modules/mruby/src/array.c +4 -3
- data/modules/mruby/src/class.c +13 -8
- data/modules/mruby/src/codegen.c +9 -8
- data/modules/mruby/src/error.c +7 -5
- data/modules/mruby/src/error.h +1 -0
- data/modules/mruby/src/etc.c +1 -1
- data/modules/mruby/src/gc.c +163 -128
- data/modules/mruby/src/kernel.c +43 -15
- data/modules/mruby/src/numeric.c +9 -7
- data/modules/mruby/src/object.c +1 -1
- data/modules/mruby/src/parse.y +37 -19
- data/modules/mruby/src/range.c +10 -24
- data/modules/mruby/src/state.c +2 -6
- data/modules/mruby/src/string.c +0 -9
- data/modules/mruby/src/variable.c +2 -2
- data/modules/mruby/src/vm.c +12 -6
- data/modules/mruby/tasks/mrbgem_spec.rake +7 -0
- data/modules/mruby/tasks/mrbgems.rake +2 -1
- data/modules/mruby/tasks/mrbgems_test.rake +1 -1
- data/modules/mruby/tasks/mruby_build.rake +4 -3
- data/modules/mruby/tasks/mruby_build_commands.rake +6 -1
- data/modules/mruby/tasks/mruby_build_gem.rake +2 -2
- data/modules/mruby/tasks/toolchains/androideabi.rake +2 -0
- data/modules/mruby/test/assert.rb +2 -2
- data/modules/mruby/test/t/argumenterror.rb +3 -3
- data/modules/mruby/test/t/array.rb +55 -55
- data/modules/mruby/test/t/basicobject.rb +1 -1
- data/modules/mruby/test/t/bs_block.rb +12 -12
- data/modules/mruby/test/t/class.rb +21 -21
- data/modules/mruby/test/t/enumerable.rb +18 -18
- data/modules/mruby/test/t/exception.rb +20 -20
- data/modules/mruby/test/t/false.rb +3 -3
- data/modules/mruby/test/t/float.rb +40 -40
- data/modules/mruby/test/t/gc.rb +10 -10
- data/modules/mruby/test/t/hash.rb +41 -41
- data/modules/mruby/test/t/indexerror.rb +2 -2
- data/modules/mruby/test/t/integer.rb +41 -41
- data/modules/mruby/test/t/kernel.rb +33 -33
- data/modules/mruby/test/t/literals.rb +82 -82
- data/modules/mruby/test/t/localjumperror.rb +1 -1
- data/modules/mruby/test/t/module.rb +170 -31
- data/modules/mruby/test/t/nameerror.rb +5 -5
- data/modules/mruby/test/t/nil.rb +2 -2
- data/modules/mruby/test/t/nomethoderror.rb +1 -1
- data/modules/mruby/test/t/numeric.rb +5 -5
- data/modules/mruby/test/t/object.rb +2 -2
- data/modules/mruby/test/t/proc.rb +8 -8
- data/modules/mruby/test/t/range.rb +9 -9
- data/modules/mruby/test/t/rangeerror.rb +2 -2
- data/modules/mruby/test/t/runtimeerror.rb +1 -1
- data/modules/mruby/test/t/standarderror.rb +2 -2
- data/modules/mruby/test/t/string.rb +100 -100
- data/modules/mruby/test/t/symbol.rb +5 -5
- data/modules/mruby/test/t/syntax.rb +15 -6
- data/modules/mruby/test/t/true.rb +3 -3
- data/modules/mruby/test/t/typeerror.rb +2 -2
- data/modules/mruby/tools/mrbc/mrbc.c +10 -4
- data/modules/mruby/travis_config.rb +1 -0
- data/scripts/gen_gems_config.rb +5 -1
- metadata +19 -4
- data/modules/emscripten/tools/test-js-optimizer-asm-outline-output.js +0 -570
@@ -5,6 +5,8 @@ var LibraryOpenAL = {
|
|
5
5
|
$AL: {
|
6
6
|
contexts: [],
|
7
7
|
currentContext: null,
|
8
|
+
QUEUE_INTERVAL: 25,
|
9
|
+
QUEUE_LOOKAHEAD: 100
|
8
10
|
},
|
9
11
|
|
10
12
|
alcProcessContext: function(context) {},
|
@@ -39,6 +41,7 @@ var LibraryOpenAL = {
|
|
39
41
|
|
40
42
|
alcDestroyContext: function(context) {
|
41
43
|
// Stop playback, etc
|
44
|
+
clearInterval(context.interval);
|
42
45
|
},
|
43
46
|
|
44
47
|
alcCloseDevice: function(device) {
|
@@ -54,6 +57,7 @@ var LibraryOpenAL = {
|
|
54
57
|
}
|
55
58
|
},
|
56
59
|
|
60
|
+
alcCreateContext__deps: ['updateSources'],
|
57
61
|
alcCreateContext: function(device, attrList) {
|
58
62
|
if (device != 1) {
|
59
63
|
return 0;
|
@@ -76,18 +80,152 @@ var LibraryOpenAL = {
|
|
76
80
|
}
|
77
81
|
|
78
82
|
if (ctx) {
|
79
|
-
|
83
|
+
var context = {
|
84
|
+
ctx: ctx,
|
85
|
+
err: 0,
|
86
|
+
src: [],
|
87
|
+
buf: [],
|
88
|
+
interval: setInterval(function() { _updateSources(context); }, AL.QUEUE_INTERVAL)
|
89
|
+
};
|
90
|
+
AL.contexts.push(context);
|
80
91
|
return AL.contexts.length;
|
81
92
|
} else {
|
82
93
|
return 0;
|
83
94
|
}
|
84
95
|
},
|
85
96
|
|
97
|
+
updateSources__deps: ['updateSource'],
|
98
|
+
updateSources: function(context) {
|
99
|
+
for (var i = 0; i < context.src.length; i++) {
|
100
|
+
_updateSource(context.src[i]);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
|
104
|
+
updateSource__deps: ['setSourceState'],
|
105
|
+
updateSource: function(src) {
|
106
|
+
#if OPENAL_DEBUG
|
107
|
+
var idx = AL.currentContext.src.indexOf(src);
|
108
|
+
#endif
|
109
|
+
if (src.state !== 0x1012 /* AL_PLAYING */) {
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
var currentTime = AL.currentContext.ctx.currentTime;
|
114
|
+
var startTime = src.bufferPosition;
|
115
|
+
|
116
|
+
for (var i = src.buffersPlayed; i < src.queue.length; i++) {
|
117
|
+
var entry = src.queue[i];
|
118
|
+
|
119
|
+
var startOffset = startTime - currentTime;
|
120
|
+
var endTime = startTime + entry.buffer.duration;
|
121
|
+
|
122
|
+
// Clean up old buffers.
|
123
|
+
if (currentTime >= endTime) {
|
124
|
+
// Update our location in the queue.
|
125
|
+
src.bufferPosition = endTime;
|
126
|
+
src.buffersPlayed = i + 1;
|
127
|
+
|
128
|
+
// Stop / restart the source when we hit the end.
|
129
|
+
if (src.buffersPlayed >= src.queue.length) {
|
130
|
+
if (src.loop) {
|
131
|
+
_setSourceState(src, 0x1012 /* AL_PLAYING */);
|
132
|
+
} else {
|
133
|
+
_setSourceState(src, 0x1014 /* AL_STOPPED */);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
// Process all buffers that'll be played before the next tick.
|
138
|
+
else if (startOffset < (AL.QUEUE_LOOKAHEAD / 1000) && !entry.src) {
|
139
|
+
// If the start offset is negative, we need to offset the actual buffer.
|
140
|
+
var offset = Math.abs(Math.min(startOffset, 0));
|
141
|
+
|
142
|
+
entry.src = AL.currentContext.ctx.createBufferSource();
|
143
|
+
entry.src.buffer = entry.buffer;
|
144
|
+
entry.src.connect(src.gain);
|
145
|
+
entry.src.start(startTime, offset);
|
146
|
+
|
147
|
+
#if OPENAL_DEBUG
|
148
|
+
console.log('updateSource queuing buffer ' + i + ' for source ' + idx + ' at ' + startTime + ' (offset by ' + offset + ')');
|
149
|
+
#endif
|
150
|
+
}
|
151
|
+
|
152
|
+
startTime = endTime;
|
153
|
+
}
|
154
|
+
},
|
155
|
+
|
156
|
+
setSourceState__deps: ['updateSource', 'stopSourceQueue'],
|
157
|
+
setSourceState: function(src, state) {
|
158
|
+
#if OPENAL_DEBUG
|
159
|
+
var idx = AL.currentContext.src.indexOf(src);
|
160
|
+
#endif
|
161
|
+
if (state === 0x1012 /* AL_PLAYING */) {
|
162
|
+
if (src.state !== 0x1013 /* AL_PAUSED */) {
|
163
|
+
src.state = 0x1012 /* AL_PLAYING */;
|
164
|
+
// Reset our position.
|
165
|
+
src.bufferPosition = AL.currentContext.ctx.currentTime;
|
166
|
+
src.buffersPlayed = 0;
|
167
|
+
#if OPENAL_DEBUG
|
168
|
+
console.log('setSourceState resetting and playing source ' + idx);
|
169
|
+
#endif
|
170
|
+
} else {
|
171
|
+
src.state = 0x1012 /* AL_PLAYING */;
|
172
|
+
// Use the current offset from src.bufferPosition to resume at the correct point.
|
173
|
+
src.bufferPosition = AL.currentContext.ctx.currentTime - src.bufferPosition;
|
174
|
+
#if OPENAL_DEBUG
|
175
|
+
console.log('setSourceState resuming source ' + idx + ' at ' + src.bufferPosition.toFixed(4));
|
176
|
+
#endif
|
177
|
+
}
|
178
|
+
_stopSourceQueue(src);
|
179
|
+
_updateSource(src);
|
180
|
+
} else if (state === 0x1013 /* AL_PAUSED */) {
|
181
|
+
if (src.state === 0x1012 /* AL_PLAYING */) {
|
182
|
+
src.state = 0x1013 /* AL_PAUSED */;
|
183
|
+
// Store off the current offset to restore with on resume.
|
184
|
+
src.bufferPosition = AL.currentContext.ctx.currentTime - src.bufferPosition;
|
185
|
+
_stopSourceQueue(src);
|
186
|
+
#if OPENAL_DEBUG
|
187
|
+
console.log('setSourceState pausing source ' + idx + ' at ' + src.bufferPosition.toFixed(4));
|
188
|
+
#endif
|
189
|
+
}
|
190
|
+
} else if (state === 0x1014 /* AL_STOPPED */) {
|
191
|
+
if (src.state !== 0x1011 /* AL_INITIAL */) {
|
192
|
+
src.state = 0x1014 /* AL_STOPPED */;
|
193
|
+
src.buffersPlayed = src.queue.length;
|
194
|
+
_stopSourceQueue(src);
|
195
|
+
#if OPENAL_DEBUG
|
196
|
+
console.log('setSourceState stopping source ' + idx);
|
197
|
+
#endif
|
198
|
+
}
|
199
|
+
} else if (state == 0x1011 /* AL_INITIAL */) {
|
200
|
+
if (src.state !== 0x1011 /* AL_INITIAL */) {
|
201
|
+
src.state = 0x1011 /* AL_INITIAL */;
|
202
|
+
src.bufferPosition = 0;
|
203
|
+
src.buffersPlayed = 0;
|
204
|
+
#if OPENAL_DEBUG
|
205
|
+
console.log('setSourceState initializing source ' + idx);
|
206
|
+
#endif
|
207
|
+
}
|
208
|
+
}
|
209
|
+
},
|
210
|
+
|
211
|
+
stopSourceQueue: function(src) {
|
212
|
+
for (var i = 0; i < src.queue.length; i++) {
|
213
|
+
var entry = src.queue[i];
|
214
|
+
if (entry.src) {
|
215
|
+
entry.src.stop(0);
|
216
|
+
entry.src = null;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
},
|
220
|
+
|
86
221
|
alGetError: function() {
|
87
222
|
if (!AL.currentContext) {
|
88
223
|
return 0xA004 /* AL_INVALID_OPERATION */;
|
89
224
|
} else {
|
90
|
-
|
225
|
+
// Reset error on get.
|
226
|
+
var err = AL.currentContext.err;
|
227
|
+
AL.currentContext.err = 0 /* AL_NO_ERROR */;
|
228
|
+
return err;
|
91
229
|
}
|
92
230
|
},
|
93
231
|
|
@@ -97,12 +235,12 @@ var LibraryOpenAL = {
|
|
97
235
|
return _alGetError();
|
98
236
|
},
|
99
237
|
|
100
|
-
alDeleteSources: function(count, sources)
|
101
|
-
{
|
238
|
+
alDeleteSources: function(count, sources) {
|
102
239
|
if (!AL.currentContext) {
|
103
240
|
#if OPENAL_DEBUG
|
104
241
|
console.error("alDeleteSources called without a valid context");
|
105
242
|
#endif
|
243
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
106
244
|
return;
|
107
245
|
}
|
108
246
|
for (var i = 0; i < count; ++i) {
|
@@ -116,57 +254,126 @@ var LibraryOpenAL = {
|
|
116
254
|
#if OPENAL_DEBUG
|
117
255
|
console.error("alGenSources called without a valid context");
|
118
256
|
#endif
|
257
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
119
258
|
return;
|
120
259
|
}
|
121
260
|
for (var i = 0; i < count; ++i) {
|
122
261
|
var gain = AL.currentContext.ctx.createGain();
|
123
|
-
|
124
|
-
panner.panningModel = "equalpower";
|
125
|
-
panner.distanceModel = "linear";
|
126
|
-
panner.rolloffFactor = 0.3;
|
127
|
-
gain.connect(panner);
|
128
|
-
panner.connect(AL.currentContext.ctx.destination);
|
262
|
+
gain.connect(AL.currentContext.ctx.destination);
|
129
263
|
AL.currentContext.src.push({
|
264
|
+
state: 0x1011 /* AL_INITIAL */,
|
265
|
+
queue: [],
|
130
266
|
loop: false,
|
131
|
-
|
267
|
+
get refDistance() {
|
268
|
+
return this._refDistance || 1;
|
269
|
+
},
|
270
|
+
set refDistance(val) {
|
271
|
+
this._refDistance = val;
|
272
|
+
if (this.panner) this.panner.refDistance = val;
|
273
|
+
},
|
274
|
+
get maxDistance() {
|
275
|
+
return this._maxDistance || 10000;
|
276
|
+
},
|
277
|
+
set maxDistance(val) {
|
278
|
+
this._maxDistance = val;
|
279
|
+
if (this.panner) this.panner.maxDistance = val;
|
280
|
+
},
|
281
|
+
get rolloffFactor() {
|
282
|
+
return this._rolloffFactor || 1;
|
283
|
+
},
|
284
|
+
set rolloffFactor(val) {
|
285
|
+
this._rolloffFactor = val;
|
286
|
+
if (this.panner) this.panner.rolloffFactor = val;
|
287
|
+
},
|
288
|
+
get position() {
|
289
|
+
return this._position || [0, 0, 0];
|
290
|
+
},
|
291
|
+
set position(val) {
|
292
|
+
this._position = val;
|
293
|
+
if (this.panner) this.panner.setPosition(val[0], val[1], val[2]);
|
294
|
+
},
|
295
|
+
get velocity() {
|
296
|
+
return this._velocity || [0, 0, 0];
|
297
|
+
},
|
298
|
+
set velocity(val) {
|
299
|
+
this._velocity = val;
|
300
|
+
if (this.panner) this.panner.setVelocity(val[0], val[1], val[2]);
|
301
|
+
},
|
132
302
|
gain: gain,
|
133
|
-
panner:
|
134
|
-
|
135
|
-
|
136
|
-
pausedTime: 0
|
303
|
+
panner: null,
|
304
|
+
buffersPlayed: 0,
|
305
|
+
bufferPosition: 0
|
137
306
|
});
|
138
307
|
{{{ makeSetValue('sources', 'i*4', 'AL.currentContext.src.length', 'i32') }}};
|
139
308
|
}
|
140
309
|
},
|
141
310
|
|
311
|
+
alSourcei__deps: ['updateSource'],
|
142
312
|
alSourcei: function(source, param, value) {
|
143
313
|
if (!AL.currentContext) {
|
144
314
|
#if OPENAL_DEBUG
|
145
315
|
console.error("alSourcei called without a valid context");
|
146
316
|
#endif
|
317
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
147
318
|
return;
|
148
319
|
}
|
149
|
-
|
320
|
+
var src = AL.currentContext.src[source - 1];
|
321
|
+
if (!src) {
|
150
322
|
#if OPENAL_DEBUG
|
151
323
|
console.error("alSourcei called with an invalid source");
|
152
324
|
#endif
|
325
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
153
326
|
return;
|
154
327
|
}
|
155
328
|
switch (param) {
|
156
329
|
case 0x1007 /* AL_LOOPING */:
|
157
|
-
|
330
|
+
src.loop = (value === 1 /* AL_TRUE */);
|
158
331
|
break;
|
159
332
|
case 0x1009 /* AL_BUFFER */:
|
333
|
+
var buffer = AL.currentContext.buf[value - 1];
|
160
334
|
if (value == 0) {
|
161
|
-
|
335
|
+
src.queue = [];
|
336
|
+
} else {
|
337
|
+
src.queue = [{ buffer: buffer }];
|
338
|
+
}
|
339
|
+
_updateSource(src);
|
340
|
+
break;
|
341
|
+
case 0x202 /* AL_SOURCE_RELATIVE */:
|
342
|
+
if (value === 1 /* AL_TRUE */) {
|
343
|
+
if (src.panner) {
|
344
|
+
src.panner = null;
|
345
|
+
|
346
|
+
// Disconnect from the panner.
|
347
|
+
src.gain.disconnect();
|
348
|
+
|
349
|
+
src.gain.connect(AL.currentContext.ctx.destination);
|
350
|
+
}
|
351
|
+
} else if (value === 0 /* AL_FALSE */) {
|
352
|
+
if (!src.panner) {
|
353
|
+
var panner = src.panner = AL.currentContext.ctx.createPanner();
|
354
|
+
panner.panningModel = "equalpower";
|
355
|
+
panner.distanceModel = "linear";
|
356
|
+
panner.refDistance = src.refDistance;
|
357
|
+
panner.maxDistance = src.maxDistance;
|
358
|
+
panner.rolloffFactor = src.rolloffFactor;
|
359
|
+
panner.setPosition(src.position[0], src.position[1], src.position[2]);
|
360
|
+
panner.setVelocity(src.velocity[0], src.velocity[1], src.velocity[2]);
|
361
|
+
panner.connect(AL.currentContext.ctx.destination);
|
362
|
+
|
363
|
+
// Disconnect from the default source.
|
364
|
+
src.gain.disconnect();
|
365
|
+
|
366
|
+
src.gain.connect(panner);
|
367
|
+
}
|
162
368
|
} else {
|
163
|
-
AL.currentContext.
|
369
|
+
AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */;
|
164
370
|
}
|
165
371
|
break;
|
166
372
|
default:
|
167
373
|
#if OPENAL_DEBUG
|
168
374
|
console.log("alSourcei with param " + param + " not implemented yet");
|
169
375
|
#endif
|
376
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
170
377
|
break;
|
171
378
|
}
|
172
379
|
},
|
@@ -176,130 +383,168 @@ var LibraryOpenAL = {
|
|
176
383
|
#if OPENAL_DEBUG
|
177
384
|
console.error("alSourcef called without a valid context");
|
178
385
|
#endif
|
386
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
179
387
|
return;
|
180
388
|
}
|
181
|
-
|
389
|
+
var src = AL.currentContext.src[source - 1];
|
390
|
+
if (!src) {
|
182
391
|
#if OPENAL_DEBUG
|
183
392
|
console.error("alSourcef called with an invalid source");
|
184
393
|
#endif
|
394
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
185
395
|
return;
|
186
396
|
}
|
187
397
|
switch (param) {
|
188
|
-
case 0x100A /* AL_GAIN */:
|
189
|
-
if (AL.currentContext.src[source - 1]) {
|
190
|
-
AL.currentContext.src[source - 1].gain.gain.value = value;
|
191
|
-
}
|
192
|
-
break;
|
193
398
|
case 0x1003 /* AL_PITCH */:
|
194
399
|
#if OPENAL_DEBUG
|
195
|
-
console.log("alSourcef was called with AL_PITCH
|
400
|
+
console.log("alSourcef was called with 0x1003 /* AL_PITCH */, but Web Audio does not support static pitch changes");
|
196
401
|
#endif
|
197
402
|
break;
|
403
|
+
case 0x100A /* AL_GAIN */:
|
404
|
+
src.gain.gain.value = value;
|
405
|
+
break;
|
406
|
+
// case 0x100D /* AL_MIN_GAIN */:
|
407
|
+
// break;
|
408
|
+
// case 0x100E /* AL_MAX_GAIN */:
|
409
|
+
// break;
|
410
|
+
case 0x1023 /* AL_MAX_DISTANCE */:
|
411
|
+
src.maxDistance = value;
|
412
|
+
break;
|
413
|
+
case 0x1021 /* AL_ROLLOFF_FACTOR */:
|
414
|
+
src.rolloffFactor = value;
|
415
|
+
break;
|
416
|
+
// case 0x1022 /* AL_CONE_OUTER_GAIN */:
|
417
|
+
// break;
|
418
|
+
// case 0x1001 /* AL_CONE_INNER_ANGLE */:
|
419
|
+
// break;
|
420
|
+
// case 0x1002 /* AL_CONE_OUTER_ANGLE */:
|
421
|
+
// break;
|
422
|
+
case 0x1020 /* AL_REFERENCE_DISTANCE */:
|
423
|
+
src.refDistance = value;
|
424
|
+
break;
|
198
425
|
default:
|
199
426
|
#if OPENAL_DEBUG
|
200
427
|
console.log("alSourcef with param " + param + " not implemented yet");
|
201
428
|
#endif
|
429
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
202
430
|
break;
|
203
431
|
}
|
204
432
|
},
|
205
433
|
|
206
|
-
|
434
|
+
alSource3f: function(source, param, v1, v2, v3) {
|
207
435
|
if (!AL.currentContext) {
|
208
436
|
#if OPENAL_DEBUG
|
209
|
-
console.error("
|
437
|
+
console.error("alSource3f called without a valid context");
|
210
438
|
#endif
|
439
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
211
440
|
return;
|
212
441
|
}
|
213
|
-
|
442
|
+
var src = AL.currentContext.src[source - 1];
|
443
|
+
if (!src) {
|
214
444
|
#if OPENAL_DEBUG
|
215
|
-
console.error("
|
445
|
+
console.error("alSource3f called with an invalid source");
|
216
446
|
#endif
|
447
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
217
448
|
return;
|
218
449
|
}
|
219
450
|
switch (param) {
|
220
451
|
case 0x1004 /* AL_POSITION */:
|
221
|
-
|
222
|
-
{{{ makeGetValue('value', '0', 'float') }}},
|
223
|
-
{{{ makeGetValue('value', '4', 'float') }}},
|
224
|
-
{{{ makeGetValue('value', '8', 'float') }}}
|
225
|
-
);
|
452
|
+
src.position = [v1, v2, v3];
|
226
453
|
break;
|
227
454
|
case 0x1006 /* AL_VELOCITY */:
|
228
|
-
|
229
|
-
{{{ makeGetValue('value', '0', 'float') }}},
|
230
|
-
{{{ makeGetValue('value', '4', 'float') }}},
|
231
|
-
{{{ makeGetValue('value', '8', 'float') }}}
|
232
|
-
);
|
455
|
+
src.velocity = [v1, v2, v3];
|
233
456
|
break;
|
234
457
|
default:
|
235
458
|
#if OPENAL_DEBUG
|
236
|
-
console.log("
|
459
|
+
console.log("alSource3f with param " + param + " not implemented yet");
|
237
460
|
#endif
|
461
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
238
462
|
break;
|
239
463
|
}
|
240
464
|
},
|
241
465
|
|
466
|
+
alSourcefv__deps: ['alSource3f'],
|
467
|
+
alSourcefv: function(source, param, value) {
|
468
|
+
_alSource3f(source, param,
|
469
|
+
{{{ makeGetValue('value', '0', 'float') }}},
|
470
|
+
{{{ makeGetValue('value', '4', 'float') }}},
|
471
|
+
{{{ makeGetValue('value', '8', 'float') }}});
|
472
|
+
},
|
473
|
+
|
474
|
+
alSourceQueueBuffers__deps: ["updateSource"],
|
242
475
|
alSourceQueueBuffers: function(source, count, buffers) {
|
243
476
|
if (!AL.currentContext) {
|
244
477
|
#if OPENAL_DEBUG
|
245
478
|
console.error("alSourceQueueBuffers called without a valid context");
|
246
479
|
#endif
|
480
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
247
481
|
return;
|
248
482
|
}
|
249
|
-
|
483
|
+
var src = AL.currentContext.src[source - 1];
|
484
|
+
if (!src) {
|
250
485
|
#if OPENAL_DEBUG
|
251
486
|
console.error("alSourceQueueBuffers called with an invalid source");
|
252
487
|
#endif
|
253
|
-
|
254
|
-
}
|
255
|
-
if (count != 1) {
|
256
|
-
#if OPENAL_DEBUG
|
257
|
-
console.error("Queuing multiple buffers using alSourceQueueBuffers is not supported yet");
|
258
|
-
#endif
|
488
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
259
489
|
return;
|
260
490
|
}
|
261
491
|
for (var i = 0; i < count; ++i) {
|
262
|
-
var
|
263
|
-
if (
|
492
|
+
var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
|
493
|
+
if (bufferIdx > AL.currentContext.buf.length) {
|
264
494
|
#if OPENAL_DEBUG
|
265
495
|
console.error("alSourceQueueBuffers called with an invalid buffer");
|
266
496
|
#endif
|
497
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
267
498
|
return;
|
268
499
|
}
|
269
|
-
AL.currentContext.src[source - 1].buffer = AL.currentContext.buf[buffer - 1].buf;
|
270
500
|
}
|
501
|
+
|
502
|
+
for (var i = 0; i < count; ++i) {
|
503
|
+
var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
|
504
|
+
var buffer = AL.currentContext.buf[bufferIdx - 1];
|
505
|
+
src.queue.push({ buffer: buffer, src: null });
|
506
|
+
}
|
507
|
+
|
508
|
+
_updateSource(src);
|
271
509
|
},
|
272
510
|
|
273
|
-
|
274
|
-
{
|
511
|
+
alSourceUnqueueBuffers__deps: ["updateSource"],
|
512
|
+
alSourceUnqueueBuffers: function(source, count, buffers) {
|
275
513
|
if (!AL.currentContext) {
|
276
514
|
#if OPENAL_DEBUG
|
277
515
|
console.error("alSourceUnqueueBuffers called without a valid context");
|
278
516
|
#endif
|
517
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
279
518
|
return;
|
280
519
|
}
|
281
|
-
|
520
|
+
var src = AL.currentContext.src[source - 1];
|
521
|
+
if (!src) {
|
282
522
|
#if OPENAL_DEBUG
|
283
523
|
console.error("alSourceUnqueueBuffers called with an invalid source");
|
284
524
|
#endif
|
525
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
285
526
|
return;
|
286
527
|
}
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
#endif
|
528
|
+
|
529
|
+
if (count > src.buffersPlayed) {
|
530
|
+
AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */;
|
291
531
|
return;
|
292
532
|
}
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
533
|
+
|
534
|
+
for (var i = 0; i < count; i++) {
|
535
|
+
var entry = src.queue.shift();
|
536
|
+
// Write the buffers index out to the return list.
|
537
|
+
for (var j = 0; j < AL.currentContext.buf.length; j++) {
|
538
|
+
var b = AL.currentContext.buf[j];
|
539
|
+
if (b && b == entry.buffer) {
|
297
540
|
{{{ makeSetValue('buffers', 'i*4', 'j+1', 'i32') }}};
|
298
|
-
AL.currentContext.src[source - 1].buffer = null;
|
299
541
|
break;
|
300
542
|
}
|
301
543
|
}
|
544
|
+
src.buffersPlayed--;
|
302
545
|
}
|
546
|
+
|
547
|
+
_updateSource(src);
|
303
548
|
},
|
304
549
|
|
305
550
|
alDeleteBuffers: function(count, buffers)
|
@@ -308,21 +553,43 @@ var LibraryOpenAL = {
|
|
308
553
|
#if OPENAL_DEBUG
|
309
554
|
console.error("alDeleteBuffers called without a valid context");
|
310
555
|
#endif
|
556
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
557
|
+
return;
|
558
|
+
}
|
559
|
+
if (count > AL.currentContext.buf.length) {
|
560
|
+
AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */;
|
311
561
|
return;
|
312
562
|
}
|
563
|
+
|
313
564
|
for (var i = 0; i < count; ++i) {
|
314
565
|
var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1;
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
566
|
+
|
567
|
+
// Make sure the buffer index is valid.
|
568
|
+
if (bufferIdx >= AL.currentContext.buf.length || !AL.currentContext.buf[bufferIdx]) {
|
569
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
570
|
+
return;
|
571
|
+
}
|
572
|
+
|
573
|
+
// Make sure the buffer is no longer in use.
|
574
|
+
var buffer = AL.currentContext.buf[bufferIdx];
|
575
|
+
for (var j = 0; j < AL.currentContext.src.length; ++j) {
|
576
|
+
var src = AL.currentContext.src[j];
|
577
|
+
if (!src) {
|
578
|
+
continue;
|
579
|
+
}
|
580
|
+
for (var k = 0; k < src.queue.length; k++) {
|
581
|
+
if (buffer === src.queue[k].buffer) {
|
582
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
320
583
|
return;
|
321
584
|
}
|
322
585
|
}
|
323
|
-
delete AL.currentContext.buf[bufferIdx];
|
324
586
|
}
|
325
587
|
}
|
588
|
+
|
589
|
+
for (var i = 0; i < count; ++i) {
|
590
|
+
var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1;
|
591
|
+
delete AL.currentContext.buf[bufferIdx];
|
592
|
+
}
|
326
593
|
},
|
327
594
|
|
328
595
|
alGenBuffers: function(count, buffers) {
|
@@ -330,10 +597,11 @@ var LibraryOpenAL = {
|
|
330
597
|
#if OPENAL_DEBUG
|
331
598
|
console.error("alGenBuffers called without a valid context");
|
332
599
|
#endif
|
600
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
333
601
|
return;
|
334
602
|
}
|
335
603
|
for (var i = 0; i < count; ++i) {
|
336
|
-
AL.currentContext.buf.push(
|
604
|
+
AL.currentContext.buf.push(null);
|
337
605
|
{{{ makeSetValue('buffers', 'i*4', 'AL.currentContext.buf.length', 'i32') }}};
|
338
606
|
}
|
339
607
|
},
|
@@ -343,6 +611,7 @@ var LibraryOpenAL = {
|
|
343
611
|
#if OPENAL_DEBUG
|
344
612
|
console.error("alBufferData called without a valid context");
|
345
613
|
#endif
|
614
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
346
615
|
return;
|
347
616
|
}
|
348
617
|
if (buffer > AL.currentContext.buf.length) {
|
@@ -375,16 +644,21 @@ var LibraryOpenAL = {
|
|
375
644
|
#endif
|
376
645
|
return;
|
377
646
|
}
|
378
|
-
|
647
|
+
try {
|
648
|
+
AL.currentContext.buf[buffer - 1] = AL.currentContext.ctx.createBuffer(channels, size / (bytes * channels), freq);
|
649
|
+
} catch (e) {
|
650
|
+
AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */;
|
651
|
+
return;
|
652
|
+
}
|
379
653
|
var buf = new Array(channels);
|
380
654
|
for (var i = 0; i < channels; ++i) {
|
381
|
-
buf[i] = AL.currentContext.buf[buffer - 1].
|
655
|
+
buf[i] = AL.currentContext.buf[buffer - 1].getChannelData(i);
|
382
656
|
}
|
383
657
|
for (var i = 0; i < size / (bytes * channels); ++i) {
|
384
658
|
for (var j = 0; j < channels; ++j) {
|
385
659
|
switch (bytes) {
|
386
660
|
case 1:
|
387
|
-
var val = {{{ makeGetValue('data', 'i*channels+j', 'i8') }}};
|
661
|
+
var val = {{{ makeGetValue('data', 'i*channels+j', 'i8') }}} & 0xff; // unsigned
|
388
662
|
buf[j][i] = -1.0 + val * (2/256);
|
389
663
|
break;
|
390
664
|
case 2:
|
@@ -396,110 +670,105 @@ var LibraryOpenAL = {
|
|
396
670
|
}
|
397
671
|
},
|
398
672
|
|
399
|
-
alSourcePlay__deps: [
|
673
|
+
alSourcePlay__deps: ['setSourceState'],
|
400
674
|
alSourcePlay: function(source) {
|
401
675
|
if (!AL.currentContext) {
|
402
676
|
#if OPENAL_DEBUG
|
403
677
|
console.error("alSourcePlay called without a valid context");
|
404
678
|
#endif
|
679
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
405
680
|
return;
|
406
681
|
}
|
407
|
-
|
682
|
+
var src = AL.currentContext.src[source - 1];
|
683
|
+
if (!src) {
|
408
684
|
#if OPENAL_DEBUG
|
409
685
|
console.error("alSourcePlay called with an invalid source");
|
410
686
|
#endif
|
687
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
411
688
|
return;
|
412
689
|
}
|
413
|
-
|
414
|
-
if ("src" in AL.currentContext.src[source - 1] &&
|
415
|
-
AL.currentContext.src[source - 1]["src"].buffer ==
|
416
|
-
AL.currentContext.src[source - 1].buffer) {
|
417
|
-
if (AL.currentContext.src[source - 1].paused) {
|
418
|
-
// So now we have to resume playback, remember the offset here.
|
419
|
-
offset = AL.currentContext.src[source - 1].pausedTime -
|
420
|
-
AL.currentContext.src[source - 1].playTime;
|
421
|
-
} else {
|
422
|
-
// If the source is already playing, we need to resume from beginning.
|
423
|
-
// We do that by stopping the current source and replaying it.
|
424
|
-
_alSourceStop(source);
|
425
|
-
}
|
426
|
-
}
|
427
|
-
var src = AL.currentContext.ctx.createBufferSource();
|
428
|
-
src.loop = AL.currentContext.src[source - 1].loop;
|
429
|
-
src.buffer = AL.currentContext.src[source - 1].buffer;
|
430
|
-
src.connect(AL.currentContext.src[source - 1].gain);
|
431
|
-
src.start(0, offset);
|
432
|
-
AL.currentContext.src[source - 1].playTime = AL.currentContext.ctx.currentTime;
|
433
|
-
AL.currentContext.src[source - 1].paused = false;
|
434
|
-
AL.currentContext.src[source - 1]['src'] = src;
|
690
|
+
_setSourceState(src, 0x1012 /* AL_PLAYING */);
|
435
691
|
},
|
436
692
|
|
693
|
+
alSourceStop__deps: ['setSourceState'],
|
437
694
|
alSourceStop: function(source) {
|
438
695
|
if (!AL.currentContext) {
|
439
696
|
#if OPENAL_DEBUG
|
440
697
|
console.error("alSourceStop called without a valid context");
|
441
698
|
#endif
|
699
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
442
700
|
return;
|
443
701
|
}
|
444
|
-
|
702
|
+
var src = AL.currentContext.src[source - 1];
|
703
|
+
if (!src) {
|
445
704
|
#if OPENAL_DEBUG
|
446
705
|
console.error("alSourceStop called with an invalid source");
|
447
706
|
#endif
|
707
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
448
708
|
return;
|
449
709
|
}
|
450
|
-
|
451
|
-
AL.currentContext.src[source - 1]["src"].stop(0);
|
452
|
-
delete AL.currentContext.src[source - 1]["src"];
|
453
|
-
}
|
710
|
+
_setSourceState(src, 0x1014 /* AL_STOPPED */);
|
454
711
|
},
|
455
712
|
|
713
|
+
alSourcePause__deps: ['setSourceState'],
|
456
714
|
alSourcePause: function(source) {
|
457
715
|
if (!AL.currentContext) {
|
458
716
|
#if OPENAL_DEBUG
|
459
717
|
console.error("alSourcePause called without a valid context");
|
460
718
|
#endif
|
719
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
461
720
|
return;
|
462
721
|
}
|
463
|
-
|
722
|
+
var src = AL.currentContext.src[source - 1];
|
723
|
+
if (!src) {
|
464
724
|
#if OPENAL_DEBUG
|
465
725
|
console.error("alSourcePause called with an invalid source");
|
466
726
|
#endif
|
727
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
467
728
|
return;
|
468
729
|
}
|
469
|
-
|
470
|
-
!AL.currentContext.src[source - 1].paused) {
|
471
|
-
AL.currentContext.src[source - 1].paused = true;
|
472
|
-
AL.currentContext.src[source - 1].pausedTime = AL.currentContext.ctx.currentTime;
|
473
|
-
AL.currentContext.src[source - 1]["src"].stop(0);
|
474
|
-
delete AL.currentContext.src[source - 1].src;
|
475
|
-
}
|
730
|
+
_setSourceState(src, 0x1013 /* AL_PAUSED */);
|
476
731
|
},
|
477
732
|
|
733
|
+
alGetSourcei__deps: ['updateSource'],
|
478
734
|
alGetSourcei: function(source, param, value) {
|
479
735
|
if (!AL.currentContext) {
|
480
736
|
#if OPENAL_DEBUG
|
481
737
|
console.error("alGetSourcei called without a valid context");
|
482
738
|
#endif
|
739
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
483
740
|
return;
|
484
741
|
}
|
485
|
-
|
742
|
+
var src = AL.currentContext.src[source - 1];
|
743
|
+
if (!src) {
|
486
744
|
#if OPENAL_DEBUG
|
487
745
|
console.error("alGetSourcei called with an invalid source");
|
488
746
|
#endif
|
747
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
489
748
|
return;
|
490
749
|
}
|
750
|
+
|
751
|
+
// Being that we have no way to receive end events from buffer nodes,
|
752
|
+
// we currently proccess and update a source's buffer queue every
|
753
|
+
// ~QUEUE_INTERVAL milliseconds. However, this interval is not precise,
|
754
|
+
// so we also forcefully update the source when alGetSourcei is queried
|
755
|
+
// to aid in the common scenario of application calling alGetSourcei(AL_BUFFERS_PROCESSED)
|
756
|
+
// to recycle buffers.
|
757
|
+
_updateSource(src);
|
758
|
+
|
491
759
|
switch (param) {
|
492
760
|
case 0x202 /* AL_SOURCE_RELATIVE */:
|
493
|
-
|
494
|
-
{{{ makeSetValue('value', '0', '1', 'i32') }}};
|
761
|
+
{{{ makeSetValue('value', '0', 'src.panner ? 1 : 0', 'i32') }}};
|
495
762
|
break;
|
496
763
|
case 0x1009 /* AL_BUFFER */:
|
497
|
-
if (
|
764
|
+
if (!src.queue.length) {
|
498
765
|
{{{ makeSetValue('value', '0', '0', 'i32') }}};
|
499
766
|
} else {
|
500
|
-
|
767
|
+
// Find the first unprocessed buffer.
|
768
|
+
var buffer = src.queue[src.buffersPlayed].buffer;
|
769
|
+
// Return its index.
|
501
770
|
for (var i = 0; i < AL.currentContext.buf.length; ++i) {
|
502
|
-
if (
|
771
|
+
if (buffer == AL.currentContext.buf[i]) {
|
503
772
|
{{{ makeSetValue('value', '0', 'i+1', 'i32') }}};
|
504
773
|
return;
|
505
774
|
}
|
@@ -508,32 +777,79 @@ var LibraryOpenAL = {
|
|
508
777
|
}
|
509
778
|
break;
|
510
779
|
case 0x1010 /* AL_SOURCE_STATE */:
|
511
|
-
|
512
|
-
{{{ makeSetValue('value', '0', '0x1012', 'i32') }}} /* AL_PLAYING */;
|
513
|
-
} else if (AL.currentContext.src[source - 1].paused) {
|
514
|
-
{{{ makeSetValue('value', '0', '0x1013', 'i32') }}} /* AL_PAUSED */;
|
515
|
-
} else if (AL.currentContext.src[source - 1].playTime == -1) {
|
516
|
-
{{{ makeSetValue('value', '0', '0x1011', 'i32') }}} /* AL_INITIAL */;
|
517
|
-
} else {
|
518
|
-
{{{ makeSetValue('value', '0', '0x1014', 'i32') }}} /* AL_STOPPED */;
|
519
|
-
}
|
780
|
+
{{{ makeSetValue('value', '0', 'src.state', 'i32') }}};
|
520
781
|
break;
|
521
782
|
case 0x1015 /* AL_BUFFERS_QUEUED */:
|
522
|
-
|
523
|
-
|
524
|
-
|
783
|
+
{{{ makeSetValue('value', '0', 'src.queue.length', 'i32') }}}
|
784
|
+
break;
|
785
|
+
case 0x1016 /* AL_BUFFERS_PROCESSED */:
|
786
|
+
if (src.loop) {
|
525
787
|
{{{ makeSetValue('value', '0', '0', 'i32') }}}
|
788
|
+
} else {
|
789
|
+
{{{ makeSetValue('value', '0', 'src.buffersPlayed', 'i32') }}}
|
526
790
|
}
|
527
791
|
break;
|
528
|
-
|
529
|
-
|
530
|
-
|
792
|
+
default:
|
793
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
794
|
+
break;
|
795
|
+
}
|
796
|
+
},
|
797
|
+
|
798
|
+
alGetSourcef: function(source, param, value) {
|
799
|
+
if (!AL.currentContext) {
|
800
|
+
#if OPENAL_DEBUG
|
801
|
+
console.error("alGetSourcef called without a valid context");
|
802
|
+
#endif
|
803
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
804
|
+
return;
|
805
|
+
}
|
806
|
+
var src = AL.currentContext.src[source - 1];
|
807
|
+
if (!src) {
|
808
|
+
#if OPENAL_DEBUG
|
809
|
+
console.error("alGetSourcef called with an invalid source");
|
810
|
+
#endif
|
811
|
+
AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */;
|
812
|
+
return;
|
813
|
+
}
|
814
|
+
switch (param) {
|
815
|
+
// case 0x1003 /* AL_PITCH */:
|
816
|
+
// break;
|
817
|
+
case 0x100A /* AL_GAIN */:
|
818
|
+
{{{ makeSetValue('value', '0', 'src.gain.gain.value', 'float') }}}
|
819
|
+
break;
|
820
|
+
// case 0x100D /* AL_MIN_GAIN */:
|
821
|
+
// break;
|
822
|
+
// case 0x100E /* AL_MAX_GAIN */:
|
823
|
+
// break;
|
824
|
+
case 0x1023 /* AL_MAX_DISTANCE */:
|
825
|
+
{{{ makeSetValue('value', '0', 'src.maxDistance', 'float') }}}
|
826
|
+
break;
|
827
|
+
case 0x1021 /* AL_ROLLOFF_FACTOR */:
|
828
|
+
{{{ makeSetValue('value', '0', 'src.rolloffFactor', 'float') }}}
|
829
|
+
break;
|
830
|
+
// case 0x1022 /* AL_CONE_OUTER_GAIN */:
|
831
|
+
// break;
|
832
|
+
// case 0x1001 /* AL_CONE_INNER_ANGLE */:
|
833
|
+
// break;
|
834
|
+
// case 0x1002 /* AL_CONE_OUTER_ANGLE */:
|
835
|
+
// break;
|
836
|
+
case 0x1020 /* AL_REFERENCE_DISTANCE */:
|
837
|
+
{{{ makeSetValue('value', '0', 'src.refDistance', 'float') }}}
|
838
|
+
break;
|
839
|
+
// case 0x1024 /* AL_SEC_OFFSET */:
|
840
|
+
// break;
|
841
|
+
// case 0x1025 /* AL_SAMPLE_OFFSET */:
|
842
|
+
// break;
|
843
|
+
// case 0x1026 /* AL_BYTE_OFFSET */:
|
844
|
+
// break;
|
845
|
+
default:
|
846
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
531
847
|
break;
|
532
848
|
}
|
533
849
|
},
|
534
850
|
|
535
851
|
alDistanceModel: function(model) {
|
536
|
-
if (model
|
852
|
+
if (model !== 0 /* AL_NONE */) {
|
537
853
|
#if OPENAL_DEBUG
|
538
854
|
console.log("Only alDistanceModel(AL_NONE) is currently supported");
|
539
855
|
#endif
|
@@ -545,6 +861,7 @@ var LibraryOpenAL = {
|
|
545
861
|
#if OPENAL_DEBUG
|
546
862
|
console.error("alListenerfv called without a valid context");
|
547
863
|
#endif
|
864
|
+
AL.currentContext.err = 0xA004 /* AL_INVALID_OPERATION */;
|
548
865
|
return;
|
549
866
|
}
|
550
867
|
switch (param) {
|
@@ -576,6 +893,7 @@ var LibraryOpenAL = {
|
|
576
893
|
#if OPENAL_DEBUG
|
577
894
|
console.log("alListenerfv with param " + param + " not implemented yet");
|
578
895
|
#endif
|
896
|
+
AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */;
|
579
897
|
break;
|
580
898
|
}
|
581
899
|
},
|
@@ -588,13 +906,27 @@ var LibraryOpenAL = {
|
|
588
906
|
return 0;
|
589
907
|
},
|
590
908
|
|
909
|
+
alGetString: function(param) {
|
910
|
+
return allocate(intArrayFromString('NA'), 'i8', ALLOC_NORMAL);
|
911
|
+
},
|
912
|
+
|
591
913
|
alGetProcAddress: function(fname) {
|
592
914
|
return 0;
|
593
915
|
},
|
594
916
|
|
917
|
+
alcGetString: function(param) {
|
918
|
+
return allocate(intArrayFromString('NA'), 'i8', ALLOC_NORMAL);
|
919
|
+
},
|
920
|
+
|
595
921
|
alcGetProcAddress: function(device, fname) {
|
596
922
|
return 0;
|
597
923
|
},
|
924
|
+
|
925
|
+
alDopplerFactor: function(value) {
|
926
|
+
},
|
927
|
+
|
928
|
+
alDopplerVelocity: function(value) {
|
929
|
+
}
|
598
930
|
};
|
599
931
|
|
600
932
|
autoAddDeps(LibraryOpenAL, '$AL');
|