mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
update to snapshot spandsp-20080911.tar.gz
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9767 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
* License along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id: tone_generate.c,v 1.43 2008/07/02 14:48:26 steveu Exp $
|
||||
* $Id: tone_generate.c,v 1.46 2008/09/11 15:13:42 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@@ -72,15 +72,27 @@ void make_tone_gen_descriptor(tone_gen_descriptor_t *s,
|
||||
memset(s, 0, sizeof(*s));
|
||||
if (f1)
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
s->tone[0].phase_rate = dds_phase_rate((float) f1);
|
||||
if (f2 < 0)
|
||||
s->tone[0].phase_rate = -s->tone[0].phase_rate;
|
||||
s->tone[0].gain = dds_scaling_dbm0((float) l1);
|
||||
#else
|
||||
s->tone[0].phase_rate = dds_phase_ratef((float) f1);
|
||||
if (f2 < 0)
|
||||
s->tone[0].phase_rate = -s->tone[0].phase_rate;
|
||||
s->tone[0].gain = dds_scaling_dbm0f((float) l1);
|
||||
#endif
|
||||
}
|
||||
if (f2)
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
s->tone[1].phase_rate = dds_phase_rate((float) abs(f2));
|
||||
s->tone[1].gain = (f2 < 0) ? (float) 32767.0f*l2/100.0f : dds_scaling_dbm0((float) l2);
|
||||
#else
|
||||
s->tone[1].phase_rate = dds_phase_ratef((float) abs(f2));
|
||||
s->tone[1].gain = (f2 < 0) ? (float) l2/100.0f : dds_scaling_dbm0f((float) l2);
|
||||
#endif
|
||||
}
|
||||
|
||||
s->duration[0] = d1*SAMPLE_RATE/1000;
|
||||
@@ -118,7 +130,11 @@ int tone_gen(tone_gen_state_t *s, int16_t amp[], int max_samples)
|
||||
{
|
||||
int samples;
|
||||
int limit;
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
int16_t xamp;
|
||||
#else
|
||||
float xamp;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
if (s->current_section < 0)
|
||||
@@ -141,30 +157,49 @@ int tone_gen(tone_gen_state_t *s, int16_t amp[], int max_samples)
|
||||
{
|
||||
if (s->tone[0].phase_rate < 0)
|
||||
{
|
||||
/* Modulated tone */
|
||||
for ( ; samples < limit; samples++)
|
||||
{
|
||||
/* There must be two, and only two tones */
|
||||
/* There must be two, and only two, tones */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
xamp = ((int32_t) dds_mod(&s->phase[0], -s->tone[0].phase_rate, s->tone[0].gain, 0)
|
||||
*(32767 + (int32_t) dds_mod(&s->phase[1], s->tone[1].phase_rate, s->tone[1].gain, 0))) >> 15;
|
||||
amp[samples] = xamp;
|
||||
#else
|
||||
xamp = dds_modf(&s->phase[0], -s->tone[0].phase_rate, s->tone[0].gain, 0)
|
||||
*(1.0f + dds_modf(&s->phase[1], s->tone[1].phase_rate, s->tone[1].gain, 0));
|
||||
amp[samples] = (int16_t) lrintf(xamp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ; samples < limit; samples++)
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
xamp = 0;
|
||||
#else
|
||||
xamp = 0.0f;
|
||||
#endif
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (s->tone[i].phase_rate == 0)
|
||||
break;
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
xamp += dds_mod(&s->phase[i], s->tone[i].phase_rate, s->tone[i].gain, 0);
|
||||
#else
|
||||
xamp += dds_modf(&s->phase[i], s->tone[i].phase_rate, s->tone[i].gain, 0);
|
||||
#endif
|
||||
}
|
||||
/* Saturation of the answer is the right thing at this point.
|
||||
However, we are normally generating well controlled tones,
|
||||
that cannot clip. So, the overhead of doing saturation is
|
||||
a waste of valuable time. */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
amp[samples] = xamp;
|
||||
#else
|
||||
amp[samples] = (int16_t) lrintf(xamp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user