Minor changes.

git-svn-id: http://op25.osmocom.org/svn/trunk@162 65a5c917-d112-43f1-993d-58c26a4786be
This commit is contained in:
stevie 2009-08-30 02:47:30 +00:00
parent 9f3907e8e9
commit e01775be01
4 changed files with 121 additions and 95 deletions

30
imbe/Makefile Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/make
#
CDEBUG = -g
CPPFLAGS = $(CDEBUG) $(CDEFS)
CXXFLAGS = -I.
LIBS =
LDFLAGS =
SRCFILES = *.cc
DEPFILES = .*.d
OBJFILES = *.o
SRCS = $(wildcard $(SRCFILES))
DEPS = $(SRCS:%.cc=.%.d)
OBJS = $(SRCS:%.cc=%.o)
AOUT = imbe
.PHONY: clean
.%.d: %.cc
$(SHELL) -ec '$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; [ -s $@ ] || rm -f $@'
$(AOUT): $(LIBS) $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
rm -f $(AOUT) $(OBJFILES) $(DEPFILES) *~
include $(DEPS)

View File

@ -22,9 +22,9 @@
*/ */
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <cstdio>
#include <cstdlib>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <math.h> #include <math.h>
@ -1055,11 +1055,8 @@ op25_imbe::~op25_imbe()
} }
} }
static const char* Sync = "111113113311333313133333";
void void
op25_imbe::imbe_frame(unsigned char* buf) op25_imbe::decode(uint8_t *buf)
{ {
// process input 144-bit IMBE frame - converts to 88-bit frame // process input 144-bit IMBE frame - converts to 88-bit frame
int i; int i;
@ -1069,8 +1066,8 @@ op25_imbe::imbe_frame(unsigned char* buf)
unsigned int ET = 0; unsigned int ET = 0;
unsigned char O[12]; unsigned char O[12];
// Hamming/Golay - etc. // PN/Hamming/Golay - etc.
vfDec(buf, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET) ; correct(buf, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET) ;
//replace the sync bit(LSB of u7) with the BOT flag //replace the sync bit(LSB of u7) with the BOT flag
BOT = 1; BOT = 1;
@ -1104,11 +1101,11 @@ op25_imbe::imbe_frame(unsigned char* buf)
#endif #endif
// process 88-bit frame // process 88-bit frame
decode(O); decode_audio(O);
} }
void void
op25_imbe::AdaptiveSmoothing(float SE, float ER, float ET) op25_imbe::adaptive_smoothing(float SE, float ER, float ET)
{ {
float VM; float VM;
float AM; float AM;
@ -1144,9 +1141,8 @@ op25_imbe::AdaptiveSmoothing(float SE, float ER, float ET)
} }
void void
op25_imbe::CplxFFT(float REX[], float IMX[]) op25_imbe::fft(float REX[], float IMX[])
{ {
int I; int I;
int J; int J;
int K; int K;
@ -1190,7 +1186,7 @@ op25_imbe::CplxFFT(float REX[], float IMX[])
} }
void void
op25_imbe::decode(uint8_t *A) op25_imbe::decode_audio(uint8_t *A)
{ {
uint32_t u0, u1, u2, u3, u4, u5, u6, u7, E0, ET; uint32_t u0, u1, u2, u3, u4, u5, u6, u7, E0, ET;
int K; int K;
@ -1207,26 +1203,26 @@ op25_imbe::decode(uint8_t *A)
// Whuh?! // Whuh?!
} else { } else {
K = rearrange(u0, u1, u2, u3, u4, u5, u6, u7); // re-arrange the bits from u to b (ToDo: make 'b' return value ???) K = rearrange(u0, u1, u2, u3, u4, u5, u6, u7); // re-arrange the bits from u to b (ToDo: make 'b' return value ???)
DecodeVUV(K); decode_vuv(K);
Len3 = L - 1; Start3 =((Len3 *(Len3 - 1)) / 2) - 28; Len3 = L - 1; Start3 =((Len3 *(Len3 - 1)) / 2) - 28;
Len8 = L - 6; Start8 =((Len8 *(Len8 - 1)) / 2) - 3; Len8 = L - 6; Start8 =((Len8 *(Len8 - 1)) / 2) - 3;
DecodeSpectralAmplitudes(Start3, Start8); decode_spectral_amplitudes(Start3, Start8);
EnhanceSpectralAmplitudes(SE); enhance_spectral_amplitudes(SE);
AdaptiveSmoothing(SE, ER, ET); adaptive_smoothing(SE, ER, ET);
//(8000 samp/sec) *(1 sec/50 frame) = 160 samp/frame //(8000 samp/sec) *(1 sec/50 frame) = 160 samp/frame
//fHz = 4000 * w0 / M_PI //fHz = 4000 * w0 / M_PI
//synth: //synth:
SynthUnvoiced(); synth_unvoiced();
SynthVoiced(); synth_voiced();
//output: //output:
for(en = 0; en <= 159; en++) { for(en = 0; en <= 159; en++) {
// The unvoiced samples are loud and the voiced are low...I don't know why. // The unvoiced samples are loud and the voiced are low...I don't know why.
// Most of the difference is compensated by removing the 146.6433 factor // Most of the difference is compensated by removing the 146.6433 factor
// in the SynthUnvoiced procedure. The final tweak is done by raising the // in the synth_unvoiced procedure. The final tweak is done by raising the
// voiced samples: // voiced samples:
OutSamp = suv[en] + sv[en] * 4; //balance v/uv loudness OutSamp = suv[en] + sv[en] * 4; //balance v/uv loudness
if(abs((int)OutSamp) > 32767) { if(abs((int)OutSamp) > 32767) {
@ -1249,7 +1245,7 @@ op25_imbe::decode(uint8_t *A)
} }
void void
op25_imbe::DecodeSpectralAmplitudes(int Start3, int Start8) op25_imbe::decode_spectral_amplitudes(int Start3, int Start8)
{ {
float G[7]; //Can we use C(1 to 6,1) for this? float G[7]; //Can we use C(1 to 6,1) for this?
int J[7]; int J[7];
@ -1263,9 +1259,6 @@ op25_imbe::DecodeSpectralAmplitudes(int Start3, int Start8)
int P3, P8, eye, jay, kay, ell, em, iTk; int P3, P8, eye, jay, kay, ell, em, iTk;
P3 = Start3; P8 = Start8; P3 = Start3; P8 = Start8;
G[1] = AnnexE[bee[2]]; G[1] = AnnexE[bee[2]];
@ -1342,7 +1335,7 @@ op25_imbe::DecodeSpectralAmplitudes(int Start3, int Start8)
} }
void void
op25_imbe::DecodeVUV(int K) op25_imbe::decode_vuv(int K)
{ {
int bee1, ell, kay; int bee1, ell, kay;
bee1 = bee[1]; bee1 = bee[1];
@ -1358,7 +1351,7 @@ op25_imbe::DecodeVUV(int K)
} }
void void
op25_imbe::EnhanceSpectralAmplitudes(float& SE) op25_imbe::enhance_spectral_amplitudes(float& SE)
{ {
float RM0; float RM0;
float RM1; float RM1;
@ -1406,7 +1399,7 @@ op25_imbe::EnhanceSpectralAmplitudes(float& SE)
} }
void void
op25_imbe::RealIFFT(float FDi[], float FDq[], float TD[]) op25_imbe::ifft(float FDi[], float FDq[], float TD[]) // ToDo: replace "real IFFT" with fftw3 IFFT proc!
{ {
//Inverse FFT: //Inverse FFT:
// transform 129-point freq domain(FDx) to 256-point time domain(TD) // transform 129-point freq domain(FDx) to 256-point time domain(TD)
@ -1424,20 +1417,26 @@ op25_imbe::RealIFFT(float FDi[], float FDq[], float TD[])
J = I + 64; //64 to 127 J = I + 64; //64 to 127
K = I * 2; //0 to 126(step 2) K = I * 2; //0 to 126(step 2)
H = 128 - K; //128 to 2(step 2) H = 128 - K; //128 to 2(step 2)
Ai[I] = FDi[K] + FDq[K]; Aq[I] = FDi[K + 1] + FDq[K + 1]; Ai[I] = FDi[K] + FDq[K];
Ai[J] = FDi[H] - FDq[H]; Aq[J] = FDi[H - 1] - FDq[H - 1]; Aq[I] = FDi[K + 1] + FDq[K + 1];
Ai[J] = FDi[H] - FDq[H];
Aq[J] = FDi[H - 1] - FDq[H - 1];
} }
CplxFFT( Ai, Aq); fft(Ai, Aq);
for(I = 1; I <= 63; I++) { for(I = 1; I <= 63; I++) {
J = 128 - I; //127 to 65 J = 128 - I; //127 to 65
K = I + 128; //129 to 191 K = I + 128; //129 to 191
H = J + 128; //255 to 193 H = J + 128; //255 to 193
FDi[K] =(Aq[I] + Aq[J]) / 2; FDi[H] = FDi[K] ; //a FDi[K] =(Aq[I] + Aq[J]) / 2;
FDq[K] = -(Ai[I] - Ai[J]) / 2; FDq[H] = -FDq[K] ; //b FDi[H] = FDi[K] ; //a
FDi[I] =(Ai[I] + Ai[J]) / 2; FDi[J] = FDi[I] ; //c FDq[K] = -(Ai[I] - Ai[J]) / 2;
FDq[I] =(Aq[I] - Aq[J]) / 2; FDq[J] = -FDq[I] ; //d FDq[H] = -FDq[K] ; //b
FDi[I] =(Ai[I] + Ai[J]) / 2;
FDi[J] = FDi[I] ; //c
FDq[I] =(Aq[I] - Aq[J]) / 2;
FDq[J] = -FDq[I] ; //d
} }
//I,J=64 K,H=192 //I,J=64 K,H=192
@ -1573,7 +1572,7 @@ op25_imbe::rearrange(uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3, uint32_
} }
void void
op25_imbe::SynthUnvoiced() op25_imbe::synth_unvoiced()
{ {
float Uwi[256] ; float Uwi[256] ;
float Uwq[256] ; float Uwq[256] ;
@ -1619,7 +1618,7 @@ op25_imbe::SynthUnvoiced()
Uwi[em] = 0; Uwq[em] = 0; Uwi[em] = 0; Uwq[em] = 0;
} }
RealIFFT(Uwi, Uwq, uw); ifft(Uwi, Uwq, uw);
// ws(n)*uw(n,-1) + ws(n-159)*uw(n-159,0) uw(-128 to 127) // ws(n)*uw(n,-1) + ws(n-159)*uw(n-159,0) uw(-128 to 127)
//suv(n) = -------------------------------------- //suv(n) = --------------------------------------
@ -1640,18 +1639,17 @@ op25_imbe::SynthUnvoiced()
} }
void void
op25_imbe::SynthVoiced() op25_imbe::synth_voiced()
{ {
float MaxL;
float MaxL ; float Tmp;
float Tmp ; float Dpl;
float Dpl ; float Dwl;
float Dwl ; float THa;
float THa ; float THb;
float THb ; float MNew;
float MNew ; float MOld;
float MOld ; float Mb;
float Mb ;
int ell, en; int ell, en;
@ -1667,7 +1665,7 @@ op25_imbe::SynthVoiced()
phi[ell][ New] = psi1 * ell; phi[ell][ New] = psi1 * ell;
} }
Tmp = Luv / L; Tmp = Luv / L;
for( ; ell <= MaxL; ell++) { for(; ell <= MaxL; ell++) {
phi[ell][ New] = psi1 * ell + Tmp * PhzNz[ell]; phi[ell][ New] = psi1 * ell + Tmp * PhzNz[ell];
} }
@ -1835,7 +1833,9 @@ op25_imbe::vfPrGen15(unsigned int& Pr)
n = 0; n = 0;
for(i = 14; i >= 0; i--) { for(i = 14; i >= 0; i--) {
Pr =(173 * Pr + 13849) & 0xffffu; Pr =(173 * Pr + 13849) & 0xffffu;
if(Pr & 32768) { n = n +(1 << i); } if(Pr & 32768) {
n = n +(1 << i);
}
} }
return n; return n;
} }
@ -1854,9 +1854,9 @@ op25_imbe::vfPrGen23(unsigned int& Pr)
} }
void void
op25_imbe::vfDec(unsigned char* A, unsigned int& u0, unsigned int& u1, unsigned int& u2, unsigned int& u3, unsigned int& u4, unsigned int& u5, unsigned int& u6, unsigned int& u7, unsigned int& E0, unsigned int& ET) op25_imbe::correct(uint8_t* A, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET)
{ {
unsigned int RX=0; unsigned int RX = 0;
ET = 0; ET = 0;
@ -1899,22 +1899,3 @@ op25_imbe::vfHmg15113Dec(int RX, int ET) // should be int& ET!
} }
return Dat; return Dat;
} }
int
main(int ac, char **av)
{
op25_imbe *imbe = new op25_imbe();
while(--ac) {
FILE *fp = fopen(*++av, "r");
if(fp) {
uint8_t buf[18];
while(1 == fread(buf, sizeof(buf), 1, fp)) {
imbe->imbe_frame(buf);
}
fclose(fp);
} else {
perror(*av);
}
}
return(0);
}

View File

@ -24,22 +24,20 @@
#ifndef INCLUDED_IMBE_H #ifndef INCLUDED_IMBE_H
#define INCLUDED_IMBE_H #define INCLUDED_IMBE_H
#include <stdint.h>
class op25_imbe { class op25_imbe {
public: public:
op25_imbe(); op25_imbe();
~op25_imbe(); ~op25_imbe();
void imbe_frame(unsigned char*); void decode(uint8_t *buf);
void init();
private: private:
// define global lookup tables
//NOTE: Single-letter variable names are upper case only; //NOTE: Single-letter variable names are upper case only;
// Lower case if needed is spelled. e.g. L, ell // Lower case if needed is spelled. e.g. L, ell
// global Seq ER ? // global Seq ER ?
//Working arrays
int bee[58]; //Encoded Spectral Amplitudes int bee[58]; //Encoded Spectral Amplitudes
float M[57][2]; //Enhanced Spectral Amplitudes float M[57][2]; //Enhanced Spectral Amplitudes
float Mu[57][2]; //Unenhanced Spectral Amplitudes float Mu[57][2]; //Unenhanced Spectral Amplitudes
@ -51,7 +49,6 @@ private:
float psi1; float psi1;
float phi[57][2]; float phi[57][2];
//Variables
int Old; int Old;
int New; int New;
int L; int L;
@ -68,7 +65,7 @@ private:
FILE *out; FILE *out;
// member functions // member functions
uint32_t extract(const uint8_t* buf, size_t begin, size_t end); uint32_t extract(const uint8_t* buf, size_t begin, size_t end);
unsigned int vfPickBits0(unsigned char *); unsigned int vfPickBits0(unsigned char *);
@ -87,22 +84,18 @@ private:
unsigned int vfPrGen15(unsigned int& ); unsigned int vfPrGen15(unsigned int& );
unsigned int vfPrGen23(unsigned int& ); unsigned int vfPrGen23(unsigned int& );
#if 0 void correct(uint8_t* A, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET);
void vfDec(const uint8_t*, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&);
#else void decode_audio(uint8_t *);
void vfDec(unsigned char*, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&); void decode_spectral_amplitudes(int, int );
#endif void decode_vuv(int );
void decode(uint8_t *); void adaptive_smoothing(float, float, float );
void DecodeSpectralAmplitudes(int, int ); void fft(float i[], float q[]);
void DecodeVUV(int ); void enhance_spectral_amplitudes(float&);
void AdaptiveSmoothing(float, float, float ); void ifft(float i[], float q[], float[]);
void CplxFFT(float [], float []);
void EnhanceSpectralAmplitudes(float&);
void RealIFFT(float [], float [], float []);
uint16_t rearrange(uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3, uint32_t u4, uint32_t u5, uint32_t u6, uint32_t u7); uint16_t rearrange(uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3, uint32_t u4, uint32_t u5, uint32_t u6, uint32_t u7);
void SynthUnvoiced(void); void synth_unvoiced();
void SynthVoiced(void); void synth_voiced();
void Synth(void);
void unpack(uint8_t *buf, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET); void unpack(uint8_t *buf, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET);
}; };

22
imbe/main.cc Normal file
View File

@ -0,0 +1,22 @@
#include <cstdio>
#include <cstdlib>
#include <imbe.h>
int
main(int ac, char **av)
{
op25_imbe *imbe = new op25_imbe();
while(--ac) {
FILE *fp = fopen(*++av, "r");
if(fp) {
uint8_t buf[18];
while(1 == fread(buf, sizeof(buf), 1, fp)) {
imbe->decode(buf);
}
fclose(fp);
} else {
perror(*av);
}
}
return(0);
}