@kmamal/sdl 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  SDL bindings for Node.js.
9
9
  Provides window management, input events (keyboard, mouse, joystick, controller), audio playback and recording, and clipboard manipulation.
10
- You can use it together with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) to get native WebGL drawing without having to use a browser.
10
+ You can also use it together with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) to get native WebGL drawing without having to use a browser.
11
11
 
12
12
  It should work on Linux, Mac, and Windows.
13
13
  Prebuilt binaries are available for x64 architectures, and arm-based Macs.
@@ -223,7 +223,9 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
223
223
  * [sdl.audio.maxSampleValue(format)](#sdlaudiomaxsamplevalueformat)
224
224
  * [sdl.audio.zeroSampleValue(format)](#sdlaudiozerosamplevalueformat)
225
225
  * [sdl.audio.readSample(format, buffer[, offset])](#sdlaudioreadsampleformat-buffer-offset)
226
+ * [sdl.audio.readerName(format)](#sdlaudioreadernameformat)
226
227
  * [sdl.audio.writeSample(format, buffer, value[, offset])](#sdlaudiowritesampleformat-buffer-value-offset)
228
+ * [sdl.audio.writerName(format)](#sdlaudiowriternameformat)
227
229
  * [sdl.audio.devices](#sdlaudiodevices)
228
230
  * [sdl.audio.openDevice(device[, options])](#sdlaudioopendevicedevice-options)
229
231
  * [class AudioInstance](#class-audioinstance)
@@ -238,7 +240,9 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
238
240
  * [audioInstance.maxSampleValue](#audioinstancemaxsamplevalue)
239
241
  * [audioInstance.zeroSampleValue](#audioinstancezerosamplevalue)
240
242
  * [audioInstance.readSample(buffer[, offset])](#audioinstancereadsamplebuffer-offset)
243
+ * [audioInstance.readerName](#audioinstancereadername)
241
244
  * [audioInstance.writeSample(buffer, value[, offset])](#audioinstancewritesamplebuffer-value-offset)
245
+ * [audioInstance.writerName](#audioinstancewritername)
242
246
  * [audioInstance.buffered](#audioinstancebuffered)
243
247
  * [audioInstance.playing](#audioinstanceplaying)
244
248
  * [audioInstance.play([play])](#audioinstanceplayplay)
@@ -1914,6 +1918,15 @@ Helper function which maps each sample format to the sample value that correspon
1914
1918
  Helper function which calls the appropriate `read*` method of `Buffer` based on the format argument.
1915
1919
  For example, a call to `sdl.audio.readSample('f32', buffer, offset)` would be equivalent to `buffer.readFloatLE(offset)`.
1916
1920
 
1921
+ ### sdl.audio.readerName(format)
1922
+
1923
+ * `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
1924
+ * Returns: `<string>` The name of the read method.
1925
+
1926
+ Helper function which returns the name of the appropriate `read*` method of `Buffer` based on the format argument.
1927
+ Most of the time you will want to use [sdl.audio.readSample](#sdlaudioreadsampleformat-buffer-offset) directly.
1928
+ The method name is only really useful for passing to worker threads.
1929
+
1917
1930
  ### sdl.audio.writeSample(format, buffer, value[, offset])
1918
1931
 
1919
1932
  * `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
@@ -1925,6 +1938,15 @@ For example, a call to `sdl.audio.readSample('f32', buffer, offset)` would be eq
1925
1938
  Helper function which calls the appropriate `write*` method of `Buffer` based on the format argument.
1926
1939
  For example, a call to `sdl.audio.writeSample('f32', buffer, value, offset)` would be equivalent to `buffer.writeFloatLE(value, offset)`.
1927
1940
 
1941
+ ### sdl.audio.writerName(format)
1942
+
1943
+ * `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
1944
+ * Returns: `<string>` The name of the write method.
1945
+
1946
+ Helper function which returns the name of the appropriate `write*` method of `Buffer` based on the format argument.
1947
+ Most of the time you will want to use [sdl.audio.writeSample](#sdlaudiowritesampleformat-buffer-value-offset) directly.
1948
+ The method name is only really useful for passing to worker threads.
1949
+
1928
1950
  ### sdl.audio.devices
1929
1951
 
1930
1952
  * `<object>[]`
@@ -2056,6 +2078,14 @@ The sample value that corresponds to silence, based on the format the instance w
2056
2078
  Helper function which calls the appropriate `read*` method of `Buffer` based on the format the instance was opened with.
2057
2079
  For example, for an instance opened with the `'f32'` sample format, a call to `audioinstance.readSample(buffer, offset)` would be equivalent to `buffer.readFloatLE(offset)`.
2058
2080
 
2081
+ ### audioInstance.readerName
2082
+
2083
+ * `<string>`
2084
+
2085
+ The name of the appropriate `read*` method of `Buffer` based on the format the instance was opened with.
2086
+ Most of the time you will want to use [audioInstance.readSample](#audioinstancereadsamplebuffer-offset) directly.
2087
+ The method name is only really useful for passing to worker threads.
2088
+
2059
2089
  ### audioInstance.writeSample(buffer, value[, offset])
2060
2090
 
2061
2091
  * `buffer: <Buffer>` The buffer to write the sample to.
@@ -2066,6 +2096,14 @@ For example, for an instance opened with the `'f32'` sample format, a call to `a
2066
2096
  Helper function which calls the appropriate `write*` method of `Buffer` based on the format the instance was opened with.
2067
2097
  For example, for an instance opened with the `'f32'` sample format, a call to `audioinstance.writeSample(buffer, value, offset)` would be equivalent to `buffer.writeFloatLE(value, offset)`.
2068
2098
 
2099
+ ### audioInstance.writerName
2100
+
2101
+ * `<string>`
2102
+
2103
+ The name of the appropriate `write*` method of `Buffer` based on the format the instance was opened with.
2104
+ Most of the time you will want to use [audioInstance.writeSample](#audioinstancewritesamplebuffer-value-offset) directly.
2105
+ The method name is only really useful for passing to worker threads.
2106
+
2069
2107
  ### audioInstance.buffered
2070
2108
 
2071
2109
  * `<number>`
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0",
2
+ "version": "0.6.2",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -10,10 +10,6 @@
10
10
  "window",
11
11
  "screen",
12
12
  "video",
13
- "audio",
14
- "sound",
15
- "speaker",
16
- "mic",
17
13
  "input",
18
14
  "mouse",
19
15
  "keyboard",
@@ -21,6 +17,10 @@
21
17
  "controller",
22
18
  "gamepad",
23
19
  "rumble",
20
+ "audio",
21
+ "sound",
22
+ "speaker",
23
+ "mic",
24
24
  "clipboard",
25
25
  "game"
26
26
  ],
@@ -50,5 +50,8 @@
50
50
  "owner": "kmamal",
51
51
  "repo": "build-sdl",
52
52
  "version": "2.24.1"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^18.11.10"
53
56
  }
54
57
  }
@@ -50,6 +50,8 @@ class AudioInstance extends EventsViaPoll {
50
50
  this._minSampleValue = helper.minSampleValue
51
51
  this._maxSampleValue = helper.maxSampleValue
52
52
  this._zeroSampleValue = helper.zeroSampleValue
53
+ this._readerName = helper.readerName
54
+ this._writerName = helper.writerName
53
55
  this._reader = helper.reader
54
56
  this._writer = helper.writer
55
57
 
@@ -73,10 +75,14 @@ class AudioInstance extends EventsViaPoll {
73
75
  return this._reader.call(buffer, offset)
74
76
  }
75
77
 
78
+ get readerName () { return this._readerName }
79
+
76
80
  writeSample (buffer, value, offset) {
77
81
  return this._writer.call(buffer, value, offset)
78
82
  }
79
83
 
84
+ get writerName () { return this._writerName }
85
+
80
86
  get buffered () { return this._buffered }
81
87
 
82
88
  get playing () { return this._playing }
@@ -23,53 +23,53 @@ const floatLimits = {
23
23
 
24
24
  const AudioFormatHelpers = {
25
25
  s8: {
26
- reader: Buffer.prototype.readInt8,
27
- writer: Buffer.prototype.writeInt8,
26
+ readerName: 'readInt8',
27
+ writerName: 'writeInt8',
28
28
  ...signedLimits(8),
29
29
  },
30
30
  u8: {
31
- reader: Buffer.prototype.readUInt8,
32
- writer: Buffer.prototype.writeUInt8,
31
+ readerName: 'readUInt8',
32
+ writerName: 'writeUInt8',
33
33
  ...unsignedLimits(8),
34
34
  },
35
35
  s16lsb: {
36
- reader: Buffer.prototype.readInt16LE,
37
- writer: Buffer.prototype.writeInt16LE,
36
+ readerName: 'readInt16LE',
37
+ writerName: 'writeInt16LE',
38
38
  ...signedLimits(16),
39
39
  },
40
40
  s16msb: {
41
- reader: Buffer.prototype.readInt16BE,
42
- writer: Buffer.prototype.writeInt16BE,
41
+ readerName: 'readInt16BE',
42
+ writerName: 'writeInt16BE',
43
43
  ...signedLimits(16),
44
44
  },
45
45
  u16lsb: {
46
- reader: Buffer.prototype.readUInt16LE,
47
- writer: Buffer.prototype.writeUInt16LE,
46
+ readerName: 'readUInt16LE',
47
+ writerName: 'writeUInt16LE',
48
48
  ...unsignedLimits(16),
49
49
  },
50
50
  u16msb: {
51
- reader: Buffer.prototype.readUInt16BE,
52
- writer: Buffer.prototype.writeUInt16BE,
51
+ readerName: 'readUInt16BE',
52
+ writerName: 'writeUInt16BE',
53
53
  ...unsignedLimits(16),
54
54
  },
55
55
  s32lsb: {
56
- reader: Buffer.prototype.readInt32LE,
57
- writer: Buffer.prototype.writeInt32LE,
56
+ readerName: 'readInt32LE',
57
+ writerName: 'writeInt32LE',
58
58
  ...signedLimits(32),
59
59
  },
60
60
  s32msb: {
61
- reader: Buffer.prototype.readInt32BE,
62
- writer: Buffer.prototype.writeInt32BE,
61
+ readerName: 'readInt32BE',
62
+ writerName: 'writeInt32BE',
63
63
  ...signedLimits(32),
64
64
  },
65
65
  f32lsb: {
66
- reader: Buffer.prototype.readFloatLE,
67
- writer: Buffer.prototype.writeFloatLE,
66
+ readerName: 'readFloatLE',
67
+ writerName: 'writeFloatLE',
68
68
  ...floatLimits,
69
69
  },
70
70
  f32msb: {
71
- reader: Buffer.prototype.readFloatBE,
72
- writer: Buffer.prototype.writeFloatBE,
71
+ readerName: 'readFloatBE',
72
+ writerName: 'writeFloatBE',
73
73
  ...floatLimits,
74
74
  },
75
75
  }
@@ -91,4 +91,9 @@ if (Os.endianness() === 'LE') {
91
91
  AudioFormatHelpers.f32sys = AudioFormatHelpers.f32msb
92
92
  }
93
93
 
94
+ for (const helper of Object.values(AudioFormatHelpers)) {
95
+ helper.reader = Buffer.prototype[helper.readerName]
96
+ helper.writer = Buffer.prototype[helper.writerName]
97
+ }
98
+
94
99
  module.exports = { AudioFormatHelpers }
@@ -17,7 +17,7 @@ const audio = new class extends EventsViaPoll {
17
17
  }
18
18
 
19
19
  openDevice (device, options = {}) {
20
- return device.type === "recording"
20
+ return device.type === 'recording'
21
21
  ? new AudioRecordingInstance(device, options)
22
22
  : new AudioPlaybackInstance(device, options)
23
23
  }
@@ -31,9 +31,17 @@ const audio = new class extends EventsViaPoll {
31
31
  return AudioFormatHelpers[format].reader.call(buffer, offset)
32
32
  }
33
33
 
34
+ readerName (format) {
35
+ return AudioFormatHelpers[format].readerName
36
+ }
37
+
34
38
  writeSample (format, buffer, value, offset) {
35
39
  return AudioFormatHelpers[format].writer.call(buffer, value, offset)
36
40
  }
41
+
42
+ writerName (format) {
43
+ return AudioFormatHelpers[format].writerName
44
+ }
37
45
  }()
38
46
 
39
47
  module.exports = { audio }
@@ -164,7 +164,7 @@ const handleEvents = () => {
164
164
  if (!window) { continue }
165
165
 
166
166
  const { key } = event
167
- event.key = mapping[key] ?? key?.length === 1 ? key : null
167
+ event.key = mapping[key] ?? (key?.length === 1 ? key : null)
168
168
 
169
169
  if (Object.keys(event).length > 0) {
170
170
  window.emit(Enums.eventTypeNames[type], event)