DsdDopOutput

class DsdDopOutput(target: PcmOutput, channels: Int, slotBytes: Int, confirmedDop: Boolean) : PcmOutput(source)

Exact native DSD to DoP framing for an independently confirmed DoP route. Input is chronological interleaved bytes with the oldest bit in bit 7. One byte-frame can be held across writes; drain completes an incomplete final pair with the DSD idle byte 0x69 as its later byte, under the next marker. Position and latency use DSD byte-frames at the bit rate divided by eight.

Constructors

Link copied to clipboard
constructor(target: PcmOutput, channels: Int, slotBytes: Int, confirmedDop: Boolean)

Properties

Link copied to clipboard
open override val bitPerfect: StateFlow<BitPerfectState>

Whether the output is bit-perfect, and how well that can be known; see BitPerfectState.

Link copied to clipboard
open override val isDrained: Boolean

true once everything written before drain has played.

Link copied to clipboard
open override val latencyFrames: Long

Frames between the host and the DAC: what is buffered plus what is in flight.

Link copied to clipboard
open override val playedFrames: Long

Frames that have actually played since the start or the last flush, in the output's own frame rate. Silence inserted while paused or underrun does not count. Audible position is startPosition + playedFrames / frameRate.

Link copied to clipboard
open override val writableBytes: Int

How many bytes a writer should write now: the room up to the target depth, a whole number of frames. A pull loop writes this much and sleeps when it is 0. It is a target, not a hard limit.

Functions

Link copied to clipboard
open override fun close()

Stops the output and releases it. Safe to call again.

Link copied to clipboard
open override fun drain()

Declares the end of the audio: what is buffered plays out, including a tail shorter than the start threshold. Do not call it between tracks of a gapless sequence; keep writing instead. Writes fail until flush.

Link copied to clipboard
open override fun flush()

Discards everything buffered and resets playedFrames to 0. Use it for a seek, a stop, or a track the user picked; it keeps a deep buffer from costing responsiveness. On the direct USB output with DacConfig.cancelInFlightOnFlush (on by default), the output thread also asks the host controller to cancel the submitted transfers that carry music from before the flush, waits up to a second for them to be handed back (the stream fails if they are not), and sends silence until the ring refills. A transfer that completes before its cancellation takes effect still plays, and no time to silence is guaranteed. With the flag off, or on the managed output, audio already on the bus or in the platform's last buffer may still be heard.

Link copied to clipboard
open override fun pause()

Pauses output without discarding what is buffered. play continues exactly where it stopped. Audio already handed to the platform or the bus still plays out first (milliseconds).

Link copied to clipboard
open override fun play()

Starts or resumes output. A new stream starts by itself once enough audio is buffered.

Link copied to clipboard
open override fun write(buffer: ByteBuffer): Int

Writes whole frames from the buffer's position and advances the position by the bytes taken. Direct buffers are read in place; a heap buffer is copied. Returns the bytes taken, which can be less than buffer.remaining() (the output is full: keep the rest and try again), and 0 for a partial frame. On success the return value equals the position delta. Accepted source frames may be held in a converter before playback; use playedFrames for playback position. Keep the remaining buffer after a failure. For INVALID_ARGUMENT, correct the layout or padding before retrying; do not silently truncate or mask samples.