[Speex-dev] encode return 0
Andrea Laperuta
andrea.laperuta at digint.it
Wed Oct 10 01:34:14 PDT 2007
Hi.
I’m trying to use the speex library in c#, everything seems to works right,
when I call the speex_encode_int function it always return 0, any help would
be appreciated.
Here’s the sequence of calls:
//Initialization
_Mode = speex_lib_get_mode(0);
_State = speex_encoder_init(_Mode);
fixed (int* __FrameSize = &_FrameSize, __Complexity = &_Complexity,
__SamplingRate = &_SamplingRate)
{
speex_encoder_ctl(_State, 3 /*SPEEX_GET_FRAME_SIZE*/, __FrameSize);
speex_encoder_ctl(_State, 16 /*SPEEX_SET_COMPLEXITY*/,
__Complexity);
speex_encoder_ctl(_State, 24 /*SPEEX_SET_SAMPLING_RATE*/,
__SamplingRate);
}
_Bits = new SpeexBits();
//Data encoding
public byte[] ProcessData(byte[] ABuffer, int ADataSize)
{
int OutputDataSize;
short[] TempData = new short[ADataSize];
for (int Index = ADataSize-1; Index >= 0; Index--)
TempData[Index] = (short)((ABuffer[Index] << 8) ^ 0x8000);
fixed (short* __TempData = &TempData[0])
{
fixed (void* __Bits = &_Bits)
{
if (speex_encode_int(_State, __TempData, __Bits) == 1)
{
fixed (void* __Buffer = _Buffer)
OutputDataSize = speex_bits_write(__Bits, __Buffer,
_Buffer.Length);
speex_bits_reset(__Bits);
}
else
return null;
}
}
byte[] Result = new byte[OutputDataSize];
for (int Index = 0; Index < OutputDataSize; Index++)
Result[Index] = (byte)(_Buffer[Index] >> 8);
return Result;
}
Thank you in advance.
Regards,
Andrew.
Andrea Laperuta
Solution Architect & Team Leader
DigInt Srl
Via Dei Pioppi n. 18/A
20024 Garbagnate Milanese (MI)
Tel. +39 0299020206
Fax. +39 029958518
web: HYPERLINK "http://www.ikon-corp.it/"www.digint.it
* HYPERLINK "mailto:andrea.laperuta at ikon-corp.it"andrea.laperuta at digint.it
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.6/1060 - Release Date: 09/10/2007
16.43
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20071010/6222d047/attachment.htm
More information about the Speex-dev
mailing list