1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 12:22:00 -05:00
sdrangel/wdsp/slew.cpp

208 lines
5.3 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* slew.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2023 Warren Pratt, NR0V
Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The author can be reached by email at
warren@wpratt.com
*/
#include "comm.hpp"
#include "slew.hpp"
#include "TXA.hpp"
namespace WDSP {
enum _USLEW
{
BEGIN,
WAIT,
UP,
ON
};
void USLEW::calc_uslew (USLEW *a)
{
int i;
2024-06-24 21:50:48 -04:00
float delta, theta;
2024-06-16 05:31:13 -04:00
a->runmode = 0;
a->state = BEGIN;
a->count = 0;
a->ndelup = (int)(a->tdelay * a->rate);
a->ntup = (int)(a->tupslew * a->rate);
2024-06-24 21:50:48 -04:00
a->cup = new float[a->ntup + 1]; // (float *) malloc0 ((a->ntup + 1) * sizeof (float));
delta = PI / (float)a->ntup;
2024-06-16 05:31:13 -04:00
theta = 0.0;
for (i = 0; i <= a->ntup; i++)
{
a->cup[i] = 0.5 * (1.0 - cos (theta));
theta += delta;
}
*a->ch_upslew &= ~((long)1); // InterlockedBitTestAndReset (a->ch_upslew, 0);
}
void USLEW::decalc_uslew (USLEW *a)
{
delete[] (a->cup);
}
2024-07-13 18:05:10 -04:00
USLEW* USLEW::create_uslew (
TXA *txa,
long *ch_upslew,
int size,
float* in,
float* out,
float rate,
float tdelay,
float tupslew
)
2024-06-16 05:31:13 -04:00
{
USLEW *a = new USLEW;
a->txa = txa;
a->ch_upslew = ch_upslew;
a->size = size;
a->in = in;
a->out = out;
a->rate = rate;
a->tdelay = tdelay;
a->tupslew = tupslew;
calc_uslew (a);
return a;
}
void USLEW::destroy_uslew (USLEW *a)
{
decalc_uslew (a);
delete (a);
}
void USLEW::flush_uslew (USLEW *a)
{
a->state = BEGIN;
a->runmode = 0;
*a->ch_upslew &= ~1L; //InterlockedBitTestAndReset (a->ch_upslew, 0);
}
void USLEW::xuslew (USLEW *a)
{
if (!a->runmode && TXA::UslewCheck (*a->txa))
a->runmode = 1;
long upslew = *a->ch_upslew;
*a->ch_upslew = 1L;
if (a->runmode && upslew) //_InterlockedAnd (a->ch_upslew, 1))
{
int i;
2024-06-24 21:50:48 -04:00
float I, Q;
2024-06-16 05:31:13 -04:00
for (i = 0; i < a->size; i++)
{
I = a->in[2 * i + 0];
Q = a->in[2 * i + 1];
switch (a->state)
{
case BEGIN:
a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0;
if ((I != 0.0) || (Q != 0.0))
{
if (a->ndelup > 0)
{
a->state = WAIT;
a->count = a->ndelup;
}
else if (a->ntup > 0)
{
a->state = UP;
a->count = a->ntup;
}
else
a->state = ON;
}
break;
case WAIT:
a->out[2 * i + 0] = 0.0;
a->out[2 * i + 1] = 0.0;
if (a->count-- == 0)
{
if (a->ntup > 0)
{
a->state = UP;
a->count = a->ntup;
}
else
a->state = ON;
}
break;
case UP:
a->out[2 * i + 0] = I * a->cup[a->ntup - a->count];
a->out[2 * i + 1] = Q * a->cup[a->ntup - a->count];
if (a->count-- == 0)
a->state = ON;
break;
case ON:
a->out[2 * i + 0] = I;
a->out[2 * i + 1] = Q;
*a->ch_upslew &= ~((long)1); // InterlockedBitTestAndReset (a->ch_upslew, 0);
a->runmode = 0;
break;
}
}
}
else if (a->out != a->in)
2024-07-16 17:15:13 -04:00
std::copy( a->in, a->in + a->size * 2, a->out);
2024-06-16 05:31:13 -04:00
}
2024-06-24 21:50:48 -04:00
void USLEW::setBuffers_uslew (USLEW *a, float* in, float* out)
2024-06-16 05:31:13 -04:00
{
a->in = in;
a->out = out;
}
void USLEW::setSamplerate_uslew (USLEW *a, int rate)
{
decalc_uslew (a);
a->rate = rate;
calc_uslew (a);
}
void USLEW::setSize_uslew (USLEW *a, int size)
{
a->size = size;
flush_uslew (a);
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
2024-06-24 21:50:48 -04:00
void USLEW::SetuSlewTime (TXA& txa, float time)
2024-06-16 05:31:13 -04:00
{
// NOTE: 'time' is in seconds
USLEW *a = txa.uslew;
2024-06-16 05:31:13 -04:00
decalc_uslew (a);
a->tupslew = time;
calc_uslew (a);
}
} // namespace WDSP