Community
cancel
Showing results for 
Search instead for 
Did you mean: 
fala70
Beginner
70 Views

AMR Narrow Band

Is there a decoder for AMR Narrow Band ? I didn't see nothing about this.

thanks
Stefano
0 Kudos
2 Replies
Vyacheslav_Baranniko
New Contributor II
70 Views

Hi Stefano

GSMAMR is supported by freely available IPP samples, specifically by speech_codec sample from speech-codecs package, see.ipp-samplesspeech-codecsapplicationusc_speech_codec eadme.htm

Best regards, Slava

IPP speech coding

fala70
Beginner
70 Views

I developed a source code for decode frames AMR-NB to PCM using GSMAMR decoder. It doesn't work good I hear strange noise sound.

My Module source is very simple there is a init func and a Decode func. My frames data are 5,15 kbit/s (mono), 14 bytes for 20 ms. Decode func. return 320 bytes pcm format decoded. Are you sure that AMR-NB is GSMAMR CODEC ???
below there is the code class Camrdec

class AMRDEC_API Camrdec {
private:
USC_Handle hUSCDecoder;
USC_CodecInfo pInfo;
int nbanksEnc,nbanksDec;
USC_MemBank* pBanksDec;
USC_Fxns *USC_Codec_Fxn;

void FreeCodecMemory();
int EvaluateEncodedByteSize(int bitrate);
int EvaluateEncodedBitSize(int bitrate);

//[BitRate:EncodeBitSize:NFramesToSend]
//bitrate->encodedbitsize
int BitsLenTbl[9][3];
public:
Camrdec(void);
~Camrdec(void);
bool Init(int bitrate);
int DecodeOneFrame(char *src,char *dst);
};

#include "stdafx.h"
#include "amrdec.h"
#include
#include
#include
#include

#ifdef __cplusplus
extern "C" {
#endif
extern USC_Fxns USC_GSMAMR_Fxns;
#ifdef __cplusplus
}
#endif



// Costruttore di una classe esportata.
// Vedere amrdec.h per la definizione della classe
Camrdec::Camrdec()
{
nbanksEnc = nbanksDec = 0;
pBanksDec = NULL;
USC_Codec_Fxn = &USC_GSMAMR_Fxns;


BitsLenTbl[0][0]=6600;BitsLenTbl[0][1]=132;BitsLenTbl[0][2]=1;
BitsLenTbl[1][0]=8850;BitsLenTbl[1][1]=177;BitsLenTbl[1][2]=1;
BitsLenTbl[2][0]=12650;BitsLenTbl[2][1]=253;BitsLenTbl[2][2]=1;
BitsLenTbl[3][0]=14250;BitsLenTbl[3][1]=285;BitsLenTbl[3][2]=1;
BitsLenTbl[4][0]=15850;BitsLenTbl[4][1]=317;BitsLenTbl[4][2]=1;
BitsLenTbl[5][0]=18250;BitsLenTbl[5][1]=365;BitsLenTbl[5][2]=1;
BitsLenTbl[6][0]=19850;BitsLenTbl[6][1]=397;BitsLenTbl[6][2]=1;
BitsLenTbl[7][0]=23050;BitsLenTbl[7][1 ]=461;BitsLenTbl[7][2]=1;
BitsLenTbl[8][0]=23850;BitsLenTbl[8][1]=477;BitsLenTbl[8][2]=1;

return;
}

Camrdec::~Camrdec()
{
FreeCodecMemory();
}

bool Camrdec::Init(int bitrate)
{
FreeCodecMemory();


if (USC_NoError != USC_Codec_Fxn->std.GetInfo((USC_Handle)NULL, &pInfo))
return false;

pInfo.params.direction = USC_DECODE; /* Direction: decode */
pInfo.params.modes.vad = 0; /* Suppress a silence compression */
pInfo.params.law = 0; /* Linear PCM input */
pInfo.params.modes.bitrate = bitrate;
pInfo.pPcmTypesTbl->sample_frequency = 8000;

/* Learn how many memory block needed for the decoder */
if(USC_NoError != USC_Codec_Fxn->std.NumAlloc(&pInfo.params, &nbanksDec))
return false;


/* allocate memory for memory bank table */
pBanksDec = (USC_MemBank*)malloc(sizeof(USC_MemBank)*nbanksDec);


/* Query how big has to be each block */
if(USC_NoError != USC_Codec_Fxn->std.MemAlloc(&pInfo.params, pBanksDec))
return false;


/* allocate memory for each block */
int i;
for(i=0; i{
pBanksDec.pMem = ( char*)malloc(pBanksDec.nbytes);
}
/* Create decoder instance */
if(USC_NoError != USC_Codec_Fxn->std.Init(&pInfo.params, pBanksDec, &hUSCDecoder))
return false;

return true;
}

void Camrdec::FreeCodecMemory()
{
int i;
/*
Release decoder memory
*/
for(i=0; i{
if (pBanksDec.pMem)
free(pBanksDec.pMem);
}
if (pBanksDec)
free(pBanksDec);
nbanksDec = 0;
}

#define RX_SPEECH_GOOD 0

int Camrdec::DecodeOneFrame(char *src,char *dst)
{
USC_Bitstream in;
USC_PCMStream out;

in.pBuffer = src;
in.frametype = RX_SPEECH_GOOD ;
in.bitrate = pInfo.params.modes.bitrate;
in.nbytes = 14;//EvaluateEncodedByteSize(in.bitrate);
//return in.nbytes;
//DbgOutInt("Size bytes", in.nbytes);

out.pBuffer = dst;
out.pcmType.bitPerSample = pInfo.pPcmTypesTbl->bitPerSample;
out.pcmType.sample_frequency = 5500;//pInfo.pPcmTypesTbl->sample_frequency;
out.bitrate = pInfo.params.modes.bitrate;
if(USC_NoError != USC_Codec_Fxn->Decode (hUSCDecoder, &in, &out))
return -1;
return out.nbytes;

}

void DbgOutInt(string label, int value ) {
stringstream strs;
strs << value;
label.append(strs.str()) ;
const char *c_str =label.c_str() ;
OutputDebugString( c_str ) ;
}

int Camrdec::EvaluateEncodedBitSize(int bitrate)
{
int len = sizeof(BitsLenTbl)/sizeof(BitsLenTbl[0]);
for (int i=0; i{
if (BitsLenTbl[0] == bitrate)
return BitsLenTbl[1];
}
return -1;
}

int Camrdec::EvaluateEncodedByteSize(int bitrate)
{
int len = EvaluateEncodedBitSize(bitrate);
#if 1//KARTHIK
return ((len + 14)/15)*sizeof(short);
#else
return ((len + 7)/8)*sizeof(char);
#endif
}

Reply