Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6708 Discussions

API Questions while trying to implement the G722 Codec in c#

pheitkemper
Beginner
759 Views
I've looked at the docs and the sample C code to try and implement a G722 codec in C#.

The docs seem to suggest that encode/decode is done as follows:

enumG722Mode
{
kbps64=1,
kbps56=2,
kbps48=3
}

...
unsafepublicshort[]encode(short[]data,intsize)
{
short[]QMFVec=newshort[LEN_BLOCK];
short[]CodeVec=newshort[LEN_BLOCK];
fixed(short*pData=data,pQMFVec=QMFVec,pCodeVec=CodeVec)
{
fixed(short*pDelay=delay)
{
ippStatus=sc.ippsQMFEncode_G722_16s(pData,pQMFVec,size,pDelay);
}
fixed(IppsEncoderState_G722_16s*pEncoderState=&encoderState)
{
ippStatus=sc.ippsSBADPCMEncode_G722_16s(pQMFVec,pCodeVec,size,pEncoderState);
}
}
returnCodeVec;
}
 
unsafepublicshort[]decode(short[]data,intsize,G722Modemode)
{
short[]QMFVec=newshort[LEN_BLOCK];
short[]CodeVec=newshort[LEN_BLOCK];
 
fixed(short*pData=data,pQMFVec=QMFVec,pCodeVec=CodeVec)
{
fixed(IppsDecoderState_G722_16s*pDecoderState=&decoderState)
{
ippStatus=sc.ippsSBADPCMDecode_G722_16s(pData,pQMFVec,size,(short)mode,pDecoderState);
}
fixed(short*pDelay=delay)
{
ippStatus=sc.ippsQMFDecode_G722_16s(pQMFVec,pCodeVec,size,pDelay);
}
}
returnCodeVec;
}
I have a few questions.
Is the above code correct?
What is the correct value of LEN_BLOCK?
What is the correct size for the delay buffer?
The docs say to call SBADPCMEncodeInit_G722 or SBADPCMDecodeInit_G722 "when starting from the reset state." What does that mean? Before each encode/decode cycle, or once at initialization of the object?

In the samples, owng722sb.c uses these APIs, but adds a lot of other calculations- UnpackCodeword_G722(), etc. These operations are not mentioned in the docs. Do I have to perform other calculations as well?
My C is a little rusty. What is the net effect of the macro IPP_ALIGNED_ARRAY, assuming I'm running on IA32. Do I need to perform some sort of byte alignment? If so, how do you do that in C#?

Thanks,
Paul
0 Kudos
5 Replies
Joseph_S_Intel
Employee
759 Views

Paul, there is an implementation of the G.722 codec using Intel IPP in the Intel IPP samples which you can find at:http://software.intel.com/en-us/articles/intel-ipp/#resources

Did you try using that as a template?

Here is the description of the sample:

The USC G722 codec is designed to operate with a digital signal appropriate to G.722 specification for 7 KHz Audio Coding within 64 Kbit/s promoted by International Telecommunication Union ( www.itu.org ). It is fully compliant with ITU-T G.722 and has been implemented using the Intel Integrated Performance Primitives (Intel IPP) Speech Coding functions. The USC G722 codec supports compression with 20ms frame length at 64 kbps producing 1280 bits per frame (bpf) and decompression with 64, 56 or 48 kbps depending on the transmit mode. The latter two modes allow an auxiliary data to be carried within the 64 kbps channel in lower sub-band at 8 and 16 kbps respectively

0 Kudos
Igor_B_Intel1
Employee
759 Views
Hi Paul,
My suggestion to use codec through USC interface. This is high level API targeting to hide a lot of codec implementation details.Please go through the uscmanual.pdf in speech coding samples.

What about your questions about codec implementation details:
1. The correct value for LEN_BLOCK is 320.
2. The delay is 24 samples.
3. You should to call them once during instance initializing stage.
4. Yes you have to include them all to get fully workable codec.
5. IPP_ALIGNED_ARRAY macro allocates alighned buffer on the stack and targeted to speed up processign code.

Igor
0 Kudos
pheitkemper
Beginner
759 Views

What does #4 refer to, the Unpack...() functions? Those aren't in the IPP library. That's a function that's only inside of the usc_... sample files. Therefore it should not be necessary, right?

I compiled the USC library. Did I do something wrong? Because the output was.lib files. This is even more difficult than the IPP primitives, especially for someone trying to implement an app in C#. Now I have to write a dll with managed C++ classes to wrap the .lib file(s), in order to call it from my C# program, and I have to write a bunch of dllImport statements that Intel had already written for the primitives.

Thx,
Paul

0 Kudos
pheitkemper
Beginner
759 Views
I have compiled the sample code to generate the lib files. I have written a VS2010 dll to call the functions. That code is based on the code sample in uscmanual.pdf. I have written some C# to call the C++ dll functions. The problem I am having now is that I get a null ptr when I try to access the USC_Gxxx_Fnxs variable. I am declaring the pointer as follows:

USC_Fxns *USC_Gxxx_Fnxs;

extern "C"

{

USC_Fxns USC_G729I_Fxns;

USC_Fxns USC_G729A_Fxns;

USC_Fxns USC_G729IFP_Fxns;

USC_Fxns USC_G729AFP_Fxns;

USC_Fxns USC_AMRWB_Fxns;

USC_Fxns USC_G728_Fxns;

USC_Fxns USC_G722_Fxns;

USC_Fxns USC_G726_Fxns;

USC_Fxns USC_G723_Fxns;

USC_Fxns USC_GSMAMR_Fxns;

USC_Fxns USC_GSMFR_Fxns;

USC_Fxns USC_G722SB_Fxns;

USC_Fxns USC_G711A_Fxns;

USC_Fxns USC_G711U_Fxns;

USC_Fxns USC_AMRWBE_Fxns;

USC_Fxns USC_G7291_Fxns;

USC_Fxns USC_ILBC_Fxns;

USC_Fxns USC_MSRTAFP_Fxns;

}

Then in my function, I assign the pointer lis this:
USC_Gxxx_Fnxs = &USC_G711U_Fxns;

The first time I try to dereference the pointer, I get an access violation:

/* Get the size of the Gxxx codec status structure */

if(USC_NoError != USC_Gxxx_Fnxs->std.GetInfoSize(&infoSize))

{

exit(1);

}

I see that the USC_G711U_Fxns structure is defined in uscg711.c, where it is it is fully assigned. I don't see what the problem is on my end.

Please advise.

0 Kudos
Igor_B_Intel1
Employee
759 Views
Hi,
Please make sure that USC_XXX_Fxns objects declared as exported from dll. For that purpuse, please check USCFUN macro declaration. Then if you don't generate and use import library please study routine "void *TryToFindStatic(const Ipp8s *nameCodec)" which located at the file loadcodec.c in usc_speech_codec sample. This routine targeted to open DLL and locate there USC_XXX_Fxns object.

Igor S. Belyakov
0 Kudos
Reply