Skip to main content

ArcadeSound

caution

This service is experimental and may change in the future.

A sound playing device.

This is typically run over an SPI connection, not regular single-wire Jacdac.

import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()

Commands

play

Play samples, which are single channel, signed 16-bit little endian values.

arcadeSound.play(samples: Buffer): Promise<void>

Registers

sampleRate

Get or set playback sample rate (in samples per second). If you set it, read it back, as the value may be rounded up or down.

  • type: Register<number> (packing format u22.10)

  • read and write

import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()
// ...
const value = await arcadeSound.sampleRate.read()
await arcadeSound.sampleRate.write(value)
  • track incoming values
import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()
// ...
arcadeSound.sampleRate.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

bufferSize

The size of the internal audio buffer.

  • type: Register<number> (packing format u32)

  • constant: the register value will not change (until the next reset)

  • read only

import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()
// ...
const value = await arcadeSound.bufferSize.read()
note

write and read will block until a server is bound to the client.

bufferPending

How much data is still left in the buffer to play. Clients should not send more data than buffer_size - buffer_pending, but can keep the buffer_pending as low as they want to ensure low latency of audio playback.

  • type: Register<number> (packing format u32)

  • read only

import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()
// ...
const value = await arcadeSound.bufferPending.read()
  • track incoming values
import { ArcadeSound } from "@devicescript/core"

const arcadeSound = new ArcadeSound()
// ...
arcadeSound.bufferPending.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.