[Speex-dev] SpeexCodec run in linux of decode

r96128 r96128 at csie.ntu.edu.tw
Mon Dec 10 22:06:50 PST 2007


Hi , may I ask some question about the decode files?
here is my decode.c 
but when the program run to speex_encoder_destroy(state);
It shows that segmentation fault ,I feel comfused, could you tell
thanks!
#define MAX_FRAME_SIZE 320
int main()
{
	FILE *fout;
	char *inFile;
	FILE *fin;
	short out[MAX_FRAME_SIZE];
	char cbits[200];
	int nbBytes;
	void *state;
	SpeexBits bits;
	//int tmp;
	int m_frame_size;

	speex_bits_init(&bits);
	state = speex_decoder_init(&speex_nb_mode);
	speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &m_frame_size);
	//tmp = 1;
	//speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);

	//outFile = argv[1];
	inFile = "out.spx";
	fin = fopen(inFile, "r+b");
	fout = fopen("out.pcm", "w+b");
	
	if(fin == NULL || fout == NULL){
		printf("FILE open error\n");
		return 1;
	}

	while(1)
	{
		fread(&nbBytes, sizeof(int), 1, fin);
#ifdef _DEBUG
		printf("\nnbBytes: %d\n",nbBytes);
#endif
		if (feof(fin))
			break;

		fread(cbits, 1, nbBytes, fin);

		speex_bits_read_from(&bits, cbits, nbBytes);
		speex_decode_int(state, &bits, out);

		fwrite(out, sizeof(short), m_frame_size, fout);
	}
	speex_encoder_destroy(state);
	speex_bits_destroy(&bits);
	fclose(fin);
	fclose(fout);

	return 0;
}--
Open WebMail Project (http://openwebmail.org)



More information about the Speex-dev mailing list