sfml.js 0.0.1 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.ja.md +173 -0
- package/README.ko.md +173 -0
- package/README.md +129 -20
- package/README.zh-CN.md +173 -0
- package/assets/branding/sfml-js-symbol-pentagon.svg +24 -0
- package/assets/branding/sfml-js-wordmark-dark.svg +20 -0
- package/assets/branding/sfml-js-wordmark.svg +19 -0
- package/assets/breakout.png +0 -0
- package/binding.gyp +95 -183
- package/dist/audio/effect-processor.d.ts +67 -0
- package/dist/audio/effect-processor.js +58 -0
- package/dist/audio/input-sound-file.d.ts +138 -0
- package/dist/audio/input-sound-file.js +253 -0
- package/dist/audio/listener.d.ts +90 -0
- package/dist/audio/listener.js +148 -0
- package/dist/audio/music.d.ts +210 -0
- package/dist/audio/music.js +353 -0
- package/dist/audio/output-sound-file.d.ts +47 -0
- package/dist/audio/output-sound-file.js +102 -0
- package/dist/audio/playback-device.d.ts +121 -0
- package/dist/audio/playback-device.js +152 -0
- package/dist/audio/sound-buffer-recorder.d.ts +114 -0
- package/dist/audio/sound-buffer-recorder.js +142 -0
- package/dist/audio/sound-buffer.d.ts +150 -0
- package/dist/audio/sound-buffer.js +237 -0
- package/dist/audio/sound-file-factory.d.ts +100 -0
- package/dist/audio/sound-file-factory.js +225 -0
- package/dist/audio/sound-file-reader.d.ts +191 -0
- package/dist/audio/sound-file-reader.js +132 -0
- package/dist/audio/sound-file-writer.d.ts +59 -0
- package/dist/audio/sound-file-writer.js +20 -0
- package/dist/audio/sound-recorder.d.ts +184 -0
- package/dist/audio/sound-recorder.js +286 -0
- package/dist/audio/sound-source.d.ts +336 -0
- package/dist/audio/sound-source.js +389 -0
- package/dist/audio/sound-stream.d.ts +76 -0
- package/dist/audio/sound-stream.js +83 -0
- package/dist/audio/sound.d.ts +41 -0
- package/dist/audio/sound.js +66 -0
- package/dist/audio/value.d.ts +359 -0
- package/dist/audio/value.js +353 -0
- package/dist/audio/worker.d.ts +306 -0
- package/dist/audio/worker.js +2 -0
- package/dist/graphics/blend-mode.d.ts +248 -0
- package/dist/graphics/blend-mode.js +234 -0
- package/dist/graphics/boolean-vector.d.ts +134 -0
- package/dist/graphics/boolean-vector.js +202 -0
- package/dist/graphics/circle-shape.d.ts +84 -0
- package/dist/graphics/circle-shape.js +72 -0
- package/dist/graphics/color.d.ts +278 -0
- package/dist/graphics/color.js +291 -0
- package/dist/graphics/convex-shape.d.ts +56 -0
- package/dist/graphics/convex-shape.js +59 -0
- package/dist/graphics/drawable.d.ts +22 -0
- package/dist/graphics/drawable.js +20 -0
- package/dist/graphics/font.d.ts +199 -0
- package/dist/graphics/font.js +319 -0
- package/dist/graphics/glsl-matrix.d.ts +62 -0
- package/dist/graphics/glsl-matrix.js +106 -0
- package/dist/graphics/glsl.d.ts +165 -0
- package/dist/graphics/glsl.js +215 -0
- package/dist/graphics/glyph.d.ts +133 -0
- package/dist/graphics/glyph.js +138 -0
- package/dist/graphics/image.d.ts +192 -0
- package/dist/graphics/image.js +285 -0
- package/dist/graphics/primitive-type.d.ts +51 -0
- package/dist/graphics/primitive-type.js +60 -0
- package/dist/graphics/rect.d.ts +203 -0
- package/dist/graphics/rect.js +249 -0
- package/dist/graphics/rectangle-shape.d.ts +55 -0
- package/dist/graphics/rectangle-shape.js +60 -0
- package/dist/graphics/render-states.d.ts +188 -0
- package/dist/graphics/render-states.js +115 -0
- package/dist/graphics/render-target.d.ts +222 -0
- package/dist/graphics/render-target.js +434 -0
- package/dist/graphics/render-texture.d.ts +130 -0
- package/dist/graphics/render-texture.js +187 -0
- package/dist/graphics/render-window.d.ts +138 -0
- package/dist/graphics/render-window.js +154 -0
- package/dist/graphics/shader.d.ts +192 -0
- package/dist/graphics/shader.js +321 -0
- package/dist/graphics/shape.d.ts +189 -0
- package/dist/graphics/shape.js +277 -0
- package/dist/graphics/sprite.d.ts +104 -0
- package/dist/graphics/sprite.js +164 -0
- package/dist/graphics/stencil-mode.d.ts +230 -0
- package/dist/graphics/stencil-mode.js +173 -0
- package/dist/graphics/swap.d.ts +17 -0
- package/dist/graphics/swap.js +16 -0
- package/dist/graphics/text.d.ts +759 -0
- package/dist/graphics/text.js +724 -0
- package/dist/graphics/texture.d.ts +255 -0
- package/dist/graphics/texture.js +390 -0
- package/dist/graphics/transform.d.ts +129 -0
- package/dist/graphics/transform.js +274 -0
- package/dist/graphics/transformable.d.ts +24 -0
- package/dist/graphics/transformable.js +38 -0
- package/dist/graphics/vertex-array.d.ts +123 -0
- package/dist/graphics/vertex-array.js +234 -0
- package/dist/graphics/vertex-buffer.d.ts +205 -0
- package/dist/graphics/vertex-buffer.js +256 -0
- package/dist/graphics/vertex.d.ts +111 -0
- package/dist/graphics/vertex.js +134 -0
- package/dist/graphics/view.d.ts +172 -0
- package/dist/graphics/view.js +296 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +251 -0
- package/dist/internal/audio-codec-registry.d.ts +13 -0
- package/dist/internal/audio-codec-registry.js +64 -0
- package/dist/internal/audio-input-stream.d.ts +13 -0
- package/dist/internal/audio-input-stream.js +44 -0
- package/dist/internal/audio-music-pump.d.ts +63 -0
- package/dist/internal/audio-music-pump.js +193 -0
- package/dist/internal/audio-native.d.ts +145 -0
- package/dist/internal/audio-native.js +24 -0
- package/dist/internal/audio-recorder-session.d.ts +77 -0
- package/dist/internal/audio-recorder-session.js +182 -0
- package/dist/internal/audio-worker-session.d.ts +18 -0
- package/dist/internal/audio-worker-session.js +82 -0
- package/dist/internal/audio-worker.d.ts +1 -0
- package/dist/internal/audio-worker.js +134 -0
- package/dist/internal/glsl-value.d.ts +51 -0
- package/dist/internal/glsl-value.js +69 -0
- package/dist/internal/graphics-state.d.ts +45 -0
- package/dist/internal/graphics-state.js +123 -0
- package/dist/internal/input-stream.d.ts +4 -0
- package/dist/internal/input-stream.js +25 -0
- package/dist/internal/lazy-value.d.ts +17 -0
- package/dist/internal/lazy-value.js +43 -0
- package/dist/internal/native.d.ts +317 -0
- package/dist/internal/native.js +8 -0
- package/dist/internal/numeric-properties.d.ts +2 -0
- package/dist/internal/numeric-properties.js +39 -0
- package/dist/internal/render-states.d.ts +4 -0
- package/dist/internal/render-states.js +44 -0
- package/dist/internal/scalar.d.ts +52 -0
- package/dist/internal/scalar.js +95 -0
- package/dist/internal/shaped-glyph.d.ts +32 -0
- package/dist/internal/shaped-glyph.js +51 -0
- package/dist/internal/struct-view.d.ts +11 -0
- package/dist/internal/struct-view.js +39 -0
- package/dist/internal/text-indices.d.ts +7 -0
- package/dist/internal/text-indices.js +22 -0
- package/dist/internal/transformable.d.ts +124 -0
- package/dist/internal/transformable.js +121 -0
- package/dist/internal/value-storage.d.ts +33 -0
- package/dist/internal/value-storage.js +21 -0
- package/dist/network/common.d.ts +23 -0
- package/dist/network/common.js +78 -0
- package/dist/network/dns.d.ts +124 -0
- package/dist/network/dns.js +142 -0
- package/dist/network/ftp.d.ts +265 -0
- package/dist/network/ftp.js +417 -0
- package/dist/network/gen/constants.d.ts +878 -0
- package/dist/network/gen/constants.js +886 -0
- package/dist/network/http.d.ts +458 -0
- package/dist/network/http.js +732 -0
- package/dist/network/ip-address.d.ts +210 -0
- package/dist/network/ip-address.js +301 -0
- package/dist/network/packet.d.ts +249 -0
- package/dist/network/packet.js +326 -0
- package/dist/network/sftp.d.ts +661 -0
- package/dist/network/sftp.js +826 -0
- package/dist/network/socket-selector.d.ts +132 -0
- package/dist/network/socket-selector.js +214 -0
- package/dist/network/socket.d.ts +301 -0
- package/dist/network/socket.js +402 -0
- package/dist/network/tcp-listener.d.ts +114 -0
- package/dist/network/tcp-listener.js +199 -0
- package/dist/network/tcp-socket.d.ts +307 -0
- package/dist/network/tcp-socket.js +493 -0
- package/dist/network/tls-material.d.ts +22 -0
- package/dist/network/tls-material.js +52 -0
- package/dist/network/udp-socket.d.ts +178 -0
- package/dist/network/udp-socket.js +285 -0
- package/dist/system/angle.d.ts +77 -0
- package/dist/system/angle.js +122 -0
- package/dist/system/clock.d.ts +65 -0
- package/dist/system/clock.js +99 -0
- package/dist/system/err.d.ts +18 -0
- package/dist/system/err.js +61 -0
- package/dist/system/error.d.ts +15 -0
- package/dist/system/error.js +22 -0
- package/dist/system/file-input-stream.d.ts +68 -0
- package/dist/system/file-input-stream.js +148 -0
- package/dist/system/input-stream.d.ts +114 -0
- package/dist/system/input-stream.js +106 -0
- package/dist/system/operators.d.ts +291 -0
- package/dist/system/operators.js +505 -0
- package/dist/system/sleep.d.ts +9 -0
- package/dist/system/sleep.js +28 -0
- package/dist/system/suspend-aware-clock.d.ts +22 -0
- package/dist/system/suspend-aware-clock.js +29 -0
- package/dist/system/time.d.ts +100 -0
- package/dist/system/time.js +188 -0
- package/dist/system/timeout-with-predicate.d.ts +60 -0
- package/dist/system/timeout-with-predicate.js +52 -0
- package/dist/system/unicode.d.ts +54 -0
- package/dist/system/unicode.js +67 -0
- package/dist/system/vector2.d.ts +302 -0
- package/dist/system/vector2.js +314 -0
- package/dist/system/vector3.d.ts +249 -0
- package/dist/system/vector3.js +266 -0
- package/dist/system/version.d.ts +51 -0
- package/dist/system/version.js +24 -0
- package/dist/window/clipboard.d.ts +14 -0
- package/dist/window/clipboard.js +26 -0
- package/dist/window/context-settings.d.ts +94 -0
- package/dist/window/context-settings.js +84 -0
- package/dist/window/context.d.ts +87 -0
- package/dist/window/context.js +122 -0
- package/dist/window/cursor.d.ts +58 -0
- package/dist/window/cursor.js +80 -0
- package/dist/window/event.d.ts +529 -0
- package/dist/window/event.js +87 -0
- package/dist/window/gen/constants.d.ts +2213 -0
- package/dist/window/gen/constants.js +2227 -0
- package/dist/window/joystick.d.ts +81 -0
- package/dist/window/joystick.js +80 -0
- package/dist/window/keyboard.d.ts +50 -0
- package/dist/window/keyboard.js +59 -0
- package/dist/window/mouse.d.ts +31 -0
- package/dist/window/mouse.js +57 -0
- package/dist/window/sensor.d.ts +26 -0
- package/dist/window/sensor.js +40 -0
- package/dist/window/touch.d.ts +27 -0
- package/dist/window/touch.js +44 -0
- package/dist/window/video-mode.d.ts +77 -0
- package/dist/window/video-mode.js +99 -0
- package/dist/window/vulkan.d.ts +32 -0
- package/dist/window/vulkan.js +45 -0
- package/dist/window/window.d.ts +355 -0
- package/dist/window/window.js +434 -0
- package/docs/README.ja.md +30 -0
- package/docs/README.ko.md +30 -0
- package/docs/README.md +30 -0
- package/docs/README.zh-CN.md +30 -0
- package/docs/api.ja.md +84 -0
- package/docs/api.ko.md +84 -0
- package/docs/api.md +81 -0
- package/docs/api.zh-CN.md +81 -0
- package/docs/audio.ja.md +249 -0
- package/docs/audio.ko.md +251 -0
- package/docs/audio.md +252 -0
- package/docs/audio.zh-CN.md +252 -0
- package/docs/concepts.ja.md +130 -0
- package/docs/concepts.ko.md +130 -0
- package/docs/concepts.md +131 -0
- package/docs/concepts.zh-CN.md +131 -0
- package/docs/development.ja.md +148 -0
- package/docs/development.ko.md +148 -0
- package/docs/development.md +150 -0
- package/docs/development.zh-CN.md +150 -0
- package/docs/getting-started.ja.md +154 -0
- package/docs/getting-started.ko.md +154 -0
- package/docs/getting-started.md +156 -0
- package/docs/getting-started.zh-CN.md +156 -0
- package/docs/graphics.ja.md +256 -0
- package/docs/graphics.ko.md +254 -0
- package/docs/graphics.md +255 -0
- package/docs/graphics.zh-CN.md +257 -0
- package/docs/network.ja.md +214 -0
- package/docs/network.ko.md +216 -0
- package/docs/network.md +218 -0
- package/docs/network.zh-CN.md +218 -0
- package/docs/system.ja.md +169 -0
- package/docs/system.ko.md +171 -0
- package/docs/system.md +173 -0
- package/docs/system.zh-CN.md +173 -0
- package/docs/window.ja.md +138 -0
- package/docs/window.ko.md +140 -0
- package/docs/window.md +141 -0
- package/docs/window.zh-CN.md +141 -0
- package/native/addon.cc +129 -0
- package/native/audio-binding.cc +543 -0
- package/native/audio-codec-binding.cc +246 -0
- package/native/audio-device-binding.cc +160 -0
- package/native/audio-file-binding.cc +192 -0
- package/native/audio-recorder-binding.cc +237 -0
- package/native/audio-recorder.h +39 -0
- package/native/audio-state.h +220 -0
- package/native/audio-stream-binding.cc +284 -0
- package/native/audio-stream.h +28 -0
- package/native/audio-worker-binding.cc +447 -0
- package/native/audio-worker.h +121 -0
- package/native/batch-drawable.cc +189 -0
- package/native/batch-drawable.h +57 -0
- package/native/context-binding.cc +180 -0
- package/native/context-settings.h +74 -0
- package/native/deferred-delete.cc +49 -0
- package/native/deferred-delete.h +84 -0
- package/native/error-stream-binding.cc +270 -0
- package/native/exception-boundary.h +97 -0
- package/native/font-binding.cc +210 -0
- package/native/font-state.h +27 -0
- package/native/graphics-binding.cc +338 -0
- package/native/graphics-state.h +253 -0
- package/native/image-binding.cc +258 -0
- package/native/image-state.h +93 -0
- package/native/input-binding.cc +246 -0
- package/native/numeric-fields.h +96 -0
- package/native/render-window-binding.cc +103 -0
- package/native/render-window-state.h +22 -0
- package/native/shader-binding.cc +292 -0
- package/native/shape-binding.cc +283 -0
- package/native/shape-state.h +68 -0
- package/native/shaped-glyph-storage.h +45 -0
- package/native/shared-handle.h +69 -0
- package/native/stream-binding.cc +286 -0
- package/native/system-binding.cc +91 -0
- package/native/text-binding.cc +205 -0
- package/native/text-state.h +101 -0
- package/native/texture-binding.cc +330 -0
- package/native/texture-resource.h +52 -0
- package/native/time-value.h +28 -0
- package/native/transformable-binding.cc +23 -0
- package/native/transformable-state.h +44 -0
- package/native/value-binding.h +200 -0
- package/native/value-layout.h +116 -0
- package/native/values-binding.cc +27 -0
- package/native/vertex-binding.cc +50 -0
- package/native/vertex-buffer-binding.cc +232 -0
- package/native/vertex-storage.h +20 -0
- package/native/view-data.h +24 -0
- package/native/window-binding.cc +388 -0
- package/native/window-event.h +92 -0
- package/native/window-owner.h +81 -0
- package/package.json +87 -35
- package/src/audio/effect-processor.ts +86 -0
- package/src/audio/input-sound-file.ts +259 -0
- package/src/audio/listener.ts +136 -0
- package/src/audio/music.ts +357 -0
- package/src/audio/output-sound-file.ts +96 -0
- package/src/audio/playback-device.ts +145 -0
- package/src/audio/sound-buffer-recorder.ts +141 -0
- package/src/audio/sound-buffer.ts +275 -0
- package/src/audio/sound-file-factory.ts +235 -0
- package/src/audio/sound-file-reader.ts +224 -0
- package/src/audio/sound-file-writer.ts +61 -0
- package/src/audio/sound-recorder.ts +315 -0
- package/src/audio/sound-source.ts +396 -0
- package/src/audio/sound-stream.ts +108 -0
- package/src/audio/sound.ts +63 -0
- package/src/audio/value.ts +408 -0
- package/src/audio/worker.ts +308 -0
- package/src/graphics/blend-mode.ts +291 -0
- package/src/graphics/boolean-vector.ts +225 -0
- package/src/graphics/circle-shape.ts +113 -0
- package/src/graphics/color.ts +374 -0
- package/src/graphics/convex-shape.ts +76 -0
- package/src/graphics/drawable.ts +32 -0
- package/src/graphics/font.ts +377 -0
- package/src/graphics/glsl-matrix.ts +110 -0
- package/src/graphics/glsl.ts +229 -0
- package/src/graphics/glyph.ts +186 -0
- package/src/graphics/image.ts +366 -0
- package/src/graphics/primitive-type.ts +56 -0
- package/src/graphics/rect.ts +350 -0
- package/src/graphics/rectangle-shape.ts +76 -0
- package/src/graphics/render-states.ts +238 -0
- package/src/graphics/render-target.ts +554 -0
- package/src/graphics/render-texture.ts +234 -0
- package/src/graphics/render-window.ts +250 -0
- package/src/graphics/shader.ts +353 -0
- package/src/graphics/shape.ts +343 -0
- package/src/graphics/sprite.ts +203 -0
- package/src/graphics/stencil-mode.ts +258 -0
- package/src/graphics/swap.ts +28 -0
- package/src/graphics/text.ts +944 -0
- package/src/graphics/texture.ts +529 -0
- package/src/graphics/transform.ts +321 -0
- package/src/graphics/transformable.ts +37 -0
- package/src/graphics/vertex-array.ts +270 -0
- package/src/graphics/vertex-buffer.ts +345 -0
- package/src/graphics/vertex.ts +211 -0
- package/src/graphics/view.ts +355 -0
- package/src/index.ts +147 -0
- package/src/internal/audio-codec-registry.ts +68 -0
- package/src/internal/audio-input-stream.ts +42 -0
- package/src/internal/audio-music-pump.ts +199 -0
- package/src/internal/audio-native.ts +176 -0
- package/src/internal/audio-recorder-session.ts +234 -0
- package/src/internal/audio-worker-session.ts +89 -0
- package/src/internal/audio-worker.ts +146 -0
- package/src/internal/glsl-value.ts +79 -0
- package/src/internal/graphics-state.ts +131 -0
- package/src/internal/input-stream.ts +30 -0
- package/src/internal/lazy-value.ts +62 -0
- package/src/internal/native.ts +581 -0
- package/src/internal/numeric-properties.ts +37 -0
- package/src/internal/render-states.ts +42 -0
- package/src/internal/scalar.ts +117 -0
- package/src/internal/shaped-glyph.ts +68 -0
- package/src/internal/struct-view.ts +49 -0
- package/src/internal/text-indices.ts +19 -0
- package/src/internal/transformable.ts +260 -0
- package/src/internal/value-storage.ts +40 -0
- package/src/network/common.ts +58 -0
- package/src/network/dns.ts +191 -0
- package/src/network/ftp.ts +386 -0
- package/src/network/gen/constants.ts +879 -0
- package/src/network/http.ts +680 -0
- package/src/network/ip-address.ts +311 -0
- package/src/network/packet.ts +388 -0
- package/src/network/sftp.ts +1015 -0
- package/src/network/socket-selector.ts +206 -0
- package/src/network/socket.ts +415 -0
- package/src/network/tcp-listener.ts +193 -0
- package/src/network/tcp-socket.ts +569 -0
- package/src/network/tls-material.ts +46 -0
- package/src/network/udp-socket.ts +294 -0
- package/src/system/angle.ts +132 -0
- package/src/system/clock.ts +104 -0
- package/src/system/err.ts +58 -0
- package/src/system/error.ts +18 -0
- package/src/system/file-input-stream.ts +147 -0
- package/src/system/input-stream.ts +150 -0
- package/src/system/operators.ts +681 -0
- package/src/system/sleep.ts +25 -0
- package/src/system/suspend-aware-clock.ts +27 -0
- package/src/system/time.ts +218 -0
- package/src/system/timeout-with-predicate.ts +94 -0
- package/src/system/unicode.ts +64 -0
- package/src/system/vector2.ts +549 -0
- package/src/system/vector3.ts +433 -0
- package/src/system/version.ts +66 -0
- package/src/window/clipboard.ts +22 -0
- package/src/window/context-settings.ts +143 -0
- package/src/window/context.ts +152 -0
- package/src/window/cursor.ts +116 -0
- package/src/window/event.ts +580 -0
- package/src/window/gen/constants.ts +2231 -0
- package/src/window/joystick.ts +108 -0
- package/src/window/keyboard.ts +78 -0
- package/src/window/mouse.ts +58 -0
- package/src/window/sensor.ts +37 -0
- package/src/window/touch.ts +42 -0
- package/src/window/video-mode.ts +136 -0
- package/src/window/vulkan.ts +42 -0
- package/src/window/window.ts +579 -0
- package/test/native/audio-probes.cc +181 -0
- package/test/native/deferred-delete-probes.cc +62 -0
- package/test/native/drawable-probes.cc +168 -0
- package/test/native/exception-probes.cc +83 -0
- package/test/native/image-probes.cc +105 -0
- package/test/native/matrix-probes.cc +67 -0
- package/test/native/network-oracle.cc +32 -0
- package/test/native/render-texture-probes.cc +193 -0
- package/test/native/shader-probes.cc +69 -0
- package/test/native/shape-probes.cc +160 -0
- package/test/native/sprite-probes.cc +146 -0
- package/test/native/system-probes.cc +109 -0
- package/test/native/text-probes.cc +211 -0
- package/test/native/texture-probes.cc +200 -0
- package/test/native/time-probes.cc +143 -0
- package/test/native/transform-probes.cc +92 -0
- package/test/native/transformable-probes.cc +152 -0
- package/test/native/value-oracle.h +88 -0
- package/test/native/value-probes.cc +379 -0
- package/test/native/vertex-array-probes.cc +82 -0
- package/test/native/vertex-buffer-probes.cc +87 -0
- package/test/native/view-probes.cc +150 -0
- package/test/native/window-probes.cc +172 -0
- package/test/tsconfig.json +8 -0
- package/tools/configure-lsp.cjs +23 -0
- package/tools/constant-docs.cjs +109 -0
- package/tools/constant-docs.json +1318 -0
- package/tools/generate-network-constants.cjs +59 -0
- package/tools/generate-window-constants.cjs +178 -0
- package/tools/lib_downloader.cjs +92 -0
- package/tools/lib_downloader_urls.cjs +23 -0
- package/tsconfig.json +11 -4
- package/index.d.ts +0 -1
- package/lib/clock.d.ts +0 -8
- package/lib/clock.js +0 -5
- package/lib/color.d.ts +0 -11
- package/lib/color.js +0 -98
- package/lib/common.js +0 -47
- package/lib/drawable/circle_shape.d.ts +0 -5
- package/lib/drawable/circle_shape.js +0 -26
- package/lib/drawable/convex_shape.d.ts +0 -5
- package/lib/drawable/convex_shape.js +0 -35
- package/lib/drawable/drawable.d.ts +0 -6
- package/lib/drawable/drawable.js +0 -18
- package/lib/drawable/plugin_package.d.ts +0 -31
- package/lib/drawable/plugin_package.js +0 -102
- package/lib/drawable/rectangle_shape.d.ts +0 -9
- package/lib/drawable/rectangle_shape.js +0 -28
- package/lib/drawable/shape.d.ts +0 -14
- package/lib/drawable/shape.js +0 -30
- package/lib/drawable/sprite.d.ts +0 -17
- package/lib/drawable/sprite.js +0 -53
- package/lib/drawable/text.d.ts +0 -26
- package/lib/drawable/text.js +0 -88
- package/lib/drawable/transformable.d.ts +0 -28
- package/lib/drawable/transformable.js +0 -113
- package/lib/drawable/vertex_array.d.ts +0 -40
- package/lib/drawable/vertex_array.js +0 -128
- package/lib/font.d.ts +0 -24
- package/lib/font.js +0 -137
- package/lib/image.d.ts +0 -26
- package/lib/image.js +0 -147
- package/lib/joystick.d.ts +0 -21
- package/lib/joystick.js +0 -72
- package/lib/keyboard.d.ts +0 -113
- package/lib/keyboard.js +0 -17
- package/lib/mouse.d.ts +0 -6
- package/lib/mouse.js +0 -39
- package/lib/poll_event.d.ts +0 -138
- package/lib/rect.d.ts +0 -18
- package/lib/rect.js +0 -119
- package/lib/render_window.d.ts +0 -67
- package/lib/render_window.js +0 -197
- package/lib/sensor.d.ts +0 -12
- package/lib/sensor.js +0 -34
- package/lib/sfml.d.ts +0 -32
- package/lib/sfml.js +0 -36
- package/lib/sound/base.d.ts +0 -33
- package/lib/sound/base.js +0 -109
- package/lib/sound/music.d.ts +0 -15
- package/lib/sound/music.js +0 -65
- package/lib/sound/sound.d.ts +0 -16
- package/lib/sound/sound.js +0 -55
- package/lib/sound/sound_buffer.d.ts +0 -14
- package/lib/sound/sound_buffer.js +0 -78
- package/lib/texture.d.ts +0 -21
- package/lib/texture.js +0 -127
- package/lib/time.d.ts +0 -13
- package/lib/time.js +0 -41
- package/lib/touch.d.ts +0 -7
- package/lib/touch.js +0 -34
- package/lib/vector2.d.ts +0 -49
- package/lib/vector2.js +0 -141
- package/lib/vector3.d.ts +0 -47
- package/lib/vector3.js +0 -154
- package/lib/vertex.d.ts +0 -14
- package/lib/vertex.js +0 -177
- package/lib/video_mode.d.ts +0 -12
- package/lib/video_mode.js +0 -99
- package/src/base_class_with_loading.h +0 -21
- package/src/clock.cc +0 -71
- package/src/clock.h +0 -30
- package/src/color.cc +0 -189
- package/src/color.h +0 -49
- package/src/drawable/circle_shape.cc +0 -78
- package/src/drawable/circle_shape.h +0 -28
- package/src/drawable/convex_shape.cc +0 -57
- package/src/drawable/convex_shape.h +0 -29
- package/src/drawable/drawable-inl.h +0 -29
- package/src/drawable/drawable.cc +0 -41
- package/src/drawable/drawable.h +0 -49
- package/src/drawable/package_plugin-inl.h +0 -191
- package/src/drawable/package_plugin.h +0 -60
- package/src/drawable/rectangle_shape.cc +0 -69
- package/src/drawable/rectangle_shape.h +0 -29
- package/src/drawable/shape.cc +0 -67
- package/src/drawable/shape.h +0 -39
- package/src/drawable/sprite.cc +0 -122
- package/src/drawable/sprite.h +0 -45
- package/src/drawable/text.cc +0 -133
- package/src/drawable/text.h +0 -54
- package/src/drawable/vertex_array.cc +0 -248
- package/src/drawable/vertex_array.h +0 -46
- package/src/font.cc +0 -214
- package/src/font.h +0 -44
- package/src/gen/.gitkeep +0 -0
- package/src/gen/joystick_axis.cc +0 -30
- package/src/gen/keycode.cc +0 -226
- package/src/gen/mouse_button.cc +0 -30
- package/src/gen/sensor_type.cc +0 -26
- package/src/image.cc +0 -379
- package/src/image.h +0 -72
- package/src/joystick.cc +0 -132
- package/src/joystick.h +0 -32
- package/src/keyboard.cc +0 -65
- package/src/keyboard.h +0 -27
- package/src/mouse.cc +0 -95
- package/src/mouse.h +0 -30
- package/src/plugins/transformable_plugin-inl.h +0 -121
- package/src/plugins/transformable_plugin.h +0 -42
- package/src/poll_event.cc +0 -326
- package/src/poll_event.h +0 -18
- package/src/rect-inl.h +0 -154
- package/src/rect.cc +0 -28
- package/src/rect.h +0 -105
- package/src/render_window.cc +0 -413
- package/src/render_window.h +0 -111
- package/src/render_window_async_display.cc +0 -49
- package/src/render_window_async_draw.cc +0 -56
- package/src/resizable_buffer.h +0 -104
- package/src/sensor.cc +0 -82
- package/src/sensor.h +0 -28
- package/src/sfml.cc +0 -85
- package/src/sound/music.cc +0 -113
- package/src/sound/music.h +0 -35
- package/src/sound/sound.cc +0 -116
- package/src/sound/sound.h +0 -41
- package/src/sound/sound_buffer.cc +0 -226
- package/src/sound/sound_buffer.h +0 -46
- package/src/sound/sound_source.cc +0 -124
- package/src/sound/sound_source.h +0 -80
- package/src/texture.cc +0 -246
- package/src/texture.h +0 -47
- package/src/time.cc +0 -177
- package/src/time.h +0 -42
- package/src/touch.cc +0 -54
- package/src/touch.h +0 -23
- package/src/utils-inl.h +0 -48
- package/src/utils.h +0 -21
- package/src/vector2-inl.h +0 -198
- package/src/vector2.cc +0 -36
- package/src/vector2.h +0 -133
- package/src/vector3-inl.h +0 -200
- package/src/vector3.cc +0 -36
- package/src/vector3.h +0 -134
- package/src/vertex.cc +0 -238
- package/src/vertex.h +0 -114
- package/src/video_mode.cc +0 -184
- package/src/video_mode.h +0 -38
- package/src/workers/load_from_file_worker.h +0 -79
- package/src/workers/save_to_file_worker.h +0 -79
- package/third_party/sfml/include/SFML/Audio/AlResource.hpp +0 -70
- package/third_party/sfml/include/SFML/Audio/Export.hpp +0 -48
- package/third_party/sfml/include/SFML/Audio/InputSoundFile.hpp +0 -268
- package/third_party/sfml/include/SFML/Audio/Listener.hpp +0 -234
- package/third_party/sfml/include/SFML/Audio/Music.hpp +0 -337
- package/third_party/sfml/include/SFML/Audio/OutputSoundFile.hpp +0 -133
- package/third_party/sfml/include/SFML/Audio/Sound.hpp +0 -264
- package/third_party/sfml/include/SFML/Audio/SoundBuffer.hpp +0 -352
- package/third_party/sfml/include/SFML/Audio/SoundBufferRecorder.hpp +0 -144
- package/third_party/sfml/include/SFML/Audio/SoundFileFactory.hpp +0 -197
- package/third_party/sfml/include/SFML/Audio/SoundFileFactory.inl +0 -100
- package/third_party/sfml/include/SFML/Audio/SoundFileReader.hpp +0 -165
- package/third_party/sfml/include/SFML/Audio/SoundFileWriter.hpp +0 -125
- package/third_party/sfml/include/SFML/Audio/SoundRecorder.hpp +0 -410
- package/third_party/sfml/include/SFML/Audio/SoundSource.hpp +0 -332
- package/third_party/sfml/include/SFML/Audio/SoundStream.hpp +0 -420
- package/third_party/sfml/include/SFML/Audio.hpp +0 -56
- package/third_party/sfml/include/SFML/Config.hpp +0 -248
- package/third_party/sfml/include/SFML/GpuPreference.hpp +0 -74
- package/third_party/sfml/include/SFML/Graphics/BlendMode.hpp +0 -219
- package/third_party/sfml/include/SFML/Graphics/CircleShape.hpp +0 -154
- package/third_party/sfml/include/SFML/Graphics/Color.hpp +0 -275
- package/third_party/sfml/include/SFML/Graphics/ConvexShape.hpp +0 -153
- package/third_party/sfml/include/SFML/Graphics/Drawable.hpp +0 -126
- package/third_party/sfml/include/SFML/Graphics/Export.hpp +0 -48
- package/third_party/sfml/include/SFML/Graphics/Font.hpp +0 -496
- package/third_party/sfml/include/SFML/Graphics/Glsl.hpp +0 -227
- package/third_party/sfml/include/SFML/Graphics/Glsl.inl +0 -155
- package/third_party/sfml/include/SFML/Graphics/Glyph.hpp +0 -81
- package/third_party/sfml/include/SFML/Graphics/Image.hpp +0 -346
- package/third_party/sfml/include/SFML/Graphics/PrimitiveType.hpp +0 -58
- package/third_party/sfml/include/SFML/Graphics/Rect.hpp +0 -274
- package/third_party/sfml/include/SFML/Graphics/Rect.inl +0 -171
- package/third_party/sfml/include/SFML/Graphics/RectangleShape.hpp +0 -132
- package/third_party/sfml/include/SFML/Graphics/RenderStates.hpp +0 -174
- package/third_party/sfml/include/SFML/Graphics/RenderTarget.hpp +0 -518
- package/third_party/sfml/include/SFML/Graphics/RenderTexture.hpp +0 -334
- package/third_party/sfml/include/SFML/Graphics/RenderWindow.hpp +0 -302
- package/third_party/sfml/include/SFML/Graphics/Shader.hpp +0 -875
- package/third_party/sfml/include/SFML/Graphics/Shape.hpp +0 -355
- package/third_party/sfml/include/SFML/Graphics/Sprite.hpp +0 -279
- package/third_party/sfml/include/SFML/Graphics/Text.hpp +0 -513
- package/third_party/sfml/include/SFML/Graphics/Texture.hpp +0 -733
- package/third_party/sfml/include/SFML/Graphics/Transform.hpp +0 -497
- package/third_party/sfml/include/SFML/Graphics/Transformable.hpp +0 -429
- package/third_party/sfml/include/SFML/Graphics/Vertex.hpp +0 -148
- package/third_party/sfml/include/SFML/Graphics/VertexArray.hpp +0 -223
- package/third_party/sfml/include/SFML/Graphics/VertexBuffer.hpp +0 -408
- package/third_party/sfml/include/SFML/Graphics/View.hpp +0 -343
- package/third_party/sfml/include/SFML/Graphics.hpp +0 -68
- package/third_party/sfml/include/SFML/Main.hpp +0 -43
- package/third_party/sfml/include/SFML/Network/Export.hpp +0 -48
- package/third_party/sfml/include/SFML/Network/Ftp.hpp +0 -616
- package/third_party/sfml/include/SFML/Network/Http.hpp +0 -482
- package/third_party/sfml/include/SFML/Network/IpAddress.hpp +0 -328
- package/third_party/sfml/include/SFML/Network/Packet.hpp +0 -545
- package/third_party/sfml/include/SFML/Network/Socket.hpp +0 -219
- package/third_party/sfml/include/SFML/Network/SocketHandle.hpp +0 -57
- package/third_party/sfml/include/SFML/Network/SocketSelector.hpp +0 -263
- package/third_party/sfml/include/SFML/Network/TcpListener.hpp +0 -170
- package/third_party/sfml/include/SFML/Network/TcpSocket.hpp +0 -316
- package/third_party/sfml/include/SFML/Network/UdpSocket.hpp +0 -292
- package/third_party/sfml/include/SFML/Network.hpp +0 -53
- package/third_party/sfml/include/SFML/OpenGL.hpp +0 -78
- package/third_party/sfml/include/SFML/System/Clock.hpp +0 -117
- package/third_party/sfml/include/SFML/System/Err.hpp +0 -80
- package/third_party/sfml/include/SFML/System/Export.hpp +0 -48
- package/third_party/sfml/include/SFML/System/FileInputStream.hpp +0 -169
- package/third_party/sfml/include/SFML/System/InputStream.hpp +0 -152
- package/third_party/sfml/include/SFML/System/Lock.hpp +0 -139
- package/third_party/sfml/include/SFML/System/MemoryInputStream.hpp +0 -148
- package/third_party/sfml/include/SFML/System/Mutex.hpp +0 -148
- package/third_party/sfml/include/SFML/System/NativeActivity.hpp +0 -62
- package/third_party/sfml/include/SFML/System/NonCopyable.hpp +0 -129
- package/third_party/sfml/include/SFML/System/Sleep.hpp +0 -52
- package/third_party/sfml/include/SFML/System/String.hpp +0 -669
- package/third_party/sfml/include/SFML/System/String.inl +0 -53
- package/third_party/sfml/include/SFML/System/Thread.hpp +0 -282
- package/third_party/sfml/include/SFML/System/Thread.inl +0 -90
- package/third_party/sfml/include/SFML/System/ThreadLocal.hpp +0 -103
- package/third_party/sfml/include/SFML/System/ThreadLocalPtr.hpp +0 -158
- package/third_party/sfml/include/SFML/System/ThreadLocalPtr.inl +0 -77
- package/third_party/sfml/include/SFML/System/Time.hpp +0 -488
- package/third_party/sfml/include/SFML/System/Utf.hpp +0 -763
- package/third_party/sfml/include/SFML/System/Utf.inl +0 -752
- package/third_party/sfml/include/SFML/System/Vector2.hpp +0 -301
- package/third_party/sfml/include/SFML/System/Vector2.inl +0 -161
- package/third_party/sfml/include/SFML/System/Vector3.hpp +0 -302
- package/third_party/sfml/include/SFML/System/Vector3.inl +0 -168
- package/third_party/sfml/include/SFML/System.hpp +0 -60
- package/third_party/sfml/include/SFML/Window/Clipboard.hpp +0 -119
- package/third_party/sfml/include/SFML/Window/Context.hpp +0 -195
- package/third_party/sfml/include/SFML/Window/ContextSettings.hpp +0 -149
- package/third_party/sfml/include/SFML/Window/Cursor.hpp +0 -241
- package/third_party/sfml/include/SFML/Window/Event.hpp +0 -285
- package/third_party/sfml/include/SFML/Window/Export.hpp +0 -48
- package/third_party/sfml/include/SFML/Window/GlResource.hpp +0 -109
- package/third_party/sfml/include/SFML/Window/Joystick.hpp +0 -227
- package/third_party/sfml/include/SFML/Window/Keyboard.hpp +0 -491
- package/third_party/sfml/include/SFML/Window/Mouse.hpp +0 -180
- package/third_party/sfml/include/SFML/Window/Sensor.hpp +0 -150
- package/third_party/sfml/include/SFML/Window/Touch.hpp +0 -137
- package/third_party/sfml/include/SFML/Window/VideoMode.hpp +0 -228
- package/third_party/sfml/include/SFML/Window/Vulkan.hpp +0 -115
- package/third_party/sfml/include/SFML/Window/Window.hpp +0 -354
- package/third_party/sfml/include/SFML/Window/WindowBase.hpp +0 -518
- package/third_party/sfml/include/SFML/Window/WindowHandle.hpp +0 -101
- package/third_party/sfml/include/SFML/Window/WindowStyle.hpp +0 -53
- package/third_party/sfml/include/SFML/Window.hpp +0 -58
- package/tools/clang_format.js +0 -9
- package/tools/copier/linux.js +0 -21
- package/tools/copier/macos.js +0 -34
- package/tools/copier/windows.js +0 -33
- package/tools/joystick_axis.js +0 -63
- package/tools/keycode.js +0 -92
- package/tools/lib_downloader.js +0 -107
- package/tools/lib_downloader_urls.js +0 -59
- package/tools/mouse_button.js +0 -92
- package/tools/sensor_type.js +0 -63
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
#include "audio-worker.h"
|
|
2
|
+
|
|
3
|
+
#include <limits>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
|
|
6
|
+
namespace sfmljs::audio {
|
|
7
|
+
namespace {
|
|
8
|
+
std::mutex registryMutex;
|
|
9
|
+
std::unordered_map<std::uint64_t, std::weak_ptr<AudioWorkerState>> registry;
|
|
10
|
+
std::uint64_t nextToken{};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
std::shared_ptr<AudioWorkerState> CreateWorkerState(
|
|
14
|
+
unsigned kind, unsigned frames, unsigned channels, unsigned rate,
|
|
15
|
+
unsigned slots) {
|
|
16
|
+
if (kind > 2 || frames < 64 || frames > 65536 || channels < 1 ||
|
|
17
|
+
channels > 32 || rate < 1 || slots < 2 || slots > 32) {
|
|
18
|
+
throw std::range_error("Invalid audio queue dimensions");
|
|
19
|
+
}
|
|
20
|
+
return std::make_shared<AudioWorkerState>(kind, frames, channels, rate, slots);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
v8::Local<v8::Value> RegisterWorker(const std::shared_ptr<AudioWorkerState>& state) {
|
|
24
|
+
std::lock_guard lock(registryMutex);
|
|
25
|
+
std::erase_if(registry, [](const auto& item) { return item.second.expired(); });
|
|
26
|
+
const auto token = ++nextToken;
|
|
27
|
+
registry.emplace(token, state);
|
|
28
|
+
return v8::BigInt::NewFromUnsigned(v8::Isolate::GetCurrent(), token);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
v8::Local<v8::Object> MapWorker(const std::shared_ptr<AudioWorkerState>& state) {
|
|
32
|
+
auto result = Nan::New<v8::Object>();
|
|
33
|
+
Set(result, "handle", AudioWorkerHandle::Create(state));
|
|
34
|
+
Set(result, "fields", MapShared(v8::Isolate::GetCurrent(), state,
|
|
35
|
+
state->fields.data(), sizeof(state->fields)));
|
|
36
|
+
Set(result, "time", MapShared(v8::Isolate::GetCurrent(), state,
|
|
37
|
+
state->time.data(), sizeof(state->time)));
|
|
38
|
+
auto mapPipe = [&](AudioPipe& pipe) {
|
|
39
|
+
auto array = Nan::New<v8::Array>(static_cast<int>(pipe.blocks.size()));
|
|
40
|
+
for (unsigned i = 0; i < pipe.blocks.size(); ++i) {
|
|
41
|
+
auto& block = *pipe.blocks[i];
|
|
42
|
+
auto buffer = state->kind == 2
|
|
43
|
+
? MapShared(v8::Isolate::GetCurrent(), state, block.floats.data(),
|
|
44
|
+
block.floats.size() * sizeof(float))
|
|
45
|
+
: MapShared(v8::Isolate::GetCurrent(), state, block.pcm.data(),
|
|
46
|
+
block.pcm.size() * sizeof(std::int16_t));
|
|
47
|
+
Nan::Set(array, i, buffer).FromJust();
|
|
48
|
+
}
|
|
49
|
+
return array;
|
|
50
|
+
};
|
|
51
|
+
Set(result, "input", mapPipe(state->input));
|
|
52
|
+
Set(result, "output", mapPipe(state->output));
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
bool AudioWorkerState::Stream(sf::SoundStream::Chunk& chunk) {
|
|
57
|
+
if (streamLease) { input.Release(); streamLease = false; }
|
|
58
|
+
if (closed.load(std::memory_order_acquire)) return false;
|
|
59
|
+
const auto current = generation.load(std::memory_order_acquire);
|
|
60
|
+
for (unsigned i = 0; i < input.blocks.size(); ++i) {
|
|
61
|
+
auto* block = input.Read();
|
|
62
|
+
if (!block) break;
|
|
63
|
+
if (block->generation != current) { input.Release(); continue; }
|
|
64
|
+
chunk = {block->pcm.data(), block->count};
|
|
65
|
+
loop = block->loop;
|
|
66
|
+
streamLease = true;
|
|
67
|
+
processed.fetch_add(block->count, std::memory_order_relaxed);
|
|
68
|
+
return block->more;
|
|
69
|
+
}
|
|
70
|
+
underruns.fetch_add(1, std::memory_order_relaxed);
|
|
71
|
+
chunk = {silence.data(), silence.size()};
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void AudioWorkerState::Capture(const std::int16_t* samples, std::size_t count) {
|
|
76
|
+
if (closed.load(std::memory_order_acquire) ||
|
|
77
|
+
finish.load(std::memory_order_acquire)) return;
|
|
78
|
+
const unsigned capacity = frames * channels;
|
|
79
|
+
while (count) {
|
|
80
|
+
auto* block = input.Write();
|
|
81
|
+
if (!block) { overruns.fetch_add(count, std::memory_order_relaxed); return; }
|
|
82
|
+
const auto size = static_cast<unsigned>(std::min<std::size_t>(count, capacity));
|
|
83
|
+
std::memcpy(block->pcm.data(), samples, size * sizeof(*samples));
|
|
84
|
+
block->count = size;
|
|
85
|
+
block->channels = channels;
|
|
86
|
+
input.Publish();
|
|
87
|
+
samples += size;
|
|
88
|
+
count -= size;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void AudioWorkerState::Effect(const float* in, unsigned& inFrames, float* out,
|
|
93
|
+
unsigned& outFrames, unsigned channelCount) {
|
|
94
|
+
if (closed.load(std::memory_order_acquire) || channelCount > channels ||
|
|
95
|
+
channelCount == 0) {
|
|
96
|
+
std::fill_n(out, outFrames * channelCount, 0.f);
|
|
97
|
+
if (!in) outFrames = 0;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const unsigned accepted = in ? std::min(inFrames, frames) : 0;
|
|
101
|
+
const auto current = generation.load(std::memory_order_acquire);
|
|
102
|
+
if (in) tailDone.store(false, std::memory_order_release);
|
|
103
|
+
if (in || !tailDone.load(std::memory_order_acquire)) {
|
|
104
|
+
if (auto* block = input.Write()) {
|
|
105
|
+
block->count = accepted * channelCount;
|
|
106
|
+
block->channels = channelCount;
|
|
107
|
+
block->tail = !in;
|
|
108
|
+
block->generation = current;
|
|
109
|
+
if (accepted) std::memcpy(block->floats.data(), in, block->count * sizeof(float));
|
|
110
|
+
pending.fetch_add(1, std::memory_order_relaxed);
|
|
111
|
+
input.Publish();
|
|
112
|
+
} else {
|
|
113
|
+
overruns.fetch_add(accepted, std::memory_order_relaxed);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
inFrames = accepted;
|
|
117
|
+
const unsigned requested = outFrames;
|
|
118
|
+
unsigned written{};
|
|
119
|
+
while (written < requested) {
|
|
120
|
+
auto* block = output.Read();
|
|
121
|
+
if (!block) break;
|
|
122
|
+
if (block->channels != channelCount || block->generation != current) {
|
|
123
|
+
output.Release();
|
|
124
|
+
outputOffset = 0;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const auto count = std::min(requested - written,
|
|
128
|
+
(block->count - outputOffset) / channelCount);
|
|
129
|
+
std::memcpy(out + written * channelCount, block->floats.data() + outputOffset,
|
|
130
|
+
count * channelCount * sizeof(float));
|
|
131
|
+
written += count;
|
|
132
|
+
outputOffset += count * channelCount;
|
|
133
|
+
if (outputOffset == block->count) {
|
|
134
|
+
output.Release();
|
|
135
|
+
outputOffset = 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!in && tailDone.load(std::memory_order_acquire) &&
|
|
139
|
+
pending.load(std::memory_order_acquire) == 0) {
|
|
140
|
+
outFrames = written;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (written < requested) {
|
|
144
|
+
underruns.fetch_add(requested - written, std::memory_order_relaxed);
|
|
145
|
+
std::fill(out + written * channelCount, out + requested * channelCount, 0.f);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
class WorkerStream final : public sf::SoundStream {
|
|
150
|
+
public:
|
|
151
|
+
WorkerStream(std::shared_ptr<AudioWorkerState> state,
|
|
152
|
+
const std::vector<sf::SoundChannel>& channels)
|
|
153
|
+
: state_(std::move(state)) {
|
|
154
|
+
initialize(state_->channels, state_->rate, channels);
|
|
155
|
+
}
|
|
156
|
+
~WorkerStream() override {
|
|
157
|
+
stop();
|
|
158
|
+
state_->closed.store(true, std::memory_order_release);
|
|
159
|
+
}
|
|
160
|
+
bool onGetData(Chunk& chunk) override { return state_->Stream(chunk); }
|
|
161
|
+
void onSeek(sf::Time time) override { state_->Seek(time.asMicroseconds()); }
|
|
162
|
+
std::optional<std::uint64_t> onLoop() override {
|
|
163
|
+
if (state_->loop < 0) return std::nullopt;
|
|
164
|
+
const auto sample = static_cast<std::uint64_t>(state_->loop);
|
|
165
|
+
state_->Seek(static_cast<std::int64_t>(
|
|
166
|
+
sample / state_->channels * 1000000 / state_->rate), state_->loop);
|
|
167
|
+
return sample;
|
|
168
|
+
}
|
|
169
|
+
private:
|
|
170
|
+
std::shared_ptr<AudioWorkerState> state_;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
NAN_METHOD(CreateAudioStream) {
|
|
174
|
+
unsigned frames, channels, rate, slots;
|
|
175
|
+
std::vector<sf::SoundChannel> map;
|
|
176
|
+
if (!Unsigned(info[0], frames) || !Unsigned(info[1], channels) ||
|
|
177
|
+
!Unsigned(info[2], rate) || !Unsigned(info[3], slots) ||
|
|
178
|
+
!Channels(info[4], map)) return;
|
|
179
|
+
if (map.size() != channels) return Nan::ThrowRangeError("Channel map size mismatch");
|
|
180
|
+
auto state = CreateWorkerState(0, frames, channels, rate, slots);
|
|
181
|
+
auto source = MakeThreadOwned<Source>();
|
|
182
|
+
source->kind = 2;
|
|
183
|
+
source->stream = state;
|
|
184
|
+
source->sound = std::make_unique<WorkerStream>(state, map);
|
|
185
|
+
auto result = MapSource(source);
|
|
186
|
+
Set(result, "token", RegisterWorker(state));
|
|
187
|
+
Set(result, "worker", AudioWorkerHandle::Create(state));
|
|
188
|
+
info.GetReturnValue().Set(result);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
NAN_METHOD(OpenAudioMusicStream) {
|
|
192
|
+
auto* handle = SourceHandle::From(info[0]);
|
|
193
|
+
unsigned frames, channels, rate, slots;
|
|
194
|
+
std::vector<sf::SoundChannel> map;
|
|
195
|
+
if (!handle || !Unsigned(info[1], frames) || !Unsigned(info[2], channels) ||
|
|
196
|
+
!Unsigned(info[3], rate) || !Unsigned(info[4], slots) ||
|
|
197
|
+
!Channels(info[5], map)) return;
|
|
198
|
+
bool lossless{};
|
|
199
|
+
const auto count = info[6]->IsBigInt() ? info[6].As<v8::BigInt>()->Uint64Value(&lossless) : 0;
|
|
200
|
+
if (!lossless || map.size() != channels) return Nan::ThrowRangeError("Invalid music metadata");
|
|
201
|
+
auto source = handle->owner();
|
|
202
|
+
if (source->kind != 1 && source->kind != 3) return Nan::ThrowTypeError("Expected Music");
|
|
203
|
+
auto state = CreateWorkerState(0, frames, channels, rate, slots);
|
|
204
|
+
state->music = true;
|
|
205
|
+
state->sampleCount = count;
|
|
206
|
+
state->loopLength = count;
|
|
207
|
+
const bool looping = source->AsStream()->isLooping();
|
|
208
|
+
auto sound = std::make_unique<WorkerStream>(state, map);
|
|
209
|
+
CopySourceSettings(*sound, *source->sound);
|
|
210
|
+
sound->setLooping(looping);
|
|
211
|
+
state->looping = looping;
|
|
212
|
+
source->sound->stop();
|
|
213
|
+
source->sound = std::move(sound);
|
|
214
|
+
source->encoded = {};
|
|
215
|
+
source->kind = 3;
|
|
216
|
+
source->stream = state;
|
|
217
|
+
InstallSourceEffect(source);
|
|
218
|
+
auto result = Nan::New<v8::Object>();
|
|
219
|
+
Set(result, "handle", AudioWorkerHandle::Create(state));
|
|
220
|
+
Set(result, "token", RegisterWorker(state));
|
|
221
|
+
info.GetReturnValue().Set(result);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
NAN_METHOD(AttachAudioWorker) {
|
|
225
|
+
if (!info[0]->IsBigInt()) return Nan::ThrowTypeError("Expected an audio worker token");
|
|
226
|
+
const auto token = info[0].As<v8::BigInt>()->Uint64Value();
|
|
227
|
+
std::shared_ptr<AudioWorkerState> state;
|
|
228
|
+
{
|
|
229
|
+
std::lock_guard lock(registryMutex);
|
|
230
|
+
const auto found = registry.find(token);
|
|
231
|
+
if (found != registry.end()) { state = found->second.lock(); registry.erase(found); }
|
|
232
|
+
}
|
|
233
|
+
if (!state) return Nan::ThrowError("Audio worker token has expired or was already used");
|
|
234
|
+
info.GetReturnValue().Set(MapWorker(state));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
NAN_METHOD(PollAudioWorker) {
|
|
238
|
+
auto* handle = AudioWorkerHandle::From(info[0]);
|
|
239
|
+
if (!handle) return;
|
|
240
|
+
auto& state = *handle->owner();
|
|
241
|
+
if (state.closed.load(std::memory_order_acquire)) {
|
|
242
|
+
info.GetReturnValue().Set(-3); return;
|
|
243
|
+
}
|
|
244
|
+
if (state.kind == 1 && state.finish.load(std::memory_order_acquire)) {
|
|
245
|
+
info.GetReturnValue().Set(state.running.load(std::memory_order_acquire) ? -1 : -3);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (state.leased) return Nan::ThrowError("Previous audio block is still leased");
|
|
249
|
+
auto& f = state.fields;
|
|
250
|
+
if (state.kind == 0) {
|
|
251
|
+
const auto sequence = state.seekSequence.load(std::memory_order_acquire);
|
|
252
|
+
const auto generation = state.generation.load(std::memory_order_acquire);
|
|
253
|
+
if (sequence & 1) { info.GetReturnValue().Set(-1); return; }
|
|
254
|
+
if (state.workerGeneration != generation) {
|
|
255
|
+
const auto offset = state.seek.load(std::memory_order_relaxed);
|
|
256
|
+
const auto sample = state.seekSample.load(std::memory_order_relaxed);
|
|
257
|
+
if (state.seekSequence.load(std::memory_order_acquire) != sequence) {
|
|
258
|
+
info.GetReturnValue().Set(-1); return;
|
|
259
|
+
}
|
|
260
|
+
state.workerGeneration = generation;
|
|
261
|
+
state.workerEof = false;
|
|
262
|
+
state.time[0] = offset;
|
|
263
|
+
state.time[5] = sample;
|
|
264
|
+
info.GetReturnValue().Set(-2); return;
|
|
265
|
+
}
|
|
266
|
+
if (state.workerEof || !state.input.Write()) {
|
|
267
|
+
info.GetReturnValue().Set(-1); return;
|
|
268
|
+
}
|
|
269
|
+
f[0] = static_cast<int>(state.input.tail % state.input.blocks.size());
|
|
270
|
+
f[2] = state.frames * state.channels;
|
|
271
|
+
f[3] = 1;
|
|
272
|
+
f[4] = state.looping.load(std::memory_order_acquire);
|
|
273
|
+
state.time[1] = 0;
|
|
274
|
+
state.time[2] = static_cast<std::int64_t>(state.sampleCount);
|
|
275
|
+
state.time[3] = static_cast<std::int64_t>(state.loopOffset.load(std::memory_order_acquire));
|
|
276
|
+
state.time[4] = static_cast<std::int64_t>(state.loopLength.load(std::memory_order_acquire));
|
|
277
|
+
} else {
|
|
278
|
+
auto* input = state.input.Read();
|
|
279
|
+
while (input && state.kind == 2 &&
|
|
280
|
+
input->generation != state.generation.load(std::memory_order_acquire)) {
|
|
281
|
+
state.input.Release();
|
|
282
|
+
state.pending.fetch_sub(1, std::memory_order_release);
|
|
283
|
+
state.workerOffset = 0;
|
|
284
|
+
input = state.input.Read();
|
|
285
|
+
}
|
|
286
|
+
if (!input && state.kind == 1 &&
|
|
287
|
+
!state.running.load(std::memory_order_acquire)) {
|
|
288
|
+
info.GetReturnValue().Set(-3); return;
|
|
289
|
+
}
|
|
290
|
+
if (!input || (state.kind == 2 && !state.output.Write())) {
|
|
291
|
+
info.GetReturnValue().Set(-1); return;
|
|
292
|
+
}
|
|
293
|
+
f[0] = static_cast<int>(state.input.head % state.input.blocks.size());
|
|
294
|
+
f[1] = static_cast<int>(state.output.tail % state.output.blocks.size());
|
|
295
|
+
f[2] = input->count - state.workerOffset;
|
|
296
|
+
f[3] = input->channels;
|
|
297
|
+
f[4] = state.workerOffset;
|
|
298
|
+
f[5] = input->tail;
|
|
299
|
+
f[6] = state.frames;
|
|
300
|
+
f[7] = state.kind == 2 ? f[2] / f[3] : f[2];
|
|
301
|
+
}
|
|
302
|
+
state.leased = true;
|
|
303
|
+
info.GetReturnValue().Set(0);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
NAN_METHOD(CommitAudioWorker) {
|
|
307
|
+
auto* handle = AudioWorkerHandle::From(info[0]);
|
|
308
|
+
if (!handle) return;
|
|
309
|
+
auto& state = *handle->owner();
|
|
310
|
+
if (!state.leased) return Nan::ThrowError("No leased audio block");
|
|
311
|
+
auto& f = state.fields;
|
|
312
|
+
if (state.kind == 0) {
|
|
313
|
+
if (f[2] < 0 || static_cast<unsigned>(f[2]) > state.frames * state.channels ||
|
|
314
|
+
f[2] % state.channels || (f[2] == 0 && f[3])) {
|
|
315
|
+
return Nan::ThrowRangeError("Invalid stream sample count");
|
|
316
|
+
}
|
|
317
|
+
auto* block = state.input.Write();
|
|
318
|
+
block->count = f[2];
|
|
319
|
+
block->more = f[3] != 0;
|
|
320
|
+
block->generation = state.workerGeneration;
|
|
321
|
+
block->loop = state.time[1];
|
|
322
|
+
state.workerEof = !block->more;
|
|
323
|
+
state.input.Publish();
|
|
324
|
+
} else if (state.kind == 1) {
|
|
325
|
+
state.processed.fetch_add(state.input.Read()->count, std::memory_order_relaxed);
|
|
326
|
+
state.input.Release();
|
|
327
|
+
if (!info[1]->IsTrue()) state.finish.store(true, std::memory_order_release);
|
|
328
|
+
} else {
|
|
329
|
+
auto* input = state.input.Read();
|
|
330
|
+
if (f[6] < 0 || static_cast<unsigned>(f[6]) > state.frames || f[7] < 0 ||
|
|
331
|
+
static_cast<unsigned>(f[7]) > (input->count - state.workerOffset) / input->channels ||
|
|
332
|
+
(f[6] == 0 && f[7] == 0 && !input->tail)) {
|
|
333
|
+
return Nan::ThrowRangeError("Invalid effect frame counts or no progress");
|
|
334
|
+
}
|
|
335
|
+
if (f[6]) {
|
|
336
|
+
auto* output = state.output.Write();
|
|
337
|
+
output->count = f[6] * input->channels;
|
|
338
|
+
output->channels = input->channels;
|
|
339
|
+
output->generation = input->generation;
|
|
340
|
+
state.output.Publish();
|
|
341
|
+
}
|
|
342
|
+
state.workerOffset += f[7] * input->channels;
|
|
343
|
+
state.processed.fetch_add(f[7], std::memory_order_relaxed);
|
|
344
|
+
if (input->tail || state.workerOffset == input->count) {
|
|
345
|
+
if (input->tail && input->generation ==
|
|
346
|
+
state.generation.load(std::memory_order_acquire)) {
|
|
347
|
+
state.tailDone.store(f[6] == 0, std::memory_order_release);
|
|
348
|
+
}
|
|
349
|
+
state.input.Release();
|
|
350
|
+
state.pending.fetch_sub(1, std::memory_order_release);
|
|
351
|
+
state.workerOffset = 0;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
state.leased = false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
NAN_METHOD(CloseAudioWorker) {
|
|
358
|
+
auto* handle = AudioWorkerHandle::From(info[0]);
|
|
359
|
+
if (handle) handle->owner()->closed.store(true, std::memory_order_release);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
NAN_METHOD(AudioWorkerStats) {
|
|
363
|
+
auto* handle = AudioWorkerHandle::From(info[0]);
|
|
364
|
+
if (!handle) return;
|
|
365
|
+
auto state = handle->owner();
|
|
366
|
+
auto values = std::make_shared<std::array<std::uint64_t, 3>>();
|
|
367
|
+
*values = {state->underruns.load(std::memory_order_relaxed),
|
|
368
|
+
state->overruns.load(std::memory_order_relaxed),
|
|
369
|
+
state->processed.load(std::memory_order_relaxed)};
|
|
370
|
+
info.GetReturnValue().Set(MapShared(info.GetIsolate(), values,
|
|
371
|
+
values->data(), sizeof(*values)));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
NAN_METHOD(CreateAudioEffect) {
|
|
375
|
+
unsigned frames, channels, slots;
|
|
376
|
+
if (!Unsigned(info[0], frames) || !Unsigned(info[1], channels) ||
|
|
377
|
+
!Unsigned(info[2], slots)) return;
|
|
378
|
+
auto state = CreateWorkerState(2, frames, channels, 1, slots);
|
|
379
|
+
auto result = Nan::New<v8::Object>();
|
|
380
|
+
Set(result, "handle", AudioWorkerHandle::Create(state));
|
|
381
|
+
Set(result, "token", RegisterWorker(state));
|
|
382
|
+
info.GetReturnValue().Set(result);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
NAN_METHOD(SetAudioEffect) {
|
|
386
|
+
auto* source = SourceHandle::From(info[0]);
|
|
387
|
+
if (!source) return;
|
|
388
|
+
auto change = [&](auto action) {
|
|
389
|
+
auto& owner = *source->owner();
|
|
390
|
+
const auto status = owner.sound->getStatus();
|
|
391
|
+
const auto offset = owner.AsSound() ? owner.AsSound()->getPlayingOffset()
|
|
392
|
+
: owner.AsStream()->getPlayingOffset();
|
|
393
|
+
owner.sound->stop();
|
|
394
|
+
action();
|
|
395
|
+
if (owner.AsSound()) owner.AsSound()->setPlayingOffset(offset);
|
|
396
|
+
else owner.AsStream()->setPlayingOffset(offset);
|
|
397
|
+
if (status != sf::SoundSource::Status::Stopped) owner.sound->play();
|
|
398
|
+
if (status == sf::SoundSource::Status::Paused) owner.sound->pause();
|
|
399
|
+
};
|
|
400
|
+
if (info[1]->IsNullOrUndefined()) {
|
|
401
|
+
change([&] { source->owner()->sound->setEffectProcessor({}); });
|
|
402
|
+
if (source->owner()->effect) {
|
|
403
|
+
source->owner()->effect->attached.store(nullptr, std::memory_order_release);
|
|
404
|
+
source->owner()->effect.reset();
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
auto* handle = AudioWorkerHandle::From(info[1]);
|
|
409
|
+
if (!handle) return;
|
|
410
|
+
auto state = handle->owner();
|
|
411
|
+
if (state->kind != 2) return Nan::ThrowTypeError("Expected an effect processor");
|
|
412
|
+
if (state->closed.load(std::memory_order_acquire)) {
|
|
413
|
+
return Nan::ThrowError("Effect processor is closed");
|
|
414
|
+
}
|
|
415
|
+
if (source->owner()->effect == state) return;
|
|
416
|
+
Source* expected = nullptr;
|
|
417
|
+
if (!state->attached.compare_exchange_strong(expected, source->owner().get())) {
|
|
418
|
+
return Nan::ThrowError("An effect processor can be attached to one source");
|
|
419
|
+
}
|
|
420
|
+
change([&] {
|
|
421
|
+
if (source->owner()->effect) {
|
|
422
|
+
source->owner()->effect->attached.store(nullptr, std::memory_order_release);
|
|
423
|
+
}
|
|
424
|
+
source->owner()->effect = state;
|
|
425
|
+
state->Seek(0);
|
|
426
|
+
source->owner()->sound->setEffectProcessor(
|
|
427
|
+
[state](const float* in, unsigned& inFrames, float* out,
|
|
428
|
+
unsigned& outFrames, unsigned channels) {
|
|
429
|
+
state->Effect(in, inFrames, out, outFrames, channels);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
} // namespace sfmljs::audio
|
|
435
|
+
|
|
436
|
+
NAN_MODULE_INIT(InitializeAudioWorkers) {
|
|
437
|
+
using namespace sfmljs::audio;
|
|
438
|
+
sfmljs::SetMethod<CreateAudioStream>(target, "createAudioStream");
|
|
439
|
+
sfmljs::SetMethod<OpenAudioMusicStream>(target, "openAudioMusicStream");
|
|
440
|
+
sfmljs::SetMethod<AttachAudioWorker>(target, "attachAudioWorker");
|
|
441
|
+
sfmljs::SetMethod<PollAudioWorker>(target, "pollAudioWorker");
|
|
442
|
+
sfmljs::SetMethod<CommitAudioWorker>(target, "commitAudioWorker");
|
|
443
|
+
sfmljs::SetMethod<CloseAudioWorker>(target, "closeAudioWorker");
|
|
444
|
+
sfmljs::SetMethod<AudioWorkerStats>(target, "audioWorkerStats");
|
|
445
|
+
sfmljs::SetMethod<CreateAudioEffect>(target, "createAudioEffect");
|
|
446
|
+
sfmljs::SetMethod<SetAudioEffect>(target, "setAudioEffect");
|
|
447
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "audio-state.h"
|
|
4
|
+
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
|
|
8
|
+
namespace sfmljs::audio {
|
|
9
|
+
|
|
10
|
+
// The producer owns an empty slot and the consumer owns a published slot.
|
|
11
|
+
// Only publication/release cross threads. Samples and descriptors stay native.
|
|
12
|
+
struct AudioBlock {
|
|
13
|
+
std::vector<std::int16_t> pcm;
|
|
14
|
+
std::vector<float> floats;
|
|
15
|
+
std::atomic<bool> ready{false};
|
|
16
|
+
unsigned count{};
|
|
17
|
+
unsigned channels{};
|
|
18
|
+
std::uint64_t generation{};
|
|
19
|
+
bool more{true};
|
|
20
|
+
bool tail{};
|
|
21
|
+
std::int64_t loop{};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
struct AudioPipe {
|
|
25
|
+
std::vector<std::unique_ptr<AudioBlock>> blocks;
|
|
26
|
+
std::size_t head{}; // consumer only
|
|
27
|
+
std::size_t tail{}; // producer only
|
|
28
|
+
AudioPipe(unsigned slots, unsigned samples, bool floating) {
|
|
29
|
+
for (unsigned i = 0; i < slots; ++i) {
|
|
30
|
+
auto block = std::make_unique<AudioBlock>();
|
|
31
|
+
if (floating) block->floats.resize(samples);
|
|
32
|
+
else block->pcm.resize(samples);
|
|
33
|
+
blocks.push_back(std::move(block));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
AudioBlock* Write() {
|
|
37
|
+
auto* block = blocks[tail % blocks.size()].get();
|
|
38
|
+
return block->ready.load(std::memory_order_acquire) ? nullptr : block;
|
|
39
|
+
}
|
|
40
|
+
void Publish() {
|
|
41
|
+
blocks[tail++ % blocks.size()]->ready.store(true, std::memory_order_release);
|
|
42
|
+
}
|
|
43
|
+
AudioBlock* Read() {
|
|
44
|
+
auto* block = blocks[head % blocks.size()].get();
|
|
45
|
+
return block->ready.load(std::memory_order_acquire) ? block : nullptr;
|
|
46
|
+
}
|
|
47
|
+
void Release() {
|
|
48
|
+
blocks[head++ % blocks.size()]->ready.store(false, std::memory_order_release);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
struct AudioWorkerState {
|
|
53
|
+
// 0: stream, 1: capture, 2: effect.
|
|
54
|
+
const unsigned kind;
|
|
55
|
+
const unsigned frames;
|
|
56
|
+
const unsigned channels;
|
|
57
|
+
const unsigned rate;
|
|
58
|
+
AudioPipe input;
|
|
59
|
+
AudioPipe output;
|
|
60
|
+
std::vector<std::int16_t> silence;
|
|
61
|
+
std::atomic<bool> closed{false};
|
|
62
|
+
std::atomic<bool> running{false};
|
|
63
|
+
std::atomic<bool> finish{false};
|
|
64
|
+
std::atomic<bool> tailDone{false};
|
|
65
|
+
std::atomic<unsigned> pending{};
|
|
66
|
+
std::atomic<Source*> attached{};
|
|
67
|
+
bool music{};
|
|
68
|
+
std::uint64_t sampleCount{};
|
|
69
|
+
std::atomic<std::uint64_t> loopOffset{};
|
|
70
|
+
std::atomic<std::uint64_t> loopLength{};
|
|
71
|
+
std::atomic<bool> looping{};
|
|
72
|
+
std::atomic<std::uint64_t> generation{1};
|
|
73
|
+
// Stream-only publication sequence: odd while the two seek units are updated.
|
|
74
|
+
std::atomic<std::uint64_t> seekSequence{};
|
|
75
|
+
std::atomic<std::int64_t> seek{};
|
|
76
|
+
// Exact interleaved sample position for loop seeks; -1 for explicit times.
|
|
77
|
+
std::atomic<std::int64_t> seekSample{-1};
|
|
78
|
+
std::atomic<std::uint64_t> underruns{};
|
|
79
|
+
std::atomic<std::uint64_t> overruns{};
|
|
80
|
+
std::atomic<std::uint64_t> processed{};
|
|
81
|
+
// Used only on the attached Worker thread.
|
|
82
|
+
std::uint64_t workerGeneration{};
|
|
83
|
+
bool workerEof{};
|
|
84
|
+
bool leased{};
|
|
85
|
+
unsigned workerOffset{};
|
|
86
|
+
std::array<std::int32_t, 8> fields{};
|
|
87
|
+
std::array<std::int64_t, 6> time{};
|
|
88
|
+
// Used only on the SFML consumer thread.
|
|
89
|
+
bool streamLease{};
|
|
90
|
+
unsigned outputOffset{};
|
|
91
|
+
std::int64_t loop{};
|
|
92
|
+
|
|
93
|
+
AudioWorkerState(unsigned mode, unsigned blockFrames, unsigned channelCount,
|
|
94
|
+
unsigned sampleRate, unsigned slots)
|
|
95
|
+
: kind(mode), frames(blockFrames), channels(channelCount), rate(sampleRate),
|
|
96
|
+
input(slots, blockFrames * channelCount, mode == 2),
|
|
97
|
+
output(slots, blockFrames * channelCount, mode == 2),
|
|
98
|
+
silence(mode == 0 ? blockFrames * channelCount : 0) {}
|
|
99
|
+
void Seek(std::int64_t offset, std::int64_t sample = -1) {
|
|
100
|
+
// SFML serializes a stream's seek callbacks. Publish both units together.
|
|
101
|
+
if (kind == 0) seekSequence.fetch_add(1, std::memory_order_acq_rel);
|
|
102
|
+
seek.store(offset, std::memory_order_relaxed);
|
|
103
|
+
if (kind == 0) seekSample.store(sample, std::memory_order_relaxed);
|
|
104
|
+
generation.fetch_add(1, std::memory_order_release);
|
|
105
|
+
if (kind == 0) seekSequence.fetch_add(1, std::memory_order_release);
|
|
106
|
+
}
|
|
107
|
+
bool Stream(sf::SoundStream::Chunk& chunk);
|
|
108
|
+
void Capture(const std::int16_t* samples, std::size_t count);
|
|
109
|
+
void Effect(const float* in, unsigned& inFrames, float* out,
|
|
110
|
+
unsigned& outFrames, unsigned channelCount);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
using AudioWorkerHandle = SharedHandle<AudioWorkerState>;
|
|
114
|
+
|
|
115
|
+
std::shared_ptr<AudioWorkerState> CreateWorkerState(
|
|
116
|
+
unsigned kind, unsigned frames, unsigned channels, unsigned rate,
|
|
117
|
+
unsigned slots);
|
|
118
|
+
v8::Local<v8::Object> MapWorker(const std::shared_ptr<AudioWorkerState>& state);
|
|
119
|
+
v8::Local<v8::Value> RegisterWorker(const std::shared_ptr<AudioWorkerState>& state);
|
|
120
|
+
|
|
121
|
+
} // namespace sfmljs::audio
|