Class DtmfFileDecoder
AudioSources and DtmfDecoder.
DtmfFileDecoder is the glue between the file-I/O layer and the
format-agnostic dtmf-core decoder. Every overload opens (or
accepts) an AudioSource, reads the full stream into a normalised
double[], and forwards the buffer to
DtmfDecoder.decode(double[], DtmfConfig).
Auto-resolve
The file's declared sample rate — read from the openedAudioSource — takes precedence over the DtmfConfig the
caller supplied (Requirement 17). When source.sampleRate()
differs from config.sampleRate(), DtmfFileDecoder
internally rebuilds the config with the source's rate substituted in.
Every other field of the caller's config (tone/gap durations, detection
threshold, channel mode, window function, twist tolerances, confirmation
frames) is preserved verbatim. The analysis block size is not
copied; it is re-derived from the new rate via
BlockSizer.blockSizeFor(newRate) at build() time so the
effective bin width lands in [40, 60] Hz for the rate actually
on disk (Requirements 17.1, 17.2).
Because decoding runs at the source's rate, the DtmfTone
values returned from decode(...) carry
sampleRate = source.sampleRate() (Requirement 17.5). Callers who
need a Duration for a detected tone should use the
DtmfTone.startTime() / DtmfTone.endTime() helpers rather
than dividing by the DtmfConfig's rate.
Channel handling
Whensource.channelCount() == 2 and
config.channelMode() == MONO, the
interleaved left and right samples are averaged into a mono buffer before
invoking DtmfDecoder (Requirement 8.7). When
config.channelMode() is
STEREO_INDEPENDENT or
STEREO_DOWNMIX, the interleaved
buffer is forwarded to DtmfDecoder unchanged and
DtmfDecoder applies the configured mode (Requirement 8.8).
Unsupported inputs
- Channel counts greater than
2throwUnsupportedAudioFormatExceptionnaming the count and stating that only 1 and 2 are supported (Requirement 8.10). - A mono source paired with a stereo channel mode throws
UnsupportedAudioFormatExceptionnaming the mismatch and pointing the caller atChannelMode.MONO(Requirement 8.9). - A sample rate outside the supported
[4000, 192000]Hz range throwsUnsupportedAudioFormatExceptionnaming the rate and the range (Requirement 17.3).
Resource ownership
ThePath, InputStream, and URL overloads open
the AudioSource internally inside a try-with-resources so the
source is always closed before the method returns — on the normal path
and on any exceptional path (Requirement 8.11). The
decode(AudioSource, DtmfConfig) overload never closes the
caller-supplied source; ownership stays with the caller (Requirement
8.12).
Null-safety
Every public overload null-checks every parameter viaObjects.requireNonNull(Object, String) and throws
NullPointerException identifying the parameter (Requirements
8.13, 12.1).
Thread safety
DtmfFileDecoder is stateless and every method is static; calls
are safe to invoke concurrently from multiple threads on different
inputs.- Since:
- 2.1.0
- See Also:
-
AudioSourcesDtmfDecoderDtmfConfig
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<com.tino1b2be.dtmf.DtmfTone>decode(AudioSource source, com.tino1b2be.dtmf.DtmfConfig config) Decode the DTMF tones in an already-openedAudioSource.static List<com.tino1b2be.dtmf.DtmfTone>decode(InputStream stream, String hint, com.tino1b2be.dtmf.DtmfConfig config) Decode the DTMF tones instream.static List<com.tino1b2be.dtmf.DtmfTone>Decode the DTMF tones in the audio resource aturl.static List<com.tino1b2be.dtmf.DtmfTone>Decode the DTMF tones in the audio file atpath.
-
Method Details
-
decode
public static List<com.tino1b2be.dtmf.DtmfTone> decode(Path path, com.tino1b2be.dtmf.DtmfConfig config) throws IOException Decode the DTMF tones in the audio file atpath.The file is opened via
AudioSources.open(Path)— i.e. the registeredAudioSourceProviderthat scores highest on the file's header bytes handles the decode — and the resultingAudioSourceis closed before this method returns, whether the call succeeds or throws (Requirement 8.11).- Parameters:
path- file system path to the audio file; non-nullconfig- detection configuration; non-null. The file's declared sample rate takes precedence overconfig.sampleRate()(see the class-level auto-resolve notes).- Returns:
- the detected tones, in non-decreasing
startSampleorder - Throws:
NullPointerException- if any parameter isnullUnsupportedAudioFormatException- if no provider can decode the file, the file declares an unsupported channel count or sample rate, or the channel mode is incompatible with the sourceIOException- if an underlying I/O error occurs
-
decode
public static List<com.tino1b2be.dtmf.DtmfTone> decode(InputStream stream, String hint, com.tino1b2be.dtmf.DtmfConfig config) throws IOException Decode the DTMF tones instream.The stream is passed to
AudioSources.open(InputStream, String), which wraps non-markable streams in aBufferedInputStreambefore provider dispatch. The returnedAudioSourceis closed before this method returns (normal or exceptional); perAudioSources' contract, closing the source does not close the caller-suppliedstream(Requirement 8.11 / 4.10).- Parameters:
stream- audio byte stream; non-null. Caller retains ownership.hint- optional file-name / URL-path-segment / MIME-type hint; may benullconfig- detection configuration; non-null. The stream's declared sample rate takes precedence overconfig.sampleRate().- Returns:
- the detected tones, in non-decreasing
startSampleorder - Throws:
NullPointerException- ifstreamorconfigisnullUnsupportedAudioFormatException- seedecode(Path, DtmfConfig)IOException- if an underlying I/O error occurs
-
decode
public static List<com.tino1b2be.dtmf.DtmfTone> decode(URL url, com.tino1b2be.dtmf.DtmfConfig config) throws IOException Decode the DTMF tones in the audio resource aturl.Opens
url.openStream()viaAudioSources.open(URL), which derives a provider hint from the URL's last path segment and closes the URL-backed stream when the returnedAudioSourceis closed. TheAudioSourceis closed before this method returns (Requirement 8.11).- Parameters:
url- URL of the audio resource; non-nullconfig- detection configuration; non-null- Returns:
- the detected tones, in non-decreasing
startSampleorder - Throws:
NullPointerException- if any parameter isnullUnsupportedAudioFormatException- seedecode(Path, DtmfConfig)IOException- if an underlying I/O error occurs
-
decode
public static List<com.tino1b2be.dtmf.DtmfTone> decode(AudioSource source, com.tino1b2be.dtmf.DtmfConfig config) throws IOException Decode the DTMF tones in an already-openedAudioSource.Useful when the caller obtained the source via
AudioSources.opendirectly (e.g. to inspectsampleRate()ortotalFrames()first) or viaRawPcmAudioSource(caller has PCM bytes in memory).This overload never closes
source; ownership stays with the caller (Requirement 8.12). Callers who want the typical open-decode-close lifecycle should use one of thePath/InputStream/URLoverloads instead.- Parameters:
source- opened audio source; non-null. Not closed by this call.config- detection configuration; non-null- Returns:
- the detected tones, in non-decreasing
startSampleorder - Throws:
NullPointerException- if any parameter isnullUnsupportedAudioFormatException- if the source declares an unsupported channel count or sample rate, or the channel mode is incompatible with the sourceIOException- if an underlying I/O error occurs
-