Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(src/basop/test_framework)
add_subdirectory(src/basop/flc)
add_subdirectory(src/bs1770demo)
add_subdirectory(src/eid)
add_subdirectory(src/eid-amr)
add_subdirectory(src/esdru)
add_subdirectory(src/fir)
add_subdirectory(src/freqresp)
Expand Down
81 changes: 81 additions & 0 deletions doc/manual/eid.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
% Apr.96 - Peter Kroon
% Feb.2000 - Convergence towards STL2000
% Oct.2009 - EID-EV Jonas Svedberg, Yusuke Hiwasaki
% May.2026 - EID-AMR Balazs K�vesi, St�phane Ragot
%=============================================================================

%=============================================================================
Expand Down Expand Up @@ -1341,3 +1342,83 @@ \subsubsection{EID-EV G.192 Output frame examples }
\label{fig:G192outputFrameLayer034ErrorIndividual}
\end{center}
\end{figure}


%--------------------------------------
\section {Adaptation for 3GPP AMR codec (EID-AMR)} \label{EID-AMR}
%--------------------------------------

\subsection{Description}

The {\tt eid-xor} tool operates on bitstreams conforming to the ITU-T G.192
serial bitstream format. However, the 3GPP AMR narrowband codec uses a
different serial bitstream format, defined in Clause~6.3 of 3GPP TS~26.073.
In this format, each frame is a fixed-size block of 250 16-bit words
({\tt SERIAL\_FRAMESIZE} = 1 + 244 + 5), where:
\begin{itemize}
\item Word 0: frame type indicator (e.g.\ 0x00--0x07 for AMR modes, 0x03 = NO\_DATA)
\item Words 1--244: serial speech bits ({\tt MAX\_SERIAL} = 244)
\item Words 245--249: auxiliary/padding
\end{itemize}

Since this format is not compliant with ITU-T G.192, a dedicated tool
called {\tt eid-amr} is provided to apply frame erasure patterns to AMR
bitstreams.

\subsection{Algorithm}

The {\tt eid-amr} tool reads an AMR bitstream and a G.192 frame erasure
pattern file. For each AMR frame, one erasure flag is consumed from the
error pattern:
\begin{itemize}
\item If the flag is {\tt G192\_SYNC} (0x6B21, good frame): the AMR frame
is written to the output unchanged.
\item If the flag is {\tt G192\_FER} (0x6B20, erased frame): the frame type
is set to NO\_DATA (0x03), all 244 serial data bits are forced to zero,
and the modified frame is written to the output.
\end{itemize}

If the error pattern file is shorter than the AMR bitstream, the error
pattern is rewound and reused from the beginning (same behavior as
{\tt eid-xor}).

Note that {\tt eid-amr} handles only frame erasures; bit errors are not
supported.

\subsection{Usage}

{\tt\small
\begin{verbatim}
eid-amr <AMR_bitstream_in> <G.192_FER_pattern> <AMR_bitstream_out>
\end{verbatim}
}

Where:
\begin{itemize}
\item {\tt AMR\_bitstream\_in}: input AMR serial bitstream (ETSI/3GPP format)
\item {\tt G.192\_FER\_pattern}: G.192 word-oriented frame erasure pattern
(as generated by {\tt gen-patt} with {\tt -g192 -fer})
\item {\tt AMR\_bitstream\_out}: output AMR bitstream with erasures applied
\end{itemize}

Statistics are reported to {\tt stderr} upon completion: number of processed
frames, distorted frames, frame erasure rate, and number of error pattern
wraps.

\subsection{Example}

Generate a 3\% burst frame erasure pattern and apply it to an AMR bitstream
encoded at 4.75~kbit/s:

{\tt\small
\begin{verbatim}
gen-patt -g192 ep.g192 f 500 1 state.ser 0.03
eid-amr input_475.amr ep.g192 output_475_fer.amr
\end{verbatim}
}

\subsection{Origin}

This tool is derived from the EID-3G tool (Nobuhiko Naka, NTT DOCOMO) and
was originally submitted to 3GPP in Tdoc S4-120998 (TSGS4\#70, Chicago,
13--17 Aug 2012). Authors: Balazs K\"ovesi, St\'ephane Ragot (Orange SA).
Binary file added doc/manual/graphics/hp50_32khz.pdf
Binary file not shown.
Binary file added doc/manual/graphics/hp50_48khz.pdf
Binary file not shown.
Binary file added doc/manual/graphics/shq2_down.pdf
Binary file not shown.
Binary file added doc/manual/graphics/shq2_up.pdf
Binary file not shown.
Binary file added doc/manual/graphics/shq3_down.pdf
Binary file not shown.
Binary file added doc/manual/graphics/shq3_up.pdf
Binary file not shown.
75 changes: 70 additions & 5 deletions doc/manual/rate.tex
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,17 @@ \section{Implementation}
%-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
\subsection{FIR module}

The frequency responses of the implemented high-quality low-pass
The frequency responses of the implemented high-quality (HQ) low-pass
filters are shown in figures \ref{hq-frq-1-2} and \ref{hq-frq-1-3}
(for rate-change factors 2 and 3, respectively), while the telephone
(denoted HQ2 and HQ3 in the command line, for rate-change factors 2 and 3, respectively), while the telephone
bandwidth bandpass filter is given in figure \ref{hq-bandpass} (only
a rate-change factor of 2 is available). The impulse responses of
these filters are given in figures \ref{ir-hq-up}, \ref{ir-hq-down},
and \ref{ir-bandpass}, respectively for the up-sampling filters
(factors 2 and 3), for the down-sampling filters (factors 2 and 3),
and for the bandpass filter.
and for the bandpass filter.

Additional filters (SHQ2 and SHQ3 for super-high-quality for rate-change factors 2 and 3, respectively) with more taps (729 coefficients) and smaller transition band (stopband attenuation $-80$\,dB) are also provided; their frequency responses are given in figures \ref{shq2} and \ref{shq3}. These filters are intended for applications requiring higher spectral selectivity than the standard HQ filters, such as wideband and super-wideband codec characterization in 3GPP.

The transmit-side IRS filter has been implemented for the ``regular''
and modified flavors. The regular transmit-side P.48 IRS filter
Expand Down Expand Up @@ -546,6 +548,8 @@ \subsection{FIR module}
the same routines are called, while for IRS, band-limiting or
MUSHRA anchors, there is no rate-change routine from 16 to 32 kHz.

High-pass filters with 50 Hz cutoff frequency (3\,dB point) for the 32 and 48 kHz sampling rates (HP50\_32K with 1119 coefficients and HP50\_48K with 1679 coefficients) are also provided. Their frequency response is given in figure \ref{hp50}.

Since the digital filters have memory, state variables are needed. In
this version of the STL, a type {\tt SCD\_FIR} is defined, containing the past
sample memory, as well as filter coefficients and other control
Expand Down Expand Up @@ -583,7 +587,7 @@ \subsection{FIR module}
(b) High-quality filter for down-sampling.

\end{center}
\caption{\SF High-quality filter responses for a
\caption{\SF Super-high-quality filter responses for a
factor of 2 and sampling rates of 8000 and
16000 Hz.\label{hq-frq-1-2}}

Expand All @@ -603,13 +607,54 @@ \subsection{FIR module}
(b) High-quality filter for down-sampling.

\end{center}
\caption{\SF High-quality filter responses for a
\caption{\SF Super-high-quality filter responses for a
factor of 3 and sampling rates of 8000 and
24000 Hz.\label{hq-frq-1-3}}

\end{figure}
%------------- End of FIR filters response: frq for factor 3 ----------------

%----------- Begin of FIR filters response : frq for factor 2 ---------------
\begin{figure}[hbtp]
\begin{center}
%Both boxes' dimension: 15.24cm x 8.89cm
\includegraphics[scale=0.8]{shq2_up.pdf}
\\
(a) Super-high-quality filter for up-sampling.

\includegraphics[scale=0.8]{shq2_down.pdf}
\\
(b) Super-high-quality filter for down-sampling.

\end{center}
\caption{\SF Super-high-quality filter responses for a
factor of 2 and sampling rates of 8000 and
16000 Hz.\label{shq2}}

\end{figure}
%------------- End of FIR filters response: frq for factor 2 ----------------

%----------- Begin of FIR filters response: frq for factor 3 ---------------
\begin{figure}[hbtp]
\begin{center}
%Both boxes' dimension: 15.24cm x 8.89cm
\includegraphics[scale=0.8]{shq3_up.pdf}
\\
(a) High-quality filter for up-sampling.

\includegraphics[scale=0.8]{shq3_down.pdf}
\\
(b) High-quality filter for down-sampling.

\end{center}
\caption{\SF Super-high-quality filter responses for a
factor of 3 and sampling rates of 8000 and
24000 Hz.\label{shq3}}

\end{figure}
%------------- End of FIR filters response: frq for factor 3 ----------------



%----------- Begin of FIR filters response: frq for bandpass filter --------
\begin{figure}[hbtp]
Expand Down Expand Up @@ -1142,6 +1187,26 @@ \subsection{FIR module}
}
\end{figure}
%----- End of FIR filters response: impulse response for LP20 -----


%----------- Begin of FIR filters response : frq for factor 2 ---------------
\begin{figure}[hbtp]
\begin{center}
%Both boxes' dimension: 15.24cm x 8.89cm
\includegraphics{hp50_32khz}
\\
(a) 50Hz high-pass filter operating at 32 kHz.

\includegraphics{hp50_48khz}
\\
(b) 50Hz high-pass filter operating at 48 kHz.

\end{center}
\caption{\SF 50Hz high-pass filter responses (32000 and 48000 Hz).\label{hp50}}

\end{figure}
%------------- End of FIR filters response: frq for factor 2 ----------------

\flushfloats


Expand Down
14 changes: 14 additions & 0 deletions src/eid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ add_test(eid-xor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eid-xor -fer -bs bit -ep g192
add_test(eid-xor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eid-xor -fer -bs bit -ep byte test_data/zero.src test_data/epf05g10.byt test_data/z_f05g10.bby)
add_test(eid-xor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eid-xor -fer -bs bit -ep bit test_data/zero.src test_data/epf05g10.bit test_data/z_f05g10.bbi)


#--- eid-amr: EID for 3GPP AMR codec (from 3GPP S4-120998)
add_executable(eid-amr eid-amr.c softbit.c)
target_link_libraries(eid-amr ${M_LIBRARY})

add_test(eid-amr1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eid-amr
test_data/bst475.amr test_data/bf03.g192 test_data/bst475_bf03.tst)
add_test(eid-amr1-verify ${CMAKE_COMMAND} -E compare_files
test_data/bst475_bf03.amr test_data/bst475_bf03.tst)

add_test(eid-amr2 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/eid-amr
test_data/bst122.amr test_data/bf06.g192 test_data/bst122_bf06.tst)
add_test(eid-amr2-verify ${CMAKE_COMMAND} -E compare_files
test_data/bst122_bf06.amr test_data/bst122_bf06.tst)
24 changes: 24 additions & 0 deletions src/eid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The "Error Insertion Device" (EID) module is built of the following files:

eid-int.c: .... Interpolates error patterns from a master EP
eid-xor.c: .... Disturbs bits or erases frames based on error patterns
eid-amr.c: .... EID for 3GPP AMR codec (frame erasures via G.192 patterns)
dlyerr_2_errpat.c: Delay/error profile to frame-erasure pattern converter
ep-stats.c: ... Assesses and prints statistics about an error pattern file
gen-patt.c: ... Generates error pattern files
softbit.c: .... Library with softbit file I/O and format check
Expand Down Expand Up @@ -263,5 +265,27 @@ little-endian computers (PC/VAX/Alpha) are:
Has not been implemented yet.


## EID-AMR: Error Insertion Device for 3GPP AMR codec

The `eid-amr` tool provides frame erasure simulation for 3GPP AMR bitstreams
using G.192 error patterns. The `eid-xor` tool is not directly applicable to
AMR because the AMR bitstream follows the ETSI/3GPP format (TS 26.073 §6.3),
which is not compliant with ITU-T G.192.

Derived from the EID-3G tool (Nobuhiko Naka, NTT DOCOMO). Differences:
- No position parameter (consistent with `eid-xor` usage).
- Only frame erasures (no bit errors).
- All data bits in an erased frame are forced to zero.
- Lost frames signalled with frame type NO\_DATA (0x03).
- Statistics reported to stderr.

Usage:

eid-amr <AMR_bitstream_in> <G.192_FER_pattern> <AMR_bitstream_out>

Originally submitted to 3GPP in Tdoc S4-120998 (Aug. 2012).
Authors: Balazs Kovesi, Stephane Ragot (Orange SA).


Good luck!
-- <simao.campos@labs.comsat.com>
107 changes: 107 additions & 0 deletions src/eid/eid-amr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
eid-amr.c

EID for AMR using G.192 error pattern of frame erasures.
This tool is based on the eid-3g tool written by Nobuhiko Naka, NTT DOCOMO
(see: http://www.3gpp.org/ftp/tsg_sa/WG4_CODEC/AMR-NB_3G-Characterization/EID_Error_Patterns/)

Modifications:
- using G.192 error pattern for frame erasures
- only frame erasures (no bit errors)
- no position parameter to skip frames (usage similar to ITU-T STL eid-xor tool)
- all data bits in a lost frame are forced to a value of 0
- statistics reported to stderr at the end of processing
- uses softbit.c read_g192() for error pattern reading

NOTES:
A lost frame in DTX on/off is signalled with a frame type code 0x03,
independently from the TX or RX frame type.

Contact:
Balazs Kovesi, Stephane Ragot
ORANGE SA
firstname.lastname@orange.com

===============================================================
COPYRIGHT NOTE: This source code, and all of its derivations,
is subject to the "ITU-T General Public License". Please have
it read in the distribution disk, or in the ITU-T Recommendation
G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO CODING STANDARDS".
See LICENSE.md in the top-level directory for terms.
===============================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ugstdemo.h"
#include "softbit.h"

#define MAX_SERIAL 244
#define SERIAL_FRAMESIZE (1 + MAX_SERIAL + 5)

int main(int argc, char *argv[]) {
short spch[SERIAL_FRAMESIZE];
short epat;

FILE *fsp, *fep, *fwe;

long frame, fercnt, wrapcnt;
int i;

if (argc != 4) {
fprintf(stderr, "eid-amr: EID for 3GPP AMR codec using G.192 frame erasure patterns\n\n");
fprintf(stderr, "Usage: eid-amr <AMR bitstream (i)> <G.192 FER pattern (i)> <AMR bitstream with errors (o)>\n");
exit(1);
}

if ((fsp = fopen(argv[1], RB)) == NULL) { perror(argv[1]); exit(1); }
if ((fep = fopen(argv[2], RB)) == NULL) { perror(argv[2]); exit(1); }
if ((fwe = fopen(argv[3], WB)) == NULL) { perror(argv[3]); exit(1); }

frame = 0;
fercnt = 0;
wrapcnt = 0;

while (fread(spch, sizeof(short), SERIAL_FRAMESIZE, fsp) == SERIAL_FRAMESIZE) {
/* Read one erasure flag from G.192 error pattern */
if (read_g192(&epat, 1, fep) != 1) {
fseek(fep, 0L, SEEK_SET);
fprintf(stderr, "Warning: Error pattern file shorter than speech file\n--> wrap error pattern file\n");
wrapcnt++;
if (read_g192(&epat, 1, fep) != 1) {
fprintf(stderr, "Error: Error pattern file read failure\n");
exit(1);
}
}

if (epat == G192_FER) {
spch[0] = 0x03; /* NO_DATA frame type */
fercnt++;
for (i = 0; i < MAX_SERIAL; i++) {
spch[i + 1] = 0; /* erase bits in bad frame (force value of 0) */
}
} else if (epat != G192_SYNC) {
fprintf(stderr, "Error: invalid pattern value 0x%04X at frame %ld\n", (unsigned short)epat, frame);
exit(1);
}

fwrite(spch, sizeof(short), SERIAL_FRAMESIZE, fwe);
frame++;
}

fclose(fsp);
fclose(fep);
fclose(fwe);

fprintf(stderr, "_Input bit stream file ..................: %s\n", argv[1]);
fprintf(stderr, "_Error pattern file .....................: %s\n", argv[2]);
fprintf(stderr, "_Output bit stream file .................: %s\n", argv[3]);
fprintf(stderr, "# Error pattern files wrapped ...........: %ld times\n", wrapcnt);
fprintf(stderr, "# Processed frames ..................... : %ld\n", frame);
fprintf(stderr, "# Distorted frames ..................... : %ld\n", fercnt);
if (frame > 0)
fprintf(stderr, "# Frame erasure rate ....................: %f %%\n", (100.0 * fercnt) / frame);

return 0;
}
1 change: 1 addition & 0 deletions src/eid/test_data/bf03.g192
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k
1 change: 1 addition & 0 deletions src/eid/test_data/bf06.g192
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k k!k!k!k!k!k!k!k!k k!k!k!k!k k k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k!k
Binary file added src/eid/test_data/bst122.amr
Binary file not shown.
Binary file added src/eid/test_data/bst122_bf06.amr
Binary file not shown.
Binary file added src/eid/test_data/bst475.amr
Binary file not shown.
Binary file added src/eid/test_data/bst475_bf03.amr
Binary file not shown.
Loading