../src/x3Client_5.c:97: error: invalid conversion from void*' toSAMPLE*'
../src/x3Client_5.c:136: error: jump to label `error'
../src/x3Client_5.c:85: error: from here
../src/x3Client_5.c:96: error: crosses initialization of int bufsiz'
../src/x3Client_5.c:95: error: crosses initialization ofint bytes'
../src/x3Client_5.c:91: error: crosses initialization of `int QOS'
make.exe: *** [../src/x3Client_5.o] Error 1
Execution terminated
i'm not sure whats going on maybe there is some setting i had on before. Please let me know if it is an easy fix. i can't remember the settings (if any) i changed. the code follows:
/modular:capture, compress, add xrtp hdr, send to destinationIP or SIP server
one lib for the audio - pa, dsound, wimme {encapsulate in one lib}
one lib for compressoin - speex {with echo and denoiser}
one lib for rtp_packet - xrtp { |rtp_hdr|rtp_payload|UDP|IP|hardware link| } /
include <portaudio\portaudio.h>
include <speex\speex.h>
include <xrtp\xrtp.h>
/len needed based on speex mode/hz/channels/
define BUFLEN 100
/based on mode selected. use only wideband >3 choices no good for end users/
static int X3Audio( void inputBuffer, void outputBuffer,
unsigned long framesPerBuffer, PaTimestamp outTime, void userData ){
/all this is done each time function called: send and pump to stdout*/
(void)outTime;x3Client*Client=(x3Client*)userData;SAMPLE*input=(SAMPLE*)inputBuffer;SAMPLE*spkrs=(SAMPLE*)outputBuffer;staticintsamples=FRAMES_PER_BUFFER*NUM_CHANNELS;inti;/*capture local audio from the microphone*/for(i=0;i<samples;i++)Client->raw_audio[i]=*input++;/*reset speex buffer; compress and send packet*/speex_bits_reset(&Client->ebits);/*encode from tmp audio to ebits struct*/speex_encode_int(Client->enc_state,Client->raw_audio,&Client->ebits);/*write from ebits to audio buffer of sample size. get num of bytes captured*/Client->audio_s=speex_bits_write(&Client->ebits,Client->Packet.payload,samples);/*how much of the struct to send-fuck how much latency here?*/Client->packet_s=(Client->packet_hs+Client->audio_s);/*encapsulated in xrtp packet. now send with xrtp provided functions*/Client->bytes_s=send_xrtp_packet(&Client->Packet,Client->packet_s);/*if anything received from peer; decompress and push to stdout*/Client->bytes_r=recv_xrtp_packet(&Client->recvPacket,BUFLEN);/*put in dbits struct,contents of payload, of payload encoded size.*/speex_bits_read_from(&Client->dbits,Client->recvPacket.payload,SPEEX_ENC_MODE);/*decode from dbits to raw_audio*/speex_decode_int(Client->dec_state,&Client->dbits,Client->raw_audio);/*push the decoded packet to stdout*/for(i=0;i<samples;i++)*spkrs++=Client->raw_audio[i];return0;
/Allocate buffers 160 bytes of type short * NUM_CHANNELS max 320 bytes/
int bytes = (sizeof(SAMPLE) * FRAMES_PER_BUFFER);
int bufsiz = bytes * NUM_CHANNELS;
ClientInfo.raw_audio = malloc (bufsiz);
/set these variables to zero when the session starts/
ClientInfo.bytes_s =0;ClientInfo.audio_s=0;ClientInfo.bytes_r=0;
/initialize xrtp libray, destination address and port number/
xrtp_init(&ClientInfo.Packet,"192.168.0.3",PORT);
/get the header size after rtp initialization/
ClientInfo.packet_hs = xrtp_header_init(&ClientInfo.Packet);
/opendefault stream for input and outuput start x3/
err = Pa_OpenDefaultStream(&stream,
NUM_CHANNELS,/input channels/
NUM_CHANNELS,/output channels/
PA_SAMPLE_TYPE,/sample type/
SAMPLE_RATE,/sample rate/
FRAMES_PER_BUFFER ,/frames per buffer/
0,/let PA determine num of buffers/
X3Audio,/callback funtion/
&ClientInfo);/address of user struct/
/if opcode is 1 then stream is stopped and files are closed/
printf("we finish playing audio. Press [ENTER] to terminate");
if( (err = Pa_CloseStream( stream )) !=paNoError) goto error;
/destroy the speex enocder,decoder,bits, preprocessor /
speex_decoder_destroy(ClientInfo.dec_state);
speex_encoder_destroy(ClientInfo.enc_state);
speex_bits_destroy(&ClientInfo.dbits);
speex_bits_destroy(&ClientInfo.ebits);
/close down portaudio and Winsock API when ready/
getchar();Pa_Terminate(); xrtp_destroy(); return 0;
man i can be an idiot sometimes. i was compiling it as a C++ program, though i don't remember chaning it at all. interesting. Admin please delete this thread if you can. thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-10-18
C++ compilation is far more strict. But generally your C code should compile as C++. What is allowed in C but not is C++ is generally poor practice in C in any case. Using C++ compilation to improve the quality of your C code is no bad thing. It is not that bad after a while the 'better' practice simply becomes habit and the compiler stops criticising! I'd recommend options -Wall and -Werror too.
Of course if this is third-party or legacy code you may have to live with it.
You might consider adding this at the top:
if define _cplusplus
error Sorry, this code is not valid C++, use C compilation.
endif
It will trap this problem if you somehow do it again or reuse this code in a mixed C/C++ project.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for that info clifford especially the preprocessing directives there.
i can see why compiling your c programs could be a good habit, but might it not be exhausting in any case. for example wouldn't a c++ compiler complained if i didn't cast the return value of malloc? can't remember but if true could be exhausting..
where do i go to change the compiler warnings to -wall and -werror?
thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-10-19
>> for example wouldn't a c++ compiler complained if i didn't cast the return value of malloc?
Yes that's true.
>> could be exhausting..
Don't be so pathetic! Your poor tired digits. Besides your entire code has just one malloc call.
Besides since you were now using C++ compilation you might as well use new/delete rather than malloc/free, so the problem (and several others) goes away.
ClientInfo.raw_audio = new SAMPLE[bufsiz] ;
...
delete [] buffsize ;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
new 'knows' the size of the objects it is instantiating, so you don't need the sizeof(SAMPLE).
Oh an the -Wall -Werror: Tools->Compiler options->Compiler tab, check "Add the following commands when calling the compiler", and add them to the box. Since you are using C formatted I/O, I also suggest adding -Wformat as well.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note that you can also add the options to the project itself, in case you have multiple projects that require different options. Project-Project Options-Parameters tab.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-10-19
That is a good point, but these options are applied globally, even to existing projects. That is the reason suggested it - you would want to improve the quality of all your code.
Settings on other tabs in the Tools->Compiler options dialog are only applied when a new project is created or to files built without a project (a bad idea).
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i reinstalled devc++ and code that compiled fine before is now giving me the following errors:
Compiler: Default compiler
Building Makefile: "C:\Code\Projects\X3\Dependants\zinx\tests\Makefile.win"
Executing make clean
rm -f ../src/x3Client_5.o X3.exe
g++.exe -c ../src/x3Client_5.c -o ../src/x3Client_5.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
../src/x3Client_5.c: In function `int main()':
../src/x3Client_5.c:97: error: invalid conversion from
void*' to
SAMPLE*'../src/x3Client_5.c:136: error: jump to label `error'
../src/x3Client_5.c:85: error: from here
../src/x3Client_5.c:96: error: crosses initialization of
int bufsiz' ../src/x3Client_5.c:95: error: crosses initialization of
int bytes'../src/x3Client_5.c:91: error: crosses initialization of `int QOS'
make.exe: *** [../src/x3Client_5.o] Error 1
Execution terminated
i'm not sure whats going on maybe there is some setting i had on before. Please let me know if it is an easy fix. i can't remember the settings (if any) i changed. the code follows:
/modular:capture, compress, add xrtp hdr, send to destinationIP or SIP server
one lib for the audio - pa, dsound, wimme {encapsulate in one lib}
one lib for compressoin - speex {with echo and denoiser}
one lib for rtp_packet - xrtp { |rtp_hdr|rtp_payload|UDP|IP|hardware link| }
/
include <portaudio\portaudio.h>
include <speex\speex.h>
include <xrtp\xrtp.h>
/len needed based on speex mode/hz/channels/
define BUFLEN 100
/based on mode selected. use only wideband >3 choices no good for end users/
define SPEEX_ENC_MODE 38
define SAMPLE_RATE (8000)
define PA_SAMPLE_TYPE paInt16
define NUM_CHANNELS (1)
define FRAMES_PER_BUFFER (160)
define PORT 4950
typedef short SAMPLE;
typedef struct{
SpeexBits dbits;
SpeexBits ebits;
void enc_state;
void dec_state;
SAMPLE *raw_audio;
size_t packet_hs;
size_t audio_s;
size_t packet_s;
size_t bytes_s;
size_t bytes_r;
xrtp_packet_t Packet;
xrtp_packet_t recvPacket;
}x3Client;
static int X3Audio( void inputBuffer, void outputBuffer,
unsigned long framesPerBuffer, PaTimestamp outTime, void userData ){
/all this is done each time function called: send and pump to stdout*/
}
int main(void){
/portaudio requirements /
PortAudioStream *stream;
PaError err;
x3Client ClientInfo;
/intialize PortAudio libraries/
if( (err = Pa_Initialize())!=paNoError) goto error;
/initialize speex libraries-need to find/make/log error codes/
ClientInfo.enc_state = speex_encoder_init(&speex_nb_mode);
ClientInfo.dec_state = speex_decoder_init(&speex_nb_mode);
speex_bits_init(&ClientInfo.ebits);
speex_bits_init(&ClientInfo.dbits);int QOS=8;
speex_encoder_ctl(ClientInfo.enc_state,SPEEX_SET_QUALITY,&QOS);
/Allocate buffers 160 bytes of type short * NUM_CHANNELS max 320 bytes/
int bytes = (sizeof(SAMPLE) * FRAMES_PER_BUFFER);
int bufsiz = bytes * NUM_CHANNELS;
ClientInfo.raw_audio = malloc (bufsiz);
/set these variables to zero when the session starts/
ClientInfo.bytes_s =0;ClientInfo.audio_s=0;ClientInfo.bytes_r=0;
/initialize xrtp libray, destination address and port number/
xrtp_init(&ClientInfo.Packet,"192.168.0.3",PORT);
/get the header size after rtp initialization/
ClientInfo.packet_hs = xrtp_header_init(&ClientInfo.Packet);
/opendefault stream for input and outuput start x3/
err = Pa_OpenDefaultStream(&stream,
NUM_CHANNELS,/input channels/
NUM_CHANNELS,/output channels/
PA_SAMPLE_TYPE,/sample type/
SAMPLE_RATE,/sample rate/
FRAMES_PER_BUFFER ,/frames per buffer/
0,/let PA determine num of buffers/
X3Audio,/callback funtion/
&ClientInfo);/address of user struct/
/if opcode is 1 then stream is stopped and files are closed/
printf("we finish playing audio. Press [ENTER] to terminate");
if( (err = Pa_CloseStream( stream )) !=paNoError) goto error;
/destroy the speex enocder,decoder,bits, preprocessor /
speex_decoder_destroy(ClientInfo.dec_state);
speex_encoder_destroy(ClientInfo.enc_state);
speex_bits_destroy(&ClientInfo.dbits);
speex_bits_destroy(&ClientInfo.ebits);
/close down portaudio and Winsock API when ready/
getchar();Pa_Terminate(); xrtp_destroy(); return 0;
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
return -1;
}
man i can be an idiot sometimes. i was compiling it as a C++ program, though i don't remember chaning it at all. interesting. Admin please delete this thread if you can. thanks.
C++ compilation is far more strict. But generally your C code should compile as C++. What is allowed in C but not is C++ is generally poor practice in C in any case. Using C++ compilation to improve the quality of your C code is no bad thing. It is not that bad after a while the 'better' practice simply becomes habit and the compiler stops criticising! I'd recommend options -Wall and -Werror too.
Of course if this is third-party or legacy code you may have to live with it.
You might consider adding this at the top:
if define _cplusplus
error Sorry, this code is not valid C++, use C compilation.
endif
It will trap this problem if you somehow do it again or reuse this code in a mixed C/C++ project.
Clifford
Thanks for that info clifford especially the preprocessing directives there.
i can see why compiling your c programs could be a good habit, but might it not be exhausting in any case. for example wouldn't a c++ compiler complained if i didn't cast the return value of malloc? can't remember but if true could be exhausting..
where do i go to change the compiler warnings to -wall and -werror?
thanks
>> for example wouldn't a c++ compiler complained if i didn't cast the return value of malloc?
Yes that's true.
>> could be exhausting..
Don't be so pathetic! Your poor tired digits. Besides your entire code has just one malloc call.
Besides since you were now using C++ compilation you might as well use new/delete rather than malloc/free, so the problem (and several others) goes away.
ClientInfo.raw_audio = new SAMPLE[bufsiz] ;
...
delete [] buffsize ;
Correction:
size_t bufsiz = FRAMES_PER_BUFFER * NUM_CHANNELS ;
ClientInfo.raw_audio = new SAMPLE[bufsiz] ;
new 'knows' the size of the objects it is instantiating, so you don't need the sizeof(SAMPLE).
Oh an the -Wall -Werror: Tools->Compiler options->Compiler tab, check "Add the following commands when calling the compiler", and add them to the box. Since you are using C formatted I/O, I also suggest adding -Wformat as well.
Clifford
Note that you can also add the options to the project itself, in case you have multiple projects that require different options. Project-Project Options-Parameters tab.
That is a good point, but these options are applied globally, even to existing projects. That is the reason suggested it - you would want to improve the quality of all your code.
Settings on other tabs in the Tools->Compiler options dialog are only applied when a new project is created or to files built without a project (a bad idea).
Clifford