mirror of https://gerrit.osmocom.org/libosmocore
coding: add gsm0503_detect_a[fh]s_dtx_frame2()
The new functions accept an additional mode_id poiner, which is currently set for the following frames: AFS_ONSET, AHS_ONSET, AHS_SID_FIRST_P2 with N * 16 - M bit pattern. Also, the new API accepts soft-bits instead of hard-bits. Converting bits from soft to hard is now performed internally. Change-Id: Ibcac395f800bb64150c97fcdaca3523ecfc5fcee Related: OS#5570
This commit is contained in:
parent
fe1dcebe3a
commit
cc4213e927
|
@ -34,7 +34,14 @@ static inline const char *gsm0503_amr_dtx_frame_name(enum gsm0503_amr_dtx_frames
|
||||||
return get_value_string(gsm0503_amr_dtx_frame_names, frame);
|
return get_value_string(gsm0503_amr_dtx_frame_names, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits);
|
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits)
|
||||||
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits);
|
OSMO_DEPRECATED("Use gsm0503_detect_afs_dtx_frame2() instead");
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t *ubits)
|
||||||
|
OSMO_DEPRECATED("Use gsm0503_detect_ahs_dtx_frame2() instead");
|
||||||
|
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame2(int *n_errors, int *n_bits_total,
|
||||||
|
int *mode_id, const sbit_t *sbits);
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame2(int *n_errors, int *n_bits_total,
|
||||||
|
int *mode_id, const sbit_t *sbits);
|
||||||
|
|
||||||
/*! @} */
|
/*! @} */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* (C) 2020 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
|
* (C) 2020-2022 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-2.0+
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
|
@ -32,6 +32,8 @@
|
||||||
#include <osmocom/coding/gsm0503_parity.h>
|
#include <osmocom/coding/gsm0503_parity.h>
|
||||||
#include <osmocom/gsm/gsm0503.h>
|
#include <osmocom/gsm/gsm0503.h>
|
||||||
|
|
||||||
|
#define S2U(b) ((b) < 0)
|
||||||
|
|
||||||
/* See also: 3GPP TS 05.03, chapter 3.10.1.3, 3.10.5.2 Identification marker */
|
/* See also: 3GPP TS 05.03, chapter 3.10.1.3, 3.10.5.2 Identification marker */
|
||||||
static const ubit_t id_marker_1[] = { 1, 0, 1, 1, 0, 0, 0, 0, 1 };
|
static const ubit_t id_marker_1[] = { 1, 0, 1, 1, 0, 0, 0, 0, 1 };
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ const struct value_string gsm0503_amr_dtx_frame_names[] = {
|
||||||
{ 0, NULL }
|
{ 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool detect_afs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, uint8_t offset, uint8_t count,
|
static bool detect_afs_id_marker(int *n_errors, int *n_bits_total, const sbit_t *sbits, uint8_t offset, uint8_t count,
|
||||||
const ubit_t * id_marker, uint8_t id_marker_len)
|
const ubit_t * id_marker, uint8_t id_marker_len)
|
||||||
{
|
{
|
||||||
unsigned int i, k;
|
unsigned int i, k;
|
||||||
|
@ -69,20 +71,20 @@ static bool detect_afs_id_marker(int *n_errors, int *n_bits_total, const ubit_t
|
||||||
int bits = 0;
|
int bits = 0;
|
||||||
|
|
||||||
/* Override coded in-band data */
|
/* Override coded in-band data */
|
||||||
ubits += offset;
|
sbits += offset;
|
||||||
|
|
||||||
/* Check for identification marker bits */
|
/* Check for identification marker bits */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
for (k = 0; k < 4; k++) {
|
for (k = 0; k < 4; k++) {
|
||||||
if (id_marker[id_bit_nr % id_marker_len] != *ubits)
|
if (*sbits == 0 || id_marker[id_bit_nr % id_marker_len] != S2U(*sbits))
|
||||||
errors++;
|
errors++;
|
||||||
id_bit_nr++;
|
id_bit_nr++;
|
||||||
ubits++;
|
sbits++;
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Jump to the next block of 4 bits */
|
/* Jump to the next block of 4 bits */
|
||||||
ubits += 4;
|
sbits += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
*n_errors = errors;
|
*n_errors = errors;
|
||||||
|
@ -92,30 +94,30 @@ static bool detect_afs_id_marker(int *n_errors, int *n_bits_total, const ubit_t
|
||||||
return *n_errors < *n_bits_total / 8;
|
return *n_errors < *n_bits_total / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool detect_ahs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, const ubit_t * id_marker)
|
static bool detect_ahs_id_marker(int *n_errors, int *n_bits_total, const sbit_t *sbits, const ubit_t *id_marker)
|
||||||
{
|
{
|
||||||
unsigned int i, k;
|
unsigned int i, k;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int bits = 0;
|
int bits = 0;
|
||||||
|
|
||||||
/* Override coded in-band data */
|
/* Override coded in-band data */
|
||||||
ubits += 16;
|
sbits += 16;
|
||||||
|
|
||||||
/* Check first identification marker bits (23*9 bits) */
|
/* Check first identification marker bits (23*9 bits) */
|
||||||
for (i = 0; i < 23; i++) {
|
for (i = 0; i < 23; i++) {
|
||||||
for (k = 0; k < 9; k++) {
|
for (k = 0; k < 9; k++) {
|
||||||
if (id_marker[k] != *ubits)
|
if (*sbits == 0 || id_marker[k] != S2U(*sbits))
|
||||||
errors++;
|
errors++;
|
||||||
ubits++;
|
sbits++;
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check remaining identification marker bits (5 bits) */
|
/* Check remaining identification marker bits (5 bits) */
|
||||||
for (k = 0; k < 5; k++) {
|
for (k = 0; k < 5; k++) {
|
||||||
if (id_marker[k] != *ubits)
|
if (*sbits == 0 || id_marker[k] != S2U(*sbits))
|
||||||
errors++;
|
errors++;
|
||||||
ubits++;
|
sbits++;
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +128,7 @@ static bool detect_ahs_id_marker(int *n_errors, int *n_bits_total, const ubit_t
|
||||||
return *n_errors < *n_bits_total / 8;
|
return *n_errors < *n_bits_total / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool detect_interleaved_ahs_id_marker(int *n_errors, int *n_bits_total, const ubit_t * ubits, uint8_t offset,
|
static bool detect_interleaved_ahs_id_marker(int *n_errors, int *n_bits_total, const sbit_t *sbits, uint8_t offset,
|
||||||
uint8_t n_bits, const ubit_t * id_marker, uint8_t id_marker_len)
|
uint8_t n_bits, const ubit_t * id_marker, uint8_t id_marker_len)
|
||||||
{
|
{
|
||||||
unsigned int i, k;
|
unsigned int i, k;
|
||||||
|
@ -136,23 +138,23 @@ static bool detect_interleaved_ahs_id_marker(int *n_errors, int *n_bits_total, c
|
||||||
uint8_t remainder = n_bits % id_marker_len;
|
uint8_t remainder = n_bits % id_marker_len;
|
||||||
|
|
||||||
/* Override coded in-band data */
|
/* Override coded in-band data */
|
||||||
ubits += offset;
|
sbits += offset;
|
||||||
|
|
||||||
/* Check first identification marker bits (23*9 bits) */
|
/* Check first identification marker bits (23*9 bits) */
|
||||||
for (i = 0; i < full_rounds; i++) {
|
for (i = 0; i < full_rounds; i++) {
|
||||||
for (k = 0; k < id_marker_len; k++) {
|
for (k = 0; k < id_marker_len; k++) {
|
||||||
if (id_marker[k] != *ubits)
|
if (*sbits == 0 || id_marker[k] != S2U(*sbits))
|
||||||
errors++;
|
errors++;
|
||||||
ubits += 2;
|
sbits += 2;
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check remaining identification marker bits (5 bits) */
|
/* Check remaining identification marker bits (5 bits) */
|
||||||
for (k = 0; k < remainder; k++) {
|
for (k = 0; k < remainder; k++) {
|
||||||
if (id_marker[k] != *ubits)
|
if (*sbits == 0 || id_marker[k] != S2U(*sbits))
|
||||||
errors++;
|
errors++;
|
||||||
ubits += 2;
|
sbits += 2;
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,125 +166,127 @@ static bool detect_interleaved_ahs_id_marker(int *n_errors, int *n_bits_total, c
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an FR AMR SID_FIRST frame by its identifcation marker */
|
/* Detect an FR AMR SID_FIRST frame by its identifcation marker */
|
||||||
static bool detect_afs_sid_first(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_afs_sid_first(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_afs_id_marker(n_errors, n_bits_total, ubits, 32, 53, id_marker_0, 9);
|
return detect_afs_id_marker(n_errors, n_bits_total, sbits, 32, 53, id_marker_0, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an FR AMR SID_UPDATE frame by its identification marker */
|
/* Detect an FR AMR SID_UPDATE frame by its identification marker */
|
||||||
static bool detect_afs_sid_update(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_afs_sid_update(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_afs_id_marker(n_errors, n_bits_total, ubits, 36, 53, id_marker_0, 9);
|
return detect_afs_id_marker(n_errors, n_bits_total, sbits, 36, 53, id_marker_0, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an FR AMR ONSET frame by its repeating coded inband data */
|
/* Detect an FR AMR ONSET frame by its repeating coded inband data */
|
||||||
static bool detect_afs_onset(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static int detect_afs_onset(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
bool rc;
|
bool rc;
|
||||||
|
|
||||||
rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_1_sid, 16);
|
rc = detect_afs_id_marker(n_errors, n_bits_total, sbits, 4, 57, codec_mode_1_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 0;
|
||||||
|
|
||||||
rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_2_sid, 16);
|
rc = detect_afs_id_marker(n_errors, n_bits_total, sbits, 4, 57, codec_mode_2_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 1;
|
||||||
|
|
||||||
rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_3_sid, 16);
|
rc = detect_afs_id_marker(n_errors, n_bits_total, sbits, 4, 57, codec_mode_3_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 2;
|
||||||
|
|
||||||
rc = detect_afs_id_marker(n_errors, n_bits_total, ubits, 4, 57, codec_mode_4_sid, 16);
|
rc = detect_afs_id_marker(n_errors, n_bits_total, sbits, 4, 57, codec_mode_4_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 3;
|
||||||
|
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR SID UPDATE frame by its identification marker */
|
/* Detect an HR AMR SID UPDATE frame by its identification marker */
|
||||||
static bool detect_ahs_sid_update(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_ahs_sid_update(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_ahs_id_marker(n_errors, n_bits_total, ubits, id_marker_1);
|
return detect_ahs_id_marker(n_errors, n_bits_total, sbits, id_marker_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR SID FIRST (part 1) frame by its identification marker */
|
/* Detect an HR AMR SID FIRST (part 1) frame by its identification marker */
|
||||||
static bool detect_ahs_sid_first_p1(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_ahs_sid_first_p1(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_ahs_id_marker(n_errors, n_bits_total, ubits, id_marker_0);
|
return detect_ahs_id_marker(n_errors, n_bits_total, sbits, id_marker_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR SID FIRST (part 2) frame by its repeating coded inband data */
|
/* Detect an HR AMR SID FIRST (part 2) frame by its repeating coded inband data */
|
||||||
static bool detect_ahs_sid_first_p2(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static int detect_ahs_sid_first_p2(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
bool rc;
|
bool rc;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_1_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 0, 114, codec_mode_1_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 0;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_2_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 0, 114, codec_mode_2_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 1;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_3_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 0, 114, codec_mode_3_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 2;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 0, 114, codec_mode_4_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 0, 114, codec_mode_4_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 3;
|
||||||
|
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR ONSET frame by its repeating coded inband data */
|
/* Detect an HR AMR ONSET frame by its repeating coded inband data */
|
||||||
static bool detect_ahs_onset(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static int detect_ahs_onset(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
bool rc;
|
bool rc;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_1_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 1, 114, codec_mode_1_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 0;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_2_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 1, 114, codec_mode_2_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 1;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_3_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 1, 114, codec_mode_3_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 2;
|
||||||
|
|
||||||
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 1, 114, codec_mode_4_sid, 16);
|
rc = detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 1, 114, codec_mode_4_sid, 16);
|
||||||
if (rc)
|
if (rc)
|
||||||
return true;
|
return 3;
|
||||||
|
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR SID FIRST INHIBIT frame by its identification marker */
|
/* Detect an HR AMR SID FIRST INHIBIT frame by its identification marker */
|
||||||
static bool detect_ahs_sid_first_inh(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_ahs_sid_first_inh(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 33, 212, id_marker_1, 9);
|
return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 33, 212, id_marker_1, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect an HR AMR SID UPDATE INHIBIT frame by its identification marker */
|
/* Detect an HR AMR SID UPDATE INHIBIT frame by its identification marker */
|
||||||
static bool detect_ahs_sid_update_inh(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
static bool detect_ahs_sid_update_inh(int *n_errors, int *n_bits_total, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, ubits, 33, 212, id_marker_0, 9);
|
return detect_interleaved_ahs_id_marker(n_errors, n_bits_total, sbits, 33, 212, id_marker_0, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Detect FR AMR DTX frame in unmapped, deinterleaved frame bits.
|
/*! Detect FR AMR DTX frame in unmapped, deinterleaved frame bits.
|
||||||
* \param[in] ubits input bits (456 bit).
|
|
||||||
* \param[out] n_errors number of errornous bits.
|
* \param[out] n_errors number of errornous bits.
|
||||||
* \param[out] n_bits_total number of checked bits.
|
* \param[out] n_bits_total number of checked bits.
|
||||||
|
* \param[out] mode_id codec mode ID (0..3 or -1).
|
||||||
|
* \param[in] sbits input soft-bits (456 bit).
|
||||||
* \returns dtx frame type. */
|
* \returns dtx frame type. */
|
||||||
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame2(int *n_errors, int *n_bits_total,
|
||||||
|
int *mode_id, const sbit_t *sbits)
|
||||||
{
|
{
|
||||||
if (detect_afs_sid_first(n_errors, n_bits_total, ubits))
|
if (detect_afs_sid_first(n_errors, n_bits_total, sbits))
|
||||||
return AFS_SID_FIRST;
|
return AFS_SID_FIRST;
|
||||||
if (detect_afs_sid_update(n_errors, n_bits_total, ubits))
|
if (detect_afs_sid_update(n_errors, n_bits_total, sbits))
|
||||||
return AFS_SID_UPDATE;
|
return AFS_SID_UPDATE;
|
||||||
if (detect_afs_onset(n_errors, n_bits_total, ubits))
|
if ((*mode_id = detect_afs_onset(n_errors, n_bits_total, sbits)) != -1)
|
||||||
return AFS_ONSET;
|
return AFS_ONSET;
|
||||||
|
|
||||||
*n_errors = 0;
|
*n_errors = 0;
|
||||||
|
@ -290,27 +294,62 @@ enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_b
|
||||||
return AMR_OTHER;
|
return AMR_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Detect HR AMR DTX frame in unmapped, deinterleaved frame bits.
|
/*! Detect FR AMR DTX frame in unmapped, deinterleaved frame bits.
|
||||||
* \param[in] ubits input bits (456 bit).
|
* DEPRECATED: use gsm0503_detect_afs_dtx_frame2() instead.
|
||||||
* \param[out] n_errors number of errornous bits.
|
* \param[out] n_errors number of errornous bits.
|
||||||
* \param[out] n_bits_total number of checked bits.
|
* \param[out] n_bits_total number of checked bits.
|
||||||
* \returns dtx frame type, */
|
* \param[in] ubits input bits (456 bit).
|
||||||
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total, const ubit_t * ubits)
|
* \returns dtx frame type. */
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_afs_dtx_frame(int *n_errors, int *n_bits_total,
|
||||||
|
const ubit_t *ubits)
|
||||||
{
|
{
|
||||||
if (detect_ahs_sid_update(n_errors, n_bits_total, ubits))
|
int mode_id; /* unused */
|
||||||
|
sbit_t sbits[456];
|
||||||
|
|
||||||
|
osmo_ubit2sbit(&sbits[0], &ubits[0], sizeof(sbits));
|
||||||
|
return gsm0503_detect_afs_dtx_frame2(n_errors, n_bits_total, &mode_id, &sbits[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Detect HR AMR DTX frame in unmapped, deinterleaved frame bits.
|
||||||
|
* \param[out] n_errors number of errornous bits.
|
||||||
|
* \param[out] n_bits_total number of checked bits.
|
||||||
|
* \param[out] mode_id codec ID (CMI or CMC/CMR).
|
||||||
|
* \param[out] mode_id codec mode ID (0..3 or -1).
|
||||||
|
* \param[in] sbits input soft-bits (456 bit).
|
||||||
|
* \returns dtx frame type, */
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame2(int *n_errors, int *n_bits_total,
|
||||||
|
int *mode_id, const sbit_t *sbits)
|
||||||
|
{
|
||||||
|
if (detect_ahs_sid_update(n_errors, n_bits_total, sbits))
|
||||||
return AHS_SID_UPDATE;
|
return AHS_SID_UPDATE;
|
||||||
if (detect_ahs_sid_first_inh(n_errors, n_bits_total, ubits))
|
if (detect_ahs_sid_first_inh(n_errors, n_bits_total, sbits))
|
||||||
return AHS_SID_FIRST_INH;
|
return AHS_SID_FIRST_INH;
|
||||||
if (detect_ahs_sid_update_inh(n_errors, n_bits_total, ubits))
|
if (detect_ahs_sid_update_inh(n_errors, n_bits_total, sbits))
|
||||||
return AHS_SID_UPDATE_INH;
|
return AHS_SID_UPDATE_INH;
|
||||||
if (detect_ahs_sid_first_p1(n_errors, n_bits_total, ubits))
|
if (detect_ahs_sid_first_p1(n_errors, n_bits_total, sbits))
|
||||||
return AHS_SID_FIRST_P1;
|
return AHS_SID_FIRST_P1;
|
||||||
if (detect_ahs_sid_first_p2(n_errors, n_bits_total, ubits))
|
if ((*mode_id = detect_ahs_sid_first_p2(n_errors, n_bits_total, sbits)) != -1)
|
||||||
return AHS_SID_FIRST_P2;
|
return AHS_SID_FIRST_P2;
|
||||||
if (detect_ahs_onset(n_errors, n_bits_total, ubits))
|
if ((*mode_id = detect_ahs_onset(n_errors, n_bits_total, sbits)) != -1)
|
||||||
return AHS_ONSET;
|
return AHS_ONSET;
|
||||||
|
|
||||||
*n_errors = 0;
|
*n_errors = 0;
|
||||||
*n_bits_total = 0;
|
*n_bits_total = 0;
|
||||||
return AMR_OTHER;
|
return AMR_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Detect HR AMR DTX frame in unmapped, deinterleaved frame bits.
|
||||||
|
* DEPRECATED: use gsm0503_detect_ahs_dtx_frame2() instead.
|
||||||
|
* \param[out] n_errors number of errornous bits.
|
||||||
|
* \param[out] n_bits_total number of checked bits.
|
||||||
|
* \param[in] ubits input bits (456 bit).
|
||||||
|
* \returns dtx frame type, */
|
||||||
|
enum gsm0503_amr_dtx_frames gsm0503_detect_ahs_dtx_frame(int *n_errors, int *n_bits_total,
|
||||||
|
const ubit_t *ubits)
|
||||||
|
{
|
||||||
|
int mode_id; /* unused */
|
||||||
|
sbit_t sbits[456];
|
||||||
|
|
||||||
|
osmo_ubit2sbit(&sbits[0], &ubits[0], sizeof(sbits));
|
||||||
|
return gsm0503_detect_ahs_dtx_frame2(n_errors, n_bits_total, &mode_id, &sbits[0]);
|
||||||
|
}
|
||||||
|
|
|
@ -2158,7 +2158,6 @@ int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
|
||||||
sbit_t iB[912], cB[456], h;
|
sbit_t iB[912], cB[456], h;
|
||||||
ubit_t d[244], p[6], conv[250];
|
ubit_t d[244], p[6], conv[250];
|
||||||
int i, j, k, best = 0, rv, len, steal = 0, id = -1;
|
int i, j, k, best = 0, rv, len, steal = 0, id = -1;
|
||||||
ubit_t cBd[456];
|
|
||||||
*n_errors = 0; *n_bits_total = 0;
|
*n_errors = 0; *n_bits_total = 0;
|
||||||
static ubit_t sid_first_dummy[64] = { 0 };
|
static ubit_t sid_first_dummy[64] = { 0 };
|
||||||
sbit_t sid_update_enc[256];
|
sbit_t sid_update_enc[256];
|
||||||
|
@ -2172,7 +2171,7 @@ int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
|
||||||
|
|
||||||
if (steal > 0) {
|
if (steal > 0) {
|
||||||
/* If not NULL, dtx indicates type of previously decoded TCH/AFS frame.
|
/* If not NULL, dtx indicates type of previously decoded TCH/AFS frame.
|
||||||
* It's normally updated by gsm0503_detect_afs_dtx_frame(), which is not
|
* It's normally updated by gsm0503_detect_afs_dtx_frame2(), which is not
|
||||||
* reached in case of FACCH. Reset it here to avoid FACCH/F frames being
|
* reached in case of FACCH. Reset it here to avoid FACCH/F frames being
|
||||||
* misinterpreted as AMR's special DTX frames. */
|
* misinterpreted as AMR's special DTX frames. */
|
||||||
if (dtx != NULL)
|
if (dtx != NULL)
|
||||||
|
@ -2190,8 +2189,7 @@ int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
|
||||||
if (dtx) {
|
if (dtx) {
|
||||||
const enum gsm0503_amr_dtx_frames dtx_prev = *dtx;
|
const enum gsm0503_amr_dtx_frames dtx_prev = *dtx;
|
||||||
|
|
||||||
osmo_sbit2ubit(cBd, cB, 456);
|
*dtx = gsm0503_detect_afs_dtx_frame2(n_errors, n_bits_total, &id, cB);
|
||||||
*dtx = gsm0503_detect_afs_dtx_frame(n_errors, n_bits_total, cBd);
|
|
||||||
|
|
||||||
switch (*dtx) {
|
switch (*dtx) {
|
||||||
case AMR_OTHER:
|
case AMR_OTHER:
|
||||||
|
@ -2230,7 +2228,7 @@ int gsm0503_tch_afs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts,
|
||||||
len = 5;
|
len = 5;
|
||||||
goto out;
|
goto out;
|
||||||
case AFS_SID_UPDATE: /* TODO: parse CMI _and_ CMC/CMR (16 + 16 bit) */
|
case AFS_SID_UPDATE: /* TODO: parse CMI _and_ CMC/CMR (16 + 16 bit) */
|
||||||
case AFS_ONSET: /* TODO: parse CMI or CMC/CMR (N * 16 - M bit) */
|
case AFS_ONSET:
|
||||||
len = 0;
|
len = 0;
|
||||||
goto out;
|
goto out;
|
||||||
default:
|
default:
|
||||||
|
@ -2625,7 +2623,6 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
|
||||||
sbit_t iB[912], cB[456], h;
|
sbit_t iB[912], cB[456], h;
|
||||||
ubit_t d[244], p[6], conv[135];
|
ubit_t d[244], p[6], conv[135];
|
||||||
int i, j, k, best = 0, rv, len, steal = 0, id = -1;
|
int i, j, k, best = 0, rv, len, steal = 0, id = -1;
|
||||||
ubit_t cBd[456];
|
|
||||||
static ubit_t sid_first_dummy[64] = { 0 };
|
static ubit_t sid_first_dummy[64] = { 0 };
|
||||||
|
|
||||||
/* only unmap the stealing bits */
|
/* only unmap the stealing bits */
|
||||||
|
@ -2643,7 +2640,7 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
|
||||||
/* if we found a stole FACCH, but only at correct alignment */
|
/* if we found a stole FACCH, but only at correct alignment */
|
||||||
if (steal > 0) {
|
if (steal > 0) {
|
||||||
/* If not NULL, dtx indicates type of previously decoded TCH/AHS frame.
|
/* If not NULL, dtx indicates type of previously decoded TCH/AHS frame.
|
||||||
* It's normally updated by gsm0503_detect_ahs_dtx_frame(), which is not
|
* It's normally updated by gsm0503_detect_ahs_dtx_frame2(), which is not
|
||||||
* reached in case of FACCH. Reset it here to avoid FACCH/H frames being
|
* reached in case of FACCH. Reset it here to avoid FACCH/H frames being
|
||||||
* misinterpreted as AMR's special DTX frames. */
|
* misinterpreted as AMR's special DTX frames. */
|
||||||
if (dtx != NULL)
|
if (dtx != NULL)
|
||||||
|
@ -2682,8 +2679,7 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
|
||||||
int n_bits_total_sid;
|
int n_bits_total_sid;
|
||||||
int n_errors_sid;
|
int n_errors_sid;
|
||||||
|
|
||||||
osmo_sbit2ubit(cBd, cB, 456);
|
*dtx = gsm0503_detect_ahs_dtx_frame2(n_errors, n_bits_total, &id, cB);
|
||||||
*dtx = gsm0503_detect_ahs_dtx_frame(n_errors, n_bits_total, cBd);
|
|
||||||
/* TODO: detect and handle AHS_SID_UPDATE + AHS_SID_UPDATE_INH */
|
/* TODO: detect and handle AHS_SID_UPDATE + AHS_SID_UPDATE_INH */
|
||||||
|
|
||||||
switch (*dtx) {
|
switch (*dtx) {
|
||||||
|
@ -2705,7 +2701,7 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
|
||||||
osmo_conv_decode_ber(&gsm0503_tch_axs_sid_update,
|
osmo_conv_decode_ber(&gsm0503_tch_axs_sid_update,
|
||||||
cB + 16, conv, &n_errors_sid,
|
cB + 16, conv, &n_errors_sid,
|
||||||
&n_bits_total_sid);
|
&n_bits_total_sid);
|
||||||
/* gsm0503_detect_ahs_dtx_frame() calculates BER for the marker,
|
/* gsm0503_detect_ahs_dtx_frame2() calculates BER for the marker,
|
||||||
* osmo_conv_decode_ber() calculates BER for the coded data. */
|
* osmo_conv_decode_ber() calculates BER for the coded data. */
|
||||||
if (n_errors != NULL)
|
if (n_errors != NULL)
|
||||||
*n_errors += n_errors_sid;
|
*n_errors += n_errors_sid;
|
||||||
|
@ -2724,14 +2720,14 @@ int gsm0503_tch_ahs_decode_dtx(uint8_t *tch_data, const sbit_t *bursts, int odd,
|
||||||
tch_amr_reassemble(tch_data, conv, 39);
|
tch_amr_reassemble(tch_data, conv, 39);
|
||||||
len = 5;
|
len = 5;
|
||||||
goto out;
|
goto out;
|
||||||
case AHS_SID_FIRST_P2: /* TODO: parse CMI or CMC/CMR (N * 16 - M bit) */
|
case AHS_SID_FIRST_P2:
|
||||||
tch_amr_sid_update_append(sid_first_dummy, 0,
|
tch_amr_sid_update_append(sid_first_dummy, 0,
|
||||||
(codec_mode_req) ? codec[*ft]
|
(codec_mode_req) ? codec[*ft]
|
||||||
: codec[id > 0 ? id : 0]);
|
: codec[id > 0 ? id : 0]);
|
||||||
tch_amr_reassemble(tch_data, sid_first_dummy, 39);
|
tch_amr_reassemble(tch_data, sid_first_dummy, 39);
|
||||||
len = 5;
|
len = 5;
|
||||||
goto out;
|
goto out;
|
||||||
case AHS_ONSET: /* TODO: parse CMI or CMC/CMR (N * 16 - M bit) */
|
case AHS_ONSET:
|
||||||
case AHS_SID_FIRST_INH: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
case AHS_SID_FIRST_INH: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
||||||
case AHS_SID_UPDATE_INH: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
case AHS_SID_UPDATE_INH: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
||||||
case AHS_SID_FIRST_P1: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
case AHS_SID_FIRST_P1: /* TODO: parse CMI or CMC/CMR (16 bit) */
|
||||||
|
|
|
@ -123,6 +123,8 @@ gsm0503_amr_dtx_frame_names;
|
||||||
gsm0503_amr_dtx_frame_name;
|
gsm0503_amr_dtx_frame_name;
|
||||||
gsm0503_detect_afs_dtx_frame;
|
gsm0503_detect_afs_dtx_frame;
|
||||||
gsm0503_detect_ahs_dtx_frame;
|
gsm0503_detect_ahs_dtx_frame;
|
||||||
|
gsm0503_detect_afs_dtx_frame2;
|
||||||
|
gsm0503_detect_ahs_dtx_frame2;
|
||||||
|
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,7 +72,7 @@ char sample_sid_update_inh_frame[] =
|
||||||
"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1"
|
"xBxBxBxBxBxBxBxBxBxBxBxBxBxBxBxBx0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1x1x1x1x0x0x1x0x0x1"
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int string_to_ubit(ubit_t * ubits, char *string)
|
unsigned int string_to_sbit(sbit_t *sbits, char *string)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -80,7 +80,7 @@ unsigned int string_to_ubit(ubit_t * ubits, char *string)
|
||||||
len = strlen(string);
|
len = strlen(string);
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
ubits[i] = string[i] & 1;
|
sbits[i] = string[i] == '1' ? -127 : 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
@ -88,28 +88,32 @@ unsigned int string_to_ubit(ubit_t * ubits, char *string)
|
||||||
|
|
||||||
void test_gsm0503_detect_afs_dtx_frame(char *string)
|
void test_gsm0503_detect_afs_dtx_frame(char *string)
|
||||||
{
|
{
|
||||||
ubit_t ubits[512];
|
sbit_t sbits[512];
|
||||||
uint8_t dtx_frame_type;
|
uint8_t dtx_frame_type;
|
||||||
int n_errors;
|
int n_errors;
|
||||||
int n_bits_total;
|
int n_bits_total;
|
||||||
|
int mode_id = -1;
|
||||||
|
|
||||||
string_to_ubit(ubits, string);
|
string_to_sbit(sbits, string);
|
||||||
dtx_frame_type = gsm0503_detect_afs_dtx_frame(&n_errors, &n_bits_total, ubits);
|
dtx_frame_type = gsm0503_detect_afs_dtx_frame2(&n_errors, &n_bits_total, &mode_id, sbits);
|
||||||
printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
|
printf(" ==> %s, n_errors=%d, n_bits_total=%d, mode_id=%d\n",
|
||||||
n_errors, n_bits_total);
|
gsm0503_amr_dtx_frame_name(dtx_frame_type),
|
||||||
|
n_errors, n_bits_total, mode_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_gsm0503_detect_ahs_dtx_frame(char *string)
|
void test_gsm0503_detect_ahs_dtx_frame(char *string)
|
||||||
{
|
{
|
||||||
ubit_t ubits[512];
|
sbit_t sbits[512];
|
||||||
uint8_t dtx_frame_type;
|
uint8_t dtx_frame_type;
|
||||||
int n_errors;
|
int n_errors;
|
||||||
int n_bits_total;
|
int n_bits_total;
|
||||||
|
int mode_id = -1;
|
||||||
|
|
||||||
string_to_ubit(ubits, string);
|
string_to_sbit(sbits, string);
|
||||||
dtx_frame_type = gsm0503_detect_ahs_dtx_frame(&n_errors, &n_bits_total, ubits);
|
dtx_frame_type = gsm0503_detect_ahs_dtx_frame2(&n_errors, &n_bits_total, &mode_id, sbits);
|
||||||
printf(" ==> %s, n_errors=%i, n_bits_total=%i\n", gsm0503_amr_dtx_frame_name(dtx_frame_type),
|
printf(" ==> %s, n_errors=%d, n_bits_total=%d, mode_id=%d\n",
|
||||||
n_errors, n_bits_total);
|
gsm0503_amr_dtx_frame_name(dtx_frame_type),
|
||||||
|
n_errors, n_bits_total, mode_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_gsm0503_tch_afhs_decode_dtx(const sbit_t *bursts, size_t offset,
|
static void test_gsm0503_tch_afhs_decode_dtx(const sbit_t *bursts, size_t offset,
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
FR AMR DTX FRAMES:
|
FR AMR DTX FRAMES:
|
||||||
==> AFS_SID_FIRST, n_errors=0, n_bits_total=212
|
==> AFS_SID_FIRST, n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
==> AFS_SID_UPDATE (marker), n_errors=0, n_bits_total=212
|
==> AFS_SID_UPDATE (marker), n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
==> AFS_ONSET, n_errors=0, n_bits_total=228
|
==> AFS_ONSET, n_errors=0, n_bits_total=228, mode_id=0
|
||||||
HR AMR DTX FRAMES:
|
HR AMR DTX FRAMES:
|
||||||
==> AHS_SID_UPDATE (marker), n_errors=0, n_bits_total=212
|
==> AHS_SID_UPDATE (marker), n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
==> AHS_SID_FIRST_P1, n_errors=0, n_bits_total=212
|
==> AHS_SID_FIRST_P1, n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
==> AHS_SID_FIRST_P2, n_errors=0, n_bits_total=114
|
==> AHS_SID_FIRST_P2, n_errors=0, n_bits_total=114, mode_id=0
|
||||||
==> AHS_ONSET, n_errors=0, n_bits_total=114
|
==> AHS_ONSET, n_errors=0, n_bits_total=114, mode_id=0
|
||||||
==> AHS_SID_FIRST_INH, n_errors=0, n_bits_total=212
|
==> AHS_SID_FIRST_INH, n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
==> AHS_SID_UPDATE_INH, n_errors=0, n_bits_total=212
|
==> AHS_SID_UPDATE_INH, n_errors=0, n_bits_total=212, mode_id=-1
|
||||||
Running test_gsm0503_tch_afhs_decode_dtx(at offset=0): testing detection of AFS_SID_UPDATE
|
Running test_gsm0503_tch_afhs_decode_dtx(at offset=0): testing detection of AFS_SID_UPDATE
|
||||||
==> gsm0503_tch_afs_decode_dtx() yields 'AFS_SID_UPDATE (marker)' (rc=0, BER 0/212)
|
==> gsm0503_tch_afs_decode_dtx() yields 'AFS_SID_UPDATE (marker)' (rc=0, BER 0/212)
|
||||||
Running test_gsm0503_tch_afhs_decode_dtx(at offset=464): testing decoding of AFS_SID_UPDATE
|
Running test_gsm0503_tch_afhs_decode_dtx(at offset=464): testing decoding of AFS_SID_UPDATE
|
||||||
|
|
Loading…
Reference in New Issue