Package com.tino1b2be.dtmf
Class DtmfGenerator
java.lang.Object
com.tino1b2be.dtmf.DtmfGenerator
DTMF tone generation: turn a key sequence into normalised
double
PCM samples suitable for feeding back through
DtmfDecoder.decode(double[], DtmfConfig) or playing through an
audio output.
Per Requirements 11.1–11.5, the generator:
- accepts the sixteen DTMF keys
0-9,A-D,*,#plus lowercasea-d(normalised to uppercase); - produces each tone as
0.5 * (sin(2π·lowHz·n/Fs) + sin(2π·highHz·n/Fs))of lengthN = round(minimumToneDuration.toSeconds() * sampleRate); - inserts
M = round(minimumGapDuration.toSeconds() * sampleRate)samples of silence between consecutive tones, none after the final tone; - rejects any character outside the accepted set with
IllegalArgumentExceptionnaming the offending character and its index.
The 0.5 amplitude keeps the combined peak at 0.5, leaving
6 dB of headroom so callers can apply gain without clipping.
Total output length for a sequence of |s| characters is
|s| * N + max(0, |s| - 1) * M samples. An empty sequence produces
an empty double[].
The class is final with a private constructor; all entry points are static.
- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]generate(String sequence, DtmfConfig config) Generate a freshdouble[]holding the PCM samples forsequence.static intgenerateInto(String sequence, DtmfConfig config, double[] out, int offset) Generate PCM samples forsequenceinto a caller-supplied buffer starting atoffset.
-
Method Details
-
generate
Generate a freshdouble[]holding the PCM samples forsequence.- Parameters:
sequence- key sequence; non-null. May be emptyconfig- configuration supplying sample rate, minimum tone duration, and minimum gap duration; non-null- Returns:
- a newly allocated
double[]of length|sequence| * N + max(0, |sequence| - 1) * M - Throws:
NullPointerException- if either argument isnullIllegalArgumentException- ifsequencecontains any character outside the accepted set
-
generateInto
Generate PCM samples forsequenceinto a caller-supplied buffer starting atoffset. Returns the number of samples written.The caller is responsible for sizing
outto hold the full output:offset + |sequence| * N + max(0, |sequence| - 1) * M.- Parameters:
sequence- key sequence; non-null. May be emptyconfig- configuration supplying sample rate, minimum tone duration, and minimum gap duration; non-nullout- destination buffer; non-nulloffset- starting index intoout; must be non-negative and leave enough room for the full output- Returns:
- the number of samples written (equal to
|sequence| * N + max(0, |sequence| - 1) * M) - Throws:
NullPointerException- if any argument isnullIllegalArgumentException- ifsequencecontains any character outside the accepted set, or ifoffset < 0IndexOutOfBoundsException- ifoutis too small for the generated samples at the given offset
-