sfml.js 1.0.0 → 1.1.0
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/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +40 -48
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
|
-
audioNative,
|
|
2
|
+
audioNative,
|
|
3
|
+
audioHandle,
|
|
4
|
+
audioAsync,
|
|
5
|
+
AudioQueue,
|
|
6
|
+
type AudioHandle,
|
|
3
7
|
type AudioBufferMapping,
|
|
4
8
|
} from '../internal/audio-native';
|
|
5
9
|
import { nativeStruct } from '../internal/struct-view';
|
|
6
10
|
import { Time } from '../system/time';
|
|
7
11
|
import type { InputStream } from '../system/input-stream';
|
|
8
12
|
import { AudioInputStream } from '../internal/audio-input-stream';
|
|
9
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
audioReaders,
|
|
15
|
+
audioWriters,
|
|
16
|
+
} from '../internal/audio-codec-registry';
|
|
10
17
|
import { InputSoundFile } from './input-sound-file';
|
|
11
18
|
import { OutputSoundFile } from './output-sound-file';
|
|
12
19
|
import {
|
|
13
|
-
channels,
|
|
20
|
+
channels,
|
|
21
|
+
unsigned,
|
|
22
|
+
samples,
|
|
23
|
+
type SoundChannel,
|
|
24
|
+
type ReadonlySamples,
|
|
14
25
|
type ChannelMap,
|
|
15
26
|
} from './value';
|
|
16
27
|
|
|
17
28
|
function view(mapping: AudioBufferMapping) {
|
|
18
29
|
return nativeStruct<{
|
|
19
|
-
sampleCount: bigint;
|
|
20
|
-
|
|
30
|
+
sampleCount: bigint;
|
|
31
|
+
sampleRate: number;
|
|
32
|
+
channelCount: number;
|
|
33
|
+
duration: bigint;
|
|
34
|
+
samples: Int16Array;
|
|
35
|
+
channelMap: Int32Array;
|
|
21
36
|
}>(mapping.info, {
|
|
22
37
|
samples: new Int16Array(mapping.samples),
|
|
23
38
|
channelMap: new Int32Array(mapping.channelMap),
|
|
@@ -32,9 +47,19 @@ function view(mapping: AudioBufferMapping) {
|
|
|
32
47
|
* @ko 오디오 버퍼의 읽기 전용 인터페이스입니다.
|
|
33
48
|
* 샘플 뷰는 해당 네이티브 저장소를 유지합니다.
|
|
34
49
|
*/
|
|
35
|
-
export type ReadonlySoundBuffer = Readonly<
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
export type ReadonlySoundBuffer = Readonly<
|
|
51
|
+
Pick<
|
|
52
|
+
SoundBuffer,
|
|
53
|
+
| typeof audioHandle
|
|
54
|
+
| 'getSamples'
|
|
55
|
+
| 'getSampleCount'
|
|
56
|
+
| 'getSampleRate'
|
|
57
|
+
| 'getChannelCount'
|
|
58
|
+
| 'getChannelMap'
|
|
59
|
+
| 'getDuration'
|
|
60
|
+
| 'saveToFile'
|
|
61
|
+
>
|
|
62
|
+
>;
|
|
38
63
|
|
|
39
64
|
export const adoptAudioBuffer: unique symbol = Symbol('Audio.adoptBuffer');
|
|
40
65
|
|
|
@@ -65,15 +90,26 @@ export class SoundBuffer {
|
|
|
65
90
|
* @ko 16비트 인터리브 PCM을 복사합니다. 샘플 레이트는 Hz 단위이며
|
|
66
91
|
* channelMap은 각 채널 위치를 지정합니다.
|
|
67
92
|
*/
|
|
68
|
-
constructor(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
channelMap
|
|
93
|
+
constructor(
|
|
94
|
+
samples: Int16Array,
|
|
95
|
+
channelCount: number,
|
|
96
|
+
sampleRate: number,
|
|
97
|
+
channelMap: Iterable<SoundChannel>,
|
|
98
|
+
);
|
|
99
|
+
constructor(
|
|
100
|
+
source?: ReadonlySoundBuffer | Int16Array,
|
|
101
|
+
channelCount?: number,
|
|
102
|
+
sampleRate?: number,
|
|
103
|
+
channelMap?: Iterable<SoundChannel>,
|
|
104
|
+
) {
|
|
73
105
|
let mapping: AudioBufferMapping & { handle: AudioHandle<'buffer'> };
|
|
74
106
|
if (source instanceof Int16Array) {
|
|
75
|
-
mapping = audioNative.createAudioBuffer(
|
|
76
|
-
|
|
107
|
+
mapping = audioNative.createAudioBuffer(
|
|
108
|
+
source,
|
|
109
|
+
unsigned(sampleRate!),
|
|
110
|
+
unsigned(channelCount!),
|
|
111
|
+
channels(channelMap!),
|
|
112
|
+
);
|
|
77
113
|
} else {
|
|
78
114
|
if (source !== undefined && !(source instanceof SoundBuffer)) {
|
|
79
115
|
throw new TypeError('Expected a SoundBuffer or Int16Array');
|
|
@@ -95,15 +131,20 @@ export class SoundBuffer {
|
|
|
95
131
|
if (!(source instanceof SoundBuffer)) {
|
|
96
132
|
throw new TypeError('Expected a SoundBuffer');
|
|
97
133
|
}
|
|
98
|
-
if (source === this)
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
if (source === this) {
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
this.state = view(
|
|
138
|
+
audioNative.assignAudioBuffer(this[audioHandle], source[audioHandle]),
|
|
139
|
+
);
|
|
101
140
|
return this;
|
|
102
141
|
}
|
|
103
142
|
/** @internal */
|
|
104
143
|
static [adoptAudioBuffer](data: AudioHandle<'bufferData'>): SoundBuffer {
|
|
105
144
|
const result = new SoundBuffer();
|
|
106
|
-
result.state = view(
|
|
145
|
+
result.state = view(
|
|
146
|
+
audioNative.commitAudioBuffer(result[audioHandle], data),
|
|
147
|
+
);
|
|
107
148
|
return result;
|
|
108
149
|
}
|
|
109
150
|
/**
|
|
@@ -116,7 +157,9 @@ export class SoundBuffer {
|
|
|
116
157
|
* 성공 여부를 반환합니다.
|
|
117
158
|
*/
|
|
118
159
|
loadFromFile(filename: string): Promise<boolean> {
|
|
119
|
-
return audioReaders.size
|
|
160
|
+
return audioReaders.size
|
|
161
|
+
? this.loadDecoded(filename)
|
|
162
|
+
: this.load(filename);
|
|
120
163
|
}
|
|
121
164
|
/**
|
|
122
165
|
* Asynchronously decode encoded audio bytes and replace the PCM,
|
|
@@ -140,7 +183,8 @@ export class SoundBuffer {
|
|
|
140
183
|
* 스트림 오류는 Promise를 거부합니다.
|
|
141
184
|
*/
|
|
142
185
|
loadFromStream(stream: InputStream): Promise<boolean> {
|
|
143
|
-
return audioReaders.size
|
|
186
|
+
return audioReaders.size
|
|
187
|
+
? this.loadDecoded(stream)
|
|
144
188
|
: this.load(new AudioInputStream(stream));
|
|
145
189
|
}
|
|
146
190
|
|
|
@@ -153,13 +197,25 @@ export class SoundBuffer {
|
|
|
153
197
|
* @ko 16비트 인터리브 PCM을 동기적으로 복사하여 내용을 교체합니다.
|
|
154
198
|
* sampleRate는 Hz 단위이며 성공 여부를 반환합니다.
|
|
155
199
|
*/
|
|
156
|
-
loadFromSamples(
|
|
157
|
-
|
|
200
|
+
loadFromSamples(
|
|
201
|
+
data: Int16Array,
|
|
202
|
+
channelCount: number,
|
|
203
|
+
sampleRate: number,
|
|
204
|
+
channelMap: Iterable<SoundChannel>,
|
|
205
|
+
): boolean {
|
|
158
206
|
samples(data);
|
|
159
|
-
const result = audioNative.audioBufferSamples(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
207
|
+
const result = audioNative.audioBufferSamples(
|
|
208
|
+
data,
|
|
209
|
+
unsigned(sampleRate),
|
|
210
|
+
unsigned(channelCount),
|
|
211
|
+
channels(channelMap),
|
|
212
|
+
);
|
|
213
|
+
if (!result) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
this.state = view(
|
|
217
|
+
audioNative.commitAudioBuffer(this[audioHandle], result),
|
|
218
|
+
);
|
|
163
219
|
return true;
|
|
164
220
|
}
|
|
165
221
|
/**
|
|
@@ -181,35 +237,45 @@ export class SoundBuffer {
|
|
|
181
237
|
* @ja 全チャンネルのサンプル総数を返します。
|
|
182
238
|
* @ko 모든 채널의 샘플 총수를 반환합니다.
|
|
183
239
|
*/
|
|
184
|
-
getSampleCount(): bigint {
|
|
240
|
+
getSampleCount(): bigint {
|
|
241
|
+
return this.state.sampleCount;
|
|
242
|
+
}
|
|
185
243
|
/**
|
|
186
244
|
* Return the sample rate per channel, in Hz.
|
|
187
245
|
* @zh 返回每声道采样率,单位为 Hz。
|
|
188
246
|
* @ja チャンネルごとのサンプルレートを Hz で返します。
|
|
189
247
|
* @ko 채널별 샘플 레이트를 Hz 단위로 반환합니다.
|
|
190
248
|
*/
|
|
191
|
-
getSampleRate(): number {
|
|
249
|
+
getSampleRate(): number {
|
|
250
|
+
return this.state.sampleRate;
|
|
251
|
+
}
|
|
192
252
|
/**
|
|
193
253
|
* Return the number of channels.
|
|
194
254
|
* @zh 返回声道数量。
|
|
195
255
|
* @ja チャンネル数を返します。
|
|
196
256
|
* @ko 채널 수를 반환합니다.
|
|
197
257
|
*/
|
|
198
|
-
getChannelCount(): number {
|
|
258
|
+
getChannelCount(): number {
|
|
259
|
+
return this.state.channelCount;
|
|
260
|
+
}
|
|
199
261
|
/**
|
|
200
262
|
* Return a read-only view of channel positions in interleaved order.
|
|
201
263
|
* @zh 返回交错声道位置顺序的只读视图。
|
|
202
264
|
* @ja インターリーブ順のチャンネル位置の読み取り専用ビューを返します。
|
|
203
265
|
* @ko 인터리브 순서의 채널 위치를 나타내는 읽기 전용 뷰를 반환합니다.
|
|
204
266
|
*/
|
|
205
|
-
getChannelMap(): ChannelMap {
|
|
267
|
+
getChannelMap(): ChannelMap {
|
|
268
|
+
return this.state.channelMap;
|
|
269
|
+
}
|
|
206
270
|
/**
|
|
207
271
|
* Return a copy of the total audio duration.
|
|
208
272
|
* @zh 返回音频总时长副本。
|
|
209
273
|
* @ja 音声全体の長さのコピーを返します。
|
|
210
274
|
* @ko 오디오 전체 길이의 복사본을 반환합니다.
|
|
211
275
|
*/
|
|
212
|
-
getDuration(): Time {
|
|
276
|
+
getDuration(): Time {
|
|
277
|
+
return new Time(this.state.duration);
|
|
278
|
+
}
|
|
213
279
|
/**
|
|
214
280
|
* Asynchronously encode and save using the file extension to select the
|
|
215
281
|
* format, returning whether it succeeded.
|
|
@@ -223,53 +289,95 @@ export class SoundBuffer {
|
|
|
223
289
|
return this.queue.run(async () => {
|
|
224
290
|
const output = new OutputSoundFile();
|
|
225
291
|
try {
|
|
226
|
-
const ok = await output.openFromFile(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
292
|
+
const ok = await output.openFromFile(
|
|
293
|
+
filename,
|
|
294
|
+
this.getSampleRate(),
|
|
295
|
+
this.getChannelCount(),
|
|
296
|
+
this.getChannelMap(),
|
|
297
|
+
);
|
|
298
|
+
if (!ok) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
if (this.state.samples.length) {
|
|
302
|
+
await output.write(this.state.samples);
|
|
303
|
+
}
|
|
230
304
|
return true;
|
|
231
|
-
} finally {
|
|
305
|
+
} finally {
|
|
306
|
+
await output.close();
|
|
307
|
+
}
|
|
232
308
|
});
|
|
233
309
|
}
|
|
234
|
-
return this.queue.run(() =>
|
|
235
|
-
|
|
310
|
+
return this.queue.run(() =>
|
|
311
|
+
audioAsync(callback =>
|
|
312
|
+
audioNative.saveAudioBuffer(this[audioHandle], filename, callback),
|
|
313
|
+
),
|
|
314
|
+
);
|
|
236
315
|
}
|
|
237
|
-
private loadDecoded(
|
|
238
|
-
|
|
316
|
+
private loadDecoded(
|
|
317
|
+
input: string | Uint8Array | InputStream,
|
|
318
|
+
): Promise<boolean> {
|
|
239
319
|
return this.queue.run(async () => {
|
|
240
320
|
const file = new InputSoundFile();
|
|
241
321
|
try {
|
|
242
|
-
const ok =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
322
|
+
const ok =
|
|
323
|
+
typeof input === 'string'
|
|
324
|
+
? await file.openFromFile(input)
|
|
325
|
+
: input instanceof Uint8Array
|
|
326
|
+
? await file.openFromMemory(input)
|
|
327
|
+
: await file.openFromStream(input);
|
|
328
|
+
if (!ok) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
246
331
|
const count = file.getSampleCount();
|
|
247
|
-
if (count > 0xffffffffn)
|
|
332
|
+
if (count > 0xffffffffn) {
|
|
333
|
+
throw new RangeError('Sample buffer is too large');
|
|
334
|
+
}
|
|
248
335
|
const data = new Int16Array(
|
|
249
|
-
audioNative.allocateAudioSamples(Number(count))
|
|
336
|
+
audioNative.allocateAudioSamples(Number(count)),
|
|
337
|
+
);
|
|
250
338
|
let position = 0;
|
|
251
339
|
while (position < data.length) {
|
|
252
340
|
const read = Number(await file.read(data.subarray(position)));
|
|
253
|
-
if (!read)
|
|
341
|
+
if (!read) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
254
344
|
position += read;
|
|
255
345
|
}
|
|
256
|
-
return this.loadFromSamples(
|
|
257
|
-
|
|
258
|
-
|
|
346
|
+
return this.loadFromSamples(
|
|
347
|
+
data,
|
|
348
|
+
file.getChannelCount(),
|
|
349
|
+
file.getSampleRate(),
|
|
350
|
+
file.getChannelMap(),
|
|
351
|
+
);
|
|
352
|
+
} finally {
|
|
353
|
+
await file.close();
|
|
354
|
+
}
|
|
259
355
|
});
|
|
260
356
|
}
|
|
261
|
-
private load(
|
|
357
|
+
private load(
|
|
358
|
+
input: string | Uint8Array | AudioInputStream,
|
|
359
|
+
): Promise<boolean> {
|
|
262
360
|
return this.queue.run(async () => {
|
|
263
361
|
const stream = input instanceof AudioInputStream ? input : undefined;
|
|
264
362
|
try {
|
|
265
|
-
const load = () =>
|
|
266
|
-
callback =>
|
|
267
|
-
|
|
363
|
+
const load = () =>
|
|
364
|
+
audioAsync<AudioHandle<'bufferData'> | undefined>(callback =>
|
|
365
|
+
audioNative.loadAudioBuffer(
|
|
366
|
+
stream ? stream.handle : (input as string | Uint8Array),
|
|
367
|
+
callback,
|
|
368
|
+
),
|
|
369
|
+
);
|
|
268
370
|
const data = await (stream ? stream.run(load) : load());
|
|
269
|
-
if (!data)
|
|
270
|
-
|
|
371
|
+
if (!data) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
this.state = view(
|
|
375
|
+
audioNative.commitAudioBuffer(this[audioHandle], data),
|
|
376
|
+
);
|
|
271
377
|
return true;
|
|
272
|
-
} finally {
|
|
378
|
+
} finally {
|
|
379
|
+
stream?.close();
|
|
380
|
+
}
|
|
273
381
|
});
|
|
274
382
|
}
|
|
275
383
|
}
|
|
@@ -1,52 +1,84 @@
|
|
|
1
1
|
import {
|
|
2
|
-
audioNative,
|
|
2
|
+
audioNative,
|
|
3
|
+
audioAsync,
|
|
4
|
+
AudioQueue,
|
|
5
|
+
type AudioHandle,
|
|
3
6
|
type AudioReaderInfoMapping,
|
|
4
7
|
} from '../internal/audio-native';
|
|
5
8
|
import { AudioInputStream } from '../internal/audio-input-stream';
|
|
6
9
|
import {
|
|
7
|
-
audioReaders,
|
|
10
|
+
audioReaders,
|
|
11
|
+
audioWriters,
|
|
12
|
+
findAudioReaderInput,
|
|
13
|
+
findAudioWriter,
|
|
8
14
|
} from '../internal/audio-codec-registry';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type
|
|
15
|
+
import {
|
|
16
|
+
SoundFileReader,
|
|
17
|
+
SoundFileReaderInfo,
|
|
18
|
+
type SoundFileReaderConstructor,
|
|
19
|
+
} from './sound-file-reader';
|
|
20
|
+
import {
|
|
21
|
+
SoundFileWriter,
|
|
22
|
+
type SoundFileWriterConstructor,
|
|
23
|
+
} from './sound-file-writer';
|
|
13
24
|
import { channels, unsigned, samples, type SoundChannel } from './value';
|
|
14
25
|
import type { InputStream } from '../system/input-stream';
|
|
15
26
|
|
|
16
27
|
class NativeReader extends SoundFileReader {
|
|
17
28
|
private readonly queue = new AudioQueue();
|
|
18
29
|
private stream?: AudioInputStream;
|
|
19
|
-
constructor(private readonly handle: AudioHandle<'reader'>) {
|
|
30
|
+
constructor(private readonly handle: AudioHandle<'reader'>) {
|
|
31
|
+
super();
|
|
32
|
+
}
|
|
20
33
|
open(stream: InputStream): Promise<SoundFileReaderInfo | undefined> {
|
|
21
34
|
return this.queue.run(async () => {
|
|
22
35
|
const next = new AudioInputStream(stream);
|
|
23
36
|
try {
|
|
24
|
-
if (await stream.seek(0n) !== 0n)
|
|
37
|
+
if ((await stream.seek(0n)) !== 0n) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
25
40
|
const mapping = await next.run(() =>
|
|
26
41
|
audioAsync<AudioReaderInfoMapping | undefined>(callback =>
|
|
27
|
-
audioNative.openAudioReader(this.handle, next.handle, callback)
|
|
28
|
-
|
|
42
|
+
audioNative.openAudioReader(this.handle, next.handle, callback),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
if (!mapping) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
29
48
|
this.stream?.close();
|
|
30
49
|
this.stream = next;
|
|
31
50
|
return new SoundFileReaderInfo(undefined, mapping);
|
|
32
51
|
} finally {
|
|
33
|
-
if (this.stream !== next)
|
|
52
|
+
if (this.stream !== next) {
|
|
53
|
+
next.close();
|
|
54
|
+
}
|
|
34
55
|
}
|
|
35
56
|
});
|
|
36
57
|
}
|
|
37
58
|
read(data: Int16Array): Promise<bigint> {
|
|
38
59
|
samples(data);
|
|
39
|
-
return this.queue.run(() =>
|
|
40
|
-
|
|
60
|
+
return this.queue.run(() =>
|
|
61
|
+
this.run(() =>
|
|
62
|
+
audioAsync(callback =>
|
|
63
|
+
audioNative.readAudioReader(this.handle, data, callback),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
41
67
|
}
|
|
42
68
|
seek(offset: bigint): Promise<void> {
|
|
43
|
-
return this.queue.run(() =>
|
|
44
|
-
|
|
69
|
+
return this.queue.run(() =>
|
|
70
|
+
this.run(() =>
|
|
71
|
+
audioAsync(callback =>
|
|
72
|
+
audioNative.seekAudioReader(this.handle, offset, callback),
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
45
76
|
}
|
|
46
77
|
close(): Promise<void> {
|
|
47
78
|
return this.queue.run(async () => {
|
|
48
79
|
await audioAsync<void>(callback =>
|
|
49
|
-
audioNative.closeAudioReader(this.handle, callback)
|
|
80
|
+
audioNative.closeAudioReader(this.handle, callback),
|
|
81
|
+
);
|
|
50
82
|
this.stream?.close();
|
|
51
83
|
this.stream = undefined;
|
|
52
84
|
});
|
|
@@ -59,31 +91,48 @@ class NativeReader extends SoundFileReader {
|
|
|
59
91
|
class NativeWriter extends SoundFileWriter {
|
|
60
92
|
private readonly queue = new AudioQueue();
|
|
61
93
|
private opened = false;
|
|
62
|
-
constructor(private readonly handle: AudioHandle<'writer'>) {
|
|
63
|
-
|
|
64
|
-
|
|
94
|
+
constructor(private readonly handle: AudioHandle<'writer'>) {
|
|
95
|
+
super();
|
|
96
|
+
}
|
|
97
|
+
open(
|
|
98
|
+
filename: string,
|
|
99
|
+
rate: number,
|
|
100
|
+
count: number,
|
|
101
|
+
map: Iterable<SoundChannel>,
|
|
102
|
+
): Promise<boolean> {
|
|
65
103
|
const channelMap = channels(map);
|
|
66
104
|
unsigned(rate);
|
|
67
105
|
unsigned(count);
|
|
68
106
|
return this.queue.run(async () => {
|
|
69
107
|
this.opened = await audioAsync<boolean>(callback =>
|
|
70
|
-
audioNative.openAudioWriter(
|
|
71
|
-
|
|
108
|
+
audioNative.openAudioWriter(
|
|
109
|
+
this.handle,
|
|
110
|
+
filename,
|
|
111
|
+
rate,
|
|
112
|
+
count,
|
|
113
|
+
channelMap,
|
|
114
|
+
callback,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
72
117
|
return this.opened;
|
|
73
118
|
});
|
|
74
119
|
}
|
|
75
120
|
write(data: Int16Array): Promise<void> {
|
|
76
121
|
samples(data);
|
|
77
122
|
return this.queue.run(async () => {
|
|
78
|
-
if (!this.opened)
|
|
123
|
+
if (!this.opened) {
|
|
124
|
+
throw new Error('Writer is not open');
|
|
125
|
+
}
|
|
79
126
|
await audioAsync<void>(callback =>
|
|
80
|
-
audioNative.writeAudioWriter(this.handle, data, callback)
|
|
127
|
+
audioNative.writeAudioWriter(this.handle, data, callback),
|
|
128
|
+
);
|
|
81
129
|
});
|
|
82
130
|
}
|
|
83
131
|
close(): Promise<void> {
|
|
84
132
|
return this.queue.run(async () => {
|
|
85
133
|
await audioAsync<void>(callback =>
|
|
86
|
-
audioNative.closeAudioWriter(this.handle, callback)
|
|
134
|
+
audioNative.closeAudioWriter(this.handle, callback),
|
|
135
|
+
);
|
|
87
136
|
this.opened = false;
|
|
88
137
|
});
|
|
89
138
|
}
|
|
@@ -106,10 +155,14 @@ export class SoundFileFactory {
|
|
|
106
155
|
* 현재 Node 환경에 등록합니다.
|
|
107
156
|
*/
|
|
108
157
|
static registerReader(reader: SoundFileReaderConstructor): void {
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
158
|
+
if (
|
|
159
|
+
typeof reader !== 'function' ||
|
|
160
|
+
!(reader.prototype instanceof SoundFileReader) ||
|
|
161
|
+
typeof reader.check !== 'function'
|
|
162
|
+
) {
|
|
163
|
+
throw new TypeError(
|
|
164
|
+
'Expected a SoundFileReader class with static check()',
|
|
165
|
+
);
|
|
113
166
|
}
|
|
114
167
|
audioReaders.add(reader);
|
|
115
168
|
}
|
|
@@ -141,10 +194,14 @@ export class SoundFileFactory {
|
|
|
141
194
|
* 현재 Node 환경에 등록합니다.
|
|
142
195
|
*/
|
|
143
196
|
static registerWriter(writer: SoundFileWriterConstructor): void {
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
197
|
+
if (
|
|
198
|
+
typeof writer !== 'function' ||
|
|
199
|
+
!(writer.prototype instanceof SoundFileWriter) ||
|
|
200
|
+
typeof writer.check !== 'function'
|
|
201
|
+
) {
|
|
202
|
+
throw new TypeError(
|
|
203
|
+
'Expected a SoundFileWriter class with static check()',
|
|
204
|
+
);
|
|
148
205
|
}
|
|
149
206
|
audioWriters.add(writer);
|
|
150
207
|
}
|
|
@@ -175,8 +232,11 @@ export class SoundFileFactory {
|
|
|
175
232
|
* @ko 파일을 탐지하여 일치하는 디코더를 생성합니다.
|
|
176
233
|
* 일치 항목이 없으면 undefined이며, 사용 전 open을 호출해야 합니다.
|
|
177
234
|
*/
|
|
178
|
-
static createReaderFromFilename(
|
|
179
|
-
|
|
235
|
+
static createReaderFromFilename(
|
|
236
|
+
filename: string,
|
|
237
|
+
): Promise<SoundFileReader | undefined> {
|
|
238
|
+
return this.createReader(filename);
|
|
239
|
+
}
|
|
180
240
|
/**
|
|
181
241
|
* Probe encoded audio bytes and create a matching decoder, or return
|
|
182
242
|
* undefined if none matches.
|
|
@@ -186,8 +246,11 @@ export class SoundFileFactory {
|
|
|
186
246
|
* @ko 인코딩된 오디오 바이트를 탐지하여 일치하는 디코더를 생성합니다.
|
|
187
247
|
* 일치 항목이 없으면 undefined를 반환합니다.
|
|
188
248
|
*/
|
|
189
|
-
static createReaderFromMemory(
|
|
190
|
-
|
|
249
|
+
static createReaderFromMemory(
|
|
250
|
+
data: Uint8Array,
|
|
251
|
+
): Promise<SoundFileReader | undefined> {
|
|
252
|
+
return this.createReader(data);
|
|
253
|
+
}
|
|
191
254
|
/**
|
|
192
255
|
* Probe stream contents and create a matching decoder, or return undefined
|
|
193
256
|
* if none matches.
|
|
@@ -197,8 +260,11 @@ export class SoundFileFactory {
|
|
|
197
260
|
* @ko 스트림 내용을 탐지하여 일치하는 디코더를 생성합니다.
|
|
198
261
|
* 일치 항목이 없으면 undefined를 반환합니다.
|
|
199
262
|
*/
|
|
200
|
-
static createReaderFromStream(
|
|
201
|
-
|
|
263
|
+
static createReaderFromStream(
|
|
264
|
+
stream: InputStream,
|
|
265
|
+
): Promise<SoundFileReader | undefined> {
|
|
266
|
+
return this.createReader(stream);
|
|
267
|
+
}
|
|
202
268
|
/**
|
|
203
269
|
* Create an encoder by filename; return undefined if none matches.
|
|
204
270
|
* Calling open is still required before writing.
|
|
@@ -208,28 +274,40 @@ export class SoundFileFactory {
|
|
|
208
274
|
* @ko 파일명을 기준으로 인코더를 생성합니다. 일치 항목이 없으면 undefined이며,
|
|
209
275
|
* 쓰기 전에 open을 호출해야 합니다.
|
|
210
276
|
*/
|
|
211
|
-
static async createWriterFromFilename(
|
|
212
|
-
|
|
277
|
+
static async createWriterFromFilename(
|
|
278
|
+
filename: string,
|
|
279
|
+
): Promise<SoundFileWriter | undefined> {
|
|
213
280
|
const custom = await findAudioWriter(filename);
|
|
214
|
-
if (custom)
|
|
281
|
+
if (custom) {
|
|
282
|
+
return custom;
|
|
283
|
+
}
|
|
215
284
|
const handle = audioNative.createAudioWriter(filename);
|
|
216
285
|
return handle ? new NativeWriter(handle) : undefined;
|
|
217
286
|
}
|
|
218
|
-
private static async createReader(
|
|
219
|
-
|
|
287
|
+
private static async createReader(
|
|
288
|
+
input: string | Uint8Array | InputStream,
|
|
289
|
+
): Promise<SoundFileReader | undefined> {
|
|
220
290
|
const custom = await findAudioReaderInput(input);
|
|
221
291
|
if (custom) {
|
|
222
292
|
await custom.owned?.close();
|
|
223
293
|
return custom.reader;
|
|
224
294
|
}
|
|
225
|
-
const bridge =
|
|
226
|
-
|
|
295
|
+
const bridge =
|
|
296
|
+
typeof input === 'string' || input instanceof Uint8Array
|
|
297
|
+
? undefined
|
|
298
|
+
: new AudioInputStream(input);
|
|
227
299
|
try {
|
|
228
|
-
const create = () =>
|
|
229
|
-
callback =>
|
|
230
|
-
|
|
300
|
+
const create = () =>
|
|
301
|
+
audioAsync<AudioHandle<'reader'> | undefined>(callback =>
|
|
302
|
+
audioNative.createAudioReader(
|
|
303
|
+
bridge ? bridge.handle : (input as string | Uint8Array),
|
|
304
|
+
callback,
|
|
305
|
+
),
|
|
306
|
+
);
|
|
231
307
|
const handle = await (bridge ? bridge.run(create) : create());
|
|
232
308
|
return handle ? new NativeReader(handle) : undefined;
|
|
233
|
-
} finally {
|
|
309
|
+
} finally {
|
|
310
|
+
bridge?.close();
|
|
311
|
+
}
|
|
234
312
|
}
|
|
235
313
|
}
|