[Speex-dev] encode and decode

shlorit marmor shlorit at gmail.com
Mon Sep 6 05:22:13 PDT 2010


hi

we are trying to decode speech that was encoded on a ds'pic with a NB 8
Kb/sec.

 we wrote a simple program using the API speex lib 1.2 beta 3:





#include "stdafx.h"

#include <iostream>

#include <stdio.h>

#include "speex.h"

#include "speex_bits.h"

using namespace std;

char hex2ascii(char toconv);

#define FRAME_SIZE 160

#define nbBytes 20

int main(int argc, _TCHAR* argv[])

{

int mode = 3;

int i=0,j=0;

char ch=0;

int in=0,temp=0;

char out_ascii[640]={0};

float output[FRAME_SIZE];//the originals 160 words in float

short out[FRAME_SIZE];//the originals 160 words

char cbits[nbBytes];

void *state;//hold the state of the decoder

SpeexMode speex_nb_mode;

SpeexBits bits;

state=decoder_init_func(& speex_nb_mode);//initializing a speex decoder

speex_decoder_ctl(state,SPEEX_SET_MODE,&temp);

speex_bits_init(&bits);





we get the data throw RS232, and convert the decoded (supose to be the
original or close to it) to ASCII, so we can simply play it in MATLAB:



system("mode com1: baud=38400 parity=n data=8 stop=1");//opening the rs232



FILE* mic=fopen("com1:", "w+" );

FILE *mic1 = fopen("mic.txt" , "wt");

while(1)

{

if (feof( mic ) == 0){

cbits[i]=fgetc(mic);

if(i==20)

{

speex_bits_read_from(&bits, cbits, nbBytes);

i=0;

speex_decode(state, &bits, output);

for (j=0;j<FRAME_SIZE;j++)

{

out[j]=output[j];

out_ascii[j*4]=hex2ascii((out[j] >> 12) & 0x000F);

out_ascii[j*4+1]=hex2ascii((out[j] >> 8) & 0x000F);

out_ascii[j*4+2]=hex2ascii((out[j] >> 4) & 0x000F);

out_ascii[j*4+3]=hex2ascii(out[j]  & 0x000F);

}

fputs(out_ascii,mic1);

}

else{

i++;

}

}



fclose( mic );

fclose( mic1 );

return 0;

}



char hex2ascii(char toconv)

{

if (toconv<0x0A)

{

toconv += 0x30;

}

else

{

toconv += 0x37;

}

return (toconv);

}



the program give as an error message:

"*Unhandled exception at 0x1000b65a in new_speex.exe: 0xC0000005: Access
violation reading location 0xccccccfc.*"



we dont undersand why, maybe we are not on the correct NB mode?

we need help!



thanks

shlomo and eitan

EE students in israel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20100906/b98b63b5/attachment.htm 


More information about the Speex-dev mailing list