# HG changeset patch # User Peter Meerwald # Date 1277452672 -7200 # Node ID 13be24d74cd234c1bcca8d9efecbba9af05cb7d9 # Parent 9cadc470e3da694bd9ea8a00ab2059fe308836a4 import intercom-0.4.1 diff -r 9cadc470e3da -r 13be24d74cd2 intercom/CHANGES --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/CHANGES Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,99 @@ +CHANGES version 25sep2005 + +version 0.4.1: + fixed aec_test.cpp + Tuning of parameter Thold and xfast threshold (from -55dB to -70dB) + Speaker output only right Line-out channel + +version 0.4: + new Soft decision Adrian DTD + speex_bits_write() gives different return value with Speex 1.0 and + Speex 1.1 lib. Emit error message "Update Speex lib to 1.1" + mix 2040Hz for VHF transmitter activation (not Intercom relevant) + Common Answer button + Diversion button + visualize w vector (TCP connection intercomd to wdisplay.tcl) + Leaky NLMS algorithm + + +version 0.3.6: + Soft decision Adrian DTD instead of Geigel DTD + Soft decision Acoustic Echo Suppression + program option -b for no Acoustic Echo Suppression + Wideband Speex now 27.8kBit/s net (was 20.6kBit/s) + + +version 0.3.5: + Reduce number of compile warnings (change signed to unsigned, ...). + Disable capture switch does no longer freeze intercomd. + add Wideband Speex Codec (20.6kBit/s) + option -k works in wideband mode. + create 2 binaries for narrowband, wideband operation + + +version 0.3.4: + H-infinity LMS-pw instead of NLMS-pw algorithm. + See Haykin, Adaptive Filter Theory, 4. Edition, Chap. 5.10. + Cutoff Frequency now 2kHz for pre-whitening filters. + Correct FIR and IIR highpass filters for narrowband/wideband. + NoiseFloor is now -55dB for all codecs. + In wideband mode, option -k is broken. Compressing codecs work + bad in wideband mode. See file Makefile for wideband enabling. + Work in progress MMX and SSE implementation of dot product dotp(). + + +version 0.3.3: + experimental Wide Band support. + Open PCM out changed back to 0.3.1 behaviour. + + +version 0.3.2: + experimental Wide Band support. All codecs use 16kHz sample rate, + options -f and -k are broken. Payload types are wrong. + Open PCM out only on demand fixed in audio_write(). + + +version 0.3.1: + open UDP ports at program start in intercom.tcl (slow CPUs bug fix) + + +version 0.3: + Packet Loss Concealment for G.729, GSM-EFR + Packet Loss default behaviour is silence, optional PLC + check receive RTP packets payload type + SSRC does no longer change for the station (unique identifier) + fill RTP CSRC field at telephone conference + Avoid audio loops (multiple UDP RTP connections) by checking CSRC + Up/Down counter for active station notification in HMI + alternative fixed point acoustic echo cancellation - see aecfix.cpp + application ping from intercom.tcl to intercomd via TCP connection + + +version 0.2.2: + Codec specific ambient noise default because of AEC divergence + Allow change of stability parameter delta for NLMS-pw any time + Kill intercomd at intercom destroy (Close Button) + Better handling of Operation System jitter + Packet Loss Concealment for iLBC + + +version 0.2.1: + create 2 binaries with GSM-EFR and G.729 because of name conflicts + add G.726 32kbps codec (ITU-T G.191) + + +version 0.2: + use Tcl/Tk tcludp lib for active station and failed station signalling + use UDP port 5004 for RTP, UDP port 55004 for signalling + add G.711 A-law, G.711 u-law, GSM codec (ITU-T G.191) + add G.729 (ITU-T G.729), GSM-EFR (3GPP 46.053) codec + write-only and read-only audio fd. Open PCM out only on demand + + +version 0.1: + first release. Features: + iLBC codec (RFC3951, RFC3952) + subset of RTP stack (RFC3550, RFC3551) + Acoustic echo cancellation + telephone conference + intercom.tcl to intercomd process communication via TCP connection diff -r 9cadc470e3da -r 13be24d74cd2 intercom/COPYRIGHT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/COPYRIGHT Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,16 @@ + Copyright (C) DFS Deutsche Flugsicherung (2004). All Rights Reserved. + + You are allowed to use this source code in any open source or closed + source software you want. You are allowed to use the algorithms for a + hardware solution. You are allowed to modify the source code. + You are not allowed to remove the name of the author from this memo or + from the source code files. You are not allowed to monopolize the + source code or the algorithms behind the source code as your + intellectual property. This source code is free of royalty and comes + with no warranty. + + + Please see g711/gen-lic.txt for the ITU-T G.711 codec copyright. + Please see gsm/gen-lic.txt for the ITU-T GSM codec copyright. + Please see ilbc/COPYRIGHT and ilbc/NOTICE for the IETF iLBC codec + copyright. diff -r 9cadc470e3da -r 13be24d74cd2 intercom/INSTALL --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/INSTALL Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,38 @@ +INSTALL version 22jun2005 + +You need a C and C++ compiler for compiling. +You need bash and Tcl/Tk for running intercom. + +You need the tcludp library for intercom. To make things easy, +the intercom package contains a compiled version of tcludp. +This library was compiled on SuSE 9.1 for Tcl/Tk version 8.4. +Attention: The compiled lib is working with SuSE 9.1 and 9.2, but +not with SuSE 9.3. + +tcludp sources: http://sourceforge.net/projects/tcludp +tcludp documentation: http://tcludp.sourceforge.net/ + +You need the Speex library and the Speex headers. On SuSE Linux the +RPMs are Speex and Speex-Devel. Best for intercom are Speex version +1.1.7 or above. +Note: If you use RPM speex-devel please read the note in file +intercomd.cpp about include of speex header file. + +speex sources: http://www.speex.org + +To compile intercom enter the following commands: + + make + +To install intercom become SUPERUSER and enter: + + make install + +The executables are copied to /usr/local/bin. +The libudp is copied to /usr/local/lib. +The config file goes to ~/.intercom.conf + +Edit the file ~/.intercom.conf to get your LABELS and your +IP-ADDRESSES. + +Please read the file README. diff -r 9cadc470e3da -r 13be24d74cd2 intercom/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/Makefile Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,47 @@ + +# +# Makefile for intercom 0.4 +# for Narrowband (8kHz sample frequency): WIDEB=1 +# for Wideband (16kHz sample frequency): WIDEB=2 +# +# use checkinstall instead of make install to build a RPM + +# intercom +CFLAGS = -Wall -O2 -funroll-loops -DEFRSTUB -DG729STUB -DWIDEB=1 -I/usr/local/include +CFLAGS1 = -Wall -O2 -funroll-loops -DEFRSTUB -DG729STUB -DWIDEB=2 -I/usr/local/include +LIBS = ilbc/ilbc.a g711/g711.o gsm/gsm.a g726/g726.a -lm -lspeex +LIBS1 = ilbc/ilbc.a g711/g711.o gsm/gsm.a g726/g726.a -lm -lspeex +SUBDIRS=g711 ilbc gsm g726 + +SUBS :=$(foreach sub,$(SUBDIRS), $(sub)/$(sub).a) + +BIN_DIR=/usr/local/bin +LIB_DIR=/usr/local/lib + +OBJS = intercomd aec.o cirbuf.o oss.o rtp.o tcp.o udp.o intercomd.o sinuston.o + +# Implicit Rules +.cpp.o: + c++ $(CFLAGS) -c $< + +# Explicit Rules +all: + @for T in $(SUBDIRS); do make -C $$T $@; done + c++ $(CFLAGS) -o intercomd aec.cpp cirbuf.cpp oss.cpp \ + rtp.cpp tcp.cpp udp.cpp intercomd.cpp sinuston.cpp \ + $(LIBS) + c++ $(CFLAGS1) -o intercomd1 aec.cpp cirbuf.cpp oss.cpp \ + rtp.cpp tcp.cpp udp.cpp intercomd.cpp sinuston.cpp \ + $(LIBS1) + +install: + install intercom intercom.tcl intercom.ui.tcl $(BIN_DIR) + install intercom.conf $(BIN_DIR) + install wdisplay.tcl $(BIN_DIR) + install --strip intercomd $(BIN_DIR) + install --strip intercomd1 $(BIN_DIR) + install libudp1.0.6.so $(LIB_DIR) + +clean: + @for T in $(SUBDIRS); do make -C $$T $@; done + rm -f intercomd intercomd1 diff -r 9cadc470e3da -r 13be24d74cd2 intercom/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/README Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,72 @@ +README version 22jun2005 + +Welcome to intercom, a Voice over IP speaker-phone conference +application. The application can: +- dial a intercom partner via short-dial buttons +- make a RTP connection to transport your voice over IPv4 +- make a telephone conference +- support wideband codec (16kHz sample frequency) + +Intercom is still very limited. But the things it can do, it does +very well! + + +Modify file ~/.intercom.conf for your short-dial labels +and your IP-addresses. + +To start the application enter + + intercom + +Read shell script /usr/local/bin/intercom to get an idea of what is +going on. For better echo cancellation start intercom with the -m or +-l option. + +For a first test talk to yourself by clicking the button for your own +IP-address, e.g. EDDF TEC2 if your computer is 192.168.1.2. +The button should become green. +Attention: A short click (less then 300ms) toggles on/off, a long +click works as push-to-talk. + +ATTENTION: The intercom application needs PCM out for playback. This +hardware device is used also by other sound programs like MP3 players +(e.g. xmms) or WAV record/playback programs like sweep and audacity. The +intercom application blocks (freezes) as long as another program uses +PCM out. There are ways around this like using sound daemons aRTs or +esound. But this is outside of the intercom application. + +If you dial another intercom station, you get an one-way connection from +your microphone to the loudspeaker of your intercom partner. If your +partner clicks on the correct button (the magenta one), both of you have +a two-way communication. Now you or your partner can dial more intercom +stations to make a conference with maximum 6 stations. +Note: Start intercom with the -t option to get "everybody can talk and +listen with everybody else". + + +Read the file +http://home.arcor.de/andreadrian/intercom/draft-conference-01.txt +for more information. + + +Supported royalty free Codecs: +For License see ITU-T G.191 or IETF RFC3951 + +Narrowband (8kHz sample frequency): +----------------------------------- +IETF iLBC 15.2kBit/s Global IP Sound iLBC Public License +ITU-T G.711 A-law 64kBit/s ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE +ITU-T G.711 u-law 64kBit/s ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE +ITU-T G.726 32kbs 32kBit/s ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE +3GPP GSM 13.2kBit/s ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE + +Wideband (16kHz sample frequency): +---------------------------------- +Speex 27.8kBit/s Xiph.org license (BSD license variant) + +Author: Andre Adrian +E-Mail: Andre dot Adrian at dfs dot de +Postal: DFS Tower Frankfurt + Mr. Andre Adrian + Flughafen Gebaeude 501 + 60549 Frankfurt, Germany diff -r 9cadc470e3da -r 13be24d74cd2 intercom/aec.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/aec.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,225 @@ +/* aec.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Acoustic Echo Cancellation NLMS-pw algorithm + * + * Version 0.3 filter created with www.dsptutor.freeuk.com + * Version 0.3.1 Allow change of stability parameter delta + * Version 0.4 Leaky Normalized LMS - pre whitening algorithm + */ + +#include +#include +#include +#include +#include + +#include "oss.h" +#include "aec.h" +#include "intercomd.h" + +#include "tcp.h" + +/* Vector Dot Product */ +REAL dotp(REAL a[], REAL b[]) +{ + REAL sum0 = 0.0, sum1 = 0.0; + int j; + + for (j = 0; j < NLMS_LEN; j += 2) { + // optimize: partial loop unrolling + sum0 += a[j] * b[j]; + sum1 += a[j + 1] * b[j + 1]; + } + return sum0 + sum1; +} + + +AEC::AEC() +{ + hangover = 0; + memset(x, 0, sizeof(x)); + memset(xf, 0, sizeof(xf)); + memset(w, 0, sizeof(w)); + j = NLMS_EXT; + delta = 0.0f; + setambient(NoiseFloor); + dfast = dslow = M75dB_PCM; + xfast = xslow = M80dB_PCM; + gain = 1.0f; + Fx.init(2000.0f/RATE); + Fe.init(2000.0f/RATE); + + aes_y2 = M0dB; + + fdwdisplay = -1; + dumpcnt = 0; + memset(ws, 0, sizeof(ws)); +} + +// Adrian soft decision DTD +// (Dual Average Near-End to Far-End signal Ratio DTD) +// This algorithm uses exponential smoothing with differnt +// ageing parameters to get fast and slow near-end and far-end +// signal averages. The ratio of NFRs term +// (dfast / xfast) / (dslow / xslow) is used to compute the stepsize +// A ratio value of 2.5 is mapped to stepsize 0, a ratio of 0 is +// mapped to 1.0 with a limited linear function. +inline float AEC::dtd(REAL d, REAL x) +{ + float stepsize; + + // fast near-end and far-end average + dfast += ALPHAFAST * (fabsf(d) - dfast); + xfast += ALPHAFAST * (fabsf(x) - xfast); + + // slow near-end and far-end average + dslow += ALPHASLOW * (fabsf(d) - dslow); + xslow += ALPHASLOW * (fabsf(x) - xslow); + + if (xfast < M70dB_PCM) { + return 0.0; // no Spk signal + } + + if (dfast < M70dB_PCM) { + return 0.0; // no Mic signal + } + + // ratio of NFRs + float ratio = (dfast * xslow) / (dslow * xfast); + + // begrenzte lineare Kennlinie + const float M = (STEPY2 - STEPY1) / (STEPX2 - STEPX1); + if (ratio < STEPX1) { + stepsize = STEPY1; + } else if (ratio > STEPX2) { + stepsize = STEPY2; + } else { + // Punktrichtungsform einer Geraden + stepsize = M * (ratio - STEPX1) + STEPY1; + } + + return stepsize; +} + + +inline void AEC::leaky() +// The xfast signal is used to charge the hangover timer to Thold. +// When hangover expires (no Spk signal for some time) the vector w +// is erased. This is my implementation of Leaky NLMS. +{ + if (xfast >= M70dB_PCM) { + // vector w is valid for hangover Thold time + hangover = Thold; + } else { + if (hangover > 1) { + --hangover; + } else if (1 == hangover) { + --hangover; + // My Leaky NLMS is to erase vector w when hangover expires + memset(w, 0, sizeof(w)); + } + } +} + + +void AEC::openwdisplay() { + // open TCP connection to program wdisplay.tcl + fdwdisplay = socket_async("127.0.0.1", 50999); +}; + + +inline REAL AEC::nlms_pw(REAL d, REAL x_, float stepsize) +{ + x[j] = x_; + xf[j] = Fx.highpass(x_); // pre-whitening of x + + // calculate error value + // (mic signal - estimated mic signal from spk signal) + REAL e = d; + if (hangover > 0) { + e -= dotp(w, x + j); + } + REAL ef = Fe.highpass(e); // pre-whitening of e + + // optimize: iterative dotp(xf, xf) + dotp_xf_xf += (xf[j] * xf[j] - xf[j + NLMS_LEN - 1] * xf[j + NLMS_LEN - 1]); + + if (stepsize > 0.0) { + // calculate variable step size + REAL mikro_ef = stepsize * ef / dotp_xf_xf; + + // update tap weights (filter learning) + int i; + for (i = 0; i < NLMS_LEN; i += 2) { + // optimize: partial loop unrolling + w[i] += mikro_ef * xf[i + j]; + w[i + 1] += mikro_ef * xf[i + j + 1]; + } + } + + if (--j < 0) { + // optimize: decrease number of memory copies + j = NLMS_EXT; + memmove(x + j + 1, x, (NLMS_LEN - 1) * sizeof(REAL)); + memmove(xf + j + 1, xf, (NLMS_LEN - 1) * sizeof(REAL)); + } + + // Saturation + if (e > MAXPCM) { + return MAXPCM; + } else if (e < -MAXPCM) { + return -MAXPCM; + } else { + return e; + } +} + + +int AEC::doAEC(int d_, int x_) +{ + REAL d = (REAL) d_; + REAL x = (REAL) x_; + + // Mic Highpass Filter - to remove DC + d = acMic.highpass(d); + + // Mic Highpass Filter - cut-off below 300Hz + d = cutoff.highpass(d); + + // Amplify, for e.g. Soundcards with -6dB max. volume + d *= gain; + + // Spk Highpass Filter - to remove DC + x = acSpk.highpass(x); + + // Double Talk Detector + stepsize = dtd(d, x); + + // Leaky (ageing of vector w) + leaky(); + + // Acoustic Echo Cancellation + d = nlms_pw(d, x, stepsize); + + if (fdwdisplay >= 0) { + if (++dumpcnt >= (WIDEB*8000/10)) { + // wdisplay creates 10 dumps per seconds = large CPU load! + dumpcnt = 0; + write(fdwdisplay, ws, DUMP_LEN*sizeof(float)); + // we don't check return value. This is not production quality!!! + memset(ws, 0, sizeof(ws)); + } else { + int i; + for (i = 0; i < DUMP_LEN; i += 2) { + // optimize: partial loop unrolling + ws[i] += w[i]; + ws[i + 1] += w[i + 1]; + } + } + } + + return (int) d; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/aec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/aec.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,351 @@ +/* aec.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * Author: Andre Adrian + * + * Acoustic Echo Cancellation Leaky NLMS-pw algorithm + * + * Version 0.3 filter created with www.dsptutor.freeuk.com + * Version 0.3.1 Allow change of stability parameter delta + * Version 0.4 Leaky Normalized LMS - pre whitening algorithm + */ + +#ifndef _AEC_H /* include only once */ + +// use double if your CPU does software-emulation of float +typedef float REAL; + +/* dB Values */ +const REAL M0dB = 1.0f; +const REAL M3dB = 0.71f; +const REAL M6dB = 0.50f; +const REAL M9dB = 0.35f; +const REAL M12dB = 0.25f; +const REAL M18dB = 0.125f; +const REAL M24dB = 0.063f; + +/* dB values for 16bit PCM */ +/* MxdB_PCM = 32767 * 10 ^(x / 20) */ +const REAL M10dB_PCM = 10362.0f; +const REAL M20dB_PCM = 3277.0f; +const REAL M25dB_PCM = 1843.0f; +const REAL M30dB_PCM = 1026.0f; +const REAL M35dB_PCM = 583.0f; +const REAL M40dB_PCM = 328.0f; +const REAL M45dB_PCM = 184.0f; +const REAL M50dB_PCM = 104.0f; +const REAL M55dB_PCM = 58.0f; +const REAL M60dB_PCM = 33.0f; +const REAL M65dB_PCM = 18.0f; +const REAL M70dB_PCM = 10.0f; +const REAL M75dB_PCM = 6.0f; +const REAL M80dB_PCM = 3.0f; +const REAL M85dB_PCM = 2.0f; +const REAL M90dB_PCM = 1.0f; + +const REAL MAXPCM = 32767.0f; + +/* Design constants (Change to fine tune the algorithms */ + +/* The following values are for hardware AEC and studio quality + * microphone */ + +/* NLMS filter length in taps (samples). A longer filter length gives + * better Echo Cancellation, but maybe slower convergence speed and + * needs more CPU power (Order of NLMS is linear) */ +#define NLMS_LEN (100*WIDEB*8) + +/* Vector w visualization length in taps (samples). + * Must match argv value for wdisplay.tcl */ +#define DUMP_LEN (40*WIDEB*8) + +/* minimum energy in xf. Range: M70dB_PCM to M50dB_PCM. Should be equal + * to microphone ambient Noise level */ +const REAL NoiseFloor = M55dB_PCM; + +/* Leaky hangover in taps. + */ +const int Thold = 60 * WIDEB * 8; + +// Adrian soft decision DTD +// left point. X is ratio, Y is stepsize +const float STEPX1 = 1.0, STEPY1 = 1.0; +// right point. STEPX2=2.0 is good double talk, 3.0 is good single talk. +const float STEPX2 = 2.5, STEPY2 = 0; +const float ALPHAFAST = 1.0f / 100.0f; +const float ALPHASLOW = 1.0f / 20000.0f; + + + +/* Ageing multiplier for LMS memory vector w */ +const REAL Leaky = 0.9999f; + +/* Double Talk Detector Speaker/Microphone Threshold. Range <=1 + * Large value (M0dB) is good for Single-Talk Echo cancellation, + * small value (M12dB) is good for Doulbe-Talk AEC */ +const REAL GeigelThreshold = M6dB; + +/* for Non Linear Processor. Range >0 to 1. Large value (M0dB) is good + * for Double-Talk, small value (M12dB) is good for Single-Talk */ +const REAL NLPAttenuation = M12dB; + +/* Below this line there are no more design constants */ + + +/* Exponential Smoothing or IIR Infinite Impulse Response Filter */ +class IIR_HP { + REAL x; + +public: + IIR_HP() { + x = 0.0f; + } + + REAL highpass(REAL in) { + const REAL a0 = 0.01f; /* controls Transfer Frequency */ + /* Highpass = Signal - Lowpass. Lowpass = Exponential Smoothing */ + x += a0 * (in - x); + return in - x; + }; +}; + +#if WIDEB==1 +/* 17 taps FIR Finite Impulse Response filter + * Coefficients calculated with + * www.dsptutor.freeuk.com/KaiserFilterDesign/KaiserFilterDesign.html + */ +class FIR_HP_300Hz { + REAL z[18]; + +public: + FIR_HP_300Hz() { + memset(this, 0, sizeof(FIR_HP_300Hz)); + } + + REAL highpass(REAL in) { + const REAL a[18] = { + // Kaiser Window FIR Filter, Filter type: High pass + // Passband: 300.0 - 4000.0 Hz, Order: 16 + // Transition band: 75.0 Hz, Stopband attenuation: 10.0 dB + -0.034870606, -0.039650206, -0.044063766, -0.04800318, + -0.051370874, -0.054082647, -0.056070227, -0.057283327, + 0.8214126, -0.057283327, -0.056070227, -0.054082647, + -0.051370874, -0.04800318, -0.044063766, -0.039650206, + -0.034870606, 0.0 + }; + memmove(z + 1, z, 17 * sizeof(REAL)); + z[0] = in; + REAL sum0 = 0.0, sum1 = 0.0; + int j; + + for (j = 0; j < 18; j += 2) { + // optimize: partial loop unrolling + sum0 += a[j] * z[j]; + sum1 += a[j + 1] * z[j + 1]; + } + return sum0 + sum1; + } +}; + +#else + +/* 35 taps FIR Finite Impulse Response filter + * Passband 150Hz to 4kHz for 8kHz sample rate, 300Hz to 8kHz for 16kHz + * sample rate. + * Coefficients calculated with + * www.dsptutor.freeuk.com/KaiserFilterDesign/KaiserFilterDesign.html + */ +class FIR_HP_300Hz { + REAL z[36]; + +public: + FIR_HP_300Hz() { + memset(this, 0, sizeof(FIR_HP_300Hz)); + } + + REAL highpass(REAL in) { + const REAL a[36] = { + // Kaiser Window FIR Filter, Filter type: High pass + // Passband: 150.0 - 4000.0 Hz, Order: 34 + // Transition band: 34.0 Hz, Stopband attenuation: 10.0 dB + -0.016165324, -0.017454365, -0.01871232, -0.019931411, + -0.021104068, -0.022222936, -0.02328091, -0.024271343, + -0.025187887, -0.02602462, -0.026776174, -0.027437767, + -0.028004972, -0.028474221, -0.028842418, -0.029107114, + -0.02926664, 0.8524841, -0.02926664, -0.029107114, + -0.028842418, -0.028474221, -0.028004972, -0.027437767, + -0.026776174, -0.02602462, -0.025187887, -0.024271343, + -0.02328091, -0.022222936, -0.021104068, -0.019931411, + -0.01871232, -0.017454365, -0.016165324, 0.0 + }; + memmove(z + 1, z, 35 * sizeof(REAL)); + z[0] = in; + REAL sum0 = 0.0, sum1 = 0.0; + int j; + + for (j = 0; j < 36; j += 2) { + // optimize: partial loop unrolling + sum0 += a[j] * z[j]; + sum1 += a[j + 1] * z[j + 1]; + } + return sum0 + sum1; + } +}; +#endif + +/* Recursive single pole IIR Infinite Impulse response High-pass filter + * + * Reference: The Scientist and Engineer's Guide to Digital Processing + * + * output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1] + * + * X = exp(-2.0 * pi * Fc) + * A0 = (1 + X) / 2 + * A1 = -(1 + X) / 2 + * B1 = X + * Fc = cutoff freq / sample rate + */ +class IIR1 { + REAL in0, out0; + REAL a0, a1, b1; + +public: + IIR1() { + memset(this, 0, sizeof(IIR1)); + } + + void init(REAL Fc) { + b1 = expf(-2.0f * M_PI * Fc); + a0 = (1.0f + b1) / 2.0f; + a1 = -a0; + in0 = 0.0f; + out0 = 0.0f; + } + + REAL highpass(REAL in) { + REAL out = a0 * in + a1 * in0 + b1 * out0; + in0 = in; + out0 = out; + return out; + } +}; + + +/* Recursive two pole IIR Infinite Impulse Response filter + * Coefficients calculated with + * http://www.dsptutor.freeuk.com/IIRFilterDesign/IIRFiltDes102.html + */ +class IIR2 { + REAL x[2], y[2]; + +public: + IIR2() { + memset(this, 0, sizeof(IIR2)); + } + + REAL highpass(REAL in) { + // Butterworth IIR filter, Filter type: HP + // Passband: 2000 - 4000.0 Hz, Order: 2 + const REAL a[] = { 0.29289323f, -0.58578646f, 0.29289323f }; + const REAL b[] = { 1.3007072E-16f, 0.17157288f }; + REAL out = + a[0] * in + a[1] * x[0] + a[2] * x[1] - b[0] * y[0] - b[1] * y[1]; + + x[1] = x[0]; + x[0] = in; + y[1] = y[0]; + y[0] = out; + return out; + } +}; + + +// Extention in taps to reduce mem copies +#define NLMS_EXT (10*8) + +// block size in taps to optimize DTD calculation +#define DTD_LEN 16 + + +class AEC { + // Time domain Filters + IIR_HP acMic, acSpk; // DC-level remove Highpass) + FIR_HP_300Hz cutoff; // 150Hz cut-off Highpass + REAL gain; // Mic signal amplify + IIR1 Fx, Fe; // pre-whitening Highpass for x, e + + // Adrian soft decision DTD (Double Talk Detector) + REAL dfast, xfast; + REAL dslow, xslow; + + // NLMS-pw + REAL x[NLMS_LEN + NLMS_EXT]; // tap delayed loudspeaker signal + REAL xf[NLMS_LEN + NLMS_EXT]; // pre-whitening tap delayed signal + REAL w[NLMS_LEN]; // tap weights + int j; // optimize: less memory copies + double dotp_xf_xf; // double to avoid loss of precision + float delta; // noise floor to stabilize NLMS + + // AES + float aes_y2; // not in use! + + // w vector visualization + REAL ws[DUMP_LEN]; // tap weights sums + int fdwdisplay; // TCP file descriptor + int dumpcnt; // wdisplay output counter + +/* Double-Talk Detector + * + * in d: microphone sample (PCM as REALing point value) + * in x: loudspeaker sample (PCM as REALing point value) + * return: from 0 for doubletalk to 1.0 for single talk + */ + float dtd(REAL d, REAL x); + + void AEC::leaky(); + +/* Normalized Least Mean Square Algorithm pre-whitening (NLMS-pw) + * The LMS algorithm was developed by Bernard Widrow + * book: Haykin, Adaptive Filter Theory, 4. edition, Prentice Hall, 2002 + * + * in d: microphone sample (16bit PCM value) + * in x_: loudspeaker sample (16bit PCM value) + * in stepsize: NLMS adaptation variable + * return: echo cancelled microphone sample + */ + REAL nlms_pw(REAL d, REAL x_, float stepsize); + +public: + // variables are public for visualization + int hangover; + float stepsize; + AEC(); + +/* Acoustic Echo Cancellation and Suppression of one sample + * in d: microphone signal with echo + * in x: loudspeaker signal + * return: echo cancelled microphone signal + */ + int AEC::doAEC(int d_, int x_); + + float AEC::getambient() { + return dfast; + }; + void AEC::setambient(float Min_xf) { + dotp_xf_xf -= delta; // subtract old delta + delta = (NLMS_LEN-1) * Min_xf * Min_xf; + dotp_xf_xf += delta; // add new delta + }; + void AEC::setgain(float gain_) { + gain = gain_; + }; + void AEC::openwdisplay(); + void AEC::setaes(float aes_y2_) { + aes_y2 = aes_y2_; + }; + double AEC::max_dotp_xf_xf(double u); +}; + +#define _AEC_H +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/aec_test.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/aec_test.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,91 @@ +/* aec_test.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004). All Rights Reserved. + * + * Test stub for Acoustic Echo Cancellation NLMS-pw algorithm + * Author: Andre Adrian, DFS Deutsche Flugsicherung + * + * + * fortune says: + * It's never as good as it feels, and it's never as bad as it seems. + * + * compile +c++ -DWIDEB=2 -O2 -o aec_test aec_test.cpp aec.cpp tcp.cpp -lm + * + * Version 1.3 set/get ambient in dB + */ + +#include +#include +#include +#include + +#include "tcp.h" +#include "aec.h" + +#define TAPS (40*WIDEB*8) + +typedef signed short MONO; + +typedef struct { + signed short l; + signed short r; +} STEREO; + +float dB2q(float dB) +{ + /* Dezibel to Ratio */ + return powf(10.0f, dB / 20.0f); +} + +float q2dB(float q) +{ + /* Ratio to Dezibel */ + return 20.0f * log10f(q); +} + + +/* Read a raw audio file (8KHz sample frequency, 16bit PCM, stereo) + * from stdin, echo cancel it and write it to stdout + */ +int main(int argc, char *argv[]) +{ + STEREO inbuf[TAPS], outbuf[TAPS]; + float visualize; + + fprintf(stderr, "usage: aec_test [ambient in dB] out.raw\n"); + + AEC aec; + + if (argc >= 2) { + aec.setambient(MAXPCM*dB2q(atof(argv[1]))); + } + + int taps; + float ambient; + while (taps = fread(inbuf, sizeof(STEREO), TAPS, stdin)) { + int i; + for (i = 0; i < taps; ++i) { + int s0 = inbuf[i].l; /* left channel microphone */ + int s1 = inbuf[i].r; /* right channel speaker */ + + /* and do NLMS */ + s0 = aec.doAEC(s0, s1); + + /* output one internal variable */ + // visualize = 16 * aec.hangover; + visualize = 32000 * aec.stepsize; + + outbuf[i].l = (short)(visualize); /* left channel */ + outbuf[i].r = s0; /* right channel echo cancelled mic */ + } + + fwrite(outbuf, sizeof(STEREO), taps, stdout); + } + ambient = aec.getambient(); + float ambientdB = q2dB(ambient / 32767.0f); + fprintf(stderr, "Ambient = %2.0f dB\n", ambientdB); + fflush(NULL); + + return 0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/aec_test.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/aec_test.txt Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,54 @@ +/*************************************************************** +A.5 Test source code +***************************************************************/ + +The microphone and loudspeaker signals have to be synchronized on a +sample-to-sample basis to make acoustic echo cancellation working. +An AC97 conformal on-board soundcard in a Personal Computer can be set +in a special stereo mode: The left channnel records microphone signal +and the right channel records loudspeaker signal. + +To set-up a Linux PC with ALSA sound system, electret microphone like +Labtec Verse 333 connected to Mic in and loudspeaker connected to right +Line out enter: + + amixer -q set 'Master',0 70% unmute + amixer -q set 'PCM',0 70% unmute + amixer -q set 'Line',0 0% mute + amixer -q set 'CD',0 0% mute + amixer -q set 'Mic',0 0% mute + amixer -q set 'Video',0 0% mute + amixer -q set 'Phone',0 0% mute + amixer -q set 'PC Speaker',0 0% mute + amixer -q set 'Aux',0 0% mute + amixer -q set 'Capture',0 50%,0% + amixer -q set 'Mic Boost (+20dB)',0 1 + amixer -q cset iface=MIXER,name='Capture Source' 0,5 + amixer -q cset iface=MIXER,name='Capture Switch' 1 + +To test the acoustic echo cancellation we simulate a real telephone +conversation in 5 steps: + (1) record far-end speaker, + (2) perform acoustic echo cancellation (this should change nothing) + (3) playback far-end speaker and at the same time record near-end speaker + (4) perform acoustic echo cancellation + (5) playback near-end speaker (far-end speech should be cancelled) + +# To compile the test program aec_test read file aec_test.cpp. + +# To record 10 seconds of speech into the file b.raw enter: +arecord -c 2 -t raw -f S16_LE -r 16000 -d 10 >b.raw + +# To perform AEC at the far-end enter: +./aec_test b1.raw + +# To playback file b1.raw and simultaneously record b2.raw enter both +# commands in one go: +aplay -c 2 -t raw -f S16_LE -r 16000 b1.raw & +arecord -c 2 -t raw -f S16_LE -r 16000 -d 10 >b2.raw + +# To perform AEC at the near-end enter: +./aec_test b3.raw + +# To playback the echo-cancelled near-end enter: +aplay -c 2 -t raw -f S16_LE -r 16000 b3.raw diff -r 9cadc470e3da -r 13be24d74cd2 intercom/cirbuf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/cirbuf.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,69 @@ +/* cirbuf.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Circular buffers + * + * Version 0.2 + */ + +#include +#include + +#include "oss.h" +#include "cirbuf.h" +#include "intercomd.h" + +CIRBUF::CIRBUF() +{ + bzero(buf, CIRBUFSIZE); + in = out = len = 0; +} + +void CIRBUF::init() +{ + bzero(buf, CIRBUFSIZE); + in = out = len = 0; +} + +int CIRBUF::push(char *from, int size) +{ + memcpy(buf + in, from, size); + in += size; + if (in >= CIRBUFSIZE) { + in -= CIRBUFSIZE; + } + len += size; + if (len > CIRBUFSIZE) { + int oversize = (((len - CIRBUFSIZE) / FRAGSIZE)) * FRAGSIZE; + if (oversize < len - CIRBUFSIZE) { + oversize += FRAGSIZE; + } + // delete oldest if overrun + out += oversize; + if (out >= CIRBUFSIZE) { + out -= CIRBUFSIZE; + } + len -= oversize; + return -oversize; + } else { + return OKAY; + } +} + +int CIRBUF::pop(char *to, int size) +{ + if (len < size) { + // play out silence if underrun + bzero(to, size); + return ERROR; + } + memcpy(to, buf + out, size); + out += size; + if (out >= CIRBUFSIZE) { + out -= CIRBUFSIZE; + } + len -= size; + return OKAY; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/cirbuf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/cirbuf.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,34 @@ +/* cirbuf.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Circular Buffers + * + * Version 0.2 + */ +#ifndef _CIRBUF_H + +// must be multiple of FRAGSIZE and FRAMESIZE +#define CIRBUFSIZE (WIDEB*2*80*8*2) + +/* circular buffer for FRAGSIZE to FRAMESIZE conversion with + * overrun/underrun */ +class CIRBUF { + char buf[CIRBUFSIZE]; // must be multiple of FRAGSIZE and FRAMESIZE + int in; + int out; + int len; + +public: + CIRBUF(); + void CIRBUF::init(); + int CIRBUF::push(char *from, int size); + int CIRBUF::pop(char *to, int size); + int getlen() { + return len; + } +}; + +#define _CIRBUF_H +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/Makefile Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,108 @@ +# ----------------------------------------------------------------------------- +# Unix makefile for compiling and testing the UGST G.711 implementation +# 01.May.94 - Implemented by +# 01.Mar.95 - Updated for test procedure +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose an AWK; suggest use GNU version +# (available via anonymous ftp) +# ------------------------------------------------ +AWK = gawk +AWK_CMD = '$$6~/[0-9]+:[0-9][0-9]/ {print "sb -over",$$NF};END{print "exit"}' + +# ---------------------------------------------------------------------- +# Choose compiler. Sun: use cc. HP: gotta use gcc make ... CC=\$\(GCC\) +# ---------------------------------------------------------------------- +GCC = gcc -fno-builtin -Wall +CC_OPT = -I../utl -O3 + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = -pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# Choose a file comparison utility: +# ------------------------------------------------ +DIFF = cf -q + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +RM=rm -f +DEMO=./g711demo +REF_VECTORS= sweep-r.a sweep-r.a-a sweep-r.rea sweep-r.reu \ + sweep-r.u sweep-r.u-u sweep.src +TEST_VECTORS = sweep.a sweep.a-a sweep.rea sweep.reu sweep.u sweep.u-u +G711_OBJ = g711.o g711demo.o + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +.c.o: + $(CC) $(CC_OPT) -c $< + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g711demo + +anyway: clean g711demo + +clean: + $(RM) $(G711_OBJ) g711demo sweep.* + +cleantest: + $(RM) $(TEST_VECTORS) $(REF_VECTORS) + +veryclean: clean cleantest + $(RM) g711demo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711demo: g711demo.o g711.o + $(CC) -o g711demo g711demo.o g711.o -lm + +shiftbit: shiftbit.c ugstdemo.h + $(CC) -o shiftbit shiftbit.c + +# ------------------------------------------------ +# Test portability +# Note: there are no compliance test vectors associated with the G711 module +# ------------------------------------------------ +test: proc comp + +proc: sweep.src + # sweep-r.* have been generated from sweep.src in a reference environment + # results of the comparisons shall yield 0 different samples! + $(DEMO) A lilo sweep.src sweep.a 256 1 256 + $(DEMO) u lilo sweep.src sweep.u 256 1 256 + $(DEMO) A lili sweep.src sweep.a-a 256 1 256 + $(DEMO) u lili sweep.src sweep.u-u 256 1 256 + $(DEMO) A loli sweep.a sweep.rea 256 1 256 + $(DEMO) u loli sweep.u sweep.reu 256 1 256 + +comp: sweep-r.u-u + $(DIFF) sweep.a sweep-r.a + $(DIFF) sweep.a-a sweep-r.a-a + $(DIFF) sweep.rea sweep-r.rea + $(DIFF) sweep.reu sweep-r.reu + $(DIFF) sweep.u sweep-r.u + $(DIFF) sweep.u-u sweep-r.u-u + +# ------------------------------------------------ +# Extract from archive, if necessary +# ------------------------------------------------ +sweep.src: tst-g711.zip + $(UNZIP) tst-g711.zip sweep.src + swapover -if little sweep.src + +sweep-r.u-u: tst-g711.zip + $(UNZIP) tst-g711.zip sweep-r.* + swapover -if little sweep-r.* + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/g711.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/g711.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,314 @@ +/* Version 3.01 - 31.Jan.2000 +============================================================================= + + U U GGG SSS TTTTT + U U G S T + U U G GG SSS T + U U G G S T + UUUU GGG SSS T + + ======================================== + ITU-T - USER'S GROUP ON SOFTWARE TOOLS + ======================================== + + + ============================================================= + 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". + ============================================================= + + +MODULE: G711.C, G.711 ENCODING/DECODING FUNCTIONS + +ORIGINAL BY: + + Simao Ferraz de Campos Neto Rudolf Hofmann + CPqD/Telebras PHILIPS KOMMUNIKATIONS INDUSTRIE AG + DDS/Pr.11 Kommunikationssysteme + Rd. Mogi Mirim-Campinas Km.118 Thurn-und-Taxis-Strasse 14 + 13.085 - Campinas - SP (Brazil) D-8500 Nuernberg 10 (Germany) + + Phone : +55-192-39-6396 Phone : +49 911 526-2603 + FAX : +55-192-53-4754 FAX : +49 911 526-3385 + EMail : tdsimao@venus.cpqd.ansp.br EMail : HF@PKINBG.UUCP + + +FUNCTIONS: + +alaw_compress: ... compands 1 vector of linear PCM samples to A-law; + uses 13 Most Sig.Bits (MSBs) from input and 8 Least + Sig. Bits (LSBs) on output. + +alaw_expand: ..... expands 1 vector of A-law samples to linear PCM; + use 8 Least Sig. Bits (LSBs) from input and + 13 Most Sig.Bits (MSBs) on output. + +ulaw_compress: ... compands 1 vector of linear PCM samples to u-law; + uses 14 Most Sig.Bits (MSBs) from input and 8 Least + Sig. Bits (LSBs) on output. + +ulaw_expand: ..... expands 1 vector of u-law samples to linear PCM + use 8 Least Sig. Bits (LSBs) from input and + 14 Most Sig.Bits (MSBs) on output. + +PROTOTYPES: in g711.h + +HISTORY: +Apr/91 1.0 First version of the G711 module +10/Dec/1991 2.0 Break-up in individual functions for A,u law; + correction of bug in compression routines (use of 1 + and 2 complement); Demo program inside module. +08/Feb/1992 3.0 Demo as separate file; +31/Jan/2000 3.01 Updated documentation text; no change in functions + +13jan2005 Byte for compressed data +============================================================================= +*/ + +/* + * .......... I N C L U D E S .......... + */ + +/* Global prototype functions */ +#include "g711.h" + +/* + * .......... F U N C T I O N S .......... + */ + +/* ................... Begin of alaw_compress() ..................... */ +/* + ========================================================================== + + FUNCTION NAME: alaw_compress + + DESCRIPTION: ALaw encoding rule according ITU-T Rec. G.711. + + PROTOTYPE: void alaw_compress(long lseg, short *linbuf, short *logbuf) + + PARAMETERS: + lseg: (In) number of samples + linbuf: (In) buffer with linear samples (only 12 MSBits are taken + into account) + logbuf: (Out) buffer with compressed samples (8 bit right justified, + without sign extension) + + RETURN VALUE: none. + + HISTORY: + 10.Dec.91 1.0 Separated A-law compression function + + ========================================================================== +*/ +void alaw_compress(long lseg, short *linbuf, Byte *logbuf) +{ + short ix, iexp; + long n; + + for (n = 0; n < lseg; n++) { + ix = linbuf[n] < 0 /* 0 <= ix < 2048 */ + ? (~linbuf[n]) >> 4 /* 1's complement for negative values */ + : (linbuf[n]) >> 4; + + /* Do more, if exponent > 0 */ + if (ix > 15) { /* exponent=0 for ix <= 15 */ + iexp = 1; /* first step: */ + while (ix > 16 + 15) { /* find mantissa and exponent */ + ix >>= 1; + iexp++; + } + ix -= 16; /* second step: remove leading '1' */ + + ix += iexp << 4; /* now compute encoded value */ + } + if (linbuf[n] >= 0) + ix |= (0x0080); /* add sign bit */ + + logbuf[n] = ix ^ (0x0055); /* toggle even bits */ + } +} + +/* ................... End of alaw_compress() ..................... */ + + +/* ................... Begin of alaw_expand() ..................... */ +/* + ========================================================================== + + FUNCTION NAME: alaw_expand + + DESCRIPTION: ALaw decoding rule according ITU-T Rec. G.711. + + PROTOTYPE: void alaw_expand(long lseg, short *logbuf, short *linbuf) + + PARAMETERS: + lseg: (In) number of samples + logbuf: (In) buffer with compressed samples (8 bit right justified, + without sign extension) + linbuf: (Out) buffer with linear samples (13 bits left justified) + + RETURN VALUE: none. + + HISTORY: + 10.Dec.91 1.0 Separated A-law expansion function + + ============================================================================ +*/ +void alaw_expand(long lseg, Byte *logbuf, short *linbuf) +{ + short ix, mant, iexp; + long n; + + for (n = 0; n < lseg; n++) { + ix = logbuf[n] ^ (0x0055); /* re-toggle toggled bits */ + + ix &= (0x007F); /* remove sign bit */ + iexp = ix >> 4; /* extract exponent */ + mant = ix & (0x000F); /* now get mantissa */ + if (iexp > 0) + mant = mant + 16; /* add leading '1', if exponent > 0 */ + + mant = (mant << 4) + (0x0008); /* now mantissa left justified and */ + /* 1/2 quantization step added */ + if (iexp > 1) /* now left shift according exponent */ + mant = mant << (iexp - 1); + + linbuf[n] = logbuf[n] > 127 /* invert, if negative sample */ + ? mant : -mant; + } +} + +/* ................... End of alaw_expand() ..................... */ + + +/* ................... Begin of ulaw_compress() ..................... */ +/* + ========================================================================== + + FUNCTION NAME: ulaw_compress + + DESCRIPTION: Mu law encoding rule according ITU-T Rec. G.711. + + PROTOTYPE: void ulaw_compress(long lseg, short *linbuf, short *logbuf) + + PARAMETERS: + lseg: (In) number of samples + linbuf: (In) buffer with linear samples (only 12 MSBits are taken + into account) + logbuf: (Out) buffer with compressed samples (8 bit right justified, + without sign extension) + + RETURN VALUE: none. + + HISTORY: + 10.Dec.91 1.0 Separated mu-law compression function + + ========================================================================== +*/ +void ulaw_compress(long lseg, short *linbuf, Byte *logbuf) +{ + long n; /* samples's count */ + short i; /* aux.var. */ + short absno; /* absolute value of linear (input) sample */ + short segno; /* segment (Table 2/G711, column 1) */ + short low_nibble; /* low nibble of log companded sample */ + short high_nibble; /* high nibble of log companded sample */ + + for (n = 0; n < lseg; n++) { + /* -------------------------------------------------------------------- */ + /* Change from 14 bit left justified to 14 bit right justified */ + /* Compute absolute value; adjust for easy processing */ + /* -------------------------------------------------------------------- */ + absno = linbuf[n] < 0 /* compute 1's complement in case of */ + ? ((~linbuf[n]) >> 2) + 33 /* negative samples */ + : ((linbuf[n]) >> 2) + 33; /* NB: 33 is the difference value */ + /* between the thresholds for */ + /* A-law and u-law. */ + if (absno > (0x1FFF)) /* limitation to "absno" < 8192 */ + absno = (0x1FFF); + + /* Determination of sample's segment */ + i = absno >> 6; + segno = 1; + while (i != 0) { + segno++; + i >>= 1; + } + + /* Mounting the high-nibble of the log-PCM sample */ + high_nibble = (0x0008) - segno; + + /* Mounting the low-nibble of the log PCM sample */ + low_nibble = (absno >> segno) /* right shift of mantissa and */ + &(0x000F); /* masking away leading '1' */ + low_nibble = (0x000F) - low_nibble; + + /* Joining the high-nibble and the low-nibble of the log PCM sample */ + logbuf[n] = (high_nibble << 4) | low_nibble; + + /* Add sign bit */ + if (linbuf[n] >= 0) + logbuf[n] = logbuf[n] | (0x0080); + } +} + +/* ................... End of ulaw_compress() ..................... */ + + + +/* ................... Begin of ulaw_expand() ..................... */ +/* + ========================================================================== + + FUNCTION NAME: ulaw_expand + + DESCRIPTION: Mu law decoding rule according ITU-T Rec. G.711. + + PROTOTYPE: void ulaw_expand(long lseg, short *logbuf, short *linbuf) + + PARAMETERS: + lseg: (In) number of samples + logbuf: (In) buffer with compressed samples (8 bit right justified, + without sign extension) + linbuf: (Out) buffer with linear samples (14 bits left justified) + + RETURN VALUE: none. + + HISTORY: + 10.Dec.91 1.0 Separated mu law expansion function + + ============================================================================ +*/ + +void ulaw_expand(long lseg, Byte *logbuf, short *linbuf) +{ + long n; /* aux.var. */ + short segment; /* segment (Table 2/G711, column 1) */ + short mantissa; /* low nibble of log companded sample */ + short exponent; /* high nibble of log companded sample */ + short sign; /* sign of output sample */ + short step; + + for (n = 0; n < lseg; n++) { + sign = logbuf[n] < (0x0080) /* sign-bit = 1 for positiv values */ + ? -1 : 1; + mantissa = ~logbuf[n]; /* 1's complement of input value */ + exponent = (mantissa >> 4) & (0x0007); /* extract exponent */ + segment = exponent + 1; /* compute segment number */ + mantissa = mantissa & (0x000F); /* extract mantissa */ + + /* Compute Quantized Sample (14 bit left justified!) */ + step = (4) << segment; /* position of the LSB */ + /* = 1 quantization step) */ + linbuf[n] = sign * /* sign */ + (((0x0080) << exponent) /* '1', preceding the mantissa */ + +step * mantissa /* left shift of mantissa */ + + step / 2 /* 1/2 quantization step */ + - 4 * 33); + } +} + +/* ................... End of ulaw_expand() ..................... */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/g711.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/g711.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,47 @@ +/* + ============================================================================ + File: G711.H + ============================================================================ + + UGST/ITU-T G711 MODULE + + GLOBAL FUNCTION PROTOTYPES + + History: + 10.Dec.91 v1.0 First version + 08.Feb.92 v1.1 Non-ANSI prototypes added + 11.Jan.96 v1.2 Fixed misleading prototype parameter names in + alaw_expand() and ulaw_compress(); changed to + smart prototypes , + and + 31.Jan.2000 v3.01 [version no.aligned with g711.c] Updated list of + compilers for smart prototypes + 13jan2005 Byte for compressed data + ============================================================================ +*/ +#ifndef G711_defined +#define G711_defined 301 + +/* Smart function prototypes: for [ag]cc, VaxC, and [tb]cc */ +#if !defined(ARGS) +#if (defined(__STDC__) || defined(VMS) || defined(__DECC) || defined(MSDOS) || defined(__MSDOS__)) || defined (__CYGWIN__) || defined (_MSC_VER) +#define ARGS(s) s +#else +#define ARGS(s) () +#endif +#endif + +typedef unsigned char Byte; + +/* Function prototypes */ +void alaw_compress ARGS((long lseg, short *linbuf, Byte *logbuf)); +void alaw_expand ARGS((long lseg, Byte *logbuf, short *linbuf)); +void ulaw_compress ARGS((long lseg, short *linbuf, Byte *logbuf)); +void ulaw_expand ARGS((long lseg, Byte *logbuf, short *linbuf)); + +/* Definitions for better user interface (?!) */ +#define IS_LIN 1 +#define IS_LOG 0 + +#endif +/* .......................... End of G711.H ........................... */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/g711.rme --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/g711.rme Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,79 @@ +g711.rme - Readme for the G.711 module + + + U G S T + + Read me file for G711 module + (01.Feb.2000) + + ============================================================= + 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". + ============================================================= + + +The UGST G711 module, version 3.01 (31.Jan.2000) needs the following +files: + +g711.c .......... G711 module itself; needs the prototypes in G711.H. +g711demo.c ...... Demosntration program for the G711 module; needs the files + g711.c and ugstdemo.h in the current directory. +ugstdemo.h ...... prototypes and definitions needed by UGST demo programs. +g711.h .......... prototypes and definitions needed by the G711 module. + +As an auxililiary program, there is: +shiftbit.c ...... program to shift (with sign extension) to left or right the + input file, saving in the output file. You may need this if + you speech data file has less than 16 bit resolution and not + left-justified. + +Makefiles: +~~~~~~~~~~ +Makefiles have been provided for automatic build-up of the executable program +and to process the test files: +makefile.unx .... makefile for compiling on an Unix environment +makefile.tcc .... makefile for compiling with MSDOS Borland [bt]cc +makefile.cl ..... makefile for compiling with MS Visual C compiler +makefile.djc .... makefile for compiling with DJGPP MSDOS port of gcc +make-vms.com .... DCL for compiling in the VAX/VMS environment + +Testing: +~~~~~~~~ +The provided makefiles can run a portability test on the demo program. They +need the archive tst-g711.zip ([pk]zip compatible archive) and [pk]unzip to +extract the proper source and reference processed files. The contents of this +archive file is: +sweep.src ....... THE reference file +sweep-r.a ....... reference file: sweep.src encoded by A-law (A lilo) +sweep-r.a-a ..... reference file: sweep-r.a decoded by A-law (A loli) +sweep-r.rea ..... reference file: sweep.src enc'd *and* decoded by A-law (lili) +sweep-r.u ....... reference file: sweep.src enc'd by u-law (u lilo) +sweep-r.u-u ..... reference file: sweep-r.u dec'd by u-law (u loli) +sweep-r.reu ..... reference file: sweep.src enc'd *and* decoded by u-law (lili) + +NOTE! These files are in the big-endian (high-byte first) format. Therefore, + before using under MSDOS or VAX/VMS, the files need to be byte-swapped. + See unsupported program sb in the ../unsup directory. + The CRC-32 (unsup utility crc) for each of the test files are + given below: + + File name CRC32-BE CRC32-LE Size + ------------------------------------------ + sweep-r.a E714C343 74719FE4 131072 + sweep-r.a-a 1595D5BA ABCEAA69 131072 + sweep-r.rea 1595D5BA ABCEAA69 131072 + sweep-r.reu D6812645 63641C01 131072 + sweep-r.u E7513B35 CD170E15 131072 + sweep-r.u-u D6812645 63641C01 131072 + sweep.src 67B11DDE C8BA7682 131072 + ------------------------------------------ + Notes: + - CRC32-BE: CRC-32 for the big endian format (i.e., most + non-Intel Unix systems) + - CRC32-LE: CRC-32 for the little endian format (Intel CPUs, etc) + - Size: file size, in bytes +-- + - 31.Jan.2000 \ No newline at end of file diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/g711demo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/g711demo.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,459 @@ +/* 11.Apr.2000 v3.2 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + G711DEMO.C + + Description: + ~~~~~~~~~~~~ + Example-program for converting from linear samples to A/u law log + compression and vice-versa, according to ITU-T Rec.G711. + + Usage: + ~~~~~~ + $ g711demo [-?] [-r] [-skip skip] Law Transf InpFile OutFile + [BlockSize [1stBlock [NoOfBlocks]]] + + where: + Law is the law desired (either A or u) + Transf is the desired convertion on the input file: + [lili], linear to linear: lin -> (A/u)log -> lin + [lilo], linear to (A/u)-log + [loli], (A/u) log to linear + InpFile is the name of the file to be processed; + OutFile is the name with the compressed/expanded data; + BlockSize is the block size, in number of samples (16 -bit words) + (default is 256); + 1stBlock is the number of the first block of the input file + to be processed. (Default: 1) + NoOfBlocks is the number of blocks to be processed, starting on + block "1stBlock". (default is til end-of-file) + + Options: + -? display usage and quit. + -r disables even-bit swap by A-law encoding and decoding. + By default, even bits of the A-law samples ARE inverted + by alaw_compress() at return time, as well as by + alaw_expand() at its beginning. With the option + "-r", the log samples have NOT their even bits + inverted before being saved to disk NOR after + read from a file. + -skip is the number of samples to skip before the beginning + of the 1st block. + + Example: + $ G711 u lili voice.ref voice.rel 256 3 45 + + The command above takes the samples in file "voice.ref" and converts + them to A-law and back to linear, saving them into file "voice.rel", + starting at block 3 for 45 blocks, each block being 256 samples wide. + + Variables: + ~~~~~~~~~~ + law law to use (either A or u) + conv desired processing + inpfil input file name; + outfil output file name; + N block size; + N1 first block to filter; + N2 no. of blocks to filter; + + Compilation of Demo Program: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + The test program allows to process binary/ILS files of any size by + loading segments of data from/to file. The size of the working + segment must be entered. + + VAX/VMS: + $ CC G711 + $ link G711 + $ G711 :== $G711_Disk:[G711_Dir]G711 + $ G711 u lili ifile ofile 233 3 47 + + This command line invokes the u-law utility, converts from linear + over ulaw to linear. It processes the input file "ifile" by + loading segments of 233 samples and writes the result to "ofile", + from the 3rd segment, for 47 segments. + + Turbo-C, Turbo-C++: + > tcc G711 + > G711 a lilo ifile ofile 39 1 + + This command line invokes the a-law utility, converts from linear + to a-law. It processes the input file "ifile" by loading + segments of 39 samples and writes the result (alaw-samples) to + "ofile", starting from the beginning of the file. It will ask + the number of segments. + + HighC (MetaWare, version R2.32): + > hc386 G711.c + > Run386 G711 a loli ifile ofile 3333 + + This command line invokes the a-law utility, converts from a-law + to linear It processes the input file "ifile" (alaw-samples) by + loading segments of 3333 samples and writes the result (linear + samples) to "ofile". It will ask the starting segment and the + number of segments. + + SunC (SunOS - BSD Unix) + # cc -o g711demo g711demo.c + # g711demo a lilo ifile ofile 256 1 132 + + Exit values: + ~~~~~~~~~~~~ + 0 success (all but VMS); + 1 success (only in VMS); + 2 error opening input file; + 3 error creating output file; + 4 error moving pointer to desired start of conversion; + 5 error reading input file; + 6 error writing to file; + 7 invalid law + 8 invalid conversion + 10 error allocating memory + + Prototypes: + ~~~~~~~~~~~ + Needs ugstdemo.h and includes g711.h. + + Authors: + ~~~~~~~~ + Simao Ferraz de Campos Neto Rudolf Hofmann + CPqD/Telebras PHILIPS KOMMUNIKATIONS INDUSTRIE AG + DDS/Pr.11 Kommunikationssysteme + Rd. Mogi Mirim-Campinas Km.118 Thurn-und-Taxis-Strasse 14 + 13.080-061 - Campinas - SP (Brazil) D-8500 Nuernberg 10 (Germany) + + Phone : +55-192-39-6637 Phone : +49-911-526-2603 + FAX : +55-192-39-2179 FAX : +49-911-526-3385 + EMail : tdsimao@cpqd.ansp.br EMail : hf@pkinbg.uucp + + History: + ~~~~~~~~ + 07.Feb.1991 v1.0 Release of 1st demo program for G711 module (CPqD). + 10.Dec.1991 v2.0 Demo program incorporated in G711 module and + rebuild by PKI. + 08.Feb.1992 v2.1 Demo separated from module file; ILS header + manipulation removed; low level I/O; changes to + assure compatibility with Unix (SunOS). + 14.Apr.1993 v3.0 Inclusion of display_usage() and of option "-r" + + 22.Feb.1996 v3.1 Removed compilation warnings, included headers as + suggested by Kirchherr (FI/DBP Telekom) to run under + OpenVMS/AXP + 11.Apr.2000 v3.2 Corrected bug that made incorrect calculation on + total number of blocks to process when the block + size is not a multiple of the file + size. + 13jan2005 Byte for compressed data + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#include "ugstdemo.h" /* UGST defines for demo programs */ + +/* Include general headers */ +#include /* UNIX Standard I/O Definitions */ +#include /* Character Type Classification */ +#include /* String handling functions */ +#include /* General utility definitions */ +#include + +/* Include OS dependent headers */ +#if defined(VMS) +#include +#else /* Others */ +#include +#endif + + +/* G711 module functions */ +#include "g711.h" + + +/* + -------------------------------------------------------------------------- + void display_usage() + + Displays usage of the program. Upon completion, aborts the program. + + Created by , 14.Apr.93 + + -------------------------------------------------------------------------- +*/ +#define FP(x) fprintf(stderr, x) +void display_usage() +{ + FP("\n G711DEMO.C --- Version v3.2 of 11.Apr.2000 \n"); + FP("\n"); + FP(" Description:\n"); + FP(" ~~~~~~~~~~~~\n"); + FP(" Example-program for converting from linear samples to A/u law log\n"); + FP(" compression and vice-versa, according to ITU-T Rec.G711.\n"); + FP("\n"); + FP(" Usage:\n"); + FP(" ~~~~~~\n"); + FP(" $ G711 [-r] Law Transf InpFile OutFile BlkSize 1stBlock NoOfBlocks\n"); + FP("\n"); + FP(" where:\n"); + FP(" Law is the law desired (either A or u)\n"); + FP(" Transf is the desired convertion on the input file:\n"); + FP(" [lili], linear to linear: lin -> (A/u)log -> lin\n"); + FP(" [lilo], linear to (A/u)-log\n"); + FP(" [loli], (A/u) log to linear\n"); + FP(" InpFile is the name of the file to be processed;\n"); + FP(" OutFile is the name with the compressed/expanded data;\n"); + FP(" BlkSize is number of samples per block [256];\n"); + FP(" 1stBlock is the number of the first block of the input file\n"); + FP(" to be processed [1].\n"); + FP(" NoOfBlocks is the number of blocks to be processed, starting on\n"); + FP(" block `1stBlock'. Default is til end-of-file.\n"); + FP("\n"); + FP(" Options:\n"); + FP(" -? displays this message.\n"); + FP(" -r disables even-bit swap by A-law encoding and decoding.\n"); + FP(" -skip is the number of samples to skip.\n"); + FP("\n"); + + /* Quit program */ + exit(1); +} + +#undef FP +/* ..................... End of display_usage() .......................... */ + + +/* + ************************************************************************** + *** *** + *** Demo-Program for testing the correct implementation *** + *** and to show how to use the programs *** + *** *** + ************************************************************************** +*/ +int main(argc, argv) +int argc; +char *argv[]; +{ + long i, N, N1, N2, smpno, tot_smpno, cur_blk; + short *lin_buff; /* linear input samples */ + Byte *log_buff; /* compressed data */ + short *lon_buff; /* quantized output samples */ + char inpfil[127], outfil[127]; + FILE *Fi, *Fo; + int inp, out; + char law[4], lilo[8]; + short inp_type, out_type; + char revert_even_bits = 1; + clock_t t1, t2; /* aux. for CPU-time measurement */ +#ifdef VMS + char mrs[15]; /* for correct mrs in VMS environment */ +#endif + long start_byte, skip = 0; + +/* + * GETTING PARAMETERS + */ + /* Get options */ + if (argc < 2) + display_usage(); + else { + while (argc > 1 && argv[1][0] == '-') + if (argv[1][1] == 'r') { + /* Disable revertion of even bits */ + revert_even_bits = 0; + + /* Move argv over the option to the 1st mandatory argument */ + argv++; + + /* Update argc */ + argc--; + } else if (strcmp(argv[1], "-skip") == 0) { + /* Get skip length */ + skip = atol(argv[2]); + + /* Check bounds */ + if (skip < 0) { + fprintf(stderr, "Skip has to be > 0!\n"); + exit(10); + } + + /* Move argv over the option to the next argument */ + argv += 2; + + /* Update argc */ + argc -= 2; + } else if (argv[1][1] == '?') { + /* Display intructions */ + display_usage(); + } else { + fprintf(stderr, + "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); + display_usage(); + } + } + + + /* Get parameters */ + GET_PAR_S(1, "_Law (A, u): ................. ", law); + GET_PAR_S(2, "_Transf (lili,lilo,loli): .... ", lilo); + GET_PAR_S(3, "_File to be converted: ....... ", inpfil); + GET_PAR_S(4, "_Output File: ................ ", outfil); + FIND_PAR_L(5, "_Block Length: ............... ", N, 256); + FIND_PAR_L(6, "_Start Block: ................ ", N1, 1); + FIND_PAR_L(7, "_No. of Blocks: .............. ", N2, 0); + + + /* ......... SOME INITIALIZATIONS ......... */ + --N1; + + /* Classification of the conversion desired */ + inp_type = toupper(lilo[1]) == 'O' ? IS_LOG : IS_LIN; + out_type = toupper(lilo[3]) == 'O' ? IS_LOG : IS_LIN; + if ((out_type == IS_LOG) && (inp_type == IS_LOG)) + HARAKIRI("log. to log. makes no sense! Aborted...\n", 8); + + /* Classification of law */ + law[0] = toupper(law[0]); + if ((law[0] != (char) 'A') && (law[0] != (char) 'U')) + HARAKIRI(" Invalid law!\n", 7); + + /* .......... ALLOCATION OF BUFFERS .......... */ + + if ((lin_buff = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Can't allocate memory for input buffer\n", 10); + + if ((log_buff = (Byte *) calloc(N, sizeof(Byte))) == NULL) + HARAKIRI("Can't allocate memory for output buffer\n", 10); + + if ((lon_buff = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Can't allocate memory for temporary buffer\n", 10); + + + /* .......... FILE OPERATIONS .......... */ + +#ifdef VMS + sprintf(mrs, "mrs=%d", 2 * N); +#endif + + /* Open input file */ + if ((Fi = fopen(inpfil, RB)) == NULL) + KILL(inpfil, 2); + inp = fileno(Fi); + + /* Open (create) output file */ + if ((Fo = fopen(outfil, WB)) == NULL) + KILL(outfil, 3); + out = fileno(Fo); + + /* Define starting byte in file */ + start_byte = (N1 * N + skip) * sizeof(short); + + /* ... and move file's pointer to 1st desired block */ + if (fseek(Fi, (N1 * N + skip) * sizeof(short), 0) < 0l) + KILL(inpfil, 4); + + /* Check whether is to process til end-of-file */ + if (N2 == 0) { + struct stat st; + /* ... hey, need to skip the delayed samples! ... */ + stat(inpfil, &st); + N2 = ceil((st.st_size - start_byte) / (double) (N * sizeof(short))); + } + + +/* + * ......... COMPRESSION/EXPANSION ......... + */ + t1 = clock(); /* measure CPU-time */ + tot_smpno = 0; + + switch (law[0]) { + /* ......... Process A-law rule ......... */ + case 'A': + + /* Input: LINEAR | Output: LOG */ + if (inp_type == IS_LIN && out_type == IS_LOG) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + if ((smpno = fread(lin_buff, sizeof(short), N, Fi)) < 0) + KILL(inpfil, 5); + alaw_compress(smpno, lin_buff, log_buff); + if (!revert_even_bits) + for (i = 0; i < smpno; i++) + log_buff[i] ^= 0x0055; + + if ((smpno = fwrite(log_buff, sizeof(Byte), smpno, Fo)) < 0) + KILL(outfil, 6); + } + + /* Input: LINEAR | Output: LINEAR */ + else if (inp_type == IS_LIN && out_type == IS_LIN) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + if ((smpno = fread(lin_buff, sizeof(short), N, Fi)) < 0) + KILL(inpfil, 5); + alaw_compress(smpno, lin_buff, log_buff); + alaw_expand(smpno, log_buff, lon_buff); + if ((smpno = fwrite(lon_buff, sizeof(short), smpno, Fo)) < 0) + KILL(outfil, 6); + } + + /* Input: LOG | Output: LINEAR */ + else if (inp_type == IS_LOG) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + if ((smpno = fread(log_buff, sizeof(Byte), N, Fi)) < 0) + KILL(inpfil, 5); + if (!revert_even_bits) + for (i = 0; i < smpno; i++) + log_buff[i] ^= 0x0055; + alaw_expand(smpno, log_buff, lon_buff); + if ((smpno = fwrite(lon_buff, sizeof(short), smpno, Fo)) < 0) + KILL(outfil, 6); + } + break; + + /* ......... Process u-law rule ......... */ + + case 'U': + /* Input: LINEAR | Output: LOG */ + if (inp_type == IS_LIN && out_type == IS_LOG) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + smpno = fread(lin_buff, sizeof(short), N, Fi); + ulaw_compress(smpno, lin_buff, log_buff); + smpno = fwrite(log_buff, sizeof(Byte), smpno, Fo); + } + + /* Input: LINEAR | Output: LINEAR */ + else if (inp_type == IS_LIN && out_type == IS_LIN) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + smpno = fread(lin_buff, sizeof(short), N, Fi); + ulaw_compress(smpno, lin_buff, log_buff); + ulaw_expand(smpno, log_buff, lon_buff); + smpno = fwrite(lon_buff, sizeof(short), smpno, Fo); + } + + /* Input: LOG | Output: LINEAR */ + else if (inp_type == IS_LOG) + for (tot_smpno = cur_blk = 0; cur_blk < N2; + cur_blk++, tot_smpno += smpno) { + smpno = fread(log_buff, sizeof(Byte), N, Fi); + ulaw_expand(smpno, log_buff, lon_buff); + smpno = fwrite(lon_buff, sizeof(short), smpno, Fo); + } + break; + } + + + /* ......... FINALIZATIONS ......... */ + + t2 = clock(); + printf("Speed: %f sec CPU-time for %ld processed samples\n", + (t2 - t1) / (double) CLOCKS_PER_SEC, tot_smpno); + + fclose(Fi); + fclose(Fo); +#ifndef VMS + return (0); +#endif +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/gen-lic.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/gen-lic.txt Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,162 @@ + + + ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE + + + + This "General Public License" is published in the Annex 1 of the + ITU-T Recommendation on "SOFTWARE TOOLS FOR HOMOGENITY OF RESULTS + IN THE STANDARDIZATION PROCESS OF SPEECH AND AUDIO CODERS", + approved in Geneva, 2000. + + + TERMS AND CONDITIONS + + 1. This License Agreement applies to any module or other work + related to the ITU-T Software Tool Library, and developed by the + User's Group on Software Tools. The "Module", below, refers to any + such module or work, and a "work based on the Module" means either + the Module or any work containing the Module or a portion of it, + either verbatim or with modifications. Each licensee is addressed + as "you". + + 2. You may copy and distribute verbatim copies of the Module's + source code as you receive it, in any medium, provided that you: + - conspicuously and appropriately publish on each copy an appropriate + copyright notice and disclaimer of warranty; + - keep intact all the notices that refer to this General Public + License and to the absence of any warranty; and + - give any other recipients of the Module a copy of this General + Public License along with the Module. + You may charge a fee for the physical act of transferring a copy. + + 3. You may modify your copy or copies of the Module or any portion + of it, and copy and distribute such modifications under the terms + of Paragraph 1 above, provided that you also do the following: + + o cause the modified files to carry prominent notices stating + that you changed the files and the date of any change; and + + o cause the whole of any work that you distribute or publish, + that in whole or in part contains the Module or any part + thereof, either with or without modifications, to be licensed + at no charge to all third parties under the terms of this + General Public License (except that you may choose to grant + warranty protection to some or all third parties, at your + option). + + o If the modified module normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the simplest and most usual way, to print or + display an announcement including an appropriate copyright + notice and a notice that there is no warranty (or else, saying + that you provide a warranty) and that users may redistribute + the module under these conditions, and telling the user how to + view a copy of this General Public License. + + You may charge a fee for the physical act of transferring a copy, + and you may at your option offer warranty protection in exchange + for a fee. + + Mere aggregation of another independent work with the Module (or + its derivative) on a volume of a storage or distribution medium + does not bring the other work under the scope of these terms. + + 4. You may copy and distribute the Module (or a portion or + derivative of it, under Paragraph 2) in object code or executable + form under the terms of Paragraphs 1 and 2 above provided that you + also do one of the following: + + o accompany it with the complete corresponding machine- + readable source code, which must be distributed under the terms + of Paragraphs 1 and 2 above; or, + + o accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal + charge for the cost of distribution) a complete machine- + readable copy of the corresponding source code, to be + distributed under the terms of Paragraphs 1 and 2 above; or, + + o accompany it with the information you received as to where + the corresponding source code may be obtained. (This + alternative is allowed only for noncommercial distribution and + only if you received the module in object code or executable + form alone.) + + Source code for a work means the preferred form of the work for + making modifications to it. For an executable file, complete + source code means all the source code for all modules it contains; + but, as a special exception, it need not include source code for + modules which are standard libraries that accompany the operating + system on which the executable file runs, or for standard header + files or definitions files that accompany that operating system. + + 5. You may not copy, modify, sublicense, distribute or transfer + the Module except as expressly provided under this General Public + License. Any attempt otherwise to copy, modify, sublicense, + distribute or transfer the Module is void, and will automatically + terminate your rights to use the Module under this License. + However, parties who have received copies, or rights to use copies, + from you under this General Public License will not have their + licenses terminated so long as such parties remain in full + compliance. + + 6. By copying, distributing or modifying the Module (or any work + based on the Module) you indicate your acceptance of this license + to do so, and all its terms and conditions. + + 7. Each time you redistribute the Module (or any work based on the + Module), the recipient automatically receives a license from the + original licensor to copy, distribute or modify the Module subject + to these terms and conditions. You may not impose any further + restrictions on the recipients' exercise of the rights granted + herein. + + 8. The ITU-T may publish revised and/or new versions of this + General Public License from time to time. Such new versions will + be similar in spirit to the present version, but may differ in + detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the + Module specifies a version number of the license which applies to + it and "any later version", you have the option of following the + terms and conditions either of that version or of any later version + published by the ITU-T. If the Module does not specify a version + number of the license, you may choose any version ever published by + the ITU-T. + + 9. If you wish to incorporate parts of the Module into other free + modules whose distribution conditions are different, write to the + author to ask for permission. For software which is copyrighted by + the ITU-T, write to the ITU-T Secretariat; exceptions may be made + for this. This decision will be guided by the two goals of + preserving the free status of all derivatives of this free software + and of promoting the sharing and reuse of software generally. + + + NO WARRANTY + + 10. BECAUSE THE MODULE IS LICENSED FREE OF CHARGE, THERE IS NO + WARRANTY FOR THE MODULE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. + EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS + AND/OR OTHER PARTIES PROVIDE THE MODULE "AS IS" WITHOUT WARRANTY OF + ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE MODULE IS WITH YOU. SHOULD THE MODULE PROVE + DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR + OR CORRECTION. + + 11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN + WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY + MODIFY AND/OR REDISTRIBUTE THE MODULE AS PERMITTED ABOVE, BE LIABLE + TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR + CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE + THE MODULE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING + RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR + A FAILURE OF THE MODULE TO OPERATE WITH ANY OTHER MODULES), EVEN IF + SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/makefile.cl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/makefile.cl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,107 @@ +# ----------------------------------------------------------------------------- +# MS Visual C makefile for compiling & testing the UGST G.711 module +# 31.Jan.2000 - Implemented by +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose an AWK; suggest use GNU version +# (available via anonymous ftp) +# ------------------------------------------------ +AWK = gawk +AWK_CMD = '$$6~/[0-9]+:[0-9][0-9]/ {print "sb -over",$$NF};END{print "exit"}' + +# ---------------------------------------------------------------------- +# Choose compiler. +# ---------------------------------------------------------------------- +CC=cl +CC_OPT = -I../utl + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/MS Visual C/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = -pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# Choose a file comparison utility: +# ------------------------------------------------ +DIFF = cf -q + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +RM=rm -f +REF_VECTORS= sweep-r.a sweep-r.a-a sweep-r.rea sweep-r.reu \ + sweep-r.u sweep-r.u-u sweep.src +TEST_VECTORS = sweep.a sweep.a-a sweep.rea sweep.reu sweep.u sweep.u-u +G711_OBJ = g711.obj g711demo.obj + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +.c.obj: + $(CC) $(CC_OPT) -c $< + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g711demo + +anyway: clean g711demo + +clean: + $(RM) $(G711_OBJ) + +cleantest: + $(RM) $(TEST_VECTORS) $(REF_VECTORS) + +veryclean: clean cleantest + $(RM) g711demo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711demo: g711demo.exe +g711demo.exe: g711demo.obj g711.obj + $(CC) -o g711demo g711demo.obj g711.obj + +shiftbit: shiftbit.exe +shiftbit.exe: shiftbit.c ugstdemo.h + $(CC) -o shiftbit shiftbit.c + +# ------------------------------------------------ +# Test portability +# Note: there are no compliance test vectors associated with the FIR module +# ------------------------------------------------ +test: proc comp + +proc: sweep.src +# sweep-r.* have been generated from sweep.src in a reference environment +# results of the comparisons shall yield 0 different samples! + g711demo A lilo sweep.src sweep.a 256 1 256 + g711demo u lilo sweep.src sweep.u 256 1 256 + g711demo A lili sweep.src sweep.a-a 256 1 256 + g711demo u lili sweep.src sweep.u-u 256 1 256 + g711demo A loli sweep.a sweep.rea 256 1 256 + g711demo u loli sweep.u sweep.reu 256 1 256 + +comp: sweep-r.u-u + $(DIFF) sweep.a sweep-r.a + $(DIFF) sweep.a-a sweep-r.a-a + $(DIFF) sweep.rea sweep-r.rea + $(DIFF) sweep.reu sweep-r.reu + $(DIFF) sweep.u sweep-r.u + $(DIFF) sweep.u-u sweep-r.u-u + +# ------------------------------------------------ +# Extract from archive, if necessary +# ------------------------------------------------ +sweep.src: tst-g711.zip + $(UNZIP) tst-g711.zip sweep.src + swapover sweep.src + +sweep-r.u-u: tst-g711.zip + $(UNZIP) tst-g711.zip sweep-r.* + swapover sweep-r.* diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/makefile.djc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/makefile.djc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,108 @@ +# ----------------------------------------------------------------------------- +# MSDOS gcc port makefile for compiling and testing the UGST G.711 +# implementation. +# Implemented by -- 01.Feb.95 +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose a file comparison utility: +# ------------------------------------------------ +DIFF = cf -q + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# Choose an AWK; suggest use GNU version +# (available via anonymous ftp) +# ------------------------------------------------ +AWK = gawk +AWK_CMD = '$$6~/[0-9]+:[0-9][0-9]/ {print "sb -over",$$NF};END{print "exit"}' + +# ------------------------------------------------ +# Choose compiler. Sun: use cc. HP: gotta use gcc +# ------------------------------------------------ +GCC = gcc -fno-builtin +CC_OPT = -g -I../utl -Wall + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +RM = -rm +REF_VECTORS= sweep-r.a sweep-r.a-a sweep-r.rea sweep-r.reu \ + sweep-r.u sweep-r.u-u sweep.src +TEST_VECTORS = sweep.a sweep.a-a sweep.rea sweep.reu sweep.u sweep.u-u +G711_OBJ = g711.o g711demo.o +G711DEMO = go32 g711demo + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +.c.o: + $(CC) $(CC_OPT) -c $< + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all: g711demo + +anyway: clean g711demo + +clean: + $(RM) $(G711_OBJ) + +cleantest: + $(RM) $(TEST_VECTORS) + $(RM) $(REF_VECTORS) + +veryclean: clean cleantest + $(RM) g711demo g711demo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711demo: g711demo.o g711.o + $(CC) -o g711demo g711demo.o g711.o + +shiftbit: shiftbit.c + $(CC) -o shiftbit shiftbit.c + +# ------------------------------------------------ +# Test portability +# Note: there are no compliance test vectors associated with the G711 module +# ------------------------------------------------ +test: proc comp + +# sweep-r.* have been generated from sweep.src in a reference environment +# results of the comparisons shall yield 0 different samples! +proc: sweep.src + $(G711DEMO) A lilo sweep.src sweep.a 256 1 256 + $(G711DEMO) u lilo sweep.src sweep.u 256 1 256 + $(G711DEMO) A lili sweep.src sweep.a-a 256 1 256 + $(G711DEMO) u lili sweep.src sweep.u-u 256 1 256 + $(G711DEMO) A loli sweep.a sweep.rea 256 1 256 + $(G711DEMO) u loli sweep.u sweep.reu 256 1 256 + +comp: sweep-r.u-u + $(DIFF) sweep.a sweep-r.a + $(DIFF) sweep.a-a sweep-r.a-a + $(DIFF) sweep.rea sweep-r.rea + $(DIFF) sweep.reu sweep-r.reu + $(DIFF) sweep.u sweep-r.u + $(DIFF) sweep.u-u sweep-r.u-u + +# ------------------------------------------------- +# Extract AND byte-swap from archive, if necessary +# ------------------------------------------------- +sweep.src: tst-g711.zip + $(UNZIP) tst-g711.zip sweep.src + swapover sweep.src + +sweep-r.u-u: tst-g711.zip + $(UNZIP) tst-g711.zip $(REF_VECTORS) + swapover $(REF_VECTORS) diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/makefile.tcc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/makefile.tcc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,119 @@ +# ----------------------------------------------------------------------------- +# Borland [tb]cc makefile for compiling and testing the UGST G.711 +# implementation. +# Implemented by -- 01.Feb.95 +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose a file comparison utility: +# ------------------------------------------------ +DIFF = cf -q + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = -pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# Choose an AWK; suggest use GNU version +# (available via anonymous ftp) +# ------------------------------------------------ +AWK = gawk +###AWK_CMD = '$$6~/[0-9]+:[0-9][0-9]/ {print "sb -over",$$NF};END{print "exit"}' +AWK_CMD = '$6~/[0-9]+:[0-9][0-9]/{{print "sb -over",$NF;print "touch",$NF}}' + +# ------------------------------------------------ +# Choose compiler. Sun: use cc. HP: gotta use gcc +# ------------------------------------------------ +CC = tcc +CC_OPT = -I../utl + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +RM = -rm -f +REF_VECTORS= sweep-r.a sweep-r.a-a sweep-r.rea sweep-r.reu \ + sweep-r.u sweep-r.u-u sweep.src +TEST_VECTORS = sweep.a sweep.a-a sweep.rea sweep.reu sweep.u sweep.u-u +G711_OBJ = g711.obj g711demo.obj +G711DEMO = g711demo + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +.c.obj: + $(CC) $(CC_OPT) -c $< + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all: g711demo + +anyway: clean g711demo + +clean: + $(RM) $(G711_OBJ) + +cleantest: + $(RM) $(TEST_VECTORS) + $(RM) $(REF_VECTORS) + +veryclean: clean cleantest + $(RM) g711demo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711demo: g711demo.exe +g711demo.exe: g711demo.obj g711.obj + $(CC) $(CC_OPT) -eg711demo g711demo.obj g711.obj + +shiftbit: shiftbit.exe +shiftbit.exe: shiftbit.c + $(CC) $(CC_OPT) -eshiftbit shiftbit.c + +# ------------------------------------------------ +# Test portability +# Note: there are no compliance test vectors associated with the G711 module +# ------------------------------------------------ +test: proc comp + +# sweep-r.* have been generated from sweep.src in a reference environment +# results of the comparisons shall yield 0 different samples! +proc: sweep.src + $(G711DEMO) A lilo sweep.src sweep.a 256 1 256 + $(G711DEMO) u lilo sweep.src sweep.u 256 1 256 + $(G711DEMO) A lili sweep.src sweep.a-a 256 1 256 + $(G711DEMO) u lili sweep.src sweep.u-u 256 1 256 + $(G711DEMO) A loli sweep.a sweep.rea 256 1 256 + $(G711DEMO) u loli sweep.u sweep.reu 256 1 256 + +comp: sweep-r.u-u + $(DIFF) sweep.a sweep-r.a + $(DIFF) sweep.a-a sweep-r.a-a + $(DIFF) sweep.rea sweep-r.rea + $(DIFF) sweep.reu sweep-r.reu + $(DIFF) sweep.u sweep-r.u + $(DIFF) sweep.u-u sweep-r.u-u + +# --------------------------------------------------- +# Extract from archive and byte-swap -- if necessary +# --------------------------------------------------- +sweep.src: tst-g711.zip + $(UNZIP) tst-g711.zip sweep.src + swapover sweep.src +# $(UNZIP) -v tst-g711.zip sweep.src > x +# $(AWK) $(AWK_CMD) x > y.bat +# y +# $(RM) x y.bat + +sweep-r.u-u: tst-g711.zip + $(UNZIP) tst-g711.zip $(REF_VECTORS) + swapover $(REF_VECTORS) +# $(UNZIP) -v tst-g711.zip sweep-r.* > x +# $(AWK) $(AWK_CMD) x > y.bat +# y +# $(RM) x y.bat diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/makefile.unx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/makefile.unx Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,108 @@ +# ----------------------------------------------------------------------------- +# Unix makefile for compiling and testing the UGST G.711 implementation +# 01.May.94 - Implemented by +# 01.Mar.95 - Updated for test procedure +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose an AWK; suggest use GNU version +# (available via anonymous ftp) +# ------------------------------------------------ +AWK = gawk +AWK_CMD = '$$6~/[0-9]+:[0-9][0-9]/ {print "sb -over",$$NF};END{print "exit"}' + +# ---------------------------------------------------------------------- +# Choose compiler. Sun: use cc. HP: gotta use gcc make ... CC=\$\(GCC\) +# ---------------------------------------------------------------------- +GCC = gcc -fno-builtin -Wall +CC_OPT = -I../utl + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = -pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# Choose a file comparison utility: +# ------------------------------------------------ +DIFF = cf -q + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +RM=rm -f +DEMO=./g711demo +REF_VECTORS= sweep-r.a sweep-r.a-a sweep-r.rea sweep-r.reu \ + sweep-r.u sweep-r.u-u sweep.src +TEST_VECTORS = sweep.a sweep.a-a sweep.rea sweep.reu sweep.u sweep.u-u +G711_OBJ = g711.o g711demo.o + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +.c.o: + $(CC) $(CC_OPT) -c $< + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g711demo + +anyway: clean g711demo + +clean: + $(RM) $(G711_OBJ) + +cleantest: + $(RM) $(TEST_VECTORS) $(REF_VECTORS) + +veryclean: clean cleantest + $(RM) g711demo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711demo: g711demo.o g711.o + $(CC) -o g711demo g711demo.o g711.o -lm + +shiftbit: shiftbit.c ugstdemo.h + $(CC) -o shiftbit shiftbit.c + +# ------------------------------------------------ +# Test portability +# Note: there are no compliance test vectors associated with the G711 module +# ------------------------------------------------ +test: proc comp + +proc: sweep.src + # sweep-r.* have been generated from sweep.src in a reference environment + # results of the comparisons shall yield 0 different samples! + $(DEMO) A lilo sweep.src sweep.a 256 1 256 + $(DEMO) u lilo sweep.src sweep.u 256 1 256 + $(DEMO) A lili sweep.src sweep.a-a 256 1 256 + $(DEMO) u lili sweep.src sweep.u-u 256 1 256 + $(DEMO) A loli sweep.a sweep.rea 256 1 256 + $(DEMO) u loli sweep.u sweep.reu 256 1 256 + +comp: sweep-r.u-u + $(DIFF) sweep.a sweep-r.a + $(DIFF) sweep.a-a sweep-r.a-a + $(DIFF) sweep.rea sweep-r.rea + $(DIFF) sweep.reu sweep-r.reu + $(DIFF) sweep.u sweep-r.u + $(DIFF) sweep.u-u sweep-r.u-u + +# ------------------------------------------------ +# Extract from archive, if necessary +# ------------------------------------------------ +sweep.src: tst-g711.zip + $(UNZIP) tst-g711.zip sweep.src + swapover -if little sweep.src + +sweep-r.u-u: tst-g711.zip + $(UNZIP) tst-g711.zip sweep-r.* + swapover -if little sweep-r.* + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/shiftbit.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/shiftbit.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,120 @@ +/* + ======================================================================= + + SHIFTBIT.C + ~~~~~~~~~~ + + Description + ~~~~~~~~~~~ + + Shift samples from input file (in Qx format) such that the output file + will be in the Qy format, with sign extension. In fact, what this does + is multiply by the factor 2**(y-x) (if left-shift) or divide by the + factor 2**(x-y) (if right-shift) the input samples. + + Includes: + ~~~~~~~~~ + specific: ugstdemo.h + system: stdio.h,stat.h + + Author: + ~~~~~~~ + + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-1396 + CPqD/Telebras Fax: +55-192-53-4754 + 13085 Campinas SP Brazil E-mail: + + History: + ~~~~~~~~ + 08.Feb.91 v1.0 Created! + + ======================================================================= +*/ + +#include "ugstdemo.h" +#include + +/* + * Includes dependent of the Operating System + */ +#if defined(VMS) +# include +#elif defined (MSDOS) +# include +#else +# include +#endif + +#define RIGHT 1 +#define LEFT -1 + +main(argc, argv) +int argc; +char *argv[]; +{ + char inp[50], out[50]; + short *buf; + int qinp, qout, shift, dir; + FILE *Fi, *Fo; + int fi, fo; +#ifdef VMS + char mrs[15] = "mrs=512"; +#endif + struct stat info; + long l, k; + + GET_PAR_S(1, "Input file: ......... ", inp); + GET_PAR_I(2, "Input file is Q.", qinp); + GET_PAR_S(3, "Output file: ........ ", out); + GET_PAR_I(4, "Input file is Q.", qout); + + if (qout == qinp) + HARAKIRI("Makes no sense a shift of 0 ... \n", 7) + else + if (qout > qinp) + dir = RIGHT; + else + dir = LEFT; + + l = qout - qinp; + if (l < 0) + l = -l; + + for (shift = 1, k = 0; k < l; k++) + shift *= 2; + + if ((Fi = fopen(inp, RB)) == NULL) + KILL(inp, 2); + fi = fileno(Fi); + if ((Fo = fopen(out, WB)) == NULL) + KILL(inp, 3); + fo = fileno(Fo); + + stat(inp, &info); + if ((buf = (short *) malloc(info.st_size)) == NULL) + HARAKIRI("Can't alloc inp\n", 4); + l = info.st_size / 2; + + fprintf(stderr, "%s: Reading, ", inp); + for (k = 0; k < l; k += 256) + if (read(fi, &buf[k], 512) < 0) + KILL(inp, 5); + + fprintf(stderr, "shifting, "); + if (dir == RIGHT) + for (k = 0; k < l; k++) + buf[k] = (buf[k] * shift); + else + for (k = 0; k < l; k++) + buf[k] = (buf[k] / shift); + + fprintf(stderr, "and writing ... "); + for (k = 0; k < l; k += 256) + if (write(fo, &buf[k], 512) <= 0) + KILL(inp, 6); + + fprintf(stderr, "Done!\n"); + fclose(Fi); + fclose(Fo); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g711/ugstdemo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g711/ugstdemo.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,242 @@ +/* ------------------------------------------------------------------------- */ +/* File: UGSTDEMO.H version 2.2 22-Jan-1999 (18:00) */ +/* ------------------------------------------------------------------------- */ +/* Definitions for UGST demo programs */ +/* ------------------------------------------------------------------------- */ +#ifndef UGSTDEMO_defined +#define UGSTDEMO_defined 220 + +/* DEFINITION FOR OPERATING SYSTEMS */ + +#ifndef MSDOS +#if defined(__MSDOS__) || defined (__CYGWIN__) || defined (_MSC_VER) +# define MSDOS +#endif +#endif + +#if defined(VMS) +# if defined(__GNUC__) +# define COMPILER "GCC-VMS" +# else +# define COMPILER "VaxC-VMS" +# endif +#elif defined (__CYGWIN__) +# define COMPILER "GCC/CYGWIN-Win32" +#elif defined (_MSC_VER) +# define COMPILER "Microsoft Visual C-Win32" +#elif defined (__TURBOC__) +# define COMPILER "Borland Turbo-C-Win16" +#elif defined (__BORLANDC__) +# define COMPILER "Borland-C-Win16" +#elif defined(__GNUC__) && defined(MSDOS) +# define COMPILER "GCC/DJGPP-Win16" +#elif defined(__hpux) +# if defined(__GNUC__) +# define COMPILER "GCC-HPUX" +# else +# define COMPILER "Unknown compiler/HPUX" +# endif +#elif defined(sun) +# if defined(__GNUC__) +# define COMPILER "GCC-Sun" +# elif !defined (__unix__) +# define COMPILER "CC-Sun" +# else +# define COMPILER "ACC-SUN" +# endif +#elif defined(__alpha) +# define COMPILER "DecC-Alpha" +#elif defined(__GNUC__) +# define COMPILER "GCC-Unknown platform" +#else +# define COMPILER "Unknown compiler/Platform" +#endif + +/* DEFINITION FOR MEASURING CPU-TIME CONSUMPTION */ + +#include + +#ifndef CLOCKS_PER_SEC +#if defined(__TURBOC__)|defined(VMS) /* For Borland and Vax C compilers */ +#define CLOCKS_PER_SEC CLK_TCK +#elif defined(MSDOS) /* Only for Microsoft C compilers */ +#define CLOCKS_PER_SEC 1 +#else /* Unix */ +#define CLOCKS_PER_SEC 1000000 +#endif /* if */ +#endif /* ifndef */ + +/* DEFINITION FOR SMART PROTOTYPES */ +#ifndef ARGS +#if defined(MSDOS) || defined(__STDC__) || defined(VMS) || defined(__DECC) +#define ARGS(x) x +#else /* Unix: no parameters in prototype! */ +#define ARGS(x) () +#endif +#endif + + +/* + ----------------------------------------------------------------------- + DEFINITIONS FOR COMAND LINE INPUT OF PARAMETERS + ----------------------------------------------------------------------- + Asking User for Parameter Input + ------------------------------------------------------------------------ + if the desired parameter has not been entered, the user is asked + for this with a prompt string; otherwise the same prompt string is + printed to the screen, followed by the value read for the parameter + -------------------------------------------------------------------------- +*/ + +#define askc(m,v) {\ + fprintf(stderr,m); \ + scanf("%1s%*c",&v); \ + v=toupper(v);} + +#define asks(m,v) {\ + fprintf(stderr,m); \ + scanf("%s",v);} + +#define askl(m,v) {\ + fprintf(stderr,m);\ + scanf("%ld",&v);} + +#define asklu(m,v) {\ + fprintf(stderr,m);\ + scanf("%lu",&v);} + +#define askf(m,v) {\ + fprintf(stderr,m);\ + scanf("%f",&v);} + +#define asklf(m,v) {\ + fprintf(stderr,m);\ + scanf("%lf",&v);} + +#define aski(m,v) {\ + fprintf(stderr,m);\ + scanf("%d",&v);} + +#define GET_PAR_L(p,msg,i ) \ + { if(argc>p) { \ + i=atol(argv[p]); \ + fprintf(stderr,"%s%ld\n",msg,i);}\ + else askl(msg,i);} + +#define GET_PAR_LU(p,msg,i ) \ + { if(argc>p) { \ + sscanf(argv[p],"%ul",&(i)); \ + fprintf(stderr,"%s%lu\n",msg,i);}\ + else asklu(msg,i);} + +#define GET_PAR_I(p,msg,i ) \ + { if(argc>p) { \ + i=atoi(argv[p]); \ + fprintf(stderr,"%s%d\n",msg,i);}\ + else aski(msg,i);} + +#define GET_PAR_D(p,msg,r ) \ + { if(argc>p) {\ + r=(double)atof(argv[p]);\ + fprintf(stderr,"%s%f\n",msg,r);}\ + else asklf(msg,r);} + +#define GET_PAR_F(p,msg,r ) \ + { if(argc>p) {\ + r=atof(argv[p]);\ + fprintf(stderr,"%s%f\n",msg,r);}\ + else askf(msg,r);} + +#define GET_PAR_S(p,msg,sp) \ + { if(argc>p) {\ + strcpy(sp,argv[p]); \ + fprintf(stderr,"%s%s\n",msg,sp);}\ + else asks(msg,sp);} + +#define GET_PAR_C(p,msg,C) \ + { if(argc>p) {\ + C=toupper(argv[p][0]);\ + fprintf(stderr,"%s%c\n",msg,C);}\ + else askc(msg,C);} + +/* + -------------------------------------------------------------------------- + If the desired parameter has not been entered, a default value is + taken; otherwise the entered value is used + -------------------------------------------------------------------------- +*/ +#define FIND_PAR_C(p,msg,C,dft) \ + { C=toupper((argc>p)?argv[p][0]:dft);\ + fprintf(stderr,"%s%c\n",msg,C);} + +#define FIND_PAR_S(p,msg,i,dft) \ + { strcpy(i,(argc>p)?argv[p]:dft);\ + fprintf(stderr,"%s%s\n",msg,i); } + +#define FIND_PAR_L(p,msg,i,j) \ + if(argc>p) {\ + i=atol(argv[p]);\ + fprintf(stderr,"%s%ld\n",msg,i); }\ + else {\ + i=j; \ + fprintf(stderr,"%s%ld\n",msg,i); } + +#define FIND_PAR_I(p,msg,i,j) \ + if(argc>p) {\ + i=atoi(argv[p]);\ + fprintf(stderr,"%s%d\n",msg,i); }\ + else {\ + i=(int)j; \ + fprintf(stderr,"%s%d\n",msg,i); } + +#define FIND_PAR_F(p,msg,i,j) \ + if(argc>p) {\ + i=atof(argv[p]);\ + fprintf(stderr,"%s%f\n",msg,i); }\ + else {\ + i=j; \ + fprintf(stderr,"%s%f\n",msg,i); } + +#define FIND_PAR_D(p,msg,i,j) \ + if(argc>p) {\ + i=(double)atof(argv[p]);\ + fprintf(stderr,"%s%f\n",msg,i); }\ + else {\ + i=j; \ + fprintf(stderr,"%s%f\n",msg,i); } + +/* GENERAL DEFINITIONS */ + +/* -------------------------------------------- */ +/* ... Print error message and exit program ... */ +/* -------------------------------------------- */ +#define HARAKIRI(m,code) {fprintf(stderr,m); exit((int)code);} +/* #define KILL(f,code) {perror(f); exit((int)code);} */ +#define KILL(f,code) perror(f), exit((int)code) + + +/* DEFINITIONS FOR OPEN/CLOSE ISSUES */ + +#if defined(VMS) && !defined(__GNUC__) +# define WB "wb",mrs,"rfm=fix","ctx=stm" +# define RB "rb",mrs,"rfm=fix","ctx=stm" +# define WT "w","mrs=256","rat=cr","rfm=var" +# define RT "r","mrs=256","rat=cr","rfm=var" +# define RWT "r+","mrs=256","rat=cr","rfm=var" +#elif defined(MSDOS)|defined(__CYGWIN__) +# define WB "wb" +# define RB "rb" +# define WT "wt" +# define RT "rt" +# define RWT "rt+" +#else /* Unix */ +# define WB "w" +# define RB "r" +# define WT "w" +# define RT "r" +# define RWT "r+" +#endif + +#endif + +/* ................... End of include file UGSTDEMO.H ................... */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/Makefile Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,40 @@ +# +# makefile for iLBC Codec +# + +# For GCC compiler +CC = gcc +LFLAG = +CFLAGS = -Wall -O3 -I../g711 + +# Objects +OBJ = vbr-g726.o g711.o + +OBJS = g726.o g726_rfc3551.o + +# Implicit Rules +.c.o: + $(CC) $(CFLAGS) -c $< + +# Explicit Rules +all: g726.a vbr-g726 + +g711.o: ../g711/g711.c + $(CC) -c $(CFLAGS) ../g711/g711.c + +g726.a: $(OBJS) + ar rcs $@ $(OBJS) + +vbr-g726: $(OBJ) + $(CC) $(LFLAG) -o vbr-g726 $(CFLAGS) $(OBJ) g726.a -lm + +clean: + rm -f *.o *.a vbr-g726 voicvbrl.tst + +distclean: clean + rm -f Makefile + +dep: + makedepend -- $(CFLAGS) *.c + + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/README Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,9 @@ +voice.src 16bit PCM, Big Endian +voicevbr.arf A-Law 1 sample 16Bit? + + +time ./vbr-g726 -law l -rate 32 ../tv2/voice.raw voice32.raw + +time ./vbr-g726 -law l -rate 32 -enc ../tv2/voice.raw voice32.adp + +time ./vbr-g726 -law l -rate 32 -dec voice32.adp voice32.raw diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/cvt_h_b.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/cvt_h_b.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,350 @@ +/* +============================================================================== + + CVT_H_B.C + ~~~~~~~~~ + + Program to convert ITU-T test sequences in hexa formats to + word oriented binary files. Each line is supposed to have 32 valid + samples (16 bit, or a word), or 64 hexa characters, either upper or + lower case. In the last line is expected one word (2 hexa chars) + in hexadecimal representation as the checksum of all the samples of + the file modulus 255 (sum mod 255). + + + USAGE: + ~~~~~~ + $ cvt_h_b [-r] [-q] hex-in bin-out + where: + hex-in is the (input) hexadecimal file's name + bin-out is the (output) binary file's name + + Options + ~~~~~~~ + -q Don't print progress indicator on the screen. + -r is an optional parameter; if specified as r or R, + even-bit reversal of all samples is accomplished + before saving the file. Default is NOT invert. + + Compile: + ~~~~~~~~ + SunC: cc -o cvt_h_b cvt_h_b.c # or # + acc -o cvt_h_b cvt_h_b.c + GNUC: gcc -o cvt_h_b cvt_h_b.c + VMS: cc cvt_h_b.c + link cvt_h_b + + History: + ~~~~~~~~ + 92.01.22 1.0 1st release by tdsimao@venus.cpqd.ansp.br + 93.11.23 1.01 ported to SunOS (Unix) + + ============================================================= + 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". + ============================================================= +============================================================================== +*/ + +/* OS definition */ +#ifdef __MSDOS__ /* definition for automatic compil. under TurboC v2.0 */ +# define MSDOS /* this is already defined for Microsoft C 5.1 */ +#endif + + +/* includes in general */ +#include +#include +#include + + +/* Specific includes */ +#if defined(MSDOS) /* for MSDOS */ +# include +# include +# include +#elif defined(VMS) /* for VMS */ +# include +# include +# include +#else /* for OTHER OS, in special UNIX */ +# include +#endif + + +/* Generic defines */ +#define askc(m,v) {printf(m); scanf("%c%*c",&v);} +#define aski(m,v) {printf(m);scanf("%d",&v);} +#define asks(m,v) {printf(m);gets(v);} +#define KILL(str,code) {perror(str); exit(code);} +#define GET_PAR_I(a,s,p,msg,i) {if(a>p) i=atoi(s[p]); else aski(msg,i);} +#define GET_PAR_C(a,s,p,msg,c) {if(a>p) c=toupper(s[p][0]);else askc(msg,c);} +#define GET_PAR_S(a,s,p,msg,S) {if(a>p) strcpy(S,s[p]); else asks(msg,S);} + +#if defined(VMS) +#define WB "wb","mrs=512","rfm=fix","ctx=stm" +#define RB "rb","mrs=512","rfm=fix","ctx=stm" +#elif defined(MSDOS) +#define WB "wb" +#define RB "rb" +#else +#define WB "w" +#define RB "r" +#endif + +#define YES 1 +#define NO 0 + +/* + * -------------------------------------------------------------------------- + * ... Calculate check-sum of a array of shorts ... + * Simao 07.Mar.94 + * -------------------------------------------------------------------------- + */ +short short_check_sum(s_data, n) +short *s_data; +long n; +{ + float csum = 0; + long i; + + /* Add samples */ + while (n) + csum += s_data[--n]; + + /* return mod as a short */ + csum = fmod(csum, 255.0); + return ((short) csum); +} + + +/* + * -------------------------------------------------------------------------- + * ... Display usage of program ... + * Simao 10.Jan.93 + * -------------------------------------------------------------------------- + */ +#define FP(x) printf(x) +void display_usage() +{ + FP("Version 1.01 of 23/Nov/1993 \n"); + + FP(" CVT_H_B.C:\n"); + FP(" Program to convert ITU-T test sequences in hexa formats to\n"); + FP(" word oriented binary files. Each line is supposed to have 32 valid\n"); + FP(" samples (16 bit, or a word), or 64 hexa characters, either upper or\n"); + FP(" lower case. In the last line is expected one word (2 hexa chars)\n"); + FP(" in hexadecimal representation as the checksum of all the samples of\n"); + FP(" the file modulus 255 (sum mod 255).\n"); + FP("\n"); + FP(" Usage:\n"); + FP(" $ cvt_h_b [-r] hex-in bin-out\n"); + FP(" where:\n"); + FP(" hex-in is the (input) hexadecimal file's name\n"); + FP(" bin-out is the (output) binary file's name\n\n"); + + FP(" Options\n"); + FP(" -q Don't print progress indicator on the screen\n"); + FP(" -r is an optional parameter; if specified as r or R,\n"); + FP(" even-bit reversal of all samples is accomplished \n"); + FP(" before saving the file. Default is NOT invert.\n"); + FP("\n"); + + /* Quit program */ + exit(-128); +} + +#undef FP +/* ....................... end of display_usage() ...........................*/ + + +/*============================== */ +main(argc, argv) +int argc; +char *argv[]; +/*============================== */ +{ + char line[200], *lp; + char inpfil[50], outfil[50]; + int inp, out, itmp, count = 0; + float check_sum = 0; + short scheck_sum = 0; + short chk; + short *bin, *tmp; + long leng, i, smpno = 0, lineno = 0; + int lastline_len = 0; + + FILE *Fi, *Fo; + struct stat st; + int invert_even_bits = NO, quiet = NO; + + static char funny[8] = { '\\', '-', '/', '|', '\\', '-', '/', '|' }; + + + /* GETTING OPTIONS */ + + if (argc < 2) + display_usage(); + else { + while (argc > 1 && argv[1][0] == '-') + if (strcmp(argv[1], "-r") == 0) { + /* Reverse even bits */ + invert_even_bits = YES; + + /* Move argv over the option to the next argument */ + argv++; + + /* Update argc */ + argc--; + } else if (strcmp(argv[1], "-q") == 0) { + /* Don't print funny chars */ + quiet = YES; + + /* Move argv over the option to the next argument */ + argv++; + argc--; + } else { + fprintf(stderr, + "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); + display_usage(); + } + } + + + + /* WELCOME! */ + + fprintf(stderr, "\n\t\tConversion from ITU-T HEX of test sequence"); + fprintf(stderr, "\n\t\tfiles to binary files, 16 bits per sample\n"); + + + /* GETTING PARAMETERS */ + + GET_PAR_S(argc, argv, 1, "_Input (ITU-T HEX) file: ....... ", inpfil); + GET_PAR_S(argc, argv, 2, "_Output (`short') file: ........ ", outfil); + + + /* OPEN FILES */ + + if ((Fi = fopen(inpfil, "r")) == NULL) + KILL(inpfil, 2); + if ((Fo = fopen(outfil, WB)) == NULL) + KILL(outfil, 3); + out = fileno(Fo); + + /* FIND FILE SIZE AND ALLOC MEMORY FOR BINARY BUFFER */ + + stat(inpfil, &st); + if ((bin = (short *) malloc(st.st_size)) == (short *) NULL) { + fprintf(stderr, "\n Can't allocate memory for output buffer"); + exit(4); + } + tmp = bin; + + + /* INFOS */ + + fprintf(stderr, "\n Converting %s to %s\r", inpfil, outfil); + + + /* CONVERSION PART */ + + /* FIND NUMBER OF LINES IN FILE */ + while (fgets(line, (int) 200, Fi) != NULL) + lineno++; + rewind(Fi); + lastline_len = strlen(line); + if (line[lastline_len - 1] = '\n') + lastline_len--; + + /* READ ALL CHARS FOR THE FILE */ + while (fgets(line, (int) 200, Fi) != NULL) { + /* Print `working' flag */ + if (!quiet) + fprintf(stderr, "%c\r", funny[count % 8]); + + /* Update line counter */ + count++; + + /* Remove CR from line end */ + leng = strlen(line); + if (line[leng - 1] == '\n') + line[--leng] = '\0'; + + /* Convert line */ + switch (leng) { + case 64: + for (lp = line, i = 0; i < leng; i += 2, lp += 2) { + sscanf(lp, "%2hx", tmp); + tmp++; + smpno++; + } + break; + + case 2: + /* Check whether the last line */ + if (count != lineno) { + /* If not, it's a regular sample */ + sscanf(lp, "%2hx", tmp); + tmp++; + smpno++; + } else { + /* value is check-sum */ + sscanf(line, "%2hx", &chk); + } + break; + + default: /* for old (red-book) test sequences: initialization */ + for (i = 0; i < leng - 2; i += 2) { + sscanf(&line[i], "%2hx", tmp); + tmp++; + smpno++; + } + + /* Check sum for old files ... */ + sscanf(&line[i], "%2hx", &chk); + break; + + } + } + + /* CALCULATE CHECK-SUMS */ + scheck_sum = short_check_sum(bin, smpno); + fprintf(stderr, "Check-sum is: %d (calculated) %d (read)\n", + scheck_sum, chk); + if (chk != scheck_sum) { + fprintf(stderr, "\n Checksum Failed! (%d != %d)\n", chk, + scheck_sum); + exit(5); + } + + + /* INVERT EVEN BITS, IF IT IS THE CASE */ + + if (invert_even_bits) { + fprintf(stderr, "\r Inverting even bits, as requested\t\t"); + for (i = 0; i < (tmp - bin) / 2; i++) + bin[i] ^= 0x55; + } + + + /* SAVE TO FILE */ + + for (i = 0; i < smpno; i += 256) { + if (write(out, &bin[i], 512) != 512) + KILL(outfil, 6); + } + + + /* EXITING */ + + fprintf(stderr, "\rDone: %d samples converted!\n", smpno); + fclose(Fi); + fclose(Fo); +#ifndef VMS + exit(0); +#endif +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,3387 @@ +/* v2.0 24.Jan.2000 +============================================================================= + + U U GGG SSSS TTTTT + U U G S T + U U G GG SSSS T + U U G G S T + UUU GG SSS T + + ======================================== + ITU-T - USER'S GROUP ON SOFTWARE TOOLS + ======================================== + + + ============================================================= + 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". + ============================================================= + + +MODULE: G726.C ADPCM AT 40, 32, 24, AND 16 KBIT/S MODULE + +ORIGINAL BY: + Jose' Sindi Yamamoto (Fortran version of the G.721) + + Simao Ferraz de Campos Neto (C translation, adaptation&testing of the G.721) + + Fernando Tofolli Queiroz (Extension of the G.721 to the other rates=>G.726) + + Simao Ferraz de Campos Neto (Adaptation and testing of the G.726) + + +HISTORY: +28.Feb.1994 v1.0c Version 1.0 in C, by translating Fortran to C (f2c) +24.Jan.2000 v2.0 Corrected bug G726_compress() that caused incorrect + processing of test vector ri40fa. Corrected code + provided by Jayesh Patel . + Verified by + +FUNCTIONS: +Public: + G726_encode ..... G726 encoder function; + + G726_decode ..... G726 decoder function; + +Private: + G726_accum ...... addition of predictor outputs to form the partial + signal estimate (from the sixth order predictor) and + the signal estimate. + + G726_adda ....... addition of scale factor to logarithmic version of + quantized difference signal. + + G726_addb ....... addition of quantized difference signal and signal + estimate to form reconstructed signal. + + G726_addc....... obtain sign of addition of quantized difference signal + and partial signal estimate. + + G726_antilog .... convert quantized difference signal from the + logarithmic to the linear domain. + + G726_compress ... convert from uniform pcm to either a-law or u-law pcm. + + G726_delaya ..... memory block. + + G726_delayb ..... memory block. + + G726_delayc ..... memory block. + + G726_delayd ..... memory block. + + G726_expand ..... convert either a-law (law=1) or u-law (law=0) to + uniform pcm. + + G726_filta ...... update of short term average of f(i). + + G726_filtb ...... update of long term average of f(i). + + G726_filtc ...... low pass filter of speed control parameter. + + G726_filtd ...... update of fast quantizer scale factor. + + G726_filte ...... update of slow quantizer scale factor. + + G726_floata ..... convert 15-bit signed magnitude to floating point. + + G726_floatb ..... convert 16-bit two's complement to floating point. + + G726_fmult ...... multiply predictor coefficients with corresponding + quantized difference signal or reconstructed signal. + Multiplication is done in floating point format. + + G726_functf ..... map quantizer output into the f(i) function. + + G726_functw ..... map quantizer output into logarithmic version of scale + factor multiplier. + + G726_lima ....... limit speed control parameter. + + G726_limb ....... limit quantizer scale factor. + + G726_limc ....... limits on a2 coefficient of second order predictor. + + G726_limd ....... limits on a1 coefficient of second order predictor. + + G726_log ........ convert difference signal from linear to the + logarithmic domain. + + G726_mix ........ form linear combination of fast and slow quantizer + scale factors. + + G726_quan ....... quantize difference signal in logarithmic domain. + + G726_reconst .... reconstruction of quantized difference signal in the + logarithmic domain. + + G726_subta ...... compute difference signal by subtracting signal + estimate from input signal (or quantized reconstructed + signal in decoder). + + G726_subtb ...... scale logarithmic version of difference signal by + subtracting scale factor. + + G726_subtc ...... compute magnitude of the difference of short and + long-term function of quantizer output sequence and + then perform threshold comparison for quantizing speed + control parameter. + + G726_sync ....... re-encode output pcm sample in decoder for synchronous + tandem coding. + + G726_tone ....... partial band signal detection. + + G726_trans ...... transition detector. + + G726_triga ...... speed control trigger block. + + G726_trigb ...... predictor trigger block. + + G726_upa1 ....... update a1 coefficient of second order predictor. + + G726_upa2 ....... update a2 coefficient of second order predictor. + + G726_upb ........ update for coefficients of sixth order predictor. + + G726_xor ........ one bit "exclusive or" of sign of difference signal + and sign of delayed difference signal. + +============================================================================= +*/ + +/* + * .................. INCLUDES .................. + */ +#include "g726.h" + + +/* + * .................. FUNCTIONS .................. + */ + +/* + ---------------------------------------------------------------------------- + + void G726_encode (short *inp_buf, short *out_buf, long smpno, + ~~~~~~~~~~~~~~~~ char *law, short rate, short r, G726_state *state); + + Description: + ~~~~~~~~~~~~ + + Simulation of the ITU-T G.726 ADPCM encoder. Takes the A or mu + law input array of shorts `inp_buf' (16 bit, right- justified, + without sign extension) of length `smpno', and saves the + encoded samples in the array of shorts `out_buf', with the + same number of samples and right-justified. + + The state variables are saved in the structure `state', and the + reset can be stablished by making r equal to 1. The law is A if + `law'=='1', and mu law if `law'=='0'. + + + Return value: + ~~~~~~~~~~~~~ + None. + + Prototype: in file g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Version 1.0 in Fortran + + 05.Feb.92 v1.0c Version 1.0 in C, by translating Fortran to C (f2c) + + + ---------------------------------------------------------------------------- +*/ +void G726_encode(inp_buf, out_buf, smpno, law, rate, r, state) +unsigned char *inp_buf; +short *out_buf; +long smpno; +char *law; +short r; +short rate; +G726_state *state; +{ + short s; + short d, i; + short y; + short sigpk; + short sr, tr; + short yu; + short al, fi, dl, ap, dq, ds, se, ax, td, sl, wi; + short u1, u2, u3, u4, u5, u6; + short a1, a2, b1, b2, b3, b4, b5, b6; + short dqln; + short a1p, a2p, a1t, a2t, b1p, b2p, b3p, b4p, b5p, b6p, dq6, pk2, + sr2, wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6; + short dml, dln, app, dql, dms; + short dqs, tdp; + short sez; + short yut; + long yl; + + long j; + + /* Invert even bits if A law */ + if (*law == '1') { + for (j = 0; j < smpno; j++) + inp_buf[j] ^= 85; + } + + /* Process all desired samples in inp_buf to out_buf; The comments about + * general blocks are given as in G.726, and refer to: 4.1.1 Input PCM + * format conversion and difference signal computation 4.1.2 Adaptive + * quantizer 4.1.3 Inverse adaptive quantizer 4.1.4 Quantizer scale factor + * adaptation 4.1.5 Adaptation speed control 4.1.6 Adaptive predictor and + * reconstructed signal calculator 4.1.7 Tone and transition detector 4.1.8 + * (Only in the decoder) */ + for (j = 0; j < smpno; j++, r = 0) { + s = inp_buf[j]; + + /* Process `known-state' part of 4.2.6 */ + G726_delayd(&r, &state->sr1, &sr2); + G726_delayd(&r, &state->sr0, &state->sr1); + G726_delaya(&r, &state->a2r, &a2); + G726_delaya(&r, &state->a1r, &a1); + G726_fmult(&a2, &sr2, &wa2); + G726_fmult(&a1, &state->sr1, &wa1); + + G726_delayd(&r, &state->dq5, &dq6); + G726_delayd(&r, &state->dq4, &state->dq5); + G726_delayd(&r, &state->dq3, &state->dq4); + G726_delayd(&r, &state->dq2, &state->dq3); + G726_delayd(&r, &state->dq1, &state->dq2); + G726_delayd(&r, &state->dq0, &state->dq1); + + G726_delaya(&r, &state->b1r, &b1); + G726_delaya(&r, &state->b2r, &b2); + G726_delaya(&r, &state->b3r, &b3); + G726_delaya(&r, &state->b4r, &b4); + G726_delaya(&r, &state->b5r, &b5); + G726_delaya(&r, &state->b6r, &b6); + + G726_fmult(&b1, &state->dq1, &wb1); + G726_fmult(&b2, &state->dq2, &wb2); + G726_fmult(&b3, &state->dq3, &wb3); + G726_fmult(&b4, &state->dq4, &wb4); + G726_fmult(&b5, &state->dq5, &wb5); + G726_fmult(&b6, &dq6, &wb6); + + G726_accum(&wa1, &wa2, &wb1, &wb2, &wb3, &wb4, &wb5, &wb6, &se, + &sez); + + /* Process 4.2.1 */ + G726_expand(&s, law, &sl); + G726_subta(&sl, &se, &d); + + /* Process delays and `know-state' part of 4.2.5 */ + G726_delaya(&r, &state->dmsp, &dms); + G726_delaya(&r, &state->dmlp, &dml); + G726_delaya(&r, &state->apr, &ap); + G726_lima(&ap, &al); + + /* Process `know-state' parts of 4.2.4 */ + G726_delayb(&r, &state->yup, &yu); + G726_delayc(&r, &state->ylp, &yl); + G726_mix(&al, &yu, &yl, &y); + + /* Process 4.2.2 */ + G726_log(&d, &dl, &ds); + G726_subtb(&dl, &y, &dln); + G726_quan(rate, &dln, &ds, &i); + + /* Save ADPCM quantized sample into output buffer */ + out_buf[j] = i; + + /* Process 4.2.3 */ + G726_reconst(rate, &i, &dqln, &dqs); + G726_adda(&dqln, &y, &dql); + G726_antilog(&dql, &dqs, &dq); + + /* Part of 4.2.5 */ + G726_functf(rate, &i, &fi); + G726_filta(&fi, &dms, &state->dmsp); + G726_filtb(&fi, &dml, &state->dmlp); + + /* Remaining part of 4.2.4 */ + G726_functw(rate, &i, &wi); + G726_filtd(&wi, &y, &yut); + G726_limb(&yut, &state->yup); + G726_filte(&state->yup, &yl, &state->ylp); + + /* Process `known-state' part of 4.2.7 */ + G726_delaya(&r, &state->tdr, &td); + G726_trans(&td, &yl, &dq, &tr); + + /* More `known-state' parts of 4.2.6: update of `pk's */ + G726_delaya(&r, &state->pk1, &pk2); + G726_delaya(&r, &state->pk0, &state->pk1); + G726_addc(&dq, &sez, &state->pk0, &sigpk); + + /* 4.2.6: find sr0 */ + G726_addb(&dq, &se, &sr); + G726_floatb(&sr, &state->sr0); + + /* 4.2.6: find dq0 */ + G726_floata(&dq, &state->dq0); + + /* 4.2.6: prepar a2(r) */ + G726_upa2(&state->pk0, &state->pk1, &pk2, &a2, &a1, &sigpk, &a2t); + G726_limc(&a2t, &a2p); + G726_trigb(&tr, &a2p, &state->a2r); + + /* 4.2.6: prepar a1(r) */ + G726_upa1(&state->pk0, &state->pk1, &a1, &sigpk, &a1t); + G726_limd(&a1t, &a2p, &a1p); + G726_trigb(&tr, &a1p, &state->a1r); + + /* Remaining of 4.2.7 */ + G726_tone(&a2p, &tdp); + G726_trigb(&tr, &tdp, &state->tdr); + + /* Remaining of 4.2.5 */ + G726_subtc(&state->dmsp, &state->dmlp, &tdp, &y, &ax); + G726_filtc(&ax, &ap, &app); + G726_triga(&tr, &app, &state->apr); + + /* Remaining of 4.2.6: update of all `b's */ + G726_xor(&state->dq1, &dq, &u1); /* Here, b1 */ + G726_upb(rate, &u1, &b1, &dq, &b1p); + G726_trigb(&tr, &b1p, &state->b1r); + + G726_xor(&state->dq2, &dq, &u2); /* Here, b2 */ + G726_upb(rate, &u2, &b2, &dq, &b2p); + G726_trigb(&tr, &b2p, &state->b2r); + + G726_xor(&state->dq3, &dq, &u3); /* Here, b3 */ + G726_upb(rate, &u3, &b3, &dq, &b3p); + G726_trigb(&tr, &b3p, &state->b3r); + + G726_xor(&state->dq4, &dq, &u4); /* Here, b4 */ + G726_upb(rate, &u4, &b4, &dq, &b4p); + G726_trigb(&tr, &b4p, &state->b4r); + + G726_xor(&state->dq5, &dq, &u5); /* Here, b5 */ + G726_upb(rate, &u5, &b5, &dq, &b5p); + G726_trigb(&tr, &b5p, &state->b5r); + + G726_xor(&dq6, &dq, &u6); /* At last, b6 */ + G726_upb(rate, &u6, &b6, &dq, &b6p); + G726_trigb(&tr, &b6p, &state->b6r); + } +} + +/* ........................ end of G726_encode() ....................... */ + + +/* + ---------------------------------------------------------------------------- + + void G726_decode (short *inp_buf, short *out_buf, long smpno, + ~~~~~~~~~~~~~~~~ char *law, short rate, short r, G726_state *state); + + Description: + ~~~~~~~~~~~~ + + Simulation of the ITU-T G.726 ADPCM decoder. Takes the ADPCM + input array of shorts `inp_buf' (16 bit, right- justified, + without sign extension) of length `smpno', and saves the + decoded samples (A or mu law) in the array of shorts + `out_buf', with the same number of samples and + right-justified. + + The state variables are saved in the structure `state', and the + reset can be stablished by making r equal to 1. The law is A if + `law'=='1', and mu law if `law'=='0'. + + + Return value: + ~~~~~~~~~~~~~ + None. + + Prototype: in file g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Version 1.0 in Fortran + + 05.Feb.92 v1.0c Version 1.0 in C, by translating Fortran to C (f2c) + + + ---------------------------------------------------------------------------- +*/ +void G726_decode(inp_buf, out_buf, smpno, law, rate, r, state) +short *inp_buf; +unsigned char *out_buf; +long smpno; +char *law; +short r; +short rate; +G726_state *state; +{ + short i; + short y; + short sigpk; + short sr, tr; + short sp, dlnx, dsx, sd, slx, dlx, dx; /* these are unique to + * the decoder */ + long yl; + short yu; + short al, fi, ap, dq, se, ax, td, wi; + short u1, u2, u3, u4, u5, u6; + short a1, a2, b1, b2, b3, b4, b5, b6; + short dqln; + short a1p, a2p, a1t, a2t, b1p, b2p, b3p, b4p, b5p, b6p, dq6, pk2, + sr2, wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6; + short dml, app, dql, dms; + short dqs, tdp; + short sez; + short yut; + long j; + + /* Process all desired samples in inp_buf to out_buf; The comments about + * general blocks are given as in G.726, and refer to: 4.1.1 Input PCM + * format conversion and difference signal computation 4.1.2 Adaptive + * quantizer 4.1.3 Inverse adaptive quantizer 4.1.4 Quantizer scale factor + * adaptation 4.1.5 Adaptation speed control 4.1.6 Adaptive predictor and + * reconstructed signal calculator 4.1.7 Tone and transition detector 4.1.8 + * Output PCM format conversion and synchronous coding adjustment */ + for (j = 0; j < smpno; j++, r = 0) { + /* Process `known-state' part of 4.2.6 */ + G726_delayd(&r, &state->sr1, &sr2); + G726_delayd(&r, &state->sr0, &state->sr1); + G726_delaya(&r, &state->a2r, &a2); + G726_delaya(&r, &state->a1r, &a1); + G726_fmult(&a2, &sr2, &wa2); + G726_fmult(&a1, &state->sr1, &wa1); + + G726_delayd(&r, &state->dq5, &dq6); + G726_delayd(&r, &state->dq4, &state->dq5); + G726_delayd(&r, &state->dq3, &state->dq4); + G726_delayd(&r, &state->dq2, &state->dq3); + G726_delayd(&r, &state->dq1, &state->dq2); + G726_delayd(&r, &state->dq0, &state->dq1); + + G726_delaya(&r, &state->b1r, &b1); + G726_delaya(&r, &state->b2r, &b2); + G726_delaya(&r, &state->b3r, &b3); + G726_delaya(&r, &state->b4r, &b4); + G726_delaya(&r, &state->b5r, &b5); + G726_delaya(&r, &state->b6r, &b6); + + G726_fmult(&b1, &state->dq1, &wb1); + G726_fmult(&b2, &state->dq2, &wb2); + G726_fmult(&b3, &state->dq3, &wb3); + G726_fmult(&b4, &state->dq4, &wb4); + G726_fmult(&b5, &state->dq5, &wb5); + G726_fmult(&b6, &dq6, &wb6); + + G726_accum(&wa1, &wa2, &wb1, &wb2, &wb3, &wb4, &wb5, &wb6, &se, + &sez); + + /* Process delays and `know-state' part of 4.2.5 */ + G726_delaya(&r, &state->dmsp, &dms); + G726_delaya(&r, &state->dmlp, &dml); + G726_delaya(&r, &state->apr, &ap); + G726_lima(&ap, &al); + + /* Process `know-state' parts of 4.2.4 */ + G726_delayb(&r, &state->yup, &yu); + G726_delayc(&r, &state->ylp, &yl); + G726_mix(&al, &yu, &yl, &y); + + /* Retrieve ADPCM sample from input buffer */ + i = inp_buf[j]; + + /* Process 4.2.3 */ + G726_reconst(rate, &i, &dqln, &dqs); + G726_adda(&dqln, &y, &dql); + G726_antilog(&dql, &dqs, &dq); + + /* Process `known-state' part of 4.2.7 */ + G726_delaya(&r, &state->tdr, &td); + G726_trans(&td, &yl, &dq, &tr); + + /* Part of 4.2.5 */ + G726_functf(rate, &i, &fi); + G726_filta(&fi, &dms, &state->dmsp); + G726_filtb(&fi, &dml, &state->dmlp); + + /* Remaining part of 4.2.4 */ + G726_functw(rate, &i, &wi); + G726_filtd(&wi, &y, &yut); + G726_limb(&yut, &state->yup); + G726_filte(&state->yup, &yl, &state->ylp); + + /* More `known-state' parts of 4.2.6: update of `pk's */ + G726_delaya(&r, &state->pk1, &pk2); + G726_delaya(&r, &state->pk0, &state->pk1); + G726_addc(&dq, &sez, &state->pk0, &sigpk); + + /* 4.2.6: find sr0 */ + G726_addb(&dq, &se, &sr); + G726_floatb(&sr, &state->sr0); + + /* 4.2.6: find dq0 */ + G726_floata(&dq, &state->dq0); + + /* Process 4.2.8 */ + G726_compress(&sr, law, &sp); + G726_expand(&sp, law, &slx); + G726_subta(&slx, &se, &dx); + G726_log(&dx, &dlx, &dsx); + G726_subtb(&dlx, &y, &dlnx); + G726_sync(rate, &i, &sp, &dlnx, &dsx, law, &sd); + + /* Save output PCM word in output buffer */ + out_buf[j] = sd; + + /* 4.2.6: prepar a2(r) */ + G726_upa2(&state->pk0, &state->pk1, &pk2, &a2, &a1, &sigpk, &a2t); + G726_limc(&a2t, &a2p); + G726_trigb(&tr, &a2p, &state->a2r); + + /* 4.2.6: prepar a1(r) */ + G726_upa1(&state->pk0, &state->pk1, &a1, &sigpk, &a1t); + G726_limd(&a1t, &a2p, &a1p); + G726_trigb(&tr, &a1p, &state->a1r); + + /* Remaining of 4.2.7 */ + G726_tone(&a2p, &tdp); + G726_trigb(&tr, &tdp, &state->tdr); + + /* Remaining of 4.2.5 */ + G726_subtc(&state->dmsp, &state->dmlp, &tdp, &y, &ax); + G726_filtc(&ax, &ap, &app); + G726_triga(&tr, &app, &state->apr); + + /* Remaining of 4.2.6: update of all `b's */ + G726_xor(&state->dq1, &dq, &u1); /* Here, b1 */ + G726_upb(rate, &u1, &b1, &dq, &b1p); + G726_trigb(&tr, &b1p, &state->b1r); + + G726_xor(&state->dq2, &dq, &u2); /* Here, b2 */ + G726_upb(rate, &u2, &b2, &dq, &b2p); + G726_trigb(&tr, &b2p, &state->b2r); + + G726_xor(&state->dq3, &dq, &u3); /* Here, b3 */ + G726_upb(rate, &u3, &b3, &dq, &b3p); + G726_trigb(&tr, &b3p, &state->b3r); + + G726_xor(&state->dq4, &dq, &u4); /* Here, b4 */ + G726_upb(rate, &u4, &b4, &dq, &b4p); + G726_trigb(&tr, &b4p, &state->b4r); + + G726_xor(&state->dq5, &dq, &u5); /* Here, b5 */ + G726_upb(rate, &u5, &b5, &dq, &b5p); + G726_trigb(&tr, &b5p, &state->b5r); + + G726_xor(&dq6, &dq, &u6); /* At last, b6 */ + G726_upb(rate, &u6, &b6, &dq, &b6p); + G726_trigb(&tr, &b6p, &state->b6r); + } + + /* Invert even bits if A law */ + if (*law == '1') { + for (j = 0; j < smpno; j++) + out_buf[j] ^= 85; + } + +} + +/* ...................... end of G726_decode() ...................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_expand (short *s, char *law, short *sl); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert either a-law (law=1) or u-law (law=0) to uniform pcm. + + Inputs: s (sp in decoder), law + Output: sl (slx in decoder) + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_expand(s, law, sl) +short *s; +char *law; +short *sl; +{ + long mant, iexp; + short s1, ss, sig, ssm, ssq, sss; + + s1 = *s; + + if (*law == '1') { + /* Invert sign bit */ + s1 ^= 128; + if (s1 >= 128) { + s1 += -128; + sig = 4096; + } else { + sig = 0; + + } + iexp = s1 / 16; + + mant = s1 - (iexp << 4); + ss = (iexp == 0) ? + ((mant << 1) + 1 + sig) : + ((1 << (iexp - 1)) * ((mant << 1) + 33) + sig); + + sss = ss / 4096; + ssm = ss & 4095; + ssq = ssm << 1; + } else { + /* Invert sign bit */ + s1 ^= 128; + if (s1 >= 128) { + s1 += -128; + s1 ^= 127; + sig = 8192; + } else { + sig = 0; + s1 ^= 127; + } + iexp = s1 / 16; + + mant = s1 - (iexp << 4); + + ss = (iexp == 0) ? + ((mant << 1) + sig) : + ((1 << iexp) * ((mant << 1) + 33) - 33 + sig); + + sss = ss / 8192; + ssq = ss & 8191; + } + + *sl = (sss == 0) ? ssq : ((16384 - ssq) & 16383); + +} + +/* ...................... end of G726_expand() ...................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_subta (short *sl, short *se, short *d); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Compute difference signal by subtracting signal estimate from + input signal (or quantized reconstructed signal in decoder). + + Inputs: sl (slx in decoder), se + Output: d (dx in decoder) + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + + ---------------------------------------------------------------------- +*/ +void G726_subta(sl, se, d) +short *sl, *se, *d; +{ + long se1; + long sl1, sei, sli; + short ses, sls; + + sls = (*sl >> 13); + + sl1 = *sl; + se1 = *se; + + /* Sign extension */ + sli = (sls == 0) ? sl1 : (sl1 + 49152); + + ses = (*se >> 14); + + /* Sign extension */ + sei = (ses == 0) ? se1 : (se1 + 32768); + + /* 16 bit TC */ + *d = (short) ((sli + 65536 - sei) & 65535); + +} + +/* ......................... end of G726_subta() ......................... */ + + +/* + -------------------------------------------------------------------------- + + void G726_log (short *d, short *dl, short *ds); + ~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert difference signal from linear to the logarithmic domain. + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f 1st release to UGST, in Fortran. + + 13.Feb.92 v1.0c release of 1st version, in C. + + + -------------------------------------------------------------------------- +*/ +void G726_log(d, dl, ds) +short *d, *dl, *ds; +{ + long mant; + long d1; + long dqm, exp_; + + *ds = (*d >> 15); + + d1 = *d; + + /* Convert from 2-complement to signed magnitude */ + dqm = (*ds) ? ((65536 - d1) & 32767) : d1; + + /* Compute exponent */ + if (dqm >= 16384) + exp_ = 14; + else if (dqm >= 8192) + exp_ = 13; + else if (dqm >= 4096) + exp_ = 12; + else if (dqm >= 2048) + exp_ = 11; + else if (dqm >= 1024) + exp_ = 10; + else if (dqm >= 512) + exp_ = 9; + else if (dqm >= 256) + exp_ = 8; + else if (dqm >= 128) + exp_ = 7; + else if (dqm >= 64) + exp_ = 6; + else if (dqm >= 32) + exp_ = 5; + else if (dqm >= 16) + exp_ = 4; + else if (dqm >= 8) + exp_ = 3; + else if (dqm >= 4) + exp_ = 2; + else if (dqm >= 2) + exp_ = 1; + else + exp_ = 0; + + /* Compute approximation log2(1+x) = x */ + mant = ((dqm << 7) >> exp_) & 127; + + /* Combine mantissa and exponent (7 and 4) bits into a 11-bit word */ + *dl = (short) ((exp_ << 7) + mant); + +} + +/* ........................ end of G726_log() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_quan (short rate, short *dln, short *ds, short *i); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Quantize difference signal in logarithmic + domain. + + Inputs: dln, ds, rate + Output: i + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_quan(rate, dln, ds, i) +short *dln, *ds, *i; +short rate; +{ + if (rate == 4) { + if (*dln >= 3972) + *i = 1; + else if (*dln >= 2048) + *i = 15; + else if (*dln >= 400) + *i = 7; + else if (*dln >= 349) + *i = 6; + else if (*dln >= 300) + *i = 5; + else if (*dln >= 246) + *i = 4; + else if (*dln >= 178) + *i = 3; + else if (*dln >= 80) + *i = 2; + else + *i = 1; + + /* Adjust for sign */ + if (*ds) + *i = 15 - *i; + + if (*i == 0) + *i = 15; + } + + /* ......... end of 32 kbit part ........... */ + else if (rate == 3) { + if (*dln >= 2048) + *i = 7; + else if (*dln >= 331) + *i = 3; + else if (*dln >= 218) + *i = 2; + else if (*dln >= 8) + *i = 1; + else if (*dln >= 0) + *i = 7; + + /* Adjust for sign */ + if (*ds) + *i = 7 - *i; + + if (*i == 0) + *i = 7; + } + /* ......... end of 24 kbit part ........... */ + else if (rate == 2) { + if (*dln >= 2048) + *i = 0; + else if (*dln >= 261) + *i = 1; + else + *i = 0; + + /* Adjust for sign */ + if (*ds) + *i = 3 - *i; + } + /* ......... end of 16 kbit part ........... */ + else { + if (*dln >= 4080) + *i = 2; + else if (*dln >= 3974) + *i = 1; + else if (*dln >= 2048) + *i = 31; + else if (*dln >= 553) + *i = 15; + else if (*dln >= 528) + *i = 14; + else if (*dln >= 502) + *i = 13; + else if (*dln >= 475) + *i = 12; + else if (*dln >= 445) + *i = 11; + else if (*dln >= 413) + *i = 10; + else if (*dln >= 378) + *i = 9; + else if (*dln >= 339) + *i = 8; + else if (*dln >= 298) + *i = 7; + else if (*dln >= 250) + *i = 6; + else if (*dln >= 198) + *i = 5; + else if (*dln >= 139) + *i = 4; + else if (*dln >= 68) + *i = 3; + else if (*dln >= 0) + *i = 2; + + if (*ds) + *i = 31 - *i; + + if (*i == 0) + *i = 31; + + } /* ......... end of 40 kbit part ........... */ + +} + +/* ........................ end of G726_quan() ........................ */ + + +/* + ---------------------------------------------------------------------- + + void G726_subtb (short *dl, short *y, short *dln); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Scale logarithmic version of difference signal by subtracting + scale factor. + + Inputs: dl (dlx no decodificador), y + Output: dln (dlnx no decodificador) + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_subtb(dl, y, dln) +short *dl, *y, *dln; +{ + *dln = (*dl + 4096 - (*y >> 2)) & 4095; + +} + +/* ........................ end of G726_subtb() ........................ */ + + +/* + ---------------------------------------------------------------------- + + void G726_adda (short *dqln, short *y, short *dql); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Addition of scale factor to logarithmic version of quantized + difference signal. + + Inputs: dqln, y + Output: dql + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_adda(dqln, y, dql) +short *dqln, *y, *dql; +{ + *dql = (*dqln + (*y >> 2)) & 4095; + +} + +/* ....................... end of G726_adda() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_antilog (short *dql, short *dqs, short *dq); + ~~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert quantized difference signal from the logarithmic to + the linear domain. + + Inputs: dql, dqs + Output: dq + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_antilog(dql, dqs, dq) +short *dql, *dqs, *dq; +{ + long dqmag; + long ds, dmn, dex, dqt; + + /* Extract 4-bit exponent */ + ds = (*dql >> 11); + dex = (*dql >> 7) & 15; + + /* Extract 7-bit mantissa */ + dmn = *dql & 127; + + dqt = dmn + 128; + + /* Convert mantissa to linear using the approx. 2**x = 1+x */ + dqmag = ds ? 0 : ((dqt << 7) >> (14 - dex)); + + /* Attach sign bit to signed mag. word */ + *dq = (short) (*dqs << 15) + dqmag; +} + +/* ..................... end of G726_antilog() ..................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_reconst (short rate, short *i, short *dqln, short *dqs); + ~~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Reconstruction of quantized difference signal in the + logarithmic domain. + + Inputs: i, rate + Outputs: dqln, dqs + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_reconst(rate, i, dqln, dqs) +short *i, *dqln, *dqs; +short rate; +{ + if (rate == 4) { + /* Initialized data */ + static short tab[16] = { 2048, 4, 135, 213, 273, 323, 373, 425, + 425, 373, 323, 273, 213, 135, 4, 2048 + }; + + /* Extract sign */ + *dqs = (*i >> 3); + + /* Table look-up */ + *dqln = tab[*i]; + } + /* ............... end of 32 kbit part + * ................. */ + else if (rate == 3) { + /* Initialized data */ + static short tab[8] = { 2048, 135, 273, 373, 373, 273, 135, 2048 }; + + *dqs = (*i >> 2); + + /* Table look-up */ + *dqln = tab[*i]; + + } + + /* ............... end of 24 kbit part + * ................. */ + else if (rate == 2) { + /* Initialized data */ + static short tab[4] = { 116, 365, 365, 116 }; + + *dqs = (*i >> 1); + + /* Table look-up */ + *dqln = tab[*i]; + + } /* ............... end of 16 kbit part + * ................. */ + else { + /* Initialized data */ + static short tab[32] = + { 2048, 4030, 28, 104, 169, 224, 274, 318, 358, 395, 429, + 459, 488, 514, 539, 566, 566, 539, 514, 488, 459, 429, 395, 358, + 318, 274, 224, + 169, 104, 28, 4030, 2048 + }; + + *dqs = (*i >> 4); + + /* Table look-up */ + *dqln = tab[*i]; + + } /* ................ end of 40 kbit part + * ................... */ + + +} + +/* ....................... end of G726_reconst() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_delaya (short *r, short *x, short *y); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Memory block. + + Inputs: r, x + Output: y + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_delaya(r, x, y) +short *r, *x, *y; +{ + *y = (*r == 0) ? *x : 0; + +} + +/* ....................... end of G726_delaya() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_delayb (short *r, short *x, short *y); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Memory block. + + Inputs: r, x + Output: y + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_delayb(r, x, y) +short *r, *x, *y; +{ + *y = (*r == 0) ? *x : 544; + +} + +/* ....................... end of G726_delayb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_delayc (short *r, long *x, long *y); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Memory block. + + Inputs: r, x + Output: y + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_delayc(r, x, y) +short *r; +long *x, *y; +{ + *y = (*r == 0) ? *x : 34816; + +} + +/* ....................... end of G726_delayc() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_delayd (short *r, short *x, short *y); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Memory block + + Inputs: r, x + Output: y + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_delayd(r, x, y) +short *r, *x, *y; +{ + *y = (*r == 0) ? *x : 32; + +} + +/* ....................... end of G726_delayd() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_filtd (short *wi, short *y, short *yut); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Update of fast quantizer scale factor. + + Inputs: wi, y + Output: yut + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_filtd(wi, y, yut) +short *wi, *y, *yut; +{ + long difs, difsx; + long y1; + long wi1, dif; + + /* Compute difference */ + wi1 = *wi; + y1 = *y; + dif = ((wi1 << 5) + 131072 - y1) & 131071; + difs = (dif >> 16); + + /* Time constant is 1/32; sign extension */ + difsx = (difs == 0) ? (dif >> 5) : ((dif >> 5) + 4096); + + *yut = (short) ((y1 + difsx) & 8191); + +} + +/* ....................... end of G726_filte() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_filte (short *yup, long *yl, long *ylp); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Update of slow quantizer scale factor. + + + Inputs: yup, yl + Output: ylp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_filte(yup, yl, ylp) +short *yup; +long *yl, *ylp; +{ + long difs, difsx; + long dif, dif1, yup1; + + /* Compute difference */ + yup1 = *yup; + dif1 = 1048576 - *yl; + dif = (yup1 + (dif1 >> 6)) & 16383; + difs = (dif >> 13); + + /* Sign extension */ + difsx = (difs == 0) ? dif : (dif + 507904); + + *ylp = (*yl + difsx) & 524287; + +} + +/* ....................... end of G726_filte() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_functw (short rate, short *i, short *wi); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Map quantizer output into logarithmic version of scale factor + multiplier. + + Inputs: i, rate + Output: wi + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_functw(rate, i, wi) +short *i, *wi; +short rate; +{ + if (rate == 4) { + /* Initialized data */ + static short tab[8] = { 4084, 18, 41, 64, 112, 198, 355, 1122 }; + short im, is; + + is = (*i >> 3); + + im = (is == 0) ? (*i & 7) : ((15 - *i) & 7); + + /* Scale factor multiplier */ + *wi = tab[im]; + + + } + + + + + /* ................. end of 32 kbit part + * .............. */ + else if (rate == 3) { + + /* Initialized data */ + static short tab[4] = { 4092, 30, 137, 582 }; + short im, is; + + + is = (*i >> 2); + + im = (is == 0) ? (*i & 3) : ((7 - *i) & 3); + + *wi = tab[im]; + + + + } + + + + + /* ................. end of 24 kbit part + * .............. */ + else if (rate == 2) { + /* Initialized data */ + static short tab[2] = { 4074, 439 }; + short im, is; + + + is = (*i >> 1); + + im = (is == 0) ? (*i & 1) : ((3 - *i) & 1); + + *wi = tab[im]; + + } + + + + + /* ................. end of 16 kbit part + * .............. */ + else { + /* Initialized data */ + static short tab[16] = + { 14, 14, 24, 39, 40, 41, 58, 100, 141, 179, 219, 280, 358, + 440, 529, 696 + }; + short im, is; + + is = (*i >> 4); + + im = (is == 0) ? (*i & 15) : ((31 - *i) & 15); + + *wi = tab[im]; + } /* ................. end of 40 kbit part + * .............. */ +} + +/* ....................... end of G726_functw() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_limb (short *yut, short *yup); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Limit quantizer scale factor. + + Inputs: yut + Output: yup + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_limb(yut, yup) +short *yut, *yup; +{ + short gell, geul; + + geul = ((*yut + 11264) & 16383) >> 13; + gell = ((*yut + 15840) & 16383) >> 13; + + if (gell == 1) + *yup = 544; /* Lower limit is 1.06 */ + else if (geul == 0) + *yup = 5120; /* Upper limit is 10.0 */ + else + *yup = *yut; + +} + +/* ....................... end of G726_limb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_mix (short *al, short *yu, long *yl, short *y); + ~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Form linear combination of fast and slow quantizer scale + factors. + + Inputs: al, yu, yl + Output: y + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_mix(al, yu, yl, y) +short *al, *yu; +long *yl; +short *y; +{ + long difm, difs, prod; + long prodm, al1; + long yu1, dif; + + /* Preamble */ + al1 = *al; + yu1 = *yu; + + /* Compute difference */ + dif = (yu1 + 16384 - (*yl >> 6)) & 16383; + difs = (dif >> 13); + + /* Compute magnitude of difference */ + difm = (difs == 0) ? dif : ((16384 - dif) & 8191); + + /* Compute magnitude of product */ + prodm = ((difm * al1) >> 6); + + /* Convert magnitude to two's complement */ + prod = (difs == 0) ? prodm : ((16384 - prodm) & 16383); + + *y = (short) (((*yl >> 6) + prod) & 8191); + +} + +/* ....................... end of G726_mix() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_filta (short *fi, short *dms, short *dmsp); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Update of short term average of f(i). + + Inputs: fi, dms + Output: dmsp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_filta(fi, dms, dmsp) +short *fi, *dms, *dmsp; +{ + short difs, difsx; + short dif; + + /* Compute difference */ + dif = ((*fi << 9) + 8192 - *dms) & 8191; + difs = (dif >> 12); + + /* Time constant is 1/32, sign extension */ + difsx = (difs == 0) ? (dif >> 5) : ((dif >> 5) + 3840); + + *dmsp = (difsx + *dms) & 4095; + +} + +/* ....................... end of G726_filta() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_filtb (short *fi, short *dml, short *dmlp); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Update of long term average of f(i). + + Inputs: fi, dml + Output: dmlp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_filtb(fi, dml, dmlp) +short *fi, *dml, *dmlp; +{ + long difs, difsx; + long fi1; + long dif, dml1; + + /* Preamble */ + fi1 = *fi; + dml1 = *dml; + + /* Compute difference */ + dif = ((fi1 << 11) + 32768 - dml1) & 32767; + difs = (dif >> 14); + + /* Time constant is 1/28, sign extension */ + difsx = (difs == 0) ? (dif >> 7) : ((dif >> 7) + 16128); + + *dmlp = (short) ((difsx + dml1) & 16383); + +} + +/* ....................... end of G726_filtb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_filtc (short *ax, short *ap, short *app); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Low pass filter of speed control parameter. + + Inputs: ax, ap + Output: app + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_filtc(ax, ap, app) +short *ax, *ap, *app; +{ + short difs, difsx; + short dif; + + /* Compute difference */ + dif = ((*ax << 9) + 2048 - *ap) & 2047; + difs = (dif >> 10); + + /* Time constant is 1/16, sign extension */ + difsx = (difs == 0) ? (dif >> 4) : ((dif >> 4) + 896); + + *app = (difsx + *ap) & 1023; + +} + +/* .................... end of G726_filtc() .................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_functf (short rate, short *i, short *fi); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Map quantizer output into the f(i) function. + + Inputs: i, rate + Output: fi + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_functf(rate, i, fi) +short *i, *fi; +short rate; + +{ + short im, is; + + if (rate == 4) { + /* Initialized data */ + static short tab[8] = { 0, 0, 0, 1, 1, 1, 3, 7 }; + + is = (*i >> 3); + + im = (is == 0) ? (*i & 7) : ((15 - *i) & 7); + + *fi = tab[im]; + } + /* ................ end of 32 kbit part + * ................. */ + else if (rate == 3) { + /* Initialized data */ + static short tab[4] = { 0, 1, 2, 7 }; + + is = (*i >> 2); + + im = (is == 0) ? (*i & 3) : ((7 - *i) & 3); + + *fi = tab[im]; + + } /* ................ end of 24 kbit part + * ................. */ + else if (rate == 2) { + /* Initialized data */ + static short tab[2] = { 0, 7 }; + + + is = (*i >> 1); + + im = (is == 0) ? (*i & 1) : ((3 - *i) & 1); + + *fi = tab[im]; + + } + /* ................ end of 16 kbit part + * ................. */ + else { + /* Initialized data */ + static short tab[16] = + { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6 }; + + + is = (*i >> 4); + + im = (is == 0) ? (*i & 15) : ((31 - *i) & 15); + + *fi = tab[im]; + + } /* ................ end of 40 kbit part + * ................. */ +} + +/* ...................... end of G726_functf() ...................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_lima (short *ap, short *al); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Limit speed control parameter. + + Inputs: ap + Output: al + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_lima(ap, al) +short *ap, *al; +{ + *al = (*ap >= 256) ? 64 : (*ap >> 2); + +} + +/* ....................... end of G726_lima() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_subtc (short *dmsp, short *dmlp, short *tdp, + ~~~~~~~~~~~~~~~ short *y, short *ax); + + Description: + ~~~~~~~~~~~~ + + Functions of quantizer output sequence and then perform + threshold comparison for quantizing speed control parameter. + compute magnitude of the difference of short and long-term + + Inputs: dmsp, dmlp, tdp, y + Output: ax + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_subtc(dmsp, dmlp, tdp, y, ax) +short *dmsp, *dmlp, *tdp, *y, *ax; +{ + long difm, difs, dthr, dmlp1, dmsp1; + long dif; + + /* Preamble */ + dmsp1 = *dmsp; + dmlp1 = *dmlp; + + /* Compute difference */ + dif = ((dmsp1 << 2) + 32768 - dmlp1) & 32767; + difs = (dif >> 14); + + /* Compute magnitude of difference */ + difm = (difs == 0) ? dif : ((32768 - dif) & 16383); + + /* Compute threshold */ + dthr = (dmlp1 >> 3); + + /* Quantize speed control parameter */ + *ax = (*y >= 1536 && difm < dthr && *tdp == 0) ? 0 : 1; + +} + +/* ....................... end of G726_subtc() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_triga (short *tr, short *app, short *apr); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Speed control trigger block. + + Inputs: tr, app + Output: apr + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_triga(tr, app, apr) +short *tr, *app, *apr; +{ + *apr = (*tr == 0) ? (*app) : 256; + +} + +/* ....................... end of G726_triga() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_accum (short *wa1, short *wa2, short *wb1, + ~~~~~~~~~~~~~~~ short *wb2, short *wb3, short *wb4, + short *wb5, short *wb6, short *se, short *sez); + + Description: + ~~~~~~~~~~~~ + + Addition of predictor outputs to form the partial signal + estimate (from the sixth order predictor) and the signal + estimate. + + Inputs: wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6 + Output: se, sez + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_accum(wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6, se, sez) +short *wa1, *wa2, *wb1, *wb2, *wb3, *wb4, *wb5, *wb6, *se, *sez; +{ + unsigned long sezi; + unsigned long wa11, wa21, wb11, wb21, wb31, wb41, wb51, wb61, sei; + + /* Preamble */ + wa11 = *wa1; + wa21 = *wa2; + wb11 = *wb1; + wb21 = *wb2; + wb31 = *wb3; + wb41 = *wb4; + wb51 = *wb5; + wb61 = *wb6; + + /* Sum of partial signal estimate */ + sezi = (((((((((wb11 + wb21) & 65535) + wb31) & 65535) + + wb41) & 65535) + wb51) & 65535) + wb61) & 65535; + + /* Complete sum for signal estimate */ + sei = (((sezi + wa21) & 65535) + wa11) & 65535; + + *sez = (short) (sezi >> 1); + *se = (short) (sei >> 1); + +} + +/* ....................... end of G726_accum() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_addb (short *dq, short *se, short *sr); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Addition of quantized difference signal and signal estimate + to form reconstructed signal. + + Inputs: dq, se + Output: sr + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_addb(dq, se, sr) +short *dq, *se, *sr; +{ + unsigned long dq1, se1; + unsigned long dqi, sei; + short dqs, ses; + + /* Preamble */ + dq1 = *dq & 65535; + se1 = *se; + + /* Sign */ + dqs = (*dq >> 15) & 1; + + /* Convert signed magnitude to 2's complement */ + dqi = (dqs == 0) ? dq1 : ((65536 - (dq1 & 32767)) & 65535); + + ses = (*se >> 14); + + /* Sign extension */ + sei = (ses == 0) ? se1 : ((1 << 15) + se1); + + *sr = (short) ((dqi + sei) & 65535); + +} + +/* ....................... end of G726_addb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_addc (short *dq, short *sez, short *pk0, + ~~~~~~~~~~~~~~ short *sigpk); + + Description: + ~~~~~~~~~~~~ + + Obtain sign of addition of quantized difference signal and + partial signal estimate. + + Inputs: dq, sez + Outputs: pk0, sigpk + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_addc(dq, sez, pk0, sigpk) +short *dq, *sez, *pk0, *sigpk; +{ + unsigned long sezi; + short sezs; + unsigned long dqsez, dq1; + unsigned long dqi; + short dqs; + unsigned long sez1; + + /* Preamble */ + dq1 = *dq & 65535; + sez1 = *sez; + + /* Get sign */ + dqs = (*dq >> 15) & 1; + + /* Convert signed magnitude to 2's compelemnent */ + dqi = (dqs == 0) ? dq1 : ((65536 - (dq1 & 32767)) & 65535); + + sezs = (*sez >> 14); + + /* Sign extension */ + sezi = (sezs == 0) ? sez1 : (sez1 + 32768); + + dqsez = (dqi + sezi) & 65535; + + *pk0 = (short) (dqsez >> 15); + *sigpk = (dqsez == 0) ? 1 : 0; + +} + +/* ....................... end of G726_addc() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_floata (short *dq, short *dq0); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert 16-bit signed magnitude to floating point. + + Inputs: dq + Output: dq0 + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_floata(dq, dq0) +short *dq, *dq0; +{ + long mant; + long mag, exp_; + long dqs; + + dqs = (*dq >> 15) & 1; + + /* Compute magnitude */ + mag = *dq & 32767; + + /* Exponent */ + if (mag >= 16384) + exp_ = 15; + else if (mag >= 8192) + exp_ = 14; + else if (mag >= 4096) + exp_ = 13; + else if (mag >= 2048) + exp_ = 12; + else if (mag >= 1024) + exp_ = 11; + else if (mag >= 512) + exp_ = 10; + else if (mag >= 256) + exp_ = 9; + else if (mag >= 128) + exp_ = 8; + else if (mag >= 64) + exp_ = 7; + else if (mag >= 32) + exp_ = 6; + else if (mag >= 16) + exp_ = 5; + else if (mag >= 8) + exp_ = 4; + else if (mag >= 4) + exp_ = 3; + else if (mag >= 2) + exp_ = 2; + else if (mag == 1) + exp_ = 1; + else + exp_ = 0; + + /* Compute mantissa w/a 1 in the most sig. bit */ + mant = (mag == 0) ? (1 << 5) : ((mag << 6) >> exp_); + /* Combine sign, exponent and mantissa (1,4,6) bits in a word */ + *dq0 = (short) ((dqs << 10) + (exp_ << 6) + mant); + +} + +/* ....................... end of G726_floata() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_floatb (short *sr, short *sr0); + ~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert 16-bit two's complement to floating point. + + Inputs: sr + Output: sr0 + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_floatb(sr, sr0) +short *sr, *sr0; +{ + long mant; + long mag, exp_, srr, srs; + + /* Preamble */ + srr = *sr & 65535; + + /* Sign */ + srs = (srr >> 15); + + /* Compute magnitude */ + mag = (srs == 0) ? srr : ((65536 - srr) & 32767); + + /* Exponent */ + if (mag >= 16384) + exp_ = 15; + else if (mag >= 8192) + exp_ = 14; + else if (mag >= 4096) + exp_ = 13; + else if (mag >= 2048) + exp_ = 12; + else if (mag >= 1024) + exp_ = 11; + else if (mag >= 512) + exp_ = 10; + else if (mag >= 256) + exp_ = 9; + else if (mag >= 128) + exp_ = 8; + else if (mag >= 64) + exp_ = 7; + else if (mag >= 32) + exp_ = 6; + else if (mag >= 16) + exp_ = 5; + else if (mag >= 8) + exp_ = 4; + else if (mag >= 4) + exp_ = 3; + else if (mag >= 2) + exp_ = 2; + else if (mag == 1) + exp_ = 1; + else + exp_ = 0; + + /* Compute mantissa w/a 1 in the most sig. bit */ + mant = (mag == 0) ? (1 << 5) : ((mag << 6) >> exp_); + + /* Combine sign, exponent and mantissa (1,4,6) bits in a word */ + *sr0 = (short) ((srs << 10) + (exp_ << 6) + mant); + +} + +/* ....................... end of G726_floatb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_fmult (short *a, short *srn, short *wa); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Multiply predictor coefficients with corresponding quantized + difference signal or reconstructed signal. multiplication is + done in floating piont format + + Inputs: a (or b), srn (or dqn) + Outputs: wa (or wb) + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_fmult(An, SRn, WAn) +short *An, *SRn, *WAn; +{ + long anmag, anexp, wanmag, anmant; + long wanexp, srnexp, an, ans, wanmant, srnmant; + long wan, wans, srns, srn1; + + /* Preamble */ + an = *An & 65535; + srn1 = *SRn & 65535; + + /* Sign */ + ans = an & 32768; + ans = (ans >> 15); + + /* Convert 2's complement to signed magnitude */ + anmag = (ans == 0) ? (an >> 2) : ((16384 - (an >> 2)) & 8191); + + /* Exponent */ + if (anmag >= 4096) + anexp = 13; + else if (anmag >= 2048) + anexp = 12; + else if (anmag >= 1024) + anexp = 11; + else if (anmag >= 512) + anexp = 10; + else if (anmag >= 256) + anexp = 9; + else if (anmag >= 128) + anexp = 8; + else if (anmag >= 64) + anexp = 7; + else if (anmag >= 32) + anexp = 6; + else if (anmag >= 16) + anexp = 5; + else if (anmag >= 8) + anexp = 4; + else if (anmag >= 4) + anexp = 3; + else if (anmag >= 2) + anexp = 2; + else if (anmag == 1) + anexp = 1; + else + anexp = 0; + + /* Compute mantissa w/a 1 in the most sig. bit */ + anmant = (anmag == 0) ? (1 << 5) : ((anmag << 6) >> anexp); + + /* Split floating point word into sign, exponent and mantissa */ + srns = (srn1 >> 10); + srnexp = (srn1 >> 6) & 15; + srnmant = srn1 & 63; + + /* Floating point multiplication */ + wans = srns ^ ans; + wanexp = srnexp + anexp; + wanmant = ((srnmant * anmant) + 48) >> 4; + + /* Convert floating point to magnitude */ + wanmag = (wanexp <= 26) ? + (wanmant << 7) >> (26 - wanexp) : + ((wanmant << 7) << (wanexp - 26)) & 32767; + + /* Convert mag. to 2's complement */ + wan = (wans == 0) ? wanmag : ((65536 - wanmag) & 65535); + + *WAn = (short) wan; + +} + +/* ....................... end of G726_fmult() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_limc (short *a2t, short *a2p); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Limits on a2 coefficient of second order predictor. + + Inputs: a2t + Output: a2p + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ + +void G726_limc(a2t, a2p) +short *a2t, *a2p; +{ + long a2p1, a2t1, a2ll, a2ul; + + a2t1 = *a2t & 65535; + + a2ul = 12288; /* Upper limit of +.75 */ + a2ll = 53248; /* Lower limit of -.75 */ + + if (a2t1 >= 32768 && a2t1 <= a2ll) + a2p1 = a2ll; + else if (a2t1 >= a2ul && a2t1 <= 32767) + a2p1 = a2ul; + else + a2p1 = a2t1; + + *a2p = (short) a2p1; + +} + +/* ....................... end of G726_limc() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_limd (short *a1t, short *a2p, short *a1p); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Limits on a1 coefficient of second order predictor. + + Inputs: a1t, a2p + Output: a1p + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_limd(a1t, a2p, a1p) +short *a1t, *a2p, *a1p; +{ + long a1p1, a2p1, a1t1, ome, a1ll, a1ul; + + /* Preamble */ + a1t1 = *a1t & 65535; + a2p1 = *a2p & 65535; + + /* (1-epsilon), where epsilon = (1/16) */ + ome = 15360; + + /* Compute upper limit */ + a1ul = (ome + 65536 - a2p1) & 65535; + + /* Compute lower limit */ + a1ll = (a2p1 + 65536 - ome) & 65535; + + if (a1t1 >= 32768 && a1t1 <= a1ll) + a1p1 = a1ll; + else if (a1t1 >= a1ul && a1t1 <= 32767) + a1p1 = a1ul; + else + a1p1 = a1t1; + + *a1p = (short) a1p1; + +} + +/* ....................... end of G726_limd() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_trigb (short *tr, short *ap, short *ar); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Predictor trigger block. + + Inputs: tr, ap (ou bp ou tdp) + Output: ar (ou br ou tdr) + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_trigb(tr, ap, ar) +short *tr, *ap, *ar; +{ + *ar = (*tr == 0) ? *ap : 0; + +} + +/* ....................... end of G726_trigb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_upa1 (short *pk0, short *pk1, short *a1, + ~~~~~~~~~~~~~~ short *sigpk, short *a1t); + + Description: + ~~~~~~~~~~~~ + + Update a1 coefficient of second order predictor. + + Inputs: pk0, pk1, a1, sigpk + Output: a1t + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_upa1(pk0, pk1, a1, sigpk, a1t) +short *pk0, *pk1, *a1, *sigpk, *a1t; +{ + long a11, a1s, ua1; + long ash; + short pks; + long uga1, ula1; + + /* Preamble */ + a11 = *a1 & 65535; + + pks = (*pk0) ^ (*pk1); + + /* Gain is +/- (3/256) */ + uga1 = (*sigpk == 1) ? 0 : ((pks == 0) ? 192 : 65344); + + a1s = (a11 >> 15); + + /* Leak factor is (1/256) */ + ash = (a11 >> 8); + ula1 = ((a1s == 0) ? (65536 - ash) : (65536 - (ash + 65280))) & 65535; + + /* Compute update */ + ua1 = (uga1 + ula1) & 65535; + *a1t = (short) ((a11 + ua1) & 65535); + +} + +/* ....................... end of G726_upa1() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_upa2 (short *pk0, short *pk1, short *pk2, + ~~~~~~~~~~~~~~ short *a2, short *a1, short *sigpk, short *a2t); + + Description: + ~~~~~~~~~~~~ + + Update a2 coefficient of second order predictor. + + Inputs: pk0, pk1, pk2, a2, a1, sigpk + Output: a2t + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_upa2(pk0, pk1, pk2, a2, a1, sigpk, a2t) +short *pk0, *pk1, *pk2, *a2, *a1, *sigpk, *a2t; +{ + long uga2a, uga2b, uga2s; + long a11, a21, fa, fa1; + short a1s, a2s; + long ua2; + long uga2, ula2; + short pks1, pks2; + + /* Preamble */ + a11 = *a1 & 65535; + a21 = *a2 & 65535; + + /* 1 bit xors */ + pks1 = (*pk0 ^ *pk1); + pks2 = (*pk0 ^ *pk2); + + uga2a = (pks2 == 0) ? 16384 : 114688; + + a1s = (*a1 >> 15); + + /* Implement f(a1) w/ limiting at +/-(1/2) */ + if (a1s == 0) + fa1 = (a11 <= 8191) ? (a11 << 2) : (8191 << 2); + else + fa1 = (a11 >= 57345) ? ((a11 << 2) & 131071) : (24577 << 2); + + /* Attach sign to the result of f(a1) */ + fa = (pks1) ? fa1 : ((131072 - fa1) & 131071); + + uga2b = (uga2a + fa) & 131071; + uga2s = (uga2b >> 16); + + uga2 = (*sigpk == 1) ? 0 : + ((uga2s) ? ((uga2b >> 7) + 64512) : (uga2b >> 7)); + + a2s = (*a2 >> 15); + + ula2 = (a2s == 0) ? (65536 - (a21 >> 7)) & 65535 : + (65536 - ((a21 >> 7) + 65024)) & 65535; + + /* Compute update */ + ua2 = (uga2 + ula2) & 65535; + *a2t = (short) ((a21 + ua2) & 65535); + +} + +/* ....................... end of G726_upa2() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_upb (short rate, short *u, short *b, short *dq, short *bp); + ~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Update for coefficients of sixth order predictor. + + Inputs: u, b, dq, rate + Output: bp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_upb(rate, u, b, dq, bp) +short *u, *b, *dq, *bp; +short rate; +{ + short dqmag; + long bb, bs, ub; + long ugb, ulb; + short param; + short leak; + + /* Preamble */ + bb = *b & 65535; + + dqmag = *dq & 32767; + if (rate != 5) { + leak = 8; + param = 65280; + } else { + leak = 9; + param = 65408; + } + /* gain is 0 or +/- (1/128) */ + ugb = (dqmag == 0) ? 0 : ((*u == 0) ? 128 : 65408); + + bs = (bb >> 15); + + /* Leak factor is (1/256 or 1/512 for 40 kbit/s) */ + + ulb = (bs == 0) ? + ((65536 - (bb >> leak)) & 65535) : + ((65536 - ((bb >> leak) + param)) & 65535); + + /* Compute update */ + ub = (ugb + ulb) & 65535; +/* aux = bb + ub;*/ + + *bp = (short) ((bb + ub) & 65535); + +} + +/* ....................... end of G726_upb() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_xor (short *dqn, short *dq, short *u); + ~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + One bit "exclusive or" of sign of difference signal and sign + of delayed difference signal. + + Inputs: dqn, dq + Output: u + + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_xor(dqn, dq, u) +short *dqn, *dq, *u; +{ + short dqns; + short dqs; + + dqs = (*dq >> 15) & 1; + + dqns = (*dqn >> 10); + + *u = (dqs ^ dqns); + +} + +/* ....................... end of G726_xor() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_tone (short *a2p, short *tdp); + ~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Partial band signal detection. + + Inputs: a2p + Output: tdp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_tone(a2p, tdp) +short *a2p, *tdp; +{ + long a2p1; + + a2p1 = *a2p & 65535; + + *tdp = (a2p1 >= 32768 && a2p1 < 53760) ? 1 : 0; + +} + +/* ....................... end of G726_tone() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_trans (short *td, long *yl, short *dq, short *tr); + ~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Transition detector. + + Inputs: td, yl, dq + Output: tr + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_trans(td, yl, dq, tr) +short *td; +long *yl; +short *dq, *tr; +{ + short dqmag; + long dqthr; + short ylint; + long dqmag1; + short ylfrac; + long thr1, thr2; + + dqmag = *dq & 32767; + + ylint = (*yl >> 15); + + ylfrac = (*yl >> 10) & 31; + + thr1 = (ylfrac + 32) << ylint; + + thr2 = (ylint > 9) ? 31744 : thr1; + + dqthr = (thr2 + (thr2 >> 1)) >> 1; + + dqmag1 = dqmag; + + *tr = (dqmag1 > dqthr && *td == 1) ? 1 : 0; + +} + +/* ....................... end of G726_trans() ....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_compress (short *sr, char *law, short *sp); + ~~~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Convert from uniform pcm to either a-law or u-law pcm + + Inputs: sr, law + Output: sp + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + 24.Jan.00 v2.0 Corrected im calculation that caused incorrect + processing of test vector ri40fa. Corrected + code provided by Jayesh Patel . + Verified by + ---------------------------------------------------------------------- +*/ +void G726_compress(sr, law, sp) +short *sr; +char *law; +short *sp; +{ + short imag, iesp, ofst; + short ofst1; + long i; + long im; + short is; + long srr; + + is = (*sr >> 15); + srr = (*sr & 65535); + + /* Convert 2-complement to signed magnitude */ + im = (is == 0) ? srr : ((65536 - srr) & 32767); + + /* Compress ... */ + if (*law == '1') { + + /* Next line added by J.Patel to fix a with test vector ri40fa.o */ + im = (*sr == -32768) ? 2 : im; /* *** */ + + imag = (is == 0) ? (im >> 1) : ((im + 1) >> 1); + + if (is) + --imag; + + /* Saturation */ + if (imag > 4095) + imag = 4095; + + iesp = 7; + for (i = 1; i <= 7; ++i) { + imag += imag; + if (imag >= 4096) + break; + iesp = 7 - i; + } + + imag &= 4095; + + imag = (imag >> 8); + *sp = (is == 0) ? imag + (iesp << 4) : imag + (iesp << 4) + 128; + + /* Sign bit inversion */ + *sp ^= 128; + } else { + imag = im; + + if (imag > 8158) + imag = 8158; /* Saturation */ + + ++imag; + iesp = 0; + ofst = 31; + + if (imag > ofst) { + for (iesp = 1; iesp <= 8; ++iesp) { + ofst1 = ofst; + ofst += (1 << (iesp + 5)); + if (imag <= ofst) + break; + } + imag -= ofst1 + 1; + } + + imag /= (1 << (iesp + 1)); + + *sp = (is == 0) ? (imag + (iesp << 4)) : (imag + (iesp << 4) + 128); + + /* Sign bit inversion */ + *sp ^= 128; + *sp ^= 127; + } + +} + +/* ....................... end of G726_compress()....................... */ + + +/* + ---------------------------------------------------------------------- + + void G726_sync (short rate, short *i, short *sp, short *dlnx, + ~~~~~~~~~~~~~~ short *dsx, char *law, short *sd); + + Description: + ~~~~~~~~~~~~ + + Re-encode output pcm sample in decoder for synchronous tandem + coding. + + Inputs: i, sp, dlnx, dsx, law, rate + Output: sd + + Return value: none. + ~~~~~~~~~~~~~ + + Prototype: in g726.h + ~~~~~~~~~~ + + History: + ~~~~~~~~ + 31.Jan.91 v1.0f Release of 1st Fortran version to UGST. + + 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c) + + + ---------------------------------------------------------------------- +*/ +void G726_sync(rate, i, sp, dlnx, dsx, law, sd) +short *i, *sp, *dlnx, *dsx; +char *law; +short *sd; +short rate; +{ + short mask, id, im, is, ss; + + if (rate == 4) { + is = (*i >> 3); + + im = (is == 0) ? (*i + 8) : (*i & 7); + + /* Find value of `id' as in Table 17/G.726 */ + if (*dlnx >= 3972) + id = 9; + else if (*dlnx >= 2048) + id = 7; + else if (*dlnx >= 400) + id = 15; + else if (*dlnx >= 349) + id = 14; + else if (*dlnx >= 300) + id = 13; + else if (*dlnx >= 246) + id = 12; + else if (*dlnx >= 178) + id = 11; + else if (*dlnx >= 80) + id = 10; + else + id = 9; + + /* Account for the negative part of the table */ + if (*dsx) + id = 15 - id; + + if (id == 8) + id = 7; + } /* ............... end of 32 kbit part + * ................. */ + else if (rate == 3) { + is = (*i >> 2); + + im = (is == 0) ? (*i + 4) : (*i & 3); + + /* Find value of `id' as in the Table 18/G.726 */ + if (*dlnx >= 2048) + id = 3; + else if (*dlnx >= 331) + id = 7; + else if (*dlnx >= 218) + id = 6; + else if (*dlnx >= 8) + id = 5; + else if (*dlnx >= 0) + id = 3; + + + if (*dsx) + id = 7 - id; + + if (id == 4) + id = 3; + } /* ............... end of 24 kbit part + * ................. */ + else if (rate == 2) { + is = (*i >> 1); + + im = (is == 0) ? (*i + 2) : (*i & 1); + + /* Find value of `id' as in the Table 19/G.726 */ + if (*dlnx >= 2048) + id = 2; + else if (*dlnx >= 261) + id = 3; + else if (*dlnx >= 0) + id = 2; + + if (*dsx) + id = 3 - id; + + } /* ............... end of 16 kbit part + * ................. */ + else { + is = (*i >> 4); + + im = (is == 0) ? (*i + 16) : (*i & 15); + + /* Find value of `id' as in the Table 16/G.726 */ + + if (*dlnx >= 4080) + id = 18; + else if (*dlnx >= 3974) + id = 17; + else if (*dlnx >= 2048) + id = 15; + else if (*dlnx >= 553) + id = 31; + else if (*dlnx >= 528) + id = 30; + else if (*dlnx >= 502) + id = 29; + else if (*dlnx >= 475) + id = 28; + else if (*dlnx >= 445) + id = 27; + else if (*dlnx >= 413) + id = 26; + else if (*dlnx >= 378) + id = 25; + else if (*dlnx >= 339) + id = 24; + else if (*dlnx >= 298) + id = 23; + else if (*dlnx >= 250) + id = 22; + else if (*dlnx >= 198) + id = 21; + else if (*dlnx >= 139) + id = 20; + else if (*dlnx >= 68) + id = 19; + else if (*dlnx >= 0) + id = 18; + + if (*dsx) + id = 31 - id; + + if (id == 16) + id = 15; + + } /* ............... end of 40 kbit part + * ................. */ + + /* Choose sd as sp, sp+ or sp- */ + + ss = (*sp & 128) >> 7; + mask = (*sp & 127); + + if (*law == '1') { /* ......... A-law */ + if (id > im && ss == 1 && mask == 0) + ss = 0; + else if (id > im && ss == 1 && mask != 0) + mask--; + else if (id > im && ss == 0 && mask != 127) + mask++; + else if (id < im && ss == 1 && mask != 127) + mask++; + else if (id < im && ss == 0 && mask == 0) + ss = 1; + else if (id < im && ss == 0 && mask != 0) + mask--; + } else { /* ......... u-law */ + if (id > im && ss == 1 && mask == 127) { + ss = 0; + mask--; + } else if (id > im && ss == 1 && mask != 127) + mask++; + else if (id > im && ss == 0 && mask != 0) + mask--; + else if (id < im && ss == 1 && mask != 0) + mask--; + else if (id < im && ss == 0 && mask == 127) + ss = 1; + else if (id < im && ss == 0 && mask != 127) + mask++; + } + + *sd = mask + (ss << 7); + +} + +/* ........................ end of G726_sync() ........................ */ + +/* ************************* END OF G726.C ************************* */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,129 @@ +/* + ============================================================================ + File: G726.H 28-Feb-1991 (18:00:00) + ============================================================================ + + UGST/ITU-T G726 MODULE + + GLOBAL FUNCTION PROTOTYPES + + History: + 28.Feb.92 v1.0 First version + 06.May.94 v2.0 Smart prototypes that work with many compilers + ============================================================================ +*/ +#ifndef G726_defined +#define G726_defined 200 + +/* Smart function prototypes: for [ag]cc, VaxC, and [tb]cc */ +#if !defined(ARGS) +#if (defined(__STDC__) || defined(VMS) || defined(__DECC) || defined(MSDOS) || defined(__MSDOS__)) || defined (__CYGWIN__) || defined (_MSC_VER) +#define ARGS(s) s +#else +#define ARGS(s) () +#endif +#endif + + +/* State for G726 encoder and decoder */ +typedef struct { + short sr0, sr1; /* Reconstructed signal with delays 0 and 1 */ + short a1r, a2r; /* Triggered 2nd order predictor coeffs. */ + short b1r; /* Triggered 6nd order predictor coeffs */ + short b2r; + short b3r; + short b4r; + short b5r; + short b6r; + short dq5; /* Quantized difference signal with delays 5 + * to 0 */ + short dq4; + short dq3; + short dq2; + short dq1; + short dq0; + short dmsp; /* Short term average of the F(I) sequence */ + short dmlp; /* Long term average of the F(I) sequence */ + short apr; /* Triggered unlimited speed control + * parameter */ + short yup; /* Fast quantizer scale factor */ + short tdr; /* Triggered tone detector */ + short pk0, pk1; /* sign of dq+sez with delays 0 and 1 */ + long ylp; /* Slow quantizer scale factor */ +} G726_state; + +#ifdef VAXC +# define SHORT short +#else +# define SHORT int +#endif + +/* Function prototypes */ +void G726_encode ARGS((unsigned char *inp_buf, short *out_buf, long smpno, + char *law, SHORT rate, SHORT r, G726_state * state)); +void G726_decode ARGS((short *inp_buf, unsigned char *out_buf, long smpno, + char *law, SHORT rate, SHORT r, G726_state * state)); +void G726_expand ARGS((short *s, char *law, short *sl)); +void G726_subta ARGS((short *sl, short *se, short *d)); +void G726_log ARGS((short *d, short *dl, short *ds)); +void G726_quan ARGS((SHORT rate, short *dln, short *ds, short *i)); +void G726_subtb ARGS((short *dl, short *y, short *dln)); +void G726_adda ARGS((short *dqln, short *y, short *dql)); +void G726_antilog ARGS((short *dql, short *dqs, short *dq)); +void G726_reconst ARGS((SHORT rate, short *i, short *dqln, short *dqs)); +void G726_delaya ARGS((short *r, short *x, short *y)); +void G726_delayb ARGS((short *r, short *x, short *y)); +void G726_delayc ARGS((short *r, long *x, long *y)); +void G726_delayd ARGS((short *r, short *x, short *y)); +void G726_filtd ARGS((short *wi, short *y, short *yut)); +void G726_filte ARGS((short *yup, long *yl, long *ylp)); +void G726_functw ARGS((SHORT rate, short *i, short *wi)); +void G726_limb ARGS((short *yut, short *yup)); +void G726_mix ARGS((short *al, short *yu, long *yl, short *y)); +void G726_filta ARGS((short *fi, short *dms, short *dmsp)); +void G726_filtb ARGS((short *fi, short *dml, short *dmlp)); +void G726_filtc ARGS((short *ax, short *ap, short *app)); +void G726_functf ARGS((SHORT rate, short *i, short *fi)); +void G726_lima ARGS((short *ap, short *al)); +void G726_subtc ARGS((short *dmsp, short *dmlp, short *tdp, short *y, + short *ax)); +void G726_triga ARGS((short *tr, short *app, short *apr)); +void G726_accum ARGS((short *wa1, short *wa2, short *wb1, short *wb2, + short *wb3, short *wb4, short *wb5, short *wb6, short *se, + short *sez)); +void G726_addb ARGS((short *dq, short *se, short *sr)); +void G726_addc ARGS((short *dq, short *sez, short *pk0, short *sigpk)); +void G726_floata ARGS((short *dq, short *dq0)); +void G726_floatb ARGS((short *sr, short *sr0)); +void G726_fmult ARGS((short *An, short *SRn, short *WAn)); +void G726_limc ARGS((short *a2t, short *a2p)); +void G726_limd ARGS((short *a1t, short *a2p, short *a1p)); +void G726_trigb ARGS((short *tr, short *ap, short *ar)); +void G726_upa1 ARGS((short *pk0, short *pk1, short *a1, short *sigpk, + short *a1t)); +void G726_upa2 ARGS((short *pk0, short *pk1, short *pk2, short *a2, + short *a1, short *sigpk, short *a2t)); +void G726_upb ARGS((SHORT rate, short *u, short *b, short *dq, + short *bp)); +void G726_xor ARGS((short *dqn, short *dq, short *u)); +void G726_tone ARGS((short *a2p, short *tdp)); +void G726_trans ARGS((short *td, long *yl, short *dq, short *tr)); +void G726_compress ARGS((short *sr, char *law, short *sp)); +void G726_sync ARGS((SHORT rate, short *i, short *sp, short *dlnx, + short *dsx, char *law, short *sd)); + +/* Definitions for better user interface (?!) */ +#ifndef IS_LOG +# define IS_LOG 0 +#endif + +#ifndef IS_LIN +# define IS_LIN 1 +#endif + +#ifndef IS_ADPCM +# define IS_ADPCM 2 +#endif + +#endif +/* .......................... End of G726.H ........................... */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726.rme --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726.rme Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,52 @@ + + U G S T + + Read me file for G726 module + (24/Jan/2000) + + ============================================================= + 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". + ============================================================= + +The UGST G726 module, version 2.0 (24/Jan/2000) is constituted by the +following files: + +General: +~~~~~~~~ +g726.rme: ......... Read-me file for the G.726 module (this file) +readme.ts: ........ Short description of the test sequences - not included! +cvt_h_b.c: ........ Program that convert from the Hex-ASCII format of the + ITU-T G.726 test sequences to binary, 16-bit right + oriented files. + +C program code +~~~~~~~~~~~~~~ +g726.c .......... G726 module itself; needs the prototypes in g726.h. +g726.h .......... prototypes and definitions needed by the G726 module. + +Demos: +~~~~~~ +g726demo.c ...... Demonstration program for the G726 module; needs the files + g726.c and ugstdemo.h in the current directory. Operates + at a given fixed rate. +vbr-g726.c ...... Demonstration program for the G726 module; needs the files + g726.c and ugstdemo.h in the current directory. Operates + at a given range of rate (e.g, 32, 16, 16-32, 16-24, etc). +ugstdemo.h ...... prototypes and definitions needed by UGST demo programs. + +Makefiles +~~~~~~~~~ +Makefiles have been provided for automatic build-up of the executable program +and to process the test sequences, WHEN made available by the user and left +on the subdirectory "bin": +make-vms.com: ... DCL for VAX/VMS Vax-cc compiler or the VMS port of gcc +makefile.cl: .... make file for MS Visual C compiler +makefile.tcc: ... make file for MSDOS Borland [bt]cc +makefile.djc: ... make file for MSDOS port of gcc +makefile.unx: ... make file for Unix, using either cc, acc (Sun), or gcc + +-- -- diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726_rfc3551.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726_rfc3551.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,134 @@ +/* g726_rfc3551.c + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * Author: Andre Adrian + */ + + +/* RFC3551 + + name of sampling default + encoding sample/frame bits/sample rate ms/frame ms/packet + __________________________________________________________________ + G726-40 sample 5 8,000 20 + G726-32 sample 4 8,000 20 + G726-24 sample 3 8,000 20 + G726-16 sample 2 8,000 20 + + Applications MUST + determine the encoding type of packed codewords from the RTP payload + identifier. + + the first codeword is placed into the first octet + such that the least significant bit of the codeword aligns with the + least significant bit in the octet, the second codeword is then + packed so that its least significant bit coincides with the least + significant unoccupied bit in the octet. When a complete codeword + cannot be placed into an octet, the bits overlapping the octet + boundary are placed into the least significant bits of the next + octet. Packing MUST end with a completely packed final octet. The + number of codewords packed will therefore be a multiple of 8, 2, 8, + and 4 for G726-40, G726-32, G726-24, and G726-16, respectively. An + example of the packing scheme for G726-32 codewords is as shown, + where bit 7 is the least significant bit of the first octet, and bit + A3 is the least significant bit of the first codeword: + + 0 1 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + |B B B B|A A A A|D D D D|C C C C| ... + |0 1 2 3|0 1 2 3|0 1 2 3|0 1 2 3| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + + An example of the packing scheme for G726-24 codewords follows, where + again bit 7 is the least significant bit of the first octet, and bit + A2 is the least significant bit of the first codeword: + + 0 1 2 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + |C C|B B B|A A A|F|E E E|D D D|C|H H H|G G G|F F| ... + |1 2|0 1 2|0 1 2|2|0 1 2|0 1 2|0|0 1 2|0 1 2|0 1| + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + + PT encoding media type clock rate channels + name (Hz) + ___________________________________________________ + dyn G726-40 A 8,000 1 + dyn G726-32 A 8,000 1 + dyn G726-24 A 8,000 1 + dyn G726-16 A 8,000 1 + +*/ + +#include +#include "g711.h" +#include "g726.h" + +/* G.726 subset: 32kBit/s, A-law */ + +static void g726pack(Byte *packed, short *in, int cnt) +{ + int i; + for (i = 0; i <= cnt; i += 2, ++packed, ++in) { + *packed = (*in & 0xF); + ++in; + *packed += (*in & 0xF) * 16; + } +} + +static void g726unpack(short *out, Byte *packed, int cnt) +{ + int i; + for (i = 0; i <= cnt; i += 2, ++packed, ++out) { + *out = (*packed & 0xF); + ++out; + *out = (*packed & 0xF0) / 16; + } +} + +void g726_initEncode(G726_state *encoder_state) +{ + memset(encoder_state, 0, sizeof(G726_state)); +} + +void g726_initDecode(G726_state *decoder_state) +{ + memset(decoder_state, 0, sizeof(G726_state)); +} + +short g726_encode( /* (o) Number of bytes encoded */ + G726_state *state, /* (i/o) Encoder instance */ + unsigned char *encoded_data, /* (o) The encoded bytes */ + short *inp_buf /* (i) The signal block to encode */ + ) +{ + unsigned char inpb_buf[20*8]; + short out_buf[20*8]; + static char law[] = "1"; + + alaw_compress(20*8, inp_buf, inpb_buf); + G726_encode(inpb_buf, out_buf, 20*8, law, 4, 0, state); + g726pack(encoded_data, out_buf, 20*8); + + return 20*8/2; +} + +short g726_decode( /* (o) Number of decoded samples */ + G726_state *state, /* (i/o) Decoder instance */ + short *decoded_data, /* (o) Decoded signal block */ + unsigned char *encoded_data, /* (i) Encoded bytes */ + short mode /* (i) 0=PL, 1=Normal */ + ) +{ + short inp_buf[20*8]; + unsigned char outb_buf[20*8]; + static char law[] = "1"; + + g726unpack(inp_buf, encoded_data, 20*8); + G726_decode(inp_buf, outb_buf, 20*8, law, 4, 0, state); + alaw_expand(20*8, outb_buf, decoded_data); + + return 20*8; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726_rfc3551.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726_rfc3551.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,25 @@ +/* g726_rfc3551.c + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * Author: Andre Adrian + */ + + +void g726_initEncode(G726_state *encoder_state); + +short g726_encode( /* (o) Number of bytes encoded */ + G726_state *state, /* (i/o) Encoder instance */ + unsigned char *encoded_data, /* (o) The encoded bytes */ + short *inp_buf /* (i) The signal block to encode */ + ); + +void g726_initDecode(G726_state *decoder_state); + +short g726_decode( /* (o) Number of decoded samples */ + G726_state *state, /* (i/o) Decoder instance */ + short *decoded_data, /* (o) Decoded signal block */ + unsigned char *encoded_data, /* (i) Encoded bytes */ + short mode /* (i) 0=PL, 1=Normal */ + ); + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726_test.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726_test.sh Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,3 @@ + +./vbr-g726 -q -q -law l ../tv2/voice.raw voicvbrl.tst +diff voicvbrl.tst ../tv2/voice.g726.raw diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/g726demo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/g726demo.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,392 @@ +/* 21/Mar/2000 V1.2 + ============================================================================ + + G726DEMO.C + ~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Demonstration program for UGST/ITU-T G.726 module (the same as the Blue + Book G.726). Takes the input file and processes by the G.726 codec, + depending on user's option: for encoding, input must be in either A + or mu law (G711), for decoding, in ADPCM format. The modules called have + been originally written in Fortran, and were translated into C by the + converter f2c, version of October 15, 1990 at 19:58:17. + + Input data is supposed to be aligned at word boundaries, i.e., + organized in 16-bit words, following the operating system normal + organization (low-byte first for VMS and DOS; high byte first + for most Unix systems). G711 compressed data is supposed to be + in the 8 LEAST significant bits of the word and the ADPCM data + is in the LEAST 5 bits. Both are without sign extension. + + Output data will be generated in the same format as decribed + above for the input data. + + Usage: + ~~~~~~ + $ G726demo [-options] Law Transf Rate InpFile OutFile + [BlockSize [1stBlock [NoOfBlocks [Reset]]]] + where: + Law is the law desired (either A or u) + Transf is the desired conversion on the input file: + [lolo], (A/u)log -> ADPCM -> (A/u) log + [load], (A/u)log -> ADPCM + [adlo], ADPCM -> (A/u) log + Rate is the number of ADPCM bits per sample: + [5],[40] -> 5 bits per sample (40 kbit/s) + [4],[32] -> 4 bits per sample (32 kbit/s) + [3],[24] -> 3 bits per sample (24 kbit/s) + [2],[16] -> 2 bits per sample (16 kbit/s) + InpFile is the name of the file to be processed; + OutFile is the name with the processed data; + BlockSize is the block size, in number of samples + 1stBlock is the number of the first block of the input file + to be processed; + NoOfBlocks is the number of blocks to be processed, starting on + block "1stBlock" + Reset is the optional reset. If specified as 1, the + coder and decoder will be reset at the very beginning of + the processings. If 0, the processing will start with + the variables at a unknown state. It defaults to 1 + (reset ON). + Options: + -noreset don't apply reset to the encoder/decoder + -?/-help print help message + + + Example: + $ G726demo u lolo 4 voice.ref voice.rel 256 3 45 *OR* + $ G726demo u lolo 32 voice.ref voice.rel 256 3 45 + + The command above takes the samples in file "voice.ref", already + in mu law format, processes the data through the G726 encoder + and decoder at a rate of 32 bkit/s, saving them into the file + "voice.rel". The processing starts at block 3 for 45 blocks, + each block being 256 samples wide. + + Original authors: + ~~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto EMail : simao@cpqd.ansp.br (32k) + Fernando Tofolli Queiroz EMail : tdfernan@cpqd.ansp.br (extension) + + CPqD/Telebras Rd. Mogi Mirim-Campinas Km.118 + DDS/Pr.11 13.088-061 - Campinas - SP (Brazil) + + History: + ~~~~~~~~ + 28/Feb/1994 v1.0 Release of 1st version of this demo program + based on the g721demo of the STL92. G.726 + functionality added by Fernando Toffoli Queiroz + ; usage routine and + portability tests by Simao. + 22/Feb/1996 v1.1 Removed compilation warnings, included headers as + suggested by Kirchherr (FI/DBP Telekom) to run under + OpenVMS/AXP + 21/Mar/2000 v1.2 Changed memory allocation of floating point buffers + tmp_buf[], inp_buf[] and out_buf[] from static to + dynamic, to prevent memory invasion + when block sizes larger than 256 are specified. + Corrected bug that made incorrect calculation on + total number of blocks to process when the block + size is not a multiple of the file + size. + +============================================================================ +*/ + + +/* ..... General definitions for UGST demo programs ..... */ +#include "ugstdemo.h" + +/* ..... General include ..... */ +#include +#include +#include +#include +#include + +#if defined(VMS) +#include +#else /* Unix/DOS */ +#include +#endif + +/* ..... G.726 module as include functions ..... */ +#include "g726.h" + +/* + ------------------------------------------------------------------------- + void display_usage(void); + ~~~~~~~~~~~~~~~~~~ + Display proper usage for the demo program. Generated automatically from + program documentation. + + History: + ~~~~~~~~ + 8.Mar.94 v1.0 Created. + ------------------------------------------------------------------------- +*/ +#define P(x) printf x +void display_usage() +{ + P(("G726DEMO - Version 1.2 of 21/Mar/2000 \n\n")); + + P(("> Description:\n")); + P((" Demonstration program for UGST/ITU-T G.726 module. Takes the\n")); + P((" input file and processes by the G.726 codec,\n")); + P((" depending on user's option: for encoding, input must be in\n")); + P((" either A or mu law (G711), for decoding, in ADPCM format. The\n")); + P((" modules called have been originally written in Fortran, and were\n")); + P((" translated into C by the converter f2c, version of October 15,1990\n")); + P(("\n")); + P((" Input data is supposed to be aligned at word boundaries, i.e.,\n")); + P((" organized in 16-bit words, following the operating system normal\n")); + P((" organization (low-byte first for VMS and DOS; high byte first\n")); + P((" for most Unix systems). G711 compressed data is supposed to be\n")); + P((" in the 8 LEAST significant bits of the word and the ADPCM data\n")); + P((" is in the LEAST 5 bits. Both are without sign extension.\n")); + P(("\n")); + P((" Output data will be generated in the same format as decribed\n")); + P((" above for the input data.\n")); + P(("\n")); + + P(("> Usage:\n")); + P(("$ G726demo [-options] Law Transf Rate InpFile OutFile \n")); + P((" [BlockSize [1stBlock [NoOfBlocks [Reset]]]]\n")); + P((" where:\n")); + P((" Law is the law desired (either A or u)\n")); + P((" Transf is the desired conversion on the input file:\n")); + P((" [lolo], (A/u)log -> ADPCM -> (A/u) log\n")); + P((" [load], (A/u)log -> ADPCM \n")); + P((" [adlo], ADPCM -> (A/u) log\n")); + P((" Rate is the number of ADPCM bits per sample:\n")); + P((" [5],[40] -> 5 bits per sample (40 kbit/s)\n")); + P((" [4],[32] -> 4 bits per sample (32 kbit/s)\n")); + P((" [3],[24] -> 3 bits per sample (24 kbit/s)\n")); + P((" [2],[16] -> 2 bits per sample (16 kbit/s)\n")); + P((" InpFile is the name of the file to be processed;\n")); + P((" OutFile is the name with the processed data;\n")); + P((" BlockSize is the block size, in number of samples\n")); + P((" 1stBlock is the number of the first block of the input file\n")); + P((" to be processed;\n")); + P((" NoOfBlocks is the number of blocks to be processed, starting on\n")); + P((" block \"1stBlock\"\n")); + P((" Reset is the optional reset. If specified as 1, the\n")); + P((" coder and decoder will be reset at the very\n")); + P((" beginning of the processings. If 0, the\n")); + P((" processing will start with the variables at a\n")); + P((" unknown state. It defaults to 1 (reset ON). \n")); + P((" Options: \n")); + P((" -noreset don't apply reset to the encoder/decoder\n")); + P((" -? or -help print this help message\n")); + P(("\n")); + + /* Quit program */ + exit(-128); +} + +#undef P +/* .................... End of display_usage() ........................... */ + + +/* + ************************************************************************** + *** *** + *** Demo-Program for testing the correct implementation *** + *** and to show how to use the programs *** + *** *** + ************************************************************************** +*/ +int main(argc, argv) +int argc; +char *argv[]; +{ + G726_state encoder_state, decoder_state; + long N = 256, N1 = 1, N2 = 0, cur_blk, smpno; + short *tmp_buf, *inp_buf, *out_buf, reset = 1; + short inp_type, out_type, rate; + + /* Progress indication */ + static char quiet = 0, funny[9] = "|/-\\|/-\\"; + +/* File variables */ + char FileIn[80], FileOut[80], law[4], lilo[8]; + FILE *Fi, *Fo; + int inp, out; + long start_byte; +#ifdef VMS + char mrs[15]; +#endif + +/* + * ......... PARAMETERS FOR PROCESSING ......... + */ + + /* GETTING OPTIONS */ + + if (argc < 2) + display_usage(); + else { + while (argc > 1 && argv[1][0] == '-') + if (strcmp(argv[1], "-noreset") == 0) { + /* No reset */ + reset = 0; + + /* Update argc/argv to next valid option/argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-q") == 0) { + /* Don't print progress indicator */ + quiet = 1; + + /* Move argv over the option to the next argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-?") == 0 + || strcmp(argv[1], "-help") == 0) { + /* Print help */ + display_usage(); + } else { + fprintf(stderr, + "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); + display_usage(); + } + } + + /* Now get regular parameters */ + GET_PAR_S(1, "_Law (A,u): ................... ", law); + GET_PAR_S(2, "_Operation (lolo,load,adlo): .. ", lilo); + GET_PAR_I(3, "_Rate or bits/ADPCM sample: ... ", rate); + GET_PAR_S(4, "_Input File: .................. ", FileIn); + GET_PAR_S(5, "_Output File: ................. ", FileOut); + FIND_PAR_L(6, "_Block Size: .................. ", N, 256); + FIND_PAR_L(7, "_Starting Block: .............. ", N1, 1); + FIND_PAR_L(8, "_No. of Blocks: ............... ", N2, 0); + FIND_PAR_I(9, "_Reset (YES=1, NO=0): ......... ", reset, 1); + + /* Find starting byte in file */ + start_byte = sizeof(short) * (long) (--N1) * (long) N; + + /* Check if is to process the whole file */ + if (N2 == 0) { + struct stat st; + + /* ... find the input file size ... */ + stat(FileIn, &st); + N2 = ceil((st.st_size - start_byte) / (double) (N * sizeof(short))); + } + + /* Classification of the conversion desired */ + inp_type = toupper(lilo[1]) == 'O' ? IS_LOG : IS_ADPCM; + out_type = toupper(lilo[3]) == 'O' ? IS_LOG : IS_ADPCM; + if ((out_type == IS_ADPCM) && (inp_type == IS_ADPCM)) + HARAKIRI("Bad conversion chosen (lolo,load,adlo)! Aborted...\n", 8); + + /* Classification of law */ + if (toupper(law[0]) == (char) 'A') + law[0] = '1'; + else if (toupper(law[0]) == (char) 'U') + law[0] = '0'; + else + HARAKIRI(" Invalid law (A or u)! Aborted...\n", 7); + + /* Classification of rate */ + if (rate > 5) { + if (rate == 40) + rate = 5; + else if (rate == 32) + rate = 4; + else if (rate == 24) + rate = 3; + else if (rate == 16) + rate = 2; + else { + HARAKIRI(" Invalid rate (5/4/3/2) or (40/32/24/16)! Aborted...\n", + 9); + } + } + +/* + * ...... MEMORY ALLOCATION ......... + */ + + if ((inp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((out_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((tmp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + +/* + * ......... FILE PREPARATION ......... + */ + + /* Opening input file; abort if there's any problem */ + if ((Fi = fopen(FileIn, "rb")) == NULL) + KILL(FileIn, 2); + inp = fileno(Fi); + + /* Creates output file */ +#ifdef VMS + sprintf(mrs, "mrs=%d", 512); +#endif + if ((Fo = fopen(FileOut, WB)) == NULL) + KILL(FileOut, 3); + out = fileno(Fo); + + /* Move pointer to 1st block of interest */ + if (fseek(Fi, start_byte, 0) < 0l) + KILL(FileIn, 4); + +/* + * ......... PROCESSING ACCORDING TO ITU-T G.726 ......... + */ + + for (cur_blk = 0; cur_blk < N2; cur_blk++) { + /* Print progress flag */ + if (!quiet) + fprintf(stderr, "%c\r", funny[cur_blk % 8]); + + /* Read a block of samples */ + if ((smpno = fread(inp_buf, sizeof(short), N, Fi)) < 0) + KILL(FileIn, 5); + + /* Check if reset is needed */ + reset = (reset == 1 && cur_blk == 0) ? 1 : 0; + + /* Carry out the desired operation */ + if (inp_type == IS_LOG && out_type == IS_ADPCM) { + G726_encode(inp_buf, out_buf, smpno, law, rate, reset, + &encoder_state); + } else if (inp_type == IS_ADPCM && out_type == IS_LOG) { + G726_decode(inp_buf, out_buf, smpno, law, rate, reset, + &decoder_state); + } else if (inp_type == IS_LOG && out_type == IS_LOG) { + G726_encode(inp_buf, tmp_buf, smpno, law, rate, reset, + &encoder_state); + G726_decode(tmp_buf, out_buf, smpno, law, rate, reset, + &decoder_state); + } + + /* Write ADPCM output word */ + if ((smpno = fwrite(out_buf, sizeof(short), smpno, Fo)) < 0) + KILL(FileOut, 6); + } + +/* + * ......... FINALIZATIONS ......... + */ + + /* Close input and output files */ + fclose(Fi); + fclose(Fo); + + /* Exit with success for non-vms systems */ +#ifndef VMS + return (0); +#endif +} + +/* ............................. end of main() ............................. */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/gen-lic.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/gen-lic.txt Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,162 @@ + + + ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE + + + + This "General Public License" is published in the Annex 1 of the + ITU-T Recommendation on "SOFTWARE TOOLS FOR HOMOGENITY OF RESULTS + IN THE STANDARDIZATION PROCESS OF SPEECH AND AUDIO CODERS", + approved in Geneva, 2000. + + + TERMS AND CONDITIONS + + 1. This License Agreement applies to any module or other work + related to the ITU-T Software Tool Library, and developed by the + User's Group on Software Tools. The "Module", below, refers to any + such module or work, and a "work based on the Module" means either + the Module or any work containing the Module or a portion of it, + either verbatim or with modifications. Each licensee is addressed + as "you". + + 2. You may copy and distribute verbatim copies of the Module's + source code as you receive it, in any medium, provided that you: + - conspicuously and appropriately publish on each copy an appropriate + copyright notice and disclaimer of warranty; + - keep intact all the notices that refer to this General Public + License and to the absence of any warranty; and + - give any other recipients of the Module a copy of this General + Public License along with the Module. + You may charge a fee for the physical act of transferring a copy. + + 3. You may modify your copy or copies of the Module or any portion + of it, and copy and distribute such modifications under the terms + of Paragraph 1 above, provided that you also do the following: + + o cause the modified files to carry prominent notices stating + that you changed the files and the date of any change; and + + o cause the whole of any work that you distribute or publish, + that in whole or in part contains the Module or any part + thereof, either with or without modifications, to be licensed + at no charge to all third parties under the terms of this + General Public License (except that you may choose to grant + warranty protection to some or all third parties, at your + option). + + o If the modified module normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the simplest and most usual way, to print or + display an announcement including an appropriate copyright + notice and a notice that there is no warranty (or else, saying + that you provide a warranty) and that users may redistribute + the module under these conditions, and telling the user how to + view a copy of this General Public License. + + You may charge a fee for the physical act of transferring a copy, + and you may at your option offer warranty protection in exchange + for a fee. + + Mere aggregation of another independent work with the Module (or + its derivative) on a volume of a storage or distribution medium + does not bring the other work under the scope of these terms. + + 4. You may copy and distribute the Module (or a portion or + derivative of it, under Paragraph 2) in object code or executable + form under the terms of Paragraphs 1 and 2 above provided that you + also do one of the following: + + o accompany it with the complete corresponding machine- + readable source code, which must be distributed under the terms + of Paragraphs 1 and 2 above; or, + + o accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal + charge for the cost of distribution) a complete machine- + readable copy of the corresponding source code, to be + distributed under the terms of Paragraphs 1 and 2 above; or, + + o accompany it with the information you received as to where + the corresponding source code may be obtained. (This + alternative is allowed only for noncommercial distribution and + only if you received the module in object code or executable + form alone.) + + Source code for a work means the preferred form of the work for + making modifications to it. For an executable file, complete + source code means all the source code for all modules it contains; + but, as a special exception, it need not include source code for + modules which are standard libraries that accompany the operating + system on which the executable file runs, or for standard header + files or definitions files that accompany that operating system. + + 5. You may not copy, modify, sublicense, distribute or transfer + the Module except as expressly provided under this General Public + License. Any attempt otherwise to copy, modify, sublicense, + distribute or transfer the Module is void, and will automatically + terminate your rights to use the Module under this License. + However, parties who have received copies, or rights to use copies, + from you under this General Public License will not have their + licenses terminated so long as such parties remain in full + compliance. + + 6. By copying, distributing or modifying the Module (or any work + based on the Module) you indicate your acceptance of this license + to do so, and all its terms and conditions. + + 7. Each time you redistribute the Module (or any work based on the + Module), the recipient automatically receives a license from the + original licensor to copy, distribute or modify the Module subject + to these terms and conditions. You may not impose any further + restrictions on the recipients' exercise of the rights granted + herein. + + 8. The ITU-T may publish revised and/or new versions of this + General Public License from time to time. Such new versions will + be similar in spirit to the present version, but may differ in + detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the + Module specifies a version number of the license which applies to + it and "any later version", you have the option of following the + terms and conditions either of that version or of any later version + published by the ITU-T. If the Module does not specify a version + number of the license, you may choose any version ever published by + the ITU-T. + + 9. If you wish to incorporate parts of the Module into other free + modules whose distribution conditions are different, write to the + author to ask for permission. For software which is copyrighted by + the ITU-T, write to the ITU-T Secretariat; exceptions may be made + for this. This decision will be guided by the two goals of + preserving the free status of all derivatives of this free software + and of promoting the sharing and reuse of software generally. + + + NO WARRANTY + + 10. BECAUSE THE MODULE IS LICENSED FREE OF CHARGE, THERE IS NO + WARRANTY FOR THE MODULE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. + EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS + AND/OR OTHER PARTIES PROVIDE THE MODULE "AS IS" WITHOUT WARRANTY OF + ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE MODULE IS WITH YOU. SHOULD THE MODULE PROVE + DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR + OR CORRECTION. + + 11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN + WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY + MODIFY AND/OR REDISTRIBUTE THE MODULE AS PERMITTED ABOVE, BE LIABLE + TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR + CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE + THE MODULE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING + RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR + A FAILURE OF THE MODULE TO OPERATE WITH ANY OTHER MODULES), EVEN IF + SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/make-vms.com --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/make-vms.com Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,437 @@ +$!----------------------------------------------------------------------------- +$! VMS DCL for compiling and testing the G.726 implementation +$! The executable must be defined by variable G726 below. +$! +$! Usage: +$! @make-vms +$! or +$! @make-vms target +$! where target is +$! cc: compile usando Vax-C +$! gcc: compile usando VAX/VMS gcc +$! clean: delete object and test files +$! test: process reset vectors for all rates +$! test16: process reset vectors for 16 kbit/s +$! test24: process reset vectors for 24 kbit/s +$! test32: process reset vectors for 32 kbit/s +$! test40: process reset vectors for 40 kbit/s +$! comp: compare processed reset vectors with reference for all rates +$! comp16: compare processed reset vectors with reference for 16 kbit/s +$! comp24: compare processed reset vectors with reference for 24 kbit/s +$! comp32: compare processed reset vectors with reference for 32 kbit/s +$! comp40: compare processed reset vectors with reference for 40 kbit/s +$! +$! Implemented by -- 01.May.94 +$!----------------------------------------------------------------------------- +$ G726 := "g726demo" +$ DIFF := "cf -q" +$ RM := "delete" +$ +$ TEST_VECTORS := "*.%16.*,*.%24.*,*.%32.*,*.%40.*,*.rec.*" +$ G726_OBJ := "g726demo.obj.,g726.obj." +$ g726demo:==$"''f$environment(""DEFAULT"")'"g726demo +$ +$! General link options +$!----------------------------- +$ link_opt := "" +$ +$! Choose a C compiler +$!----------------------------- +$! > this is for Vax-C - the default +$ if ("''p1'".nes."GCC") +$ then +$ cc := "cc /include=[-.utl]" +$! +$! > these are for GNU-C +$ else +$ CC := "gcc -I../utl" +$ libs := ",GNU_CC:[000000]GCCLIB/LIB,SYS$LIBRARY:VAXCRTL/LIB" +$ endif +$ +$! General cc options +$!----------------------------- +$ CC_OPT := "" +$ +$! Process User's option +$ if ("''p1'".nes."") +$ then +$ goto 'p1' +$ else +$ goto all +$ endif +$ +$all: +$anyway: +$cc: +$gcc: +$ goto g726demo +$ exit +$ +$ +$clean: +$ 'RM' 'TEST_VECTORS','G726_OBJ' +$exit +$ +$g726demo: +$ 'CC' 'CC_OPT' g726.c +$ 'CC' 'CC_OPT' g726demo.c +$ LINK 'LINK_OPT' 'G726_OBJ''LIBS' +$ g726demo:==$"''f$environment(""DEFAULT"")'"g726demo +$ exit +$ +$ +$test: ! clean test16 test24 test32 test40 +$test16: +$! +$! Process ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'G726' a load 16 bin/nrm.a nrm.a16 256 1 64 +$ 'G726' a load 16 bin/ovr.a ovr.a16 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'G726' a adlo 16 bin/rn16fa.i rn16fa.rec 256 1 64 +$ 'G726' a adlo 16 bin/rv16fa.i rv16fa.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM 16kbit/s -> mu law output +$! +$ 'G726' u adlo 16 bin/rn16fa.i rn16fx.rec 256 1 64 +$ 'G726' u adlo 16 bin/rv16fa.i rv16fx.rec 256 1 8 +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'G726' u load 16 bin/nrm.m nrm.m16 256 1 64 +$ 'G726' u load 16 bin/ovr.m ovr.m16 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'G726' u adlo 16 bin/rn16fm.i rn16fm.rec 256 1 64 +$ 'G726' u adlo 16 bin/rv16fm.i rv16fm.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM 16kbit/s -> A law output +$! +$ 'G726' a adlo 16 bin/rn16fm.i rn16fc.rec 256 1 64 +$ 'G726' a adlo 16 bin/rv16fm.i rv16fc.rec 256 1 8 +$! +$! +$! Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'G726' a adlo 16 bin/i16 ri16fa.rec 256 1 64 +$ 'G726' u adlo 16 bin/i16 ri16fm.rec 256 1 64 +$ if ("''p1'".nes."TEST") then exit +$ +$test24: +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'G726' a load 24 bin/nrm.a nrm.a24 256 1 64 +$ 'G726' a load 24 bin/ovr.a ovr.a24 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'G726' a adlo 24 bin/rn24fa.i rn24fa.rec 256 1 64 +$ 'G726' a adlo 24 bin/rv24fa.i rv24fa.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM 24kbit/s -> mu law output +$! +$ 'G726' u adlo 24 bin/rn24fa.i rn24fx.rec 256 1 64 +$ 'G726' u adlo 24 bin/rv24fa.i rv24fx.rec 256 1 8 +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'G726' u load 24 bin/nrm.m nrm.m24 256 1 64 +$ 'G726' u load 24 bin/ovr.m ovr.m24 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'G726' u adlo 24 bin/rn24fm.i rn24fm.rec 256 1 64 +$ 'G726' u adlo 24 bin/rv24fm.i rv24fm.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM 24kbit/s -> A law output +$! +$ 'G726' a adlo 24 bin/rn24fm.i rn24fc.rec 256 1 64 +$ 'G726' a adlo 24 bin/rv24fm.i rv24fc.rec 256 1 8 +$! +$! +$! Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'G726' a adlo 24 bin/i24 ri24fa.rec 256 1 64 +$ 'G726' u adlo 24 bin/i24 ri24fm.rec 256 1 64 +$ if ("''p1'".nes."TEST") then exit +$ +$test32: +$! +$! Process ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'G726' a load 32 bin/nrm.a nrm.a32 256 1 64 +$ 'G726' a load 32 bin/ovr.a ovr.a32 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'G726' a adlo 32 bin/rn32fa.i rn32fa.rec 256 1 64 +$ 'G726' a adlo 32 bin/rv32fa.i rv32fa.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM 32kbit/s -> mu law output +$! +$ 'G726' u adlo 32 bin/rn32fa.i rn32fx.rec 256 1 64 +$ 'G726' u adlo 32 bin/rv32fa.i rv32fx.rec 256 1 8 +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'G726' u load 32 bin/nrm.m nrm.m32 256 1 64 +$ 'G726' u load 32 bin/ovr.m ovr.m32 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'G726' u adlo 32 bin/rn32fm.i rn32fm.rec 256 1 64 +$ 'G726' u adlo 32 bin/rv32fm.i rv32fm.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM 32kbit/s -> A law output +$! +$ 'G726' a adlo 32 bin/rn32fm.i rn32fc.rec 256 1 64 +$ 'G726' a adlo 32 bin/rv32fm.i rv32fc.rec 256 1 8 +$! +$! +$! Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'G726' a adlo 32 bin/i32 ri32fa.rec 256 1 64 +$ 'G726' u adlo 32 bin/i32 ri32fm.rec 256 1 64 +$ if ("''p1'".nes."TEST") then exit +$ +$test40: +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'G726' a load 40 bin/nrm.a nrm.a40 256 1 64 +$ 'G726' a load 40 bin/ovr.a ovr.a40 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'G726' a adlo 40 bin/rn40fa.i rn40fa.rec 256 1 64 +$ 'G726' a adlo 40 bin/rv40fa.i rv40fa.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM 40kbit/s -> mu law output +$! +$ 'G726' u adlo 40 bin/rn40fa.i rn40fx.rec 256 1 64 +$ 'G726' u adlo 40 bin/rv40fa.i rv40fx.rec 256 1 8 +$! +$! +$! Process ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'G726' u load 40 bin/nrm.m nrm.m40 256 1 64 +$ 'G726' u load 40 bin/ovr.m ovr.m40 256 1 8 +$! +$! Process ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'G726' u adlo 40 bin/rn40fm.i rn40fm.rec 256 1 64 +$ 'G726' u adlo 40 bin/rv40fm.i rv40fm.rec 256 1 8 +$! +$! Process ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM 40kbit/s -> A law output +$! +$ 'G726' a adlo 40 bin/rn40fm.i rn40fc.rec 256 1 64 +$ 'G726' a adlo 40 bin/rv40fm.i rv40fc.rec 256 1 8 +$! +$! +$! Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'G726' a adlo 40 bin/i40 ri40fa.rec 256 1 64 +$ 'G726' u adlo 40 bin/i40 ri40fm.rec 256 1 64 +$ exit +$ +$comp: ! comp16 comp24 comp32 comp40 +$comp16: +$! +$! ================================================================= +$! COMPARISON OF FILES ! +$! ================================================================= +$! +$! Compare ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn16fa.i nrm.a16 256 1 64 +$ 'DIFF' bin/rv16fa.i ovr.a16 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn16fa.o rn16fa.rec 256 1 64 +$ 'DIFF' bin/rv16fa.o rv16fa.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM x kbit/s -> mu law output +$! +$ 'DIFF' bin/rn16fx.o rn16fx.rec 256 1 64 +$ 'DIFF' bin/rv16fx.o rv16fx.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn16fm.i nrm.m16 256 1 64 +$ 'DIFF' bin/rv16fm.i ovr.m16 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn16fm.o rn16fm.rec 256 1 64 +$ 'DIFF' bin/rv16fm.o rv16fm.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM x kbit/s -> A law output +$! +$ 'DIFF' bin/rn16fc.o rn16fc.rec 256 1 64 +$ 'DIFF' bin/rv16fc.o rv16fc.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'DIFF' bin/ri16fa.o ri16fa.rec 256 1 64 +$ 'DIFF' bin/ri16fm.o ri16fm.rec 256 1 64 +$ if ("''p1'".nes."COMP") then exit +$ +$comp24: +$! +$! ================================================================= +$! COMPARISON OF FILES ! +$! ================================================================= +$! +$! Compare ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn24fa.i nrm.a24 256 1 64 +$ 'DIFF' bin/rv24fa.i ovr.a24 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn24fa.o rn24fa.rec 256 1 64 +$ 'DIFF' bin/rv24fa.o rv24fa.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM x kbit/s -> mu law output +$! +$ 'DIFF' bin/rn24fx.o rn24fx.rec 256 1 64 +$ 'DIFF' bin/rv24fx.o rv24fx.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn24fm.i nrm.m24 256 1 64 +$ 'DIFF' bin/rv24fm.i ovr.m24 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn24fm.o rn24fm.rec 256 1 64 +$ 'DIFF' bin/rv24fm.o rv24fm.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM x kbit/s -> A law output +$! +$ 'DIFF' bin/rn24fc.o rn24fc.rec 256 1 64 +$ 'DIFF' bin/rv24fc.o rv24fc.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'DIFF' bin/ri24fa.o ri24fa.rec 256 1 64 +$ 'DIFF' bin/ri24fm.o ri24fm.rec 256 1 64 +$ if ("''p1'".nes."COMP") then exit +$ +$comp32: +$! +$! ================================================================= +$! COMPARISON OF FILES ! +$! ================================================================= +$! +$! Compare ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn32fa.i nrm.a32 256 1 64 +$ 'DIFF' bin/rv32fa.i ovr.a32 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn32fa.o rn32fa.rec 256 1 64 +$ 'DIFF' bin/rv32fa.o rv32fa.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM x kbit/s -> mu law output +$! +$ 'DIFF' bin/rn32fx.o rn32fx.rec 256 1 64 +$ 'DIFF' bin/rv32fx.o rv32fx.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn32fm.i nrm.m32 256 1 64 +$ 'DIFF' bin/rv32fm.i ovr.m32 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn32fm.o rn32fm.rec 256 1 64 +$ 'DIFF' bin/rv32fm.o rv32fm.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM x kbit/s -> A law output +$! +$ 'DIFF' bin/rn32fc.o rn32fc.rec 256 1 64 +$ 'DIFF' bin/rv32fc.o rv32fc.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'DIFF' bin/ri32fa.o ri32fa.rec 256 1 64 +$ 'DIFF' bin/ri32fm.o ri32fm.rec 256 1 64 +$ if ("''p1'".nes."COMP") then exit +$ +$comp40: +$! +$! ================================================================= +$! COMPARISON OF FILES ! +$! ================================================================= +$! +$! Compare ADPCM/ Coder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn40fa.i nrm.a40 256 1 64 +$ 'DIFF' bin/rv40fa.i ovr.a40 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, A law +$! +$ 'DIFF' bin/rn40fa.o rn40fa.rec 256 1 64 +$ 'DIFF' bin/rv40fa.o rv40fa.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! A law input -> ADPCM x kbit/s -> mu law output +$! +$ 'DIFF' bin/rn40fx.o rn40fx.rec 256 1 64 +$ 'DIFF' bin/rv40fx.o rv40fx.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Coder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn40fm.i nrm.m40 256 1 64 +$ 'DIFF' bin/rv40fm.i ovr.m40 256 1 8 +$! +$! Compare ADPCM/ Decoder for normal and overload sequences, mu law +$! +$ 'DIFF' bin/rn40fm.o rn40fm.rec 256 1 64 +$ 'DIFF' bin/rv40fm.o rv40fm.rec 256 1 8 +$! +$! Compare ADPCM/ Cross-decoder for normal and overload sequences, +$! mu law input -> ADPCM x kbit/s -> A law output +$! +$ 'DIFF' bin/rn40fc.o rn40fc.rec 256 1 64 +$ 'DIFF' bin/rv40fc.o rv40fc.rec 256 1 8 +$! +$! +$! Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +$! +$ 'DIFF' bin/ri40fa.o ri40fa.rec 256 1 64 +$ 'DIFF' bin/ri40fm.o ri40fm.rec 256 1 64 +$ exit diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/makefile.cl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/makefile.cl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,585 @@ +#----------------------------------------------------------------------------- +# MS Visual C makefile for compiling and testing the G.726 +# implementation. +# The executable must be defined by variable G726 below. +# History: +# 31.Jan.2000 - Implemented by +# NOTE: you need to get (purchase) the G.726 test vectors from the ITU in +# order to perform the (optional) compliance test. +#----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose compiler. +# ------------------------------------------------ +CC=cl +CC_OPT = -I../utl /Yd /DEBUG + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +G726 = g726demo +VBR = vbr-g726 -q +DIFF = cf -q +RM=rm -f + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# File lists +# ------------------------------------------------ +TEST_VECTORS = *.?16 *.?24 *.?32 *.?40 *.rec + +DEMO_OBJ = g726demo.obj g726.obj +VBR_OBJ = vbr-g726.obj g726.obj g711.obj + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g726demo vbr-g726 + +anyway: clean all + +clean: + $(RM) *.obj + +cleantest: + $(RM) $(TEST_VECTORS) voicvbra.tst voicvbru.tst voicvbrl.tst + $(RM) voice.src voicevbr.arf voicevbr.lrf voicevbr.urf + +veryclean: clean cleantest + $(RM) g726demo.exe vbr-g726.exe + +# ----------------------------------------------------------------------------- +# Generic rules +# ----------------------------------------------------------------------------- +.c.obj: + $(CC) $(CC_OPT) -c $< + +# ----------------------------------------------------------------------------- +# Specific rules +# ----------------------------------------------------------------------------- +vbr-g726: vbr-g726.exe +g726demo: g726demo.exe +vbr-g726.exe: $(VBR_OBJ) + $(CC) -o vbr-g726 $(CC_OPT) $(VBR_OBJ) + +g726demo.exe: $(DEMO_OBJ) + $(CC) -o g726demo $(CC_OPT) $(DEMO_OBJ) + +g726demo.obj: g726demo.c + $(CC) -c $(CC_OPT) -I../g711 g726demo.c + +g726.obj: g726.c + $(CC) -c $(CC_OPT) g726.c + +g711.obj: ../g711/g711.c + $(CC) -c $(CC_OPT) -I../g711 ../g711/g711.c + +vbr-g726.obj: vbr-g726.c + $(CC) -c $(CC_OPT) -I../g711 vbr-g726.c + +# ---------------------------------------- +# Very simple portability test +# ---------------------------------------- +test: test-vbr-quick +proc: proc-vbr-quick +comp: comp-vbr-quick + +test-vbr-quick: proc-vbr-quick comp-vbr-quick +proc-vbr-quick: voice.src + $(VBR) -q -law A -rate 16-24-32-40-32-24 voice.src voicvbra.tst + $(VBR) -q -law l -rate 16-24-32-40-32-24 voice.src voicvbrl.tst + $(VBR) -q -law u -rate 16-24-32-40-32-24 voice.src voicvbru.tst +comp-vbr-quick: voicevbr.arf + $(DIFF) voicvbra.tst voicevbr.arf + $(DIFF) voicvbrl.tst voicevbr.lrf + $(DIFF) voicvbru.tst voicevbr.urf + +voice.src: tst-g726.zip + $(UNZIP) tst-g726.zip voice.src + sb -over voice.src + +voicevbr.arf: tst-g726.zip + $(UNZIP) tst-g726.zip voicevbr.arf voicevbr.lrf voicevbr.urf + swapover voicevbr.arf voicevbr.lrf voicevbr.urf + +# ----------------------------------------------------------------------------- +# Test the implementation for g726demo (compliance) +# In the automatic compliance testing, g726demo.c is verified by test-tv +# For vbr-g726.c, no differences should be observed, since both use g726.c, +# and differ only on the demo logic. For full compliance testing of the +# vbr-g726.c program, use test-tv-vbr +# ----------------------------------------------------------------------------- +test-tv: proc-tv-fix comp-tv +proc-tv-fix: bin/rn16fa.o clean proc16-fix proc24-fix proc32-fix proc40-fix +comp-tv-fix: comp-tv +comp-tv: comp16 comp24 comp32 comp40 + +proc16-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 16 bin/nrm.a nrm.a16 256 1 64 + $(G726) a load 16 bin/ovr.a ovr.a16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 16 bin/rn16fa.i rn16fa.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fa.i rv16fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output +# + $(G726) u adlo 16 bin/rn16fa.i rn16fx.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fa.i rv16fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 16 bin/nrm.m nrm.m16 256 1 64 + $(G726) u load 16 bin/ovr.m ovr.m16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 16 bin/rn16fm.i rn16fm.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fm.i rv16fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s -> A law output +# + $(G726) a adlo 16 bin/rn16fm.i rn16fc.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fm.i rv16fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 16 bin/i16 ri16fa.rec 256 1 64 + $(G726) u adlo 16 bin/i16 ri16fm.rec 256 1 64 + +comp16: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.i nrm.a16 256 1 64 + $(DIFF) bin/rv16fa.i ovr.a16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.o rn16fa.rec 256 1 64 + $(DIFF) bin/rv16fa.o rv16fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn16fx.o rn16fx.rec 256 1 64 + $(DIFF) bin/rv16fx.o rv16fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.i nrm.m16 256 1 64 + $(DIFF) bin/rv16fm.i ovr.m16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.o rn16fm.rec 256 1 64 + $(DIFF) bin/rv16fm.o rv16fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn16fc.o rn16fc.rec 256 1 64 + $(DIFF) bin/rv16fc.o rv16fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri16fa.o ri16fa.rec 256 1 64 + $(DIFF) bin/ri16fm.o ri16fm.rec 256 1 64 + +proc24-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 24 bin/nrm.a nrm.a24 256 1 64 + $(G726) a load 24 bin/ovr.a ovr.a24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 24 bin/rn24fa.i rn24fa.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fa.i rv24fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output +# + $(G726) u adlo 24 bin/rn24fa.i rn24fx.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fa.i rv24fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 24 bin/nrm.m nrm.m24 256 1 64 + $(G726) u load 24 bin/ovr.m ovr.m24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 24 bin/rn24fm.i rn24fm.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fm.i rv24fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s -> A law output +# + $(G726) a adlo 24 bin/rn24fm.i rn24fc.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fm.i rv24fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 24 bin/i24 ri24fa.rec 256 1 64 + $(G726) u adlo 24 bin/i24 ri24fm.rec 256 1 64 + +comp24: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.i nrm.a24 256 1 64 + $(DIFF) bin/rv24fa.i ovr.a24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.o rn24fa.rec 256 1 64 + $(DIFF) bin/rv24fa.o rv24fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn24fx.o rn24fx.rec 256 1 64 + $(DIFF) bin/rv24fx.o rv24fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.i nrm.m24 256 1 64 + $(DIFF) bin/rv24fm.i ovr.m24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.o rn24fm.rec 256 1 64 + $(DIFF) bin/rv24fm.o rv24fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn24fc.o rn24fc.rec 256 1 64 + $(DIFF) bin/rv24fc.o rv24fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri24fa.o ri24fa.rec 256 1 64 + $(DIFF) bin/ri24fm.o ri24fm.rec 256 1 64 + +proc32-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 32 bin/nrm.a nrm.a32 256 1 64 + $(G726) a load 32 bin/ovr.a ovr.a32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 32 bin/rn32fa.i rn32fa.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fa.i rv32fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output +# + $(G726) u adlo 32 bin/rn32fa.i rn32fx.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fa.i rv32fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 32 bin/nrm.m nrm.m32 256 1 64 + $(G726) u load 32 bin/ovr.m ovr.m32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 32 bin/rn32fm.i rn32fm.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fm.i rv32fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s -> A law output +# + $(G726) a adlo 32 bin/rn32fm.i rn32fc.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fm.i rv32fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 32 bin/i32 ri32fa.rec 256 1 64 + $(G726) u adlo 32 bin/i32 ri32fm.rec 256 1 64 + +comp32: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.i nrm.a32 256 1 64 + $(DIFF) bin/rv32fa.i ovr.a32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.o rn32fa.rec 256 1 64 + $(DIFF) bin/rv32fa.o rv32fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn32fx.o rn32fx.rec 256 1 64 + $(DIFF) bin/rv32fx.o rv32fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.i nrm.m32 256 1 64 + $(DIFF) bin/rv32fm.i ovr.m32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.o rn32fm.rec 256 1 64 + $(DIFF) bin/rv32fm.o rv32fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn32fc.o rn32fc.rec 256 1 64 + $(DIFF) bin/rv32fc.o rv32fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri32fa.o ri32fa.rec 256 1 64 + $(DIFF) bin/ri32fm.o ri32fm.rec 256 1 64 + +proc40-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 40 bin/nrm.a nrm.a40 256 1 64 + $(G726) a load 40 bin/ovr.a ovr.a40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 40 bin/rn40fa.i rn40fa.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fa.i rv40fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output +# + $(G726) u adlo 40 bin/rn40fa.i rn40fx.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fa.i rv40fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 40 bin/nrm.m nrm.m40 256 1 64 + $(G726) u load 40 bin/ovr.m ovr.m40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 40 bin/rn40fm.i rn40fm.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fm.i rv40fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s -> A law output +# + $(G726) a adlo 40 bin/rn40fm.i rn40fc.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fm.i rv40fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 40 bin/i40 ri40fa.rec 256 1 64 + $(G726) u adlo 40 bin/i40 ri40fm.rec 256 1 64 + +comp40: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.i nrm.a40 256 1 64 + $(DIFF) bin/rv40fa.i ovr.a40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.o rn40fa.rec 256 1 64 + $(DIFF) bin/rv40fa.o rv40fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn40fx.o rn40fx.rec 256 1 64 + $(DIFF) bin/rv40fx.o rv40fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.i nrm.m40 256 1 64 + $(DIFF) bin/rv40fm.i ovr.m40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.o rn40fm.rec 256 1 64 + $(DIFF) bin/rv40fm.o rv40fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn40fc.o rn40fc.rec 256 1 64 + $(DIFF) bin/rv40fc.o rv40fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri40fa.o ri40fa.rec 256 1 64 + $(DIFF) bin/ri40fm.o ri40fm.rec 256 1 64 + +# +# ---------------------------------------------------------------------------- +# Test the implementation for vbr-g726 (compliance) +# ---------------------------------------------------------------------------- +test-tv-vbr: proc-tv-vbr comp-tv +proc-tv-vbr: bin/rn16fa.o clean proc16-vbr proc24-vbr proc32-vbr proc40-vbr +comp-vbr-tv: comp-tv + +proc16-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 16 bin/nrm.a nrm.a16 16 1 1024 + $(VBR) -law a -enc -rate 16 bin/ovr.a ovr.a16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 16 bin/rn16fa.i rn16fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fa.i rv16fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output + $(VBR) -law u -dec -rate 16 bin/rn16fa.i rn16fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fa.i rv16fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 16 bin/nrm.m nrm.m16 16 1 1024 + $(VBR) -law u -enc -rate 16 bin/ovr.m ovr.m16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 16 bin/rn16fm.i rn16fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fm.i rv16fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s ->A law output + $(VBR) -law a -dec -rate 16 bin/rn16fm.i rn16fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fm.i rv16fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 16 bin/i16 ri16fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/i16 ri16fm.rec 16 1 1024 + +proc24-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 24 bin/nrm.a nrm.a24 16 1 1024 + $(VBR) -law a -enc -rate 24 bin/ovr.a ovr.a24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 24 bin/rn24fa.i rn24fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fa.i rv24fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output + $(VBR) -law u -dec -rate 24 bin/rn24fa.i rn24fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fa.i rv24fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 24 bin/nrm.m nrm.m24 16 1 1024 + $(VBR) -law u -enc -rate 24 bin/ovr.m ovr.m24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 24 bin/rn24fm.i rn24fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fm.i rv24fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s ->A law output + $(VBR) -law a -dec -rate 24 bin/rn24fm.i rn24fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fm.i rv24fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 24 bin/i24 ri24fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/i24 ri24fm.rec 16 1 1024 + +proc32-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 32 bin/nrm.a nrm.a32 16 1 1024 + $(VBR) -law a -enc -rate 32 bin/ovr.a ovr.a32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 32 bin/rn32fa.i rn32fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fa.i rv32fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output + $(VBR) -law u -dec -rate 32 bin/rn32fa.i rn32fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fa.i rv32fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 32 bin/nrm.m nrm.m32 16 1 1024 + $(VBR) -law u -enc -rate 32 bin/ovr.m ovr.m32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 32 bin/rn32fm.i rn32fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fm.i rv32fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s ->A law output + $(VBR) -law a -dec -rate 32 bin/rn32fm.i rn32fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fm.i rv32fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 32 bin/i32 ri32fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/i32 ri32fm.rec 16 1 1024 + +proc40-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 40 bin/nrm.a nrm.a40 16 1 1024 + $(VBR) -law a -enc -rate 40 bin/ovr.a ovr.a40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 40 bin/rn40fa.i rn40fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fa.i rv40fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output + $(VBR) -law u -dec -rate 40 bin/rn40fa.i rn40fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fa.i rv40fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 40 bin/nrm.m nrm.m40 16 1 1024 + $(VBR) -law u -enc -rate 40 bin/ovr.m ovr.m40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 40 bin/rn40fm.i rn40fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fm.i rv40fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s ->A law output + $(VBR) -law a -dec -rate 40 bin/rn40fm.i rn40fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fm.i rv40fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 40 bin/i40 ri40fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/i40 ri40fm.rec 16 1 1024 + +# ========================================= +# Process by batch +# ========================================= +batchtest: + batch test-g726 + +batchtest-vbr: + echo make -f makefile.unx test-vbr | batch diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/makefile.djc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/makefile.djc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,576 @@ +# ----------------------------------------------------------------------------- +# GNU-C MSDOS-port makefile for compiling and testing the G.726 +# implementation. The executable must be defined by variable G726 below. +# 01.May.94 - Implemented by +# 10.Mar.95 - Compilation and test sequence processing/comparison for +# vbr-g726.c. +# NOTE: you need to get (purchase) the G.726 test vectors from the ITU in +# order to perform the (optional) compliance test. +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose compileroptions +# ------------------------------------------------ +CC_OPT = -I../utl + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +G726 = go32 g726demo +VBR = go32 vbr-g726 -q +DIFF = cf -q +RM = -rm + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# File lists +# ------------------------------------------------ +TEST_VECTORS = *.?16 *.?24 *.?32 *.?40 *.rec + +DEMO_OBJ = g726demo.o g726.o +VBR_OBJ = vbr-g726.o g726.o g711.o + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g726demo vbr-g726 + +anyway: clean all + +clean: + $(RM) *.o + +cleantest: + $(RM) $(TEST_VECTORS) voicvbra.tst voicvbru.tst voicvbrl.tst + $(RM) voice.src voicevbr.arf voicevbr.lrf voicevbr.urf + +veryclean: clean cleantest + $(RM) g726demo vbr-g726 + +# ----------------------------------------------------------------------------- +# Generic rules +# ----------------------------------------------------------------------------- +.c.o: + $(CC) $(CC_OPT) -c $< + +# ----------------------------------------------------------------------------- +# Specific rules +# ----------------------------------------------------------------------------- +vbr-g726: $(VBR_OBJ) + $(CC) -o vbr-g726 $(VBR_OBJ) -lm + +g726demo: $(DEMO_OBJ) + $(CC) -o g726demo $(DEMO_OBJ) -lm + +g726demo.o: g726demo.c g726.h + $(CC) -c $(CC_OPT) -I../g711 g726demo.c + +g726.o: g726.c g726.h + $(CC) -c $(CC_OPT) g726.c + +g711.o: ../g711/g711.c + $(CC) -c $(CC_OPT) -I../g711 ../g711/g711.c + +vbr-g726.o: vbr-g726.c + $(CC) -c $(CC_OPT) -I../g711 vbr-g726.c + +# ---------------------------------------- +# Very simple portability test +# ---------------------------------------- +test: test-vbr-quick +proc: proc-vbr-quick +comp: comp-vbr-quick + +test-vbr-quick: proc-vbr-quick comp-vbr-quick +proc-vbr-quick: voice.src + $(VBR) -q -law A -rate 16-24-32-40-32-24 voice.src voicvbra.tst + $(VBR) -q -law l -rate 16-24-32-40-32-24 voice.src voicvbrl.tst + $(VBR) -q -law u -rate 16-24-32-40-32-24 voice.src voicvbru.tst +comp-vbr-quick: voicevbr.arf + $(DIFF) voicvbra.tst voicevbr.arf + $(DIFF) voicvbrl.tst voicevbr.lrf + $(DIFF) voicvbru.tst voicevbr.urf + +voice.src: tst-g726.zip + $(UNZIP) tst-g726.zip voice.src + sb -over voice.src + +voicevbr.arf: tst-g726.zip + $(UNZIP) tst-g726.zip voicevbr.arf voicevbr.lrf voicevbr.urf + swapover voicevbr.arf voicevbr.lrf voicevbr.urf + +# ----------------------------------------------------------------------------- +# Test the implementation for g726demo (compliance) +# In the automatic compliance testing, g726demo.c is verified by test-tv +# For vbr-g726.c, no differences should be observed, since both use g726.c, +# and differ only on the demo logic. For full compliance testing of the +# vbr-g726.c program, use test-tv-vbr +# ----------------------------------------------------------------------------- +test-tv: proc-tv-fix comp-tv +proc-tv-fix: bin/rn16fa.o clean proc16-fix proc24-fix proc32-fix proc40-fix +comp-tv-fix: comp-tv +comp-tv: comp16 comp24 comp32 comp40 + +proc16-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 16 bin/nrm.a nrm.a16 256 1 64 + $(G726) a load 16 bin/ovr.a ovr.a16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 16 bin/rn16fa.i rn16fa.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fa.i rv16fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output +# + $(G726) u adlo 16 bin/rn16fa.i rn16fx.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fa.i rv16fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 16 bin/nrm.m nrm.m16 256 1 64 + $(G726) u load 16 bin/ovr.m ovr.m16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 16 bin/rn16fm.i rn16fm.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fm.i rv16fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s -> A law output +# + $(G726) a adlo 16 bin/rn16fm.i rn16fc.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fm.i rv16fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 16 bin/i16 ri16fa.rec 256 1 64 + $(G726) u adlo 16 bin/i16 ri16fm.rec 256 1 64 + +comp16: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.i nrm.a16 256 1 64 + $(DIFF) bin/rv16fa.i ovr.a16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.o rn16fa.rec 256 1 64 + $(DIFF) bin/rv16fa.o rv16fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn16fx.o rn16fx.rec 256 1 64 + $(DIFF) bin/rv16fx.o rv16fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.i nrm.m16 256 1 64 + $(DIFF) bin/rv16fm.i ovr.m16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.o rn16fm.rec 256 1 64 + $(DIFF) bin/rv16fm.o rv16fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn16fc.o rn16fc.rec 256 1 64 + $(DIFF) bin/rv16fc.o rv16fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri16fa.o ri16fa.rec 256 1 64 + $(DIFF) bin/ri16fm.o ri16fm.rec 256 1 64 + +proc24-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 24 bin/nrm.a nrm.a24 256 1 64 + $(G726) a load 24 bin/ovr.a ovr.a24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 24 bin/rn24fa.i rn24fa.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fa.i rv24fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output +# + $(G726) u adlo 24 bin/rn24fa.i rn24fx.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fa.i rv24fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 24 bin/nrm.m nrm.m24 256 1 64 + $(G726) u load 24 bin/ovr.m ovr.m24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 24 bin/rn24fm.i rn24fm.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fm.i rv24fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s -> A law output +# + $(G726) a adlo 24 bin/rn24fm.i rn24fc.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fm.i rv24fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 24 bin/i24 ri24fa.rec 256 1 64 + $(G726) u adlo 24 bin/i24 ri24fm.rec 256 1 64 + +comp24: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.i nrm.a24 256 1 64 + $(DIFF) bin/rv24fa.i ovr.a24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.o rn24fa.rec 256 1 64 + $(DIFF) bin/rv24fa.o rv24fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn24fx.o rn24fx.rec 256 1 64 + $(DIFF) bin/rv24fx.o rv24fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.i nrm.m24 256 1 64 + $(DIFF) bin/rv24fm.i ovr.m24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.o rn24fm.rec 256 1 64 + $(DIFF) bin/rv24fm.o rv24fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn24fc.o rn24fc.rec 256 1 64 + $(DIFF) bin/rv24fc.o rv24fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri24fa.o ri24fa.rec 256 1 64 + $(DIFF) bin/ri24fm.o ri24fm.rec 256 1 64 + +proc32-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 32 bin/nrm.a nrm.a32 256 1 64 + $(G726) a load 32 bin/ovr.a ovr.a32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 32 bin/rn32fa.i rn32fa.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fa.i rv32fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output +# + $(G726) u adlo 32 bin/rn32fa.i rn32fx.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fa.i rv32fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 32 bin/nrm.m nrm.m32 256 1 64 + $(G726) u load 32 bin/ovr.m ovr.m32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 32 bin/rn32fm.i rn32fm.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fm.i rv32fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s -> A law output +# + $(G726) a adlo 32 bin/rn32fm.i rn32fc.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fm.i rv32fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 32 bin/i32 ri32fa.rec 256 1 64 + $(G726) u adlo 32 bin/i32 ri32fm.rec 256 1 64 + +comp32: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.i nrm.a32 256 1 64 + $(DIFF) bin/rv32fa.i ovr.a32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.o rn32fa.rec 256 1 64 + $(DIFF) bin/rv32fa.o rv32fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn32fx.o rn32fx.rec 256 1 64 + $(DIFF) bin/rv32fx.o rv32fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.i nrm.m32 256 1 64 + $(DIFF) bin/rv32fm.i ovr.m32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.o rn32fm.rec 256 1 64 + $(DIFF) bin/rv32fm.o rv32fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn32fc.o rn32fc.rec 256 1 64 + $(DIFF) bin/rv32fc.o rv32fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri32fa.o ri32fa.rec 256 1 64 + $(DIFF) bin/ri32fm.o ri32fm.rec 256 1 64 + +proc40-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 40 bin/nrm.a nrm.a40 256 1 64 + $(G726) a load 40 bin/ovr.a ovr.a40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 40 bin/rn40fa.i rn40fa.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fa.i rv40fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output +# + $(G726) u adlo 40 bin/rn40fa.i rn40fx.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fa.i rv40fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 40 bin/nrm.m nrm.m40 256 1 64 + $(G726) u load 40 bin/ovr.m ovr.m40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 40 bin/rn40fm.i rn40fm.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fm.i rv40fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s -> A law output +# + $(G726) a adlo 40 bin/rn40fm.i rn40fc.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fm.i rv40fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 40 bin/i40 ri40fa.rec 256 1 64 + $(G726) u adlo 40 bin/i40 ri40fm.rec 256 1 64 + +comp40: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.i nrm.a40 256 1 64 + $(DIFF) bin/rv40fa.i ovr.a40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.o rn40fa.rec 256 1 64 + $(DIFF) bin/rv40fa.o rv40fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn40fx.o rn40fx.rec 256 1 64 + $(DIFF) bin/rv40fx.o rv40fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.i nrm.m40 256 1 64 + $(DIFF) bin/rv40fm.i ovr.m40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.o rn40fm.rec 256 1 64 + $(DIFF) bin/rv40fm.o rv40fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn40fc.o rn40fc.rec 256 1 64 + $(DIFF) bin/rv40fc.o rv40fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri40fa.o ri40fa.rec 256 1 64 + $(DIFF) bin/ri40fm.o ri40fm.rec 256 1 64 + +# +# ----------------------------------------------------------------------------- +# Test the implementation for vbr-g726 (compliance) +# ----------------------------------------------------------------------------- +test-tv-vbr: proc-tv-vbr comp-tv +proc-tv-vbr: bin/rn16fa.o clean proc16-vbr proc24-vbr proc32-vbr proc40-vbr +comp-vbr-tv: comp-tv + +proc16-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 16 bin/nrm.a nrm.a16 16 1 1024 + $(VBR) -law a -enc -rate 16 bin/ovr.a ovr.a16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 16 bin/rn16fa.i rn16fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fa.i rv16fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output + $(VBR) -law u -dec -rate 16 bin/rn16fa.i rn16fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fa.i rv16fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 16 bin/nrm.m nrm.m16 16 1 1024 + $(VBR) -law u -enc -rate 16 bin/ovr.m ovr.m16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 16 bin/rn16fm.i rn16fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fm.i rv16fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s ->A law output + $(VBR) -law a -dec -rate 16 bin/rn16fm.i rn16fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fm.i rv16fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 16 bin/i16 ri16fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/i16 ri16fm.rec 16 1 1024 + +proc24-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 24 bin/nrm.a nrm.a24 16 1 1024 + $(VBR) -law a -enc -rate 24 bin/ovr.a ovr.a24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 24 bin/rn24fa.i rn24fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fa.i rv24fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output + $(VBR) -law u -dec -rate 24 bin/rn24fa.i rn24fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fa.i rv24fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 24 bin/nrm.m nrm.m24 16 1 1024 + $(VBR) -law u -enc -rate 24 bin/ovr.m ovr.m24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 24 bin/rn24fm.i rn24fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fm.i rv24fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s ->A law output + $(VBR) -law a -dec -rate 24 bin/rn24fm.i rn24fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fm.i rv24fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 24 bin/i24 ri24fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/i24 ri24fm.rec 16 1 1024 + +proc32-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 32 bin/nrm.a nrm.a32 16 1 1024 + $(VBR) -law a -enc -rate 32 bin/ovr.a ovr.a32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 32 bin/rn32fa.i rn32fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fa.i rv32fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output + $(VBR) -law u -dec -rate 32 bin/rn32fa.i rn32fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fa.i rv32fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 32 bin/nrm.m nrm.m32 16 1 1024 + $(VBR) -law u -enc -rate 32 bin/ovr.m ovr.m32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 32 bin/rn32fm.i rn32fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fm.i rv32fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s ->A law output + $(VBR) -law a -dec -rate 32 bin/rn32fm.i rn32fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fm.i rv32fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 32 bin/i32 ri32fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/i32 ri32fm.rec 16 1 1024 + +proc40-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 40 bin/nrm.a nrm.a40 16 1 1024 + $(VBR) -law a -enc -rate 40 bin/ovr.a ovr.a40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 40 bin/rn40fa.i rn40fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fa.i rv40fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output + $(VBR) -law u -dec -rate 40 bin/rn40fa.i rn40fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fa.i rv40fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 40 bin/nrm.m nrm.m40 16 1 1024 + $(VBR) -law u -enc -rate 40 bin/ovr.m ovr.m40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 40 bin/rn40fm.i rn40fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fm.i rv40fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s ->A law output + $(VBR) -law a -dec -rate 40 bin/rn40fm.i rn40fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fm.i rv40fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 40 bin/i40 ri40fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/i40 ri40fm.rec 16 1 1024 + + + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/makefile.tcc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/makefile.tcc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,580 @@ +# ----------------------------------------------------------------------------- +# Borland tcc/bcc makefile for compiling and testing the G.726 +# implementation. The executable must be defined by variable G726 below. +# 01.May.94 - Implemented by +# 10.Mar.95 - Compilation and test sequence processing/comparison for +# vbr-g726.c. +# NOTE: you need to get (purchase) the G.726 test vectors from the ITU in +# order to perform the (optional) compliance test. +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose compiler/options. +# ------------------------------------------------ +#CC = bcc +CC = tcc +CC_OPT = -I../utl + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +G726 = g726demo +VBR = vbr-g726 -q +DIFF = cf -q +RM = -rm -f + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# File lists +# ------------------------------------------------ +TEST_VECTORS = *.?16 *.?24 *.?32 *.?40 *.rec + +DEMO_OBJ = g726demo.obj g726.obj +VBR_OBJ = vbr-g726.obj g726.obj g711.obj + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all: g726demo vbr-g726 + +anyway: clean all + +clean: + $(RM) *.obj + +cleantest: + $(RM) $(TEST_VECTORS) voicvbra.tst voicvbru.tst voicvbrl.tst + $(RM) voice.src voicevbr.arf voicevbr.lrf voicevbr.urf + +veryclean: clean cleantest + $(RM) g726demo.exe vbr-g726.exe + +# ----------------------------------------------------------------------------- +# Generic rules +# ----------------------------------------------------------------------------- +.c.obj: + $(CC) $(CC_OPT) -c $< + +# ----------------------------------------------------------------------------- +# Specific rules +# ----------------------------------------------------------------------------- +vbr-g726: vbr-g726.exe +g726demo: g726demo.exe + +vbr-g726.exe: $(VBR_OBJ) + $(CC) -evbr-g726 $(VBR_OBJ) + +g726demo.exe: $(DEMO_OBJ) + $(CC) -eg726demo $(DEMO_OBJ) + +g726demo.obj: g726demo.c g726.h + $(CC) $(CC_OPT) -c -I../g711 g726demo.c + +g726.obj: g726.c g726.h + $(CC) -c $(CC_OPT) g726.c + +g711.obj: ../g711/g711.c + $(CC) -c $(CC_OPT) -I../g711 ../g711/g711.c + +vbr-g726.obj: vbr-g726.c + $(CC) -c $(CC_OPT) -I../g711 vbr-g726.c + +# ---------------------------------------- +# Very simple portability test +# ---------------------------------------- +test: test-vbr-quick +proc: proc-vbr-quick +comp: comp-vbr-quick + +test-vbr-quick: proc-vbr-quick comp-vbr-quick +proc-vbr-quick: voice.src + $(VBR) -q -law A -rate 16-24-32-40-32-24 voice.src voicvbra.tst + $(VBR) -q -law l -rate 16-24-32-40-32-24 voice.src voicvbrl.tst + $(VBR) -q -law u -rate 16-24-32-40-32-24 voice.src voicvbru.tst +comp-vbr-quick: voicevbr.arf + $(DIFF) voicvbra.tst voicevbr.arf + $(DIFF) voicvbrl.tst voicevbr.lrf + $(DIFF) voicvbru.tst voicevbr.urf + +voice.src: tst-g726.zip + $(UNZIP) tst-g726.zip voice.src + sb -over voice.src + +voicevbr.arf: tst-g726.zip + $(UNZIP) tst-g726.zip voicevbr.arf voicevbr.lrf voicevbr.urf + swapover voicevbr.arf voicevbr.lrf voicevbr.urf + +# ----------------------------------------------------------------------------- +# Test the implementation for g726demo (compliance) +# In the automatic compliance testing, g726demo.c is verified by test-tv +# For vbr-g726.c, no differences should be observed, since both use g726.c, +# and differ only on the demo logic. For full compliance testing of the +# vbr-g726.c program, use test-tv-vbr +# ----------------------------------------------------------------------------- +test-tv: proc-tv-fix comp-tv +proc-tv-fix: bin/rn16fa.o clean proc16-fix proc24-fix proc32-fix proc40-fix +comp-tv-fix: comp-tv +comp-tv: comp16 comp24 comp32 comp40 + +proc16-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 16 bin/nrm.a nrm.a16 256 1 64 + $(G726) a load 16 bin/ovr.a ovr.a16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 16 bin/rn16fa.i rn16fa.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fa.i rv16fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output +# + $(G726) u adlo 16 bin/rn16fa.i rn16fx.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fa.i rv16fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 16 bin/nrm.m nrm.m16 256 1 64 + $(G726) u load 16 bin/ovr.m ovr.m16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 16 bin/rn16fm.i rn16fm.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fm.i rv16fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s -> A law output +# + $(G726) a adlo 16 bin/rn16fm.i rn16fc.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fm.i rv16fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 16 bin/i16 ri16fa.rec 256 1 64 + $(G726) u adlo 16 bin/i16 ri16fm.rec 256 1 64 + +comp16: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.i nrm.a16 256 1 64 + $(DIFF) bin/rv16fa.i ovr.a16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.o rn16fa.rec 256 1 64 + $(DIFF) bin/rv16fa.o rv16fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn16fx.o rn16fx.rec 256 1 64 + $(DIFF) bin/rv16fx.o rv16fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.i nrm.m16 256 1 64 + $(DIFF) bin/rv16fm.i ovr.m16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.o rn16fm.rec 256 1 64 + $(DIFF) bin/rv16fm.o rv16fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn16fc.o rn16fc.rec 256 1 64 + $(DIFF) bin/rv16fc.o rv16fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri16fa.o ri16fa.rec 256 1 64 + $(DIFF) bin/ri16fm.o ri16fm.rec 256 1 64 + +proc24-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 24 bin/nrm.a nrm.a24 256 1 64 + $(G726) a load 24 bin/ovr.a ovr.a24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 24 bin/rn24fa.i rn24fa.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fa.i rv24fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output +# + $(G726) u adlo 24 bin/rn24fa.i rn24fx.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fa.i rv24fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 24 bin/nrm.m nrm.m24 256 1 64 + $(G726) u load 24 bin/ovr.m ovr.m24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 24 bin/rn24fm.i rn24fm.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fm.i rv24fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s -> A law output +# + $(G726) a adlo 24 bin/rn24fm.i rn24fc.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fm.i rv24fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 24 bin/i24 ri24fa.rec 256 1 64 + $(G726) u adlo 24 bin/i24 ri24fm.rec 256 1 64 + +comp24: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.i nrm.a24 256 1 64 + $(DIFF) bin/rv24fa.i ovr.a24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.o rn24fa.rec 256 1 64 + $(DIFF) bin/rv24fa.o rv24fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn24fx.o rn24fx.rec 256 1 64 + $(DIFF) bin/rv24fx.o rv24fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.i nrm.m24 256 1 64 + $(DIFF) bin/rv24fm.i ovr.m24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.o rn24fm.rec 256 1 64 + $(DIFF) bin/rv24fm.o rv24fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn24fc.o rn24fc.rec 256 1 64 + $(DIFF) bin/rv24fc.o rv24fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri24fa.o ri24fa.rec 256 1 64 + $(DIFF) bin/ri24fm.o ri24fm.rec 256 1 64 + +proc32-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 32 bin/nrm.a nrm.a32 256 1 64 + $(G726) a load 32 bin/ovr.a ovr.a32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 32 bin/rn32fa.i rn32fa.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fa.i rv32fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output +# + $(G726) u adlo 32 bin/rn32fa.i rn32fx.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fa.i rv32fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 32 bin/nrm.m nrm.m32 256 1 64 + $(G726) u load 32 bin/ovr.m ovr.m32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 32 bin/rn32fm.i rn32fm.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fm.i rv32fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s -> A law output +# + $(G726) a adlo 32 bin/rn32fm.i rn32fc.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fm.i rv32fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 32 bin/i32 ri32fa.rec 256 1 64 + $(G726) u adlo 32 bin/i32 ri32fm.rec 256 1 64 + +comp32: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.i nrm.a32 256 1 64 + $(DIFF) bin/rv32fa.i ovr.a32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.o rn32fa.rec 256 1 64 + $(DIFF) bin/rv32fa.o rv32fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn32fx.o rn32fx.rec 256 1 64 + $(DIFF) bin/rv32fx.o rv32fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.i nrm.m32 256 1 64 + $(DIFF) bin/rv32fm.i ovr.m32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.o rn32fm.rec 256 1 64 + $(DIFF) bin/rv32fm.o rv32fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn32fc.o rn32fc.rec 256 1 64 + $(DIFF) bin/rv32fc.o rv32fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri32fa.o ri32fa.rec 256 1 64 + $(DIFF) bin/ri32fm.o ri32fm.rec 256 1 64 + +proc40-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 40 bin/nrm.a nrm.a40 256 1 64 + $(G726) a load 40 bin/ovr.a ovr.a40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 40 bin/rn40fa.i rn40fa.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fa.i rv40fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output +# + $(G726) u adlo 40 bin/rn40fa.i rn40fx.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fa.i rv40fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 40 bin/nrm.m nrm.m40 256 1 64 + $(G726) u load 40 bin/ovr.m ovr.m40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 40 bin/rn40fm.i rn40fm.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fm.i rv40fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s -> A law output +# + $(G726) a adlo 40 bin/rn40fm.i rn40fc.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fm.i rv40fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 40 bin/i40 ri40fa.rec 256 1 64 + $(G726) u adlo 40 bin/i40 ri40fm.rec 256 1 64 + +comp40: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.i nrm.a40 256 1 64 + $(DIFF) bin/rv40fa.i ovr.a40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.o rn40fa.rec 256 1 64 + $(DIFF) bin/rv40fa.o rv40fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn40fx.o rn40fx.rec 256 1 64 + $(DIFF) bin/rv40fx.o rv40fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.i nrm.m40 256 1 64 + $(DIFF) bin/rv40fm.i ovr.m40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.o rn40fm.rec 256 1 64 + $(DIFF) bin/rv40fm.o rv40fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn40fc.o rn40fc.rec 256 1 64 + $(DIFF) bin/rv40fc.o rv40fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri40fa.o ri40fa.rec 256 1 64 + $(DIFF) bin/ri40fm.o ri40fm.rec 256 1 64 + + +# ----------------------------------------------------------------------------- +# Test the implementation for vbr-g726 (compliance) +# ----------------------------------------------------------------------------- +test-vbr-tv: proc-vbr-tv comp-tv +proc-vbr-tv: bin/rn16fa.o clean proc16-vbr proc24-vbr proc32-vbr proc40-vbr +comp-vbr-tv: comp-tv + +proc16-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 16 bin/nrm.a nrm.a16 16 1 1024 + $(VBR) -law a -enc -rate 16 bin/ovr.a ovr.a16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 16 bin/rn16fa.i rn16fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fa.i rv16fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output + $(VBR) -law u -dec -rate 16 bin/rn16fa.i rn16fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fa.i rv16fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 16 bin/nrm.m nrm.m16 16 1 1024 + $(VBR) -law u -enc -rate 16 bin/ovr.m ovr.m16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 16 bin/rn16fm.i rn16fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fm.i rv16fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s ->A law output + $(VBR) -law a -dec -rate 16 bin/rn16fm.i rn16fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fm.i rv16fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 16 bin/i16 ri16fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/i16 ri16fm.rec 16 1 1024 + +proc24-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 24 bin/nrm.a nrm.a24 16 1 1024 + $(VBR) -law a -enc -rate 24 bin/ovr.a ovr.a24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 24 bin/rn24fa.i rn24fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fa.i rv24fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output + $(VBR) -law u -dec -rate 24 bin/rn24fa.i rn24fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fa.i rv24fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 24 bin/nrm.m nrm.m24 16 1 1024 + $(VBR) -law u -enc -rate 24 bin/ovr.m ovr.m24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 24 bin/rn24fm.i rn24fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fm.i rv24fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s ->A law output + $(VBR) -law a -dec -rate 24 bin/rn24fm.i rn24fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fm.i rv24fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 24 bin/i24 ri24fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/i24 ri24fm.rec 16 1 1024 + +proc32-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 32 bin/nrm.a nrm.a32 16 1 1024 + $(VBR) -law a -enc -rate 32 bin/ovr.a ovr.a32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 32 bin/rn32fa.i rn32fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fa.i rv32fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output + $(VBR) -law u -dec -rate 32 bin/rn32fa.i rn32fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fa.i rv32fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 32 bin/nrm.m nrm.m32 16 1 1024 + $(VBR) -law u -enc -rate 32 bin/ovr.m ovr.m32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 32 bin/rn32fm.i rn32fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fm.i rv32fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s ->A law output + $(VBR) -law a -dec -rate 32 bin/rn32fm.i rn32fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fm.i rv32fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 32 bin/i32 ri32fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/i32 ri32fm.rec 16 1 1024 + +proc40-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 40 bin/nrm.a nrm.a40 16 1 1024 + $(VBR) -law a -enc -rate 40 bin/ovr.a ovr.a40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 40 bin/rn40fa.i rn40fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fa.i rv40fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output + $(VBR) -law u -dec -rate 40 bin/rn40fa.i rn40fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fa.i rv40fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 40 bin/nrm.m nrm.m40 16 1 1024 + $(VBR) -law u -enc -rate 40 bin/ovr.m ovr.m40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 40 bin/rn40fm.i rn40fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fm.i rv40fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s ->A law output + $(VBR) -law a -dec -rate 40 bin/rn40fm.i rn40fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fm.i rv40fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 40 bin/i40 ri40fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/i40 ri40fm.rec 16 1 1024 + + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/makefile.unx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/makefile.unx Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,583 @@ +# ----------------------------------------------------------------------------- +# Unix makefile for compiling and testing the G.726 implementation +# The executable must be defined by variable G726 below. +# 01.May.94 - Implemented by +# 10.Mar.95 - Compilation and test sequence processing/comparison for +# vbr-g726.c. +# NOTE: you need to get (purchase) the G.726 test vectors from the ITU in +# order to perform the (optional) compliance test. +# ----------------------------------------------------------------------------- + +# ------------------------------------------------ +# Choose compiler. Sun: use cc. HP: gotta use gcc +# ------------------------------------------------ +CC=gcc +CC_OPT = -Wall -g -I../utl + +# ------------------------------------------------ +# General purpose symbols +# ------------------------------------------------ +G726 = ./g726demo +VBR = ./vbr-g726 -q +# DIFF = cf -q +DIFF = diff + +# ------------------------------------------------ +# Choose an archiving utility: +# - public domain unzip, or [PC/Unix/VMS] +# - shareware pkunzip [PC only] +# ------------------------------------------------ +#UNZIP = pkunzip +UNZIP = unzip -o + +# ------------------------------------------------ +# File lists +# ------------------------------------------------ +TEST_VECTORS = *.?16 *.?24 *.?32 *.?40 *.rec + +DEMO_OBJ = g726demo.o g726.o +VBR_OBJ = vbr-g726.o g726.o g711.o + +# ------------------------------------------------ +# Targets +# ------------------------------------------------ +all:: g726demo vbr-g726 + +anyway: clean all + +clean: + $(RM) *.o + +cleantest: + $(RM) $(TEST_VECTORS) voicvbra.tst voicvbru.tst voicvbrl.tst + $(RM) voice.src voicevbr.arf voicevbr.lrf voicevbr.urf + +veryclean: clean cleantest + $(RM) g726demo vbr-g726 + +# ----------------------------------------------------------------------------- +# Generic rules +# ----------------------------------------------------------------------------- +.c.o: + $(CC) $(CC_OPT) -c $< + +# ----------------------------------------------------------------------------- +# Specific rules +# ----------------------------------------------------------------------------- +vbr-g726: $(VBR_OBJ) + $(CC) -o vbr-g726 $(VBR_OBJ) -lm + +g726demo: $(DEMO_OBJ) + $(CC) -o g726demo $(DEMO_OBJ) -lm + +g726demo.o: g726demo.c + $(CC) -c $(CC_OPT) -I../g711 g726demo.c + +g726.o: g726.c + $(CC) -c $(CC_OPT) g726.c + +g711.o: ../g711/g711.c + $(CC) -c $(CC_OPT) -I../g711 ../g711/g711.c + +vbr-g726.o: vbr-g726.c + $(CC) -c $(CC_OPT) -I../g711 vbr-g726.c + +# ---------------------------------------- +# Very simple portability test +# ---------------------------------------- +test: test-vbr-quick +proc: proc-vbr-quick +comp: comp-vbr-quick + +test-vbr-quick: proc-vbr-quick comp-vbr-quick +proc-vbr-quick: voice.src + $(VBR) -q -law A -rate 16-24-32-40-32-24 voice.src voicvbra.tst + $(VBR) -q -law l -rate 16-24-32-40-32-24 voice.src voicvbrl.tst + $(VBR) -q -law u -rate 16-24-32-40-32-24 voice.src voicvbru.tst +comp-vbr-quick: voicevbr.arf + $(DIFF) voicvbra.tst voicevbr.arf + $(DIFF) voicvbrl.tst voicevbr.lrf + $(DIFF) voicvbru.tst voicevbr.urf + +voice.src: tst-g726.zip + $(UNZIP) tst-g726.zip voice.src + sb -over -if little voice.src + +voicevbr.arf: tst-g726.zip + $(UNZIP) tst-g726.zip voicevbr.arf voicevbr.lrf voicevbr.urf + swapover -if little voicevbr.arf voicevbr.lrf voicevbr.urf + +# ----------------------------------------------------------------------------- +# Test the implementation for g726demo (compliance) +# In the automatic compliance testing, g726demo.c is verified by test-tv +# For vbr-g726.c, no differences should be observed, since both use g726.c, +# and differ only on the demo logic. For full compliance testing of the +# vbr-g726.c program, use test-tv-vbr +# ----------------------------------------------------------------------------- +test-tv: proc-tv-fix comp-tv +proc-tv-fix: bin/rn16fa.o clean proc16-fix proc24-fix proc32-fix proc40-fix +comp-tv-fix: comp-tv +comp-tv: comp16 comp24 comp32 comp40 + +proc16-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 16 bin/nrm.a nrm.a16 256 1 64 + $(G726) a load 16 bin/ovr.a ovr.a16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 16 bin/rn16fa.i rn16fa.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fa.i rv16fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output +# + $(G726) u adlo 16 bin/rn16fa.i rn16fx.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fa.i rv16fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 16 bin/nrm.m nrm.m16 256 1 64 + $(G726) u load 16 bin/ovr.m ovr.m16 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 16 bin/rn16fm.i rn16fm.rec 256 1 64 + $(G726) u adlo 16 bin/rv16fm.i rv16fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s -> A law output +# + $(G726) a adlo 16 bin/rn16fm.i rn16fc.rec 256 1 64 + $(G726) a adlo 16 bin/rv16fm.i rv16fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 16 bin/i16 ri16fa.rec 256 1 64 + $(G726) u adlo 16 bin/i16 ri16fm.rec 256 1 64 + +comp16: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.i nrm.a16 256 1 64 + $(DIFF) bin/rv16fa.i ovr.a16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn16fa.o rn16fa.rec 256 1 64 + $(DIFF) bin/rv16fa.o rv16fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn16fx.o rn16fx.rec 256 1 64 + $(DIFF) bin/rv16fx.o rv16fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.i nrm.m16 256 1 64 + $(DIFF) bin/rv16fm.i ovr.m16 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn16fm.o rn16fm.rec 256 1 64 + $(DIFF) bin/rv16fm.o rv16fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn16fc.o rn16fc.rec 256 1 64 + $(DIFF) bin/rv16fc.o rv16fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri16fa.o ri16fa.rec 256 1 64 + $(DIFF) bin/ri16fm.o ri16fm.rec 256 1 64 + +proc24-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 24 bin/nrm.a nrm.a24 256 1 64 + $(G726) a load 24 bin/ovr.a ovr.a24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 24 bin/rn24fa.i rn24fa.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fa.i rv24fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output +# + $(G726) u adlo 24 bin/rn24fa.i rn24fx.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fa.i rv24fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 24 bin/nrm.m nrm.m24 256 1 64 + $(G726) u load 24 bin/ovr.m ovr.m24 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 24 bin/rn24fm.i rn24fm.rec 256 1 64 + $(G726) u adlo 24 bin/rv24fm.i rv24fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s -> A law output +# + $(G726) a adlo 24 bin/rn24fm.i rn24fc.rec 256 1 64 + $(G726) a adlo 24 bin/rv24fm.i rv24fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 24 bin/i24 ri24fa.rec 256 1 64 + $(G726) u adlo 24 bin/i24 ri24fm.rec 256 1 64 + +comp24: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.i nrm.a24 256 1 64 + $(DIFF) bin/rv24fa.i ovr.a24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn24fa.o rn24fa.rec 256 1 64 + $(DIFF) bin/rv24fa.o rv24fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn24fx.o rn24fx.rec 256 1 64 + $(DIFF) bin/rv24fx.o rv24fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.i nrm.m24 256 1 64 + $(DIFF) bin/rv24fm.i ovr.m24 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn24fm.o rn24fm.rec 256 1 64 + $(DIFF) bin/rv24fm.o rv24fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn24fc.o rn24fc.rec 256 1 64 + $(DIFF) bin/rv24fc.o rv24fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri24fa.o ri24fa.rec 256 1 64 + $(DIFF) bin/ri24fm.o ri24fm.rec 256 1 64 + +proc32-fix: +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 32 bin/nrm.a nrm.a32 256 1 64 + $(G726) a load 32 bin/ovr.a ovr.a32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 32 bin/rn32fa.i rn32fa.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fa.i rv32fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output +# + $(G726) u adlo 32 bin/rn32fa.i rn32fx.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fa.i rv32fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 32 bin/nrm.m nrm.m32 256 1 64 + $(G726) u load 32 bin/ovr.m ovr.m32 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 32 bin/rn32fm.i rn32fm.rec 256 1 64 + $(G726) u adlo 32 bin/rv32fm.i rv32fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s -> A law output +# + $(G726) a adlo 32 bin/rn32fm.i rn32fc.rec 256 1 64 + $(G726) a adlo 32 bin/rv32fm.i rv32fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 32 bin/i32 ri32fa.rec 256 1 64 + $(G726) u adlo 32 bin/i32 ri32fm.rec 256 1 64 + +comp32: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.i nrm.a32 256 1 64 + $(DIFF) bin/rv32fa.i ovr.a32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn32fa.o rn32fa.rec 256 1 64 + $(DIFF) bin/rv32fa.o rv32fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn32fx.o rn32fx.rec 256 1 64 + $(DIFF) bin/rv32fx.o rv32fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.i nrm.m32 256 1 64 + $(DIFF) bin/rv32fm.i ovr.m32 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn32fm.o rn32fm.rec 256 1 64 + $(DIFF) bin/rv32fm.o rv32fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn32fc.o rn32fc.rec 256 1 64 + $(DIFF) bin/rv32fc.o rv32fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri32fa.o ri32fa.rec 256 1 64 + $(DIFF) bin/ri32fm.o ri32fm.rec 256 1 64 + +proc40-fix: +# +# +# Process ADPCM/ Coder for normal and overload sequences, A law +# + $(G726) a load 40 bin/nrm.a nrm.a40 256 1 64 + $(G726) a load 40 bin/ovr.a ovr.a40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, A law +# + $(G726) a adlo 40 bin/rn40fa.i rn40fa.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fa.i rv40fa.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output +# + $(G726) u adlo 40 bin/rn40fa.i rn40fx.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fa.i rv40fx.rec 256 1 8 +# +# +# Process ADPCM/ Coder for normal and overload sequences, mu law +# + $(G726) u load 40 bin/nrm.m nrm.m40 256 1 64 + $(G726) u load 40 bin/ovr.m ovr.m40 256 1 8 +# +# Process ADPCM/ Decoder for normal and overload sequences, mu law +# + $(G726) u adlo 40 bin/rn40fm.i rn40fm.rec 256 1 64 + $(G726) u adlo 40 bin/rv40fm.i rv40fm.rec 256 1 8 +# +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s -> A law output +# + $(G726) a adlo 40 bin/rn40fm.i rn40fc.rec 256 1 64 + $(G726) a adlo 40 bin/rv40fm.i rv40fc.rec 256 1 8 +# +# +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(G726) a adlo 40 bin/i40 ri40fa.rec 256 1 64 + $(G726) u adlo 40 bin/i40 ri40fm.rec 256 1 64 + +comp40: +# +# ================================================================= +# COMPARISON OF FILES ! +# ================================================================= +# +# Compare ADPCM/ Coder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.i nrm.a40 256 1 64 + $(DIFF) bin/rv40fa.i ovr.a40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, A law +# + $(DIFF) bin/rn40fa.o rn40fa.rec 256 1 64 + $(DIFF) bin/rv40fa.o rv40fa.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM x kbit/s -> mu law output +# + $(DIFF) bin/rn40fx.o rn40fx.rec 256 1 64 + $(DIFF) bin/rv40fx.o rv40fx.rec 256 1 8 +# +# +# Compare ADPCM/ Coder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.i nrm.m40 256 1 64 + $(DIFF) bin/rv40fm.i ovr.m40 256 1 8 +# +# Compare ADPCM/ Decoder for normal and overload sequences, mu law +# + $(DIFF) bin/rn40fm.o rn40fm.rec 256 1 64 + $(DIFF) bin/rv40fm.o rv40fm.rec 256 1 8 +# +# Compare ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM x kbit/s -> A law output +# + $(DIFF) bin/rn40fc.o rn40fc.rec 256 1 64 + $(DIFF) bin/rv40fc.o rv40fc.rec 256 1 8 +# +# +# Compare ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law +# + $(DIFF) bin/ri40fa.o ri40fa.rec 256 1 64 + $(DIFF) bin/ri40fm.o ri40fm.rec 256 1 64 + +# +# ---------------------------------------------------------------------------- +# Test the implementation for vbr-g726 (compliance) +# ---------------------------------------------------------------------------- +test-vbr: proc-vbr comp-tv +proc-vbr: bin/rn16fa.o clean proc16-vbr proc24-vbr proc32-vbr proc40-vbr +comp-vbr-tv: comp-tv + +proc16-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 16 bin/nrm.a nrm.a16 16 1 1024 + $(VBR) -law a -enc -rate 16 bin/ovr.a ovr.a16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 16 bin/rn16fa.i rn16fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fa.i rv16fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 16kbit/s -> mu law output + $(VBR) -law u -dec -rate 16 bin/rn16fa.i rn16fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fa.i rv16fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 16 bin/nrm.m nrm.m16 16 1 1024 + $(VBR) -law u -enc -rate 16 bin/ovr.m ovr.m16 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 16 bin/rn16fm.i rn16fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/rv16fm.i rv16fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 16kbit/s ->A law output + $(VBR) -law a -dec -rate 16 bin/rn16fm.i rn16fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 16 bin/rv16fm.i rv16fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 16 bin/i16 ri16fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 16 bin/i16 ri16fm.rec 16 1 1024 + +proc24-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 24 bin/nrm.a nrm.a24 16 1 1024 + $(VBR) -law a -enc -rate 24 bin/ovr.a ovr.a24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 24 bin/rn24fa.i rn24fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fa.i rv24fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 24kbit/s -> mu law output + $(VBR) -law u -dec -rate 24 bin/rn24fa.i rn24fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fa.i rv24fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 24 bin/nrm.m nrm.m24 16 1 1024 + $(VBR) -law u -enc -rate 24 bin/ovr.m ovr.m24 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 24 bin/rn24fm.i rn24fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/rv24fm.i rv24fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 24kbit/s ->A law output + $(VBR) -law a -dec -rate 24 bin/rn24fm.i rn24fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 24 bin/rv24fm.i rv24fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 24 bin/i24 ri24fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 24 bin/i24 ri24fm.rec 16 1 1024 + +proc32-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 32 bin/nrm.a nrm.a32 16 1 1024 + $(VBR) -law a -enc -rate 32 bin/ovr.a ovr.a32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 32 bin/rn32fa.i rn32fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fa.i rv32fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 32kbit/s -> mu law output + $(VBR) -law u -dec -rate 32 bin/rn32fa.i rn32fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fa.i rv32fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 32 bin/nrm.m nrm.m32 16 1 1024 + $(VBR) -law u -enc -rate 32 bin/ovr.m ovr.m32 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 32 bin/rn32fm.i rn32fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/rv32fm.i rv32fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 32kbit/s ->A law output + $(VBR) -law a -dec -rate 32 bin/rn32fm.i rn32fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 32 bin/rv32fm.i rv32fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 32 bin/i32 ri32fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 32 bin/i32 ri32fm.rec 16 1 1024 + +proc40-vbr: +# Process ADPCM/ Coder for normal and overload sequences, A law + $(VBR) -law a -enc -rate 40 bin/nrm.a nrm.a40 16 1 1024 + $(VBR) -law a -enc -rate 40 bin/ovr.a ovr.a40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, A law + $(VBR) -law a -dec -rate 40 bin/rn40fa.i rn40fa.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fa.i rv40fa.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# A law input -> ADPCM 40kbit/s -> mu law output + $(VBR) -law u -dec -rate 40 bin/rn40fa.i rn40fx.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fa.i rv40fx.rec 16 1 128 +# Process ADPCM/ Coder for normal and overload sequences, mu law + $(VBR) -law u -enc -rate 40 bin/nrm.m nrm.m40 16 1 1024 + $(VBR) -law u -enc -rate 40 bin/ovr.m ovr.m40 16 1 128 +# Process ADPCM/ Decoder for normal and overload sequences, mu law + $(VBR) -law u -dec -rate 40 bin/rn40fm.i rn40fm.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/rv40fm.i rv40fm.rec 16 1 128 +# Process ADPCM/ Cross-decoder for normal and overload sequences, +# mu law input -> ADPCM 40kbit/s ->A law output + $(VBR) -law a -dec -rate 40 bin/rn40fm.i rn40fc.rec 16 1 1024 + $(VBR) -law a -dec -rate 40 bin/rv40fm.i rv40fc.rec 16 1 128 +# Process ADPCM/ Decode-only for the same input ADPCM sequence, A and mu law + $(VBR) -law a -dec -rate 40 bin/i40 ri40fa.rec 16 1 1024 + $(VBR) -law u -dec -rate 40 bin/i40 ri40fm.rec 16 1 1024 + +# ========================================= +# Process by batch +# ========================================= +batchtest: + batch test-g726 + +batchtest-vbr: + echo make -f makefile.unx test-vbr | batch diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/ts-crcs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/ts-crcs Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,137 @@ +CRC-32 for the G.726 reset test vectors (in binary +format) for Little Endian (LE) and Big Endian (BE) +representations. File size in bytes. + +Test Vector CRC32-LE CRC32-BE Size +-------------------------------------------- +hi16fa.o B5529D15 47C0785A 32768 +hi16fm.o 45E2CAAF F80486CA 32768 +hi24fa.o 6C651039 A61788B3 32768 +hi24fm.o 90AAC369 D04CA4E8 32768 +hi32fa.o 032BDC9F 58ACCF65 32768 +hi32fm.o E609A301 AF6D5CA8 32768 +hi40fa.o 4288E847 FFE277CE 32768 +hi40fm.o 6760CEC6 7816567C 32768 +hn16fa.i D9452B67 56E3E70E 32768 +hn16fa.o 5769BB42 C49C3B93 32768 +hn16fc.o AAA64473 699A7089 32768 +hn16fm.i 462D3AA7 81168248 32768 +hn16fm.o 0D64BF7B CC47196D 32768 +hn16fx.o 648374B7 2D4E2BFE 32768 +hn24fa.i 4E2EF68C EFE78405 32768 +hn24fa.o B4C17299 0F5EF21B 32768 +hn24fc.o 8A87D98A 27823AFC 32768 +hn24fm.i 0D3CC715 943F776D 32768 +hn24fm.o CB056348 A1429857 32768 +hn24fx.o 53FE3ED6 883FBA15 32768 +hn32fa.i 7D201403 E218EE68 32768 +hn32fa.o C48CCAA0 2812441E 32768 +hn32fc.o F75D34B7 FAF1B673 32768 +hn32fm.i 8DA380B1 6E1F18F8 32768 +hn32fm.o 7B33BE0F 4707FD2D 32768 +hn32fx.o 95D29FC4 A8471A2F 32768 +hn40fa.i ABFFE249 EB4D4CC8 32768 +hn40fa.o 45FDCFB2 E7019BCA 32768 +hn40fc.o 58A6ECAB 0B32E6DA 32768 +hn40fm.i 31AEF693 05EA2049 32768 +hn40fm.o C60E674F C72CA1DD 32768 +hn40fx.o 64EBB5F0 458F6CFE 32768 +hv16fa.i 0ED5BB8D 02871A62 4096 +hv16fa.o 28C326A4 CD2A9F52 4096 +hv16fc.o E9ADCF3D C2DEAD6C 4096 +hv16fm.i C869A3A1 B2468458 4096 +hv16fm.o F9939DFA 26F630F6 4096 +hv16fx.o 940B4611 63C930E3 4096 +hv24fa.i B0C1B439 1D98BE10 4096 +hv24fa.o 2C840BB3 51219DD4 4096 +hv24fc.o 34A1F26F C39F3603 4096 +hv24fm.i 5D5606C5 32A96290 4096 +hv24fm.o 479FEFCF 21941584 4096 +hv24fx.o E98FB2C8 E0A3586C 4096 +hv32fa.i CBD2C051 BFC778DA 4096 +hv32fa.o 5F1881FA 11BD5753 4096 +hv32fc.o 9FFE57B4 4D07B42C 4096 +hv32fm.i 5AA75423 AE3F9D94 4096 +hv32fm.o D80DC677 0C5908C2 4096 +hv32fx.o A2087C94 63B94349 4096 +hv40fa.i E962BCD1 0DAD416C 4096 +hv40fa.o AA371F3D 31E7C704 4096 +hv40fc.o 32A2442B 769C6D46 4096 +hv40fm.i 8524772F 4DF35238 4096 +hv40fm.o 84955691 27A3EA79 4096 +hv40fx.o DB152F7A A2520940 4096 +i16 BECD68D4 03EA9895 32768 +i24 B9E07E62 43383791 32768 +i32 3224EF71 3911CECB 32768 +i40 6769DB08 7103987C 32768 +i_ini_16.a CC96CCF5 1176CC45 7168 +i_ini_16.m 8919EF2D 41096168 7168 +i_ini_24.a 975DCD55 04D971FA 7168 +i_ini_24.m 241A3FC6 2551CC02 7168 +i_ini_32.a 29C119E3 931DD788 7168 +i_ini_32.m AC21C124 16F5C8DA 7168 +i_ini_40.a C28DE49D CC43859B 7168 +i_ini_40.m 352F8ADA 0C7A9F0F 7168 +nrm.a DC0EF6B7 1D6924C9 32768 +nrm.m 037E3570 0D452065 32768 +ovr.a 44DB842D D31DFB06 4096 +ovr.m 70961D8C F05DA66F 4096 +pcm_init.a 24911525 C5BA738C 7168 +pcm_init.m 3F549981 2D8C4F06 7168 +ri16fa.o C0192185 66DF7498 32768 +ri16fm.o D26DE562 A5F2C3C1 32768 +ri24fa.o C3CF7644 066AB91A 32768 +ri24fm.o 396DB9DF AB984104 32768 +ri32fa.o D6F2A3C1 E1927547 32768 +ri32fm.o E609A301 AF6D5CA8 32768 +ri40fa.o B3029B33 A173411F 32768 +ri40fm.o 6760CEC6 7816567C 32768 +rn16fa.i C6AA81F4 63CA1ADD 32768 +rn16fa.o D61EE62F 0DD79B47 32768 +rn16fc.o 5AC460AA 042DED19 32768 +rn16fm.i BFE70690 F2F5DAD4 32768 +rn16fm.o F3108A98 6C698CF5 32768 +rn16fx.o 114D3036 89A9363C 32768 +rn24fa.i F1680970 79796E36 32768 +rn24fa.o B380AFBE 2347CC1F 32768 +rn24fc.o 8A98E842 38B3F2FC 32768 +rn24fm.i 701FFD16 B09BC5E2 32768 +rn24fm.o 44EF8D62 2E324D8B 32768 +rn24fx.o 6F40C57C 3520C131 32768 +rn32fa.i 5EF75844 EC33169F 32768 +rn32fa.o FD1F5F59 B8347FFD 32768 +rn32fc.o 5ED82AFA C341A89F 32768 +rn32fm.i 4D71ED7D 061E7987 32768 +rn32fm.o EE717250 BA8120E5 32768 +rn32fx.o 1681D37C 288E6538 32768 +rn40fa.i 769F045C 86D790A7 32768 +rn40fa.o 4E3B220F FA330705 32768 +rn40fc.o 0A8E4632 4B7A4969 32768 +rn40fm.i 158CB375 930C60BA 32768 +rn40fm.o 9037488A 4DC747E8 32768 +rn40fx.o B83BA25A 439509D0 32768 +rv16fa.i E67CE2ED 130A4925 4096 +rv16fa.o D478BA53 CF3E1409 4096 +rv16fc.o 972846FF F62BD261 4096 +rv16fm.i 571D26B4 7927341E 4096 +rv16fm.o 3AD3EBB9 6A0ED20B 4096 +rv16fx.o 25BDC120 DEA725D8 4096 +rv24fa.i FB9886BD 407E7D35 4096 +rv24fa.o D0EA2D22 868F708F 4096 +rv24fc.o 63811C68 8BC41477 4096 +rv24fm.i 25D80A39 BB6C3CD8 4096 +rv24fm.o 17FC8031 478AD7F4 4096 +rv24fx.o 7F38FBEB 5E42F526 4096 +rv32fa.i 59B7137C 089ACE16 4096 +rv32fa.o 4614EE1A 71E4C6C5 4096 +rv32fc.o 1A2CF9F6 FA992E7E 4096 +rv32fm.i 4A2299DC F188380E 4096 +rv32fm.o 79C689AB 1685AA63 4096 +rv32fx.o C166F780 0B5E8E54 4096 +rv40fa.i 48D96E4A 67ECA4CD 4096 +rv40fa.o 942603DB 4E8CFAE3 4096 +rv40fc.o 2A144A83 77D5B291 4096 +rv40fm.i 1D05E86B BE4CAA7A 4096 +rv40fm.o 7363540A B3F62CED 4096 +rv40fx.o 65540CD8 E861BB32 4096 +-------------------------------------------- diff -r 9cadc470e3da -r 13be24d74cd2 intercom/g726/vbr-g726.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/g726/vbr-g726.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,602 @@ +/* 21.Mar.2000 V1.3 + ============================================================================ + + VBR-G726.C + ~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Demonstration program for UGST/ITU-T G.726 module using the variable + bit rate feature. This version accepts either linear or G.711 A/u-law + input. Since this implementation of the G.726 requires G.711 compressed + samples, linear samples are converted to G.711 format before being + processed. Therefore, the same ammount of quantization distortion should + be expect either way. + + The modules called have been originally written in Fortran, and were + translated into C by the converter f2c, version of October 15, 1990 + at 19:58:17. + + Input data is supposed to be aligned at word boundaries, i.e., + organized in 16-bit words, following the operating system normal + organization (low-byte first for VMS and DOS; high byte first for most + Unix systems). Linear samples are supposed to be 16-bit right-adjusted. + G711 compressed data is supposed to be in the 8 LEAST + significant bits of the word and the ADPCM data is in the LEAST 5 + bits. Both are without sign extension. + + Output data will be generated in the same format as decribed above for + the input data. + + Usage: + ~~~~~~ + $ VBR-G726 [-options] InpFile OutFile + [FrameSize [1stBlock [NoOfBlocks [Reset]]]] + where: + InpFile is the name of the file to be processed; + OutFile is the name with the processed data; + FrameSize is the frame size, in number of samples; the bitrate + will only change in the boundaries of a frame + [default: 16 samples] + 1stBlock is the number of the first block of the input file + to be processed [default: 1st block] + NoOfBlocks is the number of blocks to be processed, starting on + block "1stBlock" [default: all blocks] + + Options: + -law # the letters A or a for G.711 A-law, letter u for + G.711 u-law, or letter l for linear. If linear is + chosen, A-law is used to compress/expand samples to/from + the G.726 routines. Default is A-law. + -rate # is the bit-rate (in kbit/s): 40, 32, 24 or 16 (in kbit/s); + or a combination of them using dashes (e.g. 32-24 or + 16-24-32). Default is 32 kbit/s. + -frame # Number of samples per frame for switching bit rates. + Default is 16 samples (or 2ms) + -enc run only the G.726 encoder on the samples + [default: run encoder and decoder] + -dec run only the G.726 decoder on the samples + [default: run encoder and decoder] + -noreset don't apply reset to the encoder/decoder + -?/-help print help message + + Example: + $ vbr-G726 -law u -enc -rate 32 voice.ref voice.adp 256 3 45 + + The command above takes the samples in file "voice.ref", already + in mu law format, processes the data through the G726 encoder + only at a rate of 32 bkit/s, saving them into the file + "voice.rel". The processing starts at block 3 for 45 blocks, + each block being 256 samples wide. + + Variables: + ~~~~~~~~~~ + law law to use (either A or u) + conv desired processing + rate desired rate + inpfil input file name; + outfil output file name; + N block size; + N1 first block to process; + N2 no. of blocks to process; + + Exit values: + ~~~~~~~~~~~~ + 0 success (all but VMS); + 1 success (only in VMS); + 2 error opening input file; + 3 error creating output file; + 4 error moving pointer to desired start of conversion; + 5 error reading input file; + 6 error writing to file; + 7 invalid law + 8 invalid conversion + 9 invalid rate + + Original author: + ~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto + Comsat Laboratories Tel: +1-301-428-4516 + 22300 Comsat Drive Fax: +1-301-428-9287 + Clarksburg MD 20871 - USA E-mail: simao@ctd.comsat.com + + History: + ~~~~~~~~ + 10/Mar/1995 v1.0 Created based on vbr-g726.c + 22/Feb/1996 v1.1 Removed compilation warnings, included headers as + suggested by Kirchherr (FI/DBP Telekom) to run under + OpenVMS/AXP + 22/Jul/1997 v1.2 Changed static allocation for data arrays to allow longer + frame sizes. Fix based on modifications by R. Kirchherr + + 21.Mar.2000 v1.3 Corrected bug when the bitrate is not specified by + the user. Corrected bug that made incorrect + calculation on total number of blocks to process + when the block size is not a multiple of the file + size. + ============================================================================ +*/ + +/* ..... General definitions for UGST demo programs ..... */ +#include "ugstdemo.h" + +/* ..... General include ..... */ +#include +#include +#include +#include +#include + +#if defined(VMS) +#include +#include +#else /* Unix/DOS */ +#include +#endif + +/* ..... G.726 module as include functions ..... */ +#include "g726.h" +#include "g711.h" + +/* + ------------------------------------------------------------------------- + void parse_rate(char *str, short *rate); + ~~~~~~~~~~~~~~~ + Parses string str with a list of bitrates for the operation of the G726 + algorithm and return a list of them in rate, and the number of rates read. + + Parameters: + ~~~~~~~~~~~ + str ..... string pointing to a list of dash-separated bitrates to be used. + Valid examples are: 16 (single rate), 32-24 (duo-rate), etc. + rate .... string of short numbers with each of the specified rates. + + Return: + ~~~~~~~ + Returns the number of bitrates for the ADPCM operation, 0 if str is + empty or improper, and -1 if there are too many rates requested. + + History: + ~~~~~~~~ + 10.Mar.95 v1.0 Created + ------------------------------------------------------------------------- +*/ +int parse_rate(str, rate) +char *str; +short **rate; +{ + char *s = str; + int count = 1, i; + + if (str == NULL) + return 0; + + while ((s = strchr(s, '-')) != NULL) { + s++; + count++; + } + + /* Allocates memory for the necessary number of rates */ + *rate = (short *) calloc(sizeof(short), count); + if (*rate == NULL) + return (-1); + + /* Save rates in the array */ + for (s = strtok(str, "-"), i = 0; i < count; i++) { + /* Convert to short & save */ + (*rate)[i] = atoi(s); + + /* Classification of rate - return 0 if invalid rate was specified */ + if ((*rate)[i] > 5) { + if ((*rate)[i] == 40) + (*rate)[i] = 5; + else if ((*rate)[i] == 32) + (*rate)[i] = 4; + else if ((*rate)[i] == 24) + (*rate)[i] = 3; + else if ((*rate)[i] == 16) + (*rate)[i] = 2; + else + return (0); + } + + /* Update s to the next valid rate number */ + s = strtok(NULL, "-"); + } + + /* Return the number of rates */ + return (count); +} + +/* .................... End of parse_rate() ........................... */ + + +/* + ------------------------------------------------------------------------- + void display_usage(void); + ~~~~~~~~~~~~~~~~~~ + Display proper usage for the demo program. Generated automatically from + program documentation. + + History: + ~~~~~~~~ + 10.Mar.95 v1.0 Created . + ------------------------------------------------------------------------- +*/ +#define P(x) printf x +void display_usage() +{ + P(("Version 1.3 of 21/Mar/2000 \n\n")); + + P((" VBR-G726.C \n")); + P((" Demonstration program for UGST/ITU-T G.726 module using the variable\n")); + P((" bit rate feature. This version accepts either linear or G.711 A/u-law\n")); + P((" input. Since this implementation of the G.726 requires G.711 compressed\n")); + P((" samples, linear samples are converted to G.711 format before being\n")); + P((" processed. Therefore, the same ammount of quantization distortion should\n")); + P((" be expect either way.\n")); + P((" Input data is supposed to be aligned at word boundaries, i.e.,\n")); + P((" organized in 16-bit words, following the operating system normal\n")); + P((" organization (low-byte first for VMS and DOS; high byte first for most\n")); + P((" Unix systems). Linear samples are supposed to be 16-bit right-adjusted. \n")); + P((" G711 compressed data is supposed to be in the 8 LEAST\n")); + P((" significant bits of the word and the ADPCM data is in the LEAST 5\n")); + P((" bits. Both are without sign extension.\n")); + P((" \n")); + P((" Output data will be generated in the same format as decribed above for\n")); + P((" the input data.\n")); + P((" \n")); + P((" Usage:\n")); + P((" VBR-G726 [-options] InpFile OutFile \n")); + P((" [FrameSize [1stBlock [NoOfBlocks [Reset]]]]\n")); + P((" where:\n")); + P((" InpFile is the name of the file to be processed;\n")); + P((" OutFile is the name with the processed data;\n")); + P((" FrameSize is the frame size, in number of samples; the bitrate \n")); + P((" will only change in the boundaries of a frame \n")); + P((" [default: 16 samples]\n")); + P((" 1stBlock is the number of the first block of the input file\n")); + P((" to be processed [default: 1st block]\n")); + P((" NoOfBlocks is the number of blocks to be processed, starting on\n")); + P((" block \"1stBlock\" [default: all blocks]\n")); + P(("\n")); + P((" Options:\n")); + P((" -law # the letters A or a for G.711 A-law, letter u for \n")); + P((" G.711 u-law, or letter l for linear. If linear is\n")); + P((" chosen, A-law is used to compress/expand samples to/from\n")); + P((" the G.726 routines. Default is A-law.\n")); + P((" -rate # is the bit-rate (in kbit/s): 40, 32, 24 or 16 (in kbit/s); \n")); + P((" or a combination of them using dashes (e.g. 32-24 or\n")); + P((" 16-24-32). Default is 32 kbit/s.\n")); + P((" -frame # Number of samples per frame for switching bit rates.\n")); + P((" Default is 16 samples (or 2ms) \n")); + P((" -enc run only the G.726 encoder on the samples \n")); + P((" [default: run encoder and decoder]\n")); + P((" -dec run only the G.726 decoder on the samples \n")); + P((" [default: run encoder and decoder]\n")); + P((" -noreset don't apply reset to the encoder/decoder\n")); + P((" -?/-help print help message\n")); + P(("\n")); + + /* Quit program */ + exit(-128); +} + +#undef P +/* .................... End of display_usage() ........................... */ + + +void G726_initEncode(G726_state *encoder_state) +{ + memset(encoder_state, 0, sizeof(G726_state)); +} + +void G726_initDecode(G726_state *decoder_state) +{ + memset(decoder_state, 0, sizeof(G726_state)); +} + +void g726pack(Byte *packed, short *in, int cnt) +{ + int i; + for (i = 0; i <= cnt; i += 2, ++packed, ++in) { + *packed = (*in & 0xF); + ++in; + *packed += (*in & 0xF) * 16; + } +} + +void g726unpack(short *out, Byte *packed, int cnt) +{ + int i; + for (i = 0; i <= cnt; i += 2, ++packed, ++out) { + *out = (*packed & 0xF); + ++out; + *out = (*packed & 0xF0) / 16; + } +} + +/* + ************************************************************************** + *** *** + *** Demo-Program for testing the correct implementation *** + *** and to show how to use the programs *** + *** *** + ************************************************************************** +*/ +int main(argc, argv) +int argc; +char *argv[]; +{ + G726_state encoder_state, decoder_state; + long N = 16, N1 = 1, N2 = 0, cur_blk, smpno; + short *tmp_buf, *inp_buf, *out_buf, reset = 1; + Byte tmpb_buf[N], outb_buf[N]; + short inp_type, out_type, *rate = 0; + char encode = 1, decode = 1, law[4] = "A", def_rate[] = "32"; + int rateno = 1, rate_idx; + + /* General-purpose, progress indication */ + static char quiet = 0, funny[9] = "|/-\\|/-\\"; + +/* File variables */ + char FileIn[80], FileOut[80]; + FILE *Fi, *Fo; + int inp, out; + long start_byte; +#ifdef VMS + char mrs[15]; +#endif + +/* + * ......... PARAMETERS FOR PROCESSING ......... + */ + + /* GETTING OPTIONS */ + + if (argc < 2) + display_usage(); + else { + while (argc > 1 && argv[1][0] == '-') + if (strcmp(argv[1], "-noreset") == 0) { + /* No reset */ + reset = 0; + + /* Update argc/argv to next valid option/argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-enc") == 0) { + /* Encoder-only operation */ + encode = 1; + decode = 0; + + /* Move argv over the option to the next argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-dec") == 0) { + /*Decoder-only operation */ + encode = 0; + decode = 1; + + /* Move argv over the option to the next argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-law") == 0) { + /* Define law for operation: A, u, or linear */ + switch (toupper(argv[2][0])) { + case 'A': + law[0] = '1'; + break; + case 'U': + law[0] = '0'; + break; + case 'L': + law[0] = '2'; + break; + default: + HARAKIRI(" Invalid law (A or u)! Aborted...\n", 7); + } + + /* Move argv over the option to the next argument */ + argv += 2; + argc -= 2; + } else if (strcmp(argv[1], "-frame") == 0) { + /* Define Frame size for rate change during operation */ + N = atoi(argv[2]); + + /* Move argv over the option to the next argument */ + argv += 2; + argc -= 2; + } else if (strcmp(argv[1], "-rate") == 0) { + /*Define rate(s) for operation */ + rateno = parse_rate(argv[2], &rate); + if (rateno == 0) { + fprintf(stderr, "Invalid bitrate list: %s\n", argv[2]); + exit(9); + } + /* Move argv over the option to the next argument */ + argv += 2; + argc -= 2; + } else if (strcmp(argv[1], "-q") == 0) { + /* Don't print progress indicator */ + quiet = 1; + + /* Move argv over the option to the next argument */ + argv++; + argc--; + } else if (strcmp(argv[1], "-?") == 0 + || strcmp(argv[1], "-help") == 0) { + /* Print help */ + display_usage(); + } else { + fprintf(stderr, + "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); + display_usage(); + } + } + + /* Now get regular parameters */ + GET_PAR_S(1, "_Input File: .................. ", FileIn); + GET_PAR_S(2, "_Output File: ................. ", FileOut); + FIND_PAR_L(3, "_Block Size: .................. ", N, N); + FIND_PAR_L(4, "_Starting Block: .............. ", N1, N1); + FIND_PAR_L(5, "_No. of Blocks: ............... ", N2, N2); + + /* Uses default rate if none is given */ + if (rate == 0) + rateno = parse_rate(def_rate, &rate); + + /* Inform user of the compading law used: 0->u, 1->A, 2->linear */ + fprintf(stderr, "Using %s\n", + law[0] == '1' ? "A-law" : (law[0] == '0' ? "u-law" : "linear PCM")); + + /* Find starting byte in file */ + start_byte = sizeof(short) * (long) (--N1) * (long) N; + + /* Check if is to process the whole file */ + if (N2 == 0) { + struct stat st; + + /* ... find the input file size ... */ + stat(FileIn, &st); + N2 = ceil((st.st_size - start_byte) / (double) (N * sizeof(short))); + } + + /* Define correct data I/O types */ + if (encode && decode) { + inp_type = out_type = (law[0] == '2' ? IS_LIN : IS_LOG); + } else if (encode) { + inp_type = law[0] == '2' ? IS_LIN : IS_LOG; + out_type = IS_ADPCM; + } else { + inp_type = IS_ADPCM; + out_type = law[0] == '2' ? IS_LIN : IS_LOG; + } + + /* Force law to be used *by the ADPCM* to A-law, if input is linear */ + if (law[0] == '2') + law[0] = '1'; + +/* + * ...... MEMORY ALLOCATION ......... + */ + + if ((inp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((out_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((tmp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + +/* + * ......... FILE PREPARATION ......... + */ + + /* Opening input file; abort if there's any problem */ + if ((Fi = fopen(FileIn, "rb")) == NULL) + KILL(FileIn, 2); + inp = fileno(Fi); + + /* Creates output file */ +#ifdef VMS + sprintf(mrs, "mrs=%d", 512); +#endif + if ((Fo = fopen(FileOut, WB)) == NULL) + KILL(FileOut, 3); + out = fileno(Fo); + + /* Move pointer to 1st block of interest */ + if (fseek(Fi, start_byte, 0) < 0l) + KILL(FileIn, 4); + +/* + * ......... PROCESSING ACCORDING TO ITU-T G.726 ......... + */ + /* Reset VBR counters */ + rate_idx = 0; + + for (cur_blk = 0; cur_blk < N2; cur_blk++) { + /* Set the proper rate index */ + rate_idx = cur_blk % rateno; + + /* Print progress flag */ + if (!quiet) +#ifdef DISPLAY_CURRENT_RATE + fprintf(stderr, "%d-", 8 * rate[rate_idx]); +#else + fprintf(stderr, "%c\r", funny[cur_blk % 8]); +#endif + + /* Read a block of samples */ + if ((smpno = fread(inp_buf, sizeof(short), N, Fi)) < 0) + KILL(FileIn, 5); + + /* Compress linear input samples */ + if (inp_type == IS_LIN) { + /* Compress using A-law */ + alaw_compress(smpno, inp_buf, tmpb_buf); + + /* copy temporary buffer over input buffer */ + // memcpy(inp_buf, tmp_buf, sizeof(short) * smpno); + } + + /* Check if reset is needed */ + reset = (reset == 1 && cur_blk == 0) ? 1 : 0; + + /* Carry out the desired operation */ + if (encode && !decode) + G726_encode(tmpb_buf, out_buf, smpno, law, + rate[rate_idx], reset, &encoder_state); + else if (decode && !encode) + G726_decode(inp_buf, outb_buf, smpno, law, + rate[rate_idx], reset, &decoder_state); + else if (encode && decode) { + Byte g726_buf[N/2]; + + G726_encode(tmpb_buf, tmp_buf, smpno, law, + rate[rate_idx], reset, &encoder_state); + // printf ("rate[rate_idx] = %d\n", rate[rate_idx]); + g726pack(g726_buf, tmp_buf, smpno); + + g726unpack(tmp_buf, g726_buf, smpno); + + G726_decode(tmp_buf, outb_buf, smpno, law, + rate[rate_idx], reset, &decoder_state); + } + + /* Expand linear input samples */ + if (out_type == IS_LIN) { + /* Compress using A-law */ + alaw_expand(smpno, outb_buf, tmp_buf); + + /* copy temporary buffer over input buffer */ + memcpy(out_buf, tmp_buf, sizeof(short) * smpno); + } + + /* Write ADPCM output word */ + if ((smpno = fwrite(out_buf, sizeof(short), smpno, Fo)) < 0) + KILL(FileOut, 6); + } + +/* + * ......... FINALIZATIONS ......... + */ + + /* Free allocated memory */ + free(tmp_buf); + free(out_buf); + free(inp_buf); + free(rate); + + /* Close input and output files */ + fclose(Fi); + fclose(Fo); + + /* Exit with success for non-vms systems */ +#ifndef VMS + return (0); +#endif +} + +/* ............................. end of main() ............................. */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/Makefile Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,132 @@ +#-------------------------------------------------------------------------- +# RPELTP makefile for Unix C compilers +#-------------------------------------------------------------------------- +# Original Copyright message: +# Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +# Universitaet Berlin. See the accompanying file "COPYRIGHT" for +# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +# +# File adapted by simao@ctd.comsat.com for the UGST distribution. +#-------------------------------------------------------------------------- + +# Machine dependent flags you must configure to port + +######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1) +SASR = -DSASR + +######### MUST Define USE_FLOAT_MUL for bit exact performance to GSM Spec. +MULHACK = -DUSE_FLOAT_MUL + +# Choose a compiler. The code works both with ANSI and K&R-C. +# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to +# compile without, function prototypes in the header files. +# +# You can use the -DSTUPID_COMPILER to circumvent some compilers' +# static limits regarding the number of subexpressions in a statement. + +CC = cc +CCFLAGS = -c -UNeedFunctionPrototypes -I../utl +#CCFLAGS = -g -c -UNeedFunctionPrototypes -I../utl +#CCFLAGS = -c -DSTUPID_COMPILER -I../utl + +#CC = acc +#CCFLAGS = -c -O -I../utl + +#CC = gcc +#CCFLAGS = -c -O2 -DNeedFunctionPrototypes=1 -fno-builtin -I../utl +#CCFLAGS = -c -g -Wall -DNeedFunctionPrototypes=1 -fno-builtin -I../utl + +#-------------------------------------------------------------------------- +# +# You shouldn't have to configure below this line if you're porting. +# +#-------------------------------------------------------------------------- + +# Tools +RM=rm -f + +# Local Directories +INC = . + +# Flags + +DEBUG = -DNDEBUG +######### Remove -DNDEBUG to enable assertions. + +CFLAGS = $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) -I$(INC) -I../utl +######### It's $(CC) $(CFLAGS) + + +#-------------------------------------------------------------------------- +# Headers +HEADERS = proto.h unproto.h config.h private.h gsm.h rpeltp.h + +#-------------------------------------------------------------------------- +# Sources +GSM_SOURCES = add.c code.c debug.c decode.c long_ter.c lpc.c \ + preproce.c rpe.c gsm_dest.c gsm_deco.c gsm_enco.c \ + gsm_expl.c gsm_impl.c gsm_crea.c gsm_prin.c gsm_opti.c \ + rpeltp.c short_te.c table.c + +DEMO_SOURCES = rpedemo.c ../g711/g711.c + +SOURCES = $(GSM_SOURCES) $(DEMO_SOURCES) + + +#-------------------------------------------------------------------------- +# Object files +GSM_OBJECTS = add.o code.o debug.o decode.o long_ter.o lpc.o \ + preproce.o rpe.o gsm_dest.o gsm_deco.o gsm_enco.o \ + gsm_expl.o gsm_impl.o gsm_crea.o gsm_prin.o gsm_opti.o \ + rpeltp.o short_te.o table.o gsm.o + +DEMO_OBJECTS = rpedemo.o g711.o + +OBJECTS = $(GSM_OBJECTS) $(DEMO_OBJECTS) + +# ------------------------------------------------ +# Implicit rules +# ------------------------------------------------ +.c.o: + $(CC) $(CFLAGS) $? + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +all:: gsm.a rpedemo + +gsm.a: $(GSM_OBJECTS) + ar rcs $@ $(GSM_OBJECTS) + +anyway: clean rpedemo + +clean: + $(RM) $(OBJECTS) rpedemo *.gsm *.gsm.raw gsm.a + +cleantest: + echo No test file processing available in this directory + +veryclean: clean + $(RM) rpedemo + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711.o: ../g711/g711.c + $(CC) $(CFLAGS) -I../g711 ../g711/g711.c + +rpedemo.o: rpedemo.c ../g711/g711.h + $(CC) $(CFLAGS) -I../g711 rpedemo.c + +rpedemo: $(OBJECTS) + $(CC) -o rpedemo $(DEMO_OBJECTS) gsm.a + +# ------------------------------------------------ +# Run add < add_test.dta to make sure the +# basic arithmetic functions work as intended. +# ------------------------------------------------ +add: add_test.o + $(CC) $(LFLAGS) -o add add_test.o + +addtst: add add_test.dta + add < add_test.dta > /dev/null diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/README Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,13 @@ + + +# encode english +time ./rpedemo -l -enc ../tv2/voice.raw voice.gsm + +# decode +time ./rpedemo -l -dec voice.gsm voice.gsm.raw + +# encode french/japanise +time ./rpedemo -l -enc ../tv2/speech.raw speech.gsm + +# decode +time ./rpedemo -l -dec speech.gsm speech.gsm.raw diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/add.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/add.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,256 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/add.c,v 1.2 1993/01/29 18:23:15 jutta Exp $ */ + +/* + * See private.h for the more commonly used macro versions. + */ + +#include +#include + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +#define saturate(x) \ + ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) + +word gsm_add P2((a, b), word a, word b) +{ + longword sum = (longword) a + (longword) b; + return saturate(sum); +} + +word gsm_sub P2((a, b), word a, word b) +{ + longword diff = (longword) a - (longword) b; + return saturate(diff); +} + +word gsm_mult P2((a, b), word a, word b) +{ + if (a == MIN_WORD && b == MIN_WORD) + return MAX_WORD; + else + return (word) (SASR((longword) a * (longword) b, 15)); +} + +word gsm_mult_r P2((a, b), word a, word b) +{ + if (b == MIN_WORD && a == MIN_WORD) + return MAX_WORD; + else { + longword prod = (longword) a * (longword) b + 16384; + prod >>= 15; + return prod & 0xFFFF; + } +} + +word gsm_abs P1((a), word a) +{ + return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a; +} + +longword gsm_L_mult P2((a, b), word a, word b) +{ + assert(a != MIN_WORD || b != MIN_WORD); + return ((longword) a * (longword) b) << 1; +} + +longword gsm_L_add P2((a, b), longword a, longword b) +{ + if (a < 0) { + if (b >= 0) + return a + b; + else { + ulongword A = (ulongword) - (a + 1) + (ulongword) - (b + 1); + return A >= + (ulongword) MAX_LONGWORD ? MIN_LONGWORD : -(longword) A - 2; + } + } else if (b <= 0) + return a + b; + else { + ulongword A = (ulongword) a + (ulongword) b; + return A > (ulongword) MAX_LONGWORD ? MAX_LONGWORD : A; + } +} + +longword gsm_L_sub P2((a, b), longword a, longword b) +{ + if (a >= 0) { + if (b >= 0) + return a - b; + else { + /* a>=0, b<0 */ + + ulongword A = (ulongword) a + -(b + 1); + return A >= (ulongword) MAX_LONGWORD ? MAX_LONGWORD : (A + 1); + } + } else if (b <= 0) + return a - b; + else { + /* a<0, b>0 */ + + ulongword A = (ulongword) - (a + 1) + b; + return A >= (ulongword) MAX_LONGWORD ? MIN_LONGWORD : -A - 1; + } +} + +static unsigned char bitoff[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +word gsm_norm P1((a), longword a) +/* + * the number of left shifts needed to normalize the 32 bit + * variable L_var1 for positive values on the interval + * + * with minimum of + * minimum of 1073741824 (01000000000000000000000000000000) and + * maximum of 2147483647 (01111111111111111111111111111111) + * + * + * and for negative values on the interval with + * minimum of -2147483648 (-10000000000000000000000000000000) and + * maximum of -1073741824 ( -1000000000000000000000000000000). + * + * in order to normalize the result, the following + * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 ); + * + * (That's 'ffs', only from the left, not the right..) + */ +{ + assert(a != 0); + + if (a < 0) { + if (a <= (longword) - 1073741824) + return 0; + a = ~a; + } + + return a & 0xffff0000 + ? (a & 0xff000000 ? -1 + bitoff[(unsigned char) (0xFF & (a >> 24))] + : 7 + bitoff[(unsigned char) (0xFF & (a >> 16))]) + : (a & 0xff00 ? 15 + bitoff[(unsigned char) (0xFF & (a >> 8))] + : 23 + bitoff[(unsigned char) (0xFF & a)]); +} + +longword gsm_L_asl P2((a, n), longword a, int n) +{ + if (n >= 32) + return 0; + if (n <= -32) + return -(a < 0); + if (n < 0) + return gsm_asr(a, -n); + return a << n; +} + +word gsm_asl P2((a, n), word a, int n) +{ + if (n >= 16) + return 0; + if (n <= -16) + return -(a < 0); + if (n < 0) + return gsm_asr(a, -n); + return a << n; +} + +longword gsm_L_asr P2((a, n), longword a, int n) +{ + if (n >= 32) + return -(a < 0); + if (n <= -32) + return 0; + if (n < 0) + return a << -n; + +# ifdef SASR + return a >> n; +# else + if (a >= 0) + return a >> n; + else + return -(longword) (-(ulongword) a >> n); +# endif +} + +word gsm_asr P2((a, n), word a, int n) +{ + if (n >= 16) + return -(a < 0); + if (n <= -16) + return 0; + if (n < 0) + return a << -n; + +# ifdef SASR + return a >> n; +# else + if (a >= 0) + return a >> n; + else + return -(word) (-(uword) a >> n); +# endif +} + +/* + * (From p. 46, end of section 4.2.5) + * + * NOTE: The following lines gives [sic] one correct implementation + * of the div(num, denum) arithmetic operation. Compute div + * which is the integer division of num by denum: with denum + * >= num > 0 + */ + +word gsm_div P2((num, denum), word num, word denum) +{ + longword L_num = num; + longword L_denum = denum; + word div = 0; + int k = 15; + + /* The parameter num sometimes becomes zero. + * Although this is explicitly guarded against in 4.2.5, + * we assume that the result should then be zero as well. + */ + + /* assert(num != 0); */ + + assert(num >= 0 && denum >= num); + if (num == 0) + return 0; + + while (k--) { + div <<= 1; + L_num <<= 1; + + if (L_num >= L_denum) { + L_num -= L_denum; + div++; + } + } + + return div; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/add_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/add_test.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,308 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + * + * Updated by KIRCHHERR (FI/DBP Telekom) for Alpha VMS/Apx: included unixio.h + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/add-test/RCS/add_test.c,v 1.1 1992/10/28 00:09:10 jutta Exp $ */ + +#include +#include +#include + +#ifdef VMS +#include +#endif + +#define GSM_IMPLEMENTATION +#include "private.h" +#include "gsm.h" + +#include "add.c" + +int interactive = 1; + +char *opname; +longword L_op1, L_op2, L_expect; +word op1, op2, expect; +int do_expect; + +void help() +{ + puts(" add a b sub a b mult a b div a b"); + puts("L_add A B L_sub A B L_mult A B mult_r a b"); + puts(""); + puts("abs a norm a >> a b << a b"); + puts(" L_>> A B L_<< A B"); + +} + +char *strtek P2((str, sep), char *str, char *sep) +{ + + static char *S = (char *) 0; + char *c, *base; + + if (str) + S = str; + + if (!S || !*S) + return (char *) 0; + + /* Skip delimiters. + */ + while (*S) { + for (c = sep; *c && *c != *S; c++); + if (*c) + *S++ = 0; + else + break; + } + + base = S; + + /* Skip non-delimiters. + */ + for (base = S; *S; S++) { + + for (c = sep; *c; c++) + if (*c == *S) { + *S++ = 0; + return base; + } + } + + return base == S ? (char *) 0 : base; +} + +long value P1((s), char *s) +{ + switch (*s) { + case '-': + switch (s[1]) { + case '\0': + return MIN_WORD; + case '-': + return MIN_LONGWORD; + default: + break; + } + break; + + case '+': + switch (s[1]) { + case '\0': + return MAX_WORD; + case '+': + return MAX_LONGWORD; + default: + break; + } + default: + break; + } + + return strtol(s, (char **) 0, 0); +} + +char *parse P1((buf), char *buf) +{ + char *s, *a; + long l; + + if ((a = strchr(buf, '=')) != NULL) + *a++ = 0; + + opname = s = strtek(buf, " \t("); + if (!s) + return (char *) 0; + + op1 = op2 = L_op1 = L_op2 = 0; + + if ((s = strtek((char *) 0, "( \t,")) != NULL) { + op1 = L_op1 = value(s); + if ((s = strtek((char *) 0, ", \t)")) != NULL) + op2 = L_op2 = value(s); + } + + if (a) { + do_expect = 1; + while (*a == ' ' || *a == '\t') + a++; + expect = L_expect = value(a); + } + + return opname; +} + +void fprint_word P2((f, w), FILE * f, word w) +{ + if (!w) + putc('0', f); + else + fprintf(f, "0x%4.4x (%d%s)", + (unsigned int) w, + (int) w, w == MIN_WORD ? "/-" : (w == MAX_WORD ? "/+" : "")); +} + +void print_word P1((w), word w) +{ + fprint_word(stdout, w); +} + +void fprint_longword P2((f, w), FILE * f, longword w) +{ + if (!w) + putc('0', f); + else + fprintf(f, "0x%8.8x (%ld%s)", + w, w, w == MIN_WORD ? "/-" + : (w == MAX_WORD ? "/+" + : (w == (longword) MIN_LONGWORD ? "/--" + : (w == (longword) MAX_LONGWORD ? "/++" : "")))); +} + +void print_longword P1((w), longword w) +{ + fprint_longword(stdout, w); +} + +void do_longword P1((w), longword w) +{ + if (interactive) + print_longword(w); + if (do_expect) { + if (w != L_expect) { + if (!interactive) + fprint_longword(stderr, w); + fprintf(stderr, " != %s (%ld, %ld) -- expected ", + opname, L_op1, L_op2); + fprint_longword(stderr, L_expect); + putc('\n', stderr); + } + } else if (interactive) + putchar('\n'); +} + +void do_word P1((w), word w) +{ + if (interactive) + print_word(w); + if (do_expect) { + if (w != expect) { + if (!interactive) + fprint_word(stderr, w); + fprintf(stderr, " != %s (%ld, %ld) -- expected ", + opname, L_op1, L_op2); + fprint_word(stderr, expect); + putc('\n', stderr); + } + } else if (interactive) + putchar('\n'); +} + +int main(argc, argv) +int argc; +char *argv[]; +{ + char buf[299]; + char *c; + FILE *datain; + + if (argc > 1) + datain = fopen(argv[1], "r"); + else + datain = stdin; + + if (datain == NULL) { + perror("Invalid input file!\n"); + exit(1); + } + + interactive = isatty(fileno(datain)); + + for (;;) { + if (interactive) + fprintf(stderr, "? "); + + if (!fgets(buf, sizeof(buf), datain)) + exit(0); + if ((c = strchr(buf, '\n')) != NULL) + *c = 0; + + if (*buf == ';' || *buf == '#') + continue; + if (*buf == '\'') { + puts(buf + 1); + continue; + } + if (*buf == '\"') { + fprintf(stderr, "%s\n", buf + 1); + continue; + } + + c = parse(buf); + + if (!c) + continue; + if (!strcmp(c, "add")) { + do_word(gsm_add(op1, op2)); + continue; + } + if (!strcmp(c, "sub")) { + do_word(gsm_sub(op1, op2)); + continue; + } + if (!strcmp(c, "mult")) { + do_word(gsm_mult(op1, op2)); + continue; + } + if (!strcmp(c, "mult_r")) { + do_word(gsm_mult_r(op1, op2)); + continue; + } + if (!strcmp(c, "abs")) { + do_word(gsm_abs(op1)); + continue; + } + if (!strcmp(c, "div")) { + do_word(gsm_div(op1, op2)); + continue; + } + if (!strcmp(c, "norm")) { + do_word(gsm_norm(L_op1)); + continue; + } + if (!strcmp(c, "<<")) { + do_word(gsm_asl(op1, op2)); + continue; + } + if (!strcmp(c, ">>")) { + do_word(gsm_asr(op1, op2)); + continue; + } + if (!strcmp(c, "L_mult")) { + do_longword(gsm_L_mult(op1, op2)); + continue; + } + if (!strcmp(c, "L_add")) { + do_longword(gsm_L_add(L_op1, L_op2)); + continue; + } + if (!strcmp(c, "L_sub")) { + do_longword(gsm_L_sub(L_op1, L_op2)); + continue; + } + if (!strcmp(c, "L_<<")) { + do_longword(gsm_L_asl(L_op1, L_op2)); + continue; + } + if (!strcmp(c, "L_>>")) { + do_longword(gsm_L_asr(L_op1, L_op2)); + continue; + } + help(); + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/add_test.dta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/add_test.dta Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,435 @@ +; +; Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +; Universitaet Berlin. See the accompanying file "COPYRIGHT" for +; details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +; +; +; Lines starting with ' (in the first col) are echoed. +; Lines starting with " (in the first col) are echoed to stderr. +; Lines starting with ; or empty lines are ignored. +; +; The part after (including) a trailing '=' is what you expect; +; there will be output if the result is different. +; +; - and + by itself mean MIN_WORD and MAX_WORD, respectively; +; -- and ++ mean MIN_LONGWORD and MAX_LONGWORD. +; + +'test the basic arithmetic operations used for the rpe-ltd filtering. +' +'add ================ +' basic + + add 0 0 = 0 + add 7 4 = 11 + add 4 6 = 10 + add 1 1 = 2 + +' negative operands + + add -7 4 = -3 + add 4 -6 = -2 + add -1 -3 = -4 + add 7 -4 = 3 + add -4 6 = 2 + +' positive overflow +; (max-word = 32767) + add + 1 = + + add + + = + + add -1 + = 32766 + add 32766 2 = + + add 1 32766 = + + +' underflow +; (min-word = 32768) + + add - -1 = - + add - - = - + add 1 - = -32767 + add -32767 -2 = - + add -1 -32766 = -32767 + add -32767 -1 = - + add - + = -1 + add + - = -1 + add 0 - = - + add 0 + = + +' + +'L_add ================ +' basic + + L_add 0 0 = 0 + L_add 7 4 = 11 + L_add 4 6 = 10 + L_add 1 1 = 2 + +' negative operands + + L_add -7 4 = -3 + L_add 4 -6 = -2 + L_add -1 -3 = -4 + L_add 7 -4 = 3 + L_add -4 6 = 2 + L_add 0 -1 = -1 + +' positive overflow +; (max-longword = 2147483647) + L_add ++ 1 = ++ + L_add ++ ++ = ++ + L_add -1 ++ = 2147483646 + L_add 2147483646 2 = ++ + L_add 1 2147483645 = 2147483646 + +' underflow +; (min-longword = -2147483648) + + L_add -- -1 = -- + L_add -- -- = -- + L_add 1 -- = -2147483647 + L_add -2147483647 -2 = -- + L_add -1 -2147483646 = -2147483647 + L_add -2147483647 -1 = -- + L_add -- ++ = -1 + L_add ++ -- = -1 + L_add 0 -- = -- + L_add 0 ++ = ++ +' + +'sub ================ +' basic + + sub 0 0 = 0 + sub 7 4 = 3 + sub 4 6 = -2 + sub 1 0 = 1 + +' negative operands + + sub -7 4 = -11 + sub 4 -6 = 10 + sub -1 -3 = 2 + sub 7 -4 = 11 + sub -4 6 = -10 + +' positive overflow +; (max-word = 32767) + sub 1 - = + + sub + + = 0 + sub + 0 = + + sub + -1 = + + sub + 1 = 32766 + sub 1 + = -32766 + sub 0 + = -32767 + +' underflow +; (min-word = 32768) + + sub - -1 = -32767 + sub - 1 = - + sub - - = 0 + sub - + = - + sub + - = + + sub 1 - = + + sub -1 - = + + sub -32767 2 = - + sub 0 - = + +' + +'L_sub ================ +' basic + + L_sub 0 0 = 0 + L_sub 7 4 = 3 + L_sub 4 6 = -2 + L_sub 1 0 = 1 + +' negative operands + + L_sub -7 4 = -11 + L_sub 4 -6 = 10 + L_sub -1 -3 = 2 + L_sub 7 -4 = 11 + L_sub -4 6 = -10 + +' positive overflow + L_sub 1 -- = ++ + L_sub ++ ++ = 0 + L_sub ++ 0 = ++ + L_sub ++ -1 = ++ + L_sub ++ 1 = 2147483646 + L_sub 1 ++ = -2147483646 + L_sub 0 ++ = -2147483647 + +' underflow + + L_sub -- -1 = -2147483647 + L_sub -- 1 = -- + L_sub -- -- = 0 + L_sub -- ++ = -- + L_sub + -- = ++ + L_sub 1 -- = ++ + L_sub -1 -- = ++ + L_sub -2147483647 2 = -- + L_sub 0 -- = ++ + +' +'abs ================ +' basic + + abs 0 = 0 + abs 2 = 2 + abs -459 = 459 + +' overflow + + abs + = + + abs - = + + abs -32767 = + + abs 32766 = 32766 + abs -32766 = 32766 + +' +'mult ================ +; actually, a * b >> 15 + +' basic + mult 0 0 = 0 + mult 0x100 0x100 = 2 + mult 4711 0x4000 = 2355 + +' negative operands + mult -1 0 = 0 + + mult -0x100 0x100 = -2 + mult 0x100 -0x100 = -2 + mult -0x100 -0x100 = 2 + + mult -4711 0x4000 = -2356 + mult 4711 -0x4000 = -2356 + mult -4711 -0x4000 = 2355 + +' overflow + mult + + = 32766 + mult + 0x4000 = 0x3fff + mult 0x4000 + = 0x3fff + mult + 1 = 0 + mult + 2 = 1 + mult + 3 = 2 + +' underflow + mult - - = + + mult - + = -32767 + mult + - = -32767 + mult - 1 = -1 + mult - 2 = -2 + mult - 3 = -3 + +' +'mult_r ================ +; actually, (a * b + 16384) >> 15 + +' basic + mult_r 0 0 = 0 + mult_r 0x100 0x100 = 2 + mult_r 4711 0x4000 = 2356 + +' negative operands + mult_r -1 0 = 0 + + mult_r -0x100 0x100 = -2 + mult_r 0x100 -0x100 = -2 + mult_r -0x100 -0x100 = 2 + + mult_r -4711 0x4000 = -2355 + mult_r 4711 -0x4000 = -2355 + mult_r -4711 -0x4000 = 2356 + +' overflow + mult_r + + = 32766 + mult_r + 32766 = 32765 + mult_r 32766 + = 32765 + mult_r + 0x4000 = 0x4000 + mult_r 0x4000 + = 0x4000 + mult_r + 0x4001 = 0x4000 + mult_r 0x4001 + = 0x4000 + mult_r + 2 = 2 + mult_r + 1 = 1 + mult_r 1 + = 1 + mult_r + 0 = 0 + mult_r 0 + = 0 + +' underflow + mult_r - - = + + mult_r - + = -32767 + mult_r + - = -32767 + mult_r - 1 = -1 + mult_r - 2 = -2 + mult_r - 3 = -3 + +' +'L_mult ================ +; actually, (a * b) << 1 +; assert (a != MIN_WORD && b != MIN_WORD) + +' basic + L_mult 0 0 = 0 + L_mult 2 3 = 12 + L_mult 4711 5 = 47110 + +' negative operands + + L_mult -2 3 = -12 + L_mult 2 -3 = -12 + L_mult -2 -3 = 12 + L_mult -4711 5 = -47110 + L_mult 4711 -5 = -47110 + L_mult -4711 -5 = 47110 + +' overflow + L_mult + + = 2147352578 + L_mult + -32767 = -2147352578 + L_mult -32767 + = -2147352578 + L_mult + 2 = 131068 + L_mult + 1 = 65534 + L_mult 1 + = 65534 + L_mult + 0 = 0 + L_mult 0 + = 0 + +' +'div ================ +; actually, (32767 * a) / b +; assert (a > 0 && b >= a) + +' basic + div 1 1 = + + div 4711 4711 = + + div 5 10 = 0x4000 + div 5 20 = 0x2000 + div 5 40 = 0x1000 + +' overflow + div + + = + + div 0x4000 + = 0x4000 + div 1 + = 1 + div 1 2 = 0x4000 +' +'norm ================ + +' positive + norm 1 = 30 + norm 2 = 29 + norm 3 = 29 + norm 4 = 28 + norm 5 = 28 +; etc, etc... + norm 0x08000000 = 3 + norm 0x10000000 = 2 + norm 0x20000000 = 1 + norm 0x20000001 = 1 + norm 0x3fffffff = 1 + norm 0x40000000 = 0 + norm 0x40000001 = 0 + norm 0x4ffffffe = 0 + norm ++ = 0 + +' negative + norm -1 = 31 + norm -2 = 30 + norm -3 = 29 + norm -4 = 29 + norm -5 = 28 +; etc, etc... + norm 0x4fffffff = 0 + norm -- = 0 +' +'>> ================ + +' basic + >> 1 1 = 0 + >> 4 2 = 1 + >> 0x1100 5 = 0x88 + +' negative operand + + >> 1 -1 = 2 + >> 1 -2 = 4 + >> 0x88 -5 = 0x1100 + +' overflow + >> -1 4711 = -1 + >> 1 4711 = 0 + >> -4711 4711 = -1 + >> 4711 4711 = 0 + >> + 1 = 16383 + >> - 1 = -16384 +' +'L_>> ================ + +' basic + L_>> 1 1 = 0 + L_>> 4 2 = 1 + L_>> 0x1100 5 = 0x88 + +' negative operand + + L_>> 1 -1 = 2 + L_>> 1 -2 = 4 + L_>> 0x88 -5 = 0x1100 + +' overflow + L_>> -1 4711 = -1 + L_>> 1 4711 = 0 + L_>> -4711 4711 = -1 + L_>> 4711 4711 = 0 + L_>> ++ 1 = 1073741823 + L_>> -- 1 = -1073741824 + +' +'<< ================ + +' basic + << 1 1 = 2 + << 4 2 = 16 + << 0x0088 5 = 0x1100 + +' negative operand + + << 1 -1 = 0 + << 4 -2 = 1 + << 0x1100 -5 = 0x0088 + +' overflow + << -1 4711 = 0 + << 1 4711 = 0 + << -4711 4711 = 0 + << 4711 4711 = 0 + << 4711 -4711 = 0 + << -4711 -4711 = -1 + << + 1 = 0xfffe + << -1 1 = 0xfffe + << - 1 = 0 +' +'L_<< ================ + +' basic + L_<< 1 1 = 2 + L_<< 4 2 = 16 + L_<< 0x0088 5 = 0x1100 + +' negative operand + + L_<< 1 -1 = 0 + L_<< 4 -2 = 1 + L_<< 0x1100 -5 = 0x0088 + +' overflow + L_<< -1 4711 = 0 + L_<< 1 4711 = 0 + L_<< -4711 4711 = 0 + L_<< 4711 4711 = 0 + L_<< 4711 -4711 = 0 + L_<< -4711 -4711 = -1 + L_<< ++ 1 = -2 + L_<< -1 1 = -2 + L_<< -- 1 = 0 diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/changes --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/changes Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,145 @@ +File "changes" +~~~~~~~~~~~~~~ + +LOG of the changes introduced by Simao and summary of results. + +1. first of all, file names had to fit in DOS limitations. Some names had + to be truncated, and the mapping is as follows: + gsm_create.c -> gsm_crea.c + gsm_decode.c -> gsm_deco.c + gsm_destroy.c -> gsm_dest.c + gsm_encode.c -> gsm_enco.c + gsm_explode.c -> gsm_expl.c + gsm_implode.c -> gsm_impl.c + gsm_option.c -> gsm_opti.c + gsm_print.c -> gsm_prin.c + long_term.c -> long_ter.c + preprocess.c -> preproce.c + short_term.c -> short_te.c + +2. gsm.h had added prototypes for all the existing functions + +3. add.c had to be changed to make add_test.c work + +4. private.h had to be changed to use either true-function or the safe + pseudo-functions for the GSM_... macros. This was the main reason for + the errors that were happening. + +5. undefs were preceeded by a check of their definition to avoid some + complaints from VAX-C + +6. rpe.c had to be changed in a strange hacked "switch" by its "normal" + implementation for VMS (compilation error!) - the code is as it was + in comments. + +7. To keep compatibility, the change in patch 3 to rpe.c + shall not be + #define STEP( i, H ) (e[ k + i ] * (long)H) + but + #define STEP( i, H ) (e[ k + i ] * (longword)H) + +8. long_term.c (now long_ter.c) had to have added some castings, such + as: + temp = gsm_norm( (longword)dmax << 16 ); + ^^^^^^^^^^ + because gsm_norm uses longs and dmax is short: (short)<<16 = 0 always! + Also, if MSDOS/__MSDOS__ is defined, then USE_TABLE_MUL is + #undef'd (see tests below). + +9. other small changes that I don't recall from my notes. These may include + type castings, and other changes done in the desperate search for the bugs. + + +Simplifications: +~~~~~~~~~~~~~~~~ + +Since I don't want a compress-like utility, I haven't put my hands in toast. +To ease my work, I've put all src, inc and add-test in one single directory +and simplified the makefile. I also added labels "all", "rpedemo" and "clean", +"anyway". + + +Extensions: +~~~~~~~~~~~ + +I added a DCL for compiling on VMS using either gcc or vax-c, depending on +the comments. I have also added a borland bcc make file for the pc, as well +as a gcc makefile for the pc. + +Added a demo program and 2 driving routines (currently embedded in the demo +program). With them, interfacing with the test sequence file is +straight-forward. + + +Test results: +~~~~~~~~~~~~~ + +the bcc-compiled version processed correctly all the 5 test vectors for +the following conditions: + +(SASR always defined) + +USE_FLOAT_MUL undefined +USE_FLOAT_MUL defined and FAST undefined +USE_FLOAT_MUL and FAST defined + +bcc failed compilation when USE_FLOAT_MUL undefined and USE_TABLE_MUL defined +because the table matrix is greater than 64kbytes! (No way out!) + +When compiled by bcc with both USE_FLOAT_MUL and FAST undefined, bcc +failed passing the test sequences. + +Besides compilation worked for USE_FLOAT_MUL and FAST defined, in fact, all +the runs with the test sequences were made in the "compatible mode", i.e., +with the state variable structure fuield "fast" always set as 0. Therefore, +it was not tested. Although, it is known from the original authors that +the fast mode does not work in Unix (32bit), hence it is very likely not +to work with DOS either! + +NeedFunctionPrototypes was always defined for bcc, gcc, acc, and vax-c, +and undefined for unix cc. + +Since gcc is the same implementation ported across platforms, it should +work as for SunOS, but it was not tested. + +The program worked properly for the following environments (see summary below): +SunOS 4.3: cc, acc, gcc +MS/DOS: bcc, gcc (djcpp) +VAX/VMS: cc (Vax-c), gcc + +Summary of the tests: +------------------------------------------------------------------------- +Environment Compiler Symbols defined (Note: SASR always def'd) + USE_FLOAT_MUL FAST USE_TABLE_MUL Worked? +------------------------------------------------------------------------- +SunOS 4.3: cc yes no - yes + yes yes - yes* + no - no yes + no - yes yes + acc same as for cc in SunOS 4.3 yes + gcc same as for cc in SunOS 4.3 yes +MS/DOS: bcc yes no - yes + yes yes - yes + no - no no + no - yes no + gcc Not tested other than yes/no/- yes +VAX/VMS: Vax-c same as for cc in SunOS 4.3 yes + gcc Not tested other than yes/no/- yes +------------------------------------------------------------------------- +* Note: all the runs were made in the compatible mode, therefore the + fast computation of the data was not performed! +------------------------------------------------------------------------- + +Therefore, the safest approach is to compile always with USE_FLOAT_MUL +defined and with and FAST defined if appropriate for speed! + +In Vax-C there were warnings relating to function names longer than 31 +characters. No way to circumvent this, but it is not a problem because the +31 first letters generate unique names anyway. Because of this, link will +also complain! + +The test sequence files had the byte order swaped in the Sun workstation +because of the Big Endian data orientation. + +-- -- 8/Apr/94 + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/code.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/code.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,90 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/code.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "config.h" + + +#ifdef HAS_STDLIB_H +#include +#include +#else +# include "proto.h" +extern char *memcpy P((char *, char *, int)); +#endif + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +/* + * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER + */ + +void Gsm_Coder P8((S, s, LARc, Nc, bc, Mc, xmaxc, xMc), struct gsm_state *S, word * s, /* [0..159] samples IN */ +/* + * The RPE-LTD coder works on a frame by frame basis. The length of + * the frame is equal to 160 samples. Some computations are done + * once per frame to produce at the output of the coder the + * LARc[1..8] parameters which are the coded LAR coefficients and + * also to realize the inverse filtering operation for the entire + * frame (160 samples of signal d[0..159]). These parts produce at + * the output of the coder: + */ + word * LARc, /* [0..7] LAR coefficients OUT */ +/* + * Procedure 4.2.11 to 4.2.18 are to be executed four times per + * frame. That means once for each sub-segment RPE-LTP analysis of + * 40 samples. These parts produce at the output of the coder: + */ + word * Nc, /* [0..3] LTP lag OUT */ + word * bc, /* [0..3] coded LTP gain OUT */ + word * Mc, /* [0..3] RPE grid selection OUT */ + word * xmaxc, /* [0..3] Coded maximum amplitude OUT */ + word * xMc /* [13*4] normalized RPE samples OUT */ + ) +{ + int k; + word *dp = S->dp0 + 120; /* [ -120...-1 ] */ + word *dpp = dp; /* [ 0...39 ] */ + + static word e[50] = { 0 }; + + word so[160]; + + Gsm_Preprocess(S, s, so); + Gsm_LPC_Analysis(S, so, LARc); + Gsm_Short_Term_Analysis_Filter(S, LARc, so); + + for (k = 0; k <= 3; k++, xMc += 13) { + + Gsm_Long_Term_Predictor(S, so + k * 40, /* d [0..39] IN */ + dp, /* dp [-120..-1] IN */ + e + 5, /* e [0..39] OUT */ + dpp, /* dpp [0..39] OUT */ + Nc++, bc++); + + Gsm_RPE_Encoding(S, e + 5, /* e ][0..39][ IN/OUT */ + xmaxc++, Mc++, xMc); + /* + * Gsm_Update_of_reconstructed_short_time_residual_signal + * ( dpp, e + 5, dp ); + */ + + { + register int i; + register longword ltmp; + for (i = 0; i <= 39; i++) + dp[i] = GSM_ADD(e[5 + i], dpp[i]); + } + dp += 40; + dpp += 40; + + } + (void) memcpy((char *) S->dp0, (char *) (S->dp0 + 160), + 120 * sizeof(*S->dp0)); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/config.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,33 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/config.h,v 1.2 1994/01/25 22:20:51 jutta Exp $*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/*efine SIGHANDLER_T int / * signal handlers are void */ +/*efine HAS_SYSV_SIGNAL 1 / * sigs not blocked/reset? */ + +#define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */ +/*efine HAS_LIMITS_H 1 / * /usr/include/limits.h */ +#define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */ +/*efine HAS_ERRNO_DECL 1 / * errno.h declares errno */ + +#define HAS_FSTAT 1 /* fstat syscall */ +#define HAS_FCHMOD 1 /* fchmod syscall */ +#define HAS_FCHOWN 1 /* fchown syscall */ + +#define HAS_STRING_H 1 /* /usr/include/string.h */ +/*efine HAS_STRINGS_H 1 / * /usr/include/strings.h */ + +#define HAS_UTIME 1 /* POSIX utime(path, times) */ +/*efine HAS_UTIMES 1 / * use utimes() syscall instead */ +/*efine HAS_UTIME_H 1 / * UTIME header file */ +/*efine HAS_UTIMBUF 1 / * struct utimbuf */ +/*efine HAS_UTIMEUSEC 1 / * microseconds in utimbuf? */ + +#endif /* CONFIG_H */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/cpyright --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/cpyright Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,16 @@ +Copyright 1992 by Jutta Degener and Carsten Bormann, +Technische Universitaet Berlin + +Any use of this software is permitted provided that this notice is not +removed and that neither the authors nor the Technische Universitaet Berlin +are deemed to have made any representations as to the suitability of this +software for any purpose nor are held responsible for any defects of +this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + +As a matter of courtesy, the authors request to be informed about uses +this software has found, about bugs in this software, and about any +improvements that may be of general interest. + +Berlin, 15.09.1992 +Jutta Degener +Carsten Bormann diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/debug.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/debug.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,68 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/debug.c,v 1.2 1993/01/29 18:22:20 jutta Exp $ */ + +#include "private.h" + +#ifndef NDEBUG + +/* If NDEBUG _is_ defined and no debugging should be performed, + * calls to functions in this module are #defined to nothing + * in private.h. + */ + +#include +#include "proto.h" + +void gsm_debug_words P4((name, from, to, ptr), + char *name, int from, int to, word * ptr) +{ + int nprinted = 0; + + fprintf(stderr, "%s [%d .. %d]: ", name, from, to); + while (from <= to) { + fprintf(stderr, "%d ", ptr[from]); + from++; + if (nprinted++ >= 7) { + nprinted = 0; + if (from < to) + putc('\n', stderr); + } + } + putc('\n', stderr); +} + +void gsm_debug_longwords P4((name, from, to, ptr), + char *name, int from, int to, longword * ptr) +{ + int nprinted = 0; + + fprintf(stderr, "%s [%d .. %d]: ", name, from, to); + while (from <= to) { + + fprintf(stderr, "%d ", ptr[from]); + from++; + if (nprinted++ >= 7) { + nprinted = 0; + if (from < to) + putc('\n', stderr); + } + } + putc('\n', stderr); +} + +void gsm_debug_longword P2((name, value), char *name, longword value) +{ + fprintf(stderr, "%s: %d\n", name, (long) value); +} + +void gsm_debug_word P2((name, value), char *name, word value) +{ + fprintf(stderr, "%s: %d\n", name, (long) value); +} + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/decode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/decode.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,63 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/decode.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +/* + * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER + */ + +static void Postprocessing P2((S, s), + struct gsm_state *S, register word * s) +{ + register int k; + register word msr = S->msr; + register longword ltmp; /* for GSM_ADD */ + register word tmp; + + for (k = 160; k--; s++) { + tmp = GSM_MULT_R(msr, 28180); + msr = GSM_ADD(*s, tmp); /* Deemphasis */ +#ifdef USE_ROUNDING_INSTEAD_OF_TRUNCATION + *s = GSM_ADD(msr, msr); /* Upscaling by 2 */ + *s = GSM_ADD(*s, 4) & 0xFFF8; /* Truncation */ +#else + *s = GSM_ADD(msr, msr) & 0xFFF8; /* Upscaling & Truncation */ +#endif + } + S->msr = msr; +} + +void Gsm_Decoder P8((S, LARcr, Ncr, bcr, Mcr, xmaxcr, xMcr, s), struct gsm_state *S, word * LARcr, /* [0..7] IN */ + word * Ncr, /* [0..3] IN */ + word * bcr, /* [0..3] IN */ + word * Mcr, /* [0..3] IN */ + word * xmaxcr, /* [0..3] IN */ + word * xMcr, /* [0..13*4] IN */ + word * s) +{ /* [0..159] OUT */ + int j, k; + word erp[40], wt[160]; + word *drp = S->dp0 + 120; + + for (j = 0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) { + + Gsm_RPE_Decoding(S, *xmaxcr, *Mcr, xMcr, erp); + Gsm_Long_Term_Synthesis_Filtering(S, *Ncr, *bcr, erp, drp); + + for (k = 0; k <= 39; k++) + wt[j * 40 + k] = drp[k]; + } + + Gsm_Short_Term_Synthesis_Filter(S, LARcr, wt, s); + Postprocessing(S, s); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gen-lic.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gen-lic.txt Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,162 @@ + + + ITU-T SOFTWARE TOOLS' GENERAL PUBLIC LICENSE + + + + This "General Public License" is published in the Annex 1 of the + ITU-T Recommendation on "SOFTWARE TOOLS FOR HOMOGENITY OF RESULTS + IN THE STANDARDIZATION PROCESS OF SPEECH AND AUDIO CODERS", + approved in Geneva, 2000. + + + TERMS AND CONDITIONS + + 1. This License Agreement applies to any module or other work + related to the ITU-T Software Tool Library, and developed by the + User's Group on Software Tools. The "Module", below, refers to any + such module or work, and a "work based on the Module" means either + the Module or any work containing the Module or a portion of it, + either verbatim or with modifications. Each licensee is addressed + as "you". + + 2. You may copy and distribute verbatim copies of the Module's + source code as you receive it, in any medium, provided that you: + - conspicuously and appropriately publish on each copy an appropriate + copyright notice and disclaimer of warranty; + - keep intact all the notices that refer to this General Public + License and to the absence of any warranty; and + - give any other recipients of the Module a copy of this General + Public License along with the Module. + You may charge a fee for the physical act of transferring a copy. + + 3. You may modify your copy or copies of the Module or any portion + of it, and copy and distribute such modifications under the terms + of Paragraph 1 above, provided that you also do the following: + + o cause the modified files to carry prominent notices stating + that you changed the files and the date of any change; and + + o cause the whole of any work that you distribute or publish, + that in whole or in part contains the Module or any part + thereof, either with or without modifications, to be licensed + at no charge to all third parties under the terms of this + General Public License (except that you may choose to grant + warranty protection to some or all third parties, at your + option). + + o If the modified module normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the simplest and most usual way, to print or + display an announcement including an appropriate copyright + notice and a notice that there is no warranty (or else, saying + that you provide a warranty) and that users may redistribute + the module under these conditions, and telling the user how to + view a copy of this General Public License. + + You may charge a fee for the physical act of transferring a copy, + and you may at your option offer warranty protection in exchange + for a fee. + + Mere aggregation of another independent work with the Module (or + its derivative) on a volume of a storage or distribution medium + does not bring the other work under the scope of these terms. + + 4. You may copy and distribute the Module (or a portion or + derivative of it, under Paragraph 2) in object code or executable + form under the terms of Paragraphs 1 and 2 above provided that you + also do one of the following: + + o accompany it with the complete corresponding machine- + readable source code, which must be distributed under the terms + of Paragraphs 1 and 2 above; or, + + o accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal + charge for the cost of distribution) a complete machine- + readable copy of the corresponding source code, to be + distributed under the terms of Paragraphs 1 and 2 above; or, + + o accompany it with the information you received as to where + the corresponding source code may be obtained. (This + alternative is allowed only for noncommercial distribution and + only if you received the module in object code or executable + form alone.) + + Source code for a work means the preferred form of the work for + making modifications to it. For an executable file, complete + source code means all the source code for all modules it contains; + but, as a special exception, it need not include source code for + modules which are standard libraries that accompany the operating + system on which the executable file runs, or for standard header + files or definitions files that accompany that operating system. + + 5. You may not copy, modify, sublicense, distribute or transfer + the Module except as expressly provided under this General Public + License. Any attempt otherwise to copy, modify, sublicense, + distribute or transfer the Module is void, and will automatically + terminate your rights to use the Module under this License. + However, parties who have received copies, or rights to use copies, + from you under this General Public License will not have their + licenses terminated so long as such parties remain in full + compliance. + + 6. By copying, distributing or modifying the Module (or any work + based on the Module) you indicate your acceptance of this license + to do so, and all its terms and conditions. + + 7. Each time you redistribute the Module (or any work based on the + Module), the recipient automatically receives a license from the + original licensor to copy, distribute or modify the Module subject + to these terms and conditions. You may not impose any further + restrictions on the recipients' exercise of the rights granted + herein. + + 8. The ITU-T may publish revised and/or new versions of this + General Public License from time to time. Such new versions will + be similar in spirit to the present version, but may differ in + detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the + Module specifies a version number of the license which applies to + it and "any later version", you have the option of following the + terms and conditions either of that version or of any later version + published by the ITU-T. If the Module does not specify a version + number of the license, you may choose any version ever published by + the ITU-T. + + 9. If you wish to incorporate parts of the Module into other free + modules whose distribution conditions are different, write to the + author to ask for permission. For software which is copyrighted by + the ITU-T, write to the ITU-T Secretariat; exceptions may be made + for this. This decision will be guided by the two goals of + preserving the free status of all derivatives of this free software + and of promoting the sharing and reuse of software generally. + + + NO WARRANTY + + 10. BECAUSE THE MODULE IS LICENSED FREE OF CHARGE, THERE IS NO + WARRANTY FOR THE MODULE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. + EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS + AND/OR OTHER PARTIES PROVIDE THE MODULE "AS IS" WITHOUT WARRANTY OF + ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE MODULE IS WITH YOU. SHOULD THE MODULE PROVE + DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR + OR CORRECTION. + + 11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN + WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY + MODIFY AND/OR REDISTRIBUTE THE MODULE AS PERMITTED ABOVE, BE LIABLE + TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR + CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE + THE MODULE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING + RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR + A FAILURE OF THE MODULE TO OPERATE WITH ANY OTHER MODULES), EVEN IF + SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,196 @@ + +/* + RFC3551: + + name of sampling default + encoding sample/frame bits/sample rate ms/frame ms/packet + __________________________________________________________________ + GSM frame N/A 8,000 20 20 + + + field field name bits field field name bits + ________________________________________________ + 1 LARc[0] 6 39 xmc[22] 3 + 2 LARc[1] 6 40 xmc[23] 3 + 3 LARc[2] 5 41 xmc[24] 3 + 4 LARc[3] 5 42 xmc[25] 3 + 5 LARc[4] 4 43 Nc[2] 7 + 6 LARc[5] 4 44 bc[2] 2 + 7 LARc[6] 3 45 Mc[2] 2 + 8 LARc[7] 3 46 xmaxc[2] 6 + 9 Nc[0] 7 47 xmc[26] 3 + 10 bc[0] 2 48 xmc[27] 3 + 11 Mc[0] 2 49 xmc[28] 3 + 12 xmaxc[0] 6 50 xmc[29] 3 + 13 xmc[0] 3 51 xmc[30] 3 + 14 xmc[1] 3 52 xmc[31] 3 + 15 xmc[2] 3 53 xmc[32] 3 + 16 xmc[3] 3 54 xmc[33] 3 + 17 xmc[4] 3 55 xmc[34] 3 + 18 xmc[5] 3 56 xmc[35] 3 + 19 xmc[6] 3 57 xmc[36] 3 + 20 xmc[7] 3 58 xmc[37] 3 + 21 xmc[8] 3 59 xmc[38] 3 + 22 xmc[9] 3 60 Nc[3] 7 + 23 xmc[10] 3 61 bc[3] 2 + 24 xmc[11] 3 62 Mc[3] 2 + 25 xmc[12] 3 63 xmaxc[3] 6 + 26 Nc[1] 7 64 xmc[39] 3 + 27 bc[1] 2 65 xmc[40] 3 + 28 Mc[1] 2 66 xmc[41] 3 + 29 xmaxc[1] 6 67 xmc[42] 3 + 30 xmc[13] 3 68 xmc[43] 3 + 31 xmc[14] 3 69 xmc[44] 3 + 32 xmc[15] 3 70 xmc[45] 3 + 33 xmc[16] 3 71 xmc[46] 3 + 34 xmc[17] 3 72 xmc[47] 3 + 35 xmc[18] 3 73 xmc[48] 3 + 36 xmc[19] 3 74 xmc[49] 3 + 37 xmc[20] 3 75 xmc[50] 3 + 38 xmc[21] 3 76 xmc[51] 3 + + Table 2: Ordering of GSM variables + + + Octet Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 + _____________________________________________________________________ + 0 1 1 0 1 LARc0.0 LARc0.1 LARc0.2 LARc0.3 + 1 LARc0.4 LARc0.5 LARc1.0 LARc1.1 LARc1.2 LARc1.3 LARc1.4 LARc1.5 + 2 LARc2.0 LARc2.1 LARc2.2 LARc2.3 LARc2.4 LARc3.0 LARc3.1 LARc3.2 + 3 LARc3.3 LARc3.4 LARc4.0 LARc4.1 LARc4.2 LARc4.3 LARc5.0 LARc5.1 + 4 LARc5.2 LARc5.3 LARc6.0 LARc6.1 LARc6.2 LARc7.0 LARc7.1 LARc7.2 + 5 Nc0.0 Nc0.1 Nc0.2 Nc0.3 Nc0.4 Nc0.5 Nc0.6 bc0.0 + 6 bc0.1 Mc0.0 Mc0.1 xmaxc00 xmaxc01 xmaxc02 xmaxc03 xmaxc04 + 7 xmaxc05 xmc0.0 xmc0.1 xmc0.2 xmc1.0 xmc1.1 xmc1.2 xmc2.0 + 8 xmc2.1 xmc2.2 xmc3.0 xmc3.1 xmc3.2 xmc4.0 xmc4.1 xmc4.2 + 9 xmc5.0 xmc5.1 xmc5.2 xmc6.0 xmc6.1 xmc6.2 xmc7.0 xmc7.1 + 10 xmc7.2 xmc8.0 xmc8.1 xmc8.2 xmc9.0 xmc9.1 xmc9.2 xmc10.0 + 11 xmc10.1 xmc10.2 xmc11.0 xmc11.1 xmc11.2 xmc12.0 xmc12.1 xcm12.2 + 12 Nc1.0 Nc1.1 Nc1.2 Nc1.3 Nc1.4 Nc1.5 Nc1.6 bc1.0 + 13 bc1.1 Mc1.0 Mc1.1 xmaxc10 xmaxc11 xmaxc12 xmaxc13 xmaxc14 + 14 xmax15 xmc13.0 xmc13.1 xmc13.2 xmc14.0 xmc14.1 xmc14.2 xmc15.0 + 15 xmc15.1 xmc15.2 xmc16.0 xmc16.1 xmc16.2 xmc17.0 xmc17.1 xmc17.2 + 16 xmc18.0 xmc18.1 xmc18.2 xmc19.0 xmc19.1 xmc19.2 xmc20.0 xmc20.1 + 17 xmc20.2 xmc21.0 xmc21.1 xmc21.2 xmc22.0 xmc22.1 xmc22.2 xmc23.0 + 18 xmc23.1 xmc23.2 xmc24.0 xmc24.1 xmc24.2 xmc25.0 xmc25.1 xmc25.2 + 19 Nc2.0 Nc2.1 Nc2.2 Nc2.3 Nc2.4 Nc2.5 Nc2.6 bc2.0 + 20 bc2.1 Mc2.0 Mc2.1 xmaxc20 xmaxc21 xmaxc22 xmaxc23 xmaxc24 + 21 xmaxc25 xmc26.0 xmc26.1 xmc26.2 xmc27.0 xmc27.1 xmc27.2 xmc28.0 + 22 xmc28.1 xmc28.2 xmc29.0 xmc29.1 xmc29.2 xmc30.0 xmc30.1 xmc30.2 + 23 xmc31.0 xmc31.1 xmc31.2 xmc32.0 xmc32.1 xmc32.2 xmc33.0 xmc33.1 + 24 xmc33.2 xmc34.0 xmc34.1 xmc34.2 xmc35.0 xmc35.1 xmc35.2 xmc36.0 + 25 Xmc36.1 xmc36.2 xmc37.0 xmc37.1 xmc37.2 xmc38.0 xmc38.1 xmc38.2 + 26 Nc3.0 Nc3.1 Nc3.2 Nc3.3 Nc3.4 Nc3.5 Nc3.6 bc3.0 + 27 bc3.1 Mc3.0 Mc3.1 xmaxc30 xmaxc31 xmaxc32 xmaxc33 xmaxc34 + 28 xmaxc35 xmc39.0 xmc39.1 xmc39.2 xmc40.0 xmc40.1 xmc40.2 xmc41.0 + 29 xmc41.1 xmc41.2 xmc42.0 xmc42.1 xmc42.2 xmc43.0 xmc43.1 xmc43.2 + 30 xmc44.0 xmc44.1 xmc44.2 xmc45.0 xmc45.1 xmc45.2 xmc46.0 xmc46.1 + 31 xmc46.2 xmc47.0 xmc47.1 xmc47.2 xmc48.0 xmc48.1 xmc48.2 xmc49.0 + 32 xmc49.1 xmc49.2 xmc50.0 xmc50.1 xmc50.2 xmc51.0 xmc51.1 xmc51.2 + + Table 3: GSM payload format + + In the GSM packing used by RTP, the bits SHALL be packed beginning + from the most significant bit. Every 160 sample GSM frame is coded + into one 33 octet (264 bit) buffer. Every such buffer begins with a + 4 bit signature (0xD), followed by the MSB encoding of the fields of + the frame. The first octet thus contains 1101 in the 4 most + significant bits (0-3) and the 4 most significant bits of F1 (0-3) in + the 4 least significant bits (4-7). + + + PT encoding media type clock rate channels + name (Hz) + ___________________________________________________ + 3 GSM A 8,000 1 + + */ + +typedef unsigned char Byte; + +static Byte byte; +static unsigned mask; +static Byte *packed; +static int gsmbits[76] = { + 6, 6, 5, 5, 4, 4, 3, 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 2, + 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 +}; + +static void pack(short data, int len) +{ + unsigned srcmask; + + for (srcmask = (1 << len-1); srcmask > 0; srcmask /= 2) { + if (data & srcmask) { + byte += mask; + } + mask /= 2; // shift right + if (0 == mask) { + *packed = byte; + ++packed; + mask = 128; + byte = 0; + } + } +} + +int gsmpack(Byte *gsm_frame, short *rpe_frame) +{ + int i; + + byte = 0; + mask = 128; + packed = gsm_frame; + + pack(0xD, 4); // GSM signature + for (i = 0; i < 76; ++i, ++rpe_frame) { + pack(*rpe_frame, gsmbits[i]); + } + *packed = byte; + + return 33; +} + +static short unpack(int len) +{ + unsigned srcmask; + short data = 0; + + for (srcmask = (1 << len-1); srcmask > 0; srcmask /= 2) { + if ((*packed) & mask) { + data += srcmask; + } + mask /= 2; // shift right + if (0 == mask) { + ++packed; + mask = 128; + } + } + + // fprintf(stderr, "data =%x\n", data); + return data; +} + +int gsmunpack(short *rpe_frame, Byte *gsm_frame) +{ + int i; + + byte = 0; + mask = 128; + packed = gsm_frame; + + if (unpack(4) != 0xD) { + // fprintf(stderr, "error: gsmunpack\n"); + return 0; // not GSM signature + } + for (i = 0; i < 76; ++i, ++rpe_frame) { + *rpe_frame = unpack(gsmbits[i]); + } + // exit(1) ; + return 160; // number of PCM samples +} + + + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,155 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/gsm.h,v 1.5 1994/01/25 22:20:48 jutta Exp $*/ + +#ifndef GSM_H +#define GSM_H + +#ifndef NeedFunctionPrototypes +#if defined(__cplusplus) || defined(__STDC__) || defined(VMS) +# define NeedFunctionPrototypes 1 +#endif +#endif + +/* The above 5 lines used to be several #if ... it was changed to avoid +* silly warnings and sintax errors of some compilers and to automate +* symbol definition for VMS! +* #ifdef __cplusplus +* # define NeedFunctionPrototypes 1 +* #endif +* +* #if __STDC__ +* # define NeedFunctionPrototypes 1 +* #endif +*/ + +#ifdef _NO_PROTO +# undef NeedFunctionPrototypes +#endif + +#ifdef GSM_P +#undef GSM_P /* somewhere else may have defined this... */ +#endif + +#ifdef NeedFunctionPrototypes +# define GSM_P( protos ) protos +#else +# define GSM_P( protos ) ( /* protos */ ) +#endif + +#ifdef NeedFunctionPrototypes +# include /* for FILE * */ +#endif + +/* + * Interface + */ + +typedef struct gsm_state *gsm; +typedef short gsm_signal; /* signed 16 bit */ +typedef unsigned char gsm_byte; +typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */ + +#define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */ + +#define GSM_PATCHLEVEL 3 +#define GSM_MINOR 0 +#define GSM_MAJOR 1 + +#define GSM_OPT_VERBOSE 1 +#define GSM_OPT_FAST 2 + + +/* + * Prototypes generated automatically by cproto ... + */ + +/* Prototypes for functions defined in file add.c */ +extern word gsm_add GSM_P((word a, word b)); +word gsm_sub GSM_P((word a, word b)); +word gsm_mult GSM_P((word a, word b)); +word gsm_mult_r GSM_P((word a, word b)); +word gsm_abs GSM_P((word a)); +longword gsm_L_mult GSM_P((word a, word b)); +longword gsm_L_add GSM_P((longword a, longword b)); +longword gsm_L_sub GSM_P((longword a, longword b)); +word gsm_norm GSM_P((longword a)); +longword gsm_L_asl GSM_P((longword a, int n)); +word gsm_asl GSM_P((word a, int n)); +longword gsm_L_asr GSM_P((longword a, int n)); +word gsm_asr GSM_P((word a, int n)); +word gsm_div GSM_P((word num, word denum)); + +/* Prototypes for functions defined in file code.c */ +void Gsm_Coder GSM_P((struct gsm_state * S, word * s, word * LARc, + word * Nc, word * bc, word * Mc, word * xmaxc, word * xMc)); + +/* Prototypes for functions defined in file decode.c */ +void Gsm_Decoder GSM_P((struct gsm_state * S, word * LARcr, word * Ncr, + word * bcr, word * Mcr, word * xmaxcr, word * xMcr, word * s)); + +/* Prototypes for functions defined in file long_term.c */ +void Gsm_Long_Term_Predictor GSM_P((struct gsm_state * S, word * d, + word * dp, word * e, word * dpp, word * Nc, word * bc)); +void Gsm_Long_Term_Synthesis_Filtering GSM_P((struct gsm_state * S, + word Ncr, word bcr, register word * erp, register word * drp)); + +/* Prototypes for functions defined in file lpc.c */ +void Gsm_LPC_Analysis GSM_P((struct gsm_state * S, word * s, + word * LARc)); + +/* Prototypes for functions defined in file preprocess.c */ +void Gsm_Preprocess GSM_P((struct gsm_state * S, word * s, word * so)); + +/* Prototypes for functions defined in file rpe.c */ +void Gsm_RPE_Encoding GSM_P((struct gsm_state * S, word * e, + word * xmaxc, word * Mc, word * xMc)); +void Gsm_RPE_Decoding GSM_P((struct gsm_state * S, word xmaxcr, + word Mcr, word * xMcr, word * erp)); + +/* Prototypes for functions defined in file gsm_destroy.c */ +void gsm_destroy GSM_P((gsm S)); + +/* Prototypes for functions defined in file gsm_decode.c */ +int gsm_decode GSM_P((gsm s, gsm_byte * c, gsm_signal * target)); + +/* Prototypes for functions defined in file gsm_encode.c */ +void gsm_encode GSM_P((gsm s, gsm_signal * source, gsm_byte * c)); + +/* Prototypes for functions defined in file gsm_explode.c */ +int gsm_explode GSM_P((gsm s, gsm_byte * c, gsm_signal * target)); + +/* Prototypes for functions defined in file gsm_implode.c */ +void gsm_implode GSM_P((gsm s, gsm_signal * source, gsm_byte * c)); + +/* Prototypes for functions defined in file gsm_create.c */ +gsm gsm_create GSM_P((void)); + +/* Prototypes for functions defined in file gsm_print.c */ +int gsm_print GSM_P((FILE * f, gsm s, gsm_byte * c)); + +/* Prototypes for functions defined in file gsm_option.c */ +int gsm_option GSM_P((gsm r, int opt, int *val)); + +/* Prototypes for functions defined in file short_term.c */ +void Gsm_Short_Term_Analysis_Filter GSM_P((struct gsm_state * S, + word * LARc, word * s)); +void Gsm_Short_Term_Synthesis_Filter GSM_P((struct gsm_state * S, + word * LARcr, word * wt, word * s)); + +/* These prototypes only when debugging is enabled! */ +#ifndef NDEBUG +void gsm_debug_words GSM_P((char *name, int from, int to, word * ptr)); +void gsm_debug_longwords GSM_P((char *name, int from, int to, + longword * ptr)); +void gsm_debug_longword GSM_P((char *name, longword value)); +void gsm_debug_word GSM_P((char *name, word value)); +#endif + +#undef GSM_P + +#endif /* GSM_H */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_crea.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_crea.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,43 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +#include "config.h" + +#ifdef HAS_STDLIB_H +#include +#include +#else +# include "proto.h" +extern char *memset P((char *, int, int)); +#endif +#include + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +gsm gsm_create P0() +{ + gsm r; + +#ifdef USE_TABLE_MUL + + static int mul_init = 0; + if (!mul_init) { + mul_init = 1; + init_umul_table(); + } +#endif + + r = (gsm) malloc(sizeof(struct gsm_state)); + if (!r) + return r; + + memset((char *) r, 0, sizeof(*r)); + r->nrp = 40; + + return r; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_deco.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_deco.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,127 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_decode.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +int gsm_decode P3((s, c, target), gsm s, gsm_byte * c, + gsm_signal * target) +{ + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13 * 4]; + + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) + return -1; + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + Nc[0] = (*c >> 1) & 0x7F; + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + Mc[0] = (*c >> 5) & 0x3; + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + Nc[1] = (*c >> 1) & 0x7F; + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + Mc[1] = (*c >> 5) & 0x3; + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + Nc[2] = (*c >> 1) & 0x7F; + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + Mc[2] = (*c >> 5) & 0x3; + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + Nc[3] = (*c >> 1) & 0x7F; + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + Mc[3] = (*c >> 5) & 0x3; + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target); + + return 0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_dest.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_dest.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,18 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_destroy.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include +#include "private.h" +#include "gsm.h" +#include "proto.h" + +void gsm_destroy P1((S), gsm S) +{ + if (S) + free((char *) S); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_enco.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_enco.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,208 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_encode.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +void gsm_encode P3((s, source, c), gsm s, gsm_signal * source, + gsm_byte * c) +{ + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13 * 4]; + + Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc); + + + /* variable size + + GSM_MAGIC 4 + + LARc[0] 6 + LARc[1] 6 + LARc[2] 5 + LARc[3] 5 + LARc[4] 4 + LARc[5] 4 + LARc[6] 3 + LARc[7] 3 + + Nc[0] 7 + bc[0] 2 + Mc[0] 2 + xmaxc[0] 6 + xmc[0] 3 + xmc[1] 3 + xmc[2] 3 + xmc[3] 3 + xmc[4] 3 + xmc[5] 3 + xmc[6] 3 + xmc[7] 3 + xmc[8] 3 + xmc[9] 3 + xmc[10] 3 + xmc[11] 3 + xmc[12] 3 + + Nc[1] 7 + bc[1] 2 + Mc[1] 2 + xmaxc[1] 6 + xmc[13] 3 + xmc[14] 3 + xmc[15] 3 + xmc[16] 3 + xmc[17] 3 + xmc[18] 3 + xmc[19] 3 + xmc[20] 3 + xmc[21] 3 + xmc[22] 3 + xmc[23] 3 + xmc[24] 3 + xmc[25] 3 + + Nc[2] 7 + bc[2] 2 + Mc[2] 2 + xmaxc[2] 6 + xmc[26] 3 + xmc[27] 3 + xmc[28] 3 + xmc[29] 3 + xmc[30] 3 + xmc[31] 3 + xmc[32] 3 + xmc[33] 3 + xmc[34] 3 + xmc[35] 3 + xmc[36] 3 + xmc[37] 3 + xmc[38] 3 + + Nc[3] 7 + bc[3] 2 + Mc[3] 2 + xmaxc[3] 6 + xmc[39] 3 + xmc[40] 3 + xmc[41] 3 + xmc[42] 3 + xmc[43] 3 + xmc[44] 3 + xmc[45] 3 + xmc[46] 3 + xmc[47] 3 + xmc[48] 3 + xmc[49] 3 + xmc[50] 3 + xmc[51] 3 + */ + + + *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ + |((LARc[0] >> 2) & 0xF); + *c++ = ((LARc[0] & 0x3) << 6) + | (LARc[1] & 0x3F); + *c++ = ((LARc[2] & 0x1F) << 3) + | ((LARc[3] >> 2) & 0x7); + *c++ = ((LARc[3] & 0x3) << 6) + | ((LARc[4] & 0xF) << 2) + | ((LARc[5] >> 2) & 0x3); + *c++ = ((LARc[5] & 0x3) << 6) + | ((LARc[6] & 0x7) << 3) + | (LARc[7] & 0x7); + *c++ = ((Nc[0] & 0x7F) << 1) + | ((bc[0] >> 1) & 0x1); + *c++ = ((bc[0] & 0x1) << 7) + | ((Mc[0] & 0x3) << 5) + | ((xmaxc[0] >> 1) & 0x1F); + *c++ = ((xmaxc[0] & 0x1) << 7) + | ((xmc[0] & 0x7) << 4) + | ((xmc[1] & 0x7) << 1) + | ((xmc[2] >> 2) & 0x1); + *c++ = ((xmc[2] & 0x3) << 6) + | ((xmc[3] & 0x7) << 3) + | (xmc[4] & 0x7); + *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ + |((xmc[6] & 0x7) << 2) + | ((xmc[7] >> 1) & 0x3); + *c++ = ((xmc[7] & 0x1) << 7) + | ((xmc[8] & 0x7) << 4) + | ((xmc[9] & 0x7) << 1) + | ((xmc[10] >> 2) & 0x1); + *c++ = ((xmc[10] & 0x3) << 6) + | ((xmc[11] & 0x7) << 3) + | (xmc[12] & 0x7); + *c++ = ((Nc[1] & 0x7F) << 1) + | ((bc[1] >> 1) & 0x1); + *c++ = ((bc[1] & 0x1) << 7) + | ((Mc[1] & 0x3) << 5) + | ((xmaxc[1] >> 1) & 0x1F); + *c++ = ((xmaxc[1] & 0x1) << 7) + | ((xmc[13] & 0x7) << 4) + | ((xmc[14] & 0x7) << 1) + | ((xmc[15] >> 2) & 0x1); + *c++ = ((xmc[15] & 0x3) << 6) + | ((xmc[16] & 0x7) << 3) + | (xmc[17] & 0x7); + *c++ = ((xmc[18] & 0x7) << 5) + | ((xmc[19] & 0x7) << 2) + | ((xmc[20] >> 1) & 0x3); + *c++ = ((xmc[20] & 0x1) << 7) + | ((xmc[21] & 0x7) << 4) + | ((xmc[22] & 0x7) << 1) + | ((xmc[23] >> 2) & 0x1); + *c++ = ((xmc[23] & 0x3) << 6) + | ((xmc[24] & 0x7) << 3) + | (xmc[25] & 0x7); + *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */ + |((bc[2] >> 1) & 0x1); + *c++ = ((bc[2] & 0x1) << 7) + | ((Mc[2] & 0x3) << 5) + | ((xmaxc[2] >> 1) & 0x1F); + *c++ = ((xmaxc[2] & 0x1) << 7) + | ((xmc[26] & 0x7) << 4) + | ((xmc[27] & 0x7) << 1) + | ((xmc[28] >> 2) & 0x1); + *c++ = ((xmc[28] & 0x3) << 6) + | ((xmc[29] & 0x7) << 3) + | (xmc[30] & 0x7); + *c++ = ((xmc[31] & 0x7) << 5) + | ((xmc[32] & 0x7) << 2) + | ((xmc[33] >> 1) & 0x3); + *c++ = ((xmc[33] & 0x1) << 7) + | ((xmc[34] & 0x7) << 4) + | ((xmc[35] & 0x7) << 1) + | ((xmc[36] >> 2) & 0x1); + *c++ = ((xmc[36] & 0x3) << 6) + | ((xmc[37] & 0x7) << 3) + | (xmc[38] & 0x7); + *c++ = ((Nc[3] & 0x7F) << 1) + | ((bc[3] >> 1) & 0x1); + *c++ = ((bc[3] & 0x1) << 7) + | ((Mc[3] & 0x3) << 5) + | ((xmaxc[3] >> 1) & 0x1F); + *c++ = ((xmaxc[3] & 0x1) << 7) + | ((xmc[39] & 0x7) << 4) + | ((xmc[40] & 0x7) << 1) + | ((xmc[41] >> 2) & 0x1); + *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ + |((xmc[42] & 0x7) << 3) + | (xmc[43] & 0x7); + *c++ = ((xmc[44] & 0x7) << 5) + | ((xmc[45] & 0x7) << 2) + | ((xmc[46] >> 1) & 0x3); + *c++ = ((xmc[46] & 0x1) << 7) + | ((xmc[47] & 0x7) << 4) + | ((xmc[48] & 0x7) << 1) + | ((xmc[49] >> 2) & 0x1); + *c++ = ((xmc[49] & 0x3) << 6) + | ((xmc[50] & 0x7) << 3) + | (xmc[51] & 0x7); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_expl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_expl.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,199 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_explode.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "private.h" +#include "gsm.h" +#include "proto.h" + +int gsm_explode P3((s, c, target), gsm s, gsm_byte * c, + gsm_signal * target) +{ + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) + return -1; + +#define LARc target + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + +#define Nc (target + 8) + + Nc[0] = (*c >> 1) & 0x7F; + +#define bc (target + 9) + + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + +#define Mc (target + 10) + + Mc[0] = (*c >> 5) & 0x3; + +#define xmaxc (target + 11) + + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + +#define xmc (target + 12) + + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + +#undef Nc +#define Nc (target + 25 - 1) + + Nc[1] = (*c >> 1) & 0x7F; + +#undef bc +#define bc (target + 26 - 1) + + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + +#undef Mc +#define Mc (target + 27 - 1) + + Mc[1] = (*c >> 5) & 0x3; + +#undef xmaxc +#define xmaxc (target + 28 - 1) + + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + +#undef xmc +#define xmc (target + 29 - 13) + + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + +#undef Nc +#define Nc (target + 42 - 2) + + Nc[2] = (*c >> 1) & 0x7F; + +#undef bc +#define bc (target + 43 - 2) + + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + +#undef Mc +#define Mc (target + 44 - 2) + + Mc[2] = (*c >> 5) & 0x3; + +#undef xmaxc +#define xmaxc (target + 45 - 2) + + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + +#undef xmc +#define xmc (target + 46 - 26) + + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + +#undef Nc +#define Nc (target + 59 - 3) + + Nc[3] = (*c >> 1) & 0x7F; + +#undef bc +#define bc (target + 60 - 3) + + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + +#undef Mc +#define Mc (target + 61 - 3) + + Mc[3] = (*c >> 5) & 0x3; + +#undef xmaxc +#define xmaxc (target + 62 - 3) + + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + +#undef xmc +#define xmc (target + 63 - 39) + + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + return 0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_impl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_impl.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,250 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_implode.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +void gsm_implode P3((s, source, c), gsm s, gsm_signal * source, + gsm_byte * c) +{ + /* variable size index + + GSM_MAGIC 4 - + + LARc[0] 6 0 + LARc[1] 6 1 + LARc[2] 5 2 + LARc[3] 5 3 + LARc[4] 4 4 + LARc[5] 4 5 + LARc[6] 3 6 + LARc[7] 3 7 + + Nc[0] 7 8 + bc[0] 2 9 + Mc[0] 2 10 + xmaxc[0] 6 11 + xmc[0] 3 12 + xmc[1] 3 13 + xmc[2] 3 14 + xmc[3] 3 15 + xmc[4] 3 16 + xmc[5] 3 17 + xmc[6] 3 18 + xmc[7] 3 19 + xmc[8] 3 20 + xmc[9] 3 21 + xmc[10] 3 22 + xmc[11] 3 23 + xmc[12] 3 24 + + Nc[1] 7 25 + bc[1] 2 26 + Mc[1] 2 27 + xmaxc[1] 6 28 + xmc[13] 3 29 + xmc[14] 3 30 + xmc[15] 3 31 + xmc[16] 3 32 + xmc[17] 3 33 + xmc[18] 3 34 + xmc[19] 3 35 + xmc[20] 3 36 + xmc[21] 3 37 + xmc[22] 3 38 + xmc[23] 3 39 + xmc[24] 3 40 + xmc[25] 3 41 + + Nc[2] 7 42 + bc[2] 2 43 + Mc[2] 2 44 + xmaxc[2] 6 45 + xmc[26] 3 46 + xmc[27] 3 47 + xmc[28] 3 48 + xmc[29] 3 49 + xmc[30] 3 50 + xmc[31] 3 51 + xmc[32] 3 52 + xmc[33] 3 53 + xmc[34] 3 54 + xmc[35] 3 55 + xmc[36] 3 56 + xmc[37] 3 57 + xmc[38] 3 58 + + Nc[3] 7 59 + bc[3] 2 60 + Mc[3] 2 61 + xmaxc[3] 6 62 + xmc[39] 3 63 + xmc[40] 3 64 + xmc[41] 3 65 + xmc[42] 3 66 + xmc[43] 3 67 + xmc[44] 3 68 + xmc[45] 3 69 + xmc[46] 3 70 + xmc[47] 3 71 + xmc[48] 3 72 + xmc[49] 3 73 + xmc[50] 3 74 + xmc[51] 3 75 + */ + + +#define LARc source + + *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ + |((LARc[0] >> 2) & 0xF); + *c++ = ((LARc[0] & 0x3) << 6) + | (LARc[1] & 0x3F); + *c++ = ((LARc[2] & 0x1F) << 3) + | ((LARc[3] >> 2) & 0x7); + *c++ = ((LARc[3] & 0x3) << 6) + | ((LARc[4] & 0xF) << 2) + | ((LARc[5] >> 2) & 0x3); + *c++ = ((LARc[5] & 0x3) << 6) + | ((LARc[6] & 0x7) << 3) + | (LARc[7] & 0x7); + +#define Nc (source + 8) + + *c++ = ((Nc[0] & 0x7F) << 1) +#define bc (source + 9) + | ((bc[0] >> 1) & 0x1); + *c++ = ((bc[0] & 0x1) << 7) +#define Mc (source + 10) + | ((Mc[0] & 0x3) << 5) +#define xmaxc (source + 11) + | ((xmaxc[0] >> 1) & 0x1F); + *c++ = ((xmaxc[0] & 0x1) << 7) +#define xmc (source + 12) + | ((xmc[0] & 0x7) << 4) + | ((xmc[1] & 0x7) << 1) + | ((xmc[2] >> 2) & 0x1); + *c++ = ((xmc[2] & 0x3) << 6) + | ((xmc[3] & 0x7) << 3) + | (xmc[4] & 0x7); + *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ + |((xmc[6] & 0x7) << 2) + | ((xmc[7] >> 1) & 0x3); + *c++ = ((xmc[7] & 0x1) << 7) + | ((xmc[8] & 0x7) << 4) + | ((xmc[9] & 0x7) << 1) + | ((xmc[10] >> 2) & 0x1); + *c++ = ((xmc[10] & 0x3) << 6) + | ((xmc[11] & 0x7) << 3) + | (xmc[12] & 0x7); + +#undef Nc +#define Nc (source + 25 - 1) + + *c++ = ((Nc[1] & 0x7F) << 1) +#undef bc +#define bc (source + 26 - 1) + | ((bc[1] >> 1) & 0x1); + *c++ = ((bc[1] & 0x1) << 7) +#undef Mc +#define Mc (source + 27 - 1) + | ((Mc[1] & 0x3) << 5) +#undef xmaxc +#define xmaxc (source + 28 - 1) + | ((xmaxc[1] >> 1) & 0x1F); + *c++ = ((xmaxc[1] & 0x1) << 7) +#undef xmc +#define xmc (source + 29 - 13) + | ((xmc[13] & 0x7) << 4) + | ((xmc[14] & 0x7) << 1) + | ((xmc[15] >> 2) & 0x1); + *c++ = ((xmc[15] & 0x3) << 6) + | ((xmc[16] & 0x7) << 3) + | (xmc[17] & 0x7); + *c++ = ((xmc[18] & 0x7) << 5) + | ((xmc[19] & 0x7) << 2) + | ((xmc[20] >> 1) & 0x3); + *c++ = ((xmc[20] & 0x1) << 7) + | ((xmc[21] & 0x7) << 4) + | ((xmc[22] & 0x7) << 1) + | ((xmc[23] >> 2) & 0x1); + *c++ = ((xmc[23] & 0x3) << 6) + | ((xmc[24] & 0x7) << 3) + | (xmc[25] & 0x7); + +#undef Nc +#define Nc (source + 42 - 2) + + *c++ = ((Nc[2] & 0x7F) << 1) + /* 20 */ +#undef bc +#define bc (source + 43 - 2) + | ((bc[2] >> 1) & 0x1); + *c++ = ((bc[2] & 0x1) << 7) +#undef Mc +#define Mc (source + 44 - 2) + | ((Mc[2] & 0x3) << 5) +#undef xmaxc +#define xmaxc (source + 45 - 2) + | ((xmaxc[2] >> 1) & 0x1F); + *c++ = ((xmaxc[2] & 0x1) << 7) +#undef xmc +#define xmc (source + 46 - 26) + | ((xmc[26] & 0x7) << 4) + | ((xmc[27] & 0x7) << 1) + | ((xmc[28] >> 2) & 0x1); + *c++ = ((xmc[28] & 0x3) << 6) + | ((xmc[29] & 0x7) << 3) + | (xmc[30] & 0x7); + *c++ = ((xmc[31] & 0x7) << 5) + | ((xmc[32] & 0x7) << 2) + | ((xmc[33] >> 1) & 0x3); + *c++ = ((xmc[33] & 0x1) << 7) + | ((xmc[34] & 0x7) << 4) + | ((xmc[35] & 0x7) << 1) + | ((xmc[36] >> 2) & 0x1); + *c++ = ((xmc[36] & 0x3) << 6) + | ((xmc[37] & 0x7) << 3) + | (xmc[38] & 0x7); + +#undef Nc +#define Nc (source + 59 - 3) + + *c++ = ((Nc[3] & 0x7F) << 1) +#undef bc +#define bc (source + 60 - 3) + | ((bc[3] >> 1) & 0x1); + *c++ = ((bc[3] & 0x1) << 7) +#undef Mc +#define Mc (source + 61 - 3) + | ((Mc[3] & 0x3) << 5) +#undef xmaxc +#define xmaxc (source + 62 - 3) + | ((xmaxc[3] >> 1) & 0x1F); + *c++ = ((xmaxc[3] & 0x1) << 7) +#undef xmc +#define xmc (source + 63 - 39) + | ((xmc[39] & 0x7) << 4) + | ((xmc[40] & 0x7) << 1) + | ((xmc[41] >> 2) & 0x1); + *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ + |((xmc[42] & 0x7) << 3) + | (xmc[43] & 0x7); + *c++ = ((xmc[44] & 0x7) << 5) + | ((xmc[45] & 0x7) << 2) + | ((xmc[46] >> 1) & 0x3); + *c++ = ((xmc[46] & 0x1) << 7) + | ((xmc[47] & 0x7) << 4) + | ((xmc[48] & 0x7) << 1) + | ((xmc[49] >> 2) & 0x1); + *c++ = ((xmc[49] & 0x3) << 6) + | ((xmc[50] & 0x7) << 3) + | (xmc[51] & 0x7); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_opti.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_opti.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,40 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_option.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +int gsm_option P3((r, opt, val), gsm r, int opt, int *val) +{ + int result = -1; + + switch (opt) { + case GSM_OPT_VERBOSE: +#ifndef NDEBUG + result = r->verbose; + if (val) + r->verbose = *val; +#endif + break; + + case GSM_OPT_FAST: + +#if defined(FAST) && defined(USE_FLOAT_MUL) + result = r->fast; + if (val) + r->fast = !!*val; +#endif + break; + + default: + break; + } + return result; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/gsm_prin.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/gsm_prin.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,169 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/gsm_print.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +int gsm_print P3((f, s, c), FILE * f, gsm s, gsm_byte * c) +{ + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13 * 4]; + + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) + return -1; + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + + + Nc[0] = (*c >> 1) & 0x7F; + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + Mc[0] = (*c >> 5) & 0x3; + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + + Nc[1] = (*c >> 1) & 0x7F; + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + Mc[1] = (*c >> 5) & 0x3; + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + + + Nc[2] = (*c >> 1) & 0x7F; + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + Mc[2] = (*c >> 5) & 0x3; + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + + Nc[3] = (*c >> 1) & 0x7F; + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + Mc[3] = (*c >> 5) & 0x3; + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + fprintf(f, + "LARc:\t%2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d\n", + LARc[0], LARc[1], LARc[2], LARc[3], LARc[4], LARc[5], LARc[6], + LARc[7]); + + fprintf(f, "#1: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[0], bc[0], Mc[0], xmaxc[0]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[0], xmc[1], xmc[2], xmc[3], xmc[4], xmc[5], xmc[6], + xmc[7], xmc[8], xmc[9], xmc[10], xmc[11], xmc[12]); + + fprintf(f, "#2: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[1], bc[1], Mc[1], xmaxc[1]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[13 + 0], xmc[13 + 1], xmc[13 + 2], xmc[13 + 3], xmc[13 + 4], + xmc[13 + 5], xmc[13 + 6], xmc[13 + 7], xmc[13 + 8], xmc[13 + 9], + xmc[13 + 10], xmc[13 + 11], xmc[13 + 12]); + + fprintf(f, "#3: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[2], bc[2], Mc[2], xmaxc[2]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[26 + 0], xmc[26 + 1], xmc[26 + 2], xmc[26 + 3], xmc[26 + 4], + xmc[26 + 5], xmc[26 + 6], xmc[26 + 7], xmc[26 + 8], xmc[26 + 9], + xmc[26 + 10], xmc[26 + 11], xmc[26 + 12]); + + fprintf(f, "#4: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[3], bc[3], Mc[3], xmaxc[3]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[39 + 0], xmc[39 + 1], xmc[39 + 2], xmc[39 + 3], xmc[39 + 4], + xmc[39 + 5], xmc[39 + 6], xmc[39 + 7], xmc[39 + 8], xmc[39 + 9], + xmc[39 + 10], xmc[39 + 11], xmc[39 + 12]); + + return 0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/long_ter.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/long_ter.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,779 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/long_term.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +/* Prevent improper operation for 16-bit systems */ +#if defined(MSDOS) || defined(__MSDOS__) +# ifdef USE_TABLE_MUL +# undef USE_TABLE_MUL +# endif +#endif + +#ifdef USE_TABLE_MUL + +unsigned int umul_table[513][256]; + +init_umul_table() +{ + int i, j; + int n; + unsigned int *p = &umul_table[0][0]; + + for (i = 0; i < 513; i++) { + n = 0; + for (j = 0; j < 256; j++) { + *p++ = n; + n += i; + } + } +} + +# define umul(x9, x15) \ + ((int)(umul_table[x9][x15 & 0x0FF] + (umul_table[x9][ x15 >> 8 ] << 8))) + +# define table_mul(a, b) \ + ( (a < 0) ? ((b < 0) ? umul(-a, -b) : -umul(-a, b)) \ + : ((b < 0) ? -umul(a, -b) : umul(a, b))) + +#endif /* USE_TABLE_MUL */ + + + +/* + * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION + */ + + +/* + * This procedure computes the LTP gain (bc) and the LTP lag (Nc) + * for the long term analysis filter. This is done by calculating a + * maximum of the cross-correlation function between the current + * sub-segment short term residual signal d[0..39] (output of + * the short term analysis filter; for simplification the index + * of this array begins at 0 and ends at 39 for each sub-segment of the + * RPE-LTP analysis) and the previous reconstructed short term + * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be + * performed to avoid overflow. + */ + + /* This procedure exists in four versions. First, the two integer + * versions with or without table-multiplication (as one function); + * then, the two floating point versions (as another function), with + * or without scaling. + */ + +#ifndef USE_FLOAT_MUL + +static void Calculation_of_the_LTP_parameters P4((d, dp, bc_out, Nc_out), register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) +{ + register ulongword utmp; /* for L_ADD */ + + register int k, lambda; + word Nc, bc; + word wt[40]; + + longword L_max, L_power; + word R, S, dmax, scal; + register word temp; + + /* Search of the optimum scaling of d[0..39]. + */ + dmax = 0; + + for (k = 0; k <= 39; k++) { + temp = d[k]; + temp = GSM_ABS(temp); + if (temp > dmax) + dmax = temp; + } + + temp = 0; + if (dmax == 0) + scal = 0; + else { + assert(dmax > 0); + temp = gsm_norm((longword) dmax << 16); + } + + if (temp > 6) + scal = 0; + else + scal = 6 - temp; + + assert(scal >= 0); + + /* Initialization of a working array wt + */ + + for (k = 0; k <= 39; k++) + wt[k] = SASR(d[k], scal); + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda++) { + +# ifdef STEP +# undef STEP +# endif + +# ifdef USE_TABLE_MUL +# define STEP(k) (table_mul(wt[k], dp[k - lambda])) +# else +# define STEP(k) (wt[k] * dp[k - lambda]) +# endif + + register longword L_result; + + L_result = STEP(0); + L_result += STEP(1); + L_result += STEP(2); + L_result += STEP(3); + L_result += STEP(4); + L_result += STEP(5); + L_result += STEP(6); + L_result += STEP(7); + L_result += STEP(8); + L_result += STEP(9); + L_result += STEP(10); + L_result += STEP(11); + L_result += STEP(12); + L_result += STEP(13); + L_result += STEP(14); + L_result += STEP(15); + L_result += STEP(16); + L_result += STEP(17); + L_result += STEP(18); + L_result += STEP(19); + L_result += STEP(20); + L_result += STEP(21); + L_result += STEP(22); + L_result += STEP(23); + L_result += STEP(24); + L_result += STEP(25); + L_result += STEP(26); + L_result += STEP(27); + L_result += STEP(28); + L_result += STEP(29); + L_result += STEP(30); + L_result += STEP(31); + L_result += STEP(32); + L_result += STEP(33); + L_result += STEP(34); + L_result += STEP(35); + L_result += STEP(36); + L_result += STEP(37); + L_result += STEP(38); + L_result += STEP(39); + + if (L_result > L_max) { + + Nc = lambda; + L_max = L_result; + } + } + + *Nc_out = Nc; + + L_max <<= 1; + + /* Rescaling of L_max + */ + assert(scal <= 100 && scal >= -100); + L_max = L_max >> (6 - scal); /* sub(6, scal) */ + + assert(Nc <= 120 && Nc >= 40); + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + L_power = 0; + for (k = 0; k <= 39; k++) { + + register longword L_temp; + + L_temp = SASR((longword) (dp[k - Nc]), 3); + L_power += L_temp * L_temp; + } + L_power <<= 1; /* from L_MULT */ + + /* Normalization of L_max and L_power + */ + + if (L_max <= 0) { + *bc_out = 0; + return; + } + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + temp = gsm_norm(L_power); + + R = SASR(L_max << temp, 16); + S = SASR(L_power << temp, 16); + + /* Coding of the LTP gain + */ + + /* Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + for (bc = 0; bc <= 2; bc++) + if (R <= gsm_mult(S, gsm_DLB[bc])) + break; + *bc_out = bc; +} + +#else /* USE_FLOAT_MUL */ + +static void Calculation_of_the_LTP_parameters P4((d, dp, bc_out, Nc_out), register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) +{ + /* register ulongword utmp; / * for L_ADD */ + + register int k, lambda; + word Nc, bc; + + float wt_float[40]; + float dp_float_base[120], *dp_float = dp_float_base + 120; + + longword L_max, L_power; + word R, S, dmax, scal; + register word temp; + + /* Search of the optimum scaling of d[0..39]. + */ + dmax = 0; + + for (k = 0; k <= 39; k++) { + temp = d[k]; + temp = GSM_ABS(temp); + if (temp > dmax) + dmax = temp; + } + + temp = 0; + if (dmax == 0) + scal = 0; + else { + assert(dmax > 0); + temp = gsm_norm((longword) dmax << 16); + } + + if (temp > 6) + scal = 0; + else + scal = 6 - temp; + + assert(scal >= 0); + + /* Initialization of a working array wt + */ + + for (k = 0; k < 40; k++) + wt_float[k] = SASR(d[k], scal); + for (k = -120; k < 0; k++) + dp_float[k] = dp[k]; + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda += 9) { + + /* Calculate L_result for l = lambda .. lambda + 9. + */ + register float *lp = dp_float - lambda; + + register float W; + register float a = lp[-8], b = lp[-7], c = lp[-6], + d = lp[-5], e = lp[-4], f = lp[-3], g = lp[-2], h = lp[-1]; + register float E; + register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0, + S5 = 0, S6 = 0, S7 = 0, S8 = 0; + +# ifdef STEP +# undef STEP +# endif + +# define STEP(K, a, b, c, d, e, f, g, h) \ + W = wt_float[K]; \ + E = W * a; S8 += E; \ + E = W * b; S7 += E; \ + E = W * c; S6 += E; \ + E = W * d; S5 += E; \ + E = W * e; S4 += E; \ + E = W * f; S3 += E; \ + E = W * g; S2 += E; \ + E = W * h; S1 += E; \ + a = lp[K]; \ + E = W * a; S0 += E + +# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h) +# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a) +# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b) +# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c) +# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d) +# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e) +# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f) +# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g) + + STEP_A(0); + STEP_B(1); + STEP_C(2); + STEP_D(3); + STEP_E(4); + STEP_F(5); + STEP_G(6); + STEP_H(7); + + STEP_A(8); + STEP_B(9); + STEP_C(10); + STEP_D(11); + STEP_E(12); + STEP_F(13); + STEP_G(14); + STEP_H(15); + + STEP_A(16); + STEP_B(17); + STEP_C(18); + STEP_D(19); + STEP_E(20); + STEP_F(21); + STEP_G(22); + STEP_H(23); + + STEP_A(24); + STEP_B(25); + STEP_C(26); + STEP_D(27); + STEP_E(28); + STEP_F(29); + STEP_G(30); + STEP_H(31); + + STEP_A(32); + STEP_B(33); + STEP_C(34); + STEP_D(35); + STEP_E(36); + STEP_F(37); + STEP_G(38); + STEP_H(39); + + if (S0 > L_max) { + L_max = S0; + Nc = lambda; + } + if (S1 > L_max) { + L_max = S1; + Nc = lambda + 1; + } + if (S2 > L_max) { + L_max = S2; + Nc = lambda + 2; + } + if (S3 > L_max) { + L_max = S3; + Nc = lambda + 3; + } + if (S4 > L_max) { + L_max = S4; + Nc = lambda + 4; + } + if (S5 > L_max) { + L_max = S5; + Nc = lambda + 5; + } + if (S6 > L_max) { + L_max = S6; + Nc = lambda + 6; + } + if (S7 > L_max) { + L_max = S7; + Nc = lambda + 7; + } + if (S8 > L_max) { + L_max = S8; + Nc = lambda + 8; + } + } + *Nc_out = Nc; + + L_max <<= 1; + + /* Rescaling of L_max + */ + assert(scal <= 100 && scal >= -100); + L_max = L_max >> (6 - scal); /* sub(6, scal) */ + + assert(Nc <= 120 && Nc >= 40); + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + L_power = 0; + for (k = 0; k <= 39; k++) { + + register longword L_temp; + + L_temp = SASR(dp[k - Nc], 3); + L_power += L_temp * L_temp; + } + L_power <<= 1; /* from L_MULT */ + + /* Normalization of L_max and L_power + */ + + if (L_max <= 0) { + *bc_out = 0; + return; + } + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + temp = gsm_norm(L_power); + + R = SASR(L_max << temp, 16); + S = SASR(L_power << temp, 16); + + /* Coding of the LTP gain + */ + + /* Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + for (bc = 0; bc <= 2; bc++) + if (R <= gsm_mult(S, gsm_DLB[bc])) + break; + *bc_out = bc; +} + +#ifdef FAST + +static void Fast_Calculation_of_the_LTP_parameters P4((d, dp, bc_out, Nc_out), register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) +{ + register ulongword utmp; /* for L_ADD */ + + register int k, lambda; + word Nc, bc; + + float wt_float[40]; + float dp_float_base[120], *dp_float = dp_float_base + 120; + + register float L_max, L_power; + + for (k = 0; k < 40; ++k) + wt_float[k] = (float) d[k]; + for (k = -120; k <= 0; ++k) + dp_float[k] = (float) dp[k]; + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda += 9) { + + /* Calculate L_result for l = lambda .. lambda + 9. + */ + register float *lp = dp_float - lambda; + + register float W; + register float a = lp[-8], b = lp[-7], c = lp[-6], + d = lp[-5], e = lp[-4], f = lp[-3], g = lp[-2], h = lp[-1]; + register float E; + register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0, + S5 = 0, S6 = 0, S7 = 0, S8 = 0; + +# ifdef STEP +# undef STEP +# endif + +# define STEP(K, a, b, c, d, e, f, g, h) \ + W = wt_float[K]; \ + E = W * a; S8 += E; \ + E = W * b; S7 += E; \ + E = W * c; S6 += E; \ + E = W * d; S5 += E; \ + E = W * e; S4 += E; \ + E = W * f; S3 += E; \ + E = W * g; S2 += E; \ + E = W * h; S1 += E; \ + a = lp[K]; \ + E = W * a; S0 += E + +# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h) +# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a) +# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b) +# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c) +# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d) +# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e) +# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f) +# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g) + + STEP_A(0); + STEP_B(1); + STEP_C(2); + STEP_D(3); + STEP_E(4); + STEP_F(5); + STEP_G(6); + STEP_H(7); + + STEP_A(8); + STEP_B(9); + STEP_C(10); + STEP_D(11); + STEP_E(12); + STEP_F(13); + STEP_G(14); + STEP_H(15); + + STEP_A(16); + STEP_B(17); + STEP_C(18); + STEP_D(19); + STEP_E(20); + STEP_F(21); + STEP_G(22); + STEP_H(23); + + STEP_A(24); + STEP_B(25); + STEP_C(26); + STEP_D(27); + STEP_E(28); + STEP_F(29); + STEP_G(30); + STEP_H(31); + + STEP_A(32); + STEP_B(33); + STEP_C(34); + STEP_D(35); + STEP_E(36); + STEP_F(37); + STEP_G(38); + STEP_H(39); + + if (S0 > L_max) { + L_max = S0; + Nc = lambda; + } + if (S1 > L_max) { + L_max = S1; + Nc = lambda + 1; + } + if (S2 > L_max) { + L_max = S2; + Nc = lambda + 2; + } + if (S3 > L_max) { + L_max = S3; + Nc = lambda + 3; + } + if (S4 > L_max) { + L_max = S4; + Nc = lambda + 4; + } + if (S5 > L_max) { + L_max = S5; + Nc = lambda + 5; + } + if (S6 > L_max) { + L_max = S6; + Nc = lambda + 6; + } + if (S7 > L_max) { + L_max = S7; + Nc = lambda + 7; + } + if (S8 > L_max) { + L_max = S8; + Nc = lambda + 8; + } + } + *Nc_out = Nc; + + if (L_max <= 0.) { + *bc_out = 0; + return; + } + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + dp_float -= Nc; + L_power = 0; + for (k = 0; k < 40; ++k) { + register float f = dp_float[k]; + L_power += f * f; + } + + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + /* Coding of the LTP gain + * Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + lambda = L_max / L_power * 32768.; + for (bc = 0; bc <= 2; ++bc) + if (lambda <= gsm_DLB[bc]) + break; + *bc_out = bc; +} + +#endif /* FAST */ +#endif /* USE_FLOAT_MUL */ + + +/* 4.2.12 */ + +static void Long_term_analysis_filtering P6((bc, Nc, dp, d, dpp, e), word bc, /* IN */ + word Nc, /* IN */ + register word * dp, /* previous d [-120..-1] IN */ + register word * d, /* d [0..39] IN */ + register word * dpp, /* estimate [0..39] OUT */ + register word * e /* long term res. signal [0..39] OUT */ + ) +/* + * In this part, we have to decode the bc parameter to compute + * the samples of the estimate dpp[0..39]. The decoding of bc needs the + * use of table 4.3b. The long term residual signal e[0..39] + * is then calculated to be fed to the RPE encoding section. + */ +{ + /* register word bp; Was reported as unused */ + register int k; + register longword ltmp; + +# ifdef STEP +# undef STEP +# endif + +# define STEP(BP) \ + for (k = 0; k <= 39; k++) { \ + dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \ + e[k] = GSM_SUB( d[k], dpp[k] ); \ + } + + switch (bc) { + case 0: + STEP(3277); + break; + case 1: + STEP(11469); + break; + case 2: + STEP(21299); + break; + case 3: + STEP(32767); + break; + } +} + +void Gsm_Long_Term_Predictor P7((S, d, dp, e, dpp, Nc, bc), /* 4x for 160 samples */ + struct gsm_state *S, word * d, /* [0..39] residual signal IN */ + word * dp, /* [-120..-1] d' IN */ + word * e, /* [0..39] OUT */ + word * dpp, /* [0..39] OUT */ + word * Nc, /* correlation lag OUT */ + word * bc /* gain factor OUT */ + ) +{ + assert(d); + assert(dp); + assert(e); + assert(dpp); + assert(Nc); + assert(bc); + +#if defined(FAST) && defined(USE_FLOAT_MUL) + if (S->fast) + Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc); + else +#endif + Calculation_of_the_LTP_parameters(d, dp, bc, Nc); + + Long_term_analysis_filtering(*bc, *Nc, dp, d, dpp, e); +} + +/* 4.3.2 */ +void Gsm_Long_Term_Synthesis_Filtering P5((S, Ncr, bcr, erp, drp), struct gsm_state *S, word Ncr, word bcr, register word * erp, /* [0..39] IN */ + register word * drp /* [-120..-1] IN, [0..40] OUT */ + ) +/* + * This procedure uses the bcr and Ncr parameter to realize the + * long term synthesis filtering. The decoding of bcr needs + * table 4.3b. + */ +{ + register longword ltmp; /* for ADD */ + register int k; + word brp, drpp, Nr; + + /* Check the limits of Nr. + */ + Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr; + S->nrp = Nr; + assert(Nr >= 40 && Nr <= 120); + + /* Decoding of the LTP gain bcr + */ + brp = gsm_QLB[bcr]; + + /* Computation of the reconstructed short term residual + * signal drp[0..39] + */ + assert(brp != MIN_WORD); + + for (k = 0; k <= 39; k++) { + drpp = GSM_MULT_R(brp, drp[k - Nr]); + drp[k] = GSM_ADD(erp[k], drpp); + } + + /* + * Update of the reconstructed short term residual signal + * drp[ -1..-120 ] + */ + + for (k = 0; k <= 119; k++) + drp[-120 + k] = drp[-80 + k]; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/lpc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/lpc.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,383 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/lpc.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +#undef P + +/* + * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION + */ + +/* 4.2.4 */ + + +static void Autocorrelation P2((s, L_ACF), word * s, /* [0..159] IN/OUT */ + longword * L_ACF) +{ /* [0..8] OUT */ + /* + * The goal is to compute the array L_ACF[k]. The signal s[i] must + * be scaled in order to avoid an overflow situation. + */ + register int k, i; + + word temp, smax, scalauto; + /* longword L_temp; */ + +#ifdef USE_FLOAT_MUL + float float_s[160]; + /* longword L_temp2; */ +#else + longword L_temp2; +#endif + + /* Dynamic scaling of the array s[0..159] + */ + + /* Search for the maximum. + */ + smax = 0; + for (k = 0; k <= 159; k++) { + temp = GSM_ABS(s[k]); + if (temp > smax) + smax = temp; + } + + /* Computation of the scaling factor. + */ + if (smax == 0) + scalauto = 0; + else { + assert(smax > 0); + scalauto = 4 - gsm_norm((longword) smax << 16); /* sub(4,..) */ + } + + /* Scaling of the array s[0...159] + */ + + if (scalauto > 0) { + +# ifdef USE_FLOAT_MUL +# define SCALE(n) \ + case n: for (k = 0; k <= 159; k++) \ + float_s[k] = (float) \ + (s[k] = GSM_MULT_R(s[k], 16384 >> (n-1)));\ + break; +# else +# define SCALE(n) \ + case n: for (k = 0; k <= 159; k++) \ + s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\ + break; +# endif /* USE_FLOAT_MUL */ + + switch (scalauto) { + SCALE(1) + SCALE(2) + SCALE(3) + SCALE(4) + } +# undef SCALE + } +# ifdef USE_FLOAT_MUL + else + for (k = 0; k <= 159; k++) + float_s[k] = (float) s[k]; +# endif + + /* Compute the L_ACF[..]. + */ + { +# ifdef USE_FLOAT_MUL + register float *sp = float_s; + register float sl = *sp; +# else + word *sp = s; + word sl = *sp; +# endif + +# define STEP(k) L_ACF[k] += (longword)(sl * sp[ -(k) ]); +# define NEXTI sl = *++sp + + + for (k = 9; k--; L_ACF[k] = 0); + + STEP(0); + NEXTI; + STEP(0); + STEP(1); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + STEP(3); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + STEP(3); + STEP(4); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + STEP(3); + STEP(4); + STEP(5); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + STEP(3); + STEP(4); + STEP(5); + STEP(6); + NEXTI; + STEP(0); + STEP(1); + STEP(2); + STEP(3); + STEP(4); + STEP(5); + STEP(6); + STEP(7); + + for (i = 8; i <= 159; i++) { + + NEXTI; + + STEP(0); + STEP(1); + STEP(2); + STEP(3); + STEP(4); + STEP(5); + STEP(6); + STEP(7); + STEP(8); + } + + for (k = 9; k--; L_ACF[k] <<= 1); + + } + /* Rescaling of the array s[0..159] + */ + if (scalauto > 0) { + assert(scalauto <= 4); + for (k = 160; k--; *s++ <<= scalauto); + } +} + +#if defined(USE_FLOAT_MUL) && defined(FAST) + +static void Fast_Autocorrelation P2((s, L_ACF), word * s, /* [0..159] IN/OUT */ + longword * L_ACF) +{ /* [0..8] OUT */ + register int k, i; + float f_L_ACF[9]; + float scale; + + float s_f[160]; + register float *sf = s_f; + + for (i = 0; i < 160; ++i) + sf[i] = s[i]; + for (k = 0; k <= 8; k++) { + register float L_temp2 = 0; + register float *sfl = sf - k; + for (i = k; i < 160; ++i) + L_temp2 += sf[i] * sfl[i]; + f_L_ACF[k] = L_temp2; + } + scale = MAX_LONGWORD / f_L_ACF[0]; + + for (k = 0; k <= 8; k++) { + L_ACF[k] = f_L_ACF[k] * scale; + } +} +#endif /* defined (USE_FLOAT_MUL) && defined (FAST) */ + +/* 4.2.5 */ + +static void Reflection_coefficients P2((L_ACF, r), longword * L_ACF, /* 0...8 IN */ + register word * r /* 0...7 OUT */ + ) +{ + register int i, m, n; + register word temp; + register longword ltmp; + word ACF[9]; /* 0..8 */ + word P[9]; /* 0..8 */ + word K[9]; /* 2..8 */ + + /* Schur recursion with 16 bits arithmetic. + */ + + if (L_ACF[0] == 0) { /* everything is the same. */ + for (i = 8; i--; *r++ = 0); + return; + } + + assert(L_ACF[0] != 0); + temp = gsm_norm(L_ACF[0]); + + assert(temp >= 0 && temp < 32); + + /* ? overflow ? */ + for (i = 0; i <= 8; i++) + ACF[i] = SASR(L_ACF[i] << temp, 16); + + /* Initialize array P[..] and K[..] for the recursion. + */ + + for (i = 1; i <= 7; i++) + K[i] = ACF[i]; + for (i = 0; i <= 8; i++) + P[i] = ACF[i]; + + /* Compute reflection coefficients + */ + for (n = 1; n <= 8; n++, r++) { + + temp = P[1]; + temp = GSM_ABS(temp); + if (P[0] < temp) { + for (i = n; i <= 8; i++) + *r++ = 0; + return; + } + + *r = gsm_div(temp, P[0]); + + assert(*r >= 0); + if (P[1] > 0) + *r = -*r; /* r[n] = sub(0, r[n]) */ + assert(*r != MIN_WORD); + if (n == 8) + return; + + /* Schur recursion + */ + temp = GSM_MULT_R(P[1], *r); + P[0] = GSM_ADD(P[0], temp); + + for (m = 1; m <= 8 - n; m++) { + temp = GSM_MULT_R(K[m], *r); + P[m] = GSM_ADD(P[m + 1], temp); + + temp = GSM_MULT_R(P[m + 1], *r); + K[m] = GSM_ADD(K[m], temp); + } + } +} + +/* 4.2.6 */ + +static void Transformation_to_Log_Area_Ratios P1((r), register word * r /* 0..7 IN/OUT */ + ) +/* + * The following scaling for r[..] and LAR[..] has been used: + * + * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. + * LAR[..] = integer( real_LAR[..] * 16384 ); + * with -1.625 <= real_LAR <= 1.625 + */ +{ + register word temp; + register int i; + + + /* Computation of the LAR[0..7] from the r[0..7] + */ + for (i = 1; i <= 8; i++, r++) { + + temp = *r; + temp = GSM_ABS(temp); + assert(temp >= 0); + + if (temp < 22118) { + temp >>= 1; + } else if (temp < 31130) { + assert(temp >= 11059); + temp -= 11059; + } else { + assert(temp >= 26112); + temp -= 26112; + temp <<= 2; + } + + *r = *r < 0 ? -temp : temp; + assert(*r != MIN_WORD); + } +} + +/* 4.2.7 */ + +static void Quantization_and_coding P1((LAR), register word * LAR /* [0..7] IN/OUT */ + ) +{ + register word temp; + longword ltmp; + /* ulongword utmp; reported as unused */ + + + /* This procedure needs four tables; the following equations + * give the optimum scaling for the constants: + * + * A[0..7] = integer( real_A[0..7] * 1024 ) + * B[0..7] = integer( real_B[0..7] * 512 ) + * MAC[0..7] = maximum of the LARc[0..7] + * MIC[0..7] = minimum of the LARc[0..7] + */ + +# undef STEP +# define STEP( A, B, MAC, MIC ) \ + temp = GSM_MULT( A, *LAR ); \ + temp = GSM_ADD( temp, B ); \ + temp = GSM_ADD( temp, 256 ); \ + temp = SASR( temp, 9 ); \ + *LAR = temp>MAC ? MAC - MIC : (tempfast) + Fast_Autocorrelation(s, L_ACF); + else +#endif + Autocorrelation(s, L_ACF); + Reflection_coefficients(L_ACF, LARc); + Transformation_to_Log_Area_Ratios(LARc); + Quantization_and_coding(LARc); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/make-vms.com --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/make-vms.com Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,76 @@ +$goto start +$!============================================================================ +$! Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +$! Universitaet Berlin. See the accompanying file "COPYRIGHT" for +$! details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +$! File adapted by simao@cpqd.ansp.br. +$! +$! Machine dependent flags you must configure to port +$! - Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1' +$! - Define USE_FLOAT_MUL if your host multiplies floats faster than integers, +$! e.g. on a SPARCstation. +$! - define FAST together with USE_FLOAT_MUL to enable the GSM library's +$! approximation option for incorrect, but good-enough results. +$! Undefine for compliant operation. +$! - Define NDEBUG to avoid the generation of debug functions along the code +$! - Choose a compiler. The code works both with ANSI and K&R-C. +$! Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to +$! compile without, function prototypes in the header files. +$! +$! - You can use the -DSTUPID_COMPILER to circumvent some compilers' +$! static limits regarding the number of subexpressions in a statement. +$! +$! +$! -- *NOTE*: -- +$! +$! This VMS DCL file created by +$! for the UGST distribution +$!============================================================================= +$start: +$! --> if you want to use VAX-C, uncomment the CC and LIBS lines and +$! one of the CC_OPT below +$ CC = "cc /NOWARNING" !! "/DIA" +$ CC_OPT = "/INC=[]/INC=[-.utl] /DEF=(SASR,NeedFunctionPrototypes=1,NDEBUG)" +$! CC_OPT = "/INC=[]/INC=[-.utl] /DEF=(SASR,FAST,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! CC_OPT = "/INC=[/INC=[-.utl]] /DEF=(SASR,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! CC_OPT = "/INC=[]/INC=[-.utl] /DEF=(VMS,SASR,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! CC_OPT = "/INC=[]/INC=[-.utl] /STANDARD=portable /DEF=(VMS,SASR,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! LIBS = ",SYS$LIBRARY:VAXCRTL/LIB" +$! --> if you want to use GCC, uncomment the CC and LIBS lines and one of +$! the CC_OPT below +$! CC = "gcc" +$! CC_OPT = "/INC=[]/INC=[-.utl] /DEF=(VMS,SASR,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! CC_OPT = "/INC=[]/INC=[-.utl] /DEF=(SASR,USE_FLOAT_MUL,NeedFunctionPrototypes=1,NDEBUG)" +$! LIBS = ",GNU_CC:[000000]GCCLIB/LIB,SYS$LIBRARY:VAXCRTL/LIB" + +$! goto here +$! +$ 'CC' 'CC_OPT' rpedemo.c +$ 'CC' 'CC_OPT' rpeltp.c +$ 'CC' 'CC_OPT' add.c +$ 'CC' 'CC_OPT' code.c +$ 'CC' 'CC_OPT' debug.c +$ 'CC' 'CC_OPT' decode.c +$ 'CC' 'CC_OPT' long_ter.c +$ 'CC' 'CC_OPT' lpc.c +$ 'CC' 'CC_OPT' preproce.c +$ 'CC' 'CC_OPT' rpe.c +$ 'CC' 'CC_OPT' gsm_dest.c +$ 'CC' 'CC_OPT' gsm_deco.c +$ 'CC' 'CC_OPT' gsm_enco.c +$ 'CC' 'CC_OPT' gsm_expl.c +$ 'CC' 'CC_OPT' gsm_impl.c +$ 'CC' 'CC_OPT' gsm_crea.c +$ 'CC' 'CC_OPT' gsm_prin.c +$ 'CC' 'CC_OPT' gsm_opti.c +$ 'CC' 'CC_OPT' short_te.c +$ 'CC' 'CC_OPT' table.c +$! +$ 'CC' 'CC_OPT' g711.c +$ +$here: +$link rpedemo.obj,rpeltp.obj,add.obj,code.obj,debug.obj,decode.obj,- + long_ter.obj,lpc.obj,preproce.obj,rpe.obj,gsm_dest.obj,gsm_deco.obj,- + gsm_enco.obj,gsm_expl.obj,gsm_impl.obj,gsm_crea.obj,- + gsm_prin.obj,gsm_opti.obj,short_te.obj,table.obj,g711.obj'LIBS' +$ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/makefile.cl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/makefile.cl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,122 @@ +#-------------------------------------------------------------------------- +# RPELTP makefile for MS Visual C (Windows 9x/NT/2000) +#-------------------------------------------------------------------------- +# Original Copyright message: +# Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +# Universitaet Berlin. See the accompanying file "COPYRIGHT" for +# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +# +# File adapted by simao.campos@labs.comsat.com for the UGST distribution. +#-------------------------------------------------------------------------- + +# Machine dependent flags you must configure to port + +######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1) +SASR = -DSASR + +######### MUST Define USE_FLOAT_MUL for bit exact performance to GSM Spec. +MULHACK = -DUSE_FLOAT_MUL + +# Choose a compiler. The code works both with ANSI and K&R-C. +# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to +# compile without, function prototypes in the header files. +# +# You can use the -DSTUPID_COMPILER to circumvent some compilers' +# static limits regarding the number of subexpressions in a statement. + +CC = cl +CCFLAGS = -c -W1 -DNeedFunctionPrototypes=1 + +#-------------------------------------------------------------------------- +# +# You shouldn't have to configure below this line if you're porting. +# +#-------------------------------------------------------------------------- + +# Tools +RM=rm -f + +# Local Directories +INC = . + +# Flags + +######### Remove -DNDEBUG to enable assertions. +DEBUG = -DNDEBUG + +######### It's $(CC) $(CFLAGS) +CFLAGS = $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) -I$(INC) -I../utl + + +#-------------------------------------------------------------------------- +# Headers +HEADERS = proto.h unproto.h config.h private.h gsm.h rpeltp.h + +#-------------------------------------------------------------------------- +# Sources +GSM_SOURCES = add.c code.c debug.c decode.c long_ter.c lpc.c \ + preproce.c rpe.c gsm_dest.c gsm_deco.c gsm_enco.c \ + gsm_expl.c gsm_impl.c gsm_crea.c gsm_prin.c gsm_opti.c \ + rpeltp.c short_te.c table.c + +DEMO_SOURCES = rpedemo.c ../g711/g711.c + +SOURCES = $(GSM_SOURCES) $(DEMO_SOURCES) + +#-------------------------------------------------------------------------- +# Object files +GSM_OBJECTS = add.obj code.obj debug.obj decode.obj long_ter.obj lpc.obj \ + preproce.obj rpe.obj gsm_dest.obj gsm_deco.obj gsm_enco.obj \ + gsm_expl.obj gsm_impl.obj gsm_crea.obj gsm_prin.obj \ + gsm_opti.obj rpeltp.obj short_te.obj table.obj + +DEMO_OBJECTS = rpedemo.obj g711.obj + +OBJECTS = $(GSM_OBJECTS) $(DEMO_OBJECTS) + + +# ------------------------------------------------ +# Implicit rules +# ------------------------------------------------ +.c.obj: + $(CC) $(CFLAGS) $? + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +all:: rpedemo + +anyway: clean rpedemo + +clean: + $(RM) $(OBJECTS) + +cleantest: + echo No test file processing available in this directory + +veryclean: clean + $(RM) rpedemo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711.obj: ../g711/g711.c + $(CC) $(CFLAGS) -I../g711 ../g711/g711.c + +rpedemo.obj: rpedemo.c ../g711/g711.h + $(CC) $(CFLAGS) -I../g711 rpedemo.c + +rpedemo: rpedemo.exe +rpedemo.exe: $(OBJECTS) + $(CC) -o rpedemo $(OBJECTS) + +# ------------------------------------------------ +# Run add < add_test.dta to make sure the +# basic arithmetic functions work as intended. +# ------------------------------------------------ +add: add.exe +add.exe: add_test.o + $(CC) $(LFLAGS) -o add add_test.o + +addtst: add.exe add_test.dta + add < add_test.dta > /dev/null diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/makefile.djc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/makefile.djc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,138 @@ +#-------------------------------------------------------------------------- +# RPELTP makefile for the MSDOS port of the gcc compiler (DJGPP) +#-------------------------------------------------------------------------- +# Original Copyright message: +# Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +# Universitaet Berlin. See the accompanying file "COPYRIGHT" for +# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +# +# File adapted by simao@cpqd.ansp.br for the UGST distribution. +#-------------------------------------------------------------------------- +# + +# Machine dependent flags you must configure to port +######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1) +SASR = -DSASR + +######### MUST Define USE_FLOAT_MUL for bit exact performance to GSM Spec. +#MULHACK = -DUSE_FLOAT_MUL + +# Choose a compiler. The code works both with ANSI and K&R-C. +# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to +# compile without, function prototypes in the header files. +# +# You can use the -DSTUPID_COMPILER to circumvent some compilers' +# static limits regarding the number of subexpressions in a statement. + +CC = gcc +CCFLAGS = -c -O2 -DNeedFunctionPrototypes=1 -I../utl + +LD = $(CC) +# LDFLAGS = +# LDLIB = + + +#-------------------------------------------------------------------------- +# +# You shouldn't have to configure below this line if you're porting. +# +#-------------------------------------------------------------------------- + + +# Tools +RM=rm -f + +# Local Directories + +ROOT = .. ### <--- +ADDTST = $(ROOT)/add-test +TST = $(ROOT)/tst +MAN = $(ROOT)/man +BIN = $(ROOT)/bin +###SRC = $(ROOT)/ugst ### <--- +SRC = . +LIB = $(ROOT)/lib +TLS = $(ROOT)/tls +###INC = $(ROOT)/inc +INC = c:\gcc\include + +# Flags + +DEBUG = -DNDEBUG +######### Remove -DNDEBUG to enable assertions. + +CFLAGS = $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) $(CCINC) -I$(INC) +######### It's $(CC) $(CFLAGS) + +LFLAGS = $(LDFLAGS) $(LDINC) +######### It's $(LD) $(LFLAGS) + + +#-------------------------------------------------------------------------- +# Headers +HEADERS = proto.h unproto.h config.h private.h gsm.h rpeltp.h + +#-------------------------------------------------------------------------- +# Sources +GSM_SOURCES = add.c code.c debug.c decode.c long_ter.c lpc.c \ + preproce.c rpe.c gsm_dest.c gsm_deco.c gsm_enco.c \ + gsm_expl.c gsm_impl.c gsm_crea.c gsm_prin.c gsm_opti.c \ + rpeltp.c short_te.c table.c + +DEMO_SOURCES = rpedemo.c ../g711/g711.c + +SOURCES = $(GSM_SOURCES) $(DEMO_SOURCES) + + +#-------------------------------------------------------------------------- +# Object files +GSM_OBJECTS = add.o code.o debug.o decode.o long_ter.o lpc.o \ + preproce.o rpe.o gsm_dest.o gsm_deco.o gsm_enco.o \ + gsm_expl.o gsm_impl.o gsm_crea.o gsm_prin.o gsm_opti.o \ + rpeltp.o short_te.o table.o + +DEMO_OBJECTS = rpedemo.o g711.o + +OBJECTS = $(GSM_OBJECTS) $(DEMO_OBJECTS) + +# ------------------------------------------------ +# Implicit rules +# ------------------------------------------------ +.c.o: + $(CC) $(CFLAGS) $< + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +all:: rpedemo + +clean: + $(RM) $(OBJECTS) + +cleantest: + echo No test file processing available in this directory + +veryclean: clean + $(RM) rpedemo + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711.o: ../g711/g711.c + $(CC) $(CFLAGS) -I../g711 ../g711/g711.c + +rpedemo.o: rpedemo.c ../g711/g711.h + $(CC) $(CFLAGS) -I../g711 rpedemo.c + +rpedemo: $(OBJECTS) + $(CC) -o rpedemo $(OBJECTS) + +# ------------------------------------------------ +# Run add < add_test.dta to make sure the +# basic arithmetic functions work as intended. +# ------------------------------------------------ +add: add_test.o + $(CC) $(LFLAGS) -o add add_test.o + +addtst: add add_test.dta + add < add_test.dta > /dev/null diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/makefile.tcc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/makefile.tcc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,112 @@ +#-------------------------------------------------------------------------- +# RPELTP makefile for MSDOS Borland [bt]cc +#-------------------------------------------------------------------------- +# Original Copyright message: +# Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +# Universitaet Berlin. See the accompanying file "COPYRIGHT" for +# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +# +# File adapted by simao@ctd.comsat.com for the UGST distribution. +#-------------------------------------------------------------------------- + +######### MUST Define USE_FLOAT_MUL for bit exact performance to GSM Spec. +CC = tcc -mm -DSASR;USE_FLOAT_MUL;NeedFunctionPrototypes +INC = -I../utl;..\g711;d:\tc\include +LIB = -Ld:\tc\lib + +#-------------------------------------------------------------------------- +# Tools +#-------------------------------------------------------------------------- +RM=rm -f + +#-------------------------------------------------------------------------- +# Targets +#-------------------------------------------------------------------------- +EXE_dependencies = \ + add.obj \ + code.obj \ + debug.obj \ + decode.obj \ + gsm_crea.obj \ + gsm_deco.obj \ + gsm_dest.obj \ + gsm_enco.obj \ + gsm_expl.obj \ + gsm_impl.obj \ + gsm_opti.obj \ + gsm_prin.obj \ + long_ter.obj \ + lpc.obj \ + preproce.obj \ + rpe.obj \ + rpeltp.obj \ + rpedemo.obj \ + short_te.obj \ + table.obj \ + g711.obj + +# ------------------------------------------------ +# Implicit rules +# ------------------------------------------------ +.c.obj: + $(CC) -c {$< } + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +anyway: clean rpedemo.exe + +clean: + $(RM) *.obj + +cleantest: + echo No test file processing available in this directory + +veryclean: clean + $(RM) rpedemo.exe + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +rpedemo: rpedemo.exe +rpedemo.exe: rpedemo.cfg $(EXE_dependencies) + $(CC) $(CC_OPT) -erpedemo @rpedemo.cfg + +add.obj: add.c +code.obj: code.c +debug.obj: debug.c +decode.obj: decode.c +gsm_crea.obj: gsm_crea.c +gsm_deco.obj: gsm_deco.c +gsm_dest.obj: gsm_dest.c +gsm_enco.obj: gsm_enco.c +gsm_expl.obj: gsm_expl.c +gsm_impl.obj: gsm_impl.c +gsm_opti.obj: gsm_opti.c +gsm_prin.obj: gsm_prin.c +long_ter.obj: long_ter.c +lpc.obj: lpc.c +preproce.obj: preproce.c +rpe.obj: rpe.c +rpeltp.obj: rpeltp.c +rpedemo.obj: rpedemo.c + $(CC) -c -I../g711 rpedemo.c +short_te.obj: short_te.c +table.obj: table.c +g711.obj: ../g711/g711.c + $(CC) -c -I../g711 ../g711/g711.c + +# ------------------------------------------------ +# Borland make-specific +# ------------------------------------------------ +rpedemo.cfg: makefile.tcc + copy &&| +-ff- +-f287 +-mm +-DSASR;USE_FLOAT_MUL;NeedFunctionPrototypes +-P-.C +$(INC) +$(LIB) +$(EXE_dependencies) +| rpedemo.cfg diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/makefile.unx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/makefile.unx Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,129 @@ +#-------------------------------------------------------------------------- +# RPELTP makefile for Unix C compilers +#-------------------------------------------------------------------------- +# Original Copyright message: +# Copyright 1992 by Jutta Degener and Carsten Bormann, Technische +# Universitaet Berlin. See the accompanying file "COPYRIGHT" for +# details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. +# +# File adapted by simao@ctd.comsat.com for the UGST distribution. +#-------------------------------------------------------------------------- + +# Machine dependent flags you must configure to port + +######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1) +SASR = -DSASR + +######### MUST Define USE_FLOAT_MUL for bit exact performance to GSM Spec. +MULHACK = -DUSE_FLOAT_MUL + +# Choose a compiler. The code works both with ANSI and K&R-C. +# Use -DNeedFunctionPrototypes to compile with, -UNeedFunctionPrototypes to +# compile without, function prototypes in the header files. +# +# You can use the -DSTUPID_COMPILER to circumvent some compilers' +# static limits regarding the number of subexpressions in a statement. + +CC = cc +CCFLAGS = -c -UNeedFunctionPrototypes -I../utl +#CCFLAGS = -g -c -UNeedFunctionPrototypes -I../utl +#CCFLAGS = -c -DSTUPID_COMPILER -I../utl + +#CC = acc +#CCFLAGS = -c -O -I../utl + +#CC = gcc +#CCFLAGS = -c -O2 -DNeedFunctionPrototypes=1 -fno-builtin -I../utl +#CCFLAGS = -c -g -Wall -DNeedFunctionPrototypes=1 -fno-builtin -I../utl + +#-------------------------------------------------------------------------- +# +# You shouldn't have to configure below this line if you're porting. +# +#-------------------------------------------------------------------------- + +# Tools +RM=rm -f + +# Local Directories +INC = . + +# Flags + +DEBUG = -DNDEBUG +######### Remove -DNDEBUG to enable assertions. + +CFLAGS = $(CCFLAGS) $(SASR) $(DEBUG) $(MULHACK) $(FAST) -I$(INC) -I../utl +######### It's $(CC) $(CFLAGS) + + +#-------------------------------------------------------------------------- +# Headers +HEADERS = proto.h unproto.h config.h private.h gsm.h rpeltp.h + +#-------------------------------------------------------------------------- +# Sources +GSM_SOURCES = add.c code.c debug.c decode.c long_ter.c lpc.c \ + preproce.c rpe.c gsm_dest.c gsm_deco.c gsm_enco.c \ + gsm_expl.c gsm_impl.c gsm_crea.c gsm_prin.c gsm_opti.c \ + rpeltp.c short_te.c table.c + +DEMO_SOURCES = rpedemo.c ../g711/g711.c + +SOURCES = $(GSM_SOURCES) $(DEMO_SOURCES) + + +#-------------------------------------------------------------------------- +# Object files +GSM_OBJECTS = add.o code.o debug.o decode.o long_ter.o lpc.o \ + preproce.o rpe.o gsm_dest.o gsm_deco.o gsm_enco.o \ + gsm_expl.o gsm_impl.o gsm_crea.o gsm_prin.o gsm_opti.o \ + rpeltp.o short_te.o table.o + +DEMO_OBJECTS = rpedemo.o g711.o + +OBJECTS = $(GSM_OBJECTS) $(DEMO_OBJECTS) + +# ------------------------------------------------ +# Implicit rules +# ------------------------------------------------ +.c.o: + $(CC) $(CFLAGS) $? + +# ------------------------------------------------ +# Generic rules +# ------------------------------------------------ +all:: rpedemo + +anyway: clean rpedemo + +clean: + $(RM) $(OBJECTS) + +cleantest: + echo No test file processing available in this directory + +veryclean: clean + $(RM) rpedemo + +# ------------------------------------------------ +# Specific rules +# ------------------------------------------------ +g711.o: ../g711/g711.c + $(CC) $(CFLAGS) -I../g711 ../g711/g711.c + +rpedemo.o: rpedemo.c ../g711/g711.h + $(CC) $(CFLAGS) -I../g711 rpedemo.c + +rpedemo: $(OBJECTS) + $(CC) -o rpedemo $(OBJECTS) + +# ------------------------------------------------ +# Run add < add_test.dta to make sure the +# basic arithmetic functions work as intended. +# ------------------------------------------------ +add: add_test.o + $(CC) $(LFLAGS) -o add add_test.o + +addtst: add add_test.dta + add < add_test.dta > /dev/null diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/preproce.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/preproce.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,111 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/preprocess.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +/* 4.2.0 .. 4.2.3 PREPROCESSING SECTION + * + * After A-law to linear conversion (or directly from the + * Ato D converter) the following scaling is assumed for + * input to the RPE-LTP algorithm: + * + * in: 0.1.....................12 + * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.* + * + * Where S is the sign bit, v a valid bit, and * a "don't care" bit. + * The original signal is called sop[..] + * + * out: 0.1................... 12 + * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0 + */ + + +void Gsm_Preprocess P3((S, s, so), + struct gsm_state *S, word * s, word * so) +{ /* [0..159] IN/OUT */ + + word z1 = S->z1; + longword L_z2 = S->L_z2; + word mp = S->mp; + + word s1; + longword L_s2; + + longword L_temp; + + word msp, lsp; + word SO; + + longword ltmp; /* for ADD */ + ulongword utmp; /* for L_ADD */ + + register int k = 160; + + while (k--) { + + /* 4.2.1 Downscaling of the input signal + */ + SO = SASR(*s, 3) << 2; + s++; + + assert(SO >= -0x4000); /* downscaled by */ + assert(SO <= 0x3FFC); /* previous routine. */ + + + /* 4.2.2 Offset compensation + * + * This part implements a high-pass filter and requires extended + * arithmetic precision for the recursive part of this filter. + * The input of this procedure is the array so[0...159] and the + * output the array sof[ 0...159 ]. + */ + /* Compute the non-recursive part + */ + + s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */ + z1 = SO; + + assert(s1 != MIN_WORD); + + /* Compute the recursive part + */ + L_s2 = s1; + L_s2 <<= 15; + + /* Execution of a 31 bv 16 bits multiplication + */ + + msp = SASR(L_z2, 15); + lsp = L_z2 - ((longword) msp << 15); /* gsm_L_sub(L_z2,(msp<<15)); */ + + L_s2 += GSM_MULT_R(lsp, 32735); + L_temp = (longword) msp *32735; /* GSM_L_MULT(msp,32735) >> 1; */ + L_z2 = GSM_L_ADD(L_temp, L_s2); + + /* Compute sof[k] with rounding + */ + L_temp = GSM_L_ADD(L_z2, 16384); + + /* 4.2.3 Preemphasis + */ + + msp = GSM_MULT_R(mp, -28180); + mp = SASR(L_temp, 15); + *so++ = GSM_ADD(mp, msp); + } + + S->z1 = z1; + S->L_z2 = L_z2; + S->mp = mp; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/private.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/private.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,243 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/private.h,v 1.2 1993/01/29 18:25:27 jutta Exp $*/ + +/* + ************************** WARNING ****************************** + Several pseudo-functions GSM_... provide faster operation than + their equivalent true function, but may generate non-compatible + results. It is known that the implementation of GSM_ADD_2 is + not working correctly on 16-bit machines/compilers (besides + an error-free compilation!). In the safer case, compilation + should be carried out using SLOWER_BUT_SAFER defined. + Another test is using add_test.c, explained elsewhere. + -- [08.Apr.94] --- + ***************************************************************** +*/ + +#ifndef PRIVATE_H +#define PRIVATE_H + +typedef short word; /* 16 bit signed int */ +typedef long longword; /* 32 bit signed int */ + +typedef unsigned short uword; /* unsigned word */ +typedef unsigned long ulongword; /* unsigned longword */ + +struct gsm_state { + + word dp0[280]; + + word z1; /* preprocessing.c, Offset_com. */ + longword L_z2; /* Offset_com. */ + int mp; /* Preemphasis */ + + word u[8]; /* short_term_aly_filter.c */ + word LARpp[2][8]; /* */ + word j; /* */ + + word nrp; /* 40 *//* long_term.c, synthesis */ + word v[9]; /* short_term.c, synthesis */ + word msr; /* decoder.c, Postprocessing */ + + char verbose; /* only used if !NDEBUG */ + char fast; /* only used if FAST */ + +}; + + +#define MIN_WORD (-32768) +#define MAX_WORD ( 32767) + +#define MIN_LONGWORD ((-2147483647)-1) +#define MAX_LONGWORD ( 2147483647) + +#ifdef SASR /* >> is a signed arithmetic shift right */ +#undef SASR +#define SASR(x, by) ((x) >> (by)) +#endif /* SASR */ + + +#include "proto.h" + +/* + * Prototypes from add.c + */ +extern word gsm_mult P((word a, word b)); +extern longword gsm_L_mult P((word a, word b)); +extern word gsm_mult_r P((word a, word b)); + +extern word gsm_div P((word num, word denum)); + +extern word gsm_add P((word a, word b)); +extern longword gsm_L_add P((longword a, longword b)); + +extern word gsm_sub P((word a, word b)); +extern longword gsm_L_sub P((longword a, longword b)); + +extern word gsm_abs P((word a)); + +extern word gsm_norm P((longword a)); + +extern longword gsm_L_asl P((longword a, int n)); +extern word gsm_asl P((word a, int n)); + +extern longword gsm_L_asr P((longword a, int n)); +extern word gsm_asr P((word a, int n)); + +/* + * Inlined functions from add.h + */ +#ifndef SLOWER_BUT_SAFER +/* + * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \ + * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15)) + */ +#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \ + (SASR( ((longword)(a) * (longword)(b) + 16384), 15 )) + +# define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \ + (SASR( ((longword)(a) * (longword)(b)), 15 )) + +# define GSM_L_MULT(a, b) /* word a, word b */ \ + (((longword)(a) * (longword)(b)) << 1) + +# define GSM_L_ADD(a, b) \ + ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \ + : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \ + >= (ulongword)MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \ + : ((b) <= 0 ? (a) + (b) \ + : (utmp = (ulongword)(a) + (ulongword)(b)) >= (ulongword)MAX_LONGWORD \ + ? (ulongword)MAX_LONGWORD : utmp)) + + +/* Slower but portable */ +#define GSM_ADD_1(a, b) \ + ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \ + ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) + +/* Nonportable, but faster: */ +#define GSM_ADD_2(a, b) \ + ((unsigned)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \ + MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp) + +/* Now you choose: fast or portable? */ +/* #define GSM_ADD GSM_ADD_1 -> Slow & portable */ +/* #define GSM_ADD GSM_ADD_2 -> Fast & non-portable */ +#define GSM_ADD GSM_ADD_1 + +# define GSM_SUB(a, b) \ + ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \ + ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) + +# define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a)) + +#else + +/* Use these if necessary: */ + +# define GSM_MULT_R(a, b) gsm_mult_r(a, b) +# define GSM_MULT(a, b) gsm_mult(a, b) +# define GSM_L_MULT(a, b) gsm_L_mult(a, b) + +# define GSM_L_ADD(a, b) gsm_L_add(a, b) +# define GSM_ADD(a, b) gsm_add(a, b) +# define GSM_SUB(a, b) gsm_sub(a, b) + +# define GSM_ABS(a) gsm_abs(a) + +#endif /* SLOWER_BUT_SAFER */ + +/* + * More prototypes from implementations.. + */ +extern void Gsm_Coder P((struct gsm_state * S, word * s, /* [0..159] samples IN */ + word * LARc, /* [0..7] LAR coefficients OUT */ + word * Nc, /* [0..3] LTP lag OUT */ + word * bc, /* [0..3] coded LTP gain OUT */ + word * Mc, /* [0..3] RPE grid selection OUT */ + word * xmaxc, /* [0..3] Coded maximum amplitude OUT */ + word * xMc /* [13*4] normalized RPE samples OUT */ )); + +extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */ + struct gsm_state * S, word * d, /* [0..39] residual signal IN */ + word * dp, /* [-120..-1] d' IN */ + word * e, /* [0..40] OUT */ + word * dpp, /* [0..40] OUT */ + word * Nc, /* correlation lag OUT */ + word * bc /* gain factor OUT */ )); + +extern void Gsm_LPC_Analysis P((struct gsm_state * S, word * s, /* 0..159 signals IN/OUT */ + word * LARc)); /* 0..7 LARc's OUT */ + +extern void Gsm_Preprocess P((struct gsm_state * S, + word * s, word * so)); + +extern void Gsm_Encoding P((struct gsm_state * S, + word * e, word * ep, word * xmaxc, word * Mc, word * xMc)); + +extern void Gsm_Short_Term_Analysis_Filter P((struct gsm_state * S, word * LARc, /* coded log area ratio [0..7] IN */ + word * d /* st res. signal [0..159] IN/OUT */ )); + +extern void Gsm_Decoder P((struct gsm_state * S, word * LARcr, /* [0..7] IN */ + word * Ncr, /* [0..3] IN */ + word * bcr, /* [0..3] IN */ + word * Mcr, /* [0..3] IN */ + word * xmaxcr, /* [0..3] IN */ + word * xMcr, /* [0..13*4] IN */ + word * s)); /* [0..159] OUT */ + +extern void Gsm_Decoding P((struct gsm_state * S, word xmaxcr, word Mcr, word * xMcr, /* [0..12] IN */ + word * erp)); /* [0..39] OUT */ + +extern void Gsm_Long_Term_Synthesis_Filtering P((struct gsm_state * S, word Ncr, word bcr, word * erp, /* [0..39] IN */ + word * drp)); /* [-120..-1] IN, [0..40] OUT */ + +extern void Gsm_Short_Term_Synthesis_Filter P((struct gsm_state * S, word * LARcr, /* log area ratios [0..7] IN */ + word * drp, /* received d [0...39] IN */ + word * s)); /* signal s [0..159] OUT */ + +extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((word * dpp, /* [0...39] IN */ + word * ep, /* [0...39] IN */ + word * dp)); /* [-120...-1] IN/OUT */ + +/* + * Tables from table.c + */ +#ifndef GSM_TABLE_C + +extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8]; +extern word gsm_INVA[8]; +extern word gsm_DLB[4], gsm_QLB[4]; +extern word gsm_H[11]; +extern word gsm_NRFAC[8]; +extern word gsm_FAC[8]; + +#endif /* GSM_TABLE_C */ + +/* + * Debugging + */ +#ifdef NDEBUG + +# define gsm_debug_words(a, b, c, d) /* nil */ +# define gsm_debug_longwords(a, b, c, d) /* nil */ +# define gsm_debug_word(a, b) /* nil */ +# define gsm_debug_longword(a, b) /* nil */ + +#else /* !NDEBUG => DEBUG */ + +extern void gsm_debug_words P((char *name, int, int, word *)); +extern void gsm_debug_longwords P((char *name, int, int, longword *)); +extern void gsm_debug_longword P((char *name, longword)); +extern void gsm_debug_word P((char *name, word)); + +#endif /* !NDEBUG */ + +#include "unproto.h" + +#endif /* PRIVATE_H */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/proto.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/proto.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,76 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/proto.h,v 1.1 1992/10/28 00:11:08 jutta Exp $*/ + +#ifndef PROTO_H +#define PROTO_H + +#ifndef NeedFunctionPrototypes +#if defined(__cplusplus) || defined(__STDC__) || defined(VMS) +# define NeedFunctionPrototypes 1 +#endif +#endif + +/* This used to be as follows, but was replaced to avoid silly complaints and +* errors of some compilers. Also automated symbol definition for VMS +* #if __cplusplus +* # define NeedFunctionPrototypes 1 +* #endif +* +* #if __STDC__ +* # define NeedFunctionPrototypes 1 +* #endif +*/ + +#ifdef _NO_PROTO +# undef NeedFunctionPrototypes +#endif + +#ifdef P +#undef P /* gnu stdio.h actually defines this... */ +#undef P0 +#undef P1 +#undef P2 +#undef P3 +#undef P4 +#undef P5 +#undef P6 +#undef P7 +#undef P8 +#endif /* gnuc prototypes */ + +#ifdef NeedFunctionPrototypes + +# define P( protos ) protos + +# define P0() (void) +# define P1(x, a) (a) +# define P2(x, a, b) (a, b) +# define P3(x, a, b, c) (a, b, c) +# define P4(x, a, b, c, d) (a, b, c, d) +# define P5(x, a, b, c, d, e) (a, b, c, d, e) +# define P6(x, a, b, c, d, e, f) (a, b, c, d, e, f) +# define P7(x, a, b, c, d, e, f, g) (a, b, c, d, e, f, g) +# define P8(x, a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h) + +#else /* !NeedFunctionPrototypes */ + +# define P( protos ) ( /* protos */ ) + +# define P0() () +# define P1(x, a) x a; +# define P2(x, a, b) x a; b; +# define P3(x, a, b, c) x a; b; c; +# define P4(x, a, b, c, d) x a; b; c; d; +# define P5(x, a, b, c, d, e) x a; b; c; d; e; +# define P6(x, a, b, c, d, e, f) x a; b; c; d; e; f; +# define P7(x, a, b, c, d, e, f, g) x a; b; c; d; e; f; g; +# define P8(x, a, b, c, d, e, f, g, h) x a; b; c; d; e; f; g; h; + +#endif /* !NeedFunctionPrototypes */ + +#endif /* PROTO_H */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpe.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/rpe.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,508 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/rpe.c,v 1.2 1994/01/25 22:21:15 jutta Exp $ */ + +#include +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +/* 4.2.13 .. 4.2.17 RPE ENCODING SECTION + */ + +/* 4.2.13 */ + +static void Weighting_filter P2((e, x), register word * e, /* signal [-5..0.39.44] IN */ + word * x /* signal [0..39] OUT */ + ) +/* + * The coefficients of the weighting filter are stored in a table + * (see table 4.4). The following scaling is used: + * + * H[0..10] = integer( real_H[ 0..10] * 8192 ); + */ +{ + /* word wt[ 50 ]; */ + + register longword L_result; + register int k /* , i */ ; + + /* Initialization of a temporary working array wt[0...49] + */ + + /* for (k = 0; k <= 4; k++) wt[k] = 0; + * for (k = 5; k <= 44; k++) wt[k] = *e++; + * for (k = 45; k <= 49; k++) wt[k] = 0; + * + * (e[-5..-1] and e[40..44] are allocated by the caller, + * are initially zero and are not written anywhere.) + */ + e -= 5; + + /* Compute the signal x[0..39] + */ + for (k = 0; k <= 39; k++) { + + L_result = 8192 >> 1; + + /* for (i = 0; i <= 10; i++) { + * L_temp = GSM_L_MULT( wt[k+i], gsm_H[i] ); + * L_result = GSM_L_ADD( L_result, L_temp ); + * } + */ + +#ifdef STEP +#undef STEP +#endif +#define STEP( i, H ) (e[ k + i ] * (longword)H) + + /* Every one of these multiplications is done twice -- + * but I don't see an elegant way to optimize this. + * Do you? + */ + +#ifdef STUPID_COMPILER + L_result += STEP(0, -134); + L_result += STEP(1, -374); + /* + STEP( 2, 0 ) */ + L_result += STEP(3, 2054); + L_result += STEP(4, 5741); + L_result += STEP(5, 8192); + L_result += STEP(6, 5741); + L_result += STEP(7, 2054); + /* + STEP( 8, 0 ) */ + L_result += STEP(9, -374); + L_result += STEP(10, -134); +#else + L_result += STEP(0, -134) + + STEP(1, -374) + /* + STEP( 2, 0 ) */ + + STEP(3, 2054) + + STEP(4, 5741) + + STEP(5, 8192) + + STEP(6, 5741) + + STEP(7, 2054) + /* + STEP( 8, 0 ) */ + + STEP(9, -374) + + STEP(10, -134); +#endif + + /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *) + * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *) + * + * x[k] = SASR( L_result, 16 ); + */ + + /* 2 adds vs. >>16 => 14, minus one shift to compensate for + * those we lost when replacing L_MULT by '*'. + */ + + L_result = SASR(L_result, 13); + x[k] = (L_result < MIN_WORD ? MIN_WORD + : (L_result > MAX_WORD ? MAX_WORD : L_result)); + } +} + +/* 4.2.14 */ + +static void RPE_grid_selection P3((x, xM, Mc_out), word * x, /* [0..39] IN */ + word * xM, /* [0..12] OUT */ + word * Mc_out /* OUT */ + ) +/* + * The signal x[0..39] is used to select the RPE grid which is + * represented by Mc. + */ +{ + /* register word temp1; */ + register int /* m, */ i; + /* register ulongword utmp; */ + register longword L_result, L_temp; + longword EM; /* xxx should be L_EM? */ + word Mc; + + longword L_common_0_3; + + EM = 0; + Mc = 0; + + /* for (m = 0; m <= 3; m++) { + * L_result = 0; + * + * + * for (i = 0; i <= 12; i++) { + * + * temp1 = SASR( x[m + 3*i], 2 ); + * + * assert(temp1 != MIN_WORD); + * + * L_temp = GSM_L_MULT( temp1, temp1 ); + * L_result = GSM_L_ADD( L_temp, L_result ); + * } + * + * if (L_result > EM) { + * Mc = m; + * EM = L_result; + * } + * } + */ + +#undef STEP +#define STEP( m, i ) L_temp = SASR( (longword)x[m + 3 * i], 2 ); \ + L_result += L_temp * L_temp; + + /* common part of 0 and 3 */ + + L_result = 0; + STEP(0, 1); + STEP(0, 2); + STEP(0, 3); + STEP(0, 4); + STEP(0, 5); + STEP(0, 6); + STEP(0, 7); + STEP(0, 8); + STEP(0, 9); + STEP(0, 10); + STEP(0, 11); + STEP(0, 12); + L_common_0_3 = L_result; + + /* i = 0 */ + + STEP(0, 0); + L_result <<= 1; /* implicit in L_MULT */ + EM = L_result; + + /* i = 1 */ + + L_result = 0; + STEP(1, 0); + STEP(1, 1); + STEP(1, 2); + STEP(1, 3); + STEP(1, 4); + STEP(1, 5); + STEP(1, 6); + STEP(1, 7); + STEP(1, 8); + STEP(1, 9); + STEP(1, 10); + STEP(1, 11); + STEP(1, 12); + L_result <<= 1; + if (L_result > EM) { + Mc = 1; + EM = L_result; + } + + /* i = 2 */ + + L_result = 0; + STEP(2, 0); + STEP(2, 1); + STEP(2, 2); + STEP(2, 3); + STEP(2, 4); + STEP(2, 5); + STEP(2, 6); + STEP(2, 7); + STEP(2, 8); + STEP(2, 9); + STEP(2, 10); + STEP(2, 11); + STEP(2, 12); + L_result <<= 1; + if (L_result > EM) { + Mc = 2; + EM = L_result; + } + + /* i = 3 */ + + L_result = L_common_0_3; + STEP(3, 12); + L_result <<= 1; + if (L_result > EM) { + Mc = 3; + EM = L_result; + } + + /**/ + /* Down-sampling by a factor 3 to get the selected xM[0..12] + * RPE sequence. + */ + for (i = 0; i <= 12; i++) + xM[i] = x[Mc + 3 * i]; + *Mc_out = Mc; +} + +/* 4.12.15 */ + +static void APCM_quantization_xmaxc_to_exp_mant P3((xmaxc, exp_out, mant_out), word xmaxc, /* IN */ + word * exp_out, /* OUT */ + word * mant_out) +{ /* OUT */ + word exp, mant; + + /* Compute exponent and mantissa of the decoded version of xmaxc + */ + + exp = 0; + if (xmaxc > 15) + exp = SASR(xmaxc, 3) - 1; + mant = xmaxc - (exp << 3); + + if (mant == 0) { + exp = -4; + mant = 7; + } else { + while (mant <= 7) { + mant = mant << 1 | 1; + exp--; + } + mant -= 8; + } + + assert(exp >= -4 && exp <= 6); + assert(mant >= 0 && mant <= 7); + + *exp_out = exp; + *mant_out = mant; +} + +static void APCM_quantization P5((xM, xMc, mant_out, exp_out, xmaxc_out), word * xM, /* [0..12] IN */ + word * xMc, /* [0..12] OUT */ + word * mant_out, /* OUT */ + word * exp_out, /* OUT */ + word * xmaxc_out /* OUT */ + ) +{ + int i, itest; + + /* register longword ltmp; / * for GSM_ADD */ + word xmax, xmaxc, temp, temp1, temp2; + word exp, mant; + + + /* Find the maximum absolute value xmax of xM[0..12]. + */ + + xmax = 0; + for (i = 0; i <= 12; i++) { + temp = xM[i]; + temp = GSM_ABS(temp); + if (temp > xmax) + xmax = temp; + } + + /* Qantizing and coding of xmax to get xmaxc. + */ + + exp = 0; + temp = SASR(xmax, 9); + itest = 0; + + for (i = 0; i <= 5; i++) { + + itest |= (temp <= 0); + temp = SASR(temp, 1); + + assert(exp <= 5); + if (itest == 0) + exp++; /* exp = add (exp, 1) */ + } + + assert(exp <= 6 && exp >= 0); + temp = exp + 5; + + assert(temp <= 11 && temp >= 0); + xmaxc = gsm_add(SASR(xmax, temp), exp << 3); + + /* Quantizing and coding of the xM[0..12] RPE sequence + * to get the xMc[0..12] + */ + + APCM_quantization_xmaxc_to_exp_mant(xmaxc, &exp, &mant); + + /* This computation uses the fact that the decoded version of xmaxc + * can be calculated by using the exponent and the mantissa part of + * xmaxc (logarithmic table). + * So, this method avoids any division and uses only a scaling + * of the RPE samples by a function of the exponent. A direct + * multiplication by the inverse of the mantissa (NRFAC[0..7] + * found in table 4.5) gives the 3 bit coded version xMc[0..12] + * of the RPE samples. + */ + + + /* Direct computation of xMc[0..12] using table 4.5 + */ + + assert(exp <= 4096 && exp >= -4096); + assert(mant >= 0 && mant <= 7); + + temp1 = 6 - exp; /* normalization by the exponent */ + temp2 = gsm_NRFAC[mant]; /* inverse mantissa */ + + for (i = 0; i <= 12; i++) { + + assert(temp1 >= 0 && temp1 < 16); + + temp = xM[i] << temp1; + temp = GSM_MULT(temp, temp2); + temp = SASR(temp, 12); + xMc[i] = temp + 4; /* see note below */ + } + + /* NOTE: This equation is used to make all the xMc[i] positive. + */ + + *mant_out = mant; + *exp_out = exp; + *xmaxc_out = xmaxc; +} + +/* 4.2.16 */ + +static void APCM_inverse_quantization P4((xMc, mant, exp, xMp), register word * xMc, /* [0..12] IN */ + word mant, word exp, register word * xMp) +{ /* [0..12] OUT */ + /* + * This part is for decoding the RPE sequence of coded xMc[0..12] + * samples to obtain the xMp[0..12] array. Table 4.6 is used to get + * the mantissa of xmaxc (FAC[0..7]). + */ + int i; + word temp, temp1, temp2, temp3; + /* ulongword utmp; */ + longword ltmp; + + assert(mant >= 0 && mant <= 7); + + temp1 = gsm_FAC[mant]; /* see 4.2-15 for mant */ + temp2 = gsm_sub(6, exp); /* see 4.2-15 for exp */ + temp3 = gsm_asl(1, gsm_sub(temp2, 1)); + + for (i = 13; i--;) { + + assert(*xMc <= 7 && *xMc >= 0); /* 3 bit unsigned */ + + /* temp = gsm_sub( *xMc++ << 1, 7 ); */ + temp = (*xMc++ << 1) - 7; /* restore sign */ + assert(temp <= 7 && temp >= -7); /* 4 bit signed */ + + temp <<= 12; /* 16 bit signed */ + temp = GSM_MULT_R(temp1, temp); + temp = GSM_ADD(temp, temp3); + *xMp++ = gsm_asr(temp, temp2); + } +} + +/* 4.2.17 */ + +static void RPE_grid_positioning P3((Mc, xMp, ep), word Mc, /* grid position IN */ + register word * xMp, /* [0..12] IN */ + register word * ep /* [0..39] OUT */ + ) +/* + * This procedure computes the reconstructed long term residual signal + * ep[0..39] for the LTP analysis filter. The inputs are the Mc + * which is the grid position selection and the xMp[0..12] decoded + * RPE samples which are upsampled by a factor of 3 by inserting zero + * values. + */ +{ +#if defined(VMS) || defined(__TURBOC__) + int k; +#endif + int i = 13; + + assert(0 <= Mc && Mc <= 3); + +#if defined(VMS) || defined(__TURBOC__) + for (k = 0; k <= 39; k++) + ep[k] = 0; + for (i = 0; i <= 12; i++) { + ep[Mc + (3 * i)] = xMp[i]; + } +#else + switch (Mc) { + case 3: + *ep++ = 0; + case 2: + do { + *ep++ = 0; + case 1: + *ep++ = 0; + case 0: + *ep++ = *xMp++; + } while (--i); + } + while (++Mc < 4) + *ep++ = 0; +#endif +} + +/* 4.2.18 */ + +/* This procedure adds the reconstructed long term residual signal + * ep[0..39] to the estimated signal dpp[0..39] from the long term + * analysis filter to compute the reconstructed short term residual + * signal dp[-40..-1]; also the reconstructed short term residual + * array dp[-120..-41] is updated. + */ + +#if 0 /* Has been inlined in code.c */ +void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp), word * dpp, /* [0...39] IN */ + word * ep, /* [0...39] IN */ + word * dp) +{ /* [-120...-1] IN/OUT */ + int k; + + for (k = 0; k <= 79; k++) + dp[-120 + k] = dp[-80 + k]; + + for (k = 0; k <= 39; k++) + dp[-40 + k] = gsm_add(ep[k], dpp[k]); +} +#endif /* Has been inlined in code.c */ + +void Gsm_RPE_Encoding P5((S, e, xmaxc, Mc, xMc), struct gsm_state *S, word * e, /* -5..-1][0..39][40..44 IN/OUT */ + word * xmaxc, /* OUT */ + word * Mc, /* OUT */ + word * xMc) +{ /* [0..12] OUT */ + word x[40]; + word xM[13], xMp[13]; + word mant, exp; + + Weighting_filter(e, x); + RPE_grid_selection(x, xM, Mc); + + APCM_quantization(xM, xMc, &mant, &exp, xmaxc); + APCM_inverse_quantization(xMc, mant, exp, xMp); + + RPE_grid_positioning(*Mc, xMp, e); + +} + +void Gsm_RPE_Decoding P5((S, xmaxcr, Mcr, xMcr, erp), struct gsm_state *S, word xmaxcr, word Mcr, word * xMcr, /* [0..12], 3 bits IN */ + word * erp /* [0..39] OUT */ + ) +{ + word exp, mant; + word xMp[13]; + + APCM_quantization_xmaxc_to_exp_mant(xmaxcr, &exp, &mant); + APCM_inverse_quantization(xMcr, mant, exp, xMp); + RPE_grid_positioning(Mcr, xMp, erp); + +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpedemo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/rpedemo.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,457 @@ +/* v1.1 - 22/Feb/1996 + ============================================================================ + + RPEDEMO.C + ~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + + Demonstration program for UGST/ITU-T RPE-LTP module. Takes the + input file and processes by the GSM 06.10 Full Rate speech codec, + depending on user's option: for encoding, input must be in + either linear, A, mu law (G711); for decoding, in GSM 06.10 76-word + format. The modules called have been written in Unix-C by Jutta + Deneger and Carsten Borman, within the Communications and + Operating Systems Research Group (KBS) of the Technishe Universitaet + Berlin. This demo program has been written by Simao F.Campos Neto, + from CPqD/Telebras based on previous UGST demo programs, as well on + a driving program by the RPE-LTP program. + + Input data is supposed to be aligned at word boundaries, i.e., + organized in 16-bit words, following the operating system normal + organization (low-byte first for VMS and DOS; high byte first for + most Unix systems). G711 compressed data is supposed to be in the 8 + LEAST significant bits of the word and the RPE-LTP data will use a + varied number of least significant bits. Both are without sign + extension. Linear format, on its hand, expect data to be 16-bit + aligned to the left, and the algorith will take only the 13 most + significant bits. This complies to the general UGST integer data + format. + + Output data will be generated in the same format as decribed + above for the input data. + + Usage: + ~~~~~~ + $ rpedemo [-l|-u|-A] [-enc|-dec] InpFile OutFile BlockSize 1stBlock + NoOfBlocks + where: + -l .......... input data for encoding and output data for decoding + are in linear format (DEFAULT). + -A .......... input data for encoding and output data for decoding + are in A-law (G.711) format. + -u .......... input data for encoding and output data for decoding + are in u-law (G.711) format. + -enc ........ run the only the decoder (default: run enc+dec) + -dec ........ run the only the encoder (default: run enc+dec) + + InpFile ..... is the name of the file to be processed; + OutFile ..... is the name with the processed data; + BlockSize ... is the block size, in number of samples (default = 160) + 1stBlock .... is the number of the first block of the input file + to be processed; + NoOfBlocks .. is the number of blocks to be processed, starting on + block "1stBlock" + + Exit values: + ~~~~~~~~~~~~ + 0 success (all but VMS); + 1 success (only in VMS); + 2 error opening input file; + 3 error creating output file; + 4 error moving pointer to desired start of conversion; + 5 error creating gsm object (i.e., state variable); + 6 error reading input file; + 7 error writing to file; + + Original authors: + ~~~~~~~~~~~~~~~~~ + Demo program: + Simao Ferraz de Campos Neto EMail : simao@cpqd.ansp.br + CPqD/Telebras Rd. Mogi Mirim-Campinas Km.118 + DDS/Pr.11 13.088-061 - Campinas - SP (Brazil) + + Module routines: + Jutta Degener (jutta@cs.tu-berlin.de) + Carsten Bormann (cabo@cs.tu-berlin.de) + + History: + ~~~~~~~~ + 28/Oct/92 r.1.0 pl.0 by Carsten Bormann (cabo at kubus) + Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + Universitaet Berlin. See the accompanying file "COPYRIGHT" for + details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + + 30/Oct/92 r.1.0 pl.1 by Jutta Degener (jutta at kraftbus) + Switched uid/gid in toast's [f]chown calls. + + 29/Jan/93 r.1.0 pl.2 by Jutta Degener (jutta at kraftbus) + fixed L_add(0,-1) in src/add.c and inc/private.h, + thanks to Raphael Trommer at AT&T Bell Laboratories; + * ANSI C compatibility details + + 20/Mar/94 v1.0 Release of 1st version of demo program + + 22/Feb/95 v1.1 Cleaned compilation warnings, modified for Alpha VMX/AXP + operation (as suggested by Kirchherr, FI/DBP Telekom) + + ============================================================================ +*/ + + +/* ..... General definitions for UGST demo programs ..... */ +#include "ugstdemo.h" + +/* ..... General include ..... */ +#include +#include +#include + +#if defined(VMS) +#include +#else /* Unix/DOS */ +#include +#endif + +/* ..... RPE-LTP module definitions ..... */ +#include "private.h" +#include "gsm.h" +#include "rpeltp.h" + +/* ..... G.711 module definitions ..... */ +#include "g711.h" + +/* ..... Local definitions ..... */ +#define LINEAR 0 /* binary: 00 */ +#define U_LAW 1 /* binary: 01 */ +#define A_LAW 3 /* binary: 11 */ + +/* ..... Local function prototypes ..... */ +void display_usage ARGS((void)); +int main ARGS((int argc, char *argv[])); + + +/* + ------------------------------------------------------------------------- + void display_usage(void); + ~~~~~~~~~~~~~~~~~~ + Display proper usage for the demo program. Generated automatically from + program documentation. + + History: + ~~~~~~~~ + 20.Mar.94 v1.0 Created. + ------------------------------------------------------------------------- +*/ +#define P(x) printf x +void display_usage() +{ + P(("RPEDEMO: Version 1.0 of 17/Mar/1994 \n\n")); + + P((" Demonstration program for UGST/ITU-T RPE-LTP based on \n")); + P((" module implemented in Unix-C by Jutta Deneger and Carsten \n")); + P((" Borman, within the Communications and Operating Systems \n")); + P((" Research Group (KBS) of the Technishe Universitaet Berlin.\n")); + P((" This demo program has been written by Simao F.Campos Neto\n")); + P(("\n")); + P((" Usage:\n")); + P((" $ rpedemo [-l|-u|-A] [-enc|-dec] InpFile OutFile BlockSize 1stBlock\n")); + P((" NoOfBlocks \n")); + P((" where:\n")); + P((" -l .......... input data for encoding and output data for decoding\n")); + P((" are in linear format (DEFAULT).\n")); + P((" -A .......... input data for encoding and output data for decoding\n")); + P((" are in A-law (G.711) format.\n")); + P((" -u .......... input data for encoding and output data for decoding\n")); + P((" are in u-law (G.711) format.\n")); + P((" -enc ........ run the only the decoder (default: run enc+dec)\n")); + P((" -dec ........ run the only the encoder (default: run enc+dec)\n")); + P(("\n")); + P((" InpFile ..... is the name of the file to be processed;\n")); + P((" OutFile ..... is the name with the processed data;\n")); + P((" BlockSize ... is the block size, in number of samples (default = 160)\n")); + P((" 1stBlock .... is the number of the first block of the input file\n")); + P((" to be processed;\n")); + P((" NoOfBlocks .. is the number of blocks to be processed, starting on\n")); + P((" block \"1stBlock\"\n")); + + /* Quit program */ + exit(-128); +} + +#undef P + +/* + ************************************************************************** + *** *** + *** Demo-Program for testing the correct implementation *** + *** and to show how to use the programs *** + *** *** + ************************************************************************** +*/ +main(argc, argv) +int argc; +char *argv[]; +{ + gsm rpe_enc_state, rpe_dec_state; + gsm_signal rpe_frame[RPE_FRAME_SIZE]; + Byte gsm_frame[33]; + long N = 256, N1 = 1, N2 = 0, cur_blk, smpno, count = 0; +#ifdef STATIC_ALLOCATION + short tmp_buf[256], inp_buf[256], out_buf[256]; +#else + short *tmp_buf, *inp_buf, *out_buf; +#endif + + /* G.711 Compression/expansion function pointers */ + void (*compress) (), (*expand) (); + + /* File variables */ + char FileIn[80], FileOut[80]; + FILE *Fi, *Fo; + long start_byte; + char format, run_encoder, run_decoder; +#ifdef VMS + char mrs[15]; +#endif + + + /* SETTING DEFAULT OPTIONS */ + format = LINEAR; + run_encoder = run_decoder = 1; + + /* GETTING OPTIONS */ + + if (argc < 2) + display_usage(); + else { + while (argc > 1 && argv[1][0] == '-') + if (strcmp(argv[1], "-") == 0) { + /* Oops, stop processing options! */ + break; + } else if (strcmp(argv[1], "-l") == 0) { + /* Input/output (uncoded) data format is linear */ + format = LINEAR; + + /* Move arg[cv] over the next valid option */ + argv++; + argc--; + } else if (strcmp(argv[1], "-A") == 0 + || strcmp(argv[1], "-a") == 0) { + /* Input/output (uncoded) data format is A-law (G.711) */ + format = A_LAW; + + /* Move arg[cv] over the next valid option */ + argv++; + argc--; + } else if (strcmp(argv[1], "-u") == 0) { + /* Input/output (uncoded) data format is u-law (G.711) */ + format = U_LAW; + + /* Move arg[cv] over the next valid option */ + argv++; + argc--; + } else if (strcmp(argv[1], "-enc") == 0) { + /* Run only the encoder */ + run_encoder = 1; + run_decoder = 0; + + /* Move arg[cv] over the next valid option */ + argv++; + argc--; + } else if (strcmp(argv[1], "-dec") == 0) { + /* Run only the encoder */ + run_encoder = 0; + run_decoder = 1; + + /* Move arg[cv] over the next valid option */ + argv++; + argc--; + } else { + fprintf(stderr, + "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); + display_usage(); + } + } + + GET_PAR_S(1, "_Input File: .................. ", FileIn); + GET_PAR_S(2, "_Output File: ................. ", FileOut); + FIND_PAR_L(3, "_Block Size: .................. ", N, RPE_WIND_SIZE); + FIND_PAR_L(4, "_Starting Block: .............. ", N1, 1); + FIND_PAR_L(5, "_No. of Blocks: ............... ", N2, 0); + + + /* Find staring byte in file; all are 16-bit word-aligned =>short data type */ + start_byte = sizeof(short) * (long) (--N1) * (long) N; + + /* Check if is to process the whole file */ + if (N2 == 0) { + struct stat st; + + /* ... find the input file size ... */ + stat(FileIn, &st); + /* convert to block count, depending on whether the input file + * is a uncoded or coded file */ + if (run_encoder) + N2 = (st.st_size - start_byte) / (N * sizeof(short)); + else + N2 = (st.st_size - start_byte) / (33 * sizeof(Byte)); + } + + /* Choose A/u law */ + if (format == A_LAW) { + expand = alaw_expand; + compress = alaw_compress; + } else if (format == U_LAW) { + expand = ulaw_expand; + compress = ulaw_compress; + } + + +/* + * ...... MEMORY ALLOCATION ......... + */ +#ifndef STATIC_ALLOCATION + if ((inp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((out_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); + if ((tmp_buf = (short *) calloc(N, sizeof(short))) == NULL) + HARAKIRI("Error in memory allocation!\n", 1); +#endif + + +/* + * ......... FILE PREPARATION ......... + */ + + /* Define stuff for VMS binary, fixed-record files */ +#ifdef VMS + sprintf(mrs, "mrs=%d", 512); +#endif + + /* Opening input/output files; abort if there's any problem */ + if ((Fi = fopen(FileIn, RB)) == NULL) + KILL(FileIn, 2); + + if ((Fo = fopen(FileOut, WB)) == NULL) + KILL(FileOut, 3); + + /* Move pointer to 1st block of interest */ + if (fseek(Fi, start_byte, 0) < 0l) + KILL(FileIn, 4); + + /* ......... CREATE AND INIT GSM OBJECT (STATE VARIABLE) ......... */ + if (!(rpe_enc_state = rpeltp_init())) + HARAKIRI("Error creating state variable for encoder\n", 5); + if (!(rpe_dec_state = rpeltp_init())) + HARAKIRI("Error creating state variable for encoder\n", 5); + + + /* ......... PROCESSING ACCORDING TO GSM 06.10 RPE-LTP CODEC ......... */ + + for (cur_blk = 0; cur_blk < N2; cur_blk++) { + /* Reset output sample vector */ + memset(out_buf, (int) 0, N); + + /* Read a block of samples */ + if (run_encoder) { + /* Reset sample vector */ + memset(inp_buf, (int) 0, N); + + /* Read a block of uncoded samples */ + if ((smpno = fread(inp_buf, sizeof(short), (long) N, Fi)) <= 0) + break; + } else { + /* Reset frame vector */ + memset(rpe_frame, (int) 0, (long) RPE_FRAME_SIZE); + + /* Read a packed frame */ + if ((smpno = fread(gsm_frame, sizeof(Byte), 33, Fi)) <= 0) { + fprintf(stderr, "fread gsm_frame\n"); + break; + } + } + + /* Carry out the desired operation */ + + /* CODEC OPERATION */ + if (run_encoder && run_decoder) { + /* Run both and save decoded samples */ + + /* First, expand samples, if needed */ + if (format) { + memcpy(tmp_buf, inp_buf, (long) (sizeof(short) * smpno)); + expand(smpno, tmp_buf, inp_buf); + } + + /* Encode & decode ... */ + rpeltp_encode(rpe_enc_state, inp_buf, rpe_frame); + rpeltp_decode(rpe_dec_state, rpe_frame, out_buf); + + /* Compress samples, if requested */ + if (format) { + memcpy(tmp_buf, out_buf, (long) (sizeof(short) * N)); + compress(N, tmp_buf, out_buf); + } + + /* Save samples to file */ + if (!(smpno = fwrite(out_buf, sizeof(short), (long) smpno, Fo))) + break; + } + /* ENCODER-ONLY OPERATION */ + else if (run_encoder) { + + /* First, expand samples, if needed */ + if (format) { + memcpy(tmp_buf, inp_buf, (long) (sizeof(short) * smpno)); + expand(smpno, tmp_buf, inp_buf); + } + + /* Run only the encoder and save rpe-ltp frame */ + gsm_encode(rpe_enc_state, inp_buf, gsm_frame); + + if (!(smpno = + fwrite(gsm_frame, sizeof(Byte), 33, Fo))) + break; + } + /* DECODER-ONLY OPERATION */ + else { + /* Decode frame */ + gsm_decode(rpe_dec_state, gsm_frame, out_buf); + + /* Compress samples, if requested */ + if (format) { + memcpy(tmp_buf, out_buf, (long) (sizeof(short) * N)); + compress(N, tmp_buf, out_buf); + } + + /* Save the decoded samples */ + if (!(smpno = fwrite(out_buf, sizeof(short), (long) N, Fo))) + break; + } + count += smpno; + } + + /* Check for errors */ + if (ferror(Fi)) + KILL(FileIn, 6); + else if (ferror(Fo)) + KILL(FileOut, 7); + + /* ......... FINALIZATIONS ......... */ + + /* Close input and output files and state */ + fclose(Fi); + fclose(Fo); + rpeltp_delete(rpe_enc_state); + rpeltp_delete(rpe_dec_state); + + /* Exit with success for non-vms systems */ +#ifndef VMS + return (0); +#endif +} + +/* ............................. end of main() ............................. */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpedemo.prj Binary file intercom/gsm/rpedemo.prj has changed diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpeltp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/rpeltp.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,282 @@ +/* v1.0 - 12/Apr/1994 + ============================================================================= + + U U GGG SSSS TTTTT + U U G S T + U U G GG SSSS T + U U G G S T + UUU GG SSS T + + ======================================== + ITU-T - USER'S GROUP ON SOFTWARE TOOLS + ======================================== + +MODULE: RPELTP.C - GSM 06.10 RPE-LTP SPEECH ENCODING ALGORITHM + +ORIGINAL BY: + + The driving routines of this module were written by: + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-6637 + CPqD/Telebras Fax: +55-192-39-6125 + 13088-061 Campinas SP Brazil E-mail: + + The true implementation was done by + Jutta Deneger (jutta@cs.tu-berlin.de) + Carsten Borman (cabo@cs.tu-berlin.de) + Communications and Operating Systems Research Group (KBS) + Technishe Universitaet Berlin + + The portability changes on the code and rearrangement were done by + +DATE: 12/Apr/1994: 18H00 -3H00GMT + +RELEASE: 1.00 + +PROTOTYPES: see rpeltp.h for driving-routine prototypes, gsm.h for + general prototypes, and private.h for special definitions. + +OBSERVATION: + Copyright note by the original authors: + " Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + Universitaet Berlin. See the accompanying file "COPYRIGHT" for + details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE." + +FUNCTIONS: (Only UGST user-level functions!) + +rpeltp_init() ......... Initializes the state variable for the encoding or + the decoding algorithm. Each need a separate state + variable!!! + +rpeltp_delete ......... Delete the state variable allocation, etc (an alias). + +rpeltp_encode ......... Entry-level function for the encoding algorithm. + +rpeltp_decode ......... Entry-level function for the decoding algorithm. + +============================================================================ +*/ +#include /* For NULL */ +#include "private.h" +#include "gsm.h" +#include "rpeltp.h" + +/* *** Alias functions *** */ +/* + ------------------------------------------------------------------------ + void rpeltp_delete(gsm_state *st); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + Frees memory of a state variable previously initialized by a call to + rpeltp_init(). This is an alias to the function gsm_destroy() implemented + by the original authors of the module. + + Variables: + ~~~~~~~~~~ + A pointer to a valid encoder or decoder state variable. + + Return value: + ~~~~~~~~~~~~~ + None. + + Prototype: in gsm.h + ~~~~~~~~~~ + + Original author: + ~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-6637 + CPqD/Telebras Fax: +55-192-39-6125 + 13088-061 Campinas SP Brazil E-mail: + + Log of changes: + ~~~~~~~~~~~~~~~ + 12.Apr.94 v.1.0 created. + + ------------------------------------------------------------------------ +*/ +/* #define rpeltp_delete gsm_destroy / * This is already done in rpeltp.h !!! */ +/* ................... End of rpeltp_delete() ......................... */ + + +/* *** True functions *** */ + +/* + ------------------------------------------------------------------------ + gsm_state *rpeltp_init(void); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Description: + ~~~~~~~~~~~~ + Allocates memory for the state variable of the encoder or the decoder, + and resets flags to proper initial values. This includes processing + strictly according to the Rec. GSM 06.10. + + In a encoder plus decoder calling program there must exist different + state variables for the encoder and for the decoder. + + Variables: + ~~~~~~~~~~ + None. + + Return value: + ~~~~~~~~~~~~~ + Returns a pointer to a valid encoder or decoder state variable. On + failure, returns NULL. + + Prototype: in rpeltp.h + ~~~~~~~~~~ + + Original author: + ~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-6637 + CPqD/Telebras Fax: +55-192-39-6125 + 13088-061 Campinas SP Brazil E-mail: + + Log of changes: + ~~~~~~~~~~~~~~~ + 12.Apr.94 v.1.0 created. + + ------------------------------------------------------------------------ +*/ +gsm rpeltp_init() +{ + gsm rpe_state; + int gsm_compliant = 0; + + /* Initializa state variable */ + if (!(rpe_state = gsm_create())) + return ((gsm) (NULL)); + + /* The gsm_{en,de}code() routines may operate on a compliant mode, or + * in a non-compliant, faster mode - here we use the complyant one */ + (void) gsm_option(rpe_state, GSM_OPT_FAST, &gsm_compliant); + + return (rpe_state); +} + +/* ................... End of rpeltp_init() ......................... */ + + +/* + ------------------------------------------------------------------------ + void gsm_state *rpeltp_encode (gsm_state *rpe_state, short *inp_buf, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ short *rpe_frame); + + + Description: + ~~~~~~~~~~~~ + Process the input buffer inp_buf with left-aligned 16-bit linear-format, + 2-complement samples using 13-bit resolution, i.e., the lower 3 bits of + each input sample are ignored. + + The rpe-ltp frame buffer rpe_frame is word-oriented (16-bit samples), + right-aligned i.e., the lower bits are the most significatives. + They follow the sequence specified by the `parameter number' in + Table 1.1 of the Rec.GSM-06.10. + + The input buffer has always 160 samples, and the generated frame has + always 76 samples. + + Variables: + ~~~~~~~~~~ + rpe_state ... state variable initialized by a previous call to rpeltp_init() + inp_buf ..... pointer to a buffer with 160 16-bit, left aligned samples + rpe_frame ... pointer to a rpe-ltp encoded frame buffer. Has length of 76. + The samples are 16-bit, right-aligned. + + Return value: + ~~~~~~~~~~~~~ + None. + + Prototype: in rpeltp.h + ~~~~~~~~~~ + + Original author: + ~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-6637 + CPqD/Telebras Fax: +55-192-39-6125 + 13088-061 Campinas SP Brazil E-mail: + + Log of changes: + ~~~~~~~~~~~~~~~ + 12.Apr.94 v.1.0 created. + + ------------------------------------------------------------------------ +*/ +void rpeltp_encode(rpe_state, inp_buf, rpe_frame) +gsm rpe_state; +short *inp_buf, *rpe_frame; +{ + gsm_frame rpe_packed_frame; + + /* Run both and save decoded samples */ + gsm_encode(rpe_state, inp_buf, rpe_packed_frame); + gsm_explode(rpe_state, rpe_packed_frame, rpe_frame); +} + +/* ................... End of rpeltp_encode() ......................... */ + + +/* + ------------------------------------------------------------------------ + void gsm_state *rpeltp_decode (gsm_state *rpe_state, short *rpe_frame, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ short *out_buf); + + + Description: + ~~~~~~~~~~~~ + Decode the input rpe-ltp encoded frame buffer rpe_buf with 76 righ-aligned + 16-bit samples, generating 160 decoded 16-bit, left-aligned linear + 2's-complement samples with 13-bit resolution, i.e., the lower 3 bits of + each input sample are zeroed. These are saved in out_buf. + + The rpe-ltp frame buffer rpe_frame sample has the sequence specified by + the `parameter number' in Table 1.1 of the Rec.GSM-06.10. + + Variables: + ~~~~~~~~~~ + rpe_state ... state variable initialized by a previous call to rpeltp_init() + rpe_frame ... pointer to a rpe-ltp encoded frame buffer. Has length of 76. + The samples are 16-bit, right-aligned. + out_buf ..... pointer to the decode sample's buffer with 160 16-bit, + left aligned samples + + Return value: + ~~~~~~~~~~~~~ + None. + + Prototype: in rpeltp.h + ~~~~~~~~~~ + + Original author: + ~~~~~~~~~~~~~~~~ + Simao Ferraz de Campos Neto + DDS/Pr11 Tel: +55-192-39-6637 + CPqD/Telebras Fax: +55-192-39-6125 + 13088-061 Campinas SP Brazil E-mail: + + Log of changes: + ~~~~~~~~~~~~~~~ + 12.Apr.94 v.1.0 created. + + ------------------------------------------------------------------------ +*/ +void rpeltp_decode(rpe_state, rpe_frame, out_buf) +gsm rpe_state; +short *out_buf, *rpe_frame; +{ + gsm_frame rpe_packed_frame; + + /* Pack frame, run only the decoder and save the decoded samples */ + gsm_implode(rpe_state, rpe_frame, rpe_packed_frame); + gsm_decode(rpe_state, rpe_packed_frame, out_buf); +} + +/* ................... End of rpeltp_decode() ......................... */ + +/* -------------------------- END OF RPELTP.C ------------------------ */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpeltp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/rpeltp.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,33 @@ +/* -------------------------------------------------------------------------- */ +/* File: RPELTP.H version 1.0 2-APR-1994 (18:00) */ +/* -------------------------------------------------------------------------- */ +/* Definitions for the rpeltp module */ +/* -------------------------------------------------------------------------- */ +#ifndef RPELTP_defined +#define RPELTP_defined 100 + +#ifndef ARGS +#if defined(MSDOS) || defined(VMS) || defined (__STDC__) +#define ARGS(x) x +#else /* Unix: no parameters in prototype! */ +#define ARGS(x) () +#endif +#endif + +/* Some basic definitions */ +#define RPE_FRAME_SIZE 76L +#define RPE_WIND_SIZE 160L + +/* Function prototypes */ +gsm rpeltp_init ARGS((void)); +void rpeltp_encode ARGS((gsm rpe_state, short *inp_buf, + short *rpe_frame)); +void rpeltp_decode ARGS((gsm rpe_state, short *rpe_frame, + short *out_buf)); + +/* Alias-function definition */ +#define rpeltp_delete gsm_destroy + +#endif /* RPELTP_defined */ + +/* ------------------------- End of file rpeltp.h ------------------------- */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/rpeltp.rme --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/rpeltp.rme Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,73 @@ + + U G S T + + rpeltp.rme - Read me file for RPELTP module + (05.May.95) + + ============================================================= + 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". Further copyright notice below. + ============================================================= + +This is the readme file for the ITU-T STL module rpeltp. This module has +been based on the implementation done by Jutta Degener and Carsten Bormann, +from the Technische Universitaet Berlin, at the Communications and +Operating Systems Research Group (KBS). + +The authors have granted the right to use it provided that the copyright +notices are kept in the files. See file "cpyright" for their copyright +conditions and statements. + +This module comprises several files, described below: + +rpeltp.rme This readme file +changes report of changes and portability notes for the UGST port, + in relation with the original distribution. +copyright Original copyright note from the original authors + +make-vms.com Program-making DCL for VAX-C and VMS port of the GNU C compiler +makefile.tcc Makefile for Borland's tcc +makefile.cl Makefile for MS Visual C Compiler +makefile.djc Makefile for the MSDOS port of the GNU-C compiler (DJCPP) +makefile.unx Unix Makefile, adapted from the original distribution +rpedemo.prj Borland's BC project file (binary!) + +add_test.c Program for testing the correct working of the functions + in add.c. Needed only when porting the program to new + platforms. +add_test.dta Input test sequence for add_test.c + +rpedemo.c demo program for the rpeltp module +ugstdemo.h UGST header with user interface macros and other nice stuf. + +The following are the functions that comprise the rpeltp module: +add.c code.c config.h debug.c decode.c +gsm.h gsm_crea.c gsm_deco.c gsm_dest.c gsm_enco.c +gsm_expl.c gsm_impl.c gsm_opti.c gsm_prin.c long_ter.c +lpc.c preproce.c private.h proto.h rpe.c +rpeltp.c rpeltp.h short_te.c table.c unproto.h + +all above but rpeltp.c are from the original distribution (after changes to +ensure portability!). This one has been added to provide "driving" functions +in the UGST style. + +File names from the original distribution had to be shortened because of the +DOS limitation for 8 plus 3 letters for file names. See "changes" for a +list of the files with changes (shortened) names. + +Note on Testing: +~~~~~~~~~~~~~~~~ +The directory ts has a file named sine.lin, that is a sinewave. Try make with +the proper makefile and run with the target `sine'. Then you should get no +differences. Please note that this is *not* a thorough validation of the +coder, because this is done using the 5 test sequences sold by ETSI. Because +they are sold, we cannot distribute them here. But the code has been tested, +and passed, the necessary test sequence in at least: Sun [cc/gcc/acc and +SunOs 4.3], VAX/VMS [Vax-C3/gcc], HP-UX [gcc], PC [bcc 16 bit/DJC gcc]. +Therefore, use sine.lin to test for rough errors. +NOTE: If you have the test sequences, the makefiles can process them for you, +if they are named seq01 to seq05. +-- ------- diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/short_te.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/short_te.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,419 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/short_term.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +#include +#include + +#include "private.h" + +#include "gsm.h" +#include "proto.h" + +/* + * SHORT TERM ANALYSIS FILTERING SECTION + */ + +/* 4.2.8 */ + +static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc, LARpp), word * LARc, /* coded log area ratio [0..7] IN */ + word * LARpp) +{ /* out: decoded .. */ + register word temp1; + /* register word temp2; -> This is unused */ + register long ltmp; /* for GSM_ADD */ + + /* This procedure requires for efficient implementation + * two tables. + * + * INVA[1..8] = integer( (32768 * 8) / real_A[1..8]) + * MIC[1..8] = minimum value of the LARc[1..8] + */ + + /* Compute the LARpp[1..8] + */ + + /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) { + * + * temp1 = GSM_ADD( *LARc, *MIC ) << 10; + * temp2 = *B << 1; + * temp1 = GSM_SUB( temp1, temp2 ); + * + * assert(*INVA != MIN_WORD); + * + * temp1 = GSM_MULT_R( *INVA, temp1 ); + * *LARpp = GSM_ADD( temp1, temp1 ); + * } + */ + +#ifdef STEP +#undef STEP +#endif + +#define STEP( B, MIC, INVA ) \ + temp1 = GSM_ADD( *LARc++, MIC ) << 10; \ + temp1 = GSM_SUB( temp1, B << 1 ); \ + temp1 = GSM_MULT_R( INVA, temp1 ); \ + *LARpp++ = GSM_ADD( temp1, temp1 ); + + STEP(0, -32, 13107); + STEP(0, -32, 13107); + STEP(2048, -16, 13107); + STEP(-2560, -16, 13107); + + STEP(94, -8, 19223); + STEP(-1792, -8, 17476); + STEP(-341, -4, 31454); + STEP(-1144, -4, 29708); + + /* NOTE: the addition of *MIC is used to restore + * the sign of *LARc. + */ +} + +/* 4.2.9 */ +/* Computation of the quantized reflection coefficients + */ + +/* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8] + */ + +/* + * Within each frame of 160 analyzed speech samples the short term + * analysis and synthesis filters operate with four different sets of + * coefficients, derived from the previous set of decoded LARs(LARpp(j-1)) + * and the actual set of decoded LARs (LARpp(j)) + * + * (Initial value: LARpp(j-1)[1..8] = 0.) + */ + +static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, register word * LARp) +{ + register int i; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) { + *LARp = GSM_ADD(SASR(*LARpp_j_1, 2), SASR(*LARpp_j, 2)); + *LARp = GSM_ADD(*LARp, SASR(*LARpp_j_1, 1)); + } +} + +static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, register word * LARp) +{ + register int i; + register longword ltmp; + for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { + *LARp = GSM_ADD(SASR(*LARpp_j_1, 1), SASR(*LARpp_j, 1)); + } +} + +static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, register word * LARp) +{ + register int i; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { + *LARp = GSM_ADD(SASR(*LARpp_j_1, 2), SASR(*LARpp_j, 2)); + *LARp = GSM_ADD(*LARp, SASR(*LARpp_j, 1)); + } +} + + +static void Coefficients_40_159 P2((LARpp_j, LARp), + register word * LARpp_j, register word * LARp) +{ + register int i; + + for (i = 1; i <= 8; i++, LARp++, LARpp_j++) + *LARp = *LARpp_j; +} + +/* 4.2.9.2 */ + +static void LARp_to_rp P1((LARp), register word * LARp) +{ /* [0..7] IN/OUT */ + /* + * The input of this procedure is the interpolated LARp[0..7] array. + * The reflection coefficients, rp[i], are used in the analysis + * filter and in the synthesis filter. + */ + register int i; + register word temp; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARp++) { + + /* temp = GSM_ABS( *LARp ); + * + * if (temp < 11059) temp <<= 1; + * else if (temp < 20070) temp += 11059; + * else temp = GSM_ADD( temp >> 2, 26112 ); + * + * *LARp = *LARp < 0 ? -temp : temp; + */ + + if (*LARp < 0) { + temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp); + *LARp = -((temp < 11059) ? temp << 1 + : ((temp < 20070) ? temp + 11059 : GSM_ADD(temp >> 2, 26112))); + } else { + temp = *LARp; + *LARp = (temp < 11059) ? temp << 1 + : ((temp < 20070) ? temp + 11059 : GSM_ADD(temp >> 2, 26112)); + } + } +} + + +/* 4.2.10 */ +static void Short_term_analysis_filtering P4((S, rp, k_n, s), struct gsm_state *S, register word * rp, /* [0..7] IN */ + register int k_n, /* k_end - k_start */ + register word * s /* [0..n-1] IN/OUT */ + ) +/* + * This procedure computes the short term residual signal d[..] to be fed + * to the RPE-LTP loop from the s[..] signal and from the local rp[..] + * array (quantized reflection coefficients). As the call of this + * procedure can be done in many ways (see the interpolation of the LAR + * coefficient), it is assumed that the computation begins with index + * k_start (for arrays d[..] and s[..]) and stops with index k_end + * (k_start and k_end are defined in 4.2.9.1). This procedure also + * needs to keep the array u[0..7] in memory for each call. + */ +{ + register word *u = S->u; + register int i; + register word di, zzz, ui, sav, rpi; + register longword ltmp; + + for (; k_n--; s++) { + + di = sav = *s; + + for (i = 0; i < 8; i++) { /* YYY */ + + ui = u[i]; + rpi = rp[i]; + u[i] = sav; + + zzz = GSM_MULT_R(rpi, di); + sav = GSM_ADD(ui, zzz); + + zzz = GSM_MULT_R(rpi, ui); + di = GSM_ADD(di, zzz); + } + + *s = di; + } +} + +#if defined(USE_FLOAT_MUL) && defined(FAST) + +static void Fast_Short_term_analysis_filtering P4((S, rp, k_n, s), struct gsm_state *S, register word * rp, /* [0..7] IN */ + register int k_n, /* k_end - k_start */ + register word * s /* [0..n-1] IN/OUT */ + ) +{ + register word *u = S->u; + register int i; + + float uf[8], rpf[8]; + + register float scalef = 3.0517578125e-5; + register float sav, di, temp; + + for (i = 0; i < 8; ++i) { + uf[i] = u[i]; + rpf[i] = rp[i] * scalef; + } + for (; k_n--; s++) { + sav = di = *s; + for (i = 0; i < 8; ++i) { + register float rpfi = rpf[i]; + register float ufi = uf[i]; + + uf[i] = sav; + temp = rpfi * di + ufi; + di += rpfi * ufi; + sav = temp; + } + *s = di; + } + for (i = 0; i < 8; ++i) + u[i] = uf[i]; +} +#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */ + +static void Short_term_synthesis_filtering P5((S, rrp, k, wt, sr), struct gsm_state *S, register word * rrp, /* [0..7] IN */ + register int k, /* k_end - k_start */ + register word * wt, /* [0..k-1] IN */ + register word * sr /* [0..k-1] OUT */ + ) +{ + register word *v = S->v; + register int i; + register word sri, tmp1, tmp2; + register longword ltmp; /* for GSM_ADD & GSM_SUB */ + + while (k--) { + sri = *wt++; + for (i = 8; i--;) { + + /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) ); + */ + tmp1 = rrp[i]; + tmp2 = v[i]; + tmp2 = (tmp1 == MIN_WORD && tmp2 == MIN_WORD + ? MAX_WORD + : 0x0FFFF & (((longword) tmp1 * (longword) tmp2 + + 16384) >> 15)); + + sri = GSM_SUB(sri, tmp2); + + /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) ); + */ + tmp1 = (tmp1 == MIN_WORD && sri == MIN_WORD + ? MAX_WORD + : 0x0FFFF & (((longword) tmp1 * (longword) sri + 16384) >> 15)); + + v[i + 1] = GSM_ADD(v[i], tmp1); + } + *sr++ = v[0] = sri; + } +} + + +#if defined(FAST) && defined(USE_FLOAT_MUL) + +static void Fast_Short_term_synthesis_filtering P5((S, rrp, k, wt, sr), struct gsm_state *S, register word * rrp, /* [0..7] IN */ + register int k, /* k_end - k_start */ + register word * wt, /* [0..k-1] IN */ + register word * sr /* [0..k-1] OUT */ + ) +{ + register word *v = S->v; + register int i; + + float va[9], rrpa[8]; + register float scalef = 3.0517578125e-5, temp; + + for (i = 0; i < 8; ++i) { + va[i] = v[i]; + rrpa[i] = (float) rrp[i] * scalef; + } + while (k--) { + register float sri = *wt++; + for (i = 8; i--;) { + sri -= rrpa[i] * va[i]; + if (sri < -32768.) + sri = -32768.; + else if (sri > 32767.) + sri = 32767.; + + temp = va[i] + rrpa[i] * sri; + if (temp < -32768.) + temp = -32768.; + else if (temp > 32767.) + temp = 32767.; + va[i + 1] = temp; + } + *sr++ = va[0] = sri; + } + for (i = 0; i < 9; ++i) + v[i] = va[i]; +} + +#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */ + +void Gsm_Short_Term_Analysis_Filter P3((S, LARc, s), struct gsm_state *S, word * LARc, /* coded log area ratio [0..7] IN */ + word * s /* signal [0..159] IN/OUT */ + ) +{ + word *LARpp_j = S->LARpp[S->j]; + word *LARpp_j_1 = S->LARpp[S->j ^= 1]; + + word LARp[8]; + +#ifdef FILTER +#undef FILTER +#endif + +#if defined(FAST) && defined(USE_FLOAT_MUL) +# define FILTER (* (S->fast \ + ? Fast_Short_term_analysis_filtering \ + : Short_term_analysis_filtering )) + +#else +# define FILTER Short_term_analysis_filtering +#endif + + Decoding_of_the_coded_Log_Area_Ratios(LARc, LARpp_j); + + Coefficients_0_12(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 13, s); + + Coefficients_13_26(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 14, s + 13); + + Coefficients_27_39(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 13, s + 27); + + Coefficients_40_159(LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 120, s + 40); +} + +void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s), struct gsm_state *S, word * LARcr, /* received log area ratios [0..7] IN */ + word * wt, /* received d [0..159] IN */ + word * s /* signal s [0..159] OUT */ + ) +{ + word *LARpp_j = S->LARpp[S->j]; + word *LARpp_j_1 = S->LARpp[S->j ^= 1]; + + word LARp[8]; + +#ifdef FILTER +#undef FILTER +#endif + +#if defined(FAST) && defined(USE_FLOAT_MUL) + +# define FILTER (* (S->fast \ + ? Fast_Short_term_synthesis_filtering \ + : Short_term_synthesis_filtering )) +#else +# define FILTER Short_term_synthesis_filtering +#endif + + Decoding_of_the_coded_Log_Area_Ratios(LARcr, LARpp_j); + + Coefficients_0_12(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 13, wt, s); + + Coefficients_13_26(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 14, wt + 13, s + 13); + + Coefficients_27_39(LARpp_j_1, LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 13, wt + 27, s + 27); + + Coefficients_40_159(LARpp_j, LARp); + LARp_to_rp(LARp); + FILTER(S, LARp, 120, wt + 40, s + 40); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/table.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/table.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,68 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/table.c,v 1.1 1992/10/28 00:15:50 jutta Exp $ */ + +/* Most of these tables are inlined at their point of use. + */ + +/* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP + * CODER AND DECODER + * + * (Most of them inlined, so watch out.) + */ + +#define GSM_TABLE_C +#include "private.h" +#include "gsm.h" + +/* Table 4.1 Quantization of the Log.-Area Ratios + */ +/* i 1 2 3 4 5 6 7 8 */ +word gsm_A[8] = + { 20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036 }; +word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144 }; +word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 }; +word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 }; + + +/* Table 4.2 Tabulation of 1/A[1..8] + */ +word gsm_INVA[8] = + { 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 }; + + +/* Table 4.3a Decision level of the LTP gain quantizer + */ +/* bc 0 1 2 3 */ +word gsm_DLB[4] = { 6554, 16384, 26214, 32767 }; + + +/* Table 4.3b Quantization levels of the LTP gain quantizer + */ +/* bc 0 1 2 3 */ +word gsm_QLB[4] = { 3277, 11469, 21299, 32767 }; + + +/* Table 4.4 Coefficients of the weighting filter + */ +/* i 0 1 2 3 4 5 6 7 8 9 10 */ +word gsm_H[11] = + { -134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 }; + + +/* Table 4.5 Normalized inverse mantissa used to compute xM/xmax + */ +/* i 0 1 2 3 4 5 6 7 */ +word gsm_NRFAC[8] = + { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 }; + + +/* Table 4.6 Normalized direct mantissa used to compute xM/xmax + */ +/* i 0 1 2 3 4 5 6 7 */ +word gsm_FAC[8] = + { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 }; diff -r 9cadc470e3da -r 13be24d74cd2 intercom/gsm/unproto.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/gsm/unproto.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,23 @@ +/* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + +/*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/unproto.h,v 1.1 1992/10/28 00:11:08 jutta Exp $*/ + +#ifdef PROTO_H /* sic */ +#undef PROTO_H + +#undef P +#undef P0 +#undef P1 +#undef P2 +#undef P3 +#undef P4 +#undef P5 +#undef P6 +#undef P7 +#undef P8 + +#endif /* PROTO_H */ diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/COPYRIGHT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/COPYRIGHT Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,76 @@ + Copyright (C) The Internet Society (2004). + + This document is subject to the rights, licenses and restrictions + contained in BCP 78, and except as set forth therein, the authors + retain all their rights. + + This document and the information contained herein are provided on an + "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS + OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET + ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE + INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED + WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + + +Authors' Addresses + + Soren Vang Andersen + Department of Communication Technology + Aalborg University + Fredrik Bajers Vej 7A + 9200 Aalborg + Denmark + + Phone: ++45 9 6358627 + EMail: sva@kom.auc.dk + + + Alan Duric + Telio AS + Stoperigt. 2 + Oslo, N-0250 + Norway + + Phone: +47 21673555 + EMail: alan.duric@telio.no + + + Henrik Astrom + Global IP Sound AB + Olandsgatan 42 + Stockholm, S-11663 + Sweden + + Phone: +46 8 54553040 + EMail: henrik.astrom@globalipsound.com + + + Roar Hagen + Global IP Sound AB + Olandsgatan 42 + Stockholm, S-11663 + Sweden + + Phone: +46 8 54553040 + EMail: roar.hagen@globalipsound.com + + + W. Bastiaan Kleijn + Global IP Sound AB + Olandsgatan 42 + Stockholm, S-11663 + Sweden + + Phone: +46 8 54553040 + EMail: bastiaan.kleijn@globalipsound.com + + + Jan Linden + Global IP Sound Inc. + 900 Kearny Street, suite 500 + San Francisco, CA-94133 + USA + + Phone: +1 415 397 2555 + EMail: jan.linden@globalipsound.com diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/FrameClassify.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/FrameClassify.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,117 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + FrameClassify.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "iLBC_define.h" + + /*---------------------------------------------------------------* + * Classification of subframes to localize start state + *--------------------------------------------------------------*/ + +int FrameClassify( /* index to the max-energy sub-frame */ + iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i/o) the encoder state structure */ + float *residual /* (i) lpc residual signal */ + ) +{ + float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp; + int n, l, max_ssqEn_n; + const float ssqEn_win[NSUB_MAX - 1] = { (float) 0.8, (float) 0.9, + (float) 1.0, (float) 0.9, (float) 0.8 + }; + const float sampEn_win[5] = { (float) 1.0 / (float) 6.0, + (float) 2.0 / (float) 6.0, (float) 3.0 / (float) 6.0, + (float) 4.0 / (float) 6.0, (float) 5.0 / (float) 6.0 + }; + + /* init the front and back energies to zero */ + + memset(fssqEn, 0, NSUB_MAX * sizeof(float)); + memset(bssqEn, 0, NSUB_MAX * sizeof(float)); + + /* Calculate front of first seqence */ + + n = 0; + pp = residual; + for (l = 0; l < 5; l++) { + fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); + pp++; + } + for (l = 5; l < SUBL; l++) { + + + + + + fssqEn[n] += (*pp) * (*pp); + pp++; + } + + /* Calculate front and back of all middle sequences */ + + for (n = 1; n < iLBCenc_inst->nsub - 1; n++) { + pp = residual + n * SUBL; + for (l = 0; l < 5; l++) { + fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); + bssqEn[n] += (*pp) * (*pp); + pp++; + } + for (l = 5; l < SUBL - 5; l++) { + fssqEn[n] += (*pp) * (*pp); + bssqEn[n] += (*pp) * (*pp); + pp++; + } + for (l = SUBL - 5; l < SUBL; l++) { + fssqEn[n] += (*pp) * (*pp); + bssqEn[n] += sampEn_win[SUBL - l - 1] * (*pp) * (*pp); + pp++; + } + } + + /* Calculate back of last seqence */ + + n = iLBCenc_inst->nsub - 1; + pp = residual + n * SUBL; + for (l = 0; l < SUBL - 5; l++) { + bssqEn[n] += (*pp) * (*pp); + pp++; + } + for (l = SUBL - 5; l < SUBL; l++) { + bssqEn[n] += sampEn_win[SUBL - l - 1] * (*pp) * (*pp); + pp++; + } + + /* find the index to the weighted 80 sample with + most energy */ + + if (iLBCenc_inst->mode == 20) + l = 1; + else + l = 0; + + max_ssqEn = (fssqEn[0] + bssqEn[1]) * ssqEn_win[l]; + max_ssqEn_n = 1; + for (n = 2; n < iLBCenc_inst->nsub; n++) { + + + + + + + l++; + if ((fssqEn[n - 1] + bssqEn[n]) * ssqEn_win[l] > max_ssqEn) { + max_ssqEn = (fssqEn[n - 1] + bssqEn[n]) * ssqEn_win[l]; + max_ssqEn_n = n; + } + } + + return max_ssqEn_n; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/FrameClassify.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/FrameClassify.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,26 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + FrameClassify.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_FRAMECLASSIFY_H +#define __iLBC_FRAMECLASSIFY_H + +int FrameClassify( /* index to the max-energy sub-frame */ + iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i/o) the encoder state structure */ + float *residual /* (i) lpc residual signal */ + ); + + + + + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/LPCdecode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/LPCdecode.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,145 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + LPC_decode.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "helpfun.h" +#include "lsf.h" +#include "iLBC_define.h" +#include "constants.h" + + /*---------------------------------------------------------------* + * interpolation of lsf coefficients for the decoder + *--------------------------------------------------------------*/ + +void LSFinterpolate2a_dec(float *a, /* (o) lpc coefficients for a sub-frame */ + float *lsf1, /* (i) first lsf coefficient vector */ + float *lsf2, /* (i) second lsf coefficient vector */ + float coef, /* (i) interpolation weight */ + int length /* (i) length of lsf vectors */ + ) +{ + float lsftmp[LPC_FILTERORDER]; + + interpolate(lsftmp, lsf1, lsf2, coef, length); + lsf2a(a, lsftmp); +} + + /*---------------------------------------------------------------* + * obtain dequantized lsf coefficients from quantization index + *--------------------------------------------------------------*/ + +void SimplelsfDEQ(float *lsfdeq, /* (o) dequantized lsf coefficients */ + int *index, /* (i) quantization index */ + int lpc_n /* (i) number of LPCs */ + ) +{ + int i, j, pos, cb_pos; + + + + + + /* decode first LSF */ + + pos = 0; + cb_pos = 0; + for (i = 0; i < LSF_NSPLIT; i++) { + for (j = 0; j < dim_lsfCbTbl[i]; j++) { + lsfdeq[pos + j] = lsfCbTbl[cb_pos + + (long) (index[i]) * dim_lsfCbTbl[i] + j]; + } + pos += dim_lsfCbTbl[i]; + cb_pos += size_lsfCbTbl[i] * dim_lsfCbTbl[i]; + } + + if (lpc_n > 1) { + + /* decode last LSF */ + + pos = 0; + cb_pos = 0; + for (i = 0; i < LSF_NSPLIT; i++) { + for (j = 0; j < dim_lsfCbTbl[i]; j++) { + lsfdeq[LPC_FILTERORDER + pos + j] = + lsfCbTbl[cb_pos + + (long) (index[LSF_NSPLIT + i]) * dim_lsfCbTbl[i] + j]; + } + pos += dim_lsfCbTbl[i]; + cb_pos += size_lsfCbTbl[i] * dim_lsfCbTbl[i]; + } + } +} + + /*----------------------------------------------------------------* + * obtain synthesis and weighting filters form lsf coefficients + *---------------------------------------------------------------*/ + +void DecoderInterpolateLSF(float *syntdenum, /* (o) synthesis filter coefficients */ + float *weightdenum, /* (o) weighting denumerator + coefficients */ + float *lsfdeq, /* (i) dequantized lsf coefficients */ + int length, /* (i) length of lsf coefficient vector */ + iLBC_Dec_Inst_t * iLBCdec_inst + /* (i) the decoder state structure */ + ) +{ + int i, pos, lp_length; + float lp[LPC_FILTERORDER + 1], *lsfdeq2; + + + + + + + lsfdeq2 = lsfdeq + length; + lp_length = length + 1; + + if (iLBCdec_inst->mode == 30) { + /* sub-frame 1: Interpolation between old and first */ + + LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, + lsf_weightTbl_30ms[0], length); + memcpy(syntdenum, lp, lp_length * sizeof(float)); + bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + + /* sub-frames 2 to 6: interpolation between first + and last LSF */ + + pos = lp_length; + for (i = 1; i < 6; i++) { + LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, + lsf_weightTbl_30ms[i], length); + memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); + bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + pos += lp_length; + } + } else { + pos = 0; + for (i = 0; i < iLBCdec_inst->nsub; i++) { + LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, + lsfdeq, lsf_weightTbl_20ms[i], length); + memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); + bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + pos += lp_length; + } + } + + /* update memory */ + + if (iLBCdec_inst->mode == 30) + memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, length * sizeof(float)); + else + memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, length * sizeof(float)); + +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/LPCdecode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/LPCdecode.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,37 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + LPC_decode.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_LPC_DECODE_H +#define __iLBC_LPC_DECODE_H + +void LSFinterpolate2a_dec(float *a, /* (o) lpc coefficients for a sub-frame */ + float *lsf1, /* (i) first lsf coefficient vector */ + float *lsf2, /* (i) second lsf coefficient vector */ + float coef, /* (i) interpolation weight */ + int length /* (i) length of lsf vectors */ + ); + +void SimplelsfDEQ(float *lsfdeq, /* (o) dequantized lsf coefficients */ + int *index, /* (i) quantization index */ + int lpc_n /* (i) number of LPCs */ + ); + +void DecoderInterpolateLSF(float *syntdenum, /* (o) synthesis filter coefficients */ + float *weightdenum, /* (o) weighting denumerator + coefficients */ + float *lsfdeq, /* (i) dequantized lsf coefficients */ + int length, /* (i) length of lsf coefficient vector */ + iLBC_Dec_Inst_t * iLBCdec_inst + /* (i) the decoder state structure */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/LPCencode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/LPCencode.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,235 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + LPCencode.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include + +#include "iLBC_define.h" +#include "helpfun.h" +#include "lsf.h" +#include "constants.h" + + + + + + /*----------------------------------------------------------------* + * lpc analysis (subrutine to LPCencode) + *---------------------------------------------------------------*/ + +void SimpleAnalysis(float *lsf, /* (o) lsf coefficients */ + float *data, /* (i) new data vector */ + iLBC_Enc_Inst_t * iLBCenc_inst + /* (i/o) the encoder state structure */ + ) +{ + int k, is; + float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1]; + float lp2[LPC_FILTERORDER + 1]; + float r[LPC_FILTERORDER + 1]; + + is = LPC_LOOKBACK + BLOCKL_MAX - iLBCenc_inst->blockl; + memcpy(iLBCenc_inst->lpc_buffer + is, data, + iLBCenc_inst->blockl * sizeof(float)); + + /* No lookahead, last window is asymmetric */ + + for (k = 0; k < iLBCenc_inst->lpc_n; k++) { + + is = LPC_LOOKBACK; + + if (k < (iLBCenc_inst->lpc_n - 1)) { + window(temp, lpc_winTbl, iLBCenc_inst->lpc_buffer, BLOCKL_MAX); + } else { + window(temp, lpc_asymwinTbl, + iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX); + } + + autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER); + window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1); + + levdurb(lp, temp, r, LPC_FILTERORDER); + bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER + 1); + + a2lsf(lsf + k * LPC_FILTERORDER, lp2); + } + is = LPC_LOOKBACK + BLOCKL_MAX - iLBCenc_inst->blockl; + memmove(iLBCenc_inst->lpc_buffer, + iLBCenc_inst->lpc_buffer + LPC_LOOKBACK + BLOCKL_MAX - is, + is * sizeof(float)); +} + + /*----------------------------------------------------------------* + + + + + + * lsf interpolator and conversion from lsf to a coefficients + * (subrutine to SimpleInterpolateLSF) + *---------------------------------------------------------------*/ + +void LSFinterpolate2a_enc(float *a, /* (o) lpc coefficients */ + float *lsf1, /* (i) first set of lsf coefficients */ + float *lsf2, /* (i) second set of lsf coefficients */ + float coef, /* (i) weighting coefficient to use between + lsf1 and lsf2 */ + long length /* (i) length of coefficient vectors */ + ) +{ + float lsftmp[LPC_FILTERORDER]; + + interpolate(lsftmp, lsf1, lsf2, coef, length); + lsf2a(a, lsftmp); +} + + /*----------------------------------------------------------------* + * lsf interpolator (subrutine to LPCencode) + *---------------------------------------------------------------*/ + +void SimpleInterpolateLSF(float *syntdenum, /* (o) the synthesis filter denominator + resulting from the quantized + interpolated lsf */ + float *weightdenum, /* (o) the weighting filter denominator + resulting from the unquantized + interpolated lsf */ + float *lsf, /* (i) the unquantized lsf coefficients */ + float *lsfdeq, /* (i) the dequantized lsf coefficients */ + float *lsfold, /* (i) the unquantized lsf coefficients of + the previous signal frame */ + float *lsfdeqold, /* (i) the dequantized lsf coefficients of + the previous signal frame */ + int length, /* (i) should equate LPC_FILTERORDER */ + iLBC_Enc_Inst_t * iLBCenc_inst + /* (i/o) the encoder state structure */ + ) +{ + int i, pos, lp_length; + float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2; + + lsf2 = lsf + length; + lsfdeq2 = lsfdeq + length; + lp_length = length + 1; + + if (iLBCenc_inst->mode == 30) { + /* sub-frame 1: Interpolation between old and first + + + + + + set of lsf coefficients */ + + LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, + lsf_weightTbl_30ms[0], length); + memcpy(syntdenum, lp, lp_length * sizeof(float)); + LSFinterpolate2a_enc(lp, lsfold, lsf, + lsf_weightTbl_30ms[0], length); + bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + + /* sub-frame 2 to 6: Interpolation between first + and second set of lsf coefficients */ + + pos = lp_length; + for (i = 1; i < iLBCenc_inst->nsub; i++) { + LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, + lsf_weightTbl_30ms[i], length); + memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); + + LSFinterpolate2a_enc(lp, lsf, lsf2, + lsf_weightTbl_30ms[i], length); + bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + pos += lp_length; + } + } else { + pos = 0; + for (i = 0; i < iLBCenc_inst->nsub; i++) { + LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, + lsf_weightTbl_20ms[i], length); + memcpy(syntdenum + pos, lp, lp_length * sizeof(float)); + LSFinterpolate2a_enc(lp, lsfold, lsf, + lsf_weightTbl_20ms[i], length); + bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); + pos += lp_length; + } + } + + /* update memory */ + + if (iLBCenc_inst->mode == 30) { + memcpy(lsfold, lsf2, length * sizeof(float)); + memcpy(lsfdeqold, lsfdeq2, length * sizeof(float)); + } else { + memcpy(lsfold, lsf, length * sizeof(float)); + memcpy(lsfdeqold, lsfdeq, length * sizeof(float)); + + + + + + } +} + + /*----------------------------------------------------------------* + * lsf quantizer (subrutine to LPCencode) + *---------------------------------------------------------------*/ + +void SimplelsfQ(float *lsfdeq, /* (o) dequantized lsf coefficients + (dimension FILTERORDER) */ + int *index, /* (o) quantization index */ + float *lsf, /* (i) the lsf coefficient vector to be + quantized (dimension FILTERORDER ) */ + int lpc_n /* (i) number of lsf sets to quantize */ + ) +{ + /* Quantize first LSF with memoryless split VQ */ + SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, + dim_lsfCbTbl, size_lsfCbTbl); + + if (lpc_n == 2) { + /* Quantize second LSF with memoryless split VQ */ + SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, + lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, + dim_lsfCbTbl, size_lsfCbTbl); + } +} + + /*----------------------------------------------------------------* + * lpc encoder + *---------------------------------------------------------------*/ + +void LPCencode(float *syntdenum, /* (i/o) synthesis filter coefficients + before/after encoding */ + float *weightdenum, /* (i/o) weighting denumerator + coefficients before/after + encoding */ + int *lsf_index, /* (o) lsf quantization index */ + float *data, /* (i) lsf coefficients to quantize */ + iLBC_Enc_Inst_t * iLBCenc_inst + /* (i/o) the encoder state structure */ + ) +{ + float lsf[LPC_FILTERORDER * LPC_N_MAX]; + float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; + int change = 0; + + SimpleAnalysis(lsf, data, iLBCenc_inst); + SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n); + + + + + + change = LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); + SimpleInterpolateLSF(syntdenum, weightdenum, + lsf, lsfdeq, iLBCenc_inst->lsfold, + iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/LPCencode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/LPCencode.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,26 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + LPCencode.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_LPCENCOD_H +#define __iLBC_LPCENCOD_H + +void LPCencode(float *syntdenum, /* (i/o) synthesis filter coefficients + before/after encoding */ + float *weightdenum, /* (i/o) weighting denumerator coefficients + before/after encoding */ + int *lsf_index, /* (o) lsf quantization index */ + float *data, /* (i) lsf coefficients to quantize */ + iLBC_Enc_Inst_t * iLBCenc_inst + /* (i/o) the encoder state structure */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/Makefile Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,59 @@ +# +# makefile for iLBC Codec +# + +# For GCC compiler +CC = gcc +LFLAG = +CFLAGS = -Wall -O2 + +# Objects +OBJ = iLBC_test.o + +OBJS = anaFilter.o\ + iCBSearch.o\ + packing.o\ + constants.o\ + gainquant.o\ + iLBC_decode.o\ + StateConstructW.o\ + createCB.o\ + getCBvec.o\ + iLBC_encode.o\ + StateSearchW.o\ + doCPLC.o\ + helpfun.o\ + syntFilter.o\ + enhancer.o\ + hpInput.o\ + LPCdecode.o\ + filter.o\ + hpOutput.o\ + LPCencode.o\ + FrameClassify.o\ + iCBConstruct.o\ + lsf.o + +# Implicit Rules +.c.o: + $(CC) $(CFLAGS) -c $< + +# Explicit Rules +all: ilbc.a iLBC_test + +ilbc.a: $(OBJS) + ar rcs $@ $(OBJS) + +iLBC_test: $(OBJ) + $(CC) $(LFLAG) -o iLBC_test $(CFLAGS) $(OBJ) ilbc.a -lm + +clean: + rm -f *.o *.a *~ *.moc.cpp *.bak iLBC_test + +distclean: clean + rm -f Makefile + +dep: + makedepend -- $(CFLAGS) *.c + + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/NOTICE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/NOTICE Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,38 @@ + NOTICE + +All use of the Original Code (GIPS iLBC, and code provided by GIPS as +part of any related IETF Standard or draft standard) is subject to the +complete Global IP Sound iLBC Public License, IETF Standard, Limited +Commercial Use (the (License ). By accessing the Original Code You agree +to the License terms. PLEASE SEE THE COMPLETE LICENSE BELOW FOR +ADDITIONAL TERMS. In general: + +- Personal, non-commercial use is generally permitted. + +- Commercialization is permitted with certain limitations; for example, + to ensure that every iLBC decoder can decode every iLBC-encoded + payload, commercial Deployment must comply with the applicable IETF + Standard/draft, and the format of the bitstream may not be modified. + +- You are provided no warranty or support, and all liability is + disclaimed. + +- You must register this license with GIPS prior to any commercial + Deployment. + +The License is available from +http://www.globalipsound.com/legal/licenses/ilbc; or from Global IP +Sound Europe AB, Ölandsgatan 42, SE-116 63, Stockholm, Sweden, ++46.8.545.5.30.40 tel, +46.8.545.5.30.49 fax; or from Global IP Sound +Inc., 900 Kearny Street, 5th Floor, San Francisco, California 94133-5124 +USA, +1 415.397.2555 tel, +1 415.397.2577 fax; or by sending a request +to info@globalipsound.com. + +The current IETF Standards can also be found at +http://www.ietf.org/rfc/rfc3951.txt plus +http://www.ietf.org/rfc/rfc3952.txt. The initial developer of the +Original Code is Global IP Sound Inc. Portions Copyright (C) 1999-2005, +All Rights Reserved. + +iLBC is a trademark of Global IP Sound. All redistribution is subject to +the License; source code must include this Notice. diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/README Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,22 @@ +The source files in this directory are from Appendix A Reference +Implementation of the iLBC Internet Low Bit Rate Codec. +See http://www.ilbcfreeware.org/software.html +and http://www.ietf.org/rfc/rfc3951.txt + +Place the awk script (courtesy of Wenju Jiang, Columbia University) and +the IETF rfc3951.txt file in the same directory, and then type +the following command: + +awk -f extract-cfile.awk rfc3951.txt + +Correct an error in file constants.c: +After line 13 #include "iLBC_define.h" +add the following line: + #include "constants.h" + +The end of file syntFilter.c contains after line 68 text that is not +source code. + +Source code was formated with indent: +indent -kr -i2 -nlp -ci2 -l72 -lc72 -nut *.c *.h + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/StateConstructW.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/StateConstructW.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,69 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + StateConstructW.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "iLBC_define.h" +#include "constants.h" +#include "filter.h" + + /*----------------------------------------------------------------* + * decoding of the start state + *---------------------------------------------------------------*/ + +void StateConstructW(int idxForMax, /* (i) 6-bit index for the quantization of + max amplitude */ + int *idxVec, /* (i) vector of quantization indexes */ + float *syntDenum, /* (i) synthesis filter denumerator */ + float *out, /* (o) the decoded state vector */ + int len /* (i) length of a state vector */ + ) +{ + float maxVal, tmpbuf[LPC_FILTERORDER + 2 * STATE_LEN], *tmp, + numerator[LPC_FILTERORDER + 1]; + float foutbuf[LPC_FILTERORDER + 2 * STATE_LEN], *fout; + int k, tmpi; + + /* decoding of the maximum value */ + + maxVal = state_frgqTbl[idxForMax]; + maxVal = (float) pow(10, maxVal) / (float) 4.5; + + /* initialization of buffers and coefficients */ + + memset(tmpbuf, 0, LPC_FILTERORDER * sizeof(float)); + memset(foutbuf, 0, LPC_FILTERORDER * sizeof(float)); + for (k = 0; k < LPC_FILTERORDER; k++) { + numerator[k] = syntDenum[LPC_FILTERORDER - k]; + } + numerator[LPC_FILTERORDER] = syntDenum[0]; + tmp = &tmpbuf[LPC_FILTERORDER]; + fout = &foutbuf[LPC_FILTERORDER]; + + /* decoding of the sample values */ + + for (k = 0; k < len; k++) { + tmpi = len - 1 - k; + /* maxVal = 1/scal */ + tmp[k] = maxVal * state_sq3Tbl[idxVec[tmpi]]; + } + + /* circular convolution with all-pass filter */ + + memset(tmp + len, 0, len * sizeof(float)); + ZeroPoleFilter(tmp, numerator, syntDenum, 2 * len, + LPC_FILTERORDER, fout); + for (k = 0; k < len; k++) { + out[k] = fout[len - 1 - k] + fout[2 * len - 1 - k]; + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/StateConstructW.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/StateConstructW.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,29 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + StateConstructW.h + + + + + + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_STATECONSTRUCTW_H +#define __iLBC_STATECONSTRUCTW_H + +void StateConstructW(int idxForMax, /* (i) 6-bit index for the quantization of + max amplitude */ + int *idxVec, /* (i) vector of quantization indexes */ + float *syntDenum, /* (i) synthesis filter denumerator */ + float *out, /* (o) the decoded state vector */ + int len /* (i) length of a state vector */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/StateSearchW.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/StateSearchW.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,195 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + StateSearchW.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "iLBC_define.h" +#include "constants.h" +#include "filter.h" +#include "helpfun.h" + + /*----------------------------------------------------------------* + * predictive noise shaping encoding of scaled start state + * (subrutine for StateSearchW) + *---------------------------------------------------------------*/ + +void AbsQuantW(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) Encoder instance */ + float *in, /* (i) vector to encode */ + float *syntDenum, /* (i) denominator of synthesis filter */ + float *weightDenum, /* (i) denominator of weighting filter */ + int *out, /* (o) vector of quantizer indexes */ + int len, /* (i) length of vector to encode and + vector of quantizer indexes */ + int state_first /* (i) position of start state in the + 80 vec */ + ) +{ + float *syntOut; + float syntOutBuf[LPC_FILTERORDER + STATE_SHORT_LEN_30MS]; + float toQ, xq; + int n; + int index; + + /* initialization of buffer for filtering */ + + memset(syntOutBuf, 0, LPC_FILTERORDER * sizeof(float)); + + + + + + + /* initialization of pointer for filtering */ + + syntOut = &syntOutBuf[LPC_FILTERORDER]; + + /* synthesis and weighting filters on input */ + + if (state_first) { + AllPoleFilter(in, weightDenum, SUBL, LPC_FILTERORDER); + } else { + AllPoleFilter(in, weightDenum, + iLBCenc_inst->state_short_len - SUBL, LPC_FILTERORDER); + } + + /* encoding loop */ + + for (n = 0; n < len; n++) { + + /* time update of filter coefficients */ + + if ((state_first) && (n == SUBL)) { + syntDenum += (LPC_FILTERORDER + 1); + weightDenum += (LPC_FILTERORDER + 1); + + /* synthesis and weighting filters on input */ + AllPoleFilter(&in[n], weightDenum, len - n, LPC_FILTERORDER); + + } else if ((state_first == 0) && + (n == (iLBCenc_inst->state_short_len - SUBL))) { + syntDenum += (LPC_FILTERORDER + 1); + weightDenum += (LPC_FILTERORDER + 1); + + /* synthesis and weighting filters on input */ + AllPoleFilter(&in[n], weightDenum, len - n, LPC_FILTERORDER); + + } + + /* prediction of synthesized and weighted input */ + + syntOut[n] = 0.0; + AllPoleFilter(&syntOut[n], weightDenum, 1, LPC_FILTERORDER); + + /* quantization */ + + toQ = in[n] - syntOut[n]; + + + + + + sort_sq(&xq, &index, toQ, state_sq3Tbl, 8); + out[n] = index; + syntOut[n] = state_sq3Tbl[out[n]]; + + /* update of the prediction filter */ + + AllPoleFilter(&syntOut[n], weightDenum, 1, LPC_FILTERORDER); + } +} + + /*----------------------------------------------------------------* + * encoding of start state + *---------------------------------------------------------------*/ + +void StateSearchW(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) Encoder instance */ + float *residual, /* (i) target residual vector */ + float *syntDenum, /* (i) lpc synthesis filter */ + float *weightDenum, /* (i) weighting filter denuminator */ + int *idxForMax, /* (o) quantizer index for maximum + amplitude */ + int *idxVec, /* (o) vector of quantization indexes */ + int len, /* (i) length of all vectors */ + int state_first /* (i) position of start state in the + 80 vec */ + ) +{ + float dtmp, maxVal; + float tmpbuf[LPC_FILTERORDER + 2 * STATE_SHORT_LEN_30MS]; + float *tmp, numerator[1 + LPC_FILTERORDER]; + float foutbuf[LPC_FILTERORDER + 2 * STATE_SHORT_LEN_30MS], *fout; + int k; + float qmax, scal; + + /* initialization of buffers and filter coefficients */ + + memset(tmpbuf, 0, LPC_FILTERORDER * sizeof(float)); + memset(foutbuf, 0, LPC_FILTERORDER * sizeof(float)); + for (k = 0; k < LPC_FILTERORDER; k++) { + numerator[k] = syntDenum[LPC_FILTERORDER - k]; + } + numerator[LPC_FILTERORDER] = syntDenum[0]; + tmp = &tmpbuf[LPC_FILTERORDER]; + fout = &foutbuf[LPC_FILTERORDER]; + + /* circular convolution with the all-pass filter */ + + + + + + + memcpy(tmp, residual, len * sizeof(float)); + memset(tmp + len, 0, len * sizeof(float)); + ZeroPoleFilter(tmp, numerator, syntDenum, 2 * len, + LPC_FILTERORDER, fout); + for (k = 0; k < len; k++) { + fout[k] += fout[k + len]; + } + + /* identification of the maximum amplitude value */ + + maxVal = fout[0]; + for (k = 1; k < len; k++) { + + if (fout[k] * fout[k] > maxVal * maxVal) { + maxVal = fout[k]; + } + } + maxVal = (float) fabs(maxVal); + + /* encoding of the maximum amplitude value */ + + if (maxVal < 10.0) { + maxVal = 10.0; + } + maxVal = (float) log10(maxVal); + sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64); + + /* decoding of the maximum amplitude representation value, + and corresponding scaling of start state */ + + maxVal = state_frgqTbl[*idxForMax]; + qmax = (float) pow(10, maxVal); + scal = (float) (4.5) / qmax; + for (k = 0; k < len; k++) { + fout[k] *= scal; + } + + /* predictive noise shaping encoding of scaled start state */ + + AbsQuantW(iLBCenc_inst, fout, syntDenum, + weightDenum, idxVec, len, state_first); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/StateSearchW.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/StateSearchW.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,42 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + StateSearchW.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_STATESEARCHW_H +#define __iLBC_STATESEARCHW_H + +void AbsQuantW(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) Encoder instance */ + float *in, /* (i) vector to encode */ + float *syntDenum, /* (i) denominator of synthesis filter */ + float *weightDenum, /* (i) denominator of weighting filter */ + int *out, /* (o) vector of quantizer indexes */ + int len, /* (i) length of vector to encode and + vector of quantizer indexes */ + int state_first /* (i) position of start state in the + 80 vec */ + ); + +void StateSearchW(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) Encoder instance */ + float *residual, /* (i) target residual vector */ + float *syntDenum, /* (i) lpc synthesis filter */ + float *weightDenum, /* (i) weighting filter denuminator */ + int *idxForMax, /* (o) quantizer index for maximum + amplitude */ + int *idxVec, /* (o) vector of quantization indexes */ + int len, /* (i) length of all vectors */ + int state_first /* (i) position of start state in the + 80 vec */ + ); + + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/anaFilter.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/anaFilter.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,71 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + anaFilter.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include "iLBC_define.h" + + /*----------------------------------------------------------------* + * LP analysis filter. + *---------------------------------------------------------------*/ + +void anaFilter(float *In, /* (i) Signal to be filtered */ + float *a, /* (i) LP parameters */ + int len, /* (i) Length of signal */ + float *Out, /* (o) Filtered signal */ + float *mem /* (i/o) Filter state */ + ) +{ + int i, j; + float *po, *pi, *pm, *pa; + + po = Out; + + /* Filter first part using memory from past */ + + for (i = 0; i < LPC_FILTERORDER; i++) { + pi = &In[i]; + pm = &mem[LPC_FILTERORDER - 1]; + pa = a; + *po = 0.0; + + + + + + for (j = 0; j <= i; j++) { + *po += (*pa++) * (*pi--); + } + for (j = i + 1; j < LPC_FILTERORDER + 1; j++) { + + *po += (*pa++) * (*pm--); + } + po++; + } + + /* Filter last part where the state is entirely + in the input vector */ + + for (i = LPC_FILTERORDER; i < len; i++) { + pi = &In[i]; + pa = a; + *po = 0.0; + for (j = 0; j < LPC_FILTERORDER + 1; j++) { + *po += (*pa++) * (*pi--); + } + po++; + } + + /* Update state vector */ + + memcpy(mem, &In[len - LPC_FILTERORDER], + LPC_FILTERORDER * sizeof(float)); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/anaFilter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/anaFilter.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,23 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + anaFilter.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_ANAFILTER_H +#define __iLBC_ANAFILTER_H + +void anaFilter(float *In, /* (i) Signal to be filtered */ + float *a, /* (i) LP parameters */ + int len, /* (i) Length of signal */ + float *Out, /* (o) Filtered signal */ + float *mem /* (i/o) Filter state */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/constants.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/constants.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,908 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + constants.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "iLBC_define.h" +#include "iLBC_define.h" + + /* ULP bit allocation */ + + /* 20 ms frame */ + +const iLBC_ULP_Inst_t ULP_20msTbl = { + /* LSF */ + {{6, 0, 0, 0, 0}, {7, 0, 0, 0, 0}, {7, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}, + /* Start state location, gain and samples */ + {2, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {6, 0, 0, 0, 0}, + {0, 1, 2, 0, 0}, + /* extra CB index and extra CB gain */ + {{6, 0, 1, 0, 0}, {0, 0, 7, 0, 0}, {0, 0, 7, 0, 0}}, + {{2, 0, 3, 0, 0}, {1, 1, 2, 0, 0}, {0, 0, 3, 0, 0}}, + /* CB index and CB gain */ + {{{7, 0, 1, 0, 0}, {0, 0, 7, 0, 0}, {0, 0, 7, 0, 0}}, + {{0, 0, 8, 0, 0}, {0, 0, 8, 0, 0}, {0, 0, 8, 0, 0}}, + {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}, + {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}}, + {{{1, 2, 2, 0, 0}, {1, 1, 2, 0, 0}, {0, 0, 3, 0, 0}}, + {{1, 1, 3, 0, 0}, {0, 2, 2, 0, 0}, {0, 0, 3, 0, 0}}, + {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}, + {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}} +}; + + /* 30 ms frame */ + +const iLBC_ULP_Inst_t ULP_30msTbl = { + /* LSF */ + + + + + + {{6, 0, 0, 0, 0}, {7, 0, 0, 0, 0}, {7, 0, 0, 0, 0}, + {6, 0, 0, 0, 0}, {7, 0, 0, 0, 0}, {7, 0, 0, 0, 0}}, + /* Start state location, gain and samples */ + {3, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {6, 0, 0, 0, 0}, + {0, 1, 2, 0, 0}, + /* extra CB index and extra CB gain */ + {{4, 2, 1, 0, 0}, {0, 0, 7, 0, 0}, {0, 0, 7, 0, 0}}, + {{1, 1, 3, 0, 0}, {1, 1, 2, 0, 0}, {0, 0, 3, 0, 0}}, + /* CB index and CB gain */ + {{{6, 1, 1, 0, 0}, {0, 0, 7, 0, 0}, {0, 0, 7, 0, 0}}, + {{0, 7, 1, 0, 0}, {0, 0, 8, 0, 0}, {0, 0, 8, 0, 0}}, + {{0, 7, 1, 0, 0}, {0, 0, 8, 0, 0}, {0, 0, 8, 0, 0}}, + {{0, 7, 1, 0, 0}, {0, 0, 8, 0, 0}, {0, 0, 8, 0, 0}}}, + {{{1, 2, 2, 0, 0}, {1, 2, 1, 0, 0}, {0, 0, 3, 0, 0}}, + {{0, 2, 3, 0, 0}, {0, 2, 2, 0, 0}, {0, 0, 3, 0, 0}}, + {{0, 1, 4, 0, 0}, {0, 1, 3, 0, 0}, {0, 0, 3, 0, 0}}, + {{0, 1, 4, 0, 0}, {0, 1, 3, 0, 0}, {0, 0, 3, 0, 0}}} +}; + + /* HP Filters */ + +float hpi_zero_coefsTbl[3] = { + (float) 0.92727436, (float) -1.8544941, (float) 0.92727436 +}; +float hpi_pole_coefsTbl[3] = { + (float) 1.0, (float) -1.9059465, (float) 0.9114024 +}; +float hpo_zero_coefsTbl[3] = { + (float) 0.93980581, (float) -1.8795834, (float) 0.93980581 +}; +float hpo_pole_coefsTbl[3] = { + (float) 1.0, (float) -1.9330735, (float) 0.93589199 +}; + + /* LP Filter */ + +float lpFilt_coefsTbl[FILTERORDER_DS] = { + (float) -0.066650, (float) 0.125000, (float) 0.316650, + (float) 0.414063, (float) 0.316650, + (float) 0.125000, (float) -0.066650 +}; + + /* State quantization tables */ + +float state_sq3Tbl[8] = { + (float) -3.719849, (float) -2.177490, (float) -1.130005, + + + + + + (float) -0.309692, (float) 0.444214, (float) 1.329712, + (float) 2.436279, (float) 3.983887 +}; + +float state_frgqTbl[64] = { + (float) 1.000085, (float) 1.071695, (float) 1.140395, + (float) 1.206868, (float) 1.277188, (float) 1.351503, + (float) 1.429380, (float) 1.500727, (float) 1.569049, + (float) 1.639599, (float) 1.707071, (float) 1.781531, + (float) 1.840799, (float) 1.901550, (float) 1.956695, + (float) 2.006750, (float) 2.055474, (float) 2.102787, + (float) 2.142819, (float) 2.183592, (float) 2.217962, + (float) 2.257177, (float) 2.295739, (float) 2.332967, + (float) 2.369248, (float) 2.402792, (float) 2.435080, + (float) 2.468598, (float) 2.503394, (float) 2.539284, + (float) 2.572944, (float) 2.605036, (float) 2.636331, + (float) 2.668939, (float) 2.698780, (float) 2.729101, + (float) 2.759786, (float) 2.789834, (float) 2.818679, + (float) 2.848074, (float) 2.877470, (float) 2.906899, + (float) 2.936655, (float) 2.967804, (float) 3.000115, + (float) 3.033367, (float) 3.066355, (float) 3.104231, + (float) 3.141499, (float) 3.183012, (float) 3.222952, + (float) 3.265433, (float) 3.308441, (float) 3.350823, + (float) 3.395275, (float) 3.442793, (float) 3.490801, + (float) 3.542514, (float) 3.604064, (float) 3.666050, + (float) 3.740994, (float) 3.830749, (float) 3.938770, + (float) 4.101764 +}; + + /* CB tables */ + +int search_rangeTbl[5][CB_NSTAGES] = { {58, 58, 58}, {108, 44, 44}, +{108, 108, 108}, {108, 108, 108}, {108, 108, 108} +}; +int stMemLTbl = 85; +int memLfTbl[NASUB_MAX] = { 147, 147, 147, 147 }; + + /* expansion filter(s) */ + +float cbfiltersTbl[CB_FILTERLEN] = { + (float) -0.034180, (float) 0.108887, (float) -0.184326, + (float) 0.806152, (float) 0.713379, (float) -0.144043, + (float) 0.083740, (float) -0.033691 +}; + + /* Gain Quantization */ + +float gain_sq3Tbl[8] = { + (float) -1.000000, (float) -0.659973, (float) -0.330017, + + + + + + (float) 0.000000, (float) 0.250000, (float) 0.500000, + (float) 0.750000, (float) 1.00000 +}; + +float gain_sq4Tbl[16] = { + (float) -1.049988, (float) -0.900024, (float) -0.750000, + (float) -0.599976, (float) -0.450012, (float) -0.299988, + (float) -0.150024, (float) 0.000000, (float) 0.150024, + (float) 0.299988, (float) 0.450012, (float) 0.599976, + (float) 0.750000, (float) 0.900024, (float) 1.049988, + (float) 1.200012 +}; + +float gain_sq5Tbl[32] = { + (float) 0.037476, (float) 0.075012, (float) 0.112488, + (float) 0.150024, (float) 0.187500, (float) 0.224976, + (float) 0.262512, (float) 0.299988, (float) 0.337524, + (float) 0.375000, (float) 0.412476, (float) 0.450012, + (float) 0.487488, (float) 0.525024, (float) 0.562500, + (float) 0.599976, (float) 0.637512, (float) 0.674988, + (float) 0.712524, (float) 0.750000, (float) 0.787476, + (float) 0.825012, (float) 0.862488, (float) 0.900024, + (float) 0.937500, (float) 0.974976, (float) 1.012512, + (float) 1.049988, (float) 1.087524, (float) 1.125000, + (float) 1.162476, (float) 1.200012 +}; + + /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */ +float polyphaserTbl[ENH_UPS0 * (2 * ENH_FL0 + 1)] = { + (float) 0.000000, (float) 0.000000, (float) 0.000000, + (float) 1.000000, + (float) 0.000000, (float) 0.000000, (float) 0.000000, + (float) 0.015625, (float) -0.076904, (float) 0.288330, + (float) 0.862061, + (float) -0.106445, (float) 0.018799, (float) -0.015625, + (float) 0.023682, (float) -0.124268, (float) 0.601563, + (float) 0.601563, + (float) -0.124268, (float) 0.023682, (float) -0.023682, + (float) 0.018799, (float) -0.106445, (float) 0.862061, + (float) 0.288330, + (float) -0.076904, (float) 0.015625, (float) -0.018799 +}; + +float enh_plocsTbl[ENH_NBLOCKS_TOT] = { (float) 40.0, (float) 120.0, + (float) 200.0, (float) 280.0, (float) 360.0, + (float) 440.0, (float) 520.0, (float) 600.0 +}; + + /* LPC analysis and quantization */ + +int dim_lsfCbTbl[LSF_NSPLIT] = { 3, 3, 4 }; +int size_lsfCbTbl[LSF_NSPLIT] = { 64, 128, 128 }; + + + + + + +float lsfmeanTbl[LPC_FILTERORDER] = { + (float) 0.281738, (float) 0.445801, (float) 0.663330, + (float) 0.962524, (float) 1.251831, (float) 1.533081, + (float) 1.850586, (float) 2.137817, (float) 2.481445, + (float) 2.777344 +}; + +float lsf_weightTbl_30ms[6] = { (float) (1.0 / 2.0), (float) 1.0, + (float) (2.0 / 3.0), + (float) (1.0 / 3.0), (float) 0.0, (float) 0.0 +}; + +float lsf_weightTbl_20ms[4] = + { (float) (3.0 / 4.0), (float) (2.0 / 4.0), + (float) (1.0 / 4.0), (float) (0.0) +}; + + /* Hanning LPC window */ +float lpc_winTbl[BLOCKL_MAX] = { + (float) 0.000183, (float) 0.000671, (float) 0.001526, + (float) 0.002716, (float) 0.004242, (float) 0.006104, + (float) 0.008301, (float) 0.010834, (float) 0.013702, + (float) 0.016907, (float) 0.020416, (float) 0.024261, + (float) 0.028442, (float) 0.032928, (float) 0.037750, + (float) 0.042877, (float) 0.048309, (float) 0.054047, + (float) 0.060089, (float) 0.066437, (float) 0.073090, + (float) 0.080017, (float) 0.087219, (float) 0.094727, + (float) 0.102509, (float) 0.110535, (float) 0.118835, + (float) 0.127411, (float) 0.136230, (float) 0.145294, + (float) 0.154602, (float) 0.164154, (float) 0.173920, + (float) 0.183899, (float) 0.194122, (float) 0.204529, + (float) 0.215149, (float) 0.225952, (float) 0.236938, + (float) 0.248108, (float) 0.259460, (float) 0.270966, + (float) 0.282654, (float) 0.294464, (float) 0.306396, + (float) 0.318481, (float) 0.330688, (float) 0.343018, + (float) 0.355438, (float) 0.367981, (float) 0.380585, + (float) 0.393280, (float) 0.406067, (float) 0.418884, + (float) 0.431763, (float) 0.444702, (float) 0.457672, + (float) 0.470673, (float) 0.483704, (float) 0.496735, + (float) 0.509766, (float) 0.522797, (float) 0.535828, + (float) 0.548798, (float) 0.561768, (float) 0.574677, + (float) 0.587524, (float) 0.600342, (float) 0.613068, + (float) 0.625732, (float) 0.638306, (float) 0.650787, + (float) 0.663147, (float) 0.675415, (float) 0.687561, + (float) 0.699585, (float) 0.711487, (float) 0.723206, + (float) 0.734802, (float) 0.746216, (float) 0.757477, + (float) 0.768585, (float) 0.779480, (float) 0.790192, + (float) 0.800720, (float) 0.811005, (float) 0.821106, + (float) 0.830994, (float) 0.840668, (float) 0.850067, + (float) 0.859253, (float) 0.868225, (float) 0.876892, + (float) 0.885345, (float) 0.893524, (float) 0.901428, + (float) 0.909058, (float) 0.916412, (float) 0.923492, + + + + + + (float) 0.930267, (float) 0.936768, (float) 0.942963, + (float) 0.948853, (float) 0.954437, (float) 0.959717, + (float) 0.964691, (float) 0.969360, (float) 0.973694, + (float) 0.977692, (float) 0.981384, (float) 0.984741, + (float) 0.987762, (float) 0.990479, (float) 0.992828, + (float) 0.994873, (float) 0.996552, (float) 0.997925, + (float) 0.998932, (float) 0.999603, (float) 0.999969, + (float) 0.999969, (float) 0.999603, (float) 0.998932, + (float) 0.997925, (float) 0.996552, (float) 0.994873, + (float) 0.992828, (float) 0.990479, (float) 0.987762, + (float) 0.984741, (float) 0.981384, (float) 0.977692, + (float) 0.973694, (float) 0.969360, (float) 0.964691, + (float) 0.959717, (float) 0.954437, (float) 0.948853, + (float) 0.942963, (float) 0.936768, (float) 0.930267, + (float) 0.923492, (float) 0.916412, (float) 0.909058, + (float) 0.901428, (float) 0.893524, (float) 0.885345, + (float) 0.876892, (float) 0.868225, (float) 0.859253, + (float) 0.850067, (float) 0.840668, (float) 0.830994, + (float) 0.821106, (float) 0.811005, (float) 0.800720, + (float) 0.790192, (float) 0.779480, (float) 0.768585, + (float) 0.757477, (float) 0.746216, (float) 0.734802, + (float) 0.723206, (float) 0.711487, (float) 0.699585, + (float) 0.687561, (float) 0.675415, (float) 0.663147, + (float) 0.650787, (float) 0.638306, (float) 0.625732, + (float) 0.613068, (float) 0.600342, (float) 0.587524, + (float) 0.574677, (float) 0.561768, (float) 0.548798, + (float) 0.535828, (float) 0.522797, (float) 0.509766, + (float) 0.496735, (float) 0.483704, (float) 0.470673, + (float) 0.457672, (float) 0.444702, (float) 0.431763, + (float) 0.418884, (float) 0.406067, (float) 0.393280, + (float) 0.380585, (float) 0.367981, (float) 0.355438, + (float) 0.343018, (float) 0.330688, (float) 0.318481, + (float) 0.306396, (float) 0.294464, (float) 0.282654, + (float) 0.270966, (float) 0.259460, (float) 0.248108, + (float) 0.236938, (float) 0.225952, (float) 0.215149, + (float) 0.204529, (float) 0.194122, (float) 0.183899, + (float) 0.173920, (float) 0.164154, (float) 0.154602, + (float) 0.145294, (float) 0.136230, (float) 0.127411, + (float) 0.118835, (float) 0.110535, (float) 0.102509, + (float) 0.094727, (float) 0.087219, (float) 0.080017, + (float) 0.073090, (float) 0.066437, (float) 0.060089, + (float) 0.054047, (float) 0.048309, (float) 0.042877, + (float) 0.037750, (float) 0.032928, (float) 0.028442, + (float) 0.024261, (float) 0.020416, (float) 0.016907, + (float) 0.013702, (float) 0.010834, (float) 0.008301, + (float) 0.006104, (float) 0.004242, (float) 0.002716, + (float) 0.001526, (float) 0.000671, (float) 0.000183 +}; + + + + + + /* Asymmetric LPC window */ +float lpc_asymwinTbl[BLOCKL_MAX] = { + (float) 0.000061, (float) 0.000214, (float) 0.000458, + (float) 0.000824, (float) 0.001282, (float) 0.001831, + (float) 0.002472, (float) 0.003235, (float) 0.004120, + (float) 0.005066, (float) 0.006134, (float) 0.007294, + (float) 0.008545, (float) 0.009918, (float) 0.011383, + (float) 0.012939, (float) 0.014587, (float) 0.016357, + (float) 0.018219, (float) 0.020172, (float) 0.022217, + (float) 0.024353, (float) 0.026611, (float) 0.028961, + (float) 0.031372, (float) 0.033905, (float) 0.036530, + (float) 0.039276, (float) 0.042084, (float) 0.044983, + (float) 0.047974, (float) 0.051086, (float) 0.054260, + (float) 0.057526, (float) 0.060883, (float) 0.064331, + (float) 0.067871, (float) 0.071503, (float) 0.075226, + (float) 0.079010, (float) 0.082916, (float) 0.086884, + (float) 0.090942, (float) 0.095062, (float) 0.099304, + (float) 0.103607, (float) 0.107971, (float) 0.112427, + (float) 0.116974, (float) 0.121582, (float) 0.126282, + (float) 0.131073, (float) 0.135895, (float) 0.140839, + (float) 0.145813, (float) 0.150879, (float) 0.156006, + (float) 0.161224, (float) 0.166504, (float) 0.171844, + (float) 0.177246, (float) 0.182709, (float) 0.188263, + (float) 0.193848, (float) 0.199524, (float) 0.205231, + (float) 0.211029, (float) 0.216858, (float) 0.222778, + (float) 0.228729, (float) 0.234741, (float) 0.240814, + (float) 0.246918, (float) 0.253082, (float) 0.259308, + (float) 0.265564, (float) 0.271881, (float) 0.278259, + (float) 0.284668, (float) 0.291107, (float) 0.297607, + (float) 0.304138, (float) 0.310730, (float) 0.317322, + (float) 0.323975, (float) 0.330658, (float) 0.337372, + (float) 0.344147, (float) 0.350922, (float) 0.357727, + (float) 0.364594, (float) 0.371460, (float) 0.378357, + (float) 0.385284, (float) 0.392212, (float) 0.399170, + (float) 0.406158, (float) 0.413177, (float) 0.420197, + (float) 0.427246, (float) 0.434296, (float) 0.441376, + (float) 0.448456, (float) 0.455536, (float) 0.462646, + (float) 0.469757, (float) 0.476868, (float) 0.483978, + (float) 0.491089, (float) 0.498230, (float) 0.505341, + (float) 0.512451, (float) 0.519592, (float) 0.526703, + (float) 0.533813, (float) 0.540924, (float) 0.548004, + (float) 0.555084, (float) 0.562164, (float) 0.569244, + (float) 0.576294, (float) 0.583313, (float) 0.590332, + (float) 0.597321, (float) 0.604309, (float) 0.611267, + (float) 0.618195, (float) 0.625092, (float) 0.631989, + (float) 0.638855, (float) 0.645660, (float) 0.652466, + (float) 0.659241, (float) 0.665985, (float) 0.672668, + (float) 0.679352, (float) 0.685974, (float) 0.692566, + + + + + + (float) 0.699127, (float) 0.705658, (float) 0.712128, + (float) 0.718536, (float) 0.724945, (float) 0.731262, + (float) 0.737549, (float) 0.743805, (float) 0.750000, + (float) 0.756134, (float) 0.762238, (float) 0.768280, + (float) 0.774261, (float) 0.780182, (float) 0.786072, + (float) 0.791870, (float) 0.797638, (float) 0.803314, + (float) 0.808960, (float) 0.814514, (float) 0.820038, + (float) 0.825470, (float) 0.830841, (float) 0.836151, + (float) 0.841400, (float) 0.846558, (float) 0.851654, + (float) 0.856689, (float) 0.861633, (float) 0.866516, + (float) 0.871338, (float) 0.876068, (float) 0.880737, + (float) 0.885315, (float) 0.889801, (float) 0.894226, + (float) 0.898560, (float) 0.902832, (float) 0.907013, + (float) 0.911102, (float) 0.915100, (float) 0.919037, + (float) 0.922882, (float) 0.926636, (float) 0.930328, + (float) 0.933899, (float) 0.937408, (float) 0.940796, + (float) 0.944122, (float) 0.947357, (float) 0.950470, + (float) 0.953522, (float) 0.956482, (float) 0.959351, + (float) 0.962097, (float) 0.964783, (float) 0.967377, + (float) 0.969849, (float) 0.972229, (float) 0.974518, + (float) 0.976715, (float) 0.978821, (float) 0.980835, + (float) 0.982727, (float) 0.984528, (float) 0.986237, + (float) 0.987854, (float) 0.989380, (float) 0.990784, + (float) 0.992096, (float) 0.993317, (float) 0.994415, + (float) 0.995422, (float) 0.996338, (float) 0.997162, + (float) 0.997864, (float) 0.998474, (float) 0.998962, + (float) 0.999390, (float) 0.999695, (float) 0.999878, + (float) 0.999969, (float) 0.999969, (float) 0.996918, + (float) 0.987701, (float) 0.972382, (float) 0.951050, + (float) 0.923889, (float) 0.891022, (float) 0.852631, + (float) 0.809021, (float) 0.760406, (float) 0.707092, + (float) 0.649445, (float) 0.587799, (float) 0.522491, + (float) 0.453979, (float) 0.382690, (float) 0.309021, + (float) 0.233459, (float) 0.156433, (float) 0.078461 +}; + + /* Lag window for LPC */ +float lpc_lagwinTbl[LPC_FILTERORDER + 1] = { + (float) 1.000100, (float) 0.998890, (float) 0.995569, + (float) 0.990057, (float) 0.982392, + (float) 0.972623, (float) 0.960816, (float) 0.947047, + (float) 0.931405, (float) 0.913989, (float) 0.894909 +}; + + /* LSF quantization */ +float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = { + (float) 0.155396, (float) 0.273193, (float) 0.451172, + (float) 0.390503, (float) 0.648071, (float) 1.002075, + (float) 0.440186, (float) 0.692261, (float) 0.955688, + + + + + + (float) 0.343628, (float) 0.642334, (float) 1.071533, + (float) 0.318359, (float) 0.491577, (float) 0.670532, + (float) 0.193115, (float) 0.375488, (float) 0.725708, + (float) 0.364136, (float) 0.510376, (float) 0.658691, + (float) 0.297485, (float) 0.527588, (float) 0.842529, + (float) 0.227173, (float) 0.365967, (float) 0.563110, + (float) 0.244995, (float) 0.396729, (float) 0.636475, + (float) 0.169434, (float) 0.300171, (float) 0.520264, + (float) 0.312866, (float) 0.464478, (float) 0.643188, + (float) 0.248535, (float) 0.429932, (float) 0.626099, + (float) 0.236206, (float) 0.491333, (float) 0.817139, + (float) 0.334961, (float) 0.625122, (float) 0.895752, + (float) 0.343018, (float) 0.518555, (float) 0.698608, + (float) 0.372803, (float) 0.659790, (float) 0.945435, + (float) 0.176880, (float) 0.316528, (float) 0.581421, + (float) 0.416382, (float) 0.625977, (float) 0.805176, + (float) 0.303223, (float) 0.568726, (float) 0.915039, + (float) 0.203613, (float) 0.351440, (float) 0.588135, + (float) 0.221191, (float) 0.375000, (float) 0.614746, + (float) 0.199951, (float) 0.323364, (float) 0.476074, + (float) 0.300781, (float) 0.433350, (float) 0.566895, + (float) 0.226196, (float) 0.354004, (float) 0.507568, + (float) 0.300049, (float) 0.508179, (float) 0.711670, + (float) 0.312012, (float) 0.492676, (float) 0.763428, + (float) 0.329956, (float) 0.541016, (float) 0.795776, + (float) 0.373779, (float) 0.604614, (float) 0.928833, + (float) 0.210571, (float) 0.452026, (float) 0.755249, + (float) 0.271118, (float) 0.473267, (float) 0.662476, + (float) 0.285522, (float) 0.436890, (float) 0.634399, + (float) 0.246704, (float) 0.565552, (float) 0.859009, + (float) 0.270508, (float) 0.406250, (float) 0.553589, + (float) 0.361450, (float) 0.578491, (float) 0.813843, + (float) 0.342651, (float) 0.482788, (float) 0.622437, + (float) 0.340332, (float) 0.549438, (float) 0.743164, + (float) 0.200439, (float) 0.336304, (float) 0.540894, + (float) 0.407837, (float) 0.644775, (float) 0.895142, + (float) 0.294678, (float) 0.454834, (float) 0.699097, + (float) 0.193115, (float) 0.344482, (float) 0.643188, + (float) 0.275757, (float) 0.420776, (float) 0.598755, + (float) 0.380493, (float) 0.608643, (float) 0.861084, + (float) 0.222778, (float) 0.426147, (float) 0.676514, + (float) 0.407471, (float) 0.700195, (float) 1.053101, + (float) 0.218384, (float) 0.377197, (float) 0.669922, + (float) 0.313232, (float) 0.454102, (float) 0.600952, + (float) 0.347412, (float) 0.571533, (float) 0.874146, + (float) 0.238037, (float) 0.405396, (float) 0.729492, + (float) 0.223877, (float) 0.412964, (float) 0.822021, + (float) 0.395264, (float) 0.582153, (float) 0.743896, + + + + + + (float) 0.247925, (float) 0.485596, (float) 0.720581, + (float) 0.229126, (float) 0.496582, (float) 0.907715, + (float) 0.260132, (float) 0.566895, (float) 1.012695, + (float) 0.337402, (float) 0.611572, (float) 0.978149, + (float) 0.267822, (float) 0.447632, (float) 0.769287, + (float) 0.250610, (float) 0.381714, (float) 0.530029, + (float) 0.430054, (float) 0.805054, (float) 1.221924, + (float) 0.382568, (float) 0.544067, (float) 0.701660, + (float) 0.383545, (float) 0.710327, (float) 1.149170, + (float) 0.271362, (float) 0.529053, (float) 0.775513, + (float) 0.246826, (float) 0.393555, (float) 0.588623, + (float) 0.266846, (float) 0.422119, (float) 0.676758, + (float) 0.311523, (float) 0.580688, (float) 0.838623, + (float) 1.331177, (float) 1.576782, (float) 1.779541, + (float) 1.160034, (float) 1.401978, (float) 1.768188, + (float) 1.161865, (float) 1.525146, (float) 1.715332, + (float) 0.759521, (float) 0.913940, (float) 1.119873, + (float) 0.947144, (float) 1.121338, (float) 1.282471, + (float) 1.015015, (float) 1.557007, (float) 1.804932, + (float) 1.172974, (float) 1.402100, (float) 1.692627, + (float) 1.087524, (float) 1.474243, (float) 1.665405, + (float) 0.899536, (float) 1.105225, (float) 1.406250, + (float) 1.148438, (float) 1.484741, (float) 1.796265, + (float) 0.785645, (float) 1.209839, (float) 1.567749, + (float) 0.867798, (float) 1.166504, (float) 1.450684, + (float) 0.922485, (float) 1.229858, (float) 1.420898, + (float) 0.791260, (float) 1.123291, (float) 1.409546, + (float) 0.788940, (float) 0.966064, (float) 1.340332, + (float) 1.051147, (float) 1.272827, (float) 1.556641, + (float) 0.866821, (float) 1.181152, (float) 1.538818, + (float) 0.906738, (float) 1.373535, (float) 1.607910, + (float) 1.244751, (float) 1.581421, (float) 1.933838, + (float) 0.913940, (float) 1.337280, (float) 1.539673, + (float) 0.680542, (float) 0.959229, (float) 1.662720, + (float) 0.887207, (float) 1.430542, (float) 1.800781, + (float) 0.912598, (float) 1.433594, (float) 1.683960, + (float) 0.860474, (float) 1.060303, (float) 1.455322, + (float) 1.005127, (float) 1.381104, (float) 1.706909, + (float) 0.800781, (float) 1.363892, (float) 1.829102, + (float) 0.781860, (float) 1.124390, (float) 1.505981, + (float) 1.003662, (float) 1.471436, (float) 1.684692, + (float) 0.981323, (float) 1.309570, (float) 1.618042, + (float) 1.228760, (float) 1.554321, (float) 1.756470, + (float) 0.734375, (float) 0.895752, (float) 1.225586, + (float) 0.841797, (float) 1.055664, (float) 1.249268, + (float) 0.920166, (float) 1.119385, (float) 1.486206, + (float) 0.894409, (float) 1.539063, (float) 1.828979, + (float) 1.283691, (float) 1.543335, (float) 1.858276, + + + + + + (float) 0.676025, (float) 0.933105, (float) 1.490845, + (float) 0.821289, (float) 1.491821, (float) 1.739868, + (float) 0.923218, (float) 1.144653, (float) 1.580566, + (float) 1.057251, (float) 1.345581, (float) 1.635864, + (float) 0.888672, (float) 1.074951, (float) 1.353149, + (float) 0.942749, (float) 1.195435, (float) 1.505493, + (float) 1.492310, (float) 1.788086, (float) 2.039673, + (float) 1.070313, (float) 1.634399, (float) 1.860962, + (float) 1.253296, (float) 1.488892, (float) 1.686035, + (float) 0.647095, (float) 0.864014, (float) 1.401855, + (float) 0.866699, (float) 1.254883, (float) 1.453369, + (float) 1.063965, (float) 1.532593, (float) 1.731323, + (float) 1.167847, (float) 1.521484, (float) 1.884033, + (float) 0.956055, (float) 1.502075, (float) 1.745605, + (float) 0.928711, (float) 1.288574, (float) 1.479614, + (float) 1.088013, (float) 1.380737, (float) 1.570801, + (float) 0.905029, (float) 1.186768, (float) 1.371948, + (float) 1.057861, (float) 1.421021, (float) 1.617432, + (float) 1.108276, (float) 1.312500, (float) 1.501465, + (float) 0.979492, (float) 1.416992, (float) 1.624268, + (float) 1.276001, (float) 1.661011, (float) 2.007935, + (float) 0.993042, (float) 1.168579, (float) 1.331665, + (float) 0.778198, (float) 0.944946, (float) 1.235962, + (float) 1.223755, (float) 1.491333, (float) 1.815674, + (float) 0.852661, (float) 1.350464, (float) 1.722290, + (float) 1.134766, (float) 1.593140, (float) 1.787354, + (float) 1.051392, (float) 1.339722, (float) 1.531006, + (float) 0.803589, (float) 1.271240, (float) 1.652100, + (float) 0.755737, (float) 1.143555, (float) 1.639404, + (float) 0.700928, (float) 0.837280, (float) 1.130371, + (float) 0.942749, (float) 1.197876, (float) 1.669800, + (float) 0.993286, (float) 1.378296, (float) 1.566528, + (float) 0.801025, (float) 1.095337, (float) 1.298950, + (float) 0.739990, (float) 1.032959, (float) 1.383667, + (float) 0.845703, (float) 1.072266, (float) 1.543823, + (float) 0.915649, (float) 1.072266, (float) 1.224487, + (float) 1.021973, (float) 1.226196, (float) 1.481323, + (float) 0.999878, (float) 1.204102, (float) 1.555908, + (float) 0.722290, (float) 0.913940, (float) 1.340210, + (float) 0.673340, (float) 0.835938, (float) 1.259521, + (float) 0.832397, (float) 1.208374, (float) 1.394165, + (float) 0.962158, (float) 1.576172, (float) 1.912842, + (float) 1.166748, (float) 1.370850, (float) 1.556763, + (float) 0.946289, (float) 1.138550, (float) 1.400391, + (float) 1.035034, (float) 1.218262, (float) 1.386475, + (float) 1.393799, (float) 1.717773, (float) 2.000244, + (float) 0.972656, (float) 1.260986, (float) 1.760620, + (float) 1.028198, (float) 1.288452, (float) 1.484619, + + + + + + (float) 0.773560, (float) 1.258057, (float) 1.756714, + (float) 1.080322, (float) 1.328003, (float) 1.742676, + (float) 0.823975, (float) 1.450806, (float) 1.917725, + (float) 0.859009, (float) 1.016602, (float) 1.191895, + (float) 0.843994, (float) 1.131104, (float) 1.645020, + (float) 1.189697, (float) 1.702759, (float) 1.894409, + (float) 1.346680, (float) 1.763184, (float) 2.066040, + (float) 0.980469, (float) 1.253784, (float) 1.441650, + (float) 1.338135, (float) 1.641968, (float) 1.932739, + (float) 1.223267, (float) 1.424194, (float) 1.626465, + (float) 0.765747, (float) 1.004150, (float) 1.579102, + (float) 1.042847, (float) 1.269165, (float) 1.647461, + (float) 0.968750, (float) 1.257568, (float) 1.555786, + (float) 0.826294, (float) 0.993408, (float) 1.275146, + (float) 0.742310, (float) 0.950439, (float) 1.430542, + (float) 1.054321, (float) 1.439819, (float) 1.828003, + (float) 1.072998, (float) 1.261719, (float) 1.441895, + (float) 0.859375, (float) 1.036377, (float) 1.314819, + (float) 0.895752, (float) 1.267212, (float) 1.605591, + (float) 0.805420, (float) 0.962891, (float) 1.142334, + (float) 0.795654, (float) 1.005493, (float) 1.468506, + (float) 1.105347, (float) 1.313843, (float) 1.584839, + (float) 0.792236, (float) 1.221802, (float) 1.465698, + (float) 1.170532, (float) 1.467651, (float) 1.664063, + (float) 0.838257, (float) 1.153198, (float) 1.342163, + (float) 0.968018, (float) 1.198242, (float) 1.391235, + (float) 1.250122, (float) 1.623535, (float) 1.823608, + (float) 0.711670, (float) 1.058350, (float) 1.512085, + (float) 1.204834, (float) 1.454468, (float) 1.739136, + (float) 1.137451, (float) 1.421753, (float) 1.620117, + (float) 0.820435, (float) 1.322754, (float) 1.578247, + (float) 0.798706, (float) 1.005005, (float) 1.213867, + (float) 0.980713, (float) 1.324951, (float) 1.512939, + (float) 1.112305, (float) 1.438843, (float) 1.735596, + (float) 1.135498, (float) 1.356689, (float) 1.635742, + (float) 1.101318, (float) 1.387451, (float) 1.686523, + (float) 0.849854, (float) 1.276978, (float) 1.523438, + (float) 1.377930, (float) 1.627563, (float) 1.858154, + (float) 0.884888, (float) 1.095459, (float) 1.287476, + (float) 1.289795, (float) 1.505859, (float) 1.756592, + (float) 0.817505, (float) 1.384155, (float) 1.650513, + (float) 1.446655, (float) 1.702148, (float) 1.931885, + (float) 0.835815, (float) 1.023071, (float) 1.385376, + (float) 0.916626, (float) 1.139038, (float) 1.335327, + (float) 0.980103, (float) 1.174072, (float) 1.453735, + (float) 1.705688, (float) 2.153809, (float) 2.398315, + (float) 2.743408, + (float) 1.797119, (float) 2.016846, (float) 2.445679, + (float) 2.701904, + (float) 1.990356, (float) 2.219116, (float) 2.576416, + (float) 2.813477, + + + + + + (float) 1.849365, (float) 2.190918, (float) 2.611572, + (float) 2.835083, + (float) 1.657959, (float) 1.854370, (float) 2.159058, + (float) 2.726196, + (float) 1.437744, (float) 1.897705, (float) 2.253174, + (float) 2.655396, + (float) 2.028687, (float) 2.247314, (float) 2.542358, + (float) 2.875854, + (float) 1.736938, (float) 1.922119, (float) 2.185913, + (float) 2.743408, + (float) 1.521606, (float) 1.870972, (float) 2.526855, + (float) 2.786987, + (float) 1.841431, (float) 2.050659, (float) 2.463623, + (float) 2.857666, + (float) 1.590088, (float) 2.067261, (float) 2.427979, + (float) 2.794434, + (float) 1.746826, (float) 2.057373, (float) 2.320190, + (float) 2.800781, + (float) 1.734619, (float) 1.940552, (float) 2.306030, + (float) 2.826416, + (float) 1.786255, (float) 2.204468, (float) 2.457520, + (float) 2.795288, + (float) 1.861084, (float) 2.170532, (float) 2.414551, + (float) 2.763672, + (float) 2.001465, (float) 2.307617, (float) 2.552734, + (float) 2.811890, + (float) 1.784424, (float) 2.124146, (float) 2.381592, + (float) 2.645508, + (float) 1.888794, (float) 2.135864, (float) 2.418579, + (float) 2.861206, + (float) 2.301147, (float) 2.531250, (float) 2.724976, + (float) 2.913086, + (float) 1.837769, (float) 2.051270, (float) 2.261963, + (float) 2.553223, + (float) 2.012939, (float) 2.221191, (float) 2.440186, + (float) 2.678101, + (float) 1.429565, (float) 1.858276, (float) 2.582275, + (float) 2.845703, + (float) 1.622803, (float) 1.897705, (float) 2.367310, + (float) 2.621094, + (float) 1.581543, (float) 1.960449, (float) 2.515869, + (float) 2.736450, + (float) 1.419434, (float) 1.933960, (float) 2.394653, + (float) 2.746704, + (float) 1.721924, (float) 2.059570, (float) 2.421753, + (float) 2.769653, + (float) 1.911011, (float) 2.220703, (float) 2.461060, + (float) 2.740723, + (float) 1.581177, (float) 1.860840, (float) 2.516968, + (float) 2.874634, + (float) 1.870361, (float) 2.098755, (float) 2.432373, + (float) 2.656494, + (float) 2.059692, (float) 2.279785, (float) 2.495605, + (float) 2.729370, + (float) 1.815674, (float) 2.181519, (float) 2.451538, + (float) 2.680542, + (float) 1.407959, (float) 1.768311, (float) 2.343018, + (float) 2.668091, + (float) 2.168701, (float) 2.394653, (float) 2.604736, + (float) 2.829346, + (float) 1.636230, (float) 1.865723, (float) 2.329102, + (float) 2.824219, + (float) 1.878906, (float) 2.139526, (float) 2.376709, + (float) 2.679810, + (float) 1.765381, (float) 1.971802, (float) 2.195435, + (float) 2.586914, + (float) 2.164795, (float) 2.410889, (float) 2.673706, + (float) 2.903198, + (float) 2.071899, (float) 2.331055, (float) 2.645874, + (float) 2.907104, + (float) 2.026001, (float) 2.311523, (float) 2.594849, + (float) 2.863892, + (float) 1.948975, (float) 2.180786, (float) 2.514893, + (float) 2.797852, + (float) 1.881836, (float) 2.130859, (float) 2.478149, + (float) 2.804199, + (float) 2.238159, (float) 2.452759, (float) 2.652832, + (float) 2.868286, + (float) 1.897949, (float) 2.101685, (float) 2.524292, + (float) 2.880127, + (float) 1.856445, (float) 2.074585, (float) 2.541016, + (float) 2.791748, + (float) 1.695557, (float) 2.199097, (float) 2.506226, + (float) 2.742676, + (float) 1.612671, (float) 1.877075, (float) 2.435425, + (float) 2.732910, + (float) 1.568848, (float) 1.786499, (float) 2.194580, + (float) 2.768555, + (float) 1.953369, (float) 2.164551, (float) 2.486938, + (float) 2.874023, + (float) 1.388306, (float) 1.725342, (float) 2.384521, + (float) 2.771851, + (float) 2.115356, (float) 2.337769, (float) 2.592896, + (float) 2.864014, + (float) 1.905762, (float) 2.111328, (float) 2.363525, + (float) 2.789307, + + + + + + (float) 1.882568, (float) 2.332031, (float) 2.598267, + (float) 2.827637, + (float) 1.683594, (float) 2.088745, (float) 2.361938, + (float) 2.608643, + (float) 1.874023, (float) 2.182129, (float) 2.536133, + (float) 2.766968, + (float) 1.861938, (float) 2.070435, (float) 2.309692, + (float) 2.700562, + (float) 1.722168, (float) 2.107422, (float) 2.477295, + (float) 2.837646, + (float) 1.926880, (float) 2.184692, (float) 2.442627, + (float) 2.663818, + (float) 2.123901, (float) 2.337280, (float) 2.553101, + (float) 2.777466, + (float) 1.588135, (float) 1.911499, (float) 2.212769, + (float) 2.543945, + (float) 2.053955, (float) 2.370850, (float) 2.712158, + (float) 2.939941, + (float) 2.210449, (float) 2.519653, (float) 2.770386, + (float) 2.958618, + (float) 2.199463, (float) 2.474731, (float) 2.718262, + (float) 2.919922, + (float) 1.960083, (float) 2.175415, (float) 2.608032, + (float) 2.888794, + (float) 1.953735, (float) 2.185181, (float) 2.428223, + (float) 2.809570, + (float) 1.615234, (float) 2.036499, (float) 2.576538, + (float) 2.834595, + (float) 1.621094, (float) 2.028198, (float) 2.431030, + (float) 2.664673, + (float) 1.824951, (float) 2.267456, (float) 2.514526, + (float) 2.747925, + (float) 1.994263, (float) 2.229126, (float) 2.475220, + (float) 2.833984, + (float) 1.746338, (float) 2.011353, (float) 2.588257, + (float) 2.826904, + (float) 1.562866, (float) 2.135986, (float) 2.471680, + (float) 2.687256, + (float) 1.748901, (float) 2.083496, (float) 2.460938, + (float) 2.686279, + (float) 1.758057, (float) 2.131470, (float) 2.636597, + (float) 2.891602, + (float) 2.071289, (float) 2.299072, (float) 2.550781, + (float) 2.814331, + (float) 1.839600, (float) 2.094360, (float) 2.496460, + (float) 2.723999, + (float) 1.882202, (float) 2.088257, (float) 2.636841, + (float) 2.923096, + (float) 1.957886, (float) 2.153198, (float) 2.384399, + (float) 2.615234, + (float) 1.992920, (float) 2.351196, (float) 2.654419, + (float) 2.889771, + (float) 2.012817, (float) 2.262451, (float) 2.643799, + (float) 2.903076, + (float) 2.025635, (float) 2.254761, (float) 2.508423, + (float) 2.784058, + (float) 2.316040, (float) 2.589355, (float) 2.794189, + (float) 2.963623, + (float) 1.741211, (float) 2.279541, (float) 2.578491, + (float) 2.816284, + (float) 1.845337, (float) 2.055786, (float) 2.348511, + (float) 2.822021, + (float) 1.679932, (float) 1.926514, (float) 2.499756, + (float) 2.835693, + (float) 1.722534, (float) 1.946899, (float) 2.448486, + (float) 2.728760, + (float) 1.829834, (float) 2.043213, (float) 2.580444, + (float) 2.867676, + (float) 1.676636, (float) 2.071655, (float) 2.322510, + (float) 2.704834, + (float) 1.791504, (float) 2.113525, (float) 2.469727, + (float) 2.784058, + (float) 1.977051, (float) 2.215088, (float) 2.497437, + (float) 2.726929, + (float) 1.800171, (float) 2.106689, (float) 2.357788, + (float) 2.738892, + (float) 1.827759, (float) 2.170166, (float) 2.525879, + (float) 2.852417, + (float) 1.918335, (float) 2.132813, (float) 2.488403, + (float) 2.728149, + (float) 1.916748, (float) 2.225098, (float) 2.542603, + (float) 2.857666, + (float) 1.761230, (float) 1.976074, (float) 2.507446, + (float) 2.884521, + (float) 2.053711, (float) 2.367432, (float) 2.608032, + (float) 2.837646, + (float) 1.595337, (float) 2.000977, (float) 2.307129, + (float) 2.578247, + (float) 1.470581, (float) 2.031250, (float) 2.375854, + (float) 2.647583, + (float) 1.801392, (float) 2.128052, (float) 2.399780, + (float) 2.822876, + (float) 1.853638, (float) 2.066650, (float) 2.429199, + (float) 2.751465, + (float) 1.956299, (float) 2.163696, (float) 2.394775, + (float) 2.734253, + + + + + + (float) 1.963623, (float) 2.275757, (float) 2.585327, + (float) 2.865234, + (float) 1.887451, (float) 2.105469, (float) 2.331787, + (float) 2.587402, + (float) 2.120117, (float) 2.443359, (float) 2.733887, + (float) 2.941406, + (float) 1.506348, (float) 1.766968, (float) 2.400513, + (float) 2.851807, + (float) 1.664551, (float) 1.981079, (float) 2.375732, + (float) 2.774414, + (float) 1.720703, (float) 1.978882, (float) 2.391479, + (float) 2.640991, + (float) 1.483398, (float) 1.814819, (float) 2.434448, + (float) 2.722290, + (float) 1.769043, (float) 2.136597, (float) 2.563721, + (float) 2.774414, + (float) 1.810791, (float) 2.049316, (float) 2.373901, + (float) 2.613647, + (float) 1.788330, (float) 2.005981, (float) 2.359131, + (float) 2.723145, + (float) 1.785156, (float) 1.993164, (float) 2.399780, + (float) 2.832520, + (float) 1.695313, (float) 2.022949, (float) 2.522583, + (float) 2.745117, + (float) 1.584106, (float) 1.965576, (float) 2.299927, + (float) 2.715576, + (float) 1.894897, (float) 2.249878, (float) 2.655884, + (float) 2.897705, + (float) 1.720581, (float) 1.995728, (float) 2.299438, + (float) 2.557007, + (float) 1.619385, (float) 2.173950, (float) 2.574219, + (float) 2.787964, + (float) 1.883179, (float) 2.220459, (float) 2.474365, + (float) 2.825073, + (float) 1.447632, (float) 2.045044, (float) 2.555542, + (float) 2.744873, + (float) 1.502686, (float) 2.156616, (float) 2.653320, + (float) 2.846558, + (float) 1.711548, (float) 1.944092, (float) 2.282959, + (float) 2.685791, + (float) 1.499756, (float) 1.867554, (float) 2.341064, + (float) 2.578857, + (float) 1.916870, (float) 2.135132, (float) 2.568237, + (float) 2.826050, + (float) 1.498047, (float) 1.711182, (float) 2.223267, + (float) 2.755127, + (float) 1.808716, (float) 1.997559, (float) 2.256470, + (float) 2.758545, + (float) 2.088501, (float) 2.402710, (float) 2.667358, + (float) 2.890259, + (float) 1.545044, (float) 1.819214, (float) 2.324097, + (float) 2.692993, + (float) 1.796021, (float) 2.012573, (float) 2.505737, + (float) 2.784912, + (float) 1.786499, (float) 2.041748, (float) 2.290405, + (float) 2.650757, + (float) 1.938232, (float) 2.264404, (float) 2.529053, (float) 2.796143 +}; diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/constants.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/constants.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,79 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + constants.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_CONSTANTS_H +#define __iLBC_CONSTANTS_H + +#include "iLBC_define.h" + + + /* ULP bit allocation */ + + + + + + +extern const iLBC_ULP_Inst_t ULP_20msTbl; +extern const iLBC_ULP_Inst_t ULP_30msTbl; + + /* high pass filters */ + +extern float hpi_zero_coefsTbl[]; +extern float hpi_pole_coefsTbl[]; +extern float hpo_zero_coefsTbl[]; +extern float hpo_pole_coefsTbl[]; + + /* low pass filters */ +extern float lpFilt_coefsTbl[]; + + /* LPC analysis and quantization */ + +extern float lpc_winTbl[]; +extern float lpc_asymwinTbl[]; +extern float lpc_lagwinTbl[]; +extern float lsfCbTbl[]; +extern float lsfmeanTbl[]; +extern int dim_lsfCbTbl[]; +extern int size_lsfCbTbl[]; +extern float lsf_weightTbl_30ms[]; +extern float lsf_weightTbl_20ms[]; + + /* state quantization tables */ + +extern float state_sq3Tbl[]; +extern float state_frgqTbl[]; + + /* gain quantization tables */ + +extern float gain_sq3Tbl[]; +extern float gain_sq4Tbl[]; +extern float gain_sq5Tbl[]; + + /* adaptive codebook definitions */ + +extern int search_rangeTbl[5][CB_NSTAGES]; +extern int memLfTbl[]; +extern int stMemLTbl; +extern float cbfiltersTbl[CB_FILTERLEN]; + + /* enhancer definitions */ + +extern float polyphaserTbl[]; +extern float enh_plocsTbl[]; + + + + + + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/createCB.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/createCB.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,229 @@ + + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + createCB.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + + + + + +#include "iLBC_define.h" +#include "constants.h" +#include +#include + + /*----------------------------------------------------------------* + * Construct an additional codebook vector by filtering the + * initial codebook buffer. This vector is then used to expand + * the codebook with an additional section. + *---------------------------------------------------------------*/ + +void filteredCBvecs(float *cbvectors, /* (o) Codebook vectors for the + higher section */ + float *mem, /* (i) Buffer to create codebook + vector from */ + int lMem /* (i) Length of buffer */ + ) +{ + int j, k; + float *pp, *pp1; + float tempbuff2[CB_MEML + CB_FILTERLEN]; + float *pos; + + memset(tempbuff2, 0, (CB_HALFFILTERLEN - 1) * sizeof(float)); + memcpy(&tempbuff2[CB_HALFFILTERLEN - 1], mem, lMem * sizeof(float)); + memset(&tempbuff2[lMem + CB_HALFFILTERLEN - 1], 0, + (CB_HALFFILTERLEN + 1) * sizeof(float)); + + /* Create codebook vector for higher section by filtering */ + + /* do filtering */ + pos = cbvectors; + memset(pos, 0, lMem * sizeof(float)); + for (k = 0; k < lMem; k++) { + pp = &tempbuff2[k]; + pp1 = &cbfiltersTbl[CB_FILTERLEN - 1]; + for (j = 0; j < CB_FILTERLEN; j++) { + (*pos) += (*pp++) * (*pp1--); + } + pos++; + } +} + + /*----------------------------------------------------------------* + * Search the augmented part of the codebook to find the best + * measure. + *----------------------------------------------------------------*/ + + + + + + +void searchAugmentedCB(int low, /* (i) Start index for the search */ + int high, /* (i) End index for the search */ + int stage, /* (i) Current stage */ + int startIndex, /* (i) Codebook index for the first + aug vector */ + float *target, /* (i) Target vector for encoding */ + float *buffer, /* (i) Pointer to the end of the buffer for + augmented codebook construction */ + float *max_measure, /* (i/o) Currently maximum measure */ + int *best_index, /* (o) Currently the best index */ + float *gain, /* (o) Currently the best gain */ + float *energy, /* (o) Energy of augmented codebook + vectors */ + float *invenergy /* (o) Inv energy of augmented codebook + vectors */ + ) +{ + int icount, ilow, j, tmpIndex; + float *pp, *ppo, *ppi, *ppe, crossDot, alfa; + float weighted, measure, nrjRecursive; + float ftmp; + + /* Compute the energy for the first (low-5) + noninterpolated samples */ + nrjRecursive = (float) 0.0; + pp = buffer - low + 1; + for (j = 0; j < (low - 5); j++) { + nrjRecursive += ((*pp) * (*pp)); + pp++; + } + ppe = buffer - low; + + + for (icount = low; icount <= high; icount++) { + + /* Index of the codebook vector used for retrieving + energy values */ + tmpIndex = startIndex + icount - 20; + + ilow = icount - 4; + + /* Update the energy recursively to save complexity */ + nrjRecursive = nrjRecursive + (*ppe) * (*ppe); + ppe--; + energy[tmpIndex] = nrjRecursive; + + /* Compute cross dot product for the first (low-5) + samples */ + + + + + + crossDot = (float) 0.0; + pp = buffer - icount; + for (j = 0; j < ilow; j++) { + crossDot += target[j] * (*pp++); + } + + /* interpolation */ + alfa = (float) 0.2; + ppo = buffer - 4; + ppi = buffer - icount - 4; + for (j = ilow; j < icount; j++) { + weighted = ((float) 1.0 - alfa) * (*ppo) + alfa * (*ppi); + ppo++; + ppi++; + energy[tmpIndex] += weighted * weighted; + crossDot += target[j] * weighted; + alfa += (float) 0.2; + } + + /* Compute energy and cross dot product for the + remaining samples */ + pp = buffer - icount; + for (j = icount; j < SUBL; j++) { + energy[tmpIndex] += (*pp) * (*pp); + crossDot += target[j] * (*pp++); + } + + if (energy[tmpIndex] > 0.0) { + invenergy[tmpIndex] = (float) 1.0 / (energy[tmpIndex] + EPS); + } else { + invenergy[tmpIndex] = (float) 0.0; + } + + if (stage == 0) { + measure = (float) -10000000.0; + + if (crossDot > 0.0) { + measure = crossDot * crossDot * invenergy[tmpIndex]; + } + } else { + measure = crossDot * crossDot * invenergy[tmpIndex]; + } + + /* check if measure is better */ + ftmp = crossDot * invenergy[tmpIndex]; + + if ((measure > *max_measure) && (fabs(ftmp) < CB_MAXGAIN)) { + + + + + + *best_index = tmpIndex; + *max_measure = measure; + *gain = ftmp; + } + } +} + + + /*----------------------------------------------------------------* + * Recreate a specific codebook vector from the augmented part. + * + *----------------------------------------------------------------*/ + +void createAugmentedVec(int index, /* (i) Index for the augmented vector + to be created */ + float *buffer, /* (i) Pointer to the end of the buffer for + augmented codebook construction */ + float *cbVec /* (o) The construced codebook vector */ + ) +{ + int ilow, j; + float *pp, *ppo, *ppi, alfa, alfa1, weighted; + + ilow = index - 5; + + /* copy the first noninterpolated part */ + + pp = buffer - index; + memcpy(cbVec, pp, sizeof(float) * index); + + /* interpolation */ + + alfa1 = (float) 0.2; + alfa = 0.0; + ppo = buffer - 5; + ppi = buffer - index - 5; + for (j = ilow; j < index; j++) { + weighted = ((float) 1.0 - alfa) * (*ppo) + alfa * (*ppi); + ppo++; + ppi++; + cbVec[j] = weighted; + alfa += alfa1; + } + + /* copy the second noninterpolated part */ + + pp = buffer - index; + memcpy(cbVec + index, pp, sizeof(float) * (SUBL - index)); + + + + + +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/createCB.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/createCB.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,49 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + createCB.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_CREATECB_H +#define __iLBC_CREATECB_H + +void filteredCBvecs(float *cbvectors, /* (o) Codebook vector for the + higher section */ + float *mem, /* (i) Buffer to create codebook + vectors from */ + int lMem /* (i) Length of buffer */ + ); + +void searchAugmentedCB(int low, /* (i) Start index for the search */ + int high, /* (i) End index for the search */ + int stage, /* (i) Current stage */ + int startIndex, /* (i) CB index for the first + augmented vector */ + float *target, /* (i) Target vector for encoding */ + float *buffer, /* (i) Pointer to the end of the + buffer for augmented codebook + construction */ + float *max_measure, /* (i/o) Currently maximum measure */ + int *best_index, /* (o) Currently the best index */ + float *gain, /* (o) Currently the best gain */ + float *energy, /* (o) Energy of augmented + codebook vectors */ + float *invenergy /* (o) Inv energy of aug codebook + vectors */ + ); + +void createAugmentedVec(int index, /* (i) Index for the aug vector + to be created */ + float *buffer, /* (i) Pointer to the end of the + buffer for augmented codebook + construction */ + float *cbVec /* (o) The construced codebook vector */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/doCPLC.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/doCPLC.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,259 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + doCPLC.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include +#include + + + + + +#include "iLBC_define.h" + + /*----------------------------------------------------------------* + * Compute cross correlation and pitch gain for pitch prediction + * of last subframe at given lag. + *---------------------------------------------------------------*/ + +void compCorr(float *cc, /* (o) cross correlation coefficient */ + float *gc, /* (o) gain */ + float *pm, float *buffer, /* (i) signal buffer */ + int lag, /* (i) pitch lag */ + int bLen, /* (i) length of buffer */ + int sRange /* (i) correlation search length */ + ) +{ + int i; + float ftmp1, ftmp2, ftmp3; + + /* Guard against getting outside buffer */ + if ((bLen - sRange - lag) < 0) { + sRange = bLen - lag; + } + + ftmp1 = 0.0; + ftmp2 = 0.0; + ftmp3 = 0.0; + for (i = 0; i < sRange; i++) { + ftmp1 += buffer[bLen - sRange + i] * + buffer[bLen - sRange + i - lag]; + ftmp2 += buffer[bLen - sRange + i - lag] * + buffer[bLen - sRange + i - lag]; + ftmp3 += buffer[bLen - sRange + i] * buffer[bLen - sRange + i]; + } + + if (ftmp2 > 0.0) { + *cc = ftmp1 * ftmp1 / ftmp2; + *gc = (float) fabs(ftmp1 / ftmp2); + *pm = (float) fabs(ftmp1) / + ((float) sqrt(ftmp2) * (float) sqrt(ftmp3)); + } else { + *cc = 0.0; + *gc = 0.0; + *pm = 0.0; + } +} + + + + + + /*----------------------------------------------------------------* + * Packet loss concealment routine. Conceals a residual signal + * and LP parameters. If no packet loss, update state. + *---------------------------------------------------------------*/ + +void doThePLC(float *PLCresidual, /* (o) concealed residual */ + float *PLClpc, /* (o) concealed LP parameters */ + int PLI, /* (i) packet loss indicator + 0 - no PL, 1 = PL */ + float *decresidual, /* (i) decoded residual */ + float *lpc, /* (i) decoded LPC (only used for no PL) */ + int inlag, /* (i) pitch lag */ + iLBC_Dec_Inst_t * iLBCdec_inst + /* (i/o) decoder instance */ + ) +{ + int lag = 20, randlag; + float gain, maxcc; + float use_gain; + float gain_comp, maxcc_comp, per, max_per; + int i, pick, use_lag; + float ftmp, randvec[BLOCKL_MAX], pitchfact, energy; + + /* Packet Loss */ + + if (PLI == 1) { + + iLBCdec_inst->consPLICount += 1; + + /* if previous frame not lost, + determine pitch pred. gain */ + + if (iLBCdec_inst->prevPLI != 1) { + + /* Search around the previous lag to find the + best pitch period */ + + lag = inlag - 3; + compCorr(&maxcc, &gain, &max_per, + iLBCdec_inst->prevResidual, lag, iLBCdec_inst->blockl, 60); + for (i = inlag - 2; i <= inlag + 3; i++) { + compCorr(&maxcc_comp, &gain_comp, &per, + iLBCdec_inst->prevResidual, i, iLBCdec_inst->blockl, 60); + + if (maxcc_comp > maxcc) { + maxcc = maxcc_comp; + + + + + + gain = gain_comp; + lag = i; + max_per = per; + } + } + + } + + /* previous frame lost, use recorded lag and periodicity */ + + else { + lag = iLBCdec_inst->prevLag; + max_per = iLBCdec_inst->per; + } + + /* downscaling */ + + use_gain = 1.0; + if (iLBCdec_inst->consPLICount * iLBCdec_inst->blockl > 320) + use_gain = (float) 0.9; + else if (iLBCdec_inst->consPLICount * + iLBCdec_inst->blockl > 2 * 320) + use_gain = (float) 0.7; + else if (iLBCdec_inst->consPLICount * + iLBCdec_inst->blockl > 3 * 320) + use_gain = (float) 0.5; + else if (iLBCdec_inst->consPLICount * + iLBCdec_inst->blockl > 4 * 320) + use_gain = (float) 0.0; + + /* mix noise and pitch repeatition */ + ftmp = (float) sqrt(max_per); + if (ftmp > (float) 0.7) + pitchfact = (float) 1.0; + else if (ftmp > (float) 0.4) + pitchfact = (ftmp - (float) 0.4) / ((float) 0.7 - (float) 0.4); + else + pitchfact = 0.0; + + + /* avoid repetition of same pitch cycle */ + use_lag = lag; + if (lag < 80) { + use_lag = 2 * lag; + } + + /* compute concealed residual */ + + + + + + + energy = 0.0; + for (i = 0; i < iLBCdec_inst->blockl; i++) { + + /* noise component */ + + iLBCdec_inst->seed = (iLBCdec_inst->seed * 69069L + 1) & + (0x80000000L - 1); + randlag = 50 + ((signed long) iLBCdec_inst->seed) % 70; + pick = i - randlag; + + if (pick < 0) { + randvec[i] = + iLBCdec_inst->prevResidual[iLBCdec_inst->blockl + pick]; + } else { + randvec[i] = randvec[pick]; + } + + /* pitch repeatition component */ + pick = i - use_lag; + + if (pick < 0) { + PLCresidual[i] = + iLBCdec_inst->prevResidual[iLBCdec_inst->blockl + pick]; + } else { + PLCresidual[i] = PLCresidual[pick]; + } + + /* mix random and periodicity component */ + + if (i < 80) + PLCresidual[i] = use_gain * (pitchfact * + PLCresidual[i] + ((float) 1.0 - pitchfact) * randvec[i]); + else if (i < 160) + PLCresidual[i] = (float) 0.95 *use_gain * (pitchfact * + PLCresidual[i] + ((float) 1.0 - pitchfact) * randvec[i]); + else + PLCresidual[i] = (float) 0.9 *use_gain * (pitchfact * + PLCresidual[i] + ((float) 1.0 - pitchfact) * randvec[i]); + + energy += PLCresidual[i] * PLCresidual[i]; + } + + /* less than 30 dB, use only noise */ + + + + + + + if (sqrt(energy / (float) iLBCdec_inst->blockl) < 30.0) { + gain = 0.0; + for (i = 0; i < iLBCdec_inst->blockl; i++) { + PLCresidual[i] = randvec[i]; + } + } + + /* use old LPC */ + + memcpy(PLClpc, iLBCdec_inst->prevLpc, + (LPC_FILTERORDER + 1) * sizeof(float)); + + } + + /* no packet loss, copy input */ + + else { + memcpy(PLCresidual, decresidual, + iLBCdec_inst->blockl * sizeof(float)); + memcpy(PLClpc, lpc, (LPC_FILTERORDER + 1) * sizeof(float)); + iLBCdec_inst->consPLICount = 0; + } + + /* update state */ + + if (PLI) { + iLBCdec_inst->prevLag = lag; + iLBCdec_inst->per = max_per; + } + + iLBCdec_inst->prevPLI = PLI; + memcpy(iLBCdec_inst->prevLpc, PLClpc, + (LPC_FILTERORDER + 1) * sizeof(float)); + memcpy(iLBCdec_inst->prevResidual, PLCresidual, + iLBCdec_inst->blockl * sizeof(float)); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/doCPLC.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/doCPLC.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,27 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + doCPLC.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_DOLPC_H +#define __iLBC_DOLPC_H + +void doThePLC(float *PLCresidual, /* (o) concealed residual */ + float *PLClpc, /* (o) concealed LP parameters */ + int PLI, /* (i) packet loss indicator + 0 - no PL, 1 = PL */ + float *decresidual, /* (i) decoded residual */ + float *lpc, /* (i) decoded LPC (only used for no PL) */ + int inlag, /* (i) pitch lag */ + iLBC_Dec_Inst_t * iLBCdec_inst + /* (i/o) decoder instance */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/enhancer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/enhancer.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,685 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + enhancer.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include +#include "iLBC_define.h" +#include "constants.h" +#include "filter.h" + + /*----------------------------------------------------------------* + * Find index in array such that the array element with said + * index is the element of said array closest to "value" + * according to the squared-error criterion + *---------------------------------------------------------------*/ + +void NearestNeighbor(int *index, /* (o) index of array element closest + to value */ + float *array, /* (i) data array */ + float value, /* (i) value */ + int arlength /* (i) dimension of data array */ + ) +{ + int i; + float bestcrit, crit; + + crit = array[0] - value; + bestcrit = crit * crit; + *index = 0; + for (i = 1; i < arlength; i++) { + crit = array[i] - value; + crit = crit * crit; + + if (crit < bestcrit) { + bestcrit = crit; + *index = i; + } + } +} + + /*----------------------------------------------------------------* + * compute cross correlation between sequences + *---------------------------------------------------------------*/ + +void mycorr1(float *corr, /* (o) correlation of seq1 and seq2 */ + float *seq1, /* (i) first sequence */ + int dim1, /* (i) dimension first seq1 */ + const float *seq2, /* (i) second sequence */ + int dim2 /* (i) dimension seq2 */ + ) +{ + int i, j; + + for (i = 0; i <= dim1 - dim2; i++) { + corr[i] = 0.0; + for (j = 0; j < dim2; j++) { + corr[i] += seq1[i + j] * seq2[j]; + } + } +} + + /*----------------------------------------------------------------* + * upsample finite array assuming zeros outside bounds + *---------------------------------------------------------------*/ + + + + + + +void enh_upsample(float *useq1, /* (o) upsampled output sequence */ + float *seq1, /* (i) unupsampled sequence */ + int dim1, /* (i) dimension seq1 */ + int hfl /* (i) polyphase filter length=2*hfl+1 */ + ) +{ + float *pu, *ps; + int i, j, k, q, filterlength, hfl2; + const float *polyp[ENH_UPS0]; /* pointers to + polyphase columns */ + const float *pp; + + /* define pointers for filter */ + + filterlength = 2 * hfl + 1; + + if (filterlength > dim1) { + hfl2 = (int) (dim1 / 2); + for (j = 0; j < ENH_UPS0; j++) { + polyp[j] = polyphaserTbl + j * filterlength + hfl - hfl2; + } + hfl = hfl2; + filterlength = 2 * hfl + 1; + } else { + for (j = 0; j < ENH_UPS0; j++) { + polyp[j] = polyphaserTbl + j * filterlength; + } + } + + /* filtering: filter overhangs left side of sequence */ + + pu = useq1; + for (i = hfl; i < filterlength; i++) { + for (j = 0; j < ENH_UPS0; j++) { + *pu = 0.0; + pp = polyp[j]; + ps = seq1 + i; + for (k = 0; k <= i; k++) { + *pu += *ps-- * *pp++; + } + pu++; + } + } + + /* filtering: simple convolution=inner products */ + + for (i = filterlength; i < dim1; i++) { + + + + + + for (j = 0; j < ENH_UPS0; j++) { + *pu = 0.0; + pp = polyp[j]; + ps = seq1 + i; + for (k = 0; k < filterlength; k++) { + *pu += *ps-- * *pp++; + } + pu++; + } + } + + /* filtering: filter overhangs right side of sequence */ + + for (q = 1; q <= hfl; q++) { + for (j = 0; j < ENH_UPS0; j++) { + *pu = 0.0; + pp = polyp[j] + q; + ps = seq1 + dim1 - 1; + for (k = 0; k < filterlength - q; k++) { + *pu += *ps-- * *pp++; + } + pu++; + } + } +} + + + /*----------------------------------------------------------------* + * find segment starting near idata+estSegPos that has highest + * correlation with idata+centerStartPos through + * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a + * resolution of ENH_UPSO times the original of the original + * sampling rate + *---------------------------------------------------------------*/ + +void refiner(float *seg, /* (o) segment array */ + float *updStartPos, /* (o) updated start point */ + float *idata, /* (i) original data buffer */ + int idatal, /* (i) dimension of idata */ + int centerStartPos, /* (i) beginning center segment */ + float estSegPos, /* (i) estimated beginning other segment */ + float period /* (i) estimated pitch period */ + ) +{ + int estSegPosRounded, searchSegStartPos, searchSegEndPos, corrdim; + int tloc, tloc2, i, st, en, fraction; + float vect[ENH_VECTL], corrVec[ENH_CORRDIM], maxv; + float corrVecUps[ENH_CORRDIM * ENH_UPS0]; + + + + + + /* defining array bounds */ + + estSegPosRounded = (int) (estSegPos - 0.5); + + searchSegStartPos = estSegPosRounded - ENH_SLOP; + + if (searchSegStartPos < 0) { + searchSegStartPos = 0; + } + searchSegEndPos = estSegPosRounded + ENH_SLOP; + + if (searchSegEndPos + ENH_BLOCKL >= idatal) { + searchSegEndPos = idatal - ENH_BLOCKL - 1; + } + corrdim = searchSegEndPos - searchSegStartPos + 1; + + /* compute upsampled correlation (corr33) and find + location of max */ + + mycorr1(corrVec, idata + searchSegStartPos, + corrdim + ENH_BLOCKL - 1, idata + centerStartPos, ENH_BLOCKL); + enh_upsample(corrVecUps, corrVec, corrdim, ENH_FL0); + tloc = 0; + maxv = corrVecUps[0]; + for (i = 1; i < ENH_UPS0 * corrdim; i++) { + + if (corrVecUps[i] > maxv) { + tloc = i; + maxv = corrVecUps[i]; + } + } + + /* make vector can be upsampled without ever running outside + bounds */ + + *updStartPos = (float) searchSegStartPos + + (float) tloc / (float) ENH_UPS0 + (float) 1.0; + tloc2 = (int) (tloc / ENH_UPS0); + + if (tloc > tloc2 * ENH_UPS0) { + tloc2++; + } + st = searchSegStartPos + tloc2 - ENH_FL0; + + if (st < 0) { + memset(vect, 0, -st * sizeof(float)); + memcpy(&vect[-st], idata, (ENH_VECTL + st) * sizeof(float)); + } else { + + + + + + en = st + ENH_VECTL; + + if (en > idatal) { + memcpy(vect, &idata[st], + (ENH_VECTL - (en - idatal)) * sizeof(float)); + memset(&vect[ENH_VECTL - (en - idatal)], 0, + (en - idatal) * sizeof(float)); + } else { + memcpy(vect, &idata[st], ENH_VECTL * sizeof(float)); + } + } + fraction = tloc2 * ENH_UPS0 - tloc; + + /* compute the segment (this is actually a convolution) */ + + mycorr1(seg, vect, ENH_VECTL, + polyphaserTbl + (2 * ENH_FL0 + 1) * fraction, 2 * ENH_FL0 + 1); +} + + /*----------------------------------------------------------------* + * find the smoothed output data + *---------------------------------------------------------------*/ + +void smath(float *odata, /* (o) smoothed output */ + float *sseq, /* (i) said second sequence of waveforms */ + int hl, /* (i) 2*hl+1 is sseq dimension */ + float alpha0 /* (i) max smoothing energy fraction */ + ) +{ + int i, k; + float w00, w10, w11, A, B, C, *psseq, err, errs; + float surround[BLOCKL_MAX]; /* shape contributed by other than + current */ + float wt[2 * ENH_HL + 1]; /* waveform weighting to get + surround shape */ + float denom; + + /* create shape of contribution from all waveforms except the + current one */ + + for (i = 1; i <= 2 * hl + 1; i++) { + wt[i - 1] = + (float) 0.5 *(1 - (float) cos(2 * PI * i / (2 * hl + 2))); + } + wt[hl] = 0.0; /* for clarity, not used */ + for (i = 0; i < ENH_BLOCKL; i++) { + surround[i] = sseq[i] * wt[0]; + } + + + + + + for (k = 1; k < hl; k++) { + psseq = sseq + k * ENH_BLOCKL; + for (i = 0; i < ENH_BLOCKL; i++) { + surround[i] += psseq[i] * wt[k]; + } + } + for (k = hl + 1; k <= 2 * hl; k++) { + psseq = sseq + k * ENH_BLOCKL; + for (i = 0; i < ENH_BLOCKL; i++) { + surround[i] += psseq[i] * wt[k]; + } + } + + /* compute some inner products */ + + w00 = w10 = w11 = 0.0; + psseq = sseq + hl * ENH_BLOCKL; /* current block */ + for (i = 0; i < ENH_BLOCKL; i++) { + w00 += psseq[i] * psseq[i]; + w11 += surround[i] * surround[i]; + w10 += surround[i] * psseq[i]; + } + + if (fabs(w11) < 1.0) { + w11 = 1.0; + } + C = (float) sqrt(w00 / w11); + + /* first try enhancement without power-constraint */ + + errs = 0.0; + psseq = sseq + hl * ENH_BLOCKL; + for (i = 0; i < ENH_BLOCKL; i++) { + odata[i] = C * surround[i]; + err = psseq[i] - odata[i]; + errs += err * err; + } + + /* if constraint violated by first try, add constraint */ + + if (errs > alpha0 * w00) { + if (w00 < 1) { + w00 = 1; + } + denom = (w11 * w00 - w10 * w10) / (w00 * w00); + + if (denom > 0.0001) { /* eliminates numerical problems + for if smooth */ + + + + + + A = (float) sqrt((alpha0 - alpha0 * alpha0 / 4) / denom); + B = -alpha0 / 2 - A * w10 / w00; + B = B + 1; + } else { /* essentially no difference between cycles; + smoothing not needed */ + A = 0.0; + B = 1.0; + } + + /* create smoothed sequence */ + + psseq = sseq + hl * ENH_BLOCKL; + for (i = 0; i < ENH_BLOCKL; i++) { + odata[i] = A * surround[i] + B * psseq[i]; + } + } +} + + /*----------------------------------------------------------------* + * get the pitch-synchronous sample sequence + *---------------------------------------------------------------*/ + +void getsseq(float *sseq, /* (o) the pitch-synchronous sequence */ + float *idata, /* (i) original data */ + int idatal, /* (i) dimension of data */ + int centerStartPos, /* (i) where current block starts */ + float *period, /* (i) rough-pitch-period array */ + float *plocs, /* (i) where periods of period array + are taken */ + int periodl, /* (i) dimension period array */ + int hl /* (i) 2*hl+1 is the number of sequences */ + ) +{ + int i, centerEndPos, q; + float blockStartPos[2 * ENH_HL + 1]; + int lagBlock[2 * ENH_HL + 1]; + float plocs2[ENH_PLOCSL]; + float *psseq; + + centerEndPos = centerStartPos + ENH_BLOCKL - 1; + + /* present */ + + NearestNeighbor(lagBlock + hl, plocs, + (float) 0.5 * (centerStartPos + centerEndPos), periodl); + + blockStartPos[hl] = (float) centerStartPos; + + + + + + psseq = sseq + ENH_BLOCKL * hl; + memcpy(psseq, idata + centerStartPos, ENH_BLOCKL * sizeof(float)); + + /* past */ + + for (q = hl - 1; q >= 0; q--) { + blockStartPos[q] = blockStartPos[q + 1] - period[lagBlock[q + 1]]; + NearestNeighbor(lagBlock + q, plocs, + blockStartPos[q] + + ENH_BLOCKL_HALF - period[lagBlock[q + 1]], periodl); + + + if (blockStartPos[q] - ENH_OVERHANG >= 0) { + refiner(sseq + q * ENH_BLOCKL, blockStartPos + q, idata, + idatal, centerStartPos, blockStartPos[q], + period[lagBlock[q + 1]]); + } else { + psseq = sseq + q * ENH_BLOCKL; + memset(psseq, 0, ENH_BLOCKL * sizeof(float)); + } + } + + /* future */ + + for (i = 0; i < periodl; i++) { + plocs2[i] = plocs[i] - period[i]; + } + for (q = hl + 1; q <= 2 * hl; q++) { + NearestNeighbor(lagBlock + q, plocs2, + blockStartPos[q - 1] + ENH_BLOCKL_HALF, periodl); + + blockStartPos[q] = blockStartPos[q - 1] + period[lagBlock[q]]; + if (blockStartPos[q] + ENH_BLOCKL + ENH_OVERHANG < idatal) { + refiner(sseq + ENH_BLOCKL * q, blockStartPos + q, idata, + idatal, centerStartPos, blockStartPos[q], period[lagBlock[q]]); + } else { + psseq = sseq + q * ENH_BLOCKL; + memset(psseq, 0, ENH_BLOCKL * sizeof(float)); + } + } +} + + /*----------------------------------------------------------------* + * perform enhancement on idata+centerStartPos through + * idata+centerStartPos+ENH_BLOCKL-1 + *---------------------------------------------------------------*/ + + + + + +void enhancer(float *odata, /* (o) smoothed block, dimension blockl */ + float *idata, /* (i) data buffer used for enhancing */ + int idatal, /* (i) dimension idata */ + int centerStartPos, /* (i) first sample current block + within idata */ + float alpha0, /* (i) max correction-energy-fraction + (in [0,1]) */ + float *period, /* (i) pitch period array */ + float *plocs, /* (i) locations where period array + values valid */ + int periodl /* (i) dimension of period and plocs */ + ) +{ + float sseq[(2 * ENH_HL + 1) * ENH_BLOCKL]; + + /* get said second sequence of segments */ + + getsseq(sseq, idata, idatal, centerStartPos, period, + plocs, periodl, ENH_HL); + + /* compute the smoothed output from said second sequence */ + + smath(odata, sseq, ENH_HL, alpha0); + +} + + /*----------------------------------------------------------------* + * cross correlation + *---------------------------------------------------------------*/ + +float xCorrCoef(float *target, /* (i) first array */ + float *regressor, /* (i) second array */ + int subl /* (i) dimension arrays */ + ) +{ + int i; + float ftmp1, ftmp2; + + ftmp1 = 0.0; + ftmp2 = 0.0; + for (i = 0; i < subl; i++) { + ftmp1 += target[i] * regressor[i]; + ftmp2 += regressor[i] * regressor[i]; + } + + if (ftmp1 > 0.0) { + return (float) (ftmp1 * ftmp1 / ftmp2); + } + + + + + + else { + return (float) 0.0; + } +} + + /*----------------------------------------------------------------* + * interface for enhancer + *---------------------------------------------------------------*/ + +int enhancerInterface(float *out, /* (o) enhanced signal */ + float *in, /* (i) unenhanced signal */ + iLBC_Dec_Inst_t * iLBCdec_inst /* (i) buffers etc */ + ) +{ + float *enh_buf, *enh_period; + int iblock, isample; + int lag = 0, ilag, i, ioffset; + float cc, maxcc; + float ftmp1, ftmp2; + float *inPtr, *enh_bufPtr1, *enh_bufPtr2; + float plc_pred[ENH_BLOCKL]; + + float lpState[6], downsampled[(ENH_NBLOCKS * ENH_BLOCKL + 120) / 2]; + int inLen = ENH_NBLOCKS * ENH_BLOCKL + 120; + int start, plc_blockl, inlag; + + enh_buf = iLBCdec_inst->enh_buf; + enh_period = iLBCdec_inst->enh_period; + + memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], + (ENH_BUFL - iLBCdec_inst->blockl) * sizeof(float)); + + memcpy(&enh_buf[ENH_BUFL - iLBCdec_inst->blockl], in, + iLBCdec_inst->blockl * sizeof(float)); + + if (iLBCdec_inst->mode == 30) + plc_blockl = ENH_BLOCKL; + else + plc_blockl = 40; + + /* when 20 ms frame, move processing one block */ + ioffset = 0; + if (iLBCdec_inst->mode == 20) + ioffset = 1; + + i = 3 - ioffset; + memmove(enh_period, &enh_period[i], + (ENH_NBLOCKS_TOT - i) * sizeof(float)); + + + + + + + /* Set state information to the 6 samples right before + the samples to be downsampled. */ + + memcpy(lpState, + enh_buf + (ENH_NBLOCKS_EXTRA + ioffset) * ENH_BLOCKL - 126, + 6 * sizeof(float)); + + /* Down sample a factor 2 to save computations */ + + DownSample(enh_buf + (ENH_NBLOCKS_EXTRA + ioffset) * ENH_BLOCKL - 120, + lpFilt_coefsTbl, inLen - ioffset * ENH_BLOCKL, + lpState, downsampled); + + /* Estimate the pitch in the down sampled domain. */ + for (iblock = 0; iblock < ENH_NBLOCKS - ioffset; iblock++) { + + lag = 10; + maxcc = xCorrCoef(downsampled + 60 + iblock * + ENH_BLOCKL_HALF, downsampled + 60 + iblock * + ENH_BLOCKL_HALF - lag, ENH_BLOCKL_HALF); + for (ilag = 11; ilag < 60; ilag++) { + cc = xCorrCoef(downsampled + 60 + iblock * + ENH_BLOCKL_HALF, downsampled + 60 + iblock * + ENH_BLOCKL_HALF - ilag, ENH_BLOCKL_HALF); + + if (cc > maxcc) { + maxcc = cc; + lag = ilag; + } + } + + /* Store the estimated lag in the non-downsampled domain */ + enh_period[iblock + ENH_NBLOCKS_EXTRA + ioffset] = (float) lag *2; + + + } + + + /* PLC was performed on the previous packet */ + if (iLBCdec_inst->prev_enh_pl == 1) { + + inlag = (int) enh_period[ENH_NBLOCKS_EXTRA + ioffset]; + + lag = inlag - 1; + maxcc = xCorrCoef(in, in + lag, plc_blockl); + for (ilag = inlag; ilag <= inlag + 1; ilag++) { + cc = xCorrCoef(in, in + ilag, plc_blockl); + + + + + + + if (cc > maxcc) { + maxcc = cc; + lag = ilag; + } + } + + enh_period[ENH_NBLOCKS_EXTRA + ioffset - 1] = (float) lag; + + /* compute new concealed residual for the old lookahead, + mix the forward PLC with a backward PLC from + the new frame */ + + inPtr = &in[lag - 1]; + + enh_bufPtr1 = &plc_pred[plc_blockl - 1]; + + if (lag > plc_blockl) { + start = plc_blockl; + } else { + start = lag; + } + + for (isample = start; isample > 0; isample--) { + *enh_bufPtr1-- = *inPtr--; + } + + enh_bufPtr2 = &enh_buf[ENH_BUFL - 1 - iLBCdec_inst->blockl]; + for (isample = (plc_blockl - 1 - lag); isample >= 0; isample--) { + *enh_bufPtr1-- = *enh_bufPtr2--; + } + + /* limit energy change */ + ftmp2 = 0.0; + ftmp1 = 0.0; + for (i = 0; i < plc_blockl; i++) { + ftmp2 += enh_buf[ENH_BUFL - 1 - iLBCdec_inst->blockl - i] * + enh_buf[ENH_BUFL - 1 - iLBCdec_inst->blockl - i]; + ftmp1 += plc_pred[i] * plc_pred[i]; + } + ftmp1 = (float) sqrt(ftmp1 / (float) plc_blockl); + ftmp2 = (float) sqrt(ftmp2 / (float) plc_blockl); + if (ftmp1 > (float) 2.0 * ftmp2 && ftmp1 > 0.0) { + for (i = 0; i < plc_blockl - 10; i++) { + plc_pred[i] *= (float) 2.0 *ftmp2 / ftmp1; + } + for (i = plc_blockl - 10; i < plc_blockl; i++) { + plc_pred[i] *= (float) (i - plc_blockl + 10) * + ((float) 1.0 - (float) 2.0 * ftmp2 / ftmp1) / (float) (10) + + (float) 2.0 *ftmp2 / ftmp1; + } + } + + enh_bufPtr1 = &enh_buf[ENH_BUFL - 1 - iLBCdec_inst->blockl]; + for (i = 0; i < plc_blockl; i++) { + ftmp1 = (float) (i + 1) / (float) (plc_blockl + 1); + *enh_bufPtr1 *= ftmp1; + *enh_bufPtr1 += ((float) 1.0 - ftmp1) * + plc_pred[plc_blockl - 1 - i]; + enh_bufPtr1--; + } + } + + if (iLBCdec_inst->mode == 20) { + /* Enhancer with 40 samples delay */ + for (iblock = 0; iblock < 2; iblock++) { + enhancer(out + iblock * ENH_BLOCKL, enh_buf, + ENH_BUFL, (5 + iblock) * ENH_BLOCKL + 40, + ENH_ALPHA0, enh_period, enh_plocsTbl, ENH_NBLOCKS_TOT); + } + } else if (iLBCdec_inst->mode == 30) { + /* Enhancer with 80 samples delay */ + for (iblock = 0; iblock < 3; iblock++) { + enhancer(out + iblock * ENH_BLOCKL, enh_buf, + ENH_BUFL, (4 + iblock) * ENH_BLOCKL, + ENH_ALPHA0, enh_period, enh_plocsTbl, ENH_NBLOCKS_TOT); + } + } + + return (lag * 2); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/enhancer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/enhancer.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,33 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + enhancer.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + + + + + ******************************************************************/ + +#ifndef __ENHANCER_H +#define __ENHANCER_H + +#include "iLBC_define.h" + +float xCorrCoef(float *target, /* (i) first array */ + float *regressor, /* (i) second array */ + int subl /* (i) dimension arrays */ + ); + +int enhancerInterface(float *out, /* (o) the enhanced recidual signal */ + float *in, /* (i) the recidual signal to enhance */ + iLBC_Dec_Inst_t * iLBCdec_inst + /* (i/o) the decoder state structure */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/extract-cfile.awk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/extract-cfile.awk Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,21 @@ +BEGIN { srcname = "nothing"; } +{ if (/^A\.[0-9][0-9]*\.* *[a-zA-Z][a-zA-Z_0-9]*\.[ch]/) { + if (srcname != "nothing") + close(srcname); + srcname = $2; + printf("creating source file %s\n", srcname); + }else if (srcname != "nothing") { + if (/Andersen,* *et* *al\./) + printf("skipping %s\n", $0); + else if (/ /) + printf("skipping2 %s\n", $0); + else if (/Internet Low Bit Rate Codec *December 2004/) + printf("skipping3 %s\n", $0); + else + print $0 >> srcname; + } +} +END { + printf("ending file %s\n", srcname); + close(srcname); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/filter.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/filter.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,166 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + filter.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "iLBC_define.h" + + /*----------------------------------------------------------------* + * all-pole filter + *---------------------------------------------------------------*/ + +void AllPoleFilter(float *InOut, /* (i/o) on entrance InOut[-orderCoef] to + InOut[-1] contain the state of the + filter (delayed samples). InOut[0] to + InOut[lengthInOut-1] contain the filter + input, on en exit InOut[-orderCoef] to + InOut[-1] is unchanged and InOut[0] to + InOut[lengthInOut-1] contain filtered + samples */ + float *Coef, /* (i) filter coefficients, Coef[0] is assumed + to be 1.0 */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef /* (i) number of filter coefficients */ + ) +{ + int n, k; + + for (n = 0; n < lengthInOut; n++) { + for (k = 1; k <= orderCoef; k++) { + *InOut -= Coef[k] * InOut[-k]; + + + + + + } + InOut++; + } +} + + /*----------------------------------------------------------------* + * all-zero filter + *---------------------------------------------------------------*/ + +void AllZeroFilter(float *In, /* (i) In[0] to In[lengthInOut-1] contain + filter input samples */ + float *Coef, /* (i) filter coefficients (Coef[0] is assumed + to be 1.0) */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef, /* (i) number of filter coefficients */ + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] + contain the filter state, on exit Out[0] + to Out[lengthInOut-1] contain filtered + samples */ + ) +{ + int n, k; + + for (n = 0; n < lengthInOut; n++) { + *Out = Coef[0] * In[0]; + for (k = 1; k <= orderCoef; k++) { + *Out += Coef[k] * In[-k]; + } + Out++; + In++; + } +} + + /*----------------------------------------------------------------* + * pole-zero filter + *---------------------------------------------------------------*/ + +void ZeroPoleFilter(float *In, /* (i) In[0] to In[lengthInOut-1] contain + filter input samples In[-orderCoef] to + In[-1] contain state of all-zero + section */ + float *ZeroCoef, /* (i) filter coefficients for all-zero + section (ZeroCoef[0] is assumed to + be 1.0) */ + float *PoleCoef, /* (i) filter coefficients for all-pole section + (ZeroCoef[0] is assumed to be 1.0) */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef, /* (i) number of filter coefficients */ + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] + contain state of all-pole section. On + exit Out[0] to Out[lengthInOut-1] + contain filtered samples */ + ) +{ + AllZeroFilter(In, ZeroCoef, lengthInOut, orderCoef, Out); + AllPoleFilter(Out, PoleCoef, lengthInOut, orderCoef); +} + + /*----------------------------------------------------------------* + * downsample (LP filter and decimation) + *---------------------------------------------------------------*/ + +void DownSample(float *In, /* (i) input samples */ + float *Coef, /* (i) filter coefficients */ + int lengthIn, /* (i) number of input samples */ + float *state, /* (i) filter state */ + float *Out /* (o) downsampled output */ + ) +{ + float o; + float *Out_ptr = Out; + float *Coef_ptr, *In_ptr; + float *state_ptr; + int i, j, stop; + + /* LP filter and decimate at the same time */ + + for (i = DELAY_DS; i < lengthIn; i += FACTOR_DS) { + Coef_ptr = &Coef[0]; + In_ptr = &In[i]; + state_ptr = &state[FILTERORDER_DS - 2]; + + o = (float) 0.0; + + stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS; + + for (j = 0; j < stop; j++) { + o += *Coef_ptr++ * (*In_ptr--); + } + for (j = i + 1; j < FILTERORDER_DS; j++) { + o += *Coef_ptr++ * (*state_ptr--); + } + + + + + + + *Out_ptr++ = o; + } + + /* Get the last part (use zeros as input for the future) */ + + for (i = (lengthIn + FACTOR_DS); i < (lengthIn + DELAY_DS); + i += FACTOR_DS) { + + o = (float) 0.0; + + if (i < lengthIn) { + Coef_ptr = &Coef[0]; + In_ptr = &In[i]; + for (j = 0; j < FILTERORDER_DS; j++) { + o += *Coef_ptr++ * (*Out_ptr--); + } + } else { + Coef_ptr = &Coef[i - lengthIn]; + In_ptr = &In[lengthIn - 1]; + for (j = 0; j < FILTERORDER_DS - (i - lengthIn); j++) { + o += *Coef_ptr++ * (*In_ptr--); + } + } + *Out_ptr++ = o; + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/filter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/filter.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,75 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + filter.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + + + + + + +#ifndef __iLBC_FILTER_H +#define __iLBC_FILTER_H + +void AllPoleFilter(float *InOut, /* (i/o) on entrance InOut[-orderCoef] to + InOut[-1] contain the state of the + filter (delayed samples). InOut[0] to + InOut[lengthInOut-1] contain the filter + input, on en exit InOut[-orderCoef] to + InOut[-1] is unchanged and InOut[0] to + InOut[lengthInOut-1] contain filtered + samples */ + float *Coef, /* (i) filter coefficients, Coef[0] is assumed + to be 1.0 */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef /* (i) number of filter coefficients */ + ); + +void AllZeroFilter(float *In, /* (i) In[0] to In[lengthInOut-1] contain + filter input samples */ + float *Coef, /* (i) filter coefficients (Coef[0] is assumed + to be 1.0) */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef, /* (i) number of filter coefficients */ + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] + contain the filter state, on exit Out[0] + to Out[lengthInOut-1] contain filtered + samples */ + ); + +void ZeroPoleFilter(float *In, /* (i) In[0] to In[lengthInOut-1] contain filter + input samples In[-orderCoef] to In[-1] + contain state of all-zero section */ + float *ZeroCoef, /* (i) filter coefficients for all-zero + section (ZeroCoef[0] is assumed to + be 1.0) */ + float *PoleCoef, /* (i) filter coefficients for all-pole section + (ZeroCoef[0] is assumed to be 1.0) */ + int lengthInOut, /* (i) number of input/output samples */ + int orderCoef, /* (i) number of filter coefficients */ + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] + contain state of all-pole section. On + exit Out[0] to Out[lengthInOut-1] + contain filtered samples */ + ); + + + + + + +void DownSample(float *In, /* (i) input samples */ + float *Coef, /* (i) filter coefficients */ + int lengthIn, /* (i) number of input samples */ + float *state, /* (i) filter state */ + float *Out /* (o) downsampled output */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/gainquant.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/gainquant.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,111 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + + + + + + gainquant.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include +#include "constants.h" +#include "filter.h" + + /*----------------------------------------------------------------* + * quantizer for the gain in the gain-shape coding of residual + *---------------------------------------------------------------*/ + +float gainquant( /* (o) quantized gain value */ + float in, /* (i) gain value */ + float maxIn, /* (i) maximum of gain value */ + int cblen, /* (i) number of quantization indices */ + int *index /* (o) quantization index */ + ) +{ + int i, tindex; + float minmeasure, measure, *cb, scale; + + /* ensure a lower bound on the scaling factor */ + + scale = maxIn; + + if (scale < 0.1) { + scale = (float) 0.1; + } + + /* select the quantization table */ + + if (cblen == 8) { + cb = gain_sq3Tbl; + } else if (cblen == 16) { + cb = gain_sq4Tbl; + } else { + cb = gain_sq5Tbl; + } + + /* select the best index in the quantization table */ + + minmeasure = 10000000.0; + tindex = 0; + for (i = 0; i < cblen; i++) { + + + + + + measure = (in - scale * cb[i]) * (in - scale * cb[i]); + + if (measure < minmeasure) { + tindex = i; + minmeasure = measure; + } + } + *index = tindex; + + /* return the quantized value */ + + return scale * cb[tindex]; +} + + /*----------------------------------------------------------------* + * decoder for quantized gains in the gain-shape coding of + * residual + *---------------------------------------------------------------*/ + +float gaindequant( /* (o) quantized gain value */ + int index, /* (i) quantization index */ + float maxIn, /* (i) maximum of unquantized gain */ + int cblen /* (i) number of quantization indices */ + ) +{ + float scale; + + /* obtain correct scale factor */ + + scale = (float) fabs(maxIn); + + if (scale < 0.1) { + scale = (float) 0.1; + } + + /* select the quantization table and return the decoded value */ + + if (cblen == 8) { + return scale * gain_sq3Tbl[index]; + } else if (cblen == 16) { + return scale * gain_sq4Tbl[index]; + } else if (cblen == 32) { + return scale * gain_sq5Tbl[index]; + } + + return 0.0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/gainquant.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/gainquant.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,29 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + gainquant.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_GAINQUANT_H +#define __iLBC_GAINQUANT_H + +float gainquant( /* (o) quantized gain value */ + float in, /* (i) gain value */ + float maxIn, /* (i) maximum of gain value */ + int cblen, /* (i) number of quantization indices */ + int *index /* (o) quantization index */ + ); + +float gaindequant( /* (o) quantized gain value */ + int index, /* (i) quantization index */ + float maxIn, /* (i) maximum of unquantized gain */ + int cblen /* (i) number of quantization indices */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/getCBvec.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/getCBvec.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,181 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + getCBvec.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "iLBC_define.h" +#include "constants.h" +#include + + /*----------------------------------------------------------------* + * Construct codebook vector for given index. + *---------------------------------------------------------------*/ + +void getCBvec(float *cbvec, /* (o) Constructed codebook vector */ + float *mem, /* (i) Codebook buffer */ + int index, /* (i) Codebook index */ + int lMem, /* (i) Length of codebook buffer */ + int cbveclen /* (i) Codebook vector length */ + ) +{ + int j, k, n, memInd, sFilt; + float tmpbuf[CB_MEML]; + int base_size; + int ilow, ihigh; + float alfa, alfa1; + + /* Determine size of codebook sections */ + + base_size = lMem - cbveclen + 1; + + if (cbveclen == SUBL) { + base_size += cbveclen / 2; + } + + /* No filter -> First codebook section */ + + if (index < lMem - cbveclen + 1) { + + /* first non-interpolated vectors */ + + k = index + cbveclen; + /* get vector */ + memcpy(cbvec, mem + lMem - k, cbveclen * sizeof(float)); + + } else if (index < base_size) { + + k = 2 * (index - (lMem - cbveclen + 1)) + cbveclen; + + ihigh = k / 2; + ilow = ihigh - 5; + + /* Copy first noninterpolated part */ + + memcpy(cbvec, mem + lMem - k / 2, ilow * sizeof(float)); + + /* interpolation */ + + alfa1 = (float) 0.2; + alfa = 0.0; + for (j = ilow; j < ihigh; j++) { + cbvec[j] = ((float) 1.0 - alfa) * mem[lMem - k / 2 + j] + + alfa * mem[lMem - k + j]; + + + + + + alfa += alfa1; + } + + /* Copy second noninterpolated part */ + + memcpy(cbvec + ihigh, mem + lMem - k + ihigh, + (cbveclen - ihigh) * sizeof(float)); + + } + + /* Higher codebook section based on filtering */ + + else { + + /* first non-interpolated vectors */ + + if (index - base_size < lMem - cbveclen + 1) { + float tempbuff2[CB_MEML + CB_FILTERLEN + 1]; + float *pos; + float *pp, *pp1; + + memset(tempbuff2, 0, CB_HALFFILTERLEN * sizeof(float)); + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, lMem * sizeof(float)); + memset(&tempbuff2[lMem + CB_HALFFILTERLEN], 0, + (CB_HALFFILTERLEN + 1) * sizeof(float)); + + k = index - base_size + cbveclen; + sFilt = lMem - k; + memInd = sFilt + 1 - CB_HALFFILTERLEN; + + /* do filtering */ + pos = cbvec; + memset(pos, 0, cbveclen * sizeof(float)); + for (n = 0; n < cbveclen; n++) { + pp = &tempbuff2[memInd + n + CB_HALFFILTERLEN]; + pp1 = &cbfiltersTbl[CB_FILTERLEN - 1]; + for (j = 0; j < CB_FILTERLEN; j++) { + (*pos) += (*pp++) * (*pp1--); + } + pos++; + } + } + + /* interpolated vectors */ + + else { + + + + + + float tempbuff2[CB_MEML + CB_FILTERLEN + 1]; + + float *pos; + float *pp, *pp1; + int i; + + memset(tempbuff2, 0, CB_HALFFILTERLEN * sizeof(float)); + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, lMem * sizeof(float)); + memset(&tempbuff2[lMem + CB_HALFFILTERLEN], 0, + (CB_HALFFILTERLEN + 1) * sizeof(float)); + + k = 2 * (index - base_size - (lMem - cbveclen + 1)) + cbveclen; + sFilt = lMem - k; + memInd = sFilt + 1 - CB_HALFFILTERLEN; + + /* do filtering */ + pos = &tmpbuf[sFilt]; + memset(pos, 0, k * sizeof(float)); + for (i = 0; i < k; i++) { + pp = &tempbuff2[memInd + i + CB_HALFFILTERLEN]; + pp1 = &cbfiltersTbl[CB_FILTERLEN - 1]; + for (j = 0; j < CB_FILTERLEN; j++) { + (*pos) += (*pp++) * (*pp1--); + } + pos++; + } + + ihigh = k / 2; + ilow = ihigh - 5; + + /* Copy first noninterpolated part */ + + memcpy(cbvec, tmpbuf + lMem - k / 2, ilow * sizeof(float)); + + /* interpolation */ + + alfa1 = (float) 0.2; + alfa = 0.0; + for (j = ilow; j < ihigh; j++) { + cbvec[j] = ((float) 1.0 - alfa) * + tmpbuf[lMem - k / 2 + j] + alfa * tmpbuf[lMem - k + j]; + alfa += alfa1; + } + + + + + + + /* Copy second noninterpolated part */ + + memcpy(cbvec + ihigh, tmpbuf + lMem - k + ihigh, + (cbveclen - ihigh) * sizeof(float)); + } + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/getCBvec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/getCBvec.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,23 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + getCBvec.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_GETCBVEC_H +#define __iLBC_GETCBVEC_H + +void getCBvec(float *cbvec, /* (o) Constructed codebook vector */ + float *mem, /* (i) Codebook buffer */ + int index, /* (i) Codebook index */ + int lMem, /* (i) Length of codebook buffer */ + int cbveclen /* (i) Codebook vector length */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/helpfun.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/helpfun.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,326 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + helpfun.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include + +#include "iLBC_define.h" +#include "constants.h" + + /*----------------------------------------------------------------* + * calculation of auto correlation + *---------------------------------------------------------------*/ + +void autocorr(float *r, /* (o) autocorrelation vector */ + const float *x, /* (i) data vector */ + int N, /* (i) length of data vector */ + int order /* largest lag for calculated + autocorrelations */ + ) +{ + int lag, n; + float sum; + + for (lag = 0; lag <= order; lag++) { + sum = 0; + for (n = 0; n < N - lag; n++) { + sum += x[n] * x[n + lag]; + } + r[lag] = sum; + } + + + + + +} + + /*----------------------------------------------------------------* + * window multiplication + *---------------------------------------------------------------*/ + +void window(float *z, /* (o) the windowed data */ + const float *x, /* (i) the original data vector */ + const float *y, /* (i) the window */ + int N /* (i) length of all vectors */ + ) +{ + int i; + + for (i = 0; i < N; i++) { + z[i] = x[i] * y[i]; + } +} + + /*----------------------------------------------------------------* + * levinson-durbin solution for lpc coefficients + *---------------------------------------------------------------*/ + +void levdurb(float *a, /* (o) lpc coefficient vector starting + with 1.0 */ + float *k, /* (o) reflection coefficients */ + float *r, /* (i) autocorrelation vector */ + int order /* (i) order of lpc filter */ + ) +{ + float sum, alpha; + int m, m_h, i; + + a[0] = 1.0; + + if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ + for (i = 0; i < order; i++) { + k[i] = 0; + a[i + 1] = 0; + } + } else { + a[1] = k[0] = -r[1] / r[0]; + alpha = r[0] + r[1] * k[0]; + for (m = 1; m < order; m++) { + sum = r[m + 1]; + for (i = 0; i < m; i++) { + sum += a[i + 1] * r[m - i]; + } + + + + + + k[m] = -sum / alpha; + alpha += k[m] * sum; + m_h = (m + 1) >> 1; + for (i = 0; i < m_h; i++) { + sum = a[i + 1] + k[m] * a[m - i]; + a[m - i] += k[m] * a[i + 1]; + a[i + 1] = sum; + } + a[m + 1] = k[m]; + } + } +} + + /*----------------------------------------------------------------* + * interpolation between vectors + *---------------------------------------------------------------*/ + +void interpolate(float *out, /* (o) the interpolated vector */ + float *in1, /* (i) the first vector for the + interpolation */ + float *in2, /* (i) the second vector for the + interpolation */ + float coef, /* (i) interpolation weights */ + int length /* (i) length of all vectors */ + ) +{ + int i; + float invcoef; + + invcoef = (float) 1.0 - coef; + for (i = 0; i < length; i++) { + out[i] = coef * in1[i] + invcoef * in2[i]; + } +} + + /*----------------------------------------------------------------* + * lpc bandwidth expansion + *---------------------------------------------------------------*/ + +void bwexpand(float *out, /* (o) the bandwidth expanded lpc + coefficients */ + float *in, /* (i) the lpc coefficients before bandwidth + expansion */ + float coef, /* (i) the bandwidth expansion factor */ + int length /* (i) the length of lpc coefficient vectors */ + ) +{ + int i; + + + + + + float chirp; + + chirp = coef; + + out[0] = in[0]; + for (i = 1; i < length; i++) { + out[i] = chirp * in[i]; + chirp *= coef; + } +} + + /*----------------------------------------------------------------* + * vector quantization + *---------------------------------------------------------------*/ + +void vq(float *Xq, /* (o) the quantized vector */ + int *index, /* (o) the quantization index */ + const float *CB, /* (i) the vector quantization codebook */ + float *X, /* (i) the vector to quantize */ + int n_cb, /* (i) the number of vectors in the codebook */ + int dim /* (i) the dimension of all vectors */ + ) +{ + int i, j; + int pos, minindex; + float dist, tmp, mindist; + + pos = 0; + mindist = FLOAT_MAX; + minindex = 0; + for (j = 0; j < n_cb; j++) { + dist = X[0] - CB[pos]; + dist *= dist; + for (i = 1; i < dim; i++) { + tmp = X[i] - CB[pos + i]; + dist += tmp * tmp; + } + + if (dist < mindist) { + mindist = dist; + minindex = j; + } + pos += dim; + } + for (i = 0; i < dim; i++) { + Xq[i] = CB[minindex * dim + i]; + } + *index = minindex; + + + + + +} + + /*----------------------------------------------------------------* + * split vector quantization + *---------------------------------------------------------------*/ + +void SplitVQ(float *qX, /* (o) the quantized vector */ + int *index, /* (o) a vector of indexes for all vector + codebooks in the split */ + float *X, /* (i) the vector to quantize */ + const float *CB, /* (i) the quantizer codebook */ + int nsplit, /* the number of vector splits */ + const int *dim, /* the dimension of X and qX */ + const int *cbsize /* the number of vectors in the codebook */ + ) +{ + int cb_pos, X_pos, i; + + cb_pos = 0; + X_pos = 0; + for (i = 0; i < nsplit; i++) { + vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, + cbsize[i], dim[i]); + X_pos += dim[i]; + cb_pos += dim[i] * cbsize[i]; + } +} + + /*----------------------------------------------------------------* + * scalar quantization + *---------------------------------------------------------------*/ + +void sort_sq(float *xq, /* (o) the quantized value */ + int *index, /* (o) the quantization index */ + float x, /* (i) the value to quantize */ + const float *cb, /* (i) the quantization codebook */ + int cb_size /* (i) the size of the quantization codebook */ + ) +{ + int i; + + if (x <= cb[0]) { + *index = 0; + *xq = cb[0]; + } else { + i = 0; + while ((x > cb[i]) && i < cb_size - 1) { + i++; + + + + + + } + + if (x > ((cb[i] + cb[i - 1]) / 2)) { + *index = i; + *xq = cb[i]; + } else { + *index = i - 1; + *xq = cb[i - 1]; + } + } +} + + /*----------------------------------------------------------------* + * check for stability of lsf coefficients + *---------------------------------------------------------------*/ + +int LSF_check( /* (o) 1 for stable lsf vectors and 0 for + nonstable ones */ + float *lsf, /* (i) a table of lsf vectors */ + int dim, /* (i) the dimension of each lsf vector */ + int NoAn /* (i) the number of lsf vectors in the + table */ + ) +{ + int k, n, m, Nit = 2, change = 0, pos; + float tmp; + static float eps = (float) 0.039; /* 50 Hz */ + static float eps2 = (float) 0.0195; + static float maxlsf = (float) 3.14; /* 4000 Hz */ + static float minlsf = (float) 0.01; /* 0 Hz */ + + /* LSF separation check */ + + for (n = 0; n < Nit; n++) { /* Run through a couple of times */ + for (m = 0; m < NoAn; m++) { /* Number of analyses per frame */ + for (k = 0; k < (dim - 1); k++) { + pos = m * dim + k; + + if ((lsf[pos + 1] - lsf[pos]) < eps) { + + if (lsf[pos + 1] < lsf[pos]) { + tmp = lsf[pos + 1]; + lsf[pos + 1] = lsf[pos] + eps2; + lsf[pos] = lsf[pos + 1] - eps2; + } else { + lsf[pos] -= eps2; + lsf[pos + 1] += eps2; + } + change = 1; + + + + + + } + + if (lsf[pos] < minlsf) { + lsf[pos] = minlsf; + change = 1; + } + + if (lsf[pos] > maxlsf) { + lsf[pos] = maxlsf; + change = 1; + } + } + } + } + + return change; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/helpfun.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/helpfun.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,92 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + helpfun.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_HELPFUN_H +#define __iLBC_HELPFUN_H + +void autocorr(float *r, /* (o) autocorrelation vector */ + const float *x, /* (i) data vector */ + int N, /* (i) length of data vector */ + int order /* largest lag for calculated + autocorrelations */ + ); + +void window(float *z, /* (o) the windowed data */ + const float *x, /* (i) the original data vector */ + const float *y, /* (i) the window */ + int N /* (i) length of all vectors */ + ); + +void levdurb(float *a, /* (o) lpc coefficient vector starting + with 1.0 */ + float *k, /* (o) reflection coefficients */ + float *r, /* (i) autocorrelation vector */ + int order /* (i) order of lpc filter */ + ); + +void interpolate(float *out, /* (o) the interpolated vector */ + float *in1, /* (i) the first vector for the + interpolation */ + float *in2, /* (i) the second vector for the + interpolation */ + float coef, /* (i) interpolation weights */ + int length /* (i) length of all vectors */ + ); + +void bwexpand(float *out, /* (o) the bandwidth expanded lpc + coefficients */ + float *in, /* (i) the lpc coefficients before bandwidth + expansion */ + float coef, /* (i) the bandwidth expansion factor */ + int length /* (i) the length of lpc coefficient vectors */ + ); + +void vq(float *Xq, /* (o) the quantized vector */ + int *index, /* (o) the quantization index */ + const float *CB, /* (i) the vector quantization codebook */ + float *X, /* (i) the vector to quantize */ + int n_cb, /* (i) the number of vectors in the codebook */ + int dim /* (i) the dimension of all vectors */ + ); + +void SplitVQ(float *qX, /* (o) the quantized vector */ + int *index, /* (o) a vector of indexes for all vector + codebooks in the split */ + float *X, /* (i) the vector to quantize */ + const float *CB, /* (i) the quantizer codebook */ + int nsplit, /* the number of vector splits */ + const int *dim, /* the dimension of X and qX */ + const int *cbsize /* the number of vectors in the codebook */ + ); + + +void sort_sq(float *xq, /* (o) the quantized value */ + int *index, /* (o) the quantization index */ + float x, /* (i) the value to quantize */ + const float *cb, /* (i) the quantization codebook */ + int cb_size /* (i) the size of the quantization codebook */ + ); + +int LSF_check( /* (o) 1 for stable lsf vectors and 0 for + + + + + + nonstable ones */ + float *lsf, /* (i) a table of lsf vectors */ + int dim, /* (i) the dimension of each lsf vector */ + int NoAn /* (i) the number of lsf vectors in the + table */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/hpInput.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/hpInput.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,64 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + + + + + hpInput.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "constants.h" + + /*----------------------------------------------------------------* + * Input high-pass filter + *---------------------------------------------------------------*/ + +void hpInput(float *In, /* (i) vector to filter */ + int len, /* (i) length of vector to filter */ + float *Out, /* (o) the resulting filtered vector */ + float *mem /* (i/o) the filter state */ + ) +{ + int i; + float *pi, *po; + + /* all-zero section */ + + pi = &In[0]; + po = &Out[0]; + for (i = 0; i < len; i++) { + *po = hpi_zero_coefsTbl[0] * (*pi); + *po += hpi_zero_coefsTbl[1] * mem[0]; + *po += hpi_zero_coefsTbl[2] * mem[1]; + + mem[1] = mem[0]; + mem[0] = *pi; + po++; + pi++; + + } + + /* all-pole section */ + + po = &Out[0]; + for (i = 0; i < len; i++) { + *po -= hpi_pole_coefsTbl[1] * mem[2]; + *po -= hpi_pole_coefsTbl[2] * mem[3]; + + mem[3] = mem[2]; + mem[2] = *po; + po++; + + + + + + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/hpInput.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/hpInput.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,22 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + hpInput.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_HPINPUT_H +#define __iLBC_HPINPUT_H + +void hpInput(float *In, /* (i) vector to filter */ + int len, /* (i) length of vector to filter */ + float *Out, /* (o) the resulting filtered vector */ + float *mem /* (i/o) the filter state */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/hpOutput.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/hpOutput.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,55 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + hpOutput.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "constants.h" + + /*----------------------------------------------------------------* + * Output high-pass filter + *---------------------------------------------------------------*/ + +void hpOutput(float *In, /* (i) vector to filter */ + int len, /* (i) length of vector to filter */ + float *Out, /* (o) the resulting filtered vector */ + float *mem /* (i/o) the filter state */ + ) +{ + int i; + float *pi, *po; + + /* all-zero section */ + + pi = &In[0]; + po = &Out[0]; + for (i = 0; i < len; i++) { + *po = hpo_zero_coefsTbl[0] * (*pi); + *po += hpo_zero_coefsTbl[1] * mem[0]; + *po += hpo_zero_coefsTbl[2] * mem[1]; + + mem[1] = mem[0]; + mem[0] = *pi; + po++; + pi++; + + } + + /* all-pole section */ + + po = &Out[0]; + for (i = 0; i < len; i++) { + *po -= hpo_pole_coefsTbl[1] * mem[2]; + *po -= hpo_pole_coefsTbl[2] * mem[3]; + + mem[3] = mem[2]; + mem[2] = *po; + po++; + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/hpOutput.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/hpOutput.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,22 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + hpOutput.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_HPOUTPUT_H +#define __iLBC_HPOUTPUT_H + +void hpOutput(float *In, /* (i) vector to filter */ + int len, /* (i) length of vector to filter */ + float *Out, /* (o) the resulting filtered vector */ + float *mem /* (i/o) the filter state */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iCBConstruct.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iCBConstruct.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,109 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iCBConstruct.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include + +#include "iLBC_define.h" +#include "gainquant.h" +#include "getCBvec.h" + + /*----------------------------------------------------------------* + * Convert the codebook indexes to make the search easier + *---------------------------------------------------------------*/ + + + + + + +void index_conv_enc(int *index /* (i/o) Codebook indexes */ + ) +{ + int k; + + for (k = 1; k < CB_NSTAGES; k++) { + + if ((index[k] >= 108) && (index[k] < 172)) { + index[k] -= 64; + } else if (index[k] >= 236) { + index[k] -= 128; + } else { + /* ERROR */ + } + } +} + +void index_conv_dec(int *index /* (i/o) Codebook indexes */ + ) +{ + int k; + + for (k = 1; k < CB_NSTAGES; k++) { + + if ((index[k] >= 44) && (index[k] < 108)) { + index[k] += 64; + } else if ((index[k] >= 108) && (index[k] < 128)) { + index[k] += 128; + } else { + /* ERROR */ + } + } +} + + /*----------------------------------------------------------------* + * Construct decoded vector from codebook and gains. + *---------------------------------------------------------------*/ + +void iCBConstruct(float *decvector, /* (o) Decoded vector */ + int *index, /* (i) Codebook indices */ + int *gain_index, /* (i) Gain quantization indices */ + float *mem, /* (i) Buffer for codevector construction */ + int lMem, /* (i) Length of buffer */ + int veclen, /* (i) Length of vector */ + int nStages /* (i) Number of codebook stages */ + ) +{ + int j, k; + + + + + + float gain[CB_NSTAGES]; + float cbvec[SUBL]; + + /* gain de-quantization */ + + gain[0] = gaindequant(gain_index[0], 1.0, 32); + if (nStages > 1) { + gain[1] = gaindequant(gain_index[1], (float) fabs(gain[0]), 16); + } + if (nStages > 2) { + gain[2] = gaindequant(gain_index[2], (float) fabs(gain[1]), 8); + } + + /* codebook vector construction and construction of + total vector */ + + getCBvec(cbvec, mem, index[0], lMem, veclen); + for (j = 0; j < veclen; j++) { + decvector[j] = gain[0] * cbvec[j]; + } + if (nStages > 1) { + for (k = 1; k < nStages; k++) { + getCBvec(cbvec, mem, index[k], lMem, veclen); + for (j = 0; j < veclen; j++) { + decvector[j] += gain[k] * cbvec[j]; + } + } + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iCBConstruct.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iCBConstruct.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,36 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iCBConstruct.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + + + + + + ******************************************************************/ + +#ifndef __iLBC_ICBCONSTRUCT_H +#define __iLBC_ICBCONSTRUCT_H + +void index_conv_enc(int *index /* (i/o) Codebook indexes */ + ); + +void index_conv_dec(int *index /* (i/o) Codebook indexes */ + ); + +void iCBConstruct(float *decvector, /* (o) Decoded vector */ + int *index, /* (i) Codebook indices */ + int *gain_index, /* (i) Gain quantization indices */ + float *mem, /* (i) Buffer for codevector construction */ + int lMem, /* (i) Length of buffer */ + int veclen, /* (i) Length of vector */ + int nStages /* (i) Number of codebook stages */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iCBSearch.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iCBSearch.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,487 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iCBSearch.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "iLBC_define.h" +#include "gainquant.h" +#include "createCB.h" +#include "filter.h" +#include "constants.h" + + /*----------------------------------------------------------------* + * Search routine for codebook encoding and gain quantization. + *---------------------------------------------------------------*/ + +void iCBSearch(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) the encoder state structure */ + int *index, /* (o) Codebook indices */ + int *gain_index, /* (o) Gain quantization indices */ + float *intarget, /* (i) Target vector for encoding */ + float *mem, /* (i) Buffer for codebook construction */ + int lMem, /* (i) Length of buffer */ + int lTarget, /* (i) Length of vector */ + int nStages, /* (i) Number of codebook stages */ + float *weightDenum, /* (i) weighting filter coefficients */ + float *weightState, /* (i) weighting filter state */ + int block /* (i) the sub-block number */ + ) +{ + int i, j, icount, stage, best_index, range, counter; + float max_measure, gain, measure, crossDot, ftmp; + float gains[CB_NSTAGES]; + float target[SUBL]; + int base_index, sInd, eInd, base_size; + int sIndAug = 0, eIndAug = 0; + float buf[CB_MEML + SUBL + 2 * LPC_FILTERORDER]; + float invenergy[CB_EXPAND * 128], energy[CB_EXPAND * 128]; + float *pp, *ppi = 0, *ppo = 0, *ppe = 0; + float cbvectors[CB_MEML]; + float tene, cene, cvec[SUBL]; + float aug_vec[SUBL]; + + memset(cvec, 0, SUBL * sizeof(float)); + + /* Determine size of codebook sections */ + + base_size = lMem - lTarget + 1; + + if (lTarget == SUBL) { + base_size = lMem - lTarget + 1 + lTarget / 2; + } + + /* setup buffer for weighting */ + + memcpy(buf, weightState, sizeof(float) * LPC_FILTERORDER); + memcpy(buf + LPC_FILTERORDER, mem, lMem * sizeof(float)); + memcpy(buf + LPC_FILTERORDER + lMem, intarget, + lTarget * sizeof(float)); + + /* weighting */ + + AllPoleFilter(buf + LPC_FILTERORDER, weightDenum, + lMem + lTarget, LPC_FILTERORDER); + + /* Construct the codebook and target needed */ + + memcpy(target, buf + LPC_FILTERORDER + lMem, lTarget * sizeof(float)); + + tene = 0.0; + + + + + + for (i = 0; i < lTarget; i++) { + tene += target[i] * target[i]; + } + + /* Prepare search over one more codebook section. This section + is created by filtering the original buffer with a filter. */ + + filteredCBvecs(cbvectors, buf + LPC_FILTERORDER, lMem); + + /* The Main Loop over stages */ + + for (stage = 0; stage < nStages; stage++) { + + range = search_rangeTbl[block][stage]; + + /* initialize search measure */ + + max_measure = (float) -10000000.0; + gain = (float) 0.0; + best_index = 0; + + /* Compute cross dot product between the target + and the CB memory */ + + crossDot = 0.0; + pp = buf + LPC_FILTERORDER + lMem - lTarget; + for (j = 0; j < lTarget; j++) { + crossDot += target[j] * (*pp++); + } + + if (stage == 0) { + + /* Calculate energy in the first block of + 'lTarget' samples. */ + ppe = energy; + ppi = buf + LPC_FILTERORDER + lMem - lTarget - 1; + ppo = buf + LPC_FILTERORDER + lMem - 1; + + *ppe = 0.0; + pp = buf + LPC_FILTERORDER + lMem - lTarget; + for (j = 0; j < lTarget; j++, pp++) { + *ppe += (*pp) * (*pp); + } + + if (*ppe > 0.0) { + invenergy[0] = (float) 1.0 / (*ppe + EPS); + } else { + invenergy[0] = (float) 0.0; + + + + + + } + ppe++; + + measure = (float) -10000000.0; + + if (crossDot > 0.0) { + measure = crossDot * crossDot * invenergy[0]; + } + } else { + measure = crossDot * crossDot * invenergy[0]; + } + + /* check if measure is better */ + ftmp = crossDot * invenergy[0]; + + if ((measure > max_measure) && (fabs(ftmp) < CB_MAXGAIN)) { + best_index = 0; + max_measure = measure; + gain = ftmp; + } + + /* loop over the main first codebook section, + full search */ + + for (icount = 1; icount < range; icount++) { + + /* calculate measure */ + + crossDot = 0.0; + pp = buf + LPC_FILTERORDER + lMem - lTarget - icount; + + for (j = 0; j < lTarget; j++) { + crossDot += target[j] * (*pp++); + } + + if (stage == 0) { + *ppe++ = energy[icount - 1] + (*ppi) * (*ppi) - (*ppo) * (*ppo); + ppo--; + ppi--; + + if (energy[icount] > 0.0) { + invenergy[icount] = (float) 1.0 / (energy[icount] + EPS); + } else { + invenergy[icount] = (float) 0.0; + } + + + + + + measure = (float) -10000000.0; + + if (crossDot > 0.0) { + measure = crossDot * crossDot * invenergy[icount]; + } + } else { + measure = crossDot * crossDot * invenergy[icount]; + } + + /* check if measure is better */ + ftmp = crossDot * invenergy[icount]; + + if ((measure > max_measure) && (fabs(ftmp) < CB_MAXGAIN)) { + best_index = icount; + max_measure = measure; + gain = ftmp; + } + } + + /* Loop over augmented part in the first codebook + * section, full search. + * The vectors are interpolated. + */ + + if (lTarget == SUBL) { + + /* Search for best possible cb vector and + compute the CB-vectors' energy. */ + searchAugmentedCB(20, 39, stage, base_size - lTarget / 2, + target, buf + LPC_FILTERORDER + lMem, + &max_measure, &best_index, &gain, energy, invenergy); + } + + /* set search range for following codebook sections */ + + base_index = best_index; + + /* unrestricted search */ + + if (CB_RESRANGE == -1) { + sInd = 0; + eInd = range - 1; + sIndAug = 20; + eIndAug = 39; + } + + + + + + + /* restricted search around best index from first + codebook section */ + + else { + /* Initialize search indices */ + sIndAug = 0; + eIndAug = 0; + sInd = base_index - CB_RESRANGE / 2; + eInd = sInd + CB_RESRANGE; + + if (lTarget == SUBL) { + + if (sInd < 0) { + + sIndAug = 40 + sInd; + eIndAug = 39; + sInd = 0; + + } else if (base_index < (base_size - 20)) { + + if (eInd > range) { + sInd -= (eInd - range); + eInd = range; + } + } else { /* base_index >= (base_size-20) */ + + if (sInd < (base_size - 20)) { + sIndAug = 20; + sInd = 0; + eInd = 0; + eIndAug = 19 + CB_RESRANGE; + + if (eIndAug > 39) { + eInd = eIndAug - 39; + eIndAug = 39; + } + } else { + sIndAug = 20 + sInd - (base_size - 20); + eIndAug = 39; + sInd = 0; + eInd = CB_RESRANGE - (eIndAug - sIndAug + 1); + } + } + + } else { /* lTarget = 22 or 23 */ + + if (sInd < 0) { + eInd -= sInd; + + + + + + sInd = 0; + } + + if (eInd > range) { + sInd -= (eInd - range); + eInd = range; + } + } + } + + /* search of higher codebook section */ + + /* index search range */ + counter = sInd; + sInd += base_size; + eInd += base_size; + + + if (stage == 0) { + ppe = energy + base_size; + *ppe = 0.0; + + pp = cbvectors + lMem - lTarget; + for (j = 0; j < lTarget; j++, pp++) { + *ppe += (*pp) * (*pp); + } + + ppi = cbvectors + lMem - 1 - lTarget; + ppo = cbvectors + lMem - 1; + + for (j = 0; j < (range - 1); j++) { + *(ppe + 1) = *ppe + (*ppi) * (*ppi) - (*ppo) * (*ppo); + ppo--; + ppi--; + ppe++; + } + } + + /* loop over search range */ + + for (icount = sInd; icount < eInd; icount++) { + + /* calculate measure */ + + crossDot = 0.0; + pp = cbvectors + lMem - (counter++) - lTarget; + + for (j = 0; j < lTarget; j++) { + + + + + + crossDot += target[j] * (*pp++); + } + + if (energy[icount] > 0.0) { + invenergy[icount] = (float) 1.0 / (energy[icount] + EPS); + } else { + invenergy[icount] = (float) 0.0; + } + + if (stage == 0) { + + measure = (float) -10000000.0; + + if (crossDot > 0.0) { + measure = crossDot * crossDot * invenergy[icount]; + } + } else { + measure = crossDot * crossDot * invenergy[icount]; + } + + /* check if measure is better */ + ftmp = crossDot * invenergy[icount]; + + if ((measure > max_measure) && (fabs(ftmp) < CB_MAXGAIN)) { + best_index = icount; + max_measure = measure; + gain = ftmp; + } + } + + /* Search the augmented CB inside the limited range. */ + + if ((lTarget == SUBL) && (sIndAug != 0)) { + searchAugmentedCB(sIndAug, eIndAug, stage, + 2 * base_size - 20, target, cbvectors + lMem, + &max_measure, &best_index, &gain, energy, invenergy); + } + + /* record best index */ + + index[stage] = best_index; + + /* gain quantization */ + + if (stage == 0) { + + + + + + + if (gain < 0.0) { + gain = 0.0; + } + + if (gain > CB_MAXGAIN) { + gain = (float) CB_MAXGAIN; + } + gain = gainquant(gain, 1.0, 32, &gain_index[stage]); + } else { + if (stage == 1) { + gain = gainquant(gain, (float) fabs(gains[stage - 1]), + 16, &gain_index[stage]); + } else { + gain = gainquant(gain, (float) fabs(gains[stage - 1]), + 8, &gain_index[stage]); + } + } + + /* Extract the best (according to measure) + codebook vector */ + + if (lTarget == (STATE_LEN - iLBCenc_inst->state_short_len)) { + + if (index[stage] < base_size) { + pp = buf + LPC_FILTERORDER + lMem - lTarget - index[stage]; + } else { + pp = cbvectors + lMem - lTarget - index[stage] + base_size; + } + } else { + + if (index[stage] < base_size) { + if (index[stage] < (base_size - 20)) { + pp = buf + LPC_FILTERORDER + lMem - lTarget - index[stage]; + } else { + createAugmentedVec(index[stage] - base_size + 40, + buf + LPC_FILTERORDER + lMem, aug_vec); + pp = aug_vec; + } + } else { + int filterno, position; + + filterno = index[stage] / base_size; + position = index[stage] - filterno * base_size; + + + + + + + + if (position < (base_size - 20)) { + pp = cbvectors + filterno * lMem - lTarget - + index[stage] + filterno * base_size; + } else { + createAugmentedVec(index[stage] - (filterno + 1) * base_size + + 40, cbvectors + filterno * lMem, aug_vec); + pp = aug_vec; + } + } + } + + /* Subtract the best codebook vector, according + to measure, from the target vector */ + + for (j = 0; j < lTarget; j++) { + cvec[j] += gain * (*pp); + target[j] -= gain * (*pp++); + } + + /* record quantized gain */ + + gains[stage] = gain; + + } /* end of Main Loop. for (stage=0;... */ + + /* Gain adjustment for energy matching */ + cene = 0.0; + for (i = 0; i < lTarget; i++) { + cene += cvec[i] * cvec[i]; + } + j = gain_index[0]; + + for (i = gain_index[0]; i < 32; i++) { + ftmp = cene * gain_sq5Tbl[i] * gain_sq5Tbl[i]; + + if ((ftmp < (tene * gains[0] * gains[0])) && + (gain_sq5Tbl[j] < (2.0 * gains[0]))) { + j = i; + } + } + gain_index[0] = j; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iCBSearch.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iCBSearch.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,35 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iCBSearch.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_ICBSEARCH_H +#define __iLBC_ICBSEARCH_H + + + + + + +void iCBSearch(iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i) the encoder state structure */ + int *index, /* (o) Codebook indices */ + int *gain_index, /* (o) Gain quantization indices */ + float *intarget, /* (i) Target vector for encoding */ + float *mem, /* (i) Buffer for codebook construction */ + int lMem, /* (i) Length of buffer */ + int lTarget, /* (i) Length of vector */ + int nStages, /* (i) Number of codebook stages */ + float *weightDenum, /* (i) weighting filter coefficients */ + float *weightState, /* (i) weighting filter state */ + int block /* (i) the sub-block number */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_decode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_decode.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,619 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_decode.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "iLBC_define.h" +#include "StateConstructW.h" +#include "LPCdecode.h" +#include "iCBConstruct.h" +#include "doCPLC.h" +#include "helpfun.h" +#include "constants.h" +#include "packing.h" +#include "string.h" +#include "enhancer.h" +#include "hpOutput.h" +#include "syntFilter.h" + + /*----------------------------------------------------------------* + * Initiation of decoder instance. + *---------------------------------------------------------------*/ + +short initDecode( /* (o) Number of decoded + samples */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) Decoder instance */ + int mode, /* (i) frame size mode */ + int use_enhancer /* (i) 1 to use enhancer + 0 to run without + enhancer */ + ) +{ + int i; + + iLBCdec_inst->mode = mode; + + + + + + if (mode == 30) { + iLBCdec_inst->blockl = BLOCKL_30MS; + iLBCdec_inst->nsub = NSUB_30MS; + iLBCdec_inst->nasub = NASUB_30MS; + iLBCdec_inst->lpc_n = LPC_N_30MS; + iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS; + iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS; + iLBCdec_inst->state_short_len = STATE_SHORT_LEN_30MS; + /* ULP init */ + iLBCdec_inst->ULP_inst = &ULP_30msTbl; + } else if (mode == 20) { + iLBCdec_inst->blockl = BLOCKL_20MS; + iLBCdec_inst->nsub = NSUB_20MS; + iLBCdec_inst->nasub = NASUB_20MS; + iLBCdec_inst->lpc_n = LPC_N_20MS; + iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS; + iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS; + iLBCdec_inst->state_short_len = STATE_SHORT_LEN_20MS; + /* ULP init */ + iLBCdec_inst->ULP_inst = &ULP_20msTbl; + } else { + exit(2); + } + + memset(iLBCdec_inst->syntMem, 0, LPC_FILTERORDER * sizeof(float)); + memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, + LPC_FILTERORDER * sizeof(float)); + + memset(iLBCdec_inst->old_syntdenum, 0, + ((LPC_FILTERORDER + 1) * NSUB_MAX) * sizeof(float)); + for (i = 0; i < NSUB_MAX; i++) + iLBCdec_inst->old_syntdenum[i * (LPC_FILTERORDER + 1)] = 1.0; + + iLBCdec_inst->last_lag = 20; + + iLBCdec_inst->prevLag = 120; + iLBCdec_inst->per = 0.0; + iLBCdec_inst->consPLICount = 0; + iLBCdec_inst->prevPLI = 0; + iLBCdec_inst->prevLpc[0] = 1.0; + memset(iLBCdec_inst->prevLpc + 1, 0, LPC_FILTERORDER * sizeof(float)); + memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX * sizeof(float)); + iLBCdec_inst->seed = 777; + + + + + + + memset(iLBCdec_inst->hpomem, 0, 4 * sizeof(float)); + + iLBCdec_inst->use_enhancer = use_enhancer; + memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL * sizeof(float)); + for (i = 0; i < ENH_NBLOCKS_TOT; i++) + iLBCdec_inst->enh_period[i] = (float) 40.0; + + iLBCdec_inst->prev_enh_pl = 0; + + return (iLBCdec_inst->blockl); +} + + /*----------------------------------------------------------------* + * frame residual decoder function (subrutine to iLBC_decode) + *---------------------------------------------------------------*/ + +void Decode(iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) the decoder state + structure */ + float *decresidual, /* (o) decoded residual frame */ + int start, /* (i) location of start + state */ + int idxForMax, /* (i) codebook index for the + maximum value */ + int *idxVec, /* (i) codebook indexes for the + samples in the start + state */ + float *syntdenum, /* (i) the decoded synthesis + filter coefficients */ + int *cb_index, /* (i) the indexes for the + adaptive codebook */ + int *gain_index, /* (i) the indexes for the + corresponding gains */ + int *extra_cb_index, /* (i) the indexes for the + adaptive codebook part + of start state */ + int *extra_gain_index, /* (i) the indexes for the + corresponding gains */ + int state_first /* (i) 1 if non adaptive part + of start state comes + first 0 if that part + comes last */ + ) +{ + float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; + int k, meml_gotten, Nfor, Nback, i; + int diff, start_pos; + int subcount, subframe; + + + + + + + diff = STATE_LEN - iLBCdec_inst->state_short_len; + + if (state_first == 1) { + start_pos = (start - 1) * SUBL; + } else { + start_pos = (start - 1) * SUBL + diff; + } + + /* decode scalar part of start state */ + + StateConstructW(idxForMax, idxVec, + &syntdenum[(start - 1) * (LPC_FILTERORDER + 1)], + &decresidual[start_pos], iLBCdec_inst->state_short_len); + + + if (state_first) { /* put adaptive part in the end */ + + /* setup memory */ + + memset(mem, 0, + (CB_MEML - iLBCdec_inst->state_short_len) * sizeof(float)); + memcpy(mem + CB_MEML - iLBCdec_inst->state_short_len, + decresidual + start_pos, + iLBCdec_inst->state_short_len * sizeof(float)); + + /* construct decoded vector */ + + iCBConstruct(&decresidual[start_pos + + iLBCdec_inst->state_short_len], extra_cb_index, + extra_gain_index, mem + CB_MEML - stMemLTbl, stMemLTbl, diff, + CB_NSTAGES); + + } else { /* put adaptive part in the beginning */ + + /* create reversed vectors for prediction */ + + for (k = 0; k < diff; k++) { + reverseDecresidual[k] = + decresidual[(start + 1) * SUBL - 1 - + (k + iLBCdec_inst->state_short_len)]; + } + + /* setup memory */ + + meml_gotten = iLBCdec_inst->state_short_len; + for (k = 0; k < meml_gotten; k++) { + mem[CB_MEML - 1 - k] = decresidual[start_pos + k]; + + + + + + } + memset(mem, 0, (CB_MEML - k) * sizeof(float)); + + /* construct decoded vector */ + + iCBConstruct(reverseDecresidual, extra_cb_index, + extra_gain_index, mem + CB_MEML - stMemLTbl, stMemLTbl, + diff, CB_NSTAGES); + + /* get decoded residual from reversed vector */ + + for (k = 0; k < diff; k++) { + decresidual[start_pos - 1 - k] = reverseDecresidual[k]; + } + } + + /* counter for predicted sub-frames */ + + subcount = 0; + + /* forward prediction of sub-frames */ + + Nfor = iLBCdec_inst->nsub - start - 1; + + if (Nfor > 0) { + + /* setup memory */ + + memset(mem, 0, (CB_MEML - STATE_LEN) * sizeof(float)); + memcpy(mem + CB_MEML - STATE_LEN, decresidual + (start - 1) * SUBL, + STATE_LEN * sizeof(float)); + + /* loop over sub-frames to encode */ + + for (subframe = 0; subframe < Nfor; subframe++) { + + /* construct decoded vector */ + + iCBConstruct(&decresidual[(start + 1 + subframe) * SUBL], + cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + mem + CB_MEML - memLfTbl[subcount], + memLfTbl[subcount], SUBL, CB_NSTAGES); + + /* update memory */ + + memcpy(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(float)); + memcpy(mem + CB_MEML - SUBL, + &decresidual[(start + 1 + subframe) * SUBL], + SUBL * sizeof(float)); + + subcount++; + + } + + } + + /* backward prediction of sub-frames */ + + Nback = start - 1; + + if (Nback > 0) { + + /* setup memory */ + + meml_gotten = SUBL * (iLBCdec_inst->nsub + 1 - start); + + if (meml_gotten > CB_MEML) { + meml_gotten = CB_MEML; + } + for (k = 0; k < meml_gotten; k++) { + mem[CB_MEML - 1 - k] = decresidual[(start - 1) * SUBL + k]; + } + memset(mem, 0, (CB_MEML - k) * sizeof(float)); + + /* loop over subframes to decode */ + + for (subframe = 0; subframe < Nback; subframe++) { + + /* construct decoded vector */ + + iCBConstruct(&reverseDecresidual[subframe * SUBL], + cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + mem + CB_MEML - memLfTbl[subcount], memLfTbl[subcount], + SUBL, CB_NSTAGES); + + /* update memory */ + + memcpy(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(float)); + memcpy(mem + CB_MEML - SUBL, + &reverseDecresidual[subframe * SUBL], SUBL * sizeof(float)); + + subcount++; + } + + + + + + /* get decoded residual from reversed vector */ + + for (i = 0; i < SUBL * Nback; i++) + decresidual[SUBL * Nback - i - 1] = reverseDecresidual[i]; + } +} + + /*----------------------------------------------------------------* + * main decoder function + *---------------------------------------------------------------*/ + +void iLBC_decode(float *decblock, /* (o) decoded signal block */ + unsigned char *bytes, /* (i) encoded signal bits */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) the decoder state + structure */ + int mode /* (i) 0: bad packet, PLC, + 1: normal */ + ) +{ + float data[BLOCKL_MAX]; + float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; + float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1]; + float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1]; + int k, i, start, idxForMax, pos, lastpart, ulp; + int lag, ilag; + float cc, maxcc; + int idxVec[STATE_LEN]; + int check; + int gain_index[NASUB_MAX * CB_NSTAGES], extra_gain_index[CB_NSTAGES]; + int cb_index[CB_NSTAGES * NASUB_MAX], extra_cb_index[CB_NSTAGES]; + int lsf_i[LSF_NSPLIT * LPC_N_MAX]; + int state_first; + int last_bit; + unsigned char *pbytes; + float weightdenum[(LPC_FILTERORDER + 1) * NSUB_MAX]; + int order_plus_one; + float syntdenum[NSUB_MAX * (LPC_FILTERORDER + 1)]; + float decresidual[BLOCKL_MAX]; + + if (mode > 0) { /* the data are good */ + + /* decode data */ + + pbytes = bytes; + pos = 0; + + + + + + + /* Set everything to zero before decoding */ + + for (k = 0; k < LSF_NSPLIT * LPC_N_MAX; k++) { + lsf_i[k] = 0; + } + start = 0; + state_first = 0; + idxForMax = 0; + for (k = 0; k < iLBCdec_inst->state_short_len; k++) { + idxVec[k] = 0; + } + for (k = 0; k < CB_NSTAGES; k++) { + extra_cb_index[k] = 0; + } + for (k = 0; k < CB_NSTAGES; k++) { + extra_gain_index[k] = 0; + } + for (i = 0; i < iLBCdec_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + cb_index[i * CB_NSTAGES + k] = 0; + } + } + for (i = 0; i < iLBCdec_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + gain_index[i * CB_NSTAGES + k] = 0; + } + } + + /* loop over ULP classes */ + + for (ulp = 0; ulp < 3; ulp++) { + + /* LSF */ + for (k = 0; k < LSF_NSPLIT * iLBCdec_inst->lpc_n; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos); + packcombine(&lsf_i[k], lastpart, + iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]); + } + + /* Start block info */ + + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->start_bits[ulp], &pos); + packcombine(&start, lastpart, + iLBCdec_inst->ULP_inst->start_bits[ulp]); + + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos); + packcombine(&state_first, lastpart, + iLBCdec_inst->ULP_inst->startfirst_bits[ulp]); + + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos); + packcombine(&idxForMax, lastpart, + iLBCdec_inst->ULP_inst->scale_bits[ulp]); + + for (k = 0; k < iLBCdec_inst->state_short_len; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->state_bits[ulp], &pos); + packcombine(idxVec + k, lastpart, + iLBCdec_inst->ULP_inst->state_bits[ulp]); + } + + /* 23/22 (20ms/30ms) sample block */ + + for (k = 0; k < CB_NSTAGES; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], &pos); + packcombine(extra_cb_index + k, lastpart, + iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]); + } + for (k = 0; k < CB_NSTAGES; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], &pos); + packcombine(extra_gain_index + k, lastpart, + iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]); + } + + /* The two/four (20ms/30ms) 40 sample sub-blocks */ + + for (i = 0; i < iLBCdec_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], &pos); + packcombine(cb_index + i * CB_NSTAGES + k, lastpart, + iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]); + } + } + + for (i = 0; i < iLBCdec_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + unpack(&pbytes, &lastpart, + iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], &pos); + packcombine(gain_index + i * CB_NSTAGES + k, lastpart, + iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]); + } + } + } + /* Extract last bit. If it is 1 this indicates an + empty/lost frame */ + unpack(&pbytes, &last_bit, 1, &pos); + + /* Check for bit errors or empty/lost frames */ + if (start < 1) + mode = 0; + if (iLBCdec_inst->mode == 20 && start > 3) + mode = 0; + if (iLBCdec_inst->mode == 30 && start > 5) + mode = 0; + if (last_bit == 1) + mode = 0; + + if (mode == 1) { /* No bit errors was detected, + continue decoding */ + + /* adjust index */ + index_conv_dec(cb_index); + + /* decode the lsf */ + + SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n); + check = LSF_check(lsfdeq, LPC_FILTERORDER, iLBCdec_inst->lpc_n); + DecoderInterpolateLSF(syntdenum, weightdenum, + lsfdeq, LPC_FILTERORDER, iLBCdec_inst); + + Decode(iLBCdec_inst, decresidual, start, idxForMax, + idxVec, syntdenum, cb_index, gain_index, + extra_cb_index, extra_gain_index, state_first); + + /* preparing the plc for a future loss! */ + + doThePLC(PLCresidual, PLClpc, 0, decresidual, + syntdenum + + (LPC_FILTERORDER + 1) * (iLBCdec_inst->nsub - 1), + (*iLBCdec_inst).last_lag, iLBCdec_inst); + + + + + + + + memcpy(decresidual, PLCresidual, + iLBCdec_inst->blockl * sizeof(float)); + } + + } + + if (mode == 0) { + /* the data is bad (either a PLC call + * was made or a severe bit error was detected) + */ + + /* packet loss conceal */ + + memset(zeros, 0, BLOCKL_MAX * sizeof(float)); + + one[0] = 1; + memset(one + 1, 0, LPC_FILTERORDER * sizeof(float)); + + start = 0; + + doThePLC(PLCresidual, PLClpc, 1, zeros, one, + (*iLBCdec_inst).last_lag, iLBCdec_inst); + memcpy(decresidual, PLCresidual, + iLBCdec_inst->blockl * sizeof(float)); + + order_plus_one = LPC_FILTERORDER + 1; + for (i = 0; i < iLBCdec_inst->nsub; i++) { + memcpy(syntdenum + (i * order_plus_one), PLClpc, + order_plus_one * sizeof(float)); + } + } + + if (iLBCdec_inst->use_enhancer == 1) { + + /* post filtering */ + + iLBCdec_inst->last_lag = + enhancerInterface(data, decresidual, iLBCdec_inst); + + /* synthesis filtering */ + + if (iLBCdec_inst->mode == 20) { + /* Enhancer has 40 samples delay */ + i = 0; + syntFilter(data + i * SUBL, + iLBCdec_inst->old_syntdenum + + (i + iLBCdec_inst->nsub - 1) * (LPC_FILTERORDER + 1), + SUBL, iLBCdec_inst->syntMem); + + + + + + for (i = 1; i < iLBCdec_inst->nsub; i++) { + syntFilter(data + i * SUBL, + syntdenum + (i - 1) * (LPC_FILTERORDER + 1), + SUBL, iLBCdec_inst->syntMem); + } + } else if (iLBCdec_inst->mode == 30) { + /* Enhancer has 80 samples delay */ + for (i = 0; i < 2; i++) { + syntFilter(data + i * SUBL, + iLBCdec_inst->old_syntdenum + + (i + iLBCdec_inst->nsub - 2) * (LPC_FILTERORDER + 1), + SUBL, iLBCdec_inst->syntMem); + } + for (i = 2; i < iLBCdec_inst->nsub; i++) { + syntFilter(data + i * SUBL, + syntdenum + (i - 2) * (LPC_FILTERORDER + 1), SUBL, + iLBCdec_inst->syntMem); + } + } + + } else { + + /* Find last lag */ + lag = 20; + maxcc = xCorrCoef(&decresidual[BLOCKL_MAX - ENH_BLOCKL], + &decresidual[BLOCKL_MAX - ENH_BLOCKL - lag], ENH_BLOCKL); + + for (ilag = 21; ilag < 120; ilag++) { + cc = xCorrCoef(&decresidual[BLOCKL_MAX - ENH_BLOCKL], + &decresidual[BLOCKL_MAX - ENH_BLOCKL - ilag], ENH_BLOCKL); + + if (cc > maxcc) { + maxcc = cc; + lag = ilag; + } + } + iLBCdec_inst->last_lag = lag; + + /* copy data and run synthesis filter */ + + memcpy(data, decresidual, iLBCdec_inst->blockl * sizeof(float)); + for (i = 0; i < iLBCdec_inst->nsub; i++) { + syntFilter(data + i * SUBL, + syntdenum + i * (LPC_FILTERORDER + 1), SUBL, + iLBCdec_inst->syntMem); + } + + + + + + } + + /* high pass filtering on output if desired, otherwise + copy to out */ + + hpOutput(data, iLBCdec_inst->blockl, decblock, iLBCdec_inst->hpomem); + + /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float)); */ + + memcpy(iLBCdec_inst->old_syntdenum, syntdenum, + iLBCdec_inst->nsub * (LPC_FILTERORDER + 1) * sizeof(float)); + + iLBCdec_inst->prev_enh_pl = 0; + + if (mode == 0) { /* PLC was used */ + iLBCdec_inst->prev_enh_pl = 1; + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_decode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_decode.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,35 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_decode.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_ILBCDECODE_H +#define __iLBC_ILBCDECODE_H + +#include "iLBC_define.h" + +short initDecode( /* (o) Number of decoded + samples */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) Decoder instance */ + int mode, /* (i) frame size mode */ + int use_enhancer /* (i) 1 to use enhancer + 0 to run without + enhancer */ + ); + +void iLBC_decode(float *decblock, /* (o) decoded signal block */ + unsigned char *bytes, /* (i) encoded signal bits */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) the decoder state + structure */ + int mode /* (i) 0: bad packet, PLC, + 1: normal */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_define.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_define.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,216 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_define.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ +#include + +#ifndef __iLBC_ILBCDEFINE_H +#define __iLBC_ILBCDEFINE_H + + /* general codec settings */ + +#define FS (float)8000.0 +#define BLOCKL_20MS 160 +#define BLOCKL_30MS 240 +#define BLOCKL_MAX 240 +#define NSUB_20MS 4 +#define NSUB_30MS 6 +#define NSUB_MAX 6 +#define NASUB_20MS 2 + + + + + +#define NASUB_30MS 4 +#define NASUB_MAX 4 +#define SUBL 40 +#define STATE_LEN 80 +#define STATE_SHORT_LEN_30MS 58 +#define STATE_SHORT_LEN_20MS 57 + + /* LPC settings */ + +#define LPC_FILTERORDER 10 +#define LPC_CHIRP_SYNTDENUM (float)0.9025 +#define LPC_CHIRP_WEIGHTDENUM (float)0.4222 +#define LPC_LOOKBACK 60 +#define LPC_N_20MS 1 +#define LPC_N_30MS 2 +#define LPC_N_MAX 2 +#define LPC_ASYMDIFF 20 +#define LPC_BW (float)60.0 +#define LPC_WN (float)1.0001 +#define LSF_NSPLIT 3 +#define LSF_NUMBER_OF_STEPS 4 +#define LPC_HALFORDER (LPC_FILTERORDER/2) + + /* cb settings */ + +#define CB_NSTAGES 3 +#define CB_EXPAND 2 +#define CB_MEML 147 +#define CB_FILTERLEN 2*4 +#define CB_HALFFILTERLEN 4 +#define CB_RESRANGE 34 +#define CB_MAXGAIN (float)1.3 + + /* enhancer */ + +#define ENH_BLOCKL 80 /* block length */ +#define ENH_BLOCKL_HALF (ENH_BLOCKL/2) +#define ENH_HL 3 /* 2*ENH_HL+1 is number blocks + in said second sequence */ +#define ENH_SLOP 2 /* max difference estimated and + correct pitch period */ +#define ENH_PLOCSL 20 /* pitch-estimates and pitch- + locations buffer length */ +#define ENH_OVERHANG 2 +#define ENH_UPS0 4 /* upsampling rate */ +#define ENH_FL0 3 /* 2*FLO+1 is the length of + each filter */ +#define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0) + + + + + +#define ENH_CORRDIM (2*ENH_SLOP+1) +#define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL) +#define ENH_NBLOCKS_EXTRA 5 +#define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + + ENH_NBLOCKS_EXTRA */ +#define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL +#define ENH_ALPHA0 (float)0.05 + + /* Down sampling */ + +#define FILTERORDER_DS 7 +#define DELAY_DS 3 +#define FACTOR_DS 2 + + /* bit stream defs */ + +#define NO_OF_BYTES_20MS 38 +#define NO_OF_BYTES_30MS 50 +#define NO_OF_WORDS_20MS 19 +#define NO_OF_WORDS_30MS 25 +#define STATE_BITS 3 +#define BYTE_LEN 8 +#define ULP_CLASSES 3 + + /* help parameters */ + +#define FLOAT_MAX (float)1.0e37 +#define EPS (float)2.220446049250313e-016 +#define PI (float)3.14159265358979323846 +#define MIN_SAMPLE -32768 +#define MAX_SAMPLE 32767 +#define TWO_PI (float)6.283185307 +#define PI2 (float)0.159154943 + + /* type definition encoder instance */ +typedef struct iLBC_ULP_Inst_t_ { + int lsf_bits[6][ULP_CLASSES + 2]; + int start_bits[ULP_CLASSES + 2]; + int startfirst_bits[ULP_CLASSES + 2]; + int scale_bits[ULP_CLASSES + 2]; + int state_bits[ULP_CLASSES + 2]; + int extra_cb_index[CB_NSTAGES][ULP_CLASSES + 2]; + int extra_cb_gain[CB_NSTAGES][ULP_CLASSES + 2]; + int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES + 2]; + int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES + 2]; +} iLBC_ULP_Inst_t; + + /* type definition encoder instance */ + + + + + +typedef struct iLBC_Enc_Inst_t_ { + + /* flag for frame size mode */ + int mode; + + /* basic parameters for different frame sizes */ + int blockl; + int nsub; + int nasub; + int no_of_bytes, no_of_words; + int lpc_n; + int state_short_len; + const iLBC_ULP_Inst_t *ULP_inst; + + /* analysis filter state */ + float anaMem[LPC_FILTERORDER]; + + /* old lsf parameters for interpolation */ + float lsfold[LPC_FILTERORDER]; + float lsfdeqold[LPC_FILTERORDER]; + + /* signal buffer for LP analysis */ + float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX]; + + /* state of input HP filter */ + float hpimem[4]; + +} iLBC_Enc_Inst_t; + + /* type definition decoder instance */ +typedef struct iLBC_Dec_Inst_t_ { + + /* flag for frame size mode */ + int mode; + + /* basic parameters for different frame sizes */ + int blockl; + int nsub; + int nasub; + int no_of_bytes, no_of_words; + int lpc_n; + int state_short_len; + const iLBC_ULP_Inst_t *ULP_inst; + + /* synthesis filter state */ + float syntMem[LPC_FILTERORDER]; + + /* old LSF for interpolation */ + + + + + + float lsfdeqold[LPC_FILTERORDER]; + + /* pitch lag estimated in enhancer and used in PLC */ + int last_lag; + + /* PLC state information */ + int prevLag, consPLICount, prevPLI, prev_enh_pl; + float prevLpc[LPC_FILTERORDER + 1]; + float prevResidual[NSUB_MAX * SUBL]; + float per; + unsigned long seed; + + /* previous synthesis filter parameters */ + float old_syntdenum[(LPC_FILTERORDER + 1) * NSUB_MAX]; + + /* state of output HP filter */ + float hpomem[4]; + + /* enhancer state information */ + int use_enhancer; + float enh_buf[ENH_BUFL]; + float enh_period[ENH_NBLOCKS_TOT]; + +} iLBC_Dec_Inst_t; + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_encode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_encode.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,507 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_encode.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include +#include + +#include "iLBC_define.h" +#include "LPCencode.h" +#include "FrameClassify.h" +#include "StateSearchW.h" +#include "StateConstructW.h" +#include "helpfun.h" +#include "constants.h" +#include "packing.h" +#include "iCBSearch.h" +#include "iCBConstruct.h" +#include "hpInput.h" +#include "anaFilter.h" +#include "syntFilter.h" + + /*----------------------------------------------------------------* + * Initiation of encoder instance. + *---------------------------------------------------------------*/ + +short initEncode( /* (o) Number of bytes + encoded */ + iLBC_Enc_Inst_t * iLBCenc_inst, /* (i/o) Encoder instance */ + int mode /* (i) frame size mode */ + ) +{ + iLBCenc_inst->mode = mode; + if (mode == 30) { + iLBCenc_inst->blockl = BLOCKL_30MS; + iLBCenc_inst->nsub = NSUB_30MS; + iLBCenc_inst->nasub = NASUB_30MS; + iLBCenc_inst->lpc_n = LPC_N_30MS; + iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS; + iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS; + + + + + + iLBCenc_inst->state_short_len = STATE_SHORT_LEN_30MS; + /* ULP init */ + iLBCenc_inst->ULP_inst = &ULP_30msTbl; + } else if (mode == 20) { + iLBCenc_inst->blockl = BLOCKL_20MS; + iLBCenc_inst->nsub = NSUB_20MS; + iLBCenc_inst->nasub = NASUB_20MS; + iLBCenc_inst->lpc_n = LPC_N_20MS; + iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS; + iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS; + iLBCenc_inst->state_short_len = STATE_SHORT_LEN_20MS; + /* ULP init */ + iLBCenc_inst->ULP_inst = &ULP_20msTbl; + } else { + exit(2); + } + + memset((*iLBCenc_inst).anaMem, 0, LPC_FILTERORDER * sizeof(float)); + memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, + LPC_FILTERORDER * sizeof(float)); + memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, + LPC_FILTERORDER * sizeof(float)); + memset((*iLBCenc_inst).lpc_buffer, 0, + (LPC_LOOKBACK + BLOCKL_MAX) * sizeof(float)); + memset((*iLBCenc_inst).hpimem, 0, 4 * sizeof(float)); + + return (iLBCenc_inst->no_of_bytes); +} + + /*----------------------------------------------------------------* + * main encoder function + *---------------------------------------------------------------*/ + +void iLBC_encode(unsigned char *bytes, /* (o) encoded data bits iLBC */ + float *block, /* (o) speech vector to + encode */ + iLBC_Enc_Inst_t * iLBCenc_inst /* (i/o) the general encoder + state */ + ) +{ + + float data[BLOCKL_MAX]; + float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX]; + + int start, idxForMax, idxVec[STATE_LEN]; + + + + + + float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; + int n, k, meml_gotten, Nfor, Nback, i, pos; + int gain_index[CB_NSTAGES * NASUB_MAX], extra_gain_index[CB_NSTAGES]; + int cb_index[CB_NSTAGES * NASUB_MAX], extra_cb_index[CB_NSTAGES]; + int lsf_i[LSF_NSPLIT * LPC_N_MAX]; + unsigned char *pbytes; + int diff, start_pos, state_first; + float en1, en2; + int index, ulp, firstpart; + int subcount, subframe; + float weightState[LPC_FILTERORDER]; + float syntdenum[NSUB_MAX * (LPC_FILTERORDER + 1)]; + float weightdenum[NSUB_MAX * (LPC_FILTERORDER + 1)]; + float decresidual[BLOCKL_MAX]; + + /* high pass filtering of input signal if such is not done + prior to calling this function */ + + hpInput(block, iLBCenc_inst->blockl, data, (*iLBCenc_inst).hpimem); + + /* otherwise simply copy */ + + /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float)); */ + + /* LPC of hp filtered input data */ + + LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst); + + + /* inverse filter to get residual */ + + for (n = 0; n < iLBCenc_inst->nsub; n++) { + anaFilter(&data[n * SUBL], &syntdenum[n * (LPC_FILTERORDER + 1)], + SUBL, &residual[n * SUBL], iLBCenc_inst->anaMem); + } + + /* find state location */ + + start = FrameClassify(iLBCenc_inst, residual); + + /* check if state should be in first or last part of the + two subframes */ + + diff = STATE_LEN - iLBCenc_inst->state_short_len; + en1 = 0; + index = (start - 1) * SUBL; + + + + + + for (i = 0; i < iLBCenc_inst->state_short_len; i++) { + en1 += residual[index + i] * residual[index + i]; + } + en2 = 0; + index = (start - 1) * SUBL + diff; + for (i = 0; i < iLBCenc_inst->state_short_len; i++) { + en2 += residual[index + i] * residual[index + i]; + } + + + if (en1 > en2) { + state_first = 1; + start_pos = (start - 1) * SUBL; + } else { + state_first = 0; + start_pos = (start - 1) * SUBL + diff; + } + + /* scalar quantization of state */ + + StateSearchW(iLBCenc_inst, &residual[start_pos], + &syntdenum[(start - 1) * (LPC_FILTERORDER + 1)], + &weightdenum[(start - 1) * (LPC_FILTERORDER + 1)], &idxForMax, + idxVec, iLBCenc_inst->state_short_len, state_first); + + StateConstructW(idxForMax, idxVec, + &syntdenum[(start - 1) * (LPC_FILTERORDER + 1)], + &decresidual[start_pos], iLBCenc_inst->state_short_len); + + /* predictive quantization in state */ + + if (state_first) { /* put adaptive part in the end */ + + /* setup memory */ + + memset(mem, 0, + (CB_MEML - iLBCenc_inst->state_short_len) * sizeof(float)); + memcpy(mem + CB_MEML - iLBCenc_inst->state_short_len, + decresidual + start_pos, + iLBCenc_inst->state_short_len * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + /* encode sub-frames */ + + iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, + &residual[start_pos + iLBCenc_inst->state_short_len], + mem + CB_MEML - stMemLTbl, + stMemLTbl, diff, CB_NSTAGES, + &weightdenum[start * (LPC_FILTERORDER + 1)], weightState, 0); + + /* construct decoded vector */ + + iCBConstruct(&decresidual[start_pos + + iLBCenc_inst->state_short_len], extra_cb_index, + extra_gain_index, mem + CB_MEML - stMemLTbl, stMemLTbl, diff, + CB_NSTAGES); + + } else { /* put adaptive part in the beginning */ + + /* create reversed vectors for prediction */ + + for (k = 0; k < diff; k++) { + reverseResidual[k] = residual[(start + 1) * SUBL - 1 + - (k + iLBCenc_inst->state_short_len)]; + } + + /* setup memory */ + + meml_gotten = iLBCenc_inst->state_short_len; + for (k = 0; k < meml_gotten; k++) { + mem[CB_MEML - 1 - k] = decresidual[start_pos + k]; + } + memset(mem, 0, (CB_MEML - k) * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + /* encode sub-frames */ + + iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, + reverseResidual, mem + CB_MEML - stMemLTbl, stMemLTbl, + diff, CB_NSTAGES, + &weightdenum[(start - 1) * (LPC_FILTERORDER + 1)], + weightState, 0); + + /* construct decoded vector */ + + iCBConstruct(reverseDecresidual, extra_cb_index, + extra_gain_index, mem + CB_MEML - stMemLTbl, stMemLTbl, + diff, CB_NSTAGES); + + /* get decoded residual from reversed vector */ + + for (k = 0; k < diff; k++) { + decresidual[start_pos - 1 - k] = reverseDecresidual[k]; + + + + + + } + } + + /* counter for predicted sub-frames */ + + subcount = 0; + + /* forward prediction of sub-frames */ + + Nfor = iLBCenc_inst->nsub - start - 1; + + + if (Nfor > 0) { + + /* setup memory */ + + memset(mem, 0, (CB_MEML - STATE_LEN) * sizeof(float)); + memcpy(mem + CB_MEML - STATE_LEN, decresidual + (start - 1) * SUBL, + STATE_LEN * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + /* loop over sub-frames to encode */ + + for (subframe = 0; subframe < Nfor; subframe++) { + + /* encode sub-frame */ + + iCBSearch(iLBCenc_inst, cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + &residual[(start + 1 + subframe) * SUBL], + mem + CB_MEML - memLfTbl[subcount], + memLfTbl[subcount], SUBL, CB_NSTAGES, + &weightdenum[(start + 1 + subframe) * + (LPC_FILTERORDER + 1)], weightState, subcount + 1); + + /* construct decoded vector */ + + iCBConstruct(&decresidual[(start + 1 + subframe) * SUBL], + cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + mem + CB_MEML - memLfTbl[subcount], + memLfTbl[subcount], SUBL, CB_NSTAGES); + + /* update memory */ + + memcpy(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(float)); + memcpy(mem + CB_MEML - SUBL, + &decresidual[(start + 1 + subframe) * SUBL], + SUBL * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + subcount++; + } + } + + + /* backward prediction of sub-frames */ + + Nback = start - 1; + + + if (Nback > 0) { + + /* create reverse order vectors */ + + for (n = 0; n < Nback; n++) { + for (k = 0; k < SUBL; k++) { + reverseResidual[n * SUBL + k] = + residual[(start - 1) * SUBL - 1 - n * SUBL - k]; + reverseDecresidual[n * SUBL + k] = + decresidual[(start - 1) * SUBL - 1 - n * SUBL - k]; + } + } + + /* setup memory */ + + meml_gotten = SUBL * (iLBCenc_inst->nsub + 1 - start); + + + if (meml_gotten > CB_MEML) { + meml_gotten = CB_MEML; + } + for (k = 0; k < meml_gotten; k++) { + mem[CB_MEML - 1 - k] = decresidual[(start - 1) * SUBL + k]; + } + memset(mem, 0, (CB_MEML - k) * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + /* loop over sub-frames to encode */ + + for (subframe = 0; subframe < Nback; subframe++) { + + /* encode sub-frame */ + + iCBSearch(iLBCenc_inst, cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + &reverseResidual[subframe * SUBL], + mem + CB_MEML - memLfTbl[subcount], + memLfTbl[subcount], SUBL, CB_NSTAGES, + &weightdenum[(start - 2 - subframe) * + (LPC_FILTERORDER + 1)], weightState, subcount + 1); + + /* construct decoded vector */ + + iCBConstruct(&reverseDecresidual[subframe * SUBL], + cb_index + subcount * CB_NSTAGES, + gain_index + subcount * CB_NSTAGES, + mem + CB_MEML - memLfTbl[subcount], + memLfTbl[subcount], SUBL, CB_NSTAGES); + + /* update memory */ + + memcpy(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(float)); + memcpy(mem + CB_MEML - SUBL, + &reverseDecresidual[subframe * SUBL], SUBL * sizeof(float)); + memset(weightState, 0, LPC_FILTERORDER * sizeof(float)); + + subcount++; + + } + + /* get decoded residual from reversed vector */ + + for (i = 0; i < SUBL * Nback; i++) { + decresidual[SUBL * Nback - i - 1] = reverseDecresidual[i]; + } + } + /* end encoding part */ + + /* adjust index */ + index_conv_enc(cb_index); + + /* pack bytes */ + + pbytes = bytes; + pos = 0; + + /* loop over the 3 ULP classes */ + + for (ulp = 0; ulp < 3; ulp++) { + + + + + + + /* LSF */ + for (k = 0; k < LSF_NSPLIT * iLBCenc_inst->lpc_n; k++) { + packsplit(&lsf_i[k], &firstpart, &lsf_i[k], + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp] + + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp + 1] + + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos); + } + + /* Start block info */ + + packsplit(&start, &firstpart, &start, + iLBCenc_inst->ULP_inst->start_bits[ulp], + iLBCenc_inst->ULP_inst->start_bits[ulp] + + iLBCenc_inst->ULP_inst->start_bits[ulp + 1] + + iLBCenc_inst->ULP_inst->start_bits[ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->start_bits[ulp], &pos); + + packsplit(&state_first, &firstpart, &state_first, + iLBCenc_inst->ULP_inst->startfirst_bits[ulp], + iLBCenc_inst->ULP_inst->startfirst_bits[ulp] + + iLBCenc_inst->ULP_inst->startfirst_bits[ulp + 1] + + iLBCenc_inst->ULP_inst->startfirst_bits[ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos); + + packsplit(&idxForMax, &firstpart, &idxForMax, + iLBCenc_inst->ULP_inst->scale_bits[ulp], + iLBCenc_inst->ULP_inst->scale_bits[ulp] + + iLBCenc_inst->ULP_inst->scale_bits[ulp + 1] + + iLBCenc_inst->ULP_inst->scale_bits[ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos); + + for (k = 0; k < iLBCenc_inst->state_short_len; k++) { + packsplit(idxVec + k, &firstpart, idxVec + k, + iLBCenc_inst->ULP_inst->state_bits[ulp], + iLBCenc_inst->ULP_inst->state_bits[ulp] + + iLBCenc_inst->ULP_inst->state_bits[ulp + 1] + + iLBCenc_inst->ULP_inst->state_bits[ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->state_bits[ulp], &pos); + } + + + + + + + /* 23/22 (20ms/30ms) sample block */ + + for (k = 0; k < CB_NSTAGES; k++) { + packsplit(extra_cb_index + k, &firstpart, + extra_cb_index + k, + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp] + + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp + 1] + + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], &pos); + } + + for (k = 0; k < CB_NSTAGES; k++) { + packsplit(extra_gain_index + k, &firstpart, + extra_gain_index + k, + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp] + + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp + 1] + + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], &pos); + } + + /* The two/four (20ms/30ms) 40 sample sub-blocks */ + + for (i = 0; i < iLBCenc_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + packsplit(cb_index + i * CB_NSTAGES + k, &firstpart, + cb_index + i * CB_NSTAGES + k, + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp] + + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp + 1] + + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], &pos); + } + } + + for (i = 0; i < iLBCenc_inst->nasub; i++) { + for (k = 0; k < CB_NSTAGES; k++) { + packsplit(gain_index + i * CB_NSTAGES + k, &firstpart, + gain_index + i * CB_NSTAGES + k, + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp] + + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp + 1] + + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp + 2]); + dopack(&pbytes, firstpart, + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], &pos); + } + } + } + + /* set the last bit to zero (otherwise the decoder + will treat it as a lost frame) */ + dopack(&pbytes, 0, 1, &pos); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_encode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_encode.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,31 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_encode.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_ILBCENCODE_H +#define __iLBC_ILBCENCODE_H + +#include "iLBC_define.h" + +short initEncode( /* (o) Number of bytes + encoded */ + iLBC_Enc_Inst_t * iLBCenc_inst, /* (i/o) Encoder instance */ + int mode /* (i) frame size mode */ + ); + +void iLBC_encode(unsigned char *bytes, /* (o) encoded data bits iLBC */ + float *block, /* (o) speech vector to + encode */ + iLBC_Enc_Inst_t * iLBCenc_inst /* (i/o) the general encoder + state */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/iLBC_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/iLBC_test.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,304 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + iLBC_test.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include +#include +#include +#include "iLBC_define.h" +#include "iLBC_encode.h" +#include "iLBC_decode.h" + + /* Runtime statistics */ +#include + +#define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2) + + /*----------------------------------------------------------------* + * Encoder interface function + + + + + + *---------------------------------------------------------------*/ + +short encode( /* (o) Number of bytes encoded */ + iLBC_Enc_Inst_t * iLBCenc_inst, + /* (i/o) Encoder instance */ + short *encoded_data, /* (o) The encoded bytes */ + short *data /* (i) The signal block to encode */ + ) +{ + float block[BLOCKL_MAX]; + int k; + + /* convert signal to float */ + + for (k = 0; k < iLBCenc_inst->blockl; k++) + block[k] = (float) data[k]; + + /* do the actual encoding */ + + iLBC_encode((unsigned char *) encoded_data, block, iLBCenc_inst); + + + return (iLBCenc_inst->no_of_bytes); +} + + /*----------------------------------------------------------------* + * Decoder interface function + *---------------------------------------------------------------*/ + +short decode( /* (o) Number of decoded samples */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) Decoder instance */ + short *decoded_data, /* (o) Decoded signal block */ + short *encoded_data, /* (i) Encoded bytes */ + short mode /* (i) 0=PL, 1=Normal */ + ) +{ + int k; + float decblock[BLOCKL_MAX], dtmp; + + /* check if mode is valid */ + + if (mode < 0 || mode > 1) { + printf("\nERROR - Wrong mode - 0, 1 allowed\n"); + exit(3); + } + + /* do actual decoding of block */ + + iLBC_decode(decblock, (unsigned char *) encoded_data, + iLBCdec_inst, mode); + + /* convert to short */ + + + + + + for (k = 0; k < iLBCdec_inst->blockl; k++) { + dtmp = decblock[k]; + + if (dtmp < MIN_SAMPLE) + dtmp = MIN_SAMPLE; + else if (dtmp > MAX_SAMPLE) + dtmp = MAX_SAMPLE; + decoded_data[k] = (short) dtmp; + } + + return (iLBCdec_inst->blockl); +} + + /*---------------------------------------------------------------* + * Main program to test iLBC encoding and decoding + * + * Usage: + * exefile_name.exe + * + * : Input file, speech for encoder (16-bit pcm file) + * : Bit stream output from the encoder + * : Output file, decoded speech (16-bit pcm file) + * : Bit error file, optional (16-bit) + * 1 - Packet received correctly + * 0 - Packet Lost + * + *--------------------------------------------------------------*/ + +int main(int argc, char *argv[]) +{ + + /* Runtime statistics */ + + float starttime; + float runtime; + float outtime; + + FILE *ifileid, *efileid, *ofileid, *cfileid; + short data[BLOCKL_MAX]; + short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX]; + int len; + short pli, mode; + int blockcount = 0; + int packetlosscount = 0; + + /* Create structs */ + iLBC_Enc_Inst_t Enc_Inst; + iLBC_Dec_Inst_t Dec_Inst; + + + + + + /* get arguments and open files */ + + if ((argc != 5) && (argc != 6)) { + fprintf(stderr, + "\n*-----------------------------------------------*\n"); + fprintf(stderr, + " %s <20,30> input encoded decoded (channel)\n\n", argv[0]); + fprintf(stderr, + " mode : Frame size for the encoding/decoding\n"); + fprintf(stderr, " 20 - 20 ms\n"); + fprintf(stderr, " 30 - 30 ms\n"); + fprintf(stderr, + " input : Speech for encoder (16-bit pcm file)\n"); + fprintf(stderr, " encoded : Encoded bit stream\n"); + fprintf(stderr, " decoded : Decoded speech (16-bit pcm file)\n"); + fprintf(stderr, + " channel : Packet loss pattern, optional (16-bit)\n"); + fprintf(stderr, + " 1 - Packet received correctly\n"); + fprintf(stderr, " 0 - Packet Lost\n"); + fprintf(stderr, + "*-----------------------------------------------*\n\n"); + exit(1); + } + mode = atoi(argv[1]); + if (mode != 20 && mode != 30) { + fprintf(stderr, "Wrong mode %s, must be 20, or 30\n", argv[1]); + exit(2); + } + if ((ifileid = fopen(argv[2], "rb")) == NULL) { + fprintf(stderr, "Cannot open input file %s\n", argv[2]); + exit(2); + } + if ((efileid = fopen(argv[3], "wb")) == NULL) { + fprintf(stderr, "Cannot open encoded file %s\n", argv[3]); + exit(1); + } + if ((ofileid = fopen(argv[4], "wb")) == NULL) { + fprintf(stderr, "Cannot open decoded file %s\n", argv[4]); + exit(1); + } + if (argc == 6) { + if ((cfileid = fopen(argv[5], "rb")) == NULL) { + fprintf(stderr, "Cannot open channel file %s\n", argv[5]); + exit(1); + } + } else { + cfileid = NULL; + } + + /* print info */ + + fprintf(stderr, "\n"); + fprintf(stderr, + "*---------------------------------------------------*\n"); + fprintf(stderr, + "* *\n"); + fprintf(stderr, + "* iLBC test program *\n"); + fprintf(stderr, + "* *\n"); + fprintf(stderr, + "* *\n"); + fprintf(stderr, + "*---------------------------------------------------*\n"); + fprintf(stderr, "\nMode : %2d ms\n", mode); + fprintf(stderr, "Input file : %s\n", argv[2]); + fprintf(stderr, "Encoded file : %s\n", argv[3]); + fprintf(stderr, "Output file : %s\n", argv[4]); + if (argc == 6) { + fprintf(stderr, "Channel file : %s\n", argv[5]); + } + fprintf(stderr, "\n"); + + /* Initialization */ + + initEncode(&Enc_Inst, mode); + initDecode(&Dec_Inst, mode, 1); + + /* Runtime statistics */ + + starttime = clock() / (float) CLOCKS_PER_SEC; + + /* loop over input blocks */ + + while (fread(data, sizeof(short), Enc_Inst.blockl, ifileid) == + Enc_Inst.blockl) { + + blockcount++; + + /* encoding */ + + + + + + fprintf(stderr, "--- Encoding block %i --- ", blockcount); + len = encode(&Enc_Inst, encoded_data, data); + fprintf(stderr, "\r"); + + /* write byte file */ + + fwrite(encoded_data, sizeof(unsigned char), len, efileid); + + /* get channel data if provided */ + if (argc == 6) { + if (fread(&pli, sizeof(short), 1, cfileid)) { + if ((pli != 0) && (pli != 1)) { + fprintf(stderr, "Error in channel file\n"); + exit(0); + } + if (pli == 0) { + /* Packet loss -> remove info from frame */ + memset(encoded_data, 0, sizeof(short) * ILBCNOOFWORDS_MAX); + packetlosscount++; + } + } else { + fprintf(stderr, "Error. Channel file too short\n"); + exit(0); + } + } else { + pli = 1; + } + + /* decoding */ + + fprintf(stderr, "--- Decoding block %i --- ", blockcount); + + len = decode(&Dec_Inst, decoded_data, encoded_data, pli); + fprintf(stderr, "\r"); + + /* write output file */ + + fwrite(decoded_data, sizeof(short), len, ofileid); + } + + /* Runtime statistics */ + + runtime = (float) (clock() / (float) CLOCKS_PER_SEC - starttime); + outtime = (float) ((float) blockcount * (float) mode / 1000.0); + printf("\n\nLength of speech file: %.1f s\n", outtime); + printf("Packet loss : %.1f%%\n", + 100.0 * (float) packetlosscount / (float) blockcount); + + + + + + printf("Time to run iLBC :"); + printf(" %.1f s (%.1f %% of realtime)\n\n", runtime, + (100 * runtime / outtime)); + + /* close files */ + + fclose(ifileid); + fclose(efileid); + fclose(ofileid); + if (argc == 6) { + fclose(cfileid); + } + return (0); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/lsf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/lsf.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,269 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + lsf.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include + + + + + +#include + +#include "iLBC_define.h" + + /*----------------------------------------------------------------* + * conversion from lpc coefficients to lsf coefficients + *---------------------------------------------------------------*/ + +void a2lsf(float *freq, /* (o) lsf coefficients */ + float *a /* (i) lpc coefficients */ + ) +{ + float steps[LSF_NUMBER_OF_STEPS] = + { (float) 0.00635, (float) 0.003175, (float) 0.0015875, + (float) 0.00079375 + }; + float step; + int step_idx; + int lsp_index; + float p[LPC_HALFORDER]; + float q[LPC_HALFORDER]; + float p_pre[LPC_HALFORDER]; + float q_pre[LPC_HALFORDER]; + float old_p, old_q, *old; + float *pq_coef; + float omega, old_omega; + int i; + float hlp, hlp1, hlp2, hlp3, hlp4, hlp5; + + for (i = 0; i < LPC_HALFORDER; i++) { + p[i] = (float) -1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]); + q[i] = a[LPC_FILTERORDER - i] - a[i + 1]; + } + + p_pre[0] = (float) -1.0 - p[0]; + p_pre[1] = -p_pre[0] - p[1]; + p_pre[2] = -p_pre[1] - p[2]; + p_pre[3] = -p_pre[2] - p[3]; + p_pre[4] = -p_pre[3] - p[4]; + p_pre[4] = p_pre[4] / 2; + + q_pre[0] = (float) 1.0 - q[0]; + q_pre[1] = q_pre[0] - q[1]; + q_pre[2] = q_pre[1] - q[2]; + q_pre[3] = q_pre[2] - q[3]; + q_pre[4] = q_pre[3] - q[4]; + q_pre[4] = q_pre[4] / 2; + + omega = 0.0; + + + + + + old_omega = 0.0; + + old_p = FLOAT_MAX; + old_q = FLOAT_MAX; + + /* Here we loop through lsp_index to find all the + LPC_FILTERORDER roots for omega. */ + + for (lsp_index = 0; lsp_index < LPC_FILTERORDER; lsp_index++) { + + /* Depending on lsp_index being even or odd, we + alternatively solve the roots for the two LSP equations. */ + + + if ((lsp_index & 0x1) == 0) { + pq_coef = p_pre; + old = &old_p; + } else { + pq_coef = q_pre; + old = &old_q; + } + + /* Start with low resolution grid */ + + for (step_idx = 0, step = steps[step_idx]; + step_idx < LSF_NUMBER_OF_STEPS;) { + + /* cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + + pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */ + + hlp = (float) cos(omega * TWO_PI); + hlp1 = (float) 2.0 *hlp + pq_coef[0]; + hlp2 = (float) 2.0 *hlp * hlp1 - (float) 1.0 + pq_coef[1]; + hlp3 = (float) 2.0 *hlp * hlp2 - hlp1 + pq_coef[2]; + hlp4 = (float) 2.0 *hlp * hlp3 - hlp2 + pq_coef[3]; + hlp5 = hlp * hlp4 - hlp3 + pq_coef[4]; + + + if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)) { + + if (step_idx == (LSF_NUMBER_OF_STEPS - 1)) { + + if (fabs(hlp5) >= fabs(*old)) { + freq[lsp_index] = omega - step; + } else { + freq[lsp_index] = omega; + } + + + + + + + + if ((*old) >= 0.0) { + *old = (float) -1.0 * FLOAT_MAX; + } else { + *old = FLOAT_MAX; + } + + omega = old_omega; + step_idx = 0; + + step_idx = LSF_NUMBER_OF_STEPS; + } else { + + if (step_idx == 0) { + old_omega = omega; + } + + step_idx++; + omega -= steps[step_idx]; + + /* Go back one grid step */ + + step = steps[step_idx]; + } + } else { + + /* increment omega until they are of different sign, + and we know there is at least one root between omega + and old_omega */ + *old = hlp5; + omega += step; + } + } + } + + for (i = 0; i < LPC_FILTERORDER; i++) { + freq[i] = freq[i] * TWO_PI; + } +} + + /*----------------------------------------------------------------* + * conversion from lsf coefficients to lpc coefficients + *---------------------------------------------------------------*/ + +void lsf2a(float *a_coef, /* (o) lpc coefficients */ + float *freq /* (i) lsf coefficients */ + ) +{ + int i, j; + float hlp; + float p[LPC_HALFORDER], q[LPC_HALFORDER]; + float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER], a2[LPC_HALFORDER]; + float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], b2[LPC_HALFORDER]; + + for (i = 0; i < LPC_FILTERORDER; i++) { + freq[i] = freq[i] * PI2; + } + + /* Check input for ill-conditioned cases. This part is not + found in the TIA standard. It involves the following 2 IF + blocks. If "freq" is judged ill-conditioned, then we first + modify freq[0] and freq[LPC_HALFORDER-1] (normally + LPC_HALFORDER = 10 for LPC applications), then we adjust + the other "freq" values slightly */ + + + if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)) { + + + if (freq[0] <= 0.0) { + freq[0] = (float) 0.022; + } + + + if (freq[LPC_FILTERORDER - 1] >= 0.5) { + freq[LPC_FILTERORDER - 1] = (float) 0.499; + } + + hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / + (float) (LPC_FILTERORDER - 1); + + for (i = 1; i < LPC_FILTERORDER; i++) { + freq[i] = freq[i - 1] + hlp; + } + } + + memset(a1, 0, LPC_HALFORDER * sizeof(float)); + memset(a2, 0, LPC_HALFORDER * sizeof(float)); + memset(b1, 0, LPC_HALFORDER * sizeof(float)); + memset(b2, 0, LPC_HALFORDER * sizeof(float)); + memset(a, 0, (LPC_HALFORDER + 1) * sizeof(float)); + memset(b, 0, (LPC_HALFORDER + 1) * sizeof(float)); + + + + + + + /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and + cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2. + Note that for this code p[i] specifies the coefficients + used in .Q_A(z) while q[i] specifies the coefficients used + in .P_A(z) */ + + for (i = 0; i < LPC_HALFORDER; i++) { + p[i] = (float) cos(TWO_PI * freq[2 * i]); + q[i] = (float) cos(TWO_PI * freq[2 * i + 1]); + } + + a[0] = 0.25; + b[0] = 0.25; + + for (i = 0; i < LPC_HALFORDER; i++) { + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + + for (j = 0; j < LPC_FILTERORDER; j++) { + + if (j == 0) { + a[0] = 0.25; + b[0] = -0.25; + } else { + a[0] = b[0] = 0.0; + } + + for (i = 0; i < LPC_HALFORDER; i++) { + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + + a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]); + } + + a_coef[0] = 1.0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/lsf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/lsf.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,24 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + lsf.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_LSF_H +#define __iLBC_LSF_H + +void a2lsf(float *freq, /* (o) lsf coefficients */ + float *a /* (i) lpc coefficients */ + ); + +void lsf2a(float *a_coef, /* (o) lpc coefficients */ + float *freq /* (i) lsf coefficients */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/packing.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/packing.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,170 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + packing.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include +#include + +#include "iLBC_define.h" +#include "constants.h" +#include "helpfun.h" +#include "string.h" + + /*----------------------------------------------------------------* + * splitting an integer into first most significant bits and + * remaining least significant bits + *---------------------------------------------------------------*/ + +void packsplit(int *index, /* (i) the value to split */ + int *firstpart, /* (o) the value specified by most + significant bits */ + int *rest, /* (o) the value specified by least + significant bits */ + int bitno_firstpart, /* (i) number of bits in most + significant part */ + int bitno_total /* (i) number of bits in full range + of value */ + ) +{ + int bitno_rest = bitno_total - bitno_firstpart; + + *firstpart = *index >> (bitno_rest); + *rest = *index - (*firstpart << (bitno_rest)); +} + + /*----------------------------------------------------------------* + * combining a value corresponding to msb's with a value + * corresponding to lsb's + *---------------------------------------------------------------*/ + +void packcombine(int *index, /* (i/o) the msb value in the + combined value out */ + int rest, /* (i) the lsb value */ + int bitno_rest /* (i) the number of bits in the + lsb part */ + ) +{ + *index = *index << bitno_rest; + *index += rest; +} + + /*----------------------------------------------------------------* + * packing of bits into bitstream, i.e., vector of bytes + *---------------------------------------------------------------*/ + +void dopack(unsigned char **bitstream, /* (i/o) on entrance pointer to + place in bitstream to pack + new data, on exit pointer + to place in bitstream to + pack future data */ + int index, /* (i) the value to pack */ + int bitno, /* (i) the number of bits that the + value will fit within */ + int *pos /* (i/o) write position in the + current byte */ + ) +{ + int posLeft; + + /* Clear the bits before starting in a new byte */ + + if ((*pos) == 0) { + + + + + + **bitstream = 0; + } + + while (bitno > 0) { + + /* Jump to the next byte if end of this byte is reached */ + + if (*pos == 8) { + *pos = 0; + (*bitstream)++; + **bitstream = 0; + } + + posLeft = 8 - (*pos); + + /* Insert index into the bitstream */ + + if (bitno <= posLeft) { + **bitstream |= (unsigned char) (index << (posLeft - bitno)); + *pos += bitno; + bitno = 0; + } else { + **bitstream |= (unsigned char) (index >> (bitno - posLeft)); + + *pos = 8; + index -= ((index >> (bitno - posLeft)) << (bitno - posLeft)); + + bitno -= posLeft; + } + } +} + + /*----------------------------------------------------------------* + * unpacking of bits from bitstream, i.e., vector of bytes + *---------------------------------------------------------------*/ + +void unpack(unsigned char **bitstream, /* (i/o) on entrance pointer to + place in bitstream to + unpack new data from, on + exit pointer to place in + bitstream to unpack future + data from */ + int *index, /* (o) resulting value */ + int bitno, /* (i) number of bits used to + represent the value */ + int *pos /* (i/o) read position in the + current byte */ + ) +{ + int BitsLeft; + + *index = 0; + + while (bitno > 0) { + + /* move forward in bitstream when the end of the + byte is reached */ + + if (*pos == 8) { + *pos = 0; + (*bitstream)++; + } + + BitsLeft = 8 - (*pos); + + /* Extract bits to index */ + + if (BitsLeft >= bitno) { + *index += ((((**bitstream) << (*pos)) & 0xFF) >> (8 - bitno)); + + *pos += bitno; + bitno = 0; + } else { + + if ((8 - bitno) > 0) { + *index += ((((**bitstream) << (*pos)) & 0xFF) >> (8 - bitno)); + *pos = 8; + } else { + *index += (((int) (((**bitstream) << (*pos)) & 0xFF)) << + (bitno - 8)); + *pos = 8; + } + bitno -= BitsLeft; + } + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/packing.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/packing.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,63 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + packing.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __PACKING_H +#define __PACKING_H + +void packsplit(int *index, /* (i) the value to split */ + int *firstpart, /* (o) the value specified by most + significant bits */ + int *rest, /* (o) the value specified by least + significant bits */ + int bitno_firstpart, /* (i) number of bits in most + significant part */ + int bitno_total /* (i) number of bits in full range + of value */ + ); + +void packcombine(int *index, /* (i/o) the msb value in the + combined value out */ + int rest, /* (i) the lsb value */ + int bitno_rest /* (i) the number of bits in the + lsb part */ + ); + +void dopack(unsigned char **bitstream, /* (i/o) on entrance pointer to + place in bitstream to pack + new data, on exit pointer + to place in bitstream to + pack future data */ + int index, /* (i) the value to pack */ + int bitno, /* (i) the number of bits that the + value will fit within */ + int *pos /* (i/o) write position in the + current byte */ + ); + + + + + +void unpack(unsigned char **bitstream, /* (i/o) on entrance pointer to + place in bitstream to + unpack new data from, on + exit pointer to place in + bitstream to unpack future + data from */ + int *index, /* (o) resulting value */ + int bitno, /* (i) number of bits used to + represent the value */ + int *pos /* (i/o) read position in the + current byte */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/syntFilter.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/syntFilter.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,61 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + syntFilter.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#include "iLBC_define.h" + + /*----------------------------------------------------------------* + * LP synthesis filter. + *---------------------------------------------------------------*/ + +void syntFilter(float *Out, /* (i/o) Signal to be filtered */ + float *a, /* (i) LP parameters */ + int len, /* (i) Length of signal */ + float *mem /* (i/o) Filter state */ + ) +{ + int i, j; + float *po, *pi, *pa, *pm; + + po = Out; + + /* Filter first part using memory from past */ + + for (i = 0; i < LPC_FILTERORDER; i++) { + pi = &Out[i - 1]; + pa = &a[1]; + pm = &mem[LPC_FILTERORDER - 1]; + for (j = 1; j <= i; j++) { + *po -= (*pa++) * (*pi--); + } + for (j = i + 1; j < LPC_FILTERORDER + 1; j++) { + *po -= (*pa++) * (*pm--); + } + po++; + } + + /* Filter last part where the state is entirely in + the output vector */ + + for (i = LPC_FILTERORDER; i < len; i++) { + pi = &Out[i - 1]; + pa = &a[1]; + for (j = 1; j < LPC_FILTERORDER + 1; j++) { + *po -= (*pa++) * (*pi--); + } + po++; + } + + /* Update state vector */ + + memcpy(mem, &Out[len - LPC_FILTERORDER], + LPC_FILTERORDER * sizeof(float)); +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/ilbc/syntFilter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/ilbc/syntFilter.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,22 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + syntFilter.h + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + +#ifndef __iLBC_SYNTFILTER_H +#define __iLBC_SYNTFILTER_H + +void syntFilter(float *Out, /* (i/o) Signal to be filtered */ + float *a, /* (i) LP parameters */ + int len, /* (i) Length of signal */ + float *mem /* (i/o) Filter state */ + ); + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercom --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercom Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,125 @@ +#!/bin/bash + +# intercom +# +# Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). +# All Rights Reserved. +# Author: Andre Adrian +# +# Voice-over-IP Intercom start skript for Linux with ALSA and OSS +# +# Version 0.4 +# + +echo "usage: intercom [OPTIONS] [Partner1-IP [Partner2-IP ...]]" +echo " -a value set ambient (background) noise to value decibel" +# echo " -b value set Acoustic Echo Suppression to value decibel" +echo " -e enable 2040Hz Sinustone for VHF transmitter" +echo " -f Number Number of 20ms Frames in RTP packet" +echo " -k use Packet Loss Concealment (PLC)" +echo " -l use hardware AEC and Line-in for microphone" +echo " -m use hardware AEC and Mic-in for microphone" +echo " -p Number RTP Portnumber (default is 5004)" +echo " -t Telephone conference (everybody with everybody else)" +echo " -s Percent simulated packet loss" +echo " -w visualize vector w" +echo " -I use iLBC codec (default), can do PLC" +echo " -A use G.711 A-law codec" +echo " -U use G.711 u-law codec" +echo " -6 use G.726 32kbps codec" +echo " -G use GSM codec" +echo " -S use Wideband Speex codec, can do PLC" + +# disable screen saver +xset s off +xset -dpms + +# delete old process +killall -9 intercomd 2>/dev/null +killall -9 intercomd1 2>/dev/null + +# configure audio mixer (AC97 compatible) +# check your mixer hardware with: +# cat /dev/sndstat +# +# hardware AEC test was successful with on-board sound mixers: +# Analog Devices AD1985, ICEnsemble ICE1232, Realtek ALC650 and ALC655, +# SigmaTel STAC9750/51 +# +# hardware AEC test was successful with PCI sound cards: +# Soundblaster PCI128 +# +# hardware AEC test failed with PCI sound cards: +# Soundblaster Audigy 2, C-Media 8738 + +# set playback volume +amixer -q sset 'PCM',0 70% +amixer -q sset 'Master',0 70% + +# use only PCM for playback +amixer -q set 'Master',0 unmute +amixer -q set 'PCM',0 unmute +amixer -q set 'Mic',0 mute +amixer -q set 'Line',0 mute +amixer -q set 'CD',0 mute +amixer -q set 'Aux',0 mute + +# enable recording +amixer -q cset iface=MIXER,name='Capture Switch' 1 +EXEC=intercomd +WOPTION=320 +WSTART=0 + +# handle all options +for argv in $* ;do + # echo $argv + case $argv in + ("-l") + # for Hardware AEC and Line-In Capture + amixer -q set 'Capture',0 0%-,100%- + amixer -q cset iface=MIXER,name='Capture Source' 4,5 + ;; + ("-m") + # for Hardware AEC and Mic-In Capture + amixer -q set 'Capture',0 0%-,100%- + amixer -q cset iface=MIXER,name='Capture Source' 0,5 + ;; + ("-9") + # other EXEC because of EFR G.729 link mismatch (same functionnames) + EXEC=intercomd2 + ;; + ("-S") + # other EXEC because Speex is Wideband codec + EXEC=intercomd1 + WOPTION=640 + ;; + ("-w") + # start wdisplay.tcl + WSTART=1 + ;; + esac +done + +# start wdisplay +if test $WSTART -eq 1 ;then + /usr/local/bin/wdisplay.tcl $WOPTION & + sleep 1 +fi + +# start audio/network daemon +/usr/local/bin/$EXEC $* & +sleep 1 + +# give audio/network daemon realtime process prio +# enable this if you don't use hardware AEC +# (setpriority is in RPM package rtstools) +# sudo /usr/sbin/setpriority `pidof $EXEC` fifo 1 + +# To make sudo work without password add as superuser with the program +# visudo: +# %users ALL=(root) NOPASSWD: /usr/sbin/setpriority + +# start graphical user interface +# /usr/local/bin/intercom.tcl $* -geometry 800x600 & +/usr/local/bin/intercom.tcl $* & + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercom.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercom.conf Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,12 @@ +# intercom.conf +# primitive short-dial - name - IP-address map +# Use your own IP-addresses! + +guiconfig t1 "EDDF\nTEC1" 192.168.1.1 +guiconfig t2 "EDDF\nTEC2" 192.168.1.2 +guiconfig t3 "EDDF\nTEC3" 192.168.1.3 +guiconfig t4 "EDDF\nTEC4" 192.168.1.4 +guiconfig t5 "EDDF\nTEC5" 192.168.1.5 +guiconfig t6 "EDDF\nTEC6" 192.168.1.6 +guiconfig t7 "EDDF\nTEC7" 192.168.1.7 +guiconfig t8 "EDDF\nTEC8" 192.168.1.8 diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercom.tcl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercom.tcl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,513 @@ +#!/usr/bin/wish + +# intercom.tcl +# +# Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). +# All Rights Reserved. +# Author: Andre Adrian +# +# Voice-over-IP Intercom Graphical User Interface +# +# Version 0.3.7 +# open all UDP sockets before use to fix problem with slow CPUs + + +# UDP "connection" extension for Tcl/Tk +load /usr/local/lib/libudp1.0.6.so + +# ############################################################## +# Begin Belegt [IS_30] und Umleitung [IS_41] Remote Signallisierung + +# intercom.tcl to other intercom.tcl Signalling Receive init +proc rsig_recv_init {port} { + set srv [udp_open $port] + fconfigure $srv -buffering none -translation binary + fileevent $srv readable [list ::rsig_recv $srv] + # puts "Listening on udp port: [fconfigure $srv -myport]" + return $srv +} + +# intercom.tcl to other intercom.tcl Signalling Send init +proc rsig_send_init {host} { + global rsig_send_sock + + set s [udp_open] + fconfigure $s -remote [list $host 55004] + set rsig_send_sock($host) $s +} + +# intercom.tcl to other intercom.tcl Signalling Send +proc rsig_puts {host str} { + global rsig_send_sock + + puts $rsig_send_sock($host) $str + flush $rsig_send_sock($host) +} + +# intercom.tcl from other intercom.tcl Signalling Receive +proc rsig_recv {sock} { + global ip2tmap tping + global t_updown umltgmap myipaddr + + set msg_body [read $sock] + set msg_header [fconfigure $sock -peer] + # puts "udp_server: $msg_header: [string length $msg_body] {$msg_body}" + + # to partner is first argument in msg_body + set argv [split $msg_body] + set ip_to [lindex $argv 1] + set t_to $ip2tmap($ip_to) + + # from partner is taken from msg_header + set conn [lindex $msg_header 0] + set ip_from [lindex $conn 0] + set t_from $ip2tmap($ip_from) + + switch [lindex $argv 0] { + p {rsig_puts $ip_from "q $ip_to" ;# got application ping + } + q {set tping "" ;# got application ping response (pong) + } + c {.$t_from configure -highlightbackground cyan ;# got call setup + incr t_updown($t_from) + .$t_to configure -highlightbackground cyan + incr t_updown($t_to) + } + h {incr t_updown($t_from) -1 ;# got hangup + if {$t_updown($t_from) <= 0} { + set t_updown($t_from) 0 + .$t_from configure -highlightbackground "#d9d9d9" + } + incr t_updown($t_to) -1 + if {$t_updown($t_to) <= 0} { + set t_updown($t_to) 0 + .$t_to configure -highlightbackground "#d9d9d9" + } + } + d { # puts "rsig_recv ip_from=$ip_from ip_to=$ip_to" + set umltgmap($ip_from) $ip_to ;# got diversion + # foreach i {1 2 3 4 5 6 7 8} { + # puts "umltgmap(10.232.35.$i) = $umltgmap(10.232.35.$i)" + # } + } + default {puts "rsig_recv unknown msg=$msg_body"} + } + return +} + +# End Belegt [IS_30] und Umleitung [IS_41] Remote Signallisierung + +# ############################################################## +# Begin Stoerung Signalisierung [IS_31] + +proc checkping {} { + global tping + + #puts "checkping $tping" + if {$tping != ""} { + .$tping configure -background red + .$tping configure -activebackground red + .$tping configure -highlightbackground red + } +} +# End Stoerung Signalisierung [IS_31] + +# ############################################################## +# Direct Access Button + +# View relevant function Arbeiter +proc da_update {t state} { + switch $state { + 0 { .$t configure -foreground black ;# nothing + .$t configure -activeforeground black + .$t configure -background "#d9d9d9" ;# button is grey + .$t configure -activebackground "#d9d9d9"} + 1 { .$t configure -foreground black ;# transmit + .$t configure -activeforeground black + .$t configure -background yellow + .$t configure -activebackground yellow} + 2 { .$t configure -foreground black ;# receive + .$t configure -activeforeground black + .$t configure -background magenta + .$t configure -activebackground magenta} + 3 { .$t configure -foreground black ;# full duplex + .$t configure -activeforeground black + .$t configure -background green + .$t configure -activebackground green} + } +} + +# View relevant function Vorarbeiter +proc da_ca_update {t state} { + global ta_ip ip2tmap + + # update DA button + da_update $t $state + + if {[info exists ip2tmap($ta_ip)]} { + set t_alias $ip2tmap($ta_ip) + } else { + set t_alias "" + } + + # Update Common Answer Button + if { $t_alias == $t } { + da_update ta $state + } +} + +# DA/CA button press callback +proc da_keyPress {t} { + global t2ipmap state lsig_sock longKey tping umltgmap ip2tmap + + set longKey($t) 0 ;# 1 wenn Taste lange gedrückt, sonst 0 + set ip $t2ipmap($t) ;# ip des remote intercom.tcl + set uip $umltgmap($ip) ;# Umleitung auf gleiche IP oder andere IP + + # avoid two connections to one partner in case of diversion + if {$ip != $uip} { + if {$state($t) == 0 || $state($t) == 2} { + set tumltg $ip2tmap($uip) + if {$state($tumltg) == 1 || $state($tumltg) == 3} { + puts "da_keyPress: error: already connection to this partner" + return + } + } + } + + # remote signalling + switch $state($t) { + 0 {set cmd c + after 300 [list set longKey($t) 1] + rsig_puts $uip "p $uip" ;# send application ping + set tping $t + after 200 [list checkping]} + 1 {set cmd h} + 2 {set cmd c + after 300 [list set longKey($t) 1] + rsig_puts $uip "p $uip" ;# send application ping + set tping $t + after 200 [list checkping]} + 3 {set cmd h} + } + + # local signalling to intercomd - maybe with diversion + puts $lsig_sock "$cmd $uip" + flush $lsig_sock + + # local signalling intercom.tcl - with no diversion + switch $cmd { + c {tx_begin $ip} + r {rx_begin $ip} + h {tx_end $ip} + d {rx_end $ip} + } + +# Begin Belegt Signalisierung [IS_30] + foreach i {t1 t2 t3 t4 t5 t6 t7 t8} { + set da_ip $t2ipmap($i) + rsig_puts $da_ip "$cmd $uip" + } +# End Belegt Signalisierung [IS_30] +} + +# DA/CA button release callback +proc da_keyRelease {t} { + global longKey + + if {$longKey($t)} { + keyPress $t + } +} + +# ############################################################## +# Common Answer Button Req IS_14 + +proc ca_update {} { + global ta_ip textmap + + # puts "ca_update $ta_ip" + + if {[info exists textmap($ta_ip)]} { + set ta_text $textmap($ta_ip) + } else { + set ta_text $ta_ip + } + .ta configure -text $ta_text +} + +# ############################################################## +# Diversion (Umleitung) Req. IS_41 + +# Update Umleitungstaste Req. IS_41 +proc umltg_update {} { + global umltg_state tu_ip ip2tmap + + if {[info exists tu_ip]} { + set told $ip2tmap($tu_ip) + .$told configure -background "#d9d9d9" + .$told configure -activebackground "#d9d9d9" + } + switch $umltg_state { + 0 { .tu configure -background "#d9d9d9" + .tu configure -activebackground "#d9d9d9" + .tu configure -text "" + } + 1 { .tu configure -background orange + .tu configure -activebackground orange + } + } +} + +# Diversion Button callback +proc umltg_keyRelease {} { + global umltg_state myipaddr t2ipmap + + switch $umltg_state { + 0 {set umltg_state 1} + 1 {set umltg_state 0 + # Diversion release == Diversion to myipaddr + foreach i {t1 t2 t3 t4 t5 t6 t7 t8} { + set da_ip $t2ipmap($i) + rsig_puts $da_ip "d $myipaddr" + } + } + } + umltg_update +} + +# Direct Access Buttons callback +proc umltg_da_keyRelease {t} { + global t2ipmap textmap tu_ip ip2tmap myipaddr umltg_state + + # alten Zustand deaktivieren und updaten + umltg_update + + # Model variable ändern + set tu_ip $t2ipmap($t) + + # neuen Zustand updaten + .$t configure -background orange + .$t configure -activebackground orange + set tu_text $textmap($tu_ip) + .tu configure -text $tu_text + + # Begin Umleitung Signalisierung [IS_41] + foreach i {t1 t2 t3 t4 t5 t6 t7 t8} { + set da_ip $t2ipmap($i) + rsig_puts $da_ip "d $tu_ip" + } + # End Umleitung Signalisierung [IS_41] +} + +# ############################################################## +# Direct Access / Diversion Buttons Callbacks + +proc keyPress {t} { + global umltg_state + + switch $umltg_state { + 0 {da_keyPress $t} + 1 {} + } +} + +proc keyRelease {t} { + global umltg_state told + + switch $umltg_state { + 0 {da_keyRelease $t} + 1 {umltg_da_keyRelease $t} + } +} + +# ############################################################## +# Direct Access model relevant function + +proc tx_begin {ip} { + global ip2tmap state + + set t $ip2tmap($ip) + #puts "tx_begin $ip $t" + switch $state($t) { + 0 {set state($t) 1} + 1 { } + 2 {set state($t) 3} + 3 { } + } + da_ca_update $t $state($t) +} + +proc rx_begin {ip} { + global ip2tmap state + + set t $ip2tmap($ip) + #puts "rx_begin $ip $t" + switch $state($t) { + 0 {set state($t) 2} + 1 {set state($t) 3} + 2 { } + 3 { } + } + + # Answer Button Req IS_14 + global ta_ip + + set ta_ip $ip + ca_update + + .ta configure -command [list keyRelease $t] + bind .ta [list keyPress $t] + # End Answer Button Req IS_14 + + da_ca_update $t $state($t) +} + +proc tx_end {ip} { + global ip2tmap state + + set t $ip2tmap($ip) + #puts "tx_end $ip $t" + switch $state($t) { + 0 {} + 1 {set state($t) 0} + 2 { } + 3 {set state($t) 2} + } + da_ca_update $t $state($t) +} + +proc rx_end {ip} { + global ip2tmap state + + set t $ip2tmap($ip) + #puts "rx_end $ip $t" + switch $state($t) { + 0 { } + 1 { } + 2 {set state($t) 0} + 3 {set state($t) 1} + } + da_ca_update $t $state($t) +} + +# ############################################################## +# Local Signalling + +# intercom.tcl from own intercomd Signalling Receive +proc lsig_recv {} { + global lsig_sock + + gets $lsig_sock cmd + # puts "lsig_recv $cmd" + set argv [split $cmd] + # puts $argv + set ip [lindex $argv 1] + switch [lindex $argv 0] { + c {tx_begin $ip} + r {rx_begin $ip} + h {tx_end $ip} + d {rx_end $ip} + } +} + +# ############################################################## +# Program exit (abort, close) Handler + +proc onDestroy {} { + global destroyflag lsig_sock rsig_recv_sock + + if {$destroyflag == 0} { + set destroyflag 1 + puts "Terminate intercomd and intercom" + close $lsig_sock + close $rsig_recv_sock + exec /usr/bin/killall -9 /usr/local/bin/intercomd \ + /usr/local/bin/intercomd1 + } +} + +# ############################################################## +# Read configuration file - hack just use Tcl/Tk parser + +proc guiconfig {t text ip} { + global state longKey ip2tmap t2ipmap umltgmap + + set state($t) 0 + set longKey($t) 0 + + rsig_send_init $ip + + set ip2tmap($ip) $t + set t2ipmap($t) $ip + + set umltgmap($ip) $ip ;# keine Umleitung + + .$t configure -text $text + .$t configure -command [list keyRelease $t] + bind .$t [list keyPress $t] + + # Answer Button Req IS_14 + global textmap + + set textmap($ip) $text + + da_ca_update $t $state($t) +} + +# ############################################################## +# Begin main + +# init and register programm termination handler +set destroyflag 0 +bind . [list onDestroy] + +# include GUI +source /usr/local/bin/intercom.ui.tcl +intercom_ui . + +# init model +foreach {i} {t1 t2 t3 t4 t5 t6 t7 t8} { + set t_updown($i) 0 +} + +# init view +foreach {i} {t1 t2 t3 t4 t5 t6 t7 t8 ta tu} { + .$i configure -width 5 -height 2 -highlightthickness 12 +} + +# init Common Answer-Button Req. IS_14 +set ta_ip "" + +# init and register Diversion Req. IS_41 +set umltg_state 0 +.tu configure -command [list umltg_keyRelease] + +# include configuration +if {[file exists ~/.intercom.conf]} { + source ~/.intercom.conf +} else { + file copy /usr/local/bin/intercom.conf ~/.intercom.conf + puts "" + puts "Please edit the file ~/.intercom.conf for your Labels and your" + puts "IP-addresses. Then start intercom again." + exit +} + +# init local signalling to intercomd, a TCP connection +set lsig_sock [socket 127.0.0.1 4999] +fileevent $lsig_sock readable lsig_recv + +# init remote signalling to intercom.tcl, an UDP "connection" +set rsig_recv_sock [rsig_recv_init 55004] + +# set window title +set nodename [exec uname -n] +wm title . "intercom $nodename" + +# hack: get my ip address +set hostsline [exec grep $nodename /etc/hosts] +set myipaddr [lindex [split $hostsline] 0] + +# End main +# ############################################################## diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercom.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercom.ui Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,237 @@ +WidGet file, version 1.1, created: Do Jul 21 10:07:04 CEST 2005 +Widget button#10 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#10 + other tabbing {} + other item_name ta + geometry row 5 + other type button + geometry column 5 + other comments {} +Widget button#1 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#1 + other tabbing {} + other item_name t1 + geometry row 2 + other type button + configure text t1 + geometry column 2 + other comments {} +Widget button#11 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#11 + other tabbing {} + other item_name tu + geometry row 5 + other type button + geometry column 2 + other comments {} +Widget button#2 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#2 + other tabbing {} + other item_name t2 + geometry row 2 + other type button + configure text t2 + geometry column 3 + other comments {} +Widget button#4 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#4 + other tabbing {} + other item_name t3 + geometry row 2 + other type button + configure text t3 + geometry column 4 + other comments {} +Widget button#5 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#5 + other tabbing {} + other item_name t4 + geometry row 2 + other type button + configure text t4 + geometry column 5 + other comments {} +Widget button#6 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#6 + other tabbing {} + other item_name t5 + geometry row 3 + other type button + configure text t5 + geometry column 2 + other comments {} +Widget button#7 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#7 + other tabbing {} + other item_name t6 + geometry row 3 + other type button + configure text t6 + geometry column 3 + other comments {} +Widget f + other generic_options {button { + } canvas { + } checkbutton { + } entry { + } frame { + } label { + } labelframe { + } listbox { + } menubutton { + } message { + } panedwindow { + } radiobutton { + } scale { + } scrollbar { + } spinbox { + } text { + } + } + other panel {} + other resize_row {0 0 0 0 0} + other type frame + other min_row {2 30 30 30 30} + other master {} + other pathname f + other resize_column {0 0 0 0 0} + other tags {} + other level 0 + configure background #e9e9e9 + other min_column {2 30 30 30 30} + other help {} + other Colors {black white bisque grey red green blue magenta yellow #d9d9d9} + other comments {} + other item_name f + other tabbing {} +Widget button#8 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#8 + other tabbing {} + other item_name t7 + geometry row 3 + other type button + configure text t7 + geometry column 4 + other comments {} +Widget button#9 + other error {} + other tags {} + other level {} + other help {} + other master {} + other pathname button#9 + other tabbing {} + other item_name t8 + geometry row 3 + other type button + configure text t8 + geometry column 5 + other comments {} +Widget canvas#1 + geometry columnspan 4 + geometry row 1 + configure height 0 + other error {} + other type canvas + other master {} + other pathname canvas#1 + other tags {} + other level {} + configure width 400 + other help {} + other comments {} + geometry column 2 + other item_name canvas#1 + other tabbing {} + geometry sticky nesw +Widget canvas#2 + geometry row 2 + configure height 160 + geometry rowspan 2 + other error {} + other type canvas + other master {} + other pathname canvas#2 + other tags {} + other level {} + configure width 0 + other help {} + other comments {} + geometry column 1 + other item_name canvas#2 + other tabbing {} + geometry sticky nesw +Widget label#1 + geometry row 4 + other error {} + other type label + other master {} + configure text Diversion + other pathname label#1 + other tags {} + other level {} + other help {} + geometry column 2 + other comments {} + other item_name label#1 + other tabbing {} +Widget label#2 + geometry row 4 + other error {} + other type label + other master {} + configure text Answer + other pathname label#2 + other tags {} + other level {} + other help {} + geometry column 5 + other comments {} + other item_name label#2 + other tabbing {} + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercom.ui.tcl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercom.ui.tcl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,113 @@ +#! /bin/sh +# the next line restarts using wish \ +exec wish "$0" "$@" + +# interface generated by SpecTcl version 1.1 from /home/anblf/voipconf2/intercom.ui +# root is the parent window for this user interface + +proc intercom_ui {root args} { + + # this treats "." as a special case + + if {$root == "."} { + set base "" + } else { + set base $root + } + + canvas $base.canvas#1 \ + -height 0 \ + -width 400 + + canvas $base.canvas#2 \ + -height 160 \ + -width 0 + + button $base.t1 \ + -text t1 + + button $base.t2 \ + -text t2 + + button $base.t3 \ + -text t3 + + button $base.t4 \ + -text t4 + + button $base.t5 \ + -text t5 + + button $base.t6 \ + -text t6 + + button $base.t7 \ + -text t7 + + button $base.t8 \ + -text t8 + + label $base.label#1 \ + -text Diversion + + label $base.label#2 \ + -text Answer + + button $base.tu + + button $base.ta + + + # Geometry management + + grid $base.canvas#1 -in $root -row 1 -column 2 \ + -columnspan 4 \ + -sticky nesw + grid $base.canvas#2 -in $root -row 2 -column 1 \ + -rowspan 2 \ + -sticky nesw + grid $base.t1 -in $root -row 2 -column 2 + grid $base.t2 -in $root -row 2 -column 3 + grid $base.t3 -in $root -row 2 -column 4 + grid $base.t4 -in $root -row 2 -column 5 + grid $base.t5 -in $root -row 3 -column 2 + grid $base.t6 -in $root -row 3 -column 3 + grid $base.t7 -in $root -row 3 -column 4 + grid $base.t8 -in $root -row 3 -column 5 + grid $base.label#1 -in $root -row 4 -column 2 + grid $base.label#2 -in $root -row 4 -column 5 + grid $base.tu -in $root -row 5 -column 2 + grid $base.ta -in $root -row 5 -column 5 + + # Resize behavior management + + grid rowconfigure $root 1 -weight 0 -minsize 2 + grid rowconfigure $root 2 -weight 0 -minsize 30 + grid rowconfigure $root 3 -weight 0 -minsize 30 + grid rowconfigure $root 4 -weight 0 -minsize 30 + grid rowconfigure $root 5 -weight 0 -minsize 30 + grid columnconfigure $root 1 -weight 0 -minsize 2 + grid columnconfigure $root 2 -weight 0 -minsize 30 + grid columnconfigure $root 3 -weight 0 -minsize 30 + grid columnconfigure $root 4 -weight 0 -minsize 30 + grid columnconfigure $root 5 -weight 0 -minsize 30 +# additional interface code +# end additional interface code + +} + + +# Allow interface to be run "stand-alone" for testing + +catch { + if [info exists embed_args] { + # we are running in the plugin + intercom_ui . + } else { + # we are running in stand-alone mode + if {$argv0 == [info script]} { + wm title . "Testing intercom_ui" + intercom_ui . + } + } +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercomd.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercomd.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,1376 @@ +/* intercomd.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * Author: Andre Adrian + * + * Voice over IP Intercom with Telephone conference and Acoustic Echo + * Cancellation using unicast RTP messages (RFC3550, RFC3551) + * + * Attention. This source code is for Linux only! You need: + * same endian for CPU and soundcard for 16bit PCM audio sample + * Open Source Sound (OSS) support + * ALSA Sound support for hardware (2-channel) AEC + * + * Format Sourcecode: +indent -kr -i2 -nlp -ci2 -l72 -lc72 -nut intercomd.cpp + * + * global Replace (one replace per line only!) +sed -i "s/PIT_MIN/G729_PIT_MIN/" *.h *.cpp + * + */ + +const char VERSION[] = "0.4.1"; + +#include +#include +#include +#include +#include +#include + +/* Error handling */ +#include +#include +extern int errno; + +/* low level io */ +#include +#include +#include +#include +#include +#include +#include + +/* Socket io */ +#include +#include +#include + +/* IETF iLBC codec */ +extern "C" { + #include "ilbc/iLBC_define.h" + #include "ilbc/iLBC_encode.h" + #include "ilbc/iLBC_decode.h" +} + +/* ITU-T G.711 codec */ +extern "C" { + #include "g711/g711.h" +} + +/* 3GPP GSM codec */ +extern "C" { + #include "gsm/private.h" + #include "gsm/gsm.h" + #include "gsm/rpeltp.h" +} + +/* ITU-T G.726 codec */ +extern "C" { + #include "g726/g726.h" + #include "g726/g726_rfc3551.h" +} + +/* Speex codec */ +extern "C" { + #include + /* Note: if you use the RPM speex-devel on SuSE 9.1 change the + * header file above from to */ +} + +#include "sinuston.h" + +typedef unsigned char Byte; +typedef short Word16; + +#ifdef EFRSTUB +/* EFR stubs - because of function name conflict in EFR and G.729 */ +class EFR { +public: + int EFR::initEncode(int dtx_mode_) { + return 0; + }; + int EFR::encode( /* (o) len in byte of encoded_data */ + Byte * encoded_data, /* (o) The encoded bytes */ + Word16 * data /* (i) The signal block to encode */ + ) { + return 0; + }; + int EFR::initDecode() { + return 0; + }; + int EFR::decode( /* (o) Number of decoded samples or 0 for error */ + Word16 * decoded_data, /* (o) Decoded signal block */ + Byte * encoded_data, /* (i) Encoded bytes */ + Word16 mode /* (i) 0=PL, 1=Normal */ + ) { + return 0; + }; +}; +#else + /* 3GPP GSM-EFR codec */ +#include "efr/typedef.h" +#include "efr/efr.h" +#endif + +#ifdef G729STUB +/* G.729 stubs - because of function name conflict in EFR and G.729 */ +class G729 { +public: + int G729::initEncode(int dummy) { + return 0; + }; + + int G729::encode( /* len in byte of encoded_data */ + Byte * encoded_data, /* (o) The encoded bytes */ + Word16 * data /* (i) The signal block to encode */ + ) { + return 0; + }; + int G729::initDecode() { + return 0; + }; + + int G729::decode( /* (o) Number of decoded samples */ + Word16 * decoded_data, /* (o) Decoded signal block */ + Byte * encoded_data, /* (i) Encoded bytes */ + Word16 mode /* (i) 0=PL, 1=Normal */ + ) { + return 0; + }; +}; +#else + /* ITU-T G.729 codec */ +#include "g729/typedef.h" +#include "g729/ld8k.h" +#include "g729/g729.h" +#endif + + +/* intercom */ +#include "rtp.h" +#include "udp.h" +#include "tcp.h" +#include "aec.h" +#include "oss.h" +#include "cirbuf.h" +#include "intercomd.h" + +/* Design Constants */ +#define PARTNERS 5 /* maximum telephony partners */ + +/* End of Design Constants */ +#define MAXPACKSIZE 160 /* maximum size of 20ms encoded audio */ +#define ILBC_MODE 20 +#define FRAMESIZE (20*8*WIDEB*2) /* compression frame size */ +#define MTU 1460 /* max. MTU size without Headers */ + +/* Globals */ +int wdisplay = NO; /* export aec.cpp */ + + +/* audio */ +static CIRBUF mic_cirbuf; +static CIRBUF spk_cirbuf; +static AEC aec; +static int channels = 1; +static int audio_wr_fd = -1; // Audio Output (speaker) +static int packetlc = NO; +static SINUSTON sinuston; // Erweiterung Christian Dorge +static int sinuson = 0; // Sinustonaktivierung + +/* network transmitting to partners */ +static in_addr_t to_ip[PARTNERS]; +static RTP to_rtp[PARTNERS]; +static UDP to_udp[PARTNERS]; +static iLBC_Enc_Inst_t enc_ilbc[PARTNERS]; +static G726_state enc_g726[PARTNERS]; +static EFR enc_efr[PARTNERS]; +static G729 enc_g729[PARTNERS]; +static gsm enc_gsm[PARTNERS]; +static SpeexBits enc_spxbits[PARTNERS]; +static void *enc_spx[PARTNERS]; +static CIRBUF conf_cirbuf[PARTNERS]; +static char tx_buf[PARTNERS][MTU]; +static char *tx_pbuf[PARTNERS]; +static int tx_frame[PARTNERS]; +static int to_partners = 0; +static int telephone_conference = NO; +static int tx_frames = 4; +static int tx_payloadt = PT_iLBC; /* default Codec */ +static int tx_packsize = NO_OF_BYTES_20MS; +static unsigned long to_ssrc = 0; + +/* network receiving from partners */ +static in_addr_t from_ip[PARTNERS]; +static unsigned long from_ssrc[PARTNERS]; +static int from_cnt[PARTNERS]; +static CIRBUF from_cirbuf[PARTNERS]; +static iLBC_Dec_Inst_t dec_ilbc[PARTNERS]; +static G726_state dec_g726[PARTNERS]; +static EFR dec_efr[PARTNERS]; +static G729 dec_g729[PARTNERS]; +static gsm dec_gsm[PARTNERS]; +static SpeexBits dec_spxbits[PARTNERS]; +static void *dec_spx[PARTNERS]; +static int from_partners = 0; +static int from_rx_pt[PARTNERS]; +static RTP from_rtp[PARTNERS]; + +/*----------------------------------------------------------------* +* iLBC Encoder interface function +*---------------------------------------------------------------*/ + +short encode( /* (o) Number of bytes encoded */ + iLBC_Enc_Inst_t * iLBCenc_inst, /* (i/o) Encoder instance */ + unsigned char *encoded_data, /* (o) The encoded bytes */ + short *data /* (i) The signal block to encode */ + ) +{ + float block[BLOCKL_MAX]; + int k; + + /* convert signal to float */ + + for (k = 0; k < iLBCenc_inst->blockl; k++) + block[k] = (float) data[k]; + + /* do the actual encoding */ + + iLBC_encode(encoded_data, block, iLBCenc_inst); + + return (iLBCenc_inst->no_of_bytes); +} + +short spx_encode( /* (o) Number of bytes encoded */ + SpeexBits *bits, + void *enc_state, + unsigned char *encoded_data, /* (o) The encoded bytes */ + short *data /* (i) The signal block to encode */ + ) +{ + float block[20*WIDEB*8]; + unsigned int k; + + /* convert signal to float */ + + for (k = 0; k < sizeof(block) / sizeof(float); k++) + block[k] = (float) data[k]; + + /* do the actual encoding */ + + speex_bits_reset(bits); + speex_encode(enc_state, block, bits); + int bytes = speex_bits_write(bits, (char *)encoded_data, 200); + + // RPM speex-devel 1.0.3 has different size then Speex 1.1.7 + if (bytes != SZ_SPX) { + static int errcnt = 0; + if (++errcnt > 0) { + errcnt = -250; + syslog(LOG_WARNING, "%s:%d: %s: Error bytes = %d, Update Speex lib to 1.1\n", \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, bytes); \ + } + } + return SZ_SPX; +} + +void tx_buf_init(int i) +{ + tx_pbuf[i] = tx_buf[i]; + tx_frame[i] = 0; +} + +int encode_any(int i, Byte * encoded_data, short *buf) +{ + static int once = 0; + int len = 0; + switch (tx_payloadt) { + case PT_PCMA: + len = 160; + alaw_compress(len, buf, encoded_data); + break; + case PT_PCMU: + len = 160; + ulaw_compress(len, buf, encoded_data); + break; + case PT_GSM: + gsm_encode(enc_gsm[i], buf, encoded_data); + len = 33; + break; + case PT_EFR: + len = enc_efr[i].encode(encoded_data, buf); + break; + case PT_G729: + /* G.729 is a 10ms per frame codec */ + enc_g729[i].encode(encoded_data, buf); + len = 2 * enc_g729[i].encode(encoded_data + 10, buf + 80); + break; + case PT_iLBC: + len = encode(&enc_ilbc[i], encoded_data, buf); + break; + case PT_SPX: + len = spx_encode(&enc_spxbits[i], enc_spx[i], encoded_data, buf); + if (!once) { + printf("speex encode len = %d\n", len); + once = 1; + } + break; + case PT_G726: + len = g726_encode(&enc_g726[i], encoded_data, buf); + break; + } + return len; +} + +static int packet_loss = 0; + +int audio_read(int audio_rd_fd) +{ + /* fat software interrupt routine: read audio, send UDP packets */ + + short mic_buf[FRAGSIZE / 2]; + if (1 == channels) { + size_t len = read(audio_rd_fd, mic_buf, FRAGSIZE); + return_if(len != FRAGSIZE, ERROR); + + if (0 == to_partners) { + /* start assembling send packets only if we have a target */ + return OKAY; + } + + short spk_buf[FRAGSIZE / 2]; + spk_cirbuf.pop((char *) spk_buf, FRAGSIZE); + + /* Acoustic Echo Cancellation - using software buffers */ + int i; + for (i = 0; i < FRAGSIZE / 2; ++i) { + mic_buf[i] = aec.doAEC(mic_buf[i], spk_buf[i]); + } + } else { + short mic2_buf[FRAGSIZE]; + size_t len = read(audio_rd_fd, mic2_buf, 2 * FRAGSIZE); + return_if(len != 2 * FRAGSIZE, ERROR); + + if (0 == to_partners) { + /* start assembling send packets only if we have a target */ + return OKAY; + } + + /* Acoustic Echo Cancellation - using hardware audio mixer */ + int i; + for (i = 0; i < FRAGSIZE / 2; ++i) { + mic_buf[i] = aec.doAEC(mic2_buf[2 * i], mic2_buf[2 * i + 1]); + } + } + + int ret = mic_cirbuf.push((char *) mic_buf, FRAGSIZE); + if (ret < 0) { + syslog(LOG_WARNING, "mic_cirbuf.push overrun\n"); + } + + if (mic_cirbuf.getlen() >= FRAMESIZE) { + /* My RFC3551 interpretation: Only one RTP Header for packets + * with a number of frames */ + int i; + for (i = 0; i < PARTNERS; ++i) { + if (to_ip[i] && 0 == tx_frame[i]) { + to_rtp[i].reset_csrc(); + + /* add ssrc from partners in csrc field */ + if (telephone_conference) { + int j; + for (j = 0; j < PARTNERS; ++j) { + /* do not mix in origin */ + if (from_ssrc[j] && (to_ip[i] != from_ip[j])) { + to_rtp[i].add_csrc(from_ssrc[j]); + } + } + } + /* put RTP header */ + tx_pbuf[i] = RTP_network_copy(tx_pbuf[i], &to_rtp[i]); + } + } + + /* put payload (audio) */ + short micbuf[FRAMESIZE / 2]; + mic_cirbuf.pop((char *) micbuf, FRAMESIZE); + + if (telephone_conference) { + /* telephone conference mix - everybody from/to everybody else */ + short from_buf[PARTNERS][FRAMESIZE / sizeof(short)]; + short sum_buf[FRAMESIZE / sizeof(short)]; + int i, k; + unsigned int j; + + /* get audio from other partners */ + for (i = 0; i < PARTNERS; ++i) { + conf_cirbuf[i].pop((char *) from_buf[i], FRAMESIZE); + } + + for (i = 0; i < PARTNERS; ++i) { + if (to_ip[i]) { + for (j = 0; j < FRAMESIZE / sizeof(short); ++j) { + /* mix */ + long sum = micbuf[j]; + for (k = 0; k < PARTNERS; ++k) { + if (to_ip[i] != from_ip[k]) { /* do not mix in origin */ + sum += from_buf[k][j]; + } + } + /* clip */ + if (sum > 32767) { + sum_buf[j] = 32767; + } else if (sum < -32767) { + sum_buf[j] = -32767; + } else { + sum_buf[j] = sum; + } + } + /* do encoding (audio compression) */ + Byte encoded_data[MAXPACKSIZE]; + int len = encode_any(i, encoded_data, sum_buf); + + /* distribute to transmit buffers */ + memcpy(tx_pbuf[i], encoded_data, len); + tx_pbuf[i] += len; + assert(tx_pbuf[i] - tx_buf[i] <= MTU); + } + } + } else { + /* intercom conference mixing - central node from/to other nodes */ + /* do encoding (audio compression) */ + Byte encoded_data[MAXPACKSIZE]; + int len = encode_any(0, encoded_data, micbuf); + + /* distribute to transmit buffers */ + int i; + for (i = 0; i < PARTNERS; ++i) { + if (to_ip[i]) { + memcpy(tx_pbuf[i], encoded_data, len); + tx_pbuf[i] += len; + assert(tx_pbuf[i] - tx_buf[i] <= MTU); + } + } + } + + /* transmit data packet(s) */ + for (i = 0; i < PARTNERS; ++i) { + if (to_ip[i] && ++tx_frame[i] >= tx_frames) { + + if (random() >= packet_loss) { // simulate packet loss + to_udp[i].send(tx_buf[i], tx_pbuf[i] - tx_buf[i]); + } + + /* prepare next go */ + tx_buf_init(i); + to_rtp[i].next(tx_frames * 20 * 8); + } + } + } + return OKAY; +} + +void partner_timeout() +{ + /* Delete old from_ssrc[] entries - this is not very quick! */ + int i; + for (i = 0; i < PARTNERS; ++i) { + if (from_ssrc[i] && from_cnt[i] == 0) { + char s[20]; + print_gui("d %s\n", iptoa(s, from_ip[i])); + from_ssrc[i] = 0; + from_ip[i] = 0; + from_rx_pt[i] = -1; + from_rtp[i].reset_csrc(); + --from_partners; + if (0 == from_partners) { + /* no more demand for PCM out */ + close(audio_wr_fd); + audio_wr_fd = -1; + } + } + from_cnt[i] = 0; + } +} + + +int partner_lookup(unsigned long ssrc, in_addr_t ip) +{ + /* search */ + int i; + for (i = 0; i < PARTNERS; ++i) { + if (from_ssrc[i] == ssrc) { + ++from_cnt[i]; + return i; /* old entry */ + } + } + /* add new entry */ + for (i = 0; i < PARTNERS; ++i) { + if (0 == from_ssrc[i]) { + if (0 == from_partners) { + spk_cirbuf.init(); + } + from_ssrc[i] = ssrc; + from_ip[i] = ip; + from_cnt[i] = 1; + + initDecode(dec_ilbc + i, ILBC_MODE, 1); + enc_efr[i].initDecode(); + enc_g729[i].initDecode(); + rpeltp_delete(dec_gsm[i]); + dec_gsm[i] = rpeltp_init(); + speex_bits_destroy(dec_spxbits + i); + speex_decoder_destroy(dec_spx[i]); + speex_bits_init(dec_spxbits + i); + dec_spx[i] = speex_decoder_init(&speex_wb_mode); + int value = SPX_ENH; + speex_decoder_ctl(dec_spx[i], SPEEX_SET_ENH, &value); + + from_cirbuf[i].init(); + conf_cirbuf[i].init(); + ++from_partners; + char s[20]; + print_gui("r %s\n", iptoa(s, ip)); + + printf("from_ssrc[%d] = %08lx\n", i, from_ssrc[i]); + return i; + } + } + return ERROR; +} + +/*----------------------------------------------------------------* +* iLBC Decoder interface function +*---------------------------------------------------------------*/ + +short decode( /* (o) Number of decoded samples */ + iLBC_Dec_Inst_t * iLBCdec_inst, /* (i/o) Decoder instance */ + short *decoded_data, /* (o) Decoded signal block */ + unsigned char *encoded_data, /* (i) Encoded bytes */ + short mode /* (i) 0=PL, 1=Normal */ + ) +{ + int k; + float decblock[BLOCKL_MAX], dtmp; + + /* check if mode is valid */ + + if (mode < 0 || mode > 1) { + printf("\nERROR - Wrong mode - 0, 1 allowed\n"); + exit(3); + } + + /* do actual decoding of block */ + iLBC_decode(decblock, encoded_data, iLBCdec_inst, mode); + + /* convert to short */ + + for (k = 0; k < iLBCdec_inst->blockl; k++) { + dtmp = decblock[k]; + + if (dtmp < MIN_SAMPLE) + dtmp = MIN_SAMPLE; + else if (dtmp > MAX_SAMPLE) + dtmp = MAX_SAMPLE; + decoded_data[k] = (short) dtmp; + } + + return (iLBCdec_inst->blockl); +} + +short spx_decode( /* (o) Number of decoded samples */ + SpeexBits *bits, + void *dec_state, + short *decoded_data, /* (o) Decoded signal block */ + unsigned char *encoded_data, /* (i) Encoded bytes */ + short mode /* (i) 0=PL, 1=Normal */ + ) +{ + unsigned int k; + float decblock[20*WIDEB*8]; + + /* do actual decoding of block */ + if (bits) + speex_bits_read_from(bits, (char *)encoded_data, SZ_SPX); + speex_decode(dec_state, bits, decblock); + + /* convert to short */ + + for (k = 0; k < sizeof(decblock) / sizeof(float); k++) { + decoded_data[k] = (short)decblock[k]; + } + + return 20*WIDEB*8; +} + +void audio_write() +{ + int i; + unsigned int j; + short from_buf[PARTNERS][FRAGSIZE / sizeof(short)]; + short sum_buf[FRAGSIZE / sizeof(short)]; + int playout = 0; // is 1 if we have audio, not silence + + /* get audio */ + for (i = 0; i < PARTNERS; ++i) { + int ret = from_cirbuf[i].pop((char *) from_buf[i], FRAGSIZE); + if (OKAY == ret) playout = 1; + if (packetlc && ERROR == ret && from_ssrc[i] && audio_wr_fd >= 0) { + // printf("audio_write() PLC ch=%d ret=%d \n", i, ret); + + /* do Packet Loss Concealment */ + short decoded_data[FRAMESIZE / 2]; + int len; + switch (from_rx_pt[i]) { + case PT_iLBC: + len = decode(dec_ilbc + i, decoded_data, NULL, 0); + from_cirbuf[i].push((char *) decoded_data, 2 * len); + from_cirbuf[i].pop((char *) from_buf[i], FRAGSIZE); + playout = 1; + break; + case PT_SPX: + Byte spx_dummy[SZ_SPX]; + memset(spx_dummy, 0, SZ_SPX); + len = spx_decode(NULL, dec_spx[i], + decoded_data, spx_dummy, 1); + from_cirbuf[i].push((char *) decoded_data, 2 * len); + from_cirbuf[i].pop((char *) from_buf[i], FRAGSIZE); + playout = 1; + break; + case PT_EFR: + Byte efr_dummy[31]; + memset(efr_dummy, 0, 31); + efr_dummy[0] = 0xC0; + len = dec_efr[i].decode(decoded_data, efr_dummy, 0); + from_cirbuf[i].push((char *) decoded_data, 2 * len); + from_cirbuf[i].pop((char *) from_buf[i], FRAGSIZE); + playout = 1; + break; + case PT_G729: + Byte g729_dummy[20]; + memset(g729_dummy, 0, 20); + len = dec_g729[i].decode(decoded_data, g729_dummy, 0); + len += + dec_g729[i].decode(decoded_data + 80, g729_dummy + 10, 0); + from_cirbuf[i].push((char *) decoded_data, 2 * len); + from_cirbuf[i].pop((char *) from_buf[i], FRAGSIZE); + playout = 1; + break; + } + } + } + + // if (!playout) return; // knistern with AD1985 + + // audio mixing with sinuston + for (j = 0; j < FRAGSIZE / sizeof(short); ++j) { + /* mix */ + long sum = 0; + for (i = 0; i < PARTNERS; ++i) { + sum += from_buf[i][j]; + } + /* clip */ + if (sum > 32767) { + sum = 32767; + } else if (sum < -32767) { + sum = -32767; + } + if (sinuson && playout) { + // Sinuston dazumischen 11jul2005 adrian + sum = sinuston.mischen(sum); + } + sum_buf[j] = sum; + } + + if (1 == channels) { + if (from_partners > 0) { + /* save for 1-channel AEC */ + int ret = spk_cirbuf.push((char *) sum_buf, FRAGSIZE); + if (ret < 0) { + /* syslog(LOG_WARNING, "spk_cirbuf.push overrun\n"); */ + } + } + if (audio_wr_fd < 0) { + /* late audio write open */ + audio_wr_fd = audio_init("/dev/dsp", channels, O_WRONLY); + } + if (audio_wr_fd >= 0) { + write(audio_wr_fd, sum_buf, FRAGSIZE); + } + } else { + short sum2_buf[FRAGSIZE]; + int i; + for (i = 0; i < FRAGSIZE / 2; ++i) { + sum2_buf[2 * i] = 0; /* left channel nothing */ + sum2_buf[2 * i + 1] = sum_buf[i]; /* right channel spk */ + } + if (audio_wr_fd < 0) { + /* late audio write open */ + audio_wr_fd = audio_init("/dev/dsp", channels, O_WRONLY); + } + if (audio_wr_fd >= 0) { + write(audio_wr_fd, sum2_buf, 2 * FRAGSIZE); + } + } +} + +static unsigned short rtp_port = 5004; /* see RFC3551 */ + +int udp_read(int udp_fd) +{ + /* software interrupt routine */ + char buf[MTU]; + struct sockaddr_in from_sock; + socklen_t from_socklen = sizeof(sockaddr_in); + RTP rtp_in; + + int len = recvfrom(udp_fd, buf, MTU, 0, + (struct sockaddr *) &from_sock, &from_socklen); + + /* check Port number */ + in_addr_t from_ip = ntohl(from_sock.sin_addr.s_addr); + in_port_t from_port = ntohs(from_sock.sin_port); + return_if(from_port != rtp_port, ERROR); + + char *pbuf = RTP_host_copy(&rtp_in, buf); + len -= (pbuf - buf); + return_if(len < 0, ERROR); + int rc = rtp_in.check(); + return_if(rc, ERROR); + + int partner = partner_lookup(rtp_in.getssrc(), from_ip); + return_if(partner < 0, ERROR); + + /* Avoid Megaphone (station with itself) audio loop */ + if (to_ssrc == rtp_in.getssrc()) { + // return ERROR; + } + + /* Avoid telephone conference style audio loop (multipath) */ + int i; + for (i = 0; i < PARTNERS; ++i) { + /* drop packets with SSRC the same as an known CSRC */ + if (i != partner && from_rtp[i].find_csrc(rtp_in.getssrc())) { + return ERROR; + } + } + /* to avoid silence with audio loops: Only if above test passed + * copy rtp_in */ + from_rtp[partner] = rtp_in; /* die CSRC */ + + int rx_frames = 0; + int rx_pt = rtp_in.get_pt(); + /* detect number of frames and dynamic payload type from length */ + switch (len) { + case 1 * 20: + rx_frames = 1; + break; /* G729 */ + case 1 * 33: + rx_frames = 1; + break; /* GSM */ + case 1 * 31: + rx_frames = 1; + rx_pt = PT_EFR; + break; + case 1 * 38: + rx_frames = 1; + rx_pt = PT_iLBC; + break; + case 1 * SZ_SPX: + rx_frames = 1; + rx_pt = PT_SPX; + break; + case 1 * 80: /* or 4*20 */ + switch (rx_pt) { + case PT_G729: + rx_frames = 4; + break; + default: + rx_frames = 1; + rx_pt = PT_G726; + break; + } + break; + case 1 * 160: /* or 2*80 */ + switch (rx_pt) { + case PT_PCMA: + case PT_PCMU: + rx_frames = 1; /* G711 */ + break; + default: + rx_frames = 2; /* G726 32kbps */ + rx_pt = PT_G726; + break; + } + break; + + case 2 * 20: + rx_frames = 2; + break; + case 2 * 33: + rx_frames = 2; + break; + case 2 * 31: + rx_frames = 2; + rx_pt = PT_EFR; + break; + case 2 * 38: + rx_frames = 2; + rx_pt = PT_iLBC; + break; + case 2 * SZ_SPX: + rx_frames = 2; + rx_pt = PT_SPX; + break; + case 2 * 160: /* or 4*80 */ + switch (rx_pt) { + case PT_PCMA: + case PT_PCMU: + rx_frames = 2; /* G711 */ + break; + default: + rx_frames = 4; /* G726 32kbps */ + rx_pt = PT_G726; + break; + } + break; + + case 3 * 20: + rx_frames = 3; + break; + case 3 * 33: + rx_frames = 3; + break; + case 3 * 31: + rx_frames = 3; + rx_pt = PT_EFR; + break; + case 3 * 38: + rx_frames = 3; + rx_pt = PT_iLBC; + break; + case 3 * SZ_SPX: + rx_frames = 3; + rx_pt = PT_SPX; + break; + case 3 * 80: + rx_frames = 3; + rx_pt = PT_G726; + break; + case 3 * 160: + rx_frames = 3; + break; + + case 4 * 33: + rx_frames = 4; + break; + case 4 * 31: + rx_frames = 4; + rx_pt = PT_EFR; + break; + case 4 * 38: + rx_frames = 4; + rx_pt = PT_iLBC; + break; + case 4 * SZ_SPX: + rx_frames = 4; + rx_pt = PT_SPX; + break; + case 4 * 160: + rx_frames = 4; + break; + }; + return_if(0 == rx_frames, ERROR); + + from_rx_pt[partner] = rx_pt; + for (i = 0; i < rx_frames; ++i) { + /* do decoding (audio decompression) */ + short decoded_data[FRAMESIZE / 2]; + switch (rx_pt) { + case PT_PCMA: + len = 160; + alaw_expand(len, (Byte *) pbuf, decoded_data); + pbuf += 160; + break; + case PT_PCMU: + len = 160; + ulaw_expand(len, (Byte *) pbuf, decoded_data); + pbuf += 160; + break; + case PT_GSM: + len = 160; + gsm_decode(dec_gsm[partner], (Byte *) pbuf, decoded_data); + pbuf += 33; + break; + case PT_EFR: + len = dec_efr[partner].decode(decoded_data, (Byte *) pbuf, 1); + pbuf += 31; + break; + case PT_G729: + len = dec_g729[partner].decode(decoded_data, (Byte *) pbuf, 1); + len += + dec_g729[partner].decode(decoded_data + 80, + (Byte *) (pbuf + 10), 1); + pbuf += 20; + break; + case PT_iLBC: + len = decode(dec_ilbc + partner, decoded_data, (Byte *) pbuf, 1); + pbuf += 38; + break; + case PT_SPX: + len = spx_decode(dec_spxbits + partner, dec_spx[partner], + decoded_data, (Byte *) pbuf, 1); + pbuf += SZ_SPX; + break; + case PT_G726: + len = + g726_decode(dec_g726 + partner, decoded_data, (Byte *) pbuf, 1); + pbuf += 80; + break; + } + return_if(len != FRAMESIZE / 2, ERROR); + + int ret = from_cirbuf[partner].push((char *) decoded_data, 2 * len); + if (ret < 0) { + syslog(LOG_WARNING, "from_cirbuf[%d].push overrun=%d\n", partner, + ret / FRAGSIZE); + } + if (telephone_conference) { + ret = conf_cirbuf[partner].push((char *) decoded_data, 2 * len); + if (ret < 0) { + /* syslog(LOG_WARNING, "conf_cirbuf[%d].push overrun=%d\n", + partner, ret/FRAGSIZE); */ + } + } + } + return OKAY; +} + +void spx_encoder_init(int i) +{ + speex_bits_init(enc_spxbits + i); + enc_spx[i] = speex_encoder_init(&speex_wb_mode); + int value = SPX_QUALITY; + speex_encoder_ctl(enc_spx[i], SPEEX_SET_QUALITY, &value); + value = SPX_BITRATE; + speex_encoder_ctl(enc_spx[i], SPEEX_SET_BITRATE, &value); + value = SPX_COMPLEXITY; + speex_encoder_ctl(enc_spx[i], SPEEX_SET_COMPLEXITY, &value); +} + +// user command +void command(char *cmd, int udp_fd) +{ + /* delete special characters like \r, \n */ + unsigned int i; + for (i = 0; i < strlen(cmd); ++i) { + if (cmd[i] < ' ') { /* hack: assume ASCII coding */ + cmd[i] = 0; + break; + } + } + in_addr_t ip; + switch (cmd[0]) { + default: + printf("voipconf commands:\n" + "c IP-Adress - connect to IP-Adress\n" + "h IP-Adress - hang-up IP-Adress\n\n"); + fflush(stdout); + break; + case 'p': + /* do nothing */ + break; + case 'c': + ip = atoip(cmd + 2); + for (i = 0; i < PARTNERS; ++i) { + if (0 == to_ip[i]) { + if (0 == to_partners) { + mic_cirbuf.init(); + } + tx_buf_init(i); + to_ip[i] = ip; + to_rtp[i].init(tx_payloadt, to_ssrc); + to_udp[i].send_init(cmd + 2, rtp_port, udp_fd); + switch (tx_payloadt) { + case PT_EFR: + enc_efr[i].initEncode(0); + break; + case PT_G729: + enc_g729[i].initEncode(0); + break; + case PT_iLBC: + initEncode(enc_ilbc + i, ILBC_MODE); + break; + case PT_GSM: + rpeltp_delete(enc_gsm[i]); + enc_gsm[i] = rpeltp_init(); + break; + case PT_SPX: + speex_bits_destroy(enc_spxbits + i); + speex_encoder_destroy(enc_spx[i]); + spx_encoder_init(i); + break; + } + ++to_partners; + break; + } + } + break; + case 'h': + ip = atoip(cmd + 2); + for (i = 0; i < PARTNERS; ++i) { + if (ip == to_ip[i]) { + to_ip[i] = 0; + to_udp[i].send_close(); + --to_partners; + + print_gui("%s\n", cmd); /* Tcl/Tk needs \n */ + break; + } + } + break; + } + + /* syslog(LOG_WARNING, "cmd=%s to_partners=%d\n", cmd, to_partners); */ +} + +#define CMDLEN 80 + +// local signalling from intercom.tcl +int gui_read(int gui_fd, int udp_fd) +{ + char cmd[CMDLEN]; + + int len = read(gui_fd, cmd, CMDLEN); + + if (len <= 0) { + syslog(LOG_WARNING, "gui_read() close\n"); + int ret = shutdown(gui_fd, SHUT_RDWR); + assert_errno(ret >= 0); + + return -1; + } + + command(cmd, udp_fd); + + return gui_fd; +} + +static int gui_fd = -1; + +int print_gui(const char *fmt, ...) +{ +/* in fmt: Formatstring as printf */ +/* in ...: Parameter(s) as printf */ + + if (gui_fd >= 0) { + char s[MTU]; + va_list ap; + va_start(ap, fmt); + (void) vsnprintf(s, MTU, fmt, ap); + va_end(ap); + + int len = strlen(s); + + return write(gui_fd, s, len); + } else { + return ERROR; + } +} + +struct timeval difftimeval(struct timeval time1, struct timeval time2) +{ + struct timeval diff; + + diff.tv_usec = time1.tv_usec - time2.tv_usec; + if (diff.tv_usec < 0) { + diff.tv_usec += 1000000; + time2.tv_usec += 1; + } + diff.tv_sec = time1.tv_sec - time2.tv_sec; + + return diff; +} + +float dB2q(float dB) +{ + /* Dezibel to Ratio */ + return powf(10.0f, dB / 20.0f); +} +float q2dB(float q) +{ + /* Ratio to Dezibel */ + return 20.0f * log10f(q); +} + +/* program main loop. OS Event handler */ +int loop(int audio_rd_fd, int udp_fd, int gui_listen_fd) +{ + + struct timeval timeout; + fd_set read_fds; + int max_fd = 64; /* should be max(fd, ..) + 1 */ + static struct timeval last_partner_timeout; + static struct timeval last_getambient; + static struct timeval last_spkout; + static long remainder_spkout = 0; + struct timezone tz; + static int mic_int, spk_int, time_int; + + openlog(NULL, LOG_PERROR, LOG_WARNING); + + gettimeofday(&last_partner_timeout, &tz); + gettimeofday(&last_getambient, &tz); + gettimeofday(&last_spkout, &tz); + for (;;) { + timeout.tv_sec = 0; + timeout.tv_usec = FRAGTIME * 1000; + FD_ZERO(&read_fds); + FD_SET(audio_rd_fd, &read_fds); + FD_SET(udp_fd, &read_fds); + FD_SET(gui_listen_fd, &read_fds); + if (gui_fd >= 0) { + FD_SET(gui_fd, &read_fds); + } + // int ret = select(max_fd, &read_fds, NULL, NULL, &timeout); + int ret = select(max_fd, &read_fds, NULL, NULL, NULL); + assert_errno(ret >= 0); + + if (FD_ISSET(audio_rd_fd, &read_fds)) { + audio_read(audio_rd_fd); + ++mic_int; + } + if (FD_ISSET(udp_fd, &read_fds)) { + udp_read(udp_fd); + } + if (FD_ISSET(gui_listen_fd, &read_fds)) { + gui_fd = tcp_server_init2(gui_listen_fd); + } + if (gui_fd >= 0) { + if (FD_ISSET(gui_fd, &read_fds)) { + gui_fd = gui_read(gui_fd, udp_fd); + } + } +#if 0 + if ((mic_int % (5000 / FRAGTIME)) == 0) { + printf("int: mic %d spk %d time %d\n", mic_int, spk_int, + time_int); + } +#endif + + struct timeval now, diff; + if (packetlc) { + gettimeofday(&now, &tz); + diff = difftimeval(now, last_spkout); + if (diff.tv_usec + remainder_spkout >= FRAGTIME * 1000) { + ++time_int; + last_spkout = now; + /* Linux time resolution is more coarse (15ms) then mic + * time interval (4ms), therefore remainder calculation */ + remainder_spkout = + diff.tv_usec + remainder_spkout - FRAGTIME * 1000; + if (audio_wr_fd < 0) { + /* new output: fill up Open Sound System (OSS) buffer + * to compensate Operation System Jitter */ + // audio_write(); + } + audio_write(); + ++spk_int; + } + } else { + /* because of problems with Intel ICH5/Analog Devices AD1985 + * not together with audio_read() */ + audio_write(); + } + + gettimeofday(&now, &tz); + diff = difftimeval(now, last_partner_timeout); + if (diff.tv_usec >= 160000) { /* 2*PACKETDURATION in usec */ + last_partner_timeout = now; + partner_timeout(); + } +#if 0 + gettimeofday(&now, &tz); + diff = difftimeval(now, last_getambient); + if (diff.tv_sec >= 2) { + last_getambient = now; + // if (to_partners > 0) { + // float ambient = aec.getambient(); + // float ambientdB = q2dB(ambient / 32767.0f); + // syslog(LOG_WARNING, "Ambient = %2.0f dB\n", ambientdB); + float xfastdB = q2dB(aec.xfast / 32767.0f); + float dfastdB = q2dB(aec.dfast / 32767.0f); + float efastdB = q2dB(aec.efast / 32767.0f); + float xslowdB = q2dB(aec.xslow / 32767.0f); + float dslowdB = q2dB(aec.dslow / 32767.0f); + syslog(LOG_WARNING, "ratio= %2.0f / %2.0f / %2.0f / %2.0f e= %2.0f\n", + dfastdB, xfastdB, dslowdB, xslowdB, efastdB); + // } + } +#endif + } + return ERROR; +} + +int main(int argc, char *argv[]) +{ + int i; + float ambient = 0.0f; + float dB; + +#if WIDEB==1 + tx_payloadt = PT_iLBC; + tx_packsize = SZ_iLBC; + printf("Narrowband DFS VoIP Intercom %s\n", VERSION); +#else + tx_payloadt = PT_SPX; + tx_packsize = SZ_SPX; + printf("Wideband DFS VoIP Intercom %s\n", VERSION); +#endif + for (i = 1; i < argc && '-' == argv[i][0]; ++i) { + switch (argv[i][1]) { + case 'a': /* set Ambient (No Talking) Noise level */ + ambient = atof(argv[++i]); + break; + case 'b': /* No AES */ + dB = atof(argv[++i]); + if (dB < 0.0f) { + aec.setaes(dB2q(dB)); + } else { + aec.setaes(0.0f); // 0 is no AES + } + break; + case 'e': + sinuson = 1; /* Sinuston 2040Hz zumischen */ + break; + case 'k': /* packet loss concealment */ + packetlc = YES; + break; + case 'f': /* Frames */ + tx_frames = atoi(argv[++i]); + if (tx_frames < 1) + tx_frames = 1; + if (tx_frames > 4) + tx_frames = 4; + break; + case 'l': /* use hardware AEC and Line-in for microphone */ + channels = 2; + break; + case 'm': /* use hardware AEC and Mic-in for microphone */ + channels = 2; + break; + case 'p': /* RTP Portnumber */ + rtp_port = atoi(argv[++i]); + rtp_port &= 0xFFFE; /* RFC3551: RTP port has even port number */ + break; + case 's': /* simulated Packet loss */ + packet_loss = (RAND_MAX / 100) * atoi(argv[++i]); + break; + case 't': /* Telephone conference call (true conference) */ + telephone_conference = YES; + break; + case 'w': /* visualize vector w */ + aec.openwdisplay(); + break; +#if WIDEB==1 + case 'A': /* set G.711 A-law */ + tx_payloadt = PT_PCMA; + tx_packsize = 160; /* see RFC3551 */ + break; + case 'U': /* set G.711 u-law */ + tx_payloadt = PT_PCMU; + tx_packsize = 160; /* see RFC3551 */ + break; + case '6': /* set G.726 codec */ + tx_payloadt = PT_G726; + tx_packsize = 80; /* see RFC3551 */ + break; + case 'G': /* set GSM codec */ + tx_payloadt = PT_GSM; + tx_packsize = 33; /* see RFC3551 */ + break; + case 'E': /* set GSM-EFR codec */ + tx_payloadt = PT_EFR; + tx_packsize = 31; /* see RFC3551 */ + break; + case '9': /* set G.729 codec */ + tx_payloadt = PT_G729; + tx_packsize = 20; /* see RFC3551 */ + break; +#else + case 'S': /* set Speex codec */ + tx_payloadt = PT_SPX; + tx_packsize = SZ_SPX; /* 16.8kBit/s Wideband */ + break; +#endif + } + } + + /* do -a option even if codec options follows */ + if (ambient != 0.0f) { + aec.setambient(MAXPCM * dB2q(ambient)); + } + + /* init Sinuston fuer Transmitter */ + sinuston.frequenz(2040, WIDEB*8000, -24.0f); + + /* open Audio Receive */ + int audio_rd_fd = audio_init("/dev/dsp", channels, O_RDONLY); + assert(audio_rd_fd >= 0); + + /* open Network Receive */ + int udp_fd = UDP_recv_init(rtp_port); + assert(udp_fd >= 0); + + /* open Graphical User Interface as TCP server */ + int gui_listen_fd = tcp_server_init(4999); + + /* codec Initialization */ + int j; + for (j = 0; j < PARTNERS; ++j) { + /* iLBC */ + initEncode(enc_ilbc + j, ILBC_MODE); + initDecode(dec_ilbc + j, ILBC_MODE, 1); + + /* GSM-EFR */ + enc_efr[j].initEncode(0); + dec_efr[j].initDecode(); + + /* G.729 */ + enc_g729[j].initEncode(0); + dec_g729[j].initDecode(); + + /* GSM */ + enc_gsm[i] = rpeltp_init(); + dec_gsm[i] = rpeltp_init(); + + /* Speex */ + spx_encoder_init(j); + + speex_bits_init(dec_spxbits + j); + dec_spx[j] = speex_decoder_init(&speex_wb_mode); // Wideband + int value = SPX_ENH; + speex_decoder_ctl(dec_spx[j], SPEEX_SET_ENH, &value); + } + + /* open Network Transmit Partner (Connections) */ + to_ssrc = random32(tx_payloadt); + printf("to_ssrc = %08lx\n", to_ssrc); + for (; i < argc; ++i) { + if (0 == to_partners) { + mic_cirbuf.init(); + } + tx_buf_init(to_partners); + to_ip[to_partners] = atoip(argv[i]); + to_rtp[to_partners].init(tx_payloadt, to_ssrc); + to_udp[to_partners].send_init(argv[i], rtp_port, udp_fd); + ++to_partners; + } + + loop(audio_rd_fd, udp_fd, gui_listen_fd); + + return OKAY; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/intercomd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/intercomd.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,40 @@ +/* intercomd.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Voice over IP Intercom with Telephone conference and Acoustic Echo + * Cancellation using unicast RTP messages (RFC3550) + * + * Version 0.2 + */ +#ifndef _INTERCOMD_H + +#include + +#define ERROR (-1) +#define OKAY 0 + +#define NO 0 +#define YES 1 + +/* Emit program info and abort the program if expr is false with errno */ +#define assert_errno(expr) \ +if(!(expr)) { \ + syslog(LOG_WARNING, "%s:%d: %s: Assertion '%s' failed. errno=%s\n", \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(expr), strerror(errno)); \ + exit(1); \ +} + +/* Emit program info and return function if expr is true with retvalue */ +#define return_if(expr, retvalue) \ +if(expr) { \ + syslog(LOG_WARNING, "%s:%d: %s: Check '%s' failed.\n", \ + __FILE__, __LINE__, __PRETTY_FUNCTION__, __STRING(expr)); \ + return(retvalue); \ +} + +int print_gui(const char *fmt, ...); + +#define _INTERCOMD_H +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/linux/.bashrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/linux/.bashrc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,54 @@ +# Sample .bashrc for SuSE Linux +# Copyright (c) SuSE GmbH Nuernberg + +# There are 3 different types of shells in bash: the login shell, normal shell +# and interactive shell. Login shells read ~/.profile and interactive shells +# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all +# settings made here will also take effect in a login shell. +# +# NOTE: It is recommended to make language settings in ~/.profile rather than +# here, since multilingual X sessions would not work properly if LANG is over- +# ridden in every subshell. + +# This might be helpful for Linux newbies who previously used DOS... +test -f /etc/profile.dos && . /etc/profile.dos + +# Some applications read the EDITOR variable to determine your favourite text +# editor. So uncomment the line below and enter the editor of your choice :-) +#export EDITOR=/usr/bin/vim +#export EDITOR=/usr/bin/mcedit + +# For some news readers it makes sense to specify the NEWSSERVER variable here +#export NEWSSERVER=your.news.server + +# If you want to use a Palm device with Linux, uncomment the two lines below. +# For some (older) Palm Pilots, you might need to set a lower baud rate +# e.g. 57600 or 38400; lowest is 9600 (very slow!) +# +#export PILOTPORT=/dev/pilot +#export PILOTRATE=115200 + +test -s ~/.alias && . ~/.alias + +alias shut="/sbin/shutdown -h now" +alias boot="/sbin/shutdown -r now" + +export LD_LIBRARY_PATH=/usr/local/lib + +export PATH=$PATH:/opt/OpenOffice.org/program + +# Fuer xfe und nedit +export LANG=de_DE@euro +export LC_CTYPE="de_DE@euro" +export LC_NUMERIC="de_DE@euro" +export LC_TIME="de_DE@euro" +export LC_COLLATE="de_DE@euro" +export LC_MONETARY="de_DE@euro" +export LC_MESSAGES="de_DE@euro" +export LC_PAPER="de_DE@euro" +export LC_NAME="de_DE@euro" +export LC_ADDRESS="de_DE@euro" +export LC_TELEPHONE="de_DE@euro" +export LC_MEASUREMENT="de_DE@euro" +export LC_IDENTIFICATION="de_DE@euro" + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/linux/.fvwm2rc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/linux/.fvwm2rc Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,479 @@ +# window buttons +# +#Large up Triangle for Maximize +ButtonStyle 2 4 50x24@1 75x74@0 25x74@0 50x24@1 + +#Large down Triangle for Triangle +ButtonStyle 4 4 50x74@1 75x24@0 25x24@1 50x74@1 + +#Cross for Stick +ButtonStyle 3 13 20x60@1 20x40@1 40x40@1 40x20@1 60x20@1 60x40@0 80x40@1 80x60@0 60x60@0 60x80@0 40x80@0 40x60@1 20x60@0 + + +#general configuration + +DeskTopSize 3x2 +EdgeResistance 250 10 +EdgeScroll 0 0 +ClickTime 750 +ColormapFocus FollowsMouse +IgnoreModifiers L2 +OpaqueMoveSize 100 + + +#paths specific to fvwm2 + +ModulePath /usr/X11R6/lib/X11/fvwm2 +ImagePath /usr/X11R6/share/icons/xpm/hicolor/all:/usr/X11R6/share/icons/xpm/locolor/all:/usr/X11R6/lib/X11/fvwm2/pixmaps:/usr/share/wallpapers + + +#colors + +# 0 = Default colors +# 1 = Inactive windows +# 2 = Active windows +# 3 = Inactive menu entry and menu background +# 4 = Active menu entry +# 5 = greyed out menu entry (only bg used) +# 6 = module foreground and background) +# 7 = hilight colors +*FvwmTheme: Colorset 0 fg black, bg rgb:6f/a1/dc +*FvwmTheme: Colorset 1 fg black, bg rgb:a1/b2/c8 +*FvwmTheme: Colorset 2 fg black, bg rgb:70/a2/dd +*FvwmTheme: Colorset 3 fg black, bg rgb:c8/d3/e5, VGradient 100 dtcolor5 rgb:c8/d3/e5 +*FvwmTheme: Colorset 4 fg black, bg rgb:91/ae/d6 +*FvwmTheme: Colorset 5 fg rgb:d2/bf/a8, bg rgb:b4/aa/94 +*FvwmTheme: Colorset 6 fg black, bg rgb:b4/aa/94, VGradient 100 dtcolor5 rgb:b4/aa/94 +*FvwmTheme: Colorset 7 fg black, bg rgb:94/ab/bf + +S# run FvwmTheme before anything else is done +ModuleSynchronous Timeout 5 FvwmTheme +# +# general setup +# +Style * Colorset 1 +Style * HilightColorset 2 +MenuStyle * MenuColorset 3 +MenuStyle * ActiveColorset 4 +MenuStyle * GreyedColorset 5 + +XORvalue 255 + +#fonts +DefaultFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=10;-misc-*-medium-r-semicondensed-*-13-*-*-*-*-*-iso10646-1" +WindowFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:style=bold:size=10;-misc-fixed-bold-r-normal-*-13-*-*-*-*-*-iso10646-1" +IconFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=8;-misc-fixed-medium-r-normal-*-10-*-*-*-*-*-iso10646-1" + + +#fvwm system functions + +AddToFunc QuitSave + + "I" Quit +AddToFunc InitFunction + + "I" Module FvwmBanner + + "I" Exec susewmif xmessages + + "I" Exec xterm -ls -geometry +150+85 + + "I" Module FvwmButtons + + "I" Exec fvwm-root /usr/share/wallpapers/suse9.1-default.png + + "I" Exec intercom -l -S -t + +AddToFunc RestartFunction + + "I" Module FvwmBanner + + "I" Module FvwmButtons + + "I" Exec xmessages + + "I" Exec fvwm-root /usr/share/wallpapers/suse9.1-default.png + +AddToFunc ExitFunction + + "I" Exec xsetroot + + "I" Exec susewmif kill + + "I" Exec xsetroot + +AddToFunc "StartFunction" "I" Module FvwmTaskBar + +#fvwm window modifier functions + +AddToFunc MoveOrRaise ++ "C" Raise ++ "M" Raise ++ "M" Move ++ "D" Lower +AddToFunc ResizeOrRaise ++ "C" Raise ++ "M" Raise ++ "M" Resize ++ "D" Lower +AddToFunc MaximizeFunc ++ "M" Maximize 0 100 ++ "C" Maximize 0 80 ++ "D" Maximize 100 100 +AddToFunc MoveOrIconify ++ "I" Raise ++ "M" Raise ++ "M" Move ++ "D" Iconify + + +#buttonbar menu + +AddToMenu bargraphicspopup "Graphics" Title + + "Gimp" Exec gimp + + "XV" Exec xv + +AddToMenu bartoolspopup "Tools" Title +# + "Mozilla" Exec mozilla + + "Internet" Exec qinternet + + "Browser" Exec konqueror + + "Opera" Exec opera + + "Mail" Exec netscape -messenger + + "File" Exec xfe + +AddToMenu barshellspopup "Shell in XTerm" Title + + "Shell in XTerm" Exec xterm -e bash -login + + "Root shell" Function RootShell + +AddToMenu barsusepopup "SUSE" Title + + "Control Center" Exec xterm -e su - -cyast2 + + "Help" Exec susehelp + + "SUSE menu" Popup xdg_menu + + +AddToFunc RootShell + + "I" Exec xterm -ls -vb -sb -sl 2000 -T Root -n Root -j -rw +vb -bg \#ff8c6d -e su - + +AddToMenu windowops "Window menu (Shift-Alt-Space)" Title + + "Mo&ve (Alt-F5) " Move + + "Resi&ze (Alt-F6) " Resize + + "&Iconify (Alt-F4) " Iconify + + "&Maximize/Normal (Shift-Alt-F3) " Maximize + + "(Un)St&ick (Shift-Alt-F4) " Stick + + "" Nop + + "Window &list (Alt-F11) " WindowList + + "" Nop + + "&Close (Alt-F9) " Delete + + "&Kill (Alt-F11) " Destroy + + +#Menu: Fvwm-Manpages + +AddToMenu manpages_popup "Fvwm-Manpages" Title + + "FvwmAudio" Exec xterm -e man FvwmAudio + + "FvwmAuto" Exec xterm -e man FvwmAuto + + "FvwmBacker" Exec xterm -e man FvwmBacker + + "FvwmBanner" Exec xterm -e man FvwmBanner + + "FvwmButtons" Exec xterm -e man FvwmButtons + + "FvwmCascade" Exec xterm -e man FvwmCascade + + "FvwmCommand" Exec xterm -e man FvwmCommand + + "FvwmConfig" Exec xterm -e man FvwmConfig + + "FvwmConsole" Exec xterm -e man FvwmConsole + + "FvwmConsoleC" Exec xterm -e man FvwmConsoleC + + "FvwmCpp" Exec xterm -e man FvwmCpp + + "FvwmDebug" Exec xterm -e man FvwmDebug + + "FvwmForm" Exec xterm -e man FvwmForm + + "FvwmGoodStuff" Exec xterm -e man FvwmGoodStuff + + "FvwmIconBox" Exec xterm -e man FvwmIconBox + + "FvwmIconMan" Exec xterm -e man FvwmIconMan + + "FvwmIdent" Exec xterm -e man FvwmIdent + + "FvwmM4" Exec xterm -e man FvwmM4 + + "FvwmPager" Exec xterm -e man FvwmPager + + "FvwmSave" Exec xterm -e man FvwmSave + + "FvwmSaveDesk" Exec xterm -e man FvwmSaveDesk + + "FvwmScript" Exec xterm -e man FvwmScript + + "FvwmScroll" Exec xterm -e man FvwmScroll + + "FvwmTalk" Exec xterm -e man FvwmTalk + + "FvwmTaskBar" Exec xterm -e man FvwmTaskBar + + "FvwmTile" Exec xterm -e man FvwmTile + + "FvwmWharf" Exec xterm -e man FvwmWharf + + "FvwmWinList" Exec xterm -e man FvwmWinList + + + +#Menu: Modules + +AddToMenu modules_popup "Modules" Title + + "Audio" Module FvwmAudio + + "Autoraise off" KillModule FvwmAuto + + "Autoraise 500ms" Module FvwmAuto 500 + + "Banner" Module FvwmBanner + + "Buttons" Module FvwmButtons + + "Cascade" Module FvwmCascade + + "Command" Module FvwmCommand + + "Config" Module FvwmConfig + + "Console" Module FvwmConsole + + "Debug" Module FvwmDebug + + "Form" Module FvwmForm + + "GoodStuff" Module FvwmGoodStuff + + "IconBox" Module FvwmIconBox + + "IconMan" Module FvwmIconMan + + "Ident" Module FvwmIdent + + "M4" Module FvwmM4 + + "Pager" Module FvwmPager 0 0 + + "Pipe" Module FvwmPipe + + "Save" Module FvwmSave + + "SaveDesk" Module FvwmSaveDesk + + "Script" Module FvwmScript + + "Scroll" Module FvwmScroll + + "Talk" Module FvwmTalk + + "TaskBar" Module FvwmTaskBar + + "Tile" Module FvwmTile + + "Wharf" Module FvwmWharf + + "WinList" Module FvwmWinList + + + +#Menu: WindowManager + +AddToMenu THISWM_MENU_popup "WindowManager" Title + + "Modules" Popup modules_popup + + "Fvwm-Manpages" Popup manpages_popup + + "" Nop + + "Fvwm2-Manpage" Exec xterm -e man fvwm + + "" Nop + + "Restart Fvwm2" Restart + + "" Nop + + "Exit" Quit + + + +#Menu: Keyboardclicks + +AddToMenu settings_kbdclick_popup "Keyboardclicks" Title + + "hard" Exec xset c 100 + + "Off" Exec xset c off + + "soft" Exec xset c on + + +#Menu: Mouse + +AddToMenu settings_mouse_popup "Mouse" Title + + "fast" Exec xset m 4 2 + + "Left handed mouse" Exec xmodmap -e + + "normal" Exec xset m 2 5 + + "slow" Exec xset m 1 1 + + + +#Menu: Speaker + +AddToMenu settings_speaker_popup "Speaker" Title + + "loud" Exec xset b 100 600 50 + + "normal" Exec xset b on + + "loud and long" Exec xset b 100 600 300 + + "Off" Exec xset b off + + + +#Menu: xlock + +AddToMenu settings_xlock_popup "xlock" Title + + "Blank" Exec xset s blank + + "Off" Exec xset s off + + "Pattern after 5 min" Exec xset s noblank s 300 300 + + "Immediately" Exec xset s activate + + "Default" Exec xset s default + + + +#Menu: Screen + +PipeRead 'fvwm-menu-xlock --special-first' +PipeRead 'fvwm-menu-xlock --special-first --name=XSaverMenu -- -nolock' + +AddToMenu screen_popup "Screen" Title + + "Screen-Lock" Popup XLockMenu + + "Screensaver" Popup XSaverMenu + + + +#Menu: Settings + +AddToMenu settings_popup "Settings" Title + + "Keyboardclicks" Popup settings_kbdclick_popup + + "Mouse" Popup settings_mouse_popup + + "Speaker" Popup settings_speaker_popup + + "xlock" Popup settings_xlock_popup + + +#Menu: Work + +PipeRead 'xdg_menu --charset UTF-8 --format fvwm2' + +AddToMenu WORK_MENU_popup "Work Menu" Title + + "Shell" Exec xterm -e bash -login + + "" Nop + + "Top" Exec xterm -e top + + "" Nop + + "Screen" Popup screen_popup + + "Settings" Popup settings_popup + + "WindowManager" Popup THISWM_MENU_popup + + "SUSE" Popup xdg_menu + +Style "FvwmPager" NoTitle, Sticky, WindowListSkip +*FvwmPagerRows 1 +*FvwmPagerColumns 1 +*FvwmPagerGeometry -0+0 +*FvwmPagerFore Black +*FvwmPagerBack grey67 +*FvwmPagerHilight grey50 +*FvwmPagerFont none +*FvwmPagerSmallFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=6;-misc-fixed-medium-r-normal--7-*-*-*-*-*-iso10646-1" + +AddToFunc barthiswmpopupfunc + + "I" Popup THISWM_MENU_popup + +AddToFunc barsusepopupfunc + + "I" Popup barsusepopup + +AddToFunc bargraphicspopupfunc + + "I" Popup bargraphicspopup + +AddToFunc bartoolspopupfunc + + "I" Popup bartoolspopup + +AddToFunc barshellspopupfunc + + "I" Popup barshellspopup + +*FvwmButtonsFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=9;-*-*-medium-*-semicondensed-*-12-*-*-*-*-*-iso10646-1" +*FvwmButtonsFore Black +*FvwmButtonsBack grey67 +*FvwmButtonsGeometry +0+0 +*FvwmButtonsRows 1 +*FvwmButtons (2x1 Frame 0 Swallow(UseOld) "FvwmPager" "Module FvwmPager 0 0") +*FvwmButtons: (Swallow FvwmXeyes 'Exec xeyes -name "FvwmXeyes" -geometry +0+0 -bg grey67 &') +*FvwmButtons: (Swallow FvwmXclock 'Exec xclock -name "FvwmXclock" -geometry +0+0 -padding 1 -bg grey67 &') +*FvwmButtons Fvwm2 fvwm.xpm Function barthiswmpopupfunc +*FvwmButtons SUSE big.SuSEmenu.xpm Function barsusepopupfunc +*FvwmButtons Graphics gimp.xpm Function bargraphicspopupfunc +*FvwmButtons Tools toolbox.xpm Function bartoolspopupfunc +*FvwmButtons Shells xterm.xpm Function barshellspopupfunc +#style options for modules and programs in fvwm2 + +BorderStyle Inactive -- HiddenHandles NoInset +Style "*" BackColor Grey +Style "*" ForeColor DimGrey +Style "*" SloppyFocus +Style "*" DecorateTransient +Style "*" IconBox +55 +85 +130 +480 +Style "*" StickyIcon +Style "*" SmartPlacement, RandomPlacement, ResizeOpaque +Style "*" NoPPosition +Style "FvwmWinList" NoTitle, WindowListSkip +Style "FvwmButtons" NoTitle, Sticky, WindowListSkip +Style "FvwmBanner" NoTitle, Sticky, StaysOnTop, WindowListSkip +Style "IconManModule" NoTitle, Sticky, NoHandles, Icon toolbox.xpm + +Style "FvwmTaskBar" NoTitle, Sticky, NoHandles, StaysOnTop + +Style "xeyes" SmartPlacement, RandomPlacement +Style "xclock" SmartPlacement, RandomPlacement + +# see bug #36189 +Style "AcroRead" SmartPlacement, RandomPlacement +# see bug #36188 +Style "OpenOffice*" NoPPosition, RandomPlacement, EWMHIgnoreStrutHints, EWMHMaximizeIgnoreWorkingArea, EWMHPlacementIgnoreWorkingArea + +*FvwmBackerDesk 0 -solid steelblue +*FvwmBackerDesk 1 -solid midnightblue +*FvwmBackerDesk 2 -solid yellow +*FvwmBackerDesk 3 -solid cadetblue2 +*FvwmBackerDesk 5 -solid cadetblue3 +*FvwmBackerDesk 6 -solid cadetblue4 + +*FvwmIdentBack MidnightBlue +*FvwmIdentFore Yellow +*FvwmIdentFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=10;-misc-fixed-medium-r-normal--13-*-*-*-*-*-iso10646-1" +*FvwmNoClutter 3600 Iconify 1 +*FvwmNoClutter 86400 Delete +*NoClutterModule 172800 + +*FvwmWinListBack Grey +*FvwmWinListFore Black +*FvwmWinListFocusBack Black +*FvwmWinListFocusFore Grey +*FvwmWinListIconBack LightGrey +*FvwmWinListIconFore DimGrey +*FvwmWinListFont "StringEncoding=UTF-8:xft:sans-serif:encoding=iso10646-1:size=11;-misc-fixed-medium-r-normal--15-*-*-*-*-*-iso10646-1" +*FvwmWinListAction Click1 Iconify -1,Focus +*FvwmWinListAction Click2 Iconify +*FvwmWinListAction Click3 Module "FvwmIdent" FvwmIdent +*FvwmWinListGeometry +0-1 +*FvwmWinListUseSkipList +*FvwmWinListUseIconNames + +*FvwmTaskBar: AutoHide +*FvwmTaskBar: StartMenu xdg_menu + +# Key bindings + +Key Left A SM Scroll -100 +0 +Key Left A C CursorMove -1 0 +Key Left A SC CursorMove -10 +0 + +Key Right A SM Scroll +100 +0 +Key Right A C CursorMove +1 0 +Key Right A SC CursorMove +10 +0 + +Key Up A SM Scroll +0 -100 +Key Up A C CursorMove +0 -1 +Key Up A SC CursorMove +0 -10 + +Key Down A SM Scroll +0 +100 +Key Down A C CursorMove +0 +1 +Key Down A SC CursorMove +0 +10 + +Key F1 A M Menu WORK_MENU_popup +Key F2 A M WindowList +Key F3 A M Menu xdg_menu +Key F4 A M Iconify +Key F5 A M Move +Key F6 A M Resize +Key F7 A M Raise +Key F8 A M Lower +Key F9 A M Delete +Key F10 A M Destroy + +Key F11 A M Prev [*] focus +Key F12 A M Next [*] focus +Key Tab A 4 Next [*] focus +Key Tab A S4 Prev [*] focus + +Key F3 A SM Maximize +Key F4 A SM Stick +Key F5 A SM Refresh + +Key BackSpace A SM Function "QuitSave" + +#button bar popup menus +Key s A SM Function "barsusepopupfunc" +Key g A SM Function "bargraphicpopupfunc" +Key t A SM Function "bartoolspopupfunc" +Key l A SM Function "barshellpopupfunc" +Key m A SM Function "MailFunc" + +Key F1 A SM Restart fvwm2 + + + +# Mouse bindings + +Mouse 1 R A Menu WORK_MENU_popup Nop +Mouse 2 R A Module FvwmWinList Transient +Mouse 3 R A Menu xdg_menu Nop +Mouse 2 FST A Menu windowops Nop + +Mouse 1 1 A Menu windowops Delete +Mouse 2 1 A Menu windowops Destroy +Mouse 3 1 A Menu windowops Nop + +Mouse 1 SF A Function "ResizeOrRaise" + +Mouse 1 T A Function "MoveOrRaise" + +Mouse 1 I A Iconify +Mouse 2 I A Iconify +Mouse 3 TSIF A RaiseLower + +Mouse 1 2 A Maximize 0 100 +Mouse 2 2 A Maximize 100 100 +Mouse 3 2 A Maximize 100 0 +Mouse 0 4 A Iconify +Mouse 1 3 A Stick diff -r 9cadc470e3da -r 13be24d74cd2 intercom/linux/.nedit --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/linux/.nedit Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,365 @@ +! Preferences file for NEdit +! +! This file is overwritten by the "Save Defaults..." command in NEdit +! and serves only the interactively settable options presented in the NEdit +! "Preferences" menu. To modify other options, such as background colors +! and key bindings, use the .Xdefaults file in your home directory (or +! the X resource specification method appropriate to your system). The +! contents of this file can be moved into an X resource file, but since +! resources in this file override their corresponding X resources, either +! this file should be deleted or individual resource lines in the file +! should be deleted for the moved lines to take effect. + +nedit.fileVersion: 5.3 +nedit.shellCommands: \ + spell:Alt+B:s:EX:\n\ + cat>spellTmp; xterm -e ispell -x spellTmp; cat spellTmp; rm spellTmp\n\ + wc::w:ED:\n\ + set wc=`wc`; echo $wc[1] "lines," $wc[2] "words," $wc[3] "characters"\n\ + sort::o:EX:\n\ + sort\n\ + number lines::n:AW:\n\ + nl -ba\n\ + make:Alt+Z:m:W:\n\ + make\n\ + expand::p:EX:\n\ + expand\n\ + unexpand::u:EX:\n\ + unexpand\n +nedit.macroCommands: \ + Complete Word:Alt+D::: {\n\ + # Tuning parameters\n\ + ScanDistance = 200\n\ + \n\ + # Search back to a word boundary to find the word to complete\n\ + startScan = max(0, $cursor - ScanDistance)\n\ + endScan = min($text_length, $cursor + ScanDistance)\n\ + scanString = get_range(startScan, endScan)\n\ + keyEnd = $cursor-startScan\n\ + keyStart = search_string(scanString, "<", keyEnd, "backward", "regex")\n\ + if (keyStart == -1)\n\ + return\n\ + keyString = "<" substring(scanString, keyStart, keyEnd)\n\ + \n\ + # search both forward and backward from the cursor position. Note that\n\ + # using a regex search can lead to incorrect results if any of the special\n\ + # regex characters is encountered, which is not considered a delimiter\n\ + backwardSearchResult = search_string(scanString, keyString, keyStart-1, \\\n\ + "backward", "regex")\n\ + forwardSearchResult = search_string(scanString, keyString, keyEnd, "regex")\n\ + if (backwardSearchResult == -1 && forwardSearchResult == -1) {\n\ + beep()\n\ + return\n\ + }\n\ + \n\ + # if only one direction matched, use that, otherwise use the nearest\n\ + if (backwardSearchResult == -1)\n\ + matchStart = forwardSearchResult\n\ + else if (forwardSearchResult == -1)\n\ + matchStart = backwardSearchResult\n\ + else {\n\ + if (keyStart - backwardSearchResult <= forwardSearchResult - keyEnd)\n\ + matchStart = backwardSearchResult\n\ + else\n\ + matchStart = forwardSearchResult\n\ + }\n\ + \n\ + # find the complete word\n\ + matchEnd = search_string(scanString, ">", matchStart, "regex")\n\ + completedWord = substring(scanString, matchStart, matchEnd)\n\ + \n\ + # replace it in the window\n\ + replace_range(startScan + keyStart, $cursor, completedWord)\n\ + }\n\ + Fill Sel. w/Char:::R: {\n\ + if ($selection_start == -1) {\n\ + beep()\n\ + return\n\ + }\n\ + \n\ + # Ask the user what character to fill with\n\ + fillChar = string_dialog("Fill selection with what character?", "OK", "Cancel")\n\ + if ($string_dialog_button == 2 || $string_dialog_button == 0)\n\ + return\n\ + \n\ + # Count the number of lines in the selection\n\ + nLines = 0\n\ + for (i=$selection_start; i<$selection_end; i++)\n\ + if (get_character(i) == "\\n")\n\ + nLines++\n\ + \n\ + # Create the fill text\n\ + rectangular = $selection_left != -1\n\ + line = ""\n\ + fillText = ""\n\ + if (rectangular) {\n\ + for (i=0; i<$selection_right-$selection_left; i++)\n\ + line = line fillChar\n\ + for (i=0; i=0 && get_character(i)!="\\n"; i--)\n\ + startIndent++\n\ + for (i=0; i<$wrap_margin-startIndent; i++)\n\ + fillText = fillText fillChar\n\ + fillText = fillText "\\n"\n\ + for (i=0; i<$wrap_margin; i++)\n\ + line = line fillChar\n\ + for (i=0; i=$selection_start && get_character(i)!="\\n"; \\\n\ + i--)\n\ + fillText = fillText fillChar\n\ + }\n\ + }\n\ + \n\ + # Replace the selection with the fill text\n\ + replace_selection(fillText)\n\ + }\n\ + Quote Mail Reply:::: {\n\ + if ($selection_start == -1)\n\ + replace_all("^.*$", "\\\\> &", "regex")\n\ + else\n\ + replace_in_selection("^.*$", "\\\\> &", "regex")\n\ + }\n\ + Unquote Mail Reply:::: {\n\ + if ($selection_start == -1)\n\ + replace_all("(^\\\\> )(.*)$", "\\\\2", "regex")\n\ + else\n\ + replace_in_selection("(^\\\\> )(.*)$", "\\\\2", "regex")\n\ + }\n\ + C Comments>Comment Out Sel.@C@C++:::R: {\n\ + selStart = $selection_start\n\ + selEnd = $selection_end\n\ + replace_range(selStart, selEnd, "/* " get_selection() " */")\n\ + select(selStart, selEnd + 6)\n\ + }\n\ + C Comments>C Uncomment Sel.@C@C++:::R: {\n\ + sel = get_selection()\n\ + selStart = $selection_start\n\ + selEnd = $selection_end\n\ + commentStart = search_string(sel, "/*", 0)\n\ + if (substring(sel, commentStart+2, commentStart+3) == " ")\n\ + keepStart = commentStart + 3\n\ + else\n\ + keepStart = commentStart + 2\n\ + keepEnd = search_string(sel, "*/", length(sel), "backward")\n\ + commentEnd = keepEnd + 2\n\ + if (substring(sel, keepEnd - 1, keepEnd == " "))\n\ + keepEnd = keepEnd - 1\n\ + replace_range(selStart + commentStart, selStart + commentEnd, \\\n\ + substring(sel, keepStart, keepEnd))\n\ + select(selStart, selEnd - (keepStart-commentStart) - \\\n\ + (commentEnd - keepEnd))\n\ + }\n\ + C Comments>+ C++ Comment@C++:::R: {\n\ + replace_in_selection("^.*$", "// &", "regex")\n\ + }\n\ + C Comments>- C++ Comment@C++:::R: {\n\ + replace_in_selection("(^[ \\\\t]*// ?)(.*)$", "\\\\2", "regex")\n\ + }\n\ + C Comments>+ C Bar Comment 1@C:::R: {\n\ + if ($selection_left != -1) {\n\ + dialog("Selection must not be rectangular")\n\ + return\n\ + }\n\ + start = $selection_start\n\ + end = $selection_end-1\n\ + origText = get_range($selection_start, $selection_end-1)\n\ + newText = "/*\\n" replace_in_string(get_range(start, end), \\\n\ + "^", " * ", "regex") "\\n */\\n"\n\ + replace_selection(newText)\n\ + select(start, start + length(newText))\n\ + }\n\ + C Comments>- C Bar Comment 1@C:::R: {\n\ + selStart = $selection_start\n\ + selEnd = $selection_end\n\ + newText = get_range(selStart+3, selEnd-4)\n\ + newText = replace_in_string(newText, "^ \\\\* ", "", "regex")\n\ + replace_range(selStart, selEnd, newText)\n\ + select(selStart, selStart + length(newText))\n\ + }\n\ + Make C Prototypes@C@C++:::: {\n\ + if ($selection_start == -1) {\n\ + start = 0\n\ + end = $text_length\n\ + } else {\n\ + start = $selection_start\n\ + end = $selection_end\n\ + }\n\ + string = get_range(start, end)\n\ + nDefs = 0\n\ + searchPos = 0\n\ + prototypes = ""\n\ + staticPrototypes = ""\n\ + for (;;) {\n\ + headerStart = search_string(string, \\\n\ + "^[a-zA-Z]([^;#\\"'{}=>?~"\n\ + C:.c .h::::::".,/\\`'!|@#%^&*()-=+{}[]"":;<>?~"\n\ + CSS:css::Auto:None:::".,/\\`'!|@#%^&*()=+{}[]"":;<>?~"\n\ + Csh:.csh .cshrc .login .logout:"^[ \\t]*#[ \\t]*![ \\t]*/bin/csh":::::\n\ + Fortran:.f .f77 .for::::::\n\ + Java:.java::::::\n\ + JavaScript:.js::::::\n\ + LaTeX:.tex .sty .cls .dtx .ins::::::\n\ + Lex:.lex::::::\n\ + Makefile:Makefile makefile .gmk:::None:8:8:\n\ + Matlab:.m .oct .sci::::::\n\ + NEdit Macro:.nm .neditmacro::::::\n\ + Pascal:.pas .p .int::::::\n\ + Perl:.pl .pm .p5 .PL:"^[ \\t]*#[ \\t]*!.*perl":Auto:None:::".,/\\\\`'!$@#%^&*()-=+{}[]"":;<>?~|"\n\ + PostScript:.ps .eps .epsf .epsi:"^%!":::::"/%(){}[]<>"\n\ + Python:.py:"^#!.*python":Auto:None:::\n\ + Regex:.reg .regex:"\\(\\?[:#=!iInN].+\\)":None:Continuous:::\n\ + SGML HTML:.sgml .sgm .html .htm:"\\<[Hh][Tt][Mm][Ll]\\>":::::\n\ + SQL:.sql::::::\n\ + Sh Ksh Bash:.sh .bash .ksh .profile .bashrc .bash_logout .bash_login .bash_profile:"^[ \\t]*#[ \\t]*![ \\t]*/.*bin/(sh|ksh|bash)":::::\n\ + Tcl:.tcl .tk .itcl .itk::Smart:None:::\n\ + VHDL:.vhd .vhdl .vdl::::::\n\ + Verilog:.v::::::\n\ + XML:.xml .xsl .dtd:"\\<(?i\\?xml|!doctype)"::None:::"<>/=""'()+*?|"\n\ + X Resources:.Xresources .Xdefaults .nedit:"^[!#].*([Aa]pp|[Xx]).*[Dd]efaults":::::\n\ + Yacc:.y::::::".,/\\`'!|@#%^&*()-=+{}[]"":;<>?~" +nedit.styles: Plain:black:Plain\n\ + Comment:gray20:Italic\n\ + Keyword:black:Bold\n\ + Storage Type:brown:Bold\n\ + Storage Type1:saddle brown:Bold\n\ + String:darkGreen:Plain\n\ + String1:SeaGreen:Plain\n\ + String2:darkGreen:Bold\n\ + Preprocessor:RoyalBlue4:Plain\n\ + Preprocessor1:blue:Plain\n\ + Character Const:darkGreen:Plain\n\ + Numeric Const:darkGreen:Plain\n\ + Identifier:brown:Plain\n\ + Identifier1:RoyalBlue4:Plain\n\ + Subroutine:brown:Plain\n\ + Subroutine1:chocolate:Plain\n\ + Ada Attributes:plum:Bold\n\ + Label:red:Italic\n\ + Flag:red:Bold\n\ + Text Comment:SteelBlue4:Italic\n\ + Text Key:VioletRed4:Bold\n\ + Text Key1:VioletRed4:Plain\n\ + Text Arg:RoyalBlue4:Bold\n\ + Text Arg1:SteelBlue4:Bold\n\ + Text Arg2:RoyalBlue4:Plain\n\ + Text Escape:gray30:Bold\n\ + LaTeX Math:darkGreen:Plain\n\ + Pointer:#660000:Bold\n\ + Regex:#009944:Bold\n\ + Warning:brown2:Italic +nedit.smartIndentInit: C:Default\n\ + C++:Default\n\ + Python:Default\n\ + Matlab:Default +nedit.smartIndentInitCommon: Default +nedit.autoWrap: None +nedit.wrapMargin: 0 +nedit.autoIndent: Auto +nedit.autoSave: True +nedit.saveOldVersion: False +nedit.showMatching: Delimiter +nedit.matchSyntaxBased: True +nedit.highlightSyntax: True +nedit.searchDialogs: False +nedit.beepOnSearchWrap: False +nedit.retainSearchDialogs: True +nedit.searchWraps: True +nedit.stickyCaseSenseButton: True +nedit.repositionDialogs: True +nedit.appendLF: True +nedit.sortOpenPrevMenu: True +nedit.statisticsLine: True +nedit.iSearchLine: False +nedit.lineNumbers: False +nedit.pathInWindowsMenu: True +nedit.warnFileMods: True +nedit.warnExit: True +nedit.searchMethod: Literal +nedit.textRows: 40 +nedit.textCols: 80 +nedit.tabDistance: 8 +nedit.emulateTabs: 2 +nedit.insertTabs: False +nedit.textFont: -misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-16 +nedit.boldHighlightFont: -misc-fixed-bold-r-normal--13-120-75-75-c-70-iso8859-16 +nedit.italicHighlightFont: -misc-fixed-medium-o-normal--13-120-75-75-c-70-iso8859-16 +nedit.boldItalicHighlightFont: -misc-fixed-bold-o-normal--13-120-75-75-c-70-iso8859-16 +nedit.smartTags: True +nedit.prefFileRead: True +nedit.titleFormat: {%c} [%s] %f (%S) - %d diff -r 9cadc470e3da -r 13be24d74cd2 intercom/linux/XF86Config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/linux/XF86Config Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,197 @@ +# /.../ +# SaX generated XFree86 config file +# Created on: 2004-08-24T11:14:12+0000. +# +# Version: 4.8 +# Contact: Marcus Schaefer , 2002 +# +# Automatically generated by [ISaX] (4.8) +# PLEASE DO NOT EDIT THIS FILE! +# + +Section "Files" + FontPath "/usr/X11R6/lib/X11/fonts/misc:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/local" + FontPath "/usr/X11R6/lib/X11/fonts/75dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/100dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/Type1" + FontPath "/usr/X11R6/lib/X11/fonts/URW" + FontPath "/usr/X11R6/lib/X11/fonts/Speedo" + FontPath "/usr/X11R6/lib/X11/fonts/PEX" + FontPath "/usr/X11R6/lib/X11/fonts/cyrillic" + FontPath "/usr/X11R6/lib/X11/fonts/latin2/misc:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/latin2/75dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/latin2/100dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/latin2/Type1" + FontPath "/usr/X11R6/lib/X11/fonts/latin7/75dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/baekmuk:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/japanese:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/kwintv" + FontPath "/usr/X11R6/lib/X11/fonts/truetype" + FontPath "/usr/X11R6/lib/X11/fonts/uni:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/CID" + FontPath "/usr/X11R6/lib/X11/fonts/ucs/misc:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/ucs/75dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/ucs/100dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/hellas/misc:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/hellas/75dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/hellas/100dpi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/hellas/Type1" + FontPath "/usr/X11R6/lib/X11/fonts/misc/sgi:unscaled" + FontPath "/usr/X11R6/lib/X11/fonts/xtest" + FontPath "/opt/kde3/share/fonts" + InputDevices "/dev/ttyS0" + InputDevices "/dev/ttyS1" + InputDevices "/dev/ttyS2" + InputDevices "/dev/ttyS3" + InputDevices "/dev/ttyS4" + InputDevices "/dev/ttyS5" + InputDevices "/dev/ttyS6" + InputDevices "/dev/ttyS7" + InputDevices "/dev/ttyS8" + InputDevices "/dev/psaux" + InputDevices "/dev/logibm" + InputDevices "/dev/sunmouse" + InputDevices "/dev/atibm" + InputDevices "/dev/amigamouse" + InputDevices "/dev/atarimouse" + InputDevices "/dev/inportbm" + InputDevices "/dev/gpmdata" + InputDevices "/dev/mouse" + InputDevices "/dev/usbmouse" + InputDevices "/dev/adbmouse" + InputDevices "/dev/input/mice" + InputDevices "/dev/input/event0" + InputDevices "/dev/pointer0" + InputDevices "/dev/pointer1" + InputDevices "/dev/pointer2" + InputDevices "/dev/pointer3" +EndSection + +Section "ServerFlags" + Option "AllowMouseOpenFail" +EndSection + +Section "Module" + Load "v4l" + Load "extmod" + Load "type1" + Load "freetype" + Load "dbe" + Load "speedo" + Load "glx" +EndSection + +Section "InputDevice" + Driver "kbd" + Identifier "Keyboard[0]" + Option "Protocol" "Standard" + Option "XkbLayout" "de" + Option "XkbModel" "pc105" + Option "XkbRules" "xfree86" + Option "XkbVariant" "nodeadkeys" +EndSection + + +Section "InputDevice" + Driver "mouse" + Identifier "Mouse[1]" + Option "Buttons" "5" + Option "Device" "/dev/input/mice" + Option "Name" "Autodetection" + Option "Protocol" "explorerps/2" + Option "Vendor" "Sysp" + Option "ZAxisMapping" "4 5" +EndSection + +Section "InputDevice" + Driver "elographics" + Identifier "Mouse[3]" + Option "ButtonNumber" "1" + Option "ButtonThreshold" "17" + Option "Device" "/dev/ttyS0" + Option "InputFashion" "Touchpanel" + Option "MinX" "500" + Option "MaxX" "3490" + Option "MinY" "650" + Option "MaxY" "3450" + Option "Name" "ELO;2300-TOUCHSCREEN" + Option "ReportingMode" "Scaled" + Option "SendCoreEvents" "on" +EndSection + + +Section "Monitor" + Option "CalcAlgorithm" "CheckDesktopGeometry" + DisplaySize 320 240 + HorizSync 28-38 + Identifier "Monitor[0]" + ModelName "800X600@60HZ" + VendorName "--> VESA" + VertRefresh 34-60 + UseModes "Modes[0]" +EndSection + + +Section "Modes" + Identifier "Modes[0]" + Modeline "800x600" 36.88 800 832 912 1024 600 601 604 621 + Modeline "1280x1024" 59.69 1280 1328 1456 1632 1024 1025 1028 1045 + Modeline "640x480" 23.06 640 656 720 800 480 481 484 497 + Modeline "800x600" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync +EndSection + + +Section "Screen" + DefaultDepth 16 + SubSection "Display" + Depth 15 + Modes "1280x1024" + EndSubSection + SubSection "Display" + Depth 16 + Modes "800x600" + EndSubSection + SubSection "Display" + Depth 24 + Modes "1280x1024" + EndSubSection + SubSection "Display" + Depth 32 + Modes "640x480" + EndSubSection + SubSection "Display" + Depth 8 + Modes "1280x1024" + EndSubSection + Device "Device[0]" + Identifier "Screen[0]" + Monitor "Monitor[0]" +EndSection + + +Section "Device" + BoardName "865 G" + BusID "0:2:0" + Driver "i810" + Identifier "Device[0]" + Screen 0 + VendorName "Intel" +EndSection + + +Section "ServerLayout" + Identifier "Layout[all]" + InputDevice "Keyboard[0]" "CoreKeyboard" + InputDevice "Mouse[1]" "CorePointer" + InputDevice "Mouse[3]" "SendCoreEvents" + Option "Clone" "off" + Option "Xinerama" "off" + Screen "Screen[0]" +EndSection + +Section "DRI" + Group "video" + Mode 0660 +EndSection + diff -r 9cadc470e3da -r 13be24d74cd2 intercom/linux/kphone_amixer.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/linux/kphone_amixer.sh Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,20 @@ + +# kphone_amixer.sh +# set mixer capture to left-channel=Mic, right-channel=Mix for +# acoustic echo cancellation +# +# 13jul2004 adrian: initial version +# 24aug2004 adrian: set PCM, Master volume + +amixer -q sset 'PCM',0 70% +amixer -q sset 'Master',0 70% + +amixer -q set 'PCM',0 unmute +amixer -q set 'Capture',0 0%-,100%- +amixer -q cset iface=MIXER,name='Capture Switch' 1 + +# for Mic Capture +#amixer -q cset iface=MIXER,name='Capture Source' 0,5 + +# for Line-In Capture +amixer -q cset iface=MIXER,name='Capture Source' 4,5 diff -r 9cadc470e3da -r 13be24d74cd2 intercom/oss.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/oss.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,90 @@ +/* oss.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Open Sound System functions + * + * Version 0.3 + */ + +#include +#include +#include +#include + +/* Error handling */ +#include +#include +extern int errno; + +/* low level io */ +#include +#include +#include +#include + +/* OSS, see www.4front-tech.com/pguide/index.html */ +#include + +#include "oss.h" +#include "intercomd.h" + +int audio_init(char *pathname, int channels_, int mode) +{ +/* Using OSS is simple in theory. The application just: + * Opens the device. + * Optional turns on full duplex + * Sets fragment size if necessary + * Sets number of channels, sample format and sampling rate + * Starts reading and/or writing the device + * + * Linux ALSA dmix note: To allow dmix simultaneous playback of + * different PCM-out, do not open OSS in full duplex mode. Open two file + * descriptors instead. + */ + // fprintf(stderr, "OSS Header SOUND_VERSION = %x\n", SOUND_VERSION); + + int audio_fd = open(pathname, mode); + return_if(audio_fd < 0, -1); + + fprintf(stderr, "audio_init() mode = %d\n", mode); + + int sound_version = 0; + ioctl(audio_fd, OSS_GETVERSION, &sound_version); + // fprintf(stderr, "OSS Driver SOUND_VERSION = %x\n", SOUND_VERSION); + + ioctl(audio_fd, SNDCTL_DSP_SETDUPLEX, 0); + + /* The 16 most significant bits (MMMM) determine maximum number of + * fragments. By default the driver computes this based on available + * buffer space. + * The minimum value is 2 and the maximum depends on the situation. + * Set MMMM=0x7fff if you don't want to limit the number of fragments + */ + int frag = AUDIOBUFS << 16 | FRAGSIZELD; + if (2 == channels_) { + ++frag; // double FRAGSIZE in stereo mode + } + int frag_ = frag; + ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag); + // fprintf(stderr, "SETFRAGMENT=0x%x\n", frag); + assert_errno(frag_ == frag); + + int format = FORMAT_OSS; + ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format); + assert_errno(format == FORMAT_OSS); + + int channels = channels_; + ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels); + assert_errno(channels_ == channels); + // fprintf(stderr, "SNDCTL_DSP_CHANNELS=%d\n", channels); + + int rate = RATE; + ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate); + assert_errno(RATE == rate); + // fprintf(stderr, "mode=%d SNDCTL_DSP_SPEED=%d\n", mode, rate); + + fprintf(stderr, "\n"); + return audio_fd; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/oss.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/oss.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,33 @@ +/* oss.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * Open Sound System + * + * Version 0.3 + */ +#ifndef _OSS_H + +/* Design Constants */ +#define AUDIOBUFS 3 // Soundcard buffers (minimum 2) +/* End of Design Constants */ + +#define FORMAT_OSS AFMT_S16_LE + +/* Using fragment sizes shorter than 256 bytes is not recommended as the + * default mode of application + */ +/* for Packettime = 40ms FRAGSIZELD = 7 can be used + * for Packettime = 80ms FRAGSIZELD = 8 can be used + */ +#define FRAGSIZELD (5+WIDEB) // WIDEB is 1 or 2 +#define FRAGSIZE (1< /* printf() */ +#include + +#include /* u_long */ +#include /* gettimeofday() */ +#include /* get..() */ +#include /* clock() */ +#include /* uname() */ +#include +#include + +#include "intercomd.h" +#include "rtp.h" + +/* + * Return random unsigned 32-bit quantity. Use 'type' argument if + * you need to generate several different values in close succession. + * (partly from RFC 3550 A.6 Generating a Random 32-bit Identifier) + */ +unsigned long random32(int type) +{ + struct { + int type; + struct timeval tv; + clock_t cpu; + pid_t pid; + u_long hid; + uid_t uid; + gid_t gid; + struct utsname name; + } s; + + gettimeofday(&s.tv, 0); + uname(&s.name); + s.type = type; + s.cpu = clock(); + s.pid = getpid(); + s.hid = gethostid(); + s.uid = getuid(); + s.gid = getgid(); + /* also: system uptime */ + + unsigned long *us = (unsigned long *) &s; + + /* use xor to make a (bad) random */ + /* Note: remainder of long div of 32bit prim is better */ + unsigned long random = 0; + unsigned int i; + for (i = 0; i < sizeof(s) / sizeof(long); ++i) { + random ^= *us++; + } + return random; +} /* random32 */ + + +RTP::RTP() +{ + version = 2; + padding = 0; + extension = 0; + csrc_count = 0; + marker = 0; + payload_type = PT_PCMU; + ssrc = 0; + sequence = 0; + timestamp = 0; +} + +void RTP::init(int payload_type_, unsigned long ssrc_) +{ + version = 2; + padding = 0; + extension = 0; + csrc_count = 0; + marker = 0; + payload_type = payload_type_; + ssrc = ssrc_; + /* My interpretation of RFC3550 A.6: one seed is good enough */ + sequence = random32(payload_type_); + timestamp = sequence; +} + +void RTP::next(int frameduration) +{ + ++sequence; + timestamp += frameduration; +} + +void RTP::reset_csrc() +{ + csrc_count = 0; +} + +int RTP::add_csrc(unsigned long csrc_) +{ + return_if (csrc_count >= 15, ERROR); + csrc[csrc_count++] = csrc_; + + // printf("add_csrc = %08x\n", csrc_); + return OKAY; +} + +int RTP::find_csrc(unsigned long ssrc_) +{ + unsigned int i; + + if (0 == csrc_count) return NO; + // printf("find_csrc = %08x ", ssrc_); + for (i = 0; i < csrc_count; ++i) { + // printf("%08x ", csrc[i]); + if (csrc[i] == ssrc_) { + // printf("hit\n"); + return YES; + } + } + return NO; +} + +int RTP::check() +{ + // RFC3550 A.1 RTP Data Header Validity Checks + + // RTP version field must equal 2. + if (version != 2) + return -1; + + // The payload type must be known + switch (payload_type) { + case PT_PCMU: + case PT_GSM: + case PT_PCMA: + case PT_G729: + case PT_iLBC: + case PT_EFR: + case PT_G726: + case PT_SPX: + /* do nothing */ + break; + default: + return -1; + } + + // The X bit must be zero if the profile does not specify that the + // header extension mechanism may be used. Otherwise, the extension + // length field must be less than the total packet size minus the + // fixed header length and padding. + if (extension) + return -1; // hack! + + // The length of the packet must be consistent with CC and payload + // type (if payloads have a known length). + // equal to SR or RR. + // if (csrc_count != 0) + // return -1; // hack! + + // If the P bit is set, then the last octet of the packet must + // contain a valid octet count, in particular, less than the total + // packet length minus the header size. + if (padding) + return -1; // hack! + return 0; +} + +char *RTP_network_copy(char *to, RTP * from) +{ + unsigned long *ulfrom = (unsigned long *) from; + unsigned long *ulto = (unsigned long *) to; + int i; + for (i = 0; i < 3 + from->get_cc(); ++i) { + *ulto++ = htonl(*ulfrom++); + } + return (char *) ulto; +} + +char *RTP_host_copy(RTP * to, char *from) +{ + unsigned long *ulfrom = (unsigned long *) from; + unsigned long *ulto = (unsigned long *) to; + int i; + for (i = 0; i < 3; ++i) { + *ulto++ = ntohl(*ulfrom++); + } + for (i = 0; i < to->get_cc(); ++i) { + *ulto++ = ntohl(*ulfrom++); + } + return (char *) ulfrom; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/rtp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/rtp.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,81 @@ +/* rtp.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * Author: Andre Adrian + * + * subset of Real Time Protocol Version 2 (RFC3550 and RFC3551) + * handling of extension and padding is missing + * + * Version 0.3.5 + */ + +class RTP { + /* Format in Host Byte order. Conversion with htonl() to Network Byte + * order. This data structure is implementation dependent! + * Tested with GCC and x86 */ + + /* first 32bits */ + unsigned long sequence:16; + unsigned long payload_type:7; + unsigned long marker:1; + unsigned long csrc_count:4; + unsigned long extension:1; + unsigned long padding:1; + unsigned long version:2; + + /* second 32bits */ + unsigned long timestamp; + + /* third 32bits */ + unsigned long ssrc; /* used as unique identifier */ + + /* optional - used with telephone conference */ + unsigned long csrc[15]; + +public: + RTP::RTP(); + void RTP::init(int payload_type_, unsigned long ssrc_); + int RTP::add_csrc(unsigned long csrc_); + void RTP::reset_csrc(); + int RTP::find_csrc(unsigned long ssrc_); + void RTP::next(int frameduration); + int RTP::check(); + unsigned long RTP::getssrc() { + return ssrc; + }; + int RTP::get_pt() { + return (int) payload_type; + }; + int RTP::get_cc() { + return (int) csrc_count; + } +}; + +const unsigned PT_PCMU = 0; // 8000 sample/second, G.711 u-Law +const unsigned PT_GSM = 3; // 8000 sample/second, GSM +const unsigned PT_PCMA = 8; // 8000 sample/second, G.711 A-Law +const unsigned PT_G729 = 18; // 8000 sample/second, G.729 +const unsigned PT_EFR = 97; // inofficial type GSM-EFR +const unsigned PT_iLBC = 98; // inofficial type iLBC 20ms +const unsigned PT_G726 = 99; // inofficial type G.726 32kbps +const unsigned PT_SPX = 101; // inofficial type Wideband Speex + +// Speex Wideband kbps/Bytes: 16.8/42, 20.6/52, 23.8/60, 27.8/70, +// 34.2/86, 42.2/106 +const int SPX_BITRATE = 27800; +const int SPX_COMPLEXITY = 3; +const int SPX_QUALITY = 8; +const int SPX_ENH = 1; + +#define SZ_PCMA 160 +#define SZ_PCMU 160 +#define SZ_G726 80 +#define SZ_GSM 33 +#define SZ_EFR 31 +#define SZ_SPX 70 +#define SZ_iLBC 38 + +char *RTP_network_copy(char *to, RTP * from); +char *RTP_host_copy(RTP * to, char *from); +unsigned long random32(int type); diff -r 9cadc470e3da -r 13be24d74cd2 intercom/save_ic.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/save_ic.sh Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,17 @@ +#!/bin/sh +# Name: save_ic.sh +# Project: VoIP-GS, VoIP intercom +# Copyright: DFS, Andre Adrian +# Comment: creates a tarball +# First Ed: 24oct2004 +# Version: 23sep2005 + +filename=intercom`date +%Y%m%d%H%M`.tgz + +tar -cvzf $filename \ + COPYRIGHT INSTALL README CHANGES Makefile *.txt \ + *.sh *.c* *.h intercom *.tcl *.ui \ + ilbc g711 gsm linux g726 \ + libudp1.0.6.so + +# end of file diff -r 9cadc470e3da -r 13be24d74cd2 intercom/sinuston.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/sinuston.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,172 @@ +/* sinuston.cpp + * erzeuget Sinustabelle für Frequenz + * Author: Christian Dorge, Andre Adrian + * + * Compile: +c++ -DMODULTEST -g -O0 -o sinuston sinuston.cpp + * + * debug: +ddd sinuston & + * + * Quelltext Formatierung: +indent -kr -i2 -nlp -ci2 -l72 -lc72 -nut sinuston.cpp + * + */ + +#include +#include +#include + +/* fuer syslog */ +#include + +#include "sinuston.h" + +float dB2faktor(float dB) +{ + /* Dezibel nach Faktor */ + return powf(10.0f, dB / 20.0f); +} + +float faktor2dB(float q) +{ + /* Faktor nach Dezibel */ + return 20.0f * log10f(q); +} + +int kgv(int a, int b) +{ + + int r = a; + int q = b; + int rest; + + while ((rest = r % q)) { + r = q; + q = rest; + } + int kgv = a * b / q; + // fprintf(stderr, "%d \n", kgv); + + return kgv; +} + +SINUSTON::SINUSTON() +{ + // init auf 0 + j = 0; + cnt = 0; + memset(sinustab, 0, sizeof(sinustab)); +} + +short SINUSTON::frequenz(int f1, int fs, float pegel) +{ + if (f1 < 0) { + syslog(LOG_WARNING, "Tonfrequenz < 0 \n"); + return -1; + } + + if (fs < 0) { + syslog(LOG_WARNING, "Abtastfrequenz < 0 \n"); + return -1; + } + + if (pegel > 0.0f) { + syslog(LOG_WARNING, "Pegel > 0 \n"); + return -1; + } + + if (2 * f1 > fs) { + syslog(LOG_WARNING, "Tonfrequenz > 1/2 Abtastfrequenz"); + return -1; + } + + cnt = kgv(fs, f1) / f1; + + if (cnt > SINUSTONLEN) // Prüfung, ob Samplewert nicht Größer als Max.wert der Sinustabelle + { + cnt = SINUSTONLEN; + } + + float winkelschritt = (float)f1 / (float)fs * 2 * M_PI; // Berechnung Winkelschritt + + float pegelwert = 32767 * dB2faktor(pegel); //Umrechnung Dezibel in Faktor (16bit PCM) + + for (int i = 0; i < cnt; i++) { + + sinustab[i] = (short) (pegelwert * sinf(i * winkelschritt)); + + // printf("%f, %f, %f \n", f1, fs, sinustab[i]); + + } + + return cnt; +} + +short SINUSTON::mischen(short ein_sprache) +{ + // Schleifenende + if (j >= cnt) { + j = 0; + } + + long sum = (long) ein_sprache + (long) sinustab[j]; + + // Werte limitieren auf 16bit Wertebereich + if (sum > 32767) { + sum = 32767; + } else if (sum < -32767) { + sum = -32767; + } + // Schleifeninkrement + j++; + + return (short) sum; +} + +#ifdef MODULTEST + +int main(int argc, char *argv[]) +{ + int f1 = 2040; // Frequenz Ton + int fs = 8000; // Abtastfrequenz + float pegel = -24; // minus Dezibel + short ein_sprache[80000]; + short aus_sprache_signal[80000]; + SINUSTON s; + + /* init syslog (Fehler Logging) + * syslog Fehlermeldungen auch nach /var/log/warn */ + openlog(NULL, LOG_PERROR, LOG_WARNING); + + /* + printf("Bitte Frequenz eingeben: "); + scanf("%f", &f1); + printf("Bitte Samplerate eingeben: "); + scanf("%f", &fs); + printf("Bitte Pegel eingeben: "); + scanf("%f", &pegel); + */ + + // Eingabe + fread(ein_sprache, sizeof(short), 80000, stdin); + + // Verarbeitung + short cnt = s.frequenz(f1, fs, pegel); + // fprintf(stderr, "Die Anzahl der Elemente ist %f \n", cnt); + + int j; + for (int i = 0; i < 80000; i++) { + aus_sprache_signal[i] = s.mischen(ein_sprache[i]); + } + + // Ausgabe + /* (short) wg. Ausgabe in RAW-Datei + * (1 Sample = 16bit Signed Int Wert) + * fwrite(pointer auf Daten, Datengröße des Typs, Anzahl zu lesender Elemente, Ausgabe) + */ + fwrite(aus_sprache_signal, sizeof(short), 80000, stdout); + +} + +#endif diff -r 9cadc470e3da -r 13be24d74cd2 intercom/sinuston.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/sinuston.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,36 @@ +#ifndef _INCLUDE_SINUSTON + +#define SINUSTONLEN 8000 + +/* Möglichkeit über Fkt. frequenz der Berechnung einer Sinustabelle + Möglichkeit über Fkt. mischen des Zusammenfügens eines Sinussignals mit Sprache +*/ + +class SINUSTON +{ + short sinustab[SINUSTONLEN]; // 8000 Werte entsprechen 8000 Samples + int j; // Laufvariable + int cnt; // Endwert + + +public: + SINUSTON(); + +/* in-Parameter: f1 --> Frequenz des gewünschten Tons + * fs --> Abtastfrequenz + * pegel --> Pegelwert in Dezibel + * out-Parameter: returnvalue --> -1 im Fehlerfall, sonst + * Anzahl Elemente in Sinustabelle + */ +short SINUSTON::frequenz(int f1, int fs, float pegel); + + + +/* in-Parameter: ein_sprache --> Eingangs Sprach sample + * out-Parameter: returnvalue --> Sprachsample mit Sinuston + */ +short SINUSTON::mischen(short ein_sprache); +}; + +#endif +#define _INCLUDE_SINUSTON diff -r 9cadc470e3da -r 13be24d74cd2 intercom/tcp.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/tcp.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,132 @@ +/* tcp.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * TCP server functions for IPv4 + * + * Version 0.2 + * adr 11sep2005 TCP client + */ + + +#include +#include +#include + + /* Socket io */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* error handling */ +#include + +#include + +#include "intercomd.h" + +int tcp_server_init(int port) +/* open the server (listen) port - do this one time*/ +{ + int fd = socket(PF_INET, SOCK_STREAM, 0); + assert_errno(fd >= 0); + + struct sockaddr_in sock; + memset((char *) &sock, 0, sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_addr.s_addr = htonl(INADDR_ANY); + sock.sin_port = htons(port); + if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) { + fprintf(stderr, "tcp_recv_init(): bind() failed\n"); + exit(2); + } + + int ret = listen(fd, 1); + assert_errno(ret >= 0); + + return fd; +} + +#define SA struct sockaddr + +int +socket_async(char *addr, int port) { +/* Tcl Prozedur socket -async */ +/* in addr: Server IP-Adresse auf den gehoert wird */ +/* in port: Server TCP-Port auf den gehoert wird */ + struct sockaddr_in servaddr; + struct hostent *foreign_host; + int sockfd; + int flags; + + /* Siehe Stevens[1998] Kap. 15.4 oder man 2 connect */ + + /* init local part */ + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + syslog(LOG_WARNING, "socket_async(): local socket() failed"); + return -1; + } + if (sockfd >= 64) { + syslog(LOG_WARNING, "socket_async(): local socket() sockfd >= 64"); + return -1; + } + + /* init foreign part */ + memset((char *)&servaddr, 0, sizeof(servaddr)); + + foreign_host = gethostbyname(addr); + if (foreign_host == NULL || foreign_host->h_length == 0) { + syslog(LOG_WARNING, + "socket_async(): gethostbyname(%s) failed", + addr); + return -1; + } + memcpy(&servaddr.sin_addr.s_addr, foreign_host->h_addr_list[0], foreign_host->h_length); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(port); + + /* NONBLOCK */ + flags = fcntl(sockfd, F_GETFL, 0); + fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); + + if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) != 0) { + if (errno != EINPROGRESS) { + perror("tcl.c::socket_async() connect() failed"); + return -1; + } + } + + printf("info tcp.cpp::socket_async(): host=%s IP=0x%X Port=%u\n", + addr, ntohl(servaddr.sin_addr.s_addr), port); + + return sockfd; +} + + + +int tcp_server_init2(int listen_fd) +/* open the communication (connection) - do this for every client */ +{ + // fprintf(stderr, "tcp_server_init2\n"); + + // avoid blocking accept() + int flags = fcntl(listen_fd, F_GETFL); + int ret = fcntl(listen_fd, F_SETFL, flags | O_NONBLOCK); + assert_errno(ret >= 0); + + struct sockaddr_in sock; + socklen_t socklen = sizeof(sock); + int fd = accept(listen_fd, (struct sockaddr *) &sock, &socklen); + assert_errno(fd >= 0); + + return fd; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/tcp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/tcp.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,13 @@ +/* tcp.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * TCP server functions for IPv4 + * + * Version 0.2 + */ + +int tcp_server_init(int port); +int tcp_server_init2(int listen_fd); +int socket_async(char *addr, int port); diff -r 9cadc470e3da -r 13be24d74cd2 intercom/testdenoise.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/testdenoise.c Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,69 @@ +/* testdenoise.c + * Jean-Marc Valin, www.speex.org + * Changes Andre Adrian + * + +cc -O2 -o testdenoise testdenoise.c -lm -lspeex + + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#define NN 160 + +typedef signed short MONO; + +typedef struct { + signed short l; + signed short r; +} STEREO; + +int main() +{ + STEREO in[NN]; + MONO inm[NN]; + int i; + SpeexPreprocessState *st; + int count=0; + float f; + + st = speex_preprocess_state_init(NN, 8000); + i=1; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &i); + i=0; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &i); + f=8000; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &f); + i=0; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i); + f=.4; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f); + f=.3; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f); + while (1) + { + int vad; + fread(in, sizeof(STEREO), NN, stdin); + for (i = 0; i < NN; ++i) { + inm[i] = in[i].l; + } + + if (feof(stdin)) + break; + vad = speex_preprocess(st, inm, NULL); + /*fprintf (stderr, "%d\n", vad);*/ + for (i = 0; i < NN; ++i) { + in[i].l = inm[i]; + } + fwrite(in, sizeof(STEREO), NN, stdout); + count++; + } + speex_preprocess_state_destroy(st); + return 0; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/udp.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/udp.cpp Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,157 @@ +/* udp.cpp + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * UDP functions for IPv4 + * Multicast Doc: /usr/share/doc/howto/en/html/Multicast-HOWTO.html + * + * Version 0.2 + */ + +#include +#include +#include + + /* Socket io */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "udp.h" +#include "intercomd.h" + +int UDP_recv_init(int port) +/* starte UDP LAN Empfang. Programm-Exit bei Fehler! */ +/* return: Filedescriptor fuer Empfang */ +/* in port: UDP Port Nummer */ +{ + int fd; + struct sockaddr_in sock; + int local_flag; + socklen_t local_flagsize; + + /* init UDP local1 */ + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + fprintf(stderr, "if_recv_init(): socket() failed\n"); + exit(1); + } + + memset((char *) &sock, 0, sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_addr.s_addr = htonl(INADDR_ANY); + sock.sin_port = htons(port); + if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) { + fprintf(stderr, "if_recv_init(): bind() failed\n"); + exit(2); + } + local_flagsize = sizeof(int); + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &local_flag, + &local_flagsize) < 0) { + fprintf(stderr, "if_recv_init(): getsockopt() failed\n"); + exit(3); + } + /* printf("SO_RCVBUF=%d\n", local_flag); */ + + /* printf("init socket\n"); */ + return fd; +} + +void UDP::send_init(char *foreign_name, int foreign_port, int local_fd_) +/* Starte Versand von UDP Meldungen auf LAN */ +/* in foreign_name: IP-Adresse auf die gesendet wird */ +/* in foreign_port: UDP-Port auf den gesendet wird */ +{ + struct hostent *foreign_host; + int local_flag; + socklen_t local_flagsize; + + local_fd = local_fd_; + + /* turn on broadcast */ + local_flagsize = sizeof(int); + if (getsockopt(local_fd, SOL_SOCKET, SO_BROADCAST, + (char *) &local_flag, &local_flagsize) < 0) { + fprintf(stderr, "udp_send_init(): getsockopt() failed\n"); + exit(3); + } + if (local_flag == 0) { + local_flag = 1; + setsockopt(local_fd, SOL_SOCKET, SO_BROADCAST, (char *) &local_flag, + sizeof(int)); + local_flagsize = sizeof(int); + if (getsockopt(local_fd, SOL_SOCKET, SO_BROADCAST, + (char *) &local_flag, &local_flagsize) < 0) { + fprintf(stderr, "udp_send_init() SO_BROADCAST failed\n"); + exit(3); + } + } + + /* init foreign part */ + memset((char *) &foreign_sock, 0, sizeof(foreign_sock)); + + foreign_host = gethostbyname(foreign_name); + if (foreign_host == NULL || foreign_host->h_length == 0) { + fprintf(stderr, "udp_send_init(): gethostbyname() failed"); + exit(1); + } + memcpy(&foreign_sock.sin_addr.s_addr, foreign_host->h_addr_list[0], + foreign_host->h_length); + foreign_sock.sin_family = AF_INET; + foreign_sock.sin_port = htons(foreign_port); + + + in_addr_t to_ip = ntohl(foreign_sock.sin_addr.s_addr); + char s[20]; + print_gui("c %s\n", iptoa(s, to_ip)); +} + +void UDP::send(char *buf, int bytes) +/* Sende UDP Meldung auf LAN */ +/* in buf: Meldung */ +/* in bytes: Laenge der Meldung */ +{ + int len; + + len = sendto(local_fd, + buf, bytes, + 0, (struct sockaddr *) &foreign_sock, sizeof(foreign_sock)); + if (len != bytes) { + fprintf(stderr, "udp_send(): sendto() foreign failed ret=%d\n", + len); + } +} + +void UDP::send_close() +{ + memset((char *) &foreign_sock, 0, sizeof(foreign_sock)); +} + +// IP to ASCII +char *iptoa(char *buf, in_addr_t ip) +{ + int i1 = ip >> 24; + int i2 = (ip >> 16) & 0xFF; + int i3 = (ip >> 8) & 0xFF; + int i4 = ip & 0xFF; + + sprintf(buf, "%d.%d.%d.%d", i1, i2, i3, i4); + + return buf; +} + +// ASCII to IP +in_addr_t atoip(char *buf) +{ + int i1, i2, i3, i4; + + sscanf(buf, "%d.%d.%d.%d", &i1, &i2, &i3, &i4); + + return i1 << 24 | i2 << 16 | i3 << 8 | i4; +} diff -r 9cadc470e3da -r 13be24d74cd2 intercom/udp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/udp.h Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,26 @@ +/* udp.h + * + * Copyright (C) DFS Deutsche Flugsicherung (2004, 2005). + * All Rights Reserved. + * + * UDP functions for IPv4 + * + * Version 0.2 + */ + +class UDP { + int local_fd; + struct sockaddr_in foreign_sock; +public: + void send_init(char *foreign_name, int foreign_port, int local_fd_); + void send(char *buf, int bytes); + void send_close(); +}; + +int UDP_recv_init(int port); + +// IP to ASCII +char *iptoa(char *buf, in_addr_t ip); + +// ASCII to IP +in_addr_t atoip(char *buf); diff -r 9cadc470e3da -r 13be24d74cd2 intercom/wdisplay.tcl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intercom/wdisplay.tcl Fri Jun 25 09:57:52 2010 +0200 @@ -0,0 +1,57 @@ +#!/usr/bin/wish + +# wdisplay.tcl +# show vector w values + +proc fileRecv {fd} { + global sam + + # read 4*sam bytes (sam values) into list l + set r [read $fd [expr 4*$sam]] + + # detect eof only after read! + if {[eof $fd]} { + puts "fileRecv eof" + close $fd + return + } + + binary scan $r "f$sam" l + + # linear Scale + set yscale [expr 1.0] + + # erase canvas + .ca delete ttt + + set x 0 + foreach y $l { + set y [expr 99 - $y * $yscale] + .ca create line $x 100 $x $y -tags ttt + incr x + } +} + +proc UserOpen {fd chost cport} { + fconfigure $fd -translation binary -encoding binary + fileevent $fd readable [list fileRecv $fd] +} + +# ############################################################## +# main + +# check Programm Args +if {$argc < 1} { + puts "usage: wdisplay.tcl samples" + exit +} + +set sam [lindex $argv 0] ;# vector length - see aec.cpp +# puts "sam =$sam" + +# create a canvas to draw the graphical objects on +canvas .ca -width $sam -height 200 +pack .ca + +# Open Server part of TCP connection +socket -server UserOpen 50999