Hey all I have been working on a simple VOIP app and have gotten my self totally confused. <br>
is this the right process to follow? Any tips examples guidence would be super awesome. <br>
<br>
I have my voice data. capturing. <br>
I encoding it so that there are multi speex frames per packet.<br>
<br>
on the reciving end i decode the package i recive. <br>
<br>
Yeah it dosnt work at all. :D<br>
<br>
this is the code for the encode.<br>
<br>
int PackVoiceData(SpeexBits *bits,int space_avalible_in_packect, int
size_of_data_avalible, int frame_size , void * data_to_pack, char *
destinantion_buffer )<br>
{<br>
<br>
<br>
float frame[FRAME_SIZE];<br>
int offset= 0;<br>
<br>
float * data_as_floats;<br>
short * data_as_shorts = (short *) data_to_pack;<br>
memset(destinantion_buffer , 0,size_of_data_avalible);<br>
/// memset(data_as_shorts , 0,size_of_data_avalible);<br>
int number_of_frames;<br>
<br>
/// clear the space each time.<br>
int length = space_avalible_in_packect;<br>
<br>
if ( size_of_data_avalible < space_avalible_in_packect )<br>
{<br>
length = size_of_data_avalible;<br>
}<br>
<br>
/// allocate space in memory for the float version of the data.<br>
data_as_floats = (float *)calloc ( length, sizeof( float));<br>
number_of_frames = length/FRAME_SIZE;<br>
for(int i=0; i< length; i++ )<br>
{<br>
data_as_floats[i] = data_as_shorts[i];<br>
<br>
}<br>
/// if size of data avaliable is less than the space avaliable in the packet figure<br>
/// the number of frames from the data avaliable<br>
speex_bits_reset( bits );<br>
/// Call speex incode n times before writing the data stream.<br>
for( int i =0 ; i < number_of_frames-1; i ++)<br>
{<br>
<br>
/// pack a frame <br>
for(int j=0; j< FRAME_SIZE; j++ )<br>
{<br>
frame[j] = data_as_floats [j+offset];<br>
<br>
}<br>
<br>
// this enoced the data<br>
speex_encode( encoder_state, frame , bits );<br>
// increase the offset<br>
offset+=FRAME_SIZE;<br>
<br>
}<br>
<br>
//speex_encode( encoder_state, frame , bits ); <br>
/// write teh stream out. <br>
int bytes_to_write = speex_bits_nbytes( bits );<br>
/// transform from float to char* to write. The
termination code is acutomatically added to teh end of the stream.<br>
bytes_written = speex_bits_write( bits, destinantion_buffer, bytes_to_write );<br>
/// return the amount of data writtne.<br>
printf( "bytes written %d\n" ,bytes_written );<br>
return bytes_written;<br>
<br>
<br>
<br>
}<br>
<br>
<br>
<br>
and the decode. ...<br>
<br>
int Decode( SpeexBits *bits, char * input_bits, int data_in_length , char * output )<br>
{<br>
<br>
float * out_put = (float *)calloc( data_in_length,sizeof( float ) );<br>
int number_of_frames = data_in_length/FRAME_SIZE;<br>
int offset<br>
for( int i = 0; i< number_of_frames; i++ )<br>
{<br>
<br>
// read the bits into the byte stream struct.<br>
speex_bits_read_from( bits , input_bits, FRAME_SIZE );<br>
<br>
// decode the data.<br>
speex_decode( decoder_state, bits , out_put);<br>
<br>
for( int i = 0; i < data_in_length; i++ )<br>
{<br>
<br>
output[i+offset] = out_put[i]; <br>
}<br>
<br>
offset+=FRAME_SIZE;<br>
<br>
}<br>
/// change the floats to shorts so it can be used by the sound out put. <br>
<br>
speex_bits_reset( bits );<br>
<br>
<br>
<br>
}<br>
<br>
<br>
my main loop just caputures and sends and then recives with a wait function/poll of the open socket. <br>
<br>
<br>