diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2012-03-14 10:48:46 +0100 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2016-09-12 15:51:18 -0600 |
commit | b9700ddb2d86d60d003f8cc7d40235a6eed9a49e (patch) | |
tree | 788f28bb3771585f92b1d2e300b37214fd6580e2 /src/rtfwk/common.c | |
parent | a8b5bf1a9c4e6e05f95a1825398f405795f6fa79 (diff) |
[hack] Add first attempt at live stream processing
rtfwk: Create a new rxfwk subdir to contain the 'RealTime framework' files
So that other apps can re-use it. Note that it's not part of the gmr1
lib proper and so include files are in that dir and not installed.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'src/rtfwk/common.c')
-rw-r--r-- | src/rtfwk/common.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/rtfwk/common.c b/src/rtfwk/common.c new file mode 100644 index 0000000..cf37a9d --- /dev/null +++ b/src/rtfwk/common.c @@ -0,0 +1,75 @@ +/* GMR-1 RT framework common functions */ + +/* (C) 2011-2016 by Sylvain Munaut <tnt@246tNt.com> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <complex.h> +#include <errno.h> + +#include <osmocom/dsp/cxvec.h> +#include <osmocom/dsp/cxvec_math.h> + +#include <osmocom/gmr1/sdr/defs.h> +#include <osmocom/gmr1/sdr/pi4cxpsk.h> + +#include "common.h" + + +int +win_map(struct osmo_cxvec *win, + float complex *data, int data_len, + int begin, int win_len) +{ + if ((begin + win_len) > data_len) + return -1; + + osmo_cxvec_init_from_data(win, &data[begin], win_len); + + return 0; +} + +int +burst_map(struct osmo_cxvec *burst, + float complex *data, int data_len, int base_align, int sps, + struct gmr1_pi4cxpsk_burst *burst_type, int tn, int win) +{ + int begin, len; + int etoa; + + etoa = win >> 1; + begin = base_align + (sps * tn * 39) - etoa; + len = (burst_type->len * sps) + win; + + if ((begin < 0) || ((begin + len) > data_len)) + return -EIO; + + osmo_cxvec_init_from_data(burst, &data[begin], len); + + return etoa; +} + +float +burst_energy(struct osmo_cxvec *burst) +{ + int i; + int b = (burst->len >> 5); /* exclude the borders */ + float e = 0.0f; + for (i=b; i<burst->len-b; i++) + e += osmo_normsqf(burst->data[i]); + e /= burst->len; + return e; +} |