Class Sound
Namespace: ValveResourceFormat.ResourceTypes
Assembly: ValveResourceFormat.dll
Represents a sound resource containing audio data and metadata.
public class Sound : BlockInheritance
Inherited Members
Block.Type, Block.Offset, Block.Size, Block.Resource, Block.Read(BinaryReader), Block.ToString(), Block.WriteText(IndentedTextWriter), Block.Serialize(Stream)
Extension Methods
ResourceDataExtensions.AsKeyValueCollection(Block)
Properties
AudioFormat
Gets the bitstream encoding format.
public Sound.WaveAudioFormat AudioFormat { get; }Property Value
Bits
Gets the bit size.
public uint Bits { get; }Property Value
uint
Channels
Gets the number of channels. 1 for mono, 2 for stereo.
public uint Channels { get; }Property Value
uint
Duration
Gets the duration of the sound in seconds.
public float Duration { get; }Property Value
float
Header
Gets the WAVE format header data for ADPCM audio.
public byte[] Header { get; }Property Value
byte[]
LoopEnd
Gets the loop end position in samples.
public int LoopEnd { get; }Property Value
int
LoopStart
Gets the loop start position in samples.
public int LoopStart { get; }Property Value
int
SampleCount
Gets the total number of audio samples.
public uint SampleCount { get; }Property Value
uint
SampleRate
Gets the samples per second.
public uint SampleRate { get; }Property Value
uint
SampleSize
Gets the size of each audio sample in bytes.
public uint SampleSize { get; }Property Value
uint
Sentence
Gets the sentence data containing phoneme and emphasis information.
public Sentence? Sentence { get; }Property Value
SoundType
Gets the audio file type.
public Sound.AudioFileType SoundType { get; }Property Value
StreamingDataSize
Gets the size of the streaming audio data in bytes.
public uint StreamingDataSize { get; }Property Value
uint
Type
Gets the block type.
public override BlockType Type { get; }Property Value
Methods
GetInfoRows()
Returns human readable label and value pairs describing this sound: its duration, container and encoding, channel layout, sample rate, bit depth, sample count, loop points when the sound loops, and the size of the streaming audio data.
public IReadOnlyList<(string Label, string Value)> GetInfoRows()Returns
IReadOnlyList<(string Label, string Value)>
The metadata rows, in display order.
GetSound()
Returns fully playable sound data. In case of WAV files, header is automatically generated as Valve removes it when compiling.
public byte[] GetSound()Returns
byte[]
Byte array containing sound data.
GetSoundStream()
Returns fully playable sound data. In case of WAV files, header is automatically generated as Valve removes it when compiling.
public MemoryStream GetSoundStream()Returns
Memory stream containing sound data.
Read(BinaryReader)
Reads the block data from a binary reader.
public override void Read(BinaryReader reader)Parameters
reader BinaryReader
The binary reader to read from.
ReadStreamingData(Span<byte>)
Reads the raw streaming data as stored, without the container header Sound.GetSoundStream() synthesizes, into buffer, which must be exactly Sound.StreamingDataSize bytes. The format is given by Sound.SoundType, Sound.AudioFormat, Sound.Bits, Sound.Channels, Sound.SampleRate and (for ADPCM) Sound.Header, so decoders can use the data directly without a round-trip through a synthesized RIFF header.
public void ReadStreamingData(Span<byte> buffer)Parameters
buffer Span<byte>
Serialize(Stream)
Writes the block data in its binary form, as stored in a resource file. Blocks that do not support serialization throw NotImplementedException.
public override void Serialize(Stream stream)Parameters
stream Stream
The stream to write the block data to.
WriteText(IndentedTextWriter)
Writes a human readable text dump of the block contents. This is the output Block.ToString() returns.
public override void WriteText(IndentedTextWriter writer)Parameters
writer IndentedTextWriter
The writer that receives the text, which handles indentation.
Remarks
Outputs sound metadata including sample rate, format, and channel information.

