sfml.js 0.0.1 → 1.0.0-rc.1
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.md +24 -16
- package/binding.gyp +95 -183
- package/dist/audio/effect-processor.d.ts +22 -0
- package/dist/audio/effect-processor.js +28 -0
- package/dist/audio/input-sound-file.d.ts +52 -0
- package/dist/audio/input-sound-file.js +167 -0
- package/dist/audio/listener.d.ts +28 -0
- package/dist/audio/listener.js +86 -0
- package/dist/audio/music.d.ts +60 -0
- package/dist/audio/music.js +192 -0
- package/dist/audio/output-sound-file.d.ts +15 -0
- package/dist/audio/output-sound-file.js +70 -0
- package/dist/audio/playback-device.d.ts +35 -0
- package/dist/audio/playback-device.js +71 -0
- package/dist/audio/sound-buffer-recorder.d.ts +34 -0
- package/dist/audio/sound-buffer-recorder.js +62 -0
- package/dist/audio/sound-buffer.d.ts +45 -0
- package/dist/audio/sound-buffer.js +152 -0
- package/dist/audio/sound-file-factory.d.ts +27 -0
- package/dist/audio/sound-file-factory.js +152 -0
- package/dist/audio/sound-file-reader.d.ts +60 -0
- package/dist/audio/sound-file-reader.js +61 -0
- package/dist/audio/sound-file-writer.d.ts +17 -0
- package/dist/audio/sound-file-writer.js +9 -0
- package/dist/audio/sound-recorder.d.ts +60 -0
- package/dist/audio/sound-recorder.js +162 -0
- package/dist/audio/sound-source.d.ts +108 -0
- package/dist/audio/sound-source.js +161 -0
- package/dist/audio/sound-stream.d.ts +28 -0
- package/dist/audio/sound-stream.js +47 -0
- package/dist/audio/sound.d.ts +14 -0
- package/dist/audio/sound.js +39 -0
- package/dist/audio/value.d.ts +116 -0
- package/dist/audio/value.js +157 -0
- package/dist/audio/worker.d.ts +88 -0
- package/dist/audio/worker.js +2 -0
- package/dist/graphics/blend-mode.d.ts +82 -0
- package/dist/graphics/blend-mode.js +98 -0
- package/dist/graphics/boolean-vector.d.ts +48 -0
- package/dist/graphics/boolean-vector.js +116 -0
- package/dist/graphics/circle-shape.d.ts +27 -0
- package/dist/graphics/circle-shape.js +41 -0
- package/dist/graphics/color.d.ts +93 -0
- package/dist/graphics/color.js +146 -0
- package/dist/graphics/convex-shape.d.ts +18 -0
- package/dist/graphics/convex-shape.js +33 -0
- package/dist/graphics/drawable.d.ts +9 -0
- package/dist/graphics/drawable.js +15 -0
- package/dist/graphics/font.d.ts +70 -0
- package/dist/graphics/font.js +221 -0
- package/dist/graphics/glsl-matrix.d.ts +25 -0
- package/dist/graphics/glsl-matrix.js +69 -0
- package/dist/graphics/glsl.d.ts +57 -0
- package/dist/graphics/glsl.js +112 -0
- package/dist/graphics/glyph.d.ts +44 -0
- package/dist/graphics/glyph.js +74 -0
- package/dist/graphics/image.d.ts +57 -0
- package/dist/graphics/image.js +181 -0
- package/dist/graphics/primitive-type.d.ts +16 -0
- package/dist/graphics/primitive-type.js +25 -0
- package/dist/graphics/rect.d.ts +67 -0
- package/dist/graphics/rect.js +164 -0
- package/dist/graphics/rectangle-shape.d.ts +18 -0
- package/dist/graphics/rectangle-shape.js +34 -0
- package/dist/graphics/render-states.d.ts +60 -0
- package/dist/graphics/render-states.js +74 -0
- package/dist/graphics/render-target.d.ts +99 -0
- package/dist/graphics/render-target.js +341 -0
- package/dist/graphics/render-texture.d.ts +46 -0
- package/dist/graphics/render-texture.js +120 -0
- package/dist/graphics/render-window.d.ts +49 -0
- package/dist/graphics/render-window.js +106 -0
- package/dist/graphics/shader.d.ts +63 -0
- package/dist/graphics/shader.js +215 -0
- package/dist/graphics/shape.d.ts +77 -0
- package/dist/graphics/shape.js +180 -0
- package/dist/graphics/sprite.d.ts +44 -0
- package/dist/graphics/sprite.js +116 -0
- package/dist/graphics/stencil-mode.d.ts +69 -0
- package/dist/graphics/stencil-mode.js +72 -0
- package/dist/graphics/swap.d.ts +6 -0
- package/dist/graphics/swap.js +16 -0
- package/dist/graphics/text.d.ts +238 -0
- package/dist/graphics/text.js +354 -0
- package/dist/graphics/texture.d.ts +78 -0
- package/dist/graphics/texture.js +274 -0
- package/dist/graphics/transform.d.ts +50 -0
- package/dist/graphics/transform.js +195 -0
- package/dist/graphics/transformable.d.ts +13 -0
- package/dist/graphics/transformable.js +27 -0
- package/dist/graphics/vertex-array.d.ts +54 -0
- package/dist/graphics/vertex-array.js +176 -0
- package/dist/graphics/vertex-buffer.d.ts +69 -0
- package/dist/graphics/vertex-buffer.js +167 -0
- package/dist/graphics/vertex.d.ts +42 -0
- package/dist/graphics/vertex.js +98 -0
- package/dist/graphics/view.d.ts +54 -0
- package/dist/graphics/view.js +209 -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 +26 -0
- package/dist/internal/glsl-value.js +44 -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 +44 -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 +53 -0
- package/dist/internal/transformable.js +121 -0
- package/dist/internal/value-storage.d.ts +26 -0
- package/dist/internal/value-storage.js +21 -0
- package/dist/network/common.d.ts +18 -0
- package/dist/network/common.js +73 -0
- package/dist/network/dns.d.ts +35 -0
- package/dist/network/dns.js +93 -0
- package/dist/network/ftp.d.ts +81 -0
- package/dist/network/ftp.js +233 -0
- package/dist/network/gen/constants.d.ts +252 -0
- package/dist/network/gen/constants.js +260 -0
- package/dist/network/http.d.ts +150 -0
- package/dist/network/http.js +424 -0
- package/dist/network/ip-address.d.ts +57 -0
- package/dist/network/ip-address.js +161 -0
- package/dist/network/packet.d.ts +78 -0
- package/dist/network/packet.js +238 -0
- package/dist/network/sftp.d.ts +220 -0
- package/dist/network/sftp.js +557 -0
- package/dist/network/socket-selector.d.ts +38 -0
- package/dist/network/socket-selector.js +125 -0
- package/dist/network/socket.d.ts +89 -0
- package/dist/network/socket.js +225 -0
- package/dist/network/tcp-listener.d.ts +36 -0
- package/dist/network/tcp-listener.js +126 -0
- package/dist/network/tcp-socket.d.ts +108 -0
- package/dist/network/tcp-socket.js +362 -0
- package/dist/network/tls-material.d.ts +6 -0
- package/dist/network/tls-material.js +36 -0
- package/dist/network/udp-socket.d.ts +60 -0
- package/dist/network/udp-socket.js +197 -0
- package/dist/system/angle.d.ts +27 -0
- package/dist/system/angle.js +72 -0
- package/dist/system/clock.d.ts +22 -0
- package/dist/system/clock.js +56 -0
- package/dist/system/err.d.ts +6 -0
- package/dist/system/err.js +49 -0
- package/dist/system/error.d.ts +5 -0
- package/dist/system/error.js +12 -0
- package/dist/system/file-input-stream.d.ts +21 -0
- package/dist/system/file-input-stream.js +101 -0
- package/dist/system/input-stream.d.ts +30 -0
- package/dist/system/input-stream.js +54 -0
- package/dist/system/operators.d.ts +164 -0
- package/dist/system/operators.js +402 -0
- package/dist/system/sleep.d.ts +4 -0
- package/dist/system/sleep.js +23 -0
- package/dist/system/suspend-aware-clock.d.ts +7 -0
- package/dist/system/suspend-aware-clock.js +14 -0
- package/dist/system/time.d.ts +31 -0
- package/dist/system/time.js +134 -0
- package/dist/system/timeout-with-predicate.d.ts +19 -0
- package/dist/system/timeout-with-predicate.js +35 -0
- package/dist/system/unicode.d.ts +18 -0
- package/dist/system/unicode.js +31 -0
- package/dist/system/vector2.d.ts +98 -0
- package/dist/system/vector2.js +225 -0
- package/dist/system/vector3.d.ts +83 -0
- package/dist/system/vector3.js +178 -0
- package/dist/system/version.d.ts +15 -0
- package/dist/system/version.js +18 -0
- package/dist/window/clipboard.d.ts +4 -0
- package/dist/window/clipboard.js +16 -0
- package/dist/window/context-settings.d.ts +29 -0
- package/dist/window/context-settings.js +59 -0
- package/dist/window/context.d.ts +27 -0
- package/dist/window/context.js +77 -0
- package/dist/window/cursor.d.ts +20 -0
- package/dist/window/cursor.js +56 -0
- package/dist/window/event.d.ts +176 -0
- package/dist/window/event.js +57 -0
- package/dist/window/gen/constants.d.ts +637 -0
- package/dist/window/gen/constants.js +651 -0
- package/dist/window/joystick.d.ts +25 -0
- package/dist/window/joystick.js +44 -0
- package/dist/window/keyboard.d.ts +14 -0
- package/dist/window/keyboard.js +37 -0
- package/dist/window/mouse.d.ts +10 -0
- package/dist/window/mouse.js +36 -0
- package/dist/window/sensor.d.ts +9 -0
- package/dist/window/sensor.js +23 -0
- package/dist/window/touch.d.ts +12 -0
- package/dist/window/touch.js +29 -0
- package/dist/window/video-mode.d.ts +26 -0
- package/dist/window/video-mode.js +69 -0
- package/dist/window/vulkan.d.ts +9 -0
- package/dist/window/vulkan.js +22 -0
- package/dist/window/window.d.ts +103 -0
- package/dist/window/window.js +227 -0
- package/docs/api.md +1113 -0
- package/docs/audio.md +212 -0
- package/docs/development.md +77 -0
- package/docs/network.md +169 -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 +77 -35
- package/src/audio/effect-processor.ts +41 -0
- package/src/audio/input-sound-file.ts +173 -0
- package/src/audio/listener.ts +74 -0
- package/src/audio/music.ts +191 -0
- package/src/audio/output-sound-file.ts +64 -0
- package/src/audio/playback-device.ts +59 -0
- package/src/audio/sound-buffer-recorder.ts +61 -0
- package/src/audio/sound-buffer.ts +170 -0
- package/src/audio/sound-file-factory.ts +162 -0
- package/src/audio/sound-file-reader.ts +93 -0
- package/src/audio/sound-file-writer.ts +19 -0
- package/src/audio/sound-recorder.ts +180 -0
- package/src/audio/sound-source.ts +168 -0
- package/src/audio/sound-stream.ts +60 -0
- package/src/audio/sound.ts +36 -0
- package/src/audio/value.ts +165 -0
- package/src/audio/worker.ts +90 -0
- package/src/graphics/blend-mode.ts +125 -0
- package/src/graphics/boolean-vector.ts +139 -0
- package/src/graphics/circle-shape.ts +56 -0
- package/src/graphics/color.ts +189 -0
- package/src/graphics/convex-shape.ts +38 -0
- package/src/graphics/drawable.ts +19 -0
- package/src/graphics/font.ts +248 -0
- package/src/graphics/glsl-matrix.ts +73 -0
- package/src/graphics/glsl.ts +121 -0
- package/src/graphics/glyph.ts +97 -0
- package/src/graphics/image.ts +231 -0
- package/src/graphics/primitive-type.ts +21 -0
- package/src/graphics/rect.ts +214 -0
- package/src/graphics/rectangle-shape.ts +39 -0
- package/src/graphics/render-states.ts +110 -0
- package/src/graphics/render-target.ts +431 -0
- package/src/graphics/render-texture.ts +150 -0
- package/src/graphics/render-window.ts +155 -0
- package/src/graphics/shader.ts +224 -0
- package/src/graphics/shape.ts +231 -0
- package/src/graphics/sprite.ts +143 -0
- package/src/graphics/stencil-mode.ts +97 -0
- package/src/graphics/swap.ts +17 -0
- package/src/graphics/text.ts +423 -0
- package/src/graphics/texture.ts +352 -0
- package/src/graphics/transform.ts +242 -0
- package/src/graphics/transformable.ts +26 -0
- package/src/graphics/vertex-array.ts +201 -0
- package/src/graphics/vertex-buffer.ts +209 -0
- package/src/graphics/vertex.ts +142 -0
- package/src/graphics/view.ts +237 -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 +54 -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 +109 -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 +189 -0
- package/src/internal/value-storage.ts +33 -0
- package/src/network/common.ts +53 -0
- package/src/network/dns.ts +102 -0
- package/src/network/ftp.ts +202 -0
- package/src/network/gen/constants.ts +253 -0
- package/src/network/http.ts +372 -0
- package/src/network/ip-address.ts +158 -0
- package/src/network/packet.ts +217 -0
- package/src/network/sftp.ts +574 -0
- package/src/network/socket-selector.ts +112 -0
- package/src/network/socket.ts +203 -0
- package/src/network/tcp-listener.ts +115 -0
- package/src/network/tcp-socket.ts +370 -0
- package/src/network/tls-material.ts +30 -0
- package/src/network/udp-socket.ts +176 -0
- package/src/system/angle.ts +82 -0
- package/src/system/clock.ts +61 -0
- package/src/system/err.ts +46 -0
- package/src/system/error.ts +8 -0
- package/src/system/file-input-stream.ts +100 -0
- package/src/system/input-stream.ts +66 -0
- package/src/system/operators.ts +554 -0
- package/src/system/sleep.ts +20 -0
- package/src/system/suspend-aware-clock.ts +12 -0
- package/src/system/time.ts +149 -0
- package/src/system/timeout-with-predicate.ts +53 -0
- package/src/system/unicode.ts +28 -0
- package/src/system/vector2.ts +345 -0
- package/src/system/vector3.ts +267 -0
- package/src/system/version.ts +30 -0
- package/src/window/clipboard.ts +12 -0
- package/src/window/context-settings.ts +78 -0
- package/src/window/context.ts +92 -0
- package/src/window/cursor.ts +78 -0
- package/src/window/event.ts +227 -0
- package/src/window/gen/constants.ts +655 -0
- package/src/window/joystick.ts +52 -0
- package/src/window/keyboard.ts +42 -0
- package/src/window/mouse.ts +37 -0
- package/src/window/sensor.ts +20 -0
- package/src/window/touch.ts +27 -0
- package/src/window/video-mode.ts +85 -0
- package/src/window/vulkan.ts +19 -0
- package/src/window/window.ts +311 -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/generate-network-constants.cjs +47 -0
- package/tools/generate-window-constants.cjs +164 -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,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InputSoundFile = exports.cancelAudioInput = void 0;
|
|
4
|
+
const audio_native_1 = require("../internal/audio-native");
|
|
5
|
+
const time_1 = require("../system/time");
|
|
6
|
+
const audio_input_stream_1 = require("../internal/audio-input-stream");
|
|
7
|
+
const audio_codec_registry_1 = require("../internal/audio-codec-registry");
|
|
8
|
+
const sound_file_reader_1 = require("./sound-file-reader");
|
|
9
|
+
const value_1 = require("./value");
|
|
10
|
+
exports.cancelAudioInput = Symbol('Audio.cancelInput');
|
|
11
|
+
/** 可寻址音频解码器,按调用顺序异步读取交错 16 位 PCM。 */
|
|
12
|
+
class InputSoundFile {
|
|
13
|
+
/** 创建未打开数据源的解码器。 */
|
|
14
|
+
constructor() {
|
|
15
|
+
this.queue = new audio_native_1.AudioQueue();
|
|
16
|
+
const mapping = audio_native_1.audioNative.createAudioInput();
|
|
17
|
+
this[audio_native_1.audioHandle] = mapping.handle;
|
|
18
|
+
this.u64 = new BigUint64Array(mapping.buffer);
|
|
19
|
+
this.i64 = new BigInt64Array(mapping.buffer);
|
|
20
|
+
this.u32 = new Uint32Array(mapping.buffer);
|
|
21
|
+
this.channelMap = new Int32Array(mapping.channelMap);
|
|
22
|
+
}
|
|
23
|
+
/** 异步打开音频文件并读取格式信息,返回是否成功。 */
|
|
24
|
+
openFromFile(filename) { return this.open(filename); }
|
|
25
|
+
/** 异步打开编码音频字节,返回是否成功。 */
|
|
26
|
+
openFromMemory(data) { return this.open(data); }
|
|
27
|
+
/** 异步打开可寻址流,读取期间保留数据源引用。 */
|
|
28
|
+
openFromStream(stream) {
|
|
29
|
+
return this.open(stream);
|
|
30
|
+
}
|
|
31
|
+
/** 返回所有声道合计的样本总数。 */
|
|
32
|
+
getSampleCount() { return this.u64[0]; }
|
|
33
|
+
/** 返回当前样本偏移,包含所有交错声道。 */
|
|
34
|
+
getSampleOffset() { return this.u64[1]; }
|
|
35
|
+
/** 返回音频总时长。 */
|
|
36
|
+
getDuration() { return new time_1.Time(this.i64[2]); }
|
|
37
|
+
/** 返回当前解码位置对应的时间。 */
|
|
38
|
+
getTimeOffset() { return new time_1.Time(this.i64[3]); }
|
|
39
|
+
/** 返回每声道采样率,单位为 Hz。 */
|
|
40
|
+
getSampleRate() { return this.u32[10]; }
|
|
41
|
+
/** 返回声道数。 */
|
|
42
|
+
getChannelCount() { return this.u32[11]; }
|
|
43
|
+
/** 返回交错声道的位置映射。 */
|
|
44
|
+
getChannelMap() { return this.channelMap; }
|
|
45
|
+
/** @internal */
|
|
46
|
+
[exports.cancelAudioInput]() { this.stream?.close(); }
|
|
47
|
+
/** 异步解码到 data,返回实际写入的样本数;末尾返回 0n,完成前勿修改缓冲区。 */
|
|
48
|
+
read(data) {
|
|
49
|
+
(0, value_1.samples)(data);
|
|
50
|
+
return this.queue.run(async () => {
|
|
51
|
+
if (this.custom) {
|
|
52
|
+
const count = data.length ? await this.custom.reader.read(data) : 0n;
|
|
53
|
+
if (typeof count !== 'bigint' || count < 0n ||
|
|
54
|
+
count > BigInt(data.length)) {
|
|
55
|
+
throw new RangeError('Reader returned an invalid sample count');
|
|
56
|
+
}
|
|
57
|
+
audio_native_1.audioNative.updateAudioFileMetadata(this.customMetadata, 0, count);
|
|
58
|
+
return count;
|
|
59
|
+
}
|
|
60
|
+
await this.runStream(() => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.readAudioInput(this[audio_native_1.audioHandle], data, callback)));
|
|
61
|
+
return this.u64[4];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** 异步跳转到样本偏移(bigint,包含所有声道)或时间偏移(Time)。 */
|
|
65
|
+
seek(offset) {
|
|
66
|
+
const time = offset instanceof time_1.Time;
|
|
67
|
+
const value = time ? (0, value_1.duration)(offset) : offset;
|
|
68
|
+
if (typeof value !== 'bigint' || (!time && value < 0n)) {
|
|
69
|
+
throw new RangeError('Expected a non-negative sample offset or a Time');
|
|
70
|
+
}
|
|
71
|
+
return this.queue.run(async () => {
|
|
72
|
+
if (this.custom) {
|
|
73
|
+
audio_native_1.audioNative.updateAudioFileMetadata(this.customMetadata, time ? 2 : 1, value);
|
|
74
|
+
await this.custom.reader.seek(this.u64[4]);
|
|
75
|
+
audio_native_1.audioNative.updateAudioFileMetadata(this.customMetadata, 3);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
await this.runStream(() => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.seekAudioInput(this[audio_native_1.audioHandle], value, time, callback)));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** 等待此前操作并异步关闭解码器、释放其持有的数据源。 */
|
|
83
|
+
close() {
|
|
84
|
+
return this.queue.run(async () => {
|
|
85
|
+
this.map(await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.closeAudioInput(this[audio_native_1.audioHandle], callback)));
|
|
86
|
+
this.stream?.close();
|
|
87
|
+
this.stream = undefined;
|
|
88
|
+
await this.releaseCustom();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
map(mapping) {
|
|
92
|
+
this.u64 = new BigUint64Array(mapping.buffer);
|
|
93
|
+
this.i64 = new BigInt64Array(mapping.buffer);
|
|
94
|
+
this.u32 = new Uint32Array(mapping.buffer);
|
|
95
|
+
this.channelMap = new Int32Array(mapping.channelMap);
|
|
96
|
+
}
|
|
97
|
+
runStream(action) {
|
|
98
|
+
return this.stream ? this.stream.run(action) : action();
|
|
99
|
+
}
|
|
100
|
+
async releaseCustom() {
|
|
101
|
+
const custom = this.custom;
|
|
102
|
+
this.custom = undefined;
|
|
103
|
+
this.customMetadata = undefined;
|
|
104
|
+
try {
|
|
105
|
+
await custom?.reader.close();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await custom?.owned?.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
open(input) {
|
|
112
|
+
return this.queue.run(async () => {
|
|
113
|
+
const custom = await (0, audio_codec_registry_1.findAudioReaderInput)(input);
|
|
114
|
+
if (custom) {
|
|
115
|
+
let opened = false;
|
|
116
|
+
try {
|
|
117
|
+
const info = await custom.reader.open(custom.stream);
|
|
118
|
+
if (info === undefined)
|
|
119
|
+
return false;
|
|
120
|
+
if (!(info instanceof sound_file_reader_1.SoundFileReaderInfo)) {
|
|
121
|
+
throw new TypeError('Reader.open must return SoundFileReader.Info');
|
|
122
|
+
}
|
|
123
|
+
const mapping = audio_native_1.audioNative.createAudioFileMetadata(info[audio_native_1.audioHandle]);
|
|
124
|
+
await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.closeAudioInput(this[audio_native_1.audioHandle], callback));
|
|
125
|
+
await this.releaseCustom();
|
|
126
|
+
this.stream?.close();
|
|
127
|
+
this.stream = undefined;
|
|
128
|
+
this.map(mapping);
|
|
129
|
+
this.custom = custom;
|
|
130
|
+
this.customMetadata = mapping.handle;
|
|
131
|
+
opened = true;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
if (!opened) {
|
|
136
|
+
try {
|
|
137
|
+
await custom.reader.close();
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
await custom.owned?.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const stream = typeof input === 'string' || input instanceof Uint8Array
|
|
146
|
+
? undefined : new audio_input_stream_1.AudioInputStream(input);
|
|
147
|
+
let opened = false;
|
|
148
|
+
try {
|
|
149
|
+
const load = () => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.openAudioInput(this[audio_native_1.audioHandle], stream ? stream.handle : input, callback));
|
|
150
|
+
const mapping = await (stream ? stream.run(load) : load());
|
|
151
|
+
if (mapping) {
|
|
152
|
+
await this.releaseCustom();
|
|
153
|
+
this.map(mapping);
|
|
154
|
+
this.stream?.close();
|
|
155
|
+
this.stream = stream;
|
|
156
|
+
opened = true;
|
|
157
|
+
}
|
|
158
|
+
return opened;
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
if (!opened)
|
|
162
|
+
stream?.close();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.InputSoundFile = InputSoundFile;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Vector3f } from '../system/vector3';
|
|
2
|
+
import type { ReadonlyValue as R } from '../internal/value-storage';
|
|
3
|
+
import { Cone, type ConeInput } from './value';
|
|
4
|
+
export { Cone } from './value';
|
|
5
|
+
/** 设置所有声源的总音量百分比,0 静音、100 为原始音量。 */
|
|
6
|
+
export declare function setGlobalVolume(value: number): void;
|
|
7
|
+
/** 返回总音量百分比。 */
|
|
8
|
+
export declare function getGlobalVolume(): number;
|
|
9
|
+
/** 返回监听者的三维位置副本。 */
|
|
10
|
+
export declare function getPosition(): Vector3f;
|
|
11
|
+
/** 设置监听者的世界坐标位置。 */
|
|
12
|
+
export declare function setPosition(value: R<Vector3f>): void;
|
|
13
|
+
/** 返回监听者的朝向副本。 */
|
|
14
|
+
export declare function getDirection(): Vector3f;
|
|
15
|
+
/** 设置监听者的正前方方向。 */
|
|
16
|
+
export declare function setDirection(value: R<Vector3f>): void;
|
|
17
|
+
/** 返回监听者的速度副本。 */
|
|
18
|
+
export declare function getVelocity(): Vector3f;
|
|
19
|
+
/** 设置监听者的速度,用于多普勒效应,单位为位置单位/秒。 */
|
|
20
|
+
export declare function setVelocity(value: R<Vector3f>): void;
|
|
21
|
+
/** 返回监听者上方方向的副本。 */
|
|
22
|
+
export declare function getUpVector(): Vector3f;
|
|
23
|
+
/** 设置监听者上方方向,与正前方方向共同决定空间朝向。 */
|
|
24
|
+
export declare function setUpVector(value: R<Vector3f>): void;
|
|
25
|
+
/** 复制方向锥参数并更新原生监听者。 */
|
|
26
|
+
export declare function setCone(value: Readonly<ConeInput>): void;
|
|
27
|
+
/** 返回监听者方向锥参数副本。 */
|
|
28
|
+
export declare function getCone(): Cone;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCone = exports.setCone = exports.setUpVector = exports.getUpVector = exports.setVelocity = exports.getVelocity = exports.setDirection = exports.getDirection = exports.setPosition = exports.getPosition = exports.getGlobalVolume = exports.setGlobalVolume = exports.Cone = void 0;
|
|
4
|
+
const audio_native_1 = require("../internal/audio-native");
|
|
5
|
+
const vector3_1 = require("../system/vector3");
|
|
6
|
+
const angle_1 = require("../system/angle");
|
|
7
|
+
const value_1 = require("./value");
|
|
8
|
+
var value_2 = require("./value");
|
|
9
|
+
Object.defineProperty(exports, "Cone", { enumerable: true, get: function () { return value_2.Cone; } });
|
|
10
|
+
let state;
|
|
11
|
+
function listener() {
|
|
12
|
+
if (!state) {
|
|
13
|
+
const mapping = audio_native_1.audioNative.createAudioListener();
|
|
14
|
+
state = { handle: mapping.handle, values: new Float32Array(mapping.buffer) };
|
|
15
|
+
}
|
|
16
|
+
return state;
|
|
17
|
+
}
|
|
18
|
+
function getVector(field) {
|
|
19
|
+
const { handle, values } = listener();
|
|
20
|
+
audio_native_1.audioNative.audioListenerField(handle, field, false);
|
|
21
|
+
return new vector3_1.Vector3f(values[field], values[field + 1], values[field + 2]);
|
|
22
|
+
}
|
|
23
|
+
function setVector(field, value) {
|
|
24
|
+
(0, value_1.vector)(value);
|
|
25
|
+
const { handle, values } = listener();
|
|
26
|
+
values[field] = value.x;
|
|
27
|
+
values[field + 1] = value.y;
|
|
28
|
+
values[field + 2] = value.z;
|
|
29
|
+
audio_native_1.audioNative.audioListenerField(handle, field, true);
|
|
30
|
+
}
|
|
31
|
+
/** 设置所有声源的总音量百分比,0 静音、100 为原始音量。 */
|
|
32
|
+
function setGlobalVolume(value) {
|
|
33
|
+
const { handle, values } = listener();
|
|
34
|
+
values[0] = (0, value_1.float)(value);
|
|
35
|
+
audio_native_1.audioNative.audioListenerField(handle, 0, true);
|
|
36
|
+
}
|
|
37
|
+
exports.setGlobalVolume = setGlobalVolume;
|
|
38
|
+
/** 返回总音量百分比。 */
|
|
39
|
+
function getGlobalVolume() {
|
|
40
|
+
const { handle, values } = listener();
|
|
41
|
+
audio_native_1.audioNative.audioListenerField(handle, 0, false);
|
|
42
|
+
return values[0];
|
|
43
|
+
}
|
|
44
|
+
exports.getGlobalVolume = getGlobalVolume;
|
|
45
|
+
/** 返回监听者的三维位置副本。 */
|
|
46
|
+
function getPosition() { return getVector(1); }
|
|
47
|
+
exports.getPosition = getPosition;
|
|
48
|
+
/** 设置监听者的世界坐标位置。 */
|
|
49
|
+
function setPosition(value) { setVector(1, value); }
|
|
50
|
+
exports.setPosition = setPosition;
|
|
51
|
+
/** 返回监听者的朝向副本。 */
|
|
52
|
+
function getDirection() { return getVector(4); }
|
|
53
|
+
exports.getDirection = getDirection;
|
|
54
|
+
/** 设置监听者的正前方方向。 */
|
|
55
|
+
function setDirection(value) { setVector(4, value); }
|
|
56
|
+
exports.setDirection = setDirection;
|
|
57
|
+
/** 返回监听者的速度副本。 */
|
|
58
|
+
function getVelocity() { return getVector(7); }
|
|
59
|
+
exports.getVelocity = getVelocity;
|
|
60
|
+
/** 设置监听者的速度,用于多普勒效应,单位为位置单位/秒。 */
|
|
61
|
+
function setVelocity(value) { setVector(7, value); }
|
|
62
|
+
exports.setVelocity = setVelocity;
|
|
63
|
+
/** 返回监听者上方方向的副本。 */
|
|
64
|
+
function getUpVector() { return getVector(10); }
|
|
65
|
+
exports.getUpVector = getUpVector;
|
|
66
|
+
/** 设置监听者上方方向,与正前方方向共同决定空间朝向。 */
|
|
67
|
+
function setUpVector(value) { setVector(10, value); }
|
|
68
|
+
exports.setUpVector = setUpVector;
|
|
69
|
+
/** 复制方向锥参数并更新原生监听者。 */
|
|
70
|
+
function setCone(value) {
|
|
71
|
+
const inner = (0, value_1.angle)(value.innerAngle);
|
|
72
|
+
const outer = (0, value_1.angle)(value.outerAngle);
|
|
73
|
+
const gain = (0, value_1.float)(value.outerGain);
|
|
74
|
+
const { handle, values } = listener();
|
|
75
|
+
values.set([inner, outer, gain], 13);
|
|
76
|
+
audio_native_1.audioNative.audioListenerField(handle, 13, true);
|
|
77
|
+
}
|
|
78
|
+
exports.setCone = setCone;
|
|
79
|
+
/** 返回监听者方向锥参数副本。 */
|
|
80
|
+
function getCone() {
|
|
81
|
+
const { handle, values } = listener();
|
|
82
|
+
audio_native_1.audioNative.audioListenerField(handle, 13, false);
|
|
83
|
+
return new value_1.Cone({ innerAngle: (0, angle_1.radians)(values[13]), outerAngle: (0, angle_1.radians)(values[14]),
|
|
84
|
+
outerGain: values[15] });
|
|
85
|
+
}
|
|
86
|
+
exports.getCone = getCone;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SoundStream } from './sound-stream';
|
|
2
|
+
import { Time } from '../system/time';
|
|
3
|
+
import { TimeSpan, type TimeSpanInput } from './value';
|
|
4
|
+
import type { InputStream } from '../system/input-stream';
|
|
5
|
+
import type { AudioWorkerStats, SoundStreamChunk } from './worker';
|
|
6
|
+
/** 按块解码和播放长音频,无需一次将全部样本加载到内存。 */
|
|
7
|
+
export declare class Music extends SoundStream {
|
|
8
|
+
/** 循环区间的时间段类型。 */
|
|
9
|
+
static readonly TimeSpan: typeof TimeSpan;
|
|
10
|
+
/** 串行管理打开和关闭操作。 */
|
|
11
|
+
private readonly queue;
|
|
12
|
+
/** 当前文件解码与可选子类回调会话。 */
|
|
13
|
+
private pump?;
|
|
14
|
+
/** 关闭时递增,取消此前尚未安装的打开请求。 */
|
|
15
|
+
private closeGeneration;
|
|
16
|
+
/** 创建未打开内容的音乐播放源。 */
|
|
17
|
+
constructor();
|
|
18
|
+
/** 异步打开音频文件用于流式播放,返回是否成功;不会自动 play。 */
|
|
19
|
+
openFromFile(filename: string): Promise<boolean>;
|
|
20
|
+
/** 异步打开编码音频字节用于流式播放,返回是否成功。 */
|
|
21
|
+
openFromMemory(data: Uint8Array): Promise<boolean>;
|
|
22
|
+
/** 异步打开可寻址流,保留解码所需的数据源直到 close。 */
|
|
23
|
+
openFromStream(stream: InputStream): Promise<boolean>;
|
|
24
|
+
/** 返回流式解码泵最近的错误;未使用解码泵或无错误时为 undefined。 */
|
|
25
|
+
getWorkerError(): Error | undefined;
|
|
26
|
+
/** 返回流式解码队列统计;未使用解码泵时为 undefined。 */
|
|
27
|
+
getWorkerStats(): AudioWorkerStats | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 停止播放并异步关闭解码数据源。
|
|
30
|
+
* 在自身音频回调内调用时只请求关闭;实际清理于该回调结束后完成。
|
|
31
|
+
*/
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
/** 返回音乐总时长。 */
|
|
34
|
+
getDuration(): Time;
|
|
35
|
+
/** 返回循环区间副本,包含起点偏移和长度。 */
|
|
36
|
+
getLoopPoints(): TimeSpan;
|
|
37
|
+
/** 设置循环区间;启用循环需另行调用 setLooping(true)。 */
|
|
38
|
+
setLoopPoints(value: Readonly<TimeSpanInput>): void;
|
|
39
|
+
/**
|
|
40
|
+
* 在对象所属 JS 线程填充交错 16 位 PCM;await super 可读取当前文件。
|
|
41
|
+
* samples 指向原生可复用槽,仅在回调结束前有效;false 表示末块。
|
|
42
|
+
*/
|
|
43
|
+
protected onGetData(chunk: SoundStreamChunk): boolean | Promise<boolean>;
|
|
44
|
+
/** 在对象所属 JS 线程定位;await super 执行当前文件的默认定位。 */
|
|
45
|
+
protected onSeek(offset: Time): void | Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 在对象所属 JS 线程准备末块时调用,返回下一轮交错样本偏移。
|
|
48
|
+
* super 返回文件循环区间或 EOF 的位置;undefined 表示不循环。
|
|
49
|
+
* 实际定位由音频消费线程发起,再异步交给 onSeek。
|
|
50
|
+
*/
|
|
51
|
+
protected onLoop(): bigint | undefined | Promise<bigint | undefined>;
|
|
52
|
+
/** 获取当前回调所属的会话,避免 await 后误写新打开的音乐。 */
|
|
53
|
+
private callbackPump;
|
|
54
|
+
/** 仅在子类覆写回调时安装弱引用派发器,保留普通实例 Native 路径。 */
|
|
55
|
+
private createCallbacks;
|
|
56
|
+
/** 脱离当前会话并等待 Native 队列和文件清理。 */
|
|
57
|
+
private closePump;
|
|
58
|
+
/** 打开新文件;会话回调中拒绝重开,避免等待其自身的准备阶段。 */
|
|
59
|
+
private open;
|
|
60
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Music = void 0;
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
+
const audio_native_1 = require("../internal/audio-native");
|
|
6
|
+
const sound_stream_1 = require("./sound-stream");
|
|
7
|
+
const time_1 = require("../system/time");
|
|
8
|
+
const value_1 = require("./value");
|
|
9
|
+
const audio_codec_registry_1 = require("../internal/audio-codec-registry");
|
|
10
|
+
const audio_music_pump_1 = require("../internal/audio-music-pump");
|
|
11
|
+
const input_sound_file_1 = require("./input-sound-file");
|
|
12
|
+
/** 回调内的 super 始终访问发起该回调的会话。 */
|
|
13
|
+
const callbackContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
14
|
+
/** 回收 Music 时仅持有解码会话;会话回调只能弱引用 Music。 */
|
|
15
|
+
const pumpCleanup = new FinalizationRegistry(pump => {
|
|
16
|
+
void pump.close().catch(() => { });
|
|
17
|
+
});
|
|
18
|
+
/** 按块解码和播放长音频,无需一次将全部样本加载到内存。 */
|
|
19
|
+
class Music extends sound_stream_1.SoundStream {
|
|
20
|
+
/** 创建未打开内容的音乐播放源。 */
|
|
21
|
+
constructor() {
|
|
22
|
+
super(undefined, audio_native_1.audioNative.createAudioSource());
|
|
23
|
+
/** 串行管理打开和关闭操作。 */
|
|
24
|
+
this.queue = new audio_native_1.AudioQueue();
|
|
25
|
+
/** 关闭时递增,取消此前尚未安装的打开请求。 */
|
|
26
|
+
this.closeGeneration = 0;
|
|
27
|
+
}
|
|
28
|
+
/** 异步打开音频文件用于流式播放,返回是否成功;不会自动 play。 */
|
|
29
|
+
openFromFile(filename) { return this.open(filename); }
|
|
30
|
+
/** 异步打开编码音频字节用于流式播放,返回是否成功。 */
|
|
31
|
+
openFromMemory(data) { return this.open(data); }
|
|
32
|
+
/** 异步打开可寻址流,保留解码所需的数据源直到 close。 */
|
|
33
|
+
openFromStream(stream) {
|
|
34
|
+
return this.open(stream);
|
|
35
|
+
}
|
|
36
|
+
/** 返回流式解码泵最近的错误;未使用解码泵或无错误时为 undefined。 */
|
|
37
|
+
getWorkerError() { return this.pump?.error; }
|
|
38
|
+
/** 返回流式解码队列统计;未使用解码泵时为 undefined。 */
|
|
39
|
+
getWorkerStats() {
|
|
40
|
+
return this.pump?.getStats();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 停止播放并异步关闭解码数据源。
|
|
44
|
+
* 在自身音频回调内调用时只请求关闭;实际清理于该回调结束后完成。
|
|
45
|
+
*/
|
|
46
|
+
close() {
|
|
47
|
+
++this.closeGeneration;
|
|
48
|
+
const context = callbackContext.getStore();
|
|
49
|
+
const reentrant = context?.owner.deref() === this;
|
|
50
|
+
// 先终止供数,再排队等待清理,避免打开过程仍在等待首批数据。
|
|
51
|
+
this.pump?.requestClose();
|
|
52
|
+
if (reentrant && context.pump !== this.pump)
|
|
53
|
+
context.pump.requestClose();
|
|
54
|
+
const closed = this.queue.run(async () => {
|
|
55
|
+
this.stop();
|
|
56
|
+
try {
|
|
57
|
+
await this.closePump();
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
audio_native_1.audioNative.closeAudioMusic(this[audio_native_1.audioHandle]);
|
|
61
|
+
this.refreshChannels();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (reentrant) {
|
|
65
|
+
void closed.catch(() => { });
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
return closed;
|
|
69
|
+
}
|
|
70
|
+
/** 返回音乐总时长。 */
|
|
71
|
+
getDuration() { this.command(7); return new time_1.Time(this.times[1]); }
|
|
72
|
+
/** 返回循环区间副本,包含起点偏移和长度。 */
|
|
73
|
+
getLoopPoints() {
|
|
74
|
+
this.command(6);
|
|
75
|
+
return new value_1.TimeSpan({ offset: new time_1.Time(this.times[2]),
|
|
76
|
+
length: new time_1.Time(this.times[3]) });
|
|
77
|
+
}
|
|
78
|
+
/** 设置循环区间;启用循环需另行调用 setLooping(true)。 */
|
|
79
|
+
setLoopPoints(value) {
|
|
80
|
+
const offset = (0, value_1.duration)(value.offset);
|
|
81
|
+
const length = (0, value_1.duration)(value.length);
|
|
82
|
+
this.times[2] = offset;
|
|
83
|
+
this.times[3] = length;
|
|
84
|
+
this.command(5);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 在对象所属 JS 线程填充交错 16 位 PCM;await super 可读取当前文件。
|
|
88
|
+
* samples 指向原生可复用槽,仅在回调结束前有效;false 表示末块。
|
|
89
|
+
*/
|
|
90
|
+
onGetData(chunk) {
|
|
91
|
+
return this.callbackPump().onGetData(chunk);
|
|
92
|
+
}
|
|
93
|
+
/** 在对象所属 JS 线程定位;await super 执行当前文件的默认定位。 */
|
|
94
|
+
onSeek(offset) {
|
|
95
|
+
return this.callbackPump().onSeek(offset);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 在对象所属 JS 线程准备末块时调用,返回下一轮交错样本偏移。
|
|
99
|
+
* super 返回文件循环区间或 EOF 的位置;undefined 表示不循环。
|
|
100
|
+
* 实际定位由音频消费线程发起,再异步交给 onSeek。
|
|
101
|
+
*/
|
|
102
|
+
onLoop() {
|
|
103
|
+
return this.callbackPump().onLoop();
|
|
104
|
+
}
|
|
105
|
+
/** 获取当前回调所属的会话,避免 await 后误写新打开的音乐。 */
|
|
106
|
+
callbackPump() {
|
|
107
|
+
const context = callbackContext.getStore();
|
|
108
|
+
if (context?.owner.deref() !== this) {
|
|
109
|
+
throw new Error('Music callbacks are only available during playback');
|
|
110
|
+
}
|
|
111
|
+
return context.pump;
|
|
112
|
+
}
|
|
113
|
+
/** 仅在子类覆写回调时安装弱引用派发器,保留普通实例 Native 路径。 */
|
|
114
|
+
createCallbacks() {
|
|
115
|
+
if (this.onGetData === Music.prototype.onGetData &&
|
|
116
|
+
this.onSeek === Music.prototype.onSeek &&
|
|
117
|
+
this.onLoop === Music.prototype.onLoop)
|
|
118
|
+
return undefined;
|
|
119
|
+
const owner = new WeakRef(this);
|
|
120
|
+
return {
|
|
121
|
+
onGetData: (chunk, pump) => callbackContext.run({ owner, pump }, () => {
|
|
122
|
+
const target = owner.deref();
|
|
123
|
+
if (target)
|
|
124
|
+
return target.onGetData(chunk);
|
|
125
|
+
pump.requestClose();
|
|
126
|
+
chunk.sampleCount = 0;
|
|
127
|
+
return false;
|
|
128
|
+
}),
|
|
129
|
+
onSeek: (offset, pump) => callbackContext.run({ owner, pump }, () => {
|
|
130
|
+
const target = owner.deref();
|
|
131
|
+
if (target)
|
|
132
|
+
return target.onSeek(offset);
|
|
133
|
+
pump.requestClose();
|
|
134
|
+
}),
|
|
135
|
+
onLoop: pump => callbackContext.run({ owner, pump }, () => owner.deref()?.onLoop()),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** 脱离当前会话并等待 Native 队列和文件清理。 */
|
|
139
|
+
async closePump() {
|
|
140
|
+
pumpCleanup.unregister(this);
|
|
141
|
+
const pump = this.pump;
|
|
142
|
+
this.pump = undefined;
|
|
143
|
+
await pump?.close();
|
|
144
|
+
}
|
|
145
|
+
/** 打开新文件;会话回调中拒绝重开,避免等待其自身的准备阶段。 */
|
|
146
|
+
open(input) {
|
|
147
|
+
if (callbackContext.getStore()?.owner.deref() === this) {
|
|
148
|
+
return Promise.reject(new Error('Cannot reopen Music inside its callback'));
|
|
149
|
+
}
|
|
150
|
+
const generation = this.closeGeneration;
|
|
151
|
+
return this.queue.run(async () => {
|
|
152
|
+
if (generation !== this.closeGeneration)
|
|
153
|
+
return false;
|
|
154
|
+
const callbacks = this.createCallbacks();
|
|
155
|
+
if (callbacks || audio_codec_registry_1.audioReaders.size ||
|
|
156
|
+
(typeof input !== 'string' && !(input instanceof Uint8Array))) {
|
|
157
|
+
const file = new input_sound_file_1.InputSoundFile();
|
|
158
|
+
let adopted = false;
|
|
159
|
+
try {
|
|
160
|
+
const ok = typeof input === 'string' ? await file.openFromFile(input)
|
|
161
|
+
: input instanceof Uint8Array ? await file.openFromMemory(input)
|
|
162
|
+
: await file.openFromStream(input);
|
|
163
|
+
if (!ok || generation !== this.closeGeneration)
|
|
164
|
+
return false;
|
|
165
|
+
this.stop();
|
|
166
|
+
await this.closePump();
|
|
167
|
+
if (generation !== this.closeGeneration)
|
|
168
|
+
return false;
|
|
169
|
+
const mapping = audio_native_1.audioNative.openAudioMusicStream(this[audio_native_1.audioHandle], 1024, file.getChannelCount(), file.getSampleRate(), 8, Int32Array.from(file.getChannelMap()), file.getSampleCount());
|
|
170
|
+
this.pump = new audio_music_pump_1.AudioMusicPump(mapping.handle, mapping.token, file, callbacks);
|
|
171
|
+
adopted = true;
|
|
172
|
+
pumpCleanup.register(this, this.pump, this);
|
|
173
|
+
this.refreshChannels();
|
|
174
|
+
return await this.pump.ready;
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
if (!adopted)
|
|
178
|
+
await file.close();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const ok = await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.openAudioMusic(this[audio_native_1.audioHandle], input, callback));
|
|
182
|
+
if (ok) {
|
|
183
|
+
await this.closePump();
|
|
184
|
+
this.refreshChannels();
|
|
185
|
+
}
|
|
186
|
+
return ok;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** 循环区间的时间段类型。 */
|
|
191
|
+
Music.TimeSpan = value_1.TimeSpan;
|
|
192
|
+
exports.Music = Music;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { audioHandle } from '../internal/audio-native';
|
|
2
|
+
import { type SoundChannel } from './value';
|
|
3
|
+
/** 将交错 16 位 PCM 异步编码到音频文件,格式由文件扩展名决定。 */
|
|
4
|
+
export declare class OutputSoundFile {
|
|
5
|
+
readonly [audioHandle]: import("../internal/audio-native").AudioHandle<"output">;
|
|
6
|
+
private readonly queue;
|
|
7
|
+
private writer?;
|
|
8
|
+
/** 关闭旧输出并异步创建文件,采样率以 Hz 计,返回是否成功。 */
|
|
9
|
+
openFromFile(filename: string, sampleRate: number, channelCount: number, channelMap: Iterable<SoundChannel>): Promise<boolean>;
|
|
10
|
+
/** 按顺序异步编码样本;Promise 完成前不得修改 data。 */
|
|
11
|
+
write(data: Int16Array): Promise<void>;
|
|
12
|
+
/** 等待所有写入、刷新编码器并关闭文件,确保文件内容完整。 */
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
private closeCurrent;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OutputSoundFile = void 0;
|
|
5
|
+
const audio_native_1 = require("../internal/audio-native");
|
|
6
|
+
const value_1 = require("./value");
|
|
7
|
+
const audio_codec_registry_1 = require("../internal/audio-codec-registry");
|
|
8
|
+
/** 将交错 16 位 PCM 异步编码到音频文件,格式由文件扩展名决定。 */
|
|
9
|
+
class OutputSoundFile {
|
|
10
|
+
constructor() {
|
|
11
|
+
this[_a] = audio_native_1.audioNative.createAudioOutput();
|
|
12
|
+
this.queue = new audio_native_1.AudioQueue();
|
|
13
|
+
}
|
|
14
|
+
/** 关闭旧输出并异步创建文件,采样率以 Hz 计,返回是否成功。 */
|
|
15
|
+
openFromFile(filename, sampleRate, channelCount, channelMap) {
|
|
16
|
+
(0, value_1.unsigned)(sampleRate);
|
|
17
|
+
(0, value_1.unsigned)(channelCount);
|
|
18
|
+
const map = (0, value_1.channels)(channelMap);
|
|
19
|
+
return this.queue.run(async () => {
|
|
20
|
+
await this.closeCurrent();
|
|
21
|
+
const writer = await (0, audio_codec_registry_1.findAudioWriter)(filename);
|
|
22
|
+
if (!writer) {
|
|
23
|
+
return (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.openAudioOutput(this[audio_native_1.audioHandle], filename, sampleRate, channelCount, map, callback));
|
|
24
|
+
}
|
|
25
|
+
let opened = false;
|
|
26
|
+
try {
|
|
27
|
+
const result = await writer.open(filename, sampleRate, channelCount, map);
|
|
28
|
+
if (typeof result !== 'boolean') {
|
|
29
|
+
throw new TypeError('Writer.open must return a boolean');
|
|
30
|
+
}
|
|
31
|
+
opened = result;
|
|
32
|
+
if (opened)
|
|
33
|
+
this.writer = writer;
|
|
34
|
+
return opened;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (!opened)
|
|
38
|
+
await writer.close();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** 按顺序异步编码样本;Promise 完成前不得修改 data。 */
|
|
43
|
+
write(data) {
|
|
44
|
+
(0, value_1.samples)(data);
|
|
45
|
+
return this.queue.run(async () => {
|
|
46
|
+
if (this.writer) {
|
|
47
|
+
await this.writer.write(data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.writeAudioOutput(this[audio_native_1.audioHandle], data, callback));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** 等待所有写入、刷新编码器并关闭文件,确保文件内容完整。 */
|
|
55
|
+
close() {
|
|
56
|
+
return this.queue.run(() => this.closeCurrent());
|
|
57
|
+
}
|
|
58
|
+
async closeCurrent() {
|
|
59
|
+
const writer = this.writer;
|
|
60
|
+
this.writer = undefined;
|
|
61
|
+
try {
|
|
62
|
+
await writer?.close();
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.closeAudioOutput(this[audio_native_1.audioHandle], callback));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.OutputSoundFile = OutputSoundFile;
|
|
70
|
+
_a = audio_native_1.audioHandle;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** 音频播放设备的生命周期通知。 */
|
|
2
|
+
export declare enum Notification {
|
|
3
|
+
/** 设备开始运行。 */
|
|
4
|
+
DeviceStarted = 0,
|
|
5
|
+
/** 设备停止运行。 */
|
|
6
|
+
DeviceStopped = 1,
|
|
7
|
+
/** 音频输出路由发生变化。 */
|
|
8
|
+
DeviceRerouted = 2,
|
|
9
|
+
/** 系统中断开始。 */
|
|
10
|
+
DeviceInterruptionBegan = 3,
|
|
11
|
+
/** 系统中断结束。 */
|
|
12
|
+
DeviceInterruptionEnded = 4,
|
|
13
|
+
/** 设备解除锁定。 */
|
|
14
|
+
DeviceUnlocked = 5
|
|
15
|
+
}
|
|
16
|
+
/** 接收播放设备状态通知的回调。 */
|
|
17
|
+
export type NotificationCallback = (notification: Notification) => void;
|
|
18
|
+
/** 返回可用播放设备名称。 */
|
|
19
|
+
export declare function getAvailableDevices(): string[];
|
|
20
|
+
/** 返回系统默认播放设备名称;不可用时为 undefined。 */
|
|
21
|
+
export declare function getDefaultDevice(): string | undefined;
|
|
22
|
+
/** 切换到指定名称的播放设备,返回是否成功。 */
|
|
23
|
+
export declare function setDevice(name: string): boolean;
|
|
24
|
+
/** 切换到系统默认播放设备,返回是否成功。 */
|
|
25
|
+
export declare function setDeviceToDefault(): boolean;
|
|
26
|
+
/** 切换到不输出声音的空设备,返回是否成功。 */
|
|
27
|
+
export declare function setDeviceToNull(): boolean;
|
|
28
|
+
/** 返回当前播放设备名称;不可用时为 undefined。 */
|
|
29
|
+
export declare function getDevice(): string | undefined;
|
|
30
|
+
/** 返回当前设备采样率(Hz);不可用时为 undefined。 */
|
|
31
|
+
export declare function getDeviceSampleRate(): number | undefined;
|
|
32
|
+
/** 返回当前设备是否跟随系统默认设备。 */
|
|
33
|
+
export declare function isDefaultDevice(): boolean;
|
|
34
|
+
/** 设置设备通知回调;undefined 或 null 移除回调。 */
|
|
35
|
+
export declare function setNotificationCallback(callback?: NotificationCallback | null): void;
|