Record Class WaveFormat
- Record Components:
sampleRate- sample rate in Hertz; must be strictly positivechannelCount- number of interleaved channels in each frame; must be strictly positivebitDepth- bits per sample; must be one of{16, 24, 32, 64}bytesPerFrame- size of one complete frame in bytes; must equal(bitDepth / 8) * channelCountencoding- PCM integer or IEEE float; must be non-null and, whenWaveFormat.Encoding.IEEE_FLOAT, must be paired with a bit depth in{32, 64}dataStartByteOffset- absolute byte offset of thedatachunk payload within the enclosing RIFF form; must be non-negativedataSizeBytes- length of thedatachunk payload in bytes; must be non-negativetotalFrames- number of complete frames in the payload (dataSizeBytes / bytesPerFrame); must be non-negative
fmt chunk together with the
byte-range coordinates of its data payload. Populated by the RIFF
parser in this package and handed to
com.tino1b2be.dtmf.io.wav.WavAudioSource and
WavSampleReader so they can decode frames without re-reading the
header.
This record is the shared description of a validated, supported WAV stream. By the time one is constructed, the parser has already rejected compressed encodings (µ-law, A-law, ADPCM; Requirement 9.10), unsupported bit depths, and unsupported channel counts (Requirements 9.7, 9.8, 9.9). Every field below is therefore guaranteed to be internally consistent and in range.
Field-level contract:
sampleRate— in Hertz, the value of thefmtchunk'snSamplesPerSecfield. Must be strictly positive. The downstreamDtmfFileDecoderenforces the module-wide[4000, 192000]window; this record itself does not impose that upper bound because the parser needs to carry any positive rate through toWavAudioSource.sampleRate()before the higher-level guard runs.channelCount— fromnChannels. Must be strictly positive. In practice the parser restricts the set of decoded channel counts to1or2(Requirements 9.7, 9.8, 9.9); this record accepts any positive value so unit tests can exercise the underlying container format without threading the channel guard all the way down.bitDepth— fromwBitsPerSample, or fromwValidBitsPerSampleforWAVEFORMATEXTENSIBLE. Must be one of16,24,32, or64. Thedtmf-iomodule does not support8-bit PCM (Requirement 3.4).bytesPerFrame— from thefmtchunk'snBlockAlignfield, validated by the parser to equal(bitDepth / 8) * channelCount. This record re-validates the relationship so a bug in the parser cannot silently propagate a mismatch downstream.encoding— eitherWaveFormat.Encoding.PCM_SIGNED(fromwFormatTag = 0x0001or theKSDATAFORMAT_SUBTYPE_PCMGUID) orWaveFormat.Encoding.IEEE_FLOAT(fromwFormatTag = 0x0003orKSDATAFORMAT_SUBTYPE_IEEE_FLOAT).IEEE_FLOATis only valid at32or64bits — a constraint enforced by this record's compact constructor as a belt-and-braces check on top of the parser's own validation.dataStartByteOffset— absolute byte offset within the input stream or file where the payload of thedatachunk begins (i.e. immediately after its 8-byte"data" | sizeheader). Must be non-negative.WavAudioSourceuses this value as the seek anchor whencanSeek()returnstrue: a seek to framefsets the channel position todataStartByteOffset + f * bytesPerFrame.dataSizeBytes— length of thedatachunk payload in bytes, taken either from the chunk's 32-bit size field (standardRIFF/WAVE) or from theds64chunk's 64-bitdataSizefield (RF64). Must be non-negative.totalFrames—dataSizeBytes / bytesPerFrame, i.e. the number of complete frames the file is declared to contain. Must be non-negative. Stored eagerly (rather than derived on every call) becauseAudioSource.totalFrames()is on the hot metadata path forDtmfFileDecoder's block sizing.
This record is not part of the published API. It
lives in com.tino1b2be.dtmf.io.wav.internal, whose stability
contract (see the package Javadoc) explicitly allows breakage between
any two releases. It is public at the type level purely so
WavAudioSource and WavAudioSourceProvider — which
live in the parent package and cannot otherwise see a package-private
type here — can reach it; external callers MUST NOT depend on it.
- Since:
- 2.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumNumeric-format discriminator for a validated WAV stream. -
Constructor Summary
ConstructorsConstructorDescriptionWaveFormat(int sampleRate, int channelCount, int bitDepth, int bytesPerFrame, WaveFormat.Encoding encoding, long dataStartByteOffset, long dataSizeBytes, long totalFrames) Compact constructor validating every field against the class-level contract. -
Method Summary
Modifier and TypeMethodDescriptionintbitDepth()Returns the value of thebitDepthrecord component.intReturns the value of thebytesPerFramerecord component.intReturns the value of thechannelCountrecord component.longReturns the value of thedataSizeBytesrecord component.longReturns the value of thedataStartByteOffsetrecord component.encoding()Returns the value of theencodingrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of thesampleRaterecord component.final StringtoString()Returns a string representation of this record class.longReturns the value of thetotalFramesrecord component.
-
Constructor Details
-
WaveFormat
public WaveFormat(int sampleRate, int channelCount, int bitDepth, int bytesPerFrame, WaveFormat.Encoding encoding, long dataStartByteOffset, long dataSizeBytes, long totalFrames) Compact constructor validating every field against the class-level contract. This is the single source of truth for what constitutes a "supported WAV stream" insidedtmf-io-wav; the parser runs its own pre-flight checks against the raw header bytes, but the final, authoritative guard lives here so a test fixture that constructsWaveFormatdirectly is held to the same invariants as a real file.- Throws:
NullPointerException- ifencodingisnullIllegalArgumentException- if any numeric field is out of range, ifbytesPerFramedoes not equal(bitDepth / 8) * channelCount, or ifencodingisWaveFormat.Encoding.IEEE_FLOATwith a bit depth outside{32, 64}
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
sampleRate
public int sampleRate()Returns the value of thesampleRaterecord component.- Returns:
- the value of the
sampleRaterecord component
-
channelCount
public int channelCount()Returns the value of thechannelCountrecord component.- Returns:
- the value of the
channelCountrecord component
-
bitDepth
public int bitDepth()Returns the value of thebitDepthrecord component.- Returns:
- the value of the
bitDepthrecord component
-
bytesPerFrame
public int bytesPerFrame()Returns the value of thebytesPerFramerecord component.- Returns:
- the value of the
bytesPerFramerecord component
-
encoding
Returns the value of theencodingrecord component.- Returns:
- the value of the
encodingrecord component
-
dataStartByteOffset
public long dataStartByteOffset()Returns the value of thedataStartByteOffsetrecord component.- Returns:
- the value of the
dataStartByteOffsetrecord component
-
dataSizeBytes
public long dataSizeBytes()Returns the value of thedataSizeBytesrecord component.- Returns:
- the value of the
dataSizeBytesrecord component
-
totalFrames
public long totalFrames()Returns the value of thetotalFramesrecord component.- Returns:
- the value of the
totalFramesrecord component
-