Ctrl+K

OggReader

Declaration

public sealed class Strawberry.Sound.OggReader

An ISoundReader that decodes OGG Vorbis audio files, compatible with the Strawberry engine's streaming system.

Remarks: This reader uses NVorbis (fully managed, no native dependencies) to decode OGG Vorbis files. It is compatible with WebAssembly and AOT compilation. Requires the NVorbis NuGet package: dotnet add package NVorbis

Implements: Strawberry.Sound.ISoundReader

Constructors

OggReader

Create an OggReader from a stream containing OGG Vorbis data. The stream is not closed when the reader is disposed.

void OggReader(Stream stream)

Parameters:

Name Type Description
stream System.IO.Stream Stream containing OGG Vorbis data. Must be seekable.

Properties

Stream

The original OGG file stream (read-only reference).

Stream Stream { get }

BitsPerSample

Always 16 (16-bit PCM output for OpenAL compatibility).

int BitsPerSample { get }

SampleRate

Output sample rate in Hz (from the OGG file header).

int SampleRate { get }

Channels

Output channel count (1 = mono, 2 = stereo).

int Channels { get }

DataSize

Total PCM data size in bytes, or int.MaxValue for unknown-length streams.

int DataSize { get }

Methods

Read

Read decoded PCM audio into the buffer. OGG Vorbis data is decoded on-demand and converted from float to 16-bit PCM.

int Read(byte[] buffer, int offset, int count)

Parameters:

Name Type Description
buffer System.Byte[]
offset System.Int32
count System.Int32

Returns: Number of bytes written into the buffer, or 0 if at end of data.

Seek

Seek to a byte offset in the decoded PCM data. The byte offset is converted to a sample frame position.

void Seek(long offset)

Parameters:

Name Type Description
offset System.Int64

ReadAll

Read the entire OGG file as decoded PCM data. Resets the reader to the beginning first, then decodes all audio.

byte[] ReadAll()

Dispose

void Dispose()