Class DtmfStream
- All Implemented Interfaces:
AutoCloseable,Iterator<DtmfTone>
DtmfDetector as an
Iterator over emitted DtmfTone values.
Callers wire a DtmfStream.SampleSource to an in-memory buffer, file reader,
or any other source of normalised double PCM samples, and iterate.
hasNext() pulls samples from the source until a tone becomes
available or the source signals end-of-stream; next() dequeues
the head of the buffered emissions.
Relationship to DtmfDetector (Requirement 7.5):
DtmfStream.fromSamples(samples, cfg) iterated to exhaustion
produces the same tones as a fresh DtmfDetector(cfg) fed
samples followed by DtmfDetector.flush(). The stream is a
re-packaging of the push API, not a separate detection implementation.
close() flushes the underlying detector and releases references
to the DtmfStream.SampleSource; it is idempotent and safe to call multiple
times, including from a try-with-resources block.
Instances are not thread-safe. One stream per consumer.
- Since:
- 2.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA source ofdoublePCM samples forfromSource(SampleSource, DtmfConfig). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Flush the underlying detector and release references to theDtmfStream.SampleSource.static DtmfStreamfromSamples(double[] samples, DtmfConfig config) Create aDtmfStreamover a pre-existingdouble[]sample buffer.static DtmfStreamfromSource(DtmfStream.SampleSource source, DtmfConfig config) Create aDtmfStreamthat pulls samples fromsource.booleanhasNext()next()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Method Details
-
fromSource
Create aDtmfStreamthat pulls samples fromsource.- Parameters:
source- source of PCM samples; non-nullconfig- detection configuration; non-null- Returns:
- a new stream
- Throws:
NullPointerException- if either argument isnull
-
fromSamples
Create aDtmfStreamover a pre-existingdouble[]sample buffer.The buffer is read sequentially exactly once; subsequent iteration past the end of the buffer triggers
DtmfStream.SampleSourceEOS.- Parameters:
samples- sample buffer; non-nullconfig- detection configuration; non-null- Returns:
- a new stream
- Throws:
NullPointerException- if either argument isnull
-
hasNext
public boolean hasNext()Pulls samples from the source, one read at a time, into the internal buffer; each read feeds the detector and any emitted tones are queued. Returns
trueas soon as the queue becomes non-empty; returnsfalseafter the source signals EOS,DtmfDetector.flush()has been called, and the queue is empty. -
next
- Specified by:
nextin interfaceIterator<DtmfTone>- Throws:
NoSuchElementException- if no further tones are available
-
close
public void close()Flush the underlying detector and release references to theDtmfStream.SampleSource. Idempotent: safe to call multiple times, safe to call after the iterator is already exhausted.- Specified by:
closein interfaceAutoCloseable
-