2008-09-03 19:02:00 +00:00
|
|
|
/*
|
|
|
|
* SpanDSP - a series of DSP components for telephony
|
|
|
|
*
|
|
|
|
* v27ter_tx.c - ITU V.27ter modem transmit part
|
|
|
|
*
|
|
|
|
* Written by Steve Underwood <steveu@coppice.org>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Steve Underwood
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 2.1,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
2009-01-28 04:48:03 +00:00
|
|
|
#include "config.h"
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#if defined(HAVE_TGMATH_H)
|
|
|
|
#include <tgmath.h>
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_MATH_H)
|
|
|
|
#include <math.h>
|
|
|
|
#endif
|
2013-08-08 13:40:28 +00:00
|
|
|
#if defined(HAVE_STDBOOL_H)
|
|
|
|
#include <stdbool.h>
|
|
|
|
#else
|
|
|
|
#include "spandsp/stdbool.h"
|
|
|
|
#endif
|
2009-01-28 04:48:03 +00:00
|
|
|
#include "floating_fudge.h"
|
2008-09-03 19:02:00 +00:00
|
|
|
|
|
|
|
#include "spandsp/telephony.h"
|
2013-08-05 17:10:48 +00:00
|
|
|
#include "spandsp/alloc.h"
|
2009-02-03 18:50:18 +00:00
|
|
|
#include "spandsp/fast_convert.h"
|
2008-09-03 19:02:00 +00:00
|
|
|
#include "spandsp/logging.h"
|
|
|
|
#include "spandsp/complex.h"
|
|
|
|
#include "spandsp/vector_float.h"
|
|
|
|
#include "spandsp/complex_vector_float.h"
|
2010-07-24 19:29:44 +00:00
|
|
|
#include "spandsp/vector_int.h"
|
|
|
|
#include "spandsp/complex_vector_int.h"
|
2008-09-03 19:02:00 +00:00
|
|
|
#include "spandsp/async.h"
|
|
|
|
#include "spandsp/dds.h"
|
|
|
|
#include "spandsp/power_meter.h"
|
|
|
|
|
|
|
|
#include "spandsp/v27ter_tx.h"
|
|
|
|
|
2009-01-28 04:48:03 +00:00
|
|
|
#include "spandsp/private/logging.h"
|
|
|
|
#include "spandsp/private/v27ter_tx.h"
|
|
|
|
|
2008-09-03 19:02:00 +00:00
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2014-05-07 05:11:53 +00:00
|
|
|
#define FP_SCALE(x) FP_Q6_10(x)
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-21 13:17:11 +00:00
|
|
|
#define FP_SCALE(x) (x)
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-16 07:35:39 +00:00
|
|
|
#include "v27ter_tx_4800_rrc.h"
|
|
|
|
#include "v27ter_tx_2400_rrc.h"
|
|
|
|
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The nominal frequency of the carrier, in Hertz */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define CARRIER_NOMINAL_FREQ 1800.0f
|
|
|
|
|
|
|
|
/* Segments of the training sequence */
|
|
|
|
/* V.27ter defines a long and a short sequence. FAX doesn't use the
|
|
|
|
short sequence, so it is not implemented here. */
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The start of training segment 1, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SEG_1 0
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The start of training segment 2, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SEG_2 (V27TER_TRAINING_SEG_1 + 320)
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The start of training segment 3, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SEG_3 (V27TER_TRAINING_SEG_2 + 32)
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The start of training segment 4, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SEG_4 (V27TER_TRAINING_SEG_3 + 50)
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The start of training segment 5, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SEG_5 (V27TER_TRAINING_SEG_4 + 1074)
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The end of the training, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_END (V27TER_TRAINING_SEG_5 + 8)
|
2009-04-20 18:33:33 +00:00
|
|
|
/*! The end of the shutdown sequence, in symbols */
|
2008-09-03 19:02:00 +00:00
|
|
|
#define V27TER_TRAINING_SHUTDOWN_END (V27TER_TRAINING_END + 32)
|
|
|
|
|
|
|
|
static int fake_get_bit(void *user_data)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
|
|
|
static __inline__ int scramble(v27ter_tx_state_t *s, int in_bit)
|
|
|
|
{
|
|
|
|
int out_bit;
|
|
|
|
|
|
|
|
/* This scrambler is really quite messy to implement. There seems to be no efficient shortcut */
|
|
|
|
out_bit = (in_bit ^ (s->scramble_reg >> 5) ^ (s->scramble_reg >> 6)) & 1;
|
|
|
|
if (s->scrambler_pattern_count >= 33)
|
|
|
|
{
|
|
|
|
out_bit ^= 1;
|
|
|
|
s->scrambler_pattern_count = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((((s->scramble_reg >> 7) ^ out_bit) & ((s->scramble_reg >> 8) ^ out_bit) & ((s->scramble_reg >> 11) ^ out_bit) & 1))
|
|
|
|
s->scrambler_pattern_count = 0;
|
|
|
|
else
|
|
|
|
s->scrambler_pattern_count++;
|
|
|
|
}
|
|
|
|
s->scramble_reg = (s->scramble_reg << 1) | out_bit;
|
|
|
|
return out_bit;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
|
|
|
static __inline__ int get_scrambled_bit(v27ter_tx_state_t *s)
|
|
|
|
{
|
|
|
|
int bit;
|
2013-03-13 21:04:43 +00:00
|
|
|
|
2008-09-09 17:04:42 +00:00
|
|
|
if ((bit = s->current_get_bit(s->get_bit_user_data)) == SIG_STATUS_END_OF_DATA)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
|
|
|
/* End of real data. Switch to the fake get_bit routine, until we
|
|
|
|
have shut down completely. */
|
|
|
|
if (s->status_handler)
|
2008-09-09 17:04:42 +00:00
|
|
|
s->status_handler(s->status_user_data, SIG_STATUS_END_OF_DATA);
|
2008-09-03 19:02:00 +00:00
|
|
|
s->current_get_bit = fake_get_bit;
|
2013-08-08 13:40:28 +00:00
|
|
|
s->in_training = true;
|
2008-09-03 19:02:00 +00:00
|
|
|
bit = 1;
|
|
|
|
}
|
|
|
|
return scramble(s, bit);
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
|
|
|
static complexi16_t getbaud(v27ter_tx_state_t *s)
|
|
|
|
#else
|
|
|
|
static complexf_t getbaud(v27ter_tx_state_t *s)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
static const int phase_steps_4800[8] =
|
|
|
|
{
|
|
|
|
1, 0, 2, 3, 6, 7, 5, 4
|
|
|
|
};
|
|
|
|
static const int phase_steps_2400[4] =
|
|
|
|
{
|
|
|
|
0, 2, 6, 4
|
|
|
|
};
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2009-01-28 04:48:03 +00:00
|
|
|
static const complexi16_t zero = {0, 0};
|
2012-07-21 13:17:11 +00:00
|
|
|
static const complexi16_t constellation[8] =
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-21 13:17:11 +00:00
|
|
|
static const complexf_t zero = {0.0f, 0.0f};
|
2008-09-03 19:02:00 +00:00
|
|
|
static const complexf_t constellation[8] =
|
2012-07-21 13:17:11 +00:00
|
|
|
#endif
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
2012-07-21 13:17:11 +00:00
|
|
|
{FP_SCALE( 1.414f), FP_SCALE( 0.0f)}, /* 0deg */
|
|
|
|
{FP_SCALE( 1.0f), FP_SCALE( 1.0f)}, /* 45deg */
|
|
|
|
{FP_SCALE( 0.0f), FP_SCALE( 1.414f)}, /* 90deg */
|
|
|
|
{FP_SCALE(-1.0f), FP_SCALE( 1.0f)}, /* 135deg */
|
|
|
|
{FP_SCALE(-1.414f), FP_SCALE( 0.0f)}, /* 180deg */
|
|
|
|
{FP_SCALE(-1.0f), FP_SCALE(-1.0f)}, /* 225deg */
|
|
|
|
{FP_SCALE( 0.0f), FP_SCALE(-1.414f)}, /* 270deg */
|
|
|
|
{FP_SCALE( 1.0f), FP_SCALE(-1.0f)} /* 315deg */
|
2008-09-03 19:02:00 +00:00
|
|
|
};
|
|
|
|
int bits;
|
|
|
|
|
|
|
|
if (s->in_training)
|
|
|
|
{
|
2013-03-14 13:22:51 +00:00
|
|
|
/* Send the training sequence */
|
2008-09-03 19:02:00 +00:00
|
|
|
if (++s->training_step <= V27TER_TRAINING_SEG_5)
|
|
|
|
{
|
|
|
|
if (s->training_step <= V27TER_TRAINING_SEG_4)
|
|
|
|
{
|
|
|
|
if (s->training_step <= V27TER_TRAINING_SEG_2)
|
|
|
|
{
|
|
|
|
/* Segment 1: Unmodulated carrier (talker echo protection) */
|
|
|
|
return constellation[0];
|
|
|
|
}
|
|
|
|
if (s->training_step <= V27TER_TRAINING_SEG_3)
|
|
|
|
{
|
|
|
|
/* Segment 2: Silence */
|
2009-01-28 04:48:03 +00:00
|
|
|
return zero;
|
2008-09-03 19:02:00 +00:00
|
|
|
}
|
|
|
|
/* Segment 3: Regular reversals... */
|
|
|
|
s->constellation_state = (s->constellation_state + 4) & 7;
|
|
|
|
return constellation[s->constellation_state];
|
|
|
|
}
|
|
|
|
/* Segment 4: Scrambled reversals... */
|
|
|
|
/* Apply the 1 + x^-6 + x^-7 scrambler. We want every third
|
|
|
|
bit from the scrambler. */
|
|
|
|
bits = get_scrambled_bit(s) << 2;
|
|
|
|
get_scrambled_bit(s);
|
|
|
|
get_scrambled_bit(s);
|
|
|
|
s->constellation_state = (s->constellation_state + bits) & 7;
|
|
|
|
return constellation[s->constellation_state];
|
|
|
|
}
|
|
|
|
/* We should be in the block of test ones, or shutdown ones, if we get here. */
|
|
|
|
/* There is no graceful shutdown procedure defined for V.27ter. Just
|
|
|
|
send some ones, to ensure we get the real data bits through, even
|
|
|
|
with bad ISI. */
|
|
|
|
if (s->training_step == V27TER_TRAINING_END + 1)
|
|
|
|
{
|
|
|
|
/* End of the last segment - segment 5: All ones */
|
|
|
|
/* Switch from the fake get_bit routine, to the user supplied real
|
|
|
|
one, and we are up and running. */
|
|
|
|
s->current_get_bit = s->get_bit;
|
2013-08-08 13:40:28 +00:00
|
|
|
s->in_training = false;
|
2008-09-03 19:02:00 +00:00
|
|
|
}
|
|
|
|
if (s->training_step == V27TER_TRAINING_SHUTDOWN_END)
|
|
|
|
{
|
|
|
|
if (s->status_handler)
|
2008-09-09 17:04:42 +00:00
|
|
|
s->status_handler(s->status_user_data, SIG_STATUS_SHUTDOWN_COMPLETE);
|
2008-09-03 19:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 4800bps uses 8 phases. 2400bps uses 4 phases. */
|
|
|
|
if (s->bit_rate == 4800)
|
|
|
|
{
|
|
|
|
bits = get_scrambled_bit(s);
|
|
|
|
bits = (bits << 1) | get_scrambled_bit(s);
|
|
|
|
bits = (bits << 1) | get_scrambled_bit(s);
|
|
|
|
bits = phase_steps_4800[bits];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bits = get_scrambled_bit(s);
|
|
|
|
bits = (bits << 1) | get_scrambled_bit(s);
|
|
|
|
bits = phase_steps_2400[bits];
|
|
|
|
}
|
|
|
|
s->constellation_state = (s->constellation_state + bits) & 7;
|
|
|
|
return constellation[s->constellation_state];
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-06-02 14:42:16 +00:00
|
|
|
SPAN_DECLARE_NONSTD(int) v27ter_tx(v27ter_tx_state_t *s, int16_t amp[], int len)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2012-07-20 23:18:27 +00:00
|
|
|
complexi16_t v;
|
|
|
|
complexi32_t x;
|
|
|
|
complexi32_t z;
|
|
|
|
int16_t iamp;
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-20 23:18:27 +00:00
|
|
|
complexf_t v;
|
2008-09-03 19:02:00 +00:00
|
|
|
complexf_t x;
|
|
|
|
complexf_t z;
|
2012-07-20 23:18:27 +00:00
|
|
|
float famp;
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
int sample;
|
|
|
|
|
|
|
|
if (s->training_step >= V27TER_TRAINING_SHUTDOWN_END)
|
|
|
|
{
|
|
|
|
/* Once we have sent the shutdown symbols, we stop sending completely. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* The symbol rates for the two bit rates are different. This makes it difficult to
|
|
|
|
merge both generation procedures into a single efficient loop. We do not bother
|
|
|
|
trying. We use two independent loops, filter coefficients, etc. */
|
|
|
|
if (s->bit_rate == 4800)
|
|
|
|
{
|
|
|
|
for (sample = 0; sample < len; sample++)
|
|
|
|
{
|
|
|
|
if (++s->baud_phase >= 5)
|
|
|
|
{
|
|
|
|
s->baud_phase -= 5;
|
2012-07-20 23:18:27 +00:00
|
|
|
v = getbaud(s);;
|
|
|
|
s->rrc_filter_re[s->rrc_filter_step] = v.re;
|
|
|
|
s->rrc_filter_im[s->rrc_filter_step] = v.im;
|
2008-09-03 19:02:00 +00:00
|
|
|
if (++s->rrc_filter_step >= V27TER_TX_FILTER_STEPS)
|
|
|
|
s->rrc_filter_step = 0;
|
|
|
|
}
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2012-07-20 23:18:27 +00:00
|
|
|
/* Root raised cosine pulse shaping at baseband */
|
|
|
|
x.re = vec_circular_dot_prodi16(s->rrc_filter_re, tx_pulseshaper_4800[TX_PULSESHAPER_4800_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step) >> (10 + 4);
|
|
|
|
x.im = vec_circular_dot_prodi16(s->rrc_filter_im, tx_pulseshaper_4800[TX_PULSESHAPER_4800_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step) >> (10 + 4);
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Now create and modulate the carrier */
|
2012-07-20 23:18:27 +00:00
|
|
|
z = dds_complexi32(&s->carrier_phase, s->carrier_phase_rate);
|
|
|
|
iamp = ((int32_t) x.re*z.re - x.im*z.im) >> 15;
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Don't bother saturating. We should never clip. */
|
2012-07-20 23:18:27 +00:00
|
|
|
amp[sample] = (int16_t) (((int32_t) iamp*s->gain_4800) >> 11);
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-20 23:18:27 +00:00
|
|
|
/* Root raised cosine pulse shaping at baseband */
|
|
|
|
x.re = vec_circular_dot_prodf(s->rrc_filter_re, tx_pulseshaper_4800[TX_PULSESHAPER_4800_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step);
|
|
|
|
x.im = vec_circular_dot_prodf(s->rrc_filter_im, tx_pulseshaper_4800[TX_PULSESHAPER_4800_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step);
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Now create and modulate the carrier */
|
2012-07-20 23:18:27 +00:00
|
|
|
z = dds_complexf(&s->carrier_phase, s->carrier_phase_rate);
|
|
|
|
famp = x.re*z.re - x.im*z.im;
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Don't bother saturating. We should never clip. */
|
2012-07-20 23:18:27 +00:00
|
|
|
amp[sample] = (int16_t) lfastrintf(famp*s->gain_4800);
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (sample = 0; sample < len; sample++)
|
|
|
|
{
|
|
|
|
if ((s->baud_phase += 3) >= 20)
|
|
|
|
{
|
|
|
|
s->baud_phase -= 20;
|
2012-07-20 23:18:27 +00:00
|
|
|
v = getbaud(s);
|
|
|
|
s->rrc_filter_re[s->rrc_filter_step] = v.re;
|
|
|
|
s->rrc_filter_im[s->rrc_filter_step] = v.im;
|
2008-09-03 19:02:00 +00:00
|
|
|
if (++s->rrc_filter_step >= V27TER_TX_FILTER_STEPS)
|
|
|
|
s->rrc_filter_step = 0;
|
|
|
|
}
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2012-07-20 23:18:27 +00:00
|
|
|
/* Root raised cosine pulse shaping at baseband */
|
|
|
|
x.re = vec_circular_dot_prodi16(s->rrc_filter_re, tx_pulseshaper_2400[TX_PULSESHAPER_2400_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step) >> (10 + 4);
|
|
|
|
x.im = vec_circular_dot_prodi16(s->rrc_filter_im, tx_pulseshaper_2400[TX_PULSESHAPER_2400_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step) >> (10 + 4);
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Now create and modulate the carrier */
|
2012-07-20 23:18:27 +00:00
|
|
|
z = dds_complexi32(&s->carrier_phase, s->carrier_phase_rate);
|
|
|
|
iamp = ((int32_t) x.re*z.re - x.im*z.im) >> 15;
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Don't bother saturating. We should never clip. */
|
2012-07-20 23:18:27 +00:00
|
|
|
amp[sample] = (int16_t) (((int32_t) iamp*s->gain_2400) >> 11);
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-20 23:18:27 +00:00
|
|
|
/* Root raised cosine pulse shaping at baseband */
|
|
|
|
x.re = vec_circular_dot_prodf(s->rrc_filter_re, tx_pulseshaper_2400[TX_PULSESHAPER_2400_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step);
|
|
|
|
x.im = vec_circular_dot_prodf(s->rrc_filter_im, tx_pulseshaper_2400[TX_PULSESHAPER_2400_COEFF_SETS - 1 - s->baud_phase], V27TER_TX_FILTER_STEPS, s->rrc_filter_step);
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Now create and modulate the carrier */
|
2012-07-20 23:18:27 +00:00
|
|
|
z = dds_complexf(&s->carrier_phase, s->carrier_phase_rate);
|
|
|
|
famp = x.re*z.re - x.im*z.im;
|
2008-09-03 19:02:00 +00:00
|
|
|
/* Don't bother saturating. We should never clip. */
|
2012-07-20 23:18:27 +00:00
|
|
|
amp[sample] = (int16_t) lfastrintf(famp*s->gain_2400);
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-02-02 21:36:29 +00:00
|
|
|
SPAN_DECLARE(void) v27ter_tx_power(v27ter_tx_state_t *s, float power)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
2012-07-20 23:18:27 +00:00
|
|
|
float gain;
|
2008-09-03 19:02:00 +00:00
|
|
|
|
2012-07-20 23:18:27 +00:00
|
|
|
gain = powf(10.0f, (power - DBM0_MAX_POWER)/20.0f)*32768.0f;
|
2008-09-03 19:02:00 +00:00
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2012-07-20 23:18:27 +00:00
|
|
|
s->gain_2400 = (int16_t) (gain/TX_PULSESHAPER_2400_GAIN);
|
|
|
|
s->gain_4800 = (int16_t) (gain/TX_PULSESHAPER_4800_GAIN);
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-20 23:18:27 +00:00
|
|
|
s->gain_2400 = gain/TX_PULSESHAPER_2400_GAIN;
|
|
|
|
s->gain_4800 = gain/TX_PULSESHAPER_4800_GAIN;
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-02-02 21:36:29 +00:00
|
|
|
SPAN_DECLARE(void) v27ter_tx_set_get_bit(v27ter_tx_state_t *s, get_bit_func_t get_bit, void *user_data)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
|
|
|
if (s->get_bit == s->current_get_bit)
|
|
|
|
s->current_get_bit = get_bit;
|
|
|
|
s->get_bit = get_bit;
|
|
|
|
s->get_bit_user_data = user_data;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2011-07-02 06:45:27 +00:00
|
|
|
SPAN_DECLARE(void) v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_status_func_t handler, void *user_data)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
|
|
|
s->status_handler = handler;
|
|
|
|
s->status_user_data = user_data;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-02-02 21:36:29 +00:00
|
|
|
SPAN_DECLARE(logging_state_t *) v27ter_tx_get_logging_state(v27ter_tx_state_t *s)
|
2009-01-28 04:48:03 +00:00
|
|
|
{
|
|
|
|
return &s->logging;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2013-08-08 13:40:28 +00:00
|
|
|
SPAN_DECLARE(int) v27ter_tx_restart(v27ter_tx_state_t *s, int bit_rate, bool tep)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
|
|
|
if (bit_rate != 4800 && bit_rate != 2400)
|
|
|
|
return -1;
|
|
|
|
s->bit_rate = bit_rate;
|
|
|
|
#if defined(SPANDSP_USE_FIXED_POINT)
|
2012-07-20 23:18:27 +00:00
|
|
|
vec_zeroi16(s->rrc_filter_re, sizeof(s->rrc_filter_re)/sizeof(s->rrc_filter_re[0]));
|
|
|
|
vec_zeroi16(s->rrc_filter_im, sizeof(s->rrc_filter_im)/sizeof(s->rrc_filter_im[0]));
|
2008-09-03 19:02:00 +00:00
|
|
|
#else
|
2012-07-20 23:18:27 +00:00
|
|
|
vec_zerof(s->rrc_filter_re, sizeof(s->rrc_filter_re)/sizeof(s->rrc_filter_re[0]));
|
|
|
|
vec_zerof(s->rrc_filter_im, sizeof(s->rrc_filter_im)/sizeof(s->rrc_filter_im[0]));
|
2008-09-03 19:02:00 +00:00
|
|
|
#endif
|
|
|
|
s->rrc_filter_step = 0;
|
|
|
|
s->scramble_reg = 0x3C;
|
|
|
|
s->scrambler_pattern_count = 0;
|
2013-08-08 13:40:28 +00:00
|
|
|
s->in_training = true;
|
2008-09-03 19:02:00 +00:00
|
|
|
s->training_step = (tep) ? V27TER_TRAINING_SEG_1 : V27TER_TRAINING_SEG_2;
|
|
|
|
s->carrier_phase = 0;
|
|
|
|
s->baud_phase = 0;
|
|
|
|
s->constellation_state = 0;
|
|
|
|
s->current_get_bit = fake_get_bit;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2013-08-08 13:40:28 +00:00
|
|
|
SPAN_DECLARE(v27ter_tx_state_t *) v27ter_tx_init(v27ter_tx_state_t *s, int bit_rate, bool tep, get_bit_func_t get_bit, void *user_data)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
2009-04-28 14:42:18 +00:00
|
|
|
switch (bit_rate)
|
|
|
|
{
|
|
|
|
case 4800:
|
|
|
|
case 2400:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-03 19:02:00 +00:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
2013-08-05 17:10:48 +00:00
|
|
|
if ((s = (v27ter_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
|
2008-09-03 19:02:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(s, 0, sizeof(*s));
|
|
|
|
span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
|
|
|
|
span_log_set_protocol(&s->logging, "V.27ter TX");
|
|
|
|
s->get_bit = get_bit;
|
|
|
|
s->get_bit_user_data = user_data;
|
|
|
|
s->carrier_phase_rate = dds_phase_ratef(CARRIER_NOMINAL_FREQ);
|
|
|
|
v27ter_tx_power(s, -14.0f);
|
|
|
|
v27ter_tx_restart(s, bit_rate, tep);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-02-20 18:22:32 +00:00
|
|
|
SPAN_DECLARE(int) v27ter_tx_release(v27ter_tx_state_t *s)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
|
2009-02-02 21:36:29 +00:00
|
|
|
SPAN_DECLARE(int) v27ter_tx_free(v27ter_tx_state_t *s)
|
2008-09-03 19:02:00 +00:00
|
|
|
{
|
2013-08-05 17:10:48 +00:00
|
|
|
span_free(s);
|
2008-09-03 19:02:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*- End of function --------------------------------------------------------*/
|
|
|
|
/*- End of file ------------------------------------------------------------*/
|