|
|
|
@ -35,8 +35,43 @@ INLINE double freq2iter(unsigned int hz, unsigned int sample_rate) { |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
void dtmf_samples(void *buf, unsigned long offset, unsigned long num, unsigned int event, unsigned int volume, |
|
|
|
unsigned int sample_rate) |
|
|
|
// only packed audio supported |
|
|
|
|
|
|
|
#define freq_samples_x(type, mult) \ |
|
|
|
INLINE void freq_samples_ ## type(type *samples, unsigned long offset, unsigned long num, unsigned int prim_freq, \ |
|
|
|
unsigned int sec_freq, unsigned int volume, unsigned int sample_rate, unsigned int channels) \ |
|
|
|
{ \ |
|
|
|
if (!channels) \ |
|
|
|
channels = 1; \ |
|
|
|
/* XXX initialise/save these when the DTMF event starts */ \ |
|
|
|
double vol = pow(1.122018, volume) * 2.0; \ |
|
|
|
\ |
|
|
|
double prim_iter = freq2iter(prim_freq, sample_rate); \ |
|
|
|
double sec_iter = sec_freq ? freq2iter(sec_freq, sample_rate) : 0; \ |
|
|
|
\ |
|
|
|
num += offset; /* end here */ \ |
|
|
|
while (offset < num) { \ |
|
|
|
double prim = sin(prim_iter * offset) / vol; \ |
|
|
|
type sample; \ |
|
|
|
if (!sec_freq) \ |
|
|
|
sample = prim * mult; \ |
|
|
|
else { \ |
|
|
|
double sec = sin(sec_iter * offset) / vol; \ |
|
|
|
sample = prim * mult + sec * mult; \ |
|
|
|
} \ |
|
|
|
for (unsigned int ch = 0; ch < channels; ch++) \ |
|
|
|
*samples++ = sample; \ |
|
|
|
offset++; \ |
|
|
|
} \ |
|
|
|
} |
|
|
|
|
|
|
|
freq_samples_x(int16_t, 32767.0) |
|
|
|
freq_samples_x(int32_t, 2147483647.0) |
|
|
|
freq_samples_x(double, 1.0) |
|
|
|
freq_samples_x(float, 1.0) |
|
|
|
|
|
|
|
void dtmf_samples_int16_t_mono(void *buf, unsigned long offset, unsigned long num, unsigned int event, |
|
|
|
unsigned int volume, unsigned int sample_rate) |
|
|
|
{ |
|
|
|
int16_t *samples = buf; |
|
|
|
const struct dtmf_freq *df; |
|
|
|
@ -54,18 +89,5 @@ void dtmf_samples(void *buf, unsigned long offset, unsigned long num, unsigned i |
|
|
|
} |
|
|
|
df = &dtmf_freqs[event]; |
|
|
|
|
|
|
|
// XXX initialise/save these when the DTMF event starts |
|
|
|
double vol = pow(1.122018, volume) * 2.0; |
|
|
|
|
|
|
|
double prim_freq = freq2iter(df->prim, sample_rate); |
|
|
|
double sec_freq = freq2iter(df->sec, sample_rate); |
|
|
|
|
|
|
|
num += offset; // end here |
|
|
|
while (offset < num) { |
|
|
|
double prim = sin(prim_freq * offset) / vol; |
|
|
|
double sec = sin(sec_freq * offset) / vol; |
|
|
|
int16_t sample = prim * 32767.0 + sec * 32767.0; |
|
|
|
*samples++ = sample; |
|
|
|
offset++; |
|
|
|
} |
|
|
|
freq_samples_int16_t(samples, offset, num, df->prim, df->sec, volume, sample_rate, 1); |
|
|
|
} |