Example #1
0
static gboolean
gst_siren_dec_start (GstAudioDecoder * dec)
{
  GstSirenDec *sdec = GST_SIREN_DEC (dec);

  GST_DEBUG_OBJECT (dec, "start");

  sdec->decoder = Siren7_NewDecoder (16000);;

  /* no flushing please */
  gst_audio_decoder_set_drainable (dec, FALSE);

  return TRUE;
}
Example #2
0
void
decode_wav_using_siren7 (char *input_file, char *output_file)
{
	FILE * input;
	FILE * output;
	RIFF riff_header;
	WAVE_CHUNK current_chunk;
	fmtChunkEx fmt_info;
	unsigned char *out_data = NULL;
	unsigned char *out_ptr = NULL;
	unsigned char InBuffer[40];
	unsigned int fileOffset;
	unsigned int chunkOffset;

	SirenDecoder decoder = Siren7_NewDecoder(16000);
	
	input = fopen(input_file, "rb");
	output = fopen(output_file, "wb");

	fileOffset = 0;
	fread(&riff_header, sizeof(RIFF), 1, input);
	fileOffset += sizeof(RIFF);

	riff_header.ChunkId = GUINT32_FROM_LE(riff_header.ChunkId);
	riff_header.ChunkSize = GUINT32_FROM_LE(riff_header.ChunkSize);
	riff_header.TypeID = GUINT32_FROM_LE(riff_header.TypeID);

	if (riff_header.ChunkId == RIFF_ID && riff_header.TypeID == WAVE_ID) {
		while (fileOffset < riff_header.ChunkSize) {
			fread(&current_chunk, sizeof(WAVE_CHUNK), 1, input);
			fileOffset += sizeof(WAVE_CHUNK);
			current_chunk.ChunkId = GUINT32_FROM_LE(current_chunk.ChunkId);
			current_chunk.ChunkSize = GUINT32_FROM_LE(current_chunk.ChunkSize);

			chunkOffset = 0;
			if (current_chunk.ChunkId == FMT__ID) {
				fread(&fmt_info, sizeof(fmtChunk), 1, input);
				/* Should convert from LE the fmt_info structure, but it's not necessary... */
				if (current_chunk.ChunkSize > sizeof(fmtChunk)) {
					fread(&(fmt_info.ExtraSize), sizeof(short), 1, input);
					fmt_info.ExtraSize= GUINT32_FROM_LE(fmt_info.ExtraSize);
					fmt_info.ExtraContent = (unsigned char *) malloc (fmt_info.ExtraSize);
					fread(fmt_info.ExtraContent, fmt_info.ExtraSize, 1, input);
				} else {
					fmt_info.ExtraSize = 0;
					fmt_info.ExtraContent = NULL;
				}
			} else if (current_chunk.ChunkId  == DATA_ID) {
				out_data = (unsigned char *) malloc(current_chunk.ChunkSize * 16);
				out_ptr = out_data;
				while (chunkOffset + 40 <= current_chunk.ChunkSize) {
					fread(InBuffer, 1, 40, input);
					Siren7_DecodeFrame(decoder, InBuffer, out_ptr);
					out_ptr += 640;
					chunkOffset += 40;
				}
				fread(InBuffer, 1, current_chunk.ChunkSize - chunkOffset, input);
			} else {
				fseek(input, current_chunk.ChunkSize, SEEK_CUR);
			}
			fileOffset += current_chunk.ChunkSize;
		}
	}
	
	/* The WAV heder should be converted TO LE, but should be done inside the library and it's not important for now ... */
	fwrite(&(decoder->WavHeader), sizeof(decoder->WavHeader), 1, output);
	fwrite(out_data, 1, GUINT32_FROM_LE(decoder->WavHeader.DataSize), output);
	fclose(output);

	Siren7_CloseDecoder(decoder);

	free(out_data);
	if (fmt_info.ExtraContent != NULL)
		free(fmt_info.ExtraContent);
}