예제 #1
0
void g711sync2 (_AFmoduleinst *i)
{
	g711_data *d = (g711_data *) i->modspec;

	/* sanity check. */
	assert(!d->seekok || (af_ftell(d->fh) == d->trk->fpos_next_frame));

	/* We can afford to do an lseek just in case because sync2 is rare. */
	d->trk->fpos_after_data = af_ftell(d->fh);

	d->trk->fpos_next_frame = d->saved_fpos_next_frame;
	d->trk->nextfframe = d->saved_nextfframe;
}
예제 #2
0
static status WriteFrameCount (AFfilehandle file)
{
	_Track		*track = NULL;
	_WAVEInfo	*waveinfo = NULL;
	u_int32_t	factSize = 4;
	u_int32_t	totalFrameCount;

	assert(file != NULL);

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);
	waveinfo = (_WAVEInfo *) file->formatSpecific;

	/* We only write the fact chunk for compressed audio. */
	if (track->f.compressionType == AF_COMPRESSION_NONE)
		return AF_SUCCEED;

	/*
		If the offset for the fact chunk hasn't been set yet,
		set it to the file's current position.
	*/
	if (waveinfo->factOffset == 0)
		waveinfo->factOffset = af_ftell(file->fh);
	else
		af_fseek(file->fh, waveinfo->factOffset, SEEK_SET);

	af_fwrite("fact", 4, 1, file->fh);
	factSize = HOST_TO_LENDIAN_INT32(factSize);
	af_fwrite(&factSize, 4, 1, file->fh);

	totalFrameCount = HOST_TO_LENDIAN_INT32(track->totalfframes);
	af_fwrite(&totalFrameCount, 4, 1, file->fh);

	return AF_SUCCEED;
}
예제 #3
0
static status WriteFrameCount (AFfilehandle file)
{
	_Track		*track = NULL;
	_WAVEInfo	*waveinfo = NULL;
	uint32_t	factSize = 4;
	uint32_t	totalFrameCount;

	assert(file != NULL);

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);
	waveinfo = (_WAVEInfo *) file->formatSpecific;

	/* Omit the fact chunk only for uncompressed integer audio formats. */
	if (track->f.compressionType == AF_COMPRESSION_NONE &&
		(track->f.sampleFormat == AF_SAMPFMT_TWOSCOMP ||
		track->f.sampleFormat == AF_SAMPFMT_UNSIGNED))
		return AF_SUCCEED;

	/*
		If the offset for the fact chunk hasn't been set yet,
		set it to the file's current position.
	*/
	if (waveinfo->factOffset == 0)
		waveinfo->factOffset = af_ftell(file->fh);
	else
		af_fseek(file->fh, waveinfo->factOffset, SEEK_SET);

	af_fwrite("fact", 4, 1, file->fh);
	af_write_uint32_le(&factSize, file->fh);

	totalFrameCount = track->totalfframes;
	af_write_uint32_le(&totalFrameCount, file->fh);

	return AF_SUCCEED;
}
예제 #4
0
status WriteMiscellaneous (AFfilehandle filehandle)
{
	_WAVEInfo	*wave = (_WAVEInfo *) filehandle->formatSpecific;

	if (filehandle->miscellaneousCount != 0)
	{
		int		i;
		u_int32_t	miscellaneousBytes;

		/* Start at 4 to account for 'INFO' chunk id. */
		miscellaneousBytes = 4;

		for (i=0; i<filehandle->miscellaneousCount; i++)
		{
			/* Account for miscellaneous type and size. */
			miscellaneousBytes += 8;
			miscellaneousBytes += filehandle->miscellaneous[i].size;

			/* Add a pad byte if necessary. */
			if (filehandle->miscellaneous[i].size % 2 != 0)
				miscellaneousBytes++;

			assert(miscellaneousBytes % 2 == 0);
		}

		wave->miscellaneousStartOffset = af_ftell(filehandle->fh);
		wave->totalMiscellaneousSize = miscellaneousBytes;

		/* Add 8 to account for length of 'LIST' chunk id and size. */
		af_fseek(filehandle->fh, miscellaneousBytes + 8, SEEK_CUR);
	}

	return AF_SUCCEED;
}
예제 #5
0
void g711run_push (_AFmoduleinst *i)
{
	g711_data *d = (g711_data *)i->modspec;
	AFframecount frames2write = i->inc->nframes;
	AFframecount samps2write = i->inc->nframes * i->inc->f.channelCount;
	int framesize = sizeof (g711samp) * (i->inc->f.channelCount);
	AFframecount nfr;

	assert(d->trk->f.compressionType == AF_COMPRESSION_G711_ULAW ||
		d->trk->f.compressionType == AF_COMPRESSION_G711_ALAW);

	/* Compress frames into i->outc. */

	if (d->trk->f.compressionType == AF_COMPRESSION_G711_ULAW)
		linear2ulaw_buf(i->inc->buf, i->outc->buf, samps2write);
	else
		linear2alaw_buf(i->inc->buf, i->outc->buf, samps2write);

	/* Write the compressed data. */

	nfr = af_fwrite(i->outc->buf, framesize, frames2write, d->fh);

	CHNK(printf("writing %d frames to g711 file\n", frames2write));

	if (nfr != frames2write)
	{
		/* report error if we haven't already */
		if (d->trk->filemodhappy)
		{
			/* i/o error */
			if (nfr < 0)
				_af_error(AF_BAD_WRITE,
					"unable to write data (%s) -- "
					"wrote %d out of %d frames",
					strerror(errno),
					d->trk->nextfframe + nfr,
					d->trk->nextfframe + frames2write);

			/* usual disk full error */
			else
				_af_error(AF_BAD_WRITE,
					"unable to write data (disk full) -- "
					"wrote %d out of %d frames",
					d->trk->nextfframe + nfr,
					d->trk->nextfframe + frames2write);

			d->trk->filemodhappy = AF_FALSE;
		}
	}

	d->trk->nextfframe += nfr;
	d->trk->totalfframes = d->trk->nextfframe;
	d->trk->fpos_next_frame += (nfr>0) ? nfr/framesize : 0;

	assert(!d->seekok || (af_ftell(d->fh) == d->trk->fpos_next_frame));
}
예제 #6
0
파일: FilePackIo.cpp 프로젝트: adri87/Q-A
long ZCALLBACK aftell_file_func (
   voidpf opaque,
   voidpf stream)
{
    long ret;

    (void)opaque;

    ret = af_ftell((ABSTRACTFILE *)stream);
    return ret;
}
예제 #7
0
static void ms_adpcm_run_pull (_AFmoduleinst *module)
{
	ms_adpcm_data	*d = (ms_adpcm_data *) module->modspec;
	AFframecount	frames2read = module->outc->nframes;
	AFframecount	nframes = 0;
	int		i, framesPerBlock, blockCount;
	ssize_t		blocksRead, bytesDecoded;

	framesPerBlock = d->framesPerBlock;
	assert(module->outc->nframes % framesPerBlock == 0);
	blockCount = module->outc->nframes / framesPerBlock;

	/* Read the compressed frames. */
	blocksRead = af_fread(module->inc->buf, d->blockAlign, blockCount, d->fh);

	/* Decompress into module->outc. */
	for (i=0; i<blockCount; i++)
	{
		bytesDecoded = ms_adpcm_decode_block(d,
			(const uint8_t *) module->inc->buf + i * d->blockAlign,
			(int16_t *) module->outc->buf + i * d->framesPerBlock * d->track->f.channelCount);

		nframes += framesPerBlock;
	}

	d->track->nextfframe += nframes;

	if (blocksRead > 0)
		d->track->fpos_next_frame += blocksRead * d->blockAlign;

	assert(af_ftell(d->fh) == d->track->fpos_next_frame);

	/*
		If we got EOF from read, then we return the actual amount read.

		Complain only if there should have been more frames in the file.
	*/

	if (d->track->totalfframes != -1 && nframes != frames2read)
	{
		/* Report error if we haven't already */
		if (d->track->filemodhappy)
		{
			_af_error(AF_BAD_READ,
				"file missing data -- read %d frames, should be %d",
				d->track->nextfframe,
				d->track->totalfframes);
			d->track->filemodhappy = false;
		}
	}

	module->outc->nframes = nframes;
}
예제 #8
0
static status WriteData (AFfilehandle file)
{
	_Track		*track;
	uint32_t	chunkSize;
	_WAVEInfo	*waveinfo;

	assert(file);

	waveinfo = file->formatSpecific;
	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	af_fwrite("data", 4, 1, file->fh);
	waveinfo->dataSizeOffset = af_ftell(file->fh);

	chunkSize = (int) _af_format_frame_size(&track->f, false) *
		track->totalfframes;

	af_write_uint32_le(&chunkSize, file->fh);
	track->fpos_first_frame = af_ftell(file->fh);

	return AF_SUCCEED;
}
예제 #9
0
static status WriteData (AFfilehandle file)
{
	_Track		*track;
	u_int32_t	frameSize, chunkSize;
	_WAVEInfo	*waveinfo;

	assert(file);

	waveinfo = file->formatSpecific;
	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	af_fwrite("data", 4, 1, file->fh);
	waveinfo->dataSizeOffset = af_ftell(file->fh);

	frameSize = _af_format_frame_size(&track->f, AF_FALSE);
	chunkSize = frameSize * track->totalfframes;
	chunkSize = HOST_TO_LENDIAN_INT32(chunkSize);
	af_fwrite(&chunkSize, 4, 1, file->fh);
	track->fpos_first_frame = af_ftell(file->fh);

	return AF_SUCCEED;
}
void InstallLogger::LoadParamFile(const char* parameter_filename) {
    init_done = 0;
    
    ABSTRACTFILE *af_fin = af_fopen_unlogged((parameter_filename != NULL) ?
                                parameter_filename : "unitex_logging_parameters.txt","rb");
    if (af_fin!=NULL)
    {
        size_t size_param=0;

        if (af_fseek(af_fin, 0, SEEK_END) == 0)
	    {
		    size_param = af_ftell(af_fin);
            af_fseek(af_fin, 0, SEEK_SET);
        }

        char* param=(char*)malloc(size_param+1);
        *(param+size_param)=0;
        if (af_fread(param,1,size_param,af_fin) == size_param)
        {
            
            int write_file_out=0;
            char*szPath = (char*)malloc(size_param+1);
            *szPath=0;
            sscanf(param,"%s\n%u",szPath,&write_file_out);
            write_file_out+=0;
            if ((*szPath) != 0)
            {
                ClearUniLoggerSpaceStruct(0);

                ule.szPathLog = szPath;
                ule.szNameLog = NULL;
                ule.store_file_out_content = write_file_out;

                if (AddActivityLogger(&ule) != 0)
                    init_done = 1;
                else
                {
                    ClearUniLoggerSpaceStruct(1);
                }
            }
            else
                free(szPath);
        }
        af_fclose(af_fin);
        free(param);        
    }
}
예제 #11
0
void g711run_pull (_AFmoduleinst *i)
{
	g711_data *d = (g711_data *) i->modspec;
	AFframecount frames2read = i->outc->nframes;
	AFframecount samps2read = i->outc->nframes * i->outc->f.channelCount;
	int framesize = sizeof(g711samp)*(i->outc->f.channelCount);
	AFframecount nfr;

	/* Read the compressed frames. */

	nfr = af_fread(i->inc->buf, framesize, frames2read, d->fh);

	/* Decompress into i->outc. */

	if (d->trk->f.compressionType == AF_COMPRESSION_G711_ULAW)
		ulaw2linear_buf(i->inc->buf, i->outc->buf, samps2read);
	else
		alaw2linear_buf(i->inc->buf, i->outc->buf, samps2read);

	CHNK(printf("reading %d frames from g711 file (got %d)\n",
		frames2read, nfr));

	d->trk->nextfframe += nfr;
	d->trk->fpos_next_frame += (nfr>0) ? nfr/framesize : 0;
	assert(!d->seekok || (af_ftell(d->fh) == d->trk->fpos_next_frame));

	/*
		If we got EOF from read, then we return the actual amount read.

		Complain only if there should have been more frames in the file.
	*/

	if (d->trk->totalfframes != -1 && nfr != frames2read)
	{
		/* Report error if we haven't already */
		if (d->trk->filemodhappy)
		{
			_af_error(AF_BAD_READ,
				"file missing data -- read %d frames, should be %d",
				d->trk->nextfframe,
				d->trk->totalfframes);
			d->trk->filemodhappy = AF_FALSE;
		}
	}

	i->outc->nframes = nfr;
}
예제 #12
0
_AFmoduleinst _af_ms_adpcm_init_decompress (_Track *track, AFvirtualfile *fh,
	bool seekok, bool headerless, AFframecount *chunkframes)
{
	_AFmoduleinst	ret = _AFnewmodinst(&ms_adpcm_decompress);
	ms_adpcm_data	*d;
	AUpvlist	pv;
	long		l;
	void		*v;

	assert(af_ftell(fh) == track->fpos_first_frame);

	d = (ms_adpcm_data *) _af_malloc(sizeof (ms_adpcm_data));

	d->track = track;
	d->fh = fh;

	d->track->frames2ignore = 0;
	d->track->fpos_next_frame = d->track->fpos_first_frame;

	pv = d->track->f.compressionParams;
	if (_af_pv_getlong(pv, _AF_MS_ADPCM_NUM_COEFFICIENTS, &l))
		d->numCoefficients = l;
	else
		_af_error(AF_BAD_CODEC_CONFIG, "number of coefficients not set");

	if (_af_pv_getptr(pv, _AF_MS_ADPCM_COEFFICIENTS, &v))
		memcpy(d->coefficients, v, sizeof (int16_t) * 256 * 2);
	else
		_af_error(AF_BAD_CODEC_CONFIG, "coefficient array not set");

	if (_af_pv_getlong(pv, _AF_FRAMES_PER_BLOCK, &l))
		d->framesPerBlock = l;
	else
		_af_error(AF_BAD_CODEC_CONFIG, "samples per block not set");

	if (_af_pv_getlong(pv, _AF_BLOCK_SIZE, &l))
		d->blockAlign = l;
	else
		_af_error(AF_BAD_CODEC_CONFIG, "block size not set");

	*chunkframes = d->framesPerBlock;

	ret.modspec = d;
	return ret;
}
예제 #13
0
static status ParseBODY (AFfilehandle file, AFvirtualfile *fh, uint32_t type,
	size_t size)
{
	_Track		*track;

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	/*
		IFF/8SVX files have only one audio channel with one
		byte per sample, so the number of frames is equal to
		the number of bytes.
	*/
	track->totalfframes = size;
	track->data_size = size;

	/* Sound data follows. */
	track->fpos_first_frame = af_ftell(fh);

	return AF_SUCCEED;
}
예제 #14
0
_AFmoduleinst _af_ima_adpcm_init_decompress (_Track *track, AFvirtualfile *fh,
	bool seekok, bool headerless, AFframecount *chunkframes)
{
	_AFmoduleinst	ret = _AFnewmodinst(&ima_adpcm_decompress);
	ima_adpcm_data	*d;
	AUpvlist	pv;
	int		i;
	long		l;
	void		*v;

	assert(af_ftell(fh) == track->fpos_first_frame);

	d = (ima_adpcm_data *) _af_malloc(sizeof (ima_adpcm_data));

	d->track = track;
	d->fh = fh;

	d->track->frames2ignore = 0;
	d->track->fpos_next_frame = d->track->fpos_first_frame;

	pv = d->track->f.compressionParams;

	if (_af_pv_getlong(pv, _AF_SAMPLES_PER_BLOCK, &l))
		d->samplesPerBlock = l;
	else
		_af_error(AF_BAD_CODEC_CONFIG, "samples per block not set");

	if (_af_pv_getlong(pv, _AF_BLOCK_SIZE, &l))
		d->blockAlign = l;
	else
		_af_error(AF_BAD_CODEC_CONFIG, "block size not set");

	*chunkframes = d->samplesPerBlock / d->track->f.channelCount;

	ret.modspec = d;
	return ret;
}
예제 #15
0
/*
	Parse the stored sound chunk, which usually contains little more
	than the sound data.
*/
static status ParseSSND (AFfilehandle file, AFvirtualfile *fh, u_int32_t type,
	size_t size)
{
	_Track		*track;
	u_int32_t	offset, blockSize;

	assert(!memcmp(&type, "SSND", 4));

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	af_fread(&offset, sizeof (u_int32_t), 1, fh);
	offset = BENDIAN_TO_HOST_INT32(offset);
	af_fread(&blockSize, sizeof (u_int32_t), 1, fh);
	blockSize = BENDIAN_TO_HOST_INT32(blockSize);

	/*
		This seems like a reasonable way to calculate the number of
		bytes in an SSND chunk.
	*/
	track->data_size = size - 8 - offset;

#ifdef DEBUG
	printf("offset: %d\n", offset);
	printf("block size: %d\n", blockSize);
#endif

	track->fpos_first_frame = af_ftell(fh) + offset;

#ifdef DEBUG
	printf("data start: %d\n", track->fpos_first_frame);
#endif

	/* Sound data follows. */

	return AF_SUCCEED;
}
예제 #16
0
static status WriteCues (AFfilehandle file)
{
	int		i, *markids, markCount;
	uint32_t	numCues, cueChunkSize, listChunkSize;
	_WAVEInfo	*wave;

	assert(file);

	markCount = afGetMarkIDs(file, AF_DEFAULT_TRACK, NULL);
	if (markCount == 0)
		return AF_SUCCEED;

	wave = file->formatSpecific;

	if (wave->markOffset == 0)
		wave->markOffset = af_ftell(file->fh);
	else
		af_fseek(file->fh, wave->markOffset, SEEK_SET);

	af_fwrite("cue ", 4, 1, file->fh);

	/*
		The cue chunk consists of 4 bytes for the number of cue points
		followed by 24 bytes for each cue point record.
	*/
	cueChunkSize = 4 + markCount * 24;
	af_write_uint32_le(&cueChunkSize, file->fh);
	numCues = markCount;
	af_write_uint32_le(&numCues, file->fh);

	markids = _af_calloc(markCount, sizeof (int));
	assert(markids != NULL);
	afGetMarkIDs(file, AF_DEFAULT_TRACK, markids);

	/* Write each marker to the file. */
	for (i=0; i < markCount; i++)
	{
		uint32_t	identifier, position, chunkStart, blockStart;
		uint32_t	sampleOffset;
		AFframecount	markposition;

		identifier = markids[i];
		af_write_uint32_le(&identifier, file->fh);

		position = i;
		af_write_uint32_le(&position, file->fh);

		/* For now the RIFF id is always the first data chunk. */
		af_fwrite("data", 4, 1, file->fh);

		/*
			For an uncompressed WAVE file which contains
			only one data chunk, chunkStart and blockStart
			are zero.
		*/
		chunkStart = 0;
		af_fwrite(&chunkStart, sizeof (uint32_t), 1, file->fh);

		blockStart = 0;
		af_fwrite(&blockStart, sizeof (uint32_t), 1, file->fh);

		markposition = afGetMarkPosition(file, AF_DEFAULT_TRACK, markids[i]);

		/* Sample offsets are stored in the WAVE file as frames. */
		sampleOffset = markposition;
		af_write_uint32_le(&sampleOffset, file->fh);
	}

	/*
		Now write the cue names which is in a master list chunk
		with a subchunk for each cue's name.
	*/

	listChunkSize = 4;
	for (i=0; i<markCount; i++)
	{
		const char *name;

		name = afGetMarkName(file, AF_DEFAULT_TRACK, markids[i]);

		/*
			Each label chunk consists of 4 bytes for the
			"labl" chunk ID, 4 bytes for the chunk data
			size, 4 bytes for the cue point ID, and then
			the length of the label as a Pascal-style string.

			In all, this is 12 bytes plus the length of the
			string, its size byte, and a trailing pad byte
			if the length of the chunk is otherwise odd.
		*/
		listChunkSize += 12 + (strlen(name) + 1) +
			((strlen(name) + 1) % 2);
	}

	af_fwrite("LIST", 4, 1, file->fh);
	af_write_uint32_le(&listChunkSize, file->fh);
	af_fwrite("adtl", 4, 1, file->fh);

	for (i=0; i<markCount; i++)
	{
		const char	*name;
		uint32_t	labelSize, cuePointID;

		name = afGetMarkName(file, AF_DEFAULT_TRACK, markids[i]);

		/* Make labelSize even if it is not already. */
		labelSize = 4+(strlen(name)+1) + ((strlen(name) + 1) % 2);
		cuePointID = markids[i];

		af_fwrite("labl", 4, 1, file->fh);
		af_write_uint32_le(&labelSize, file->fh);
		af_write_uint32_le(&cuePointID, file->fh);
		af_fwrite(name, strlen(name) + 1, 1, file->fh);
		/*
			If the name plus the size byte comprises an odd
			length, add another byte to make the string an
			even length.
		*/
		if (((strlen(name) + 1) % 2) != 0)
		{
			uint8_t	zero=0;
			af_write_uint8(&zero, file->fh);
		}
	}

	free(markids);

	return AF_SUCCEED;
}
예제 #17
0
status WriteMiscellaneous (AFfilehandle filehandle)
{
	_WAVEInfo	*wave = (_WAVEInfo *) filehandle->formatSpecific;

	if (filehandle->miscellaneousCount != 0)
	{
		int		i;
		uint32_t	miscellaneousBytes;
		uint32_t 	chunkSize;

		/* Start at 12 to account for 'LIST', size, and 'INFO'. */
		miscellaneousBytes = 12;

		/* Then calculate the size of the whole INFO chunk. */
		for (i=0; i<filehandle->miscellaneousCount; i++)
		{
			uint32_t	miscid;

			/* Skip miscellaneous data of an unsupported type. */
			if (misc_type_to_wave(filehandle->miscellaneous[i].type,
				&miscid) == AF_FAIL)
				continue;

			/* Account for miscellaneous type and size. */
			miscellaneousBytes += 8;
			miscellaneousBytes += filehandle->miscellaneous[i].size;

			/* Add a pad byte if necessary. */
			if (filehandle->miscellaneous[i].size % 2 != 0)
				miscellaneousBytes++;

			assert(miscellaneousBytes % 2 == 0);
		}

		if (wave->miscellaneousStartOffset == 0)
			wave->miscellaneousStartOffset = af_ftell(filehandle->fh);
		else
			af_fseek(filehandle->fh, wave->miscellaneousStartOffset, SEEK_SET);

		wave->totalMiscellaneousSize = miscellaneousBytes;

		/*
			Write the data.  On the first call to this
			function (from _af_wave_write_init), the
			data won't be available, af_fseek is used to
			reserve space until the data has been provided.
			On subseuent calls to this function (from
			_af_wave_update), the data will really be written.
		*/

		/* Write 'LIST'. */
		af_fwrite("LIST", 4, 1, filehandle->fh);

		/* Write the size of the following chunk. */
		chunkSize = miscellaneousBytes-8;
		af_write_uint32_le(&chunkSize, filehandle->fh);

		/* Write 'INFO'. */
		af_fwrite("INFO", 4, 1, filehandle->fh);

		/* Write each miscellaneous chunk. */
		for (i=0; i<filehandle->miscellaneousCount; i++)
		{
			uint32_t	miscsize = filehandle->miscellaneous[i].size;
			uint32_t 	miscid = 0;

			/* Skip miscellaneous data of an unsupported type. */
			if (misc_type_to_wave(filehandle->miscellaneous[i].type,
				&miscid) == AF_FAIL)
				continue;

			af_fwrite(&miscid, 4, 1, filehandle->fh);
			af_write_uint32_le(&miscsize, filehandle->fh);
			if (filehandle->miscellaneous[i].buffer != NULL)
			{
				uint8_t	zero = 0;

				af_fwrite(filehandle->miscellaneous[i].buffer, filehandle->miscellaneous[i].size, 1, filehandle->fh);

				/* Pad if necessary. */
				if ((filehandle->miscellaneous[i].size%2) != 0)
					af_write_uint8(&zero, filehandle->fh);
			}
			else
			{
				int	size;
				size = filehandle->miscellaneous[i].size;

				/* Pad if necessary. */
				if ((size % 2) != 0)
					size++;
				af_fseek(filehandle->fh, size, SEEK_CUR);
			}
		}
	}

	return AF_SUCCEED;
}
예제 #18
0
static status WriteFormat (AFfilehandle file)
{
	_Track		*track = NULL;
	u_int16_t	formatTag, channelCount;
	u_int32_t	sampleRate, averageBytesPerSecond;
	u_int16_t	blockAlign;
	u_int32_t	chunkSize;
	u_int16_t	bitsPerSample;
	_WAVEInfo	*waveinfo = NULL;

	assert(file != NULL);

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);
	waveinfo = (_WAVEInfo *) file->formatSpecific;

	af_fwrite("fmt ", 4, 1, file->fh);

	switch (track->f.compressionType)
	{
		case AF_COMPRESSION_NONE:
			chunkSize = 16;
			formatTag = WAVE_FORMAT_PCM;
			blockAlign = _af_format_frame_size(&track->f, AF_FALSE);
			bitsPerSample = 8 * _af_format_sample_size(&track->f, AF_FALSE);
			break;
		case AF_COMPRESSION_G711_ULAW:
			chunkSize = 18;
			formatTag = IBM_FORMAT_MULAW;
			blockAlign = _af_format_frame_size(&track->f, AF_FALSE);
			bitsPerSample = 8 * _af_format_sample_size(&track->f, AF_FALSE);
			break;
		case AF_COMPRESSION_G711_ALAW:
			chunkSize = 18;
			formatTag = IBM_FORMAT_ALAW;
			blockAlign = _af_format_frame_size(&track->f, AF_FALSE);
			bitsPerSample = 8 * _af_format_sample_size(&track->f, AF_FALSE);
			break;
		default:
			_af_error(AF_BAD_COMPTYPE, "bad compression type");
			return AF_FAIL;
	}

	chunkSize = HOST_TO_LENDIAN_INT32(chunkSize);
	af_fwrite(&chunkSize, 4, 1, file->fh);

	formatTag = HOST_TO_LENDIAN_INT16(formatTag);
	af_fwrite(&formatTag, 2, 1, file->fh);
	formatTag = LENDIAN_TO_HOST_INT16(formatTag);

	channelCount = track->f.channelCount;
	channelCount = HOST_TO_LENDIAN_INT16(channelCount);
	af_fwrite(&channelCount, 2, 1, file->fh);

	sampleRate = track->f.sampleRate;
	sampleRate = HOST_TO_LENDIAN_INT32(sampleRate);
	af_fwrite(&sampleRate, 4, 1, file->fh);

	averageBytesPerSecond =
		track->f.sampleRate * _af_format_frame_size(&track->f, AF_FALSE);
	averageBytesPerSecond = HOST_TO_LENDIAN_INT32(averageBytesPerSecond);
	af_fwrite(&averageBytesPerSecond, 4, 1, file->fh);

	blockAlign = _af_format_frame_size(&track->f, AF_FALSE);
	blockAlign = HOST_TO_LENDIAN_INT16(blockAlign);
	af_fwrite(&blockAlign, 2, 1, file->fh);

	bitsPerSample = HOST_TO_LENDIAN_INT16(bitsPerSample);
	af_fwrite(&bitsPerSample, 2, 1, file->fh);

	/*
		If the data is compressed we have additional
		format-specific information to write as well as the
		'fact' (frame count) chunk.
	*/
	if (track->f.compressionType != AF_COMPRESSION_NONE)
	{
		u_int32_t	factSize = 4;
		u_int32_t	totalFrameCount = 0;

		if (track->f.compressionType == AF_COMPRESSION_G711_ULAW ||
			track->f.compressionType == AF_COMPRESSION_G711_ALAW)
		{
			u_int16_t	zero = 0;
			af_fwrite(&zero, 2, 1, file->fh);
		}

		af_fwrite("fact", 4, 1, file->fh);
		factSize = HOST_TO_LENDIAN_INT32(factSize);
		af_fwrite(&factSize, 4, 1, file->fh);

		waveinfo->fileSizeOffset = af_ftell(file->fh);

		totalFrameCount = HOST_TO_LENDIAN_INT32(totalFrameCount);
		af_fwrite(&totalFrameCount, 4, 1, file->fh);
	}

	return AF_SUCCEED;
}
예제 #19
0
파일: UniLogger.cpp 프로젝트: adri87/Q-A
static struct ExecutionLogging* BuildAllocInitExecutionLoggingForIncrementedNumber(void* privateLoggerPtr)
{
    struct ExecutionLogging* pEL = NULL;
 
    struct UniLoggerSpace * pULS=(struct UniLoggerSpace *)privateLoggerPtr;
    struct ActivityLoggerPrivateData* pALPD = (struct ActivityLoggerPrivateData*) pULS->privateUnloggerData;

    char szNumFileSuffix[256];


    if (pULS -> auto_increment_logfilename == 0)
    {
        return NULL;
    }
    /* we take a mutex, to be sure two thread don't increment and use same number at same time */
    SyncGetMutex(pALPD->pMutexLog);

    if (pULS->szNameLog == NULL) {


        unsigned int current_number = 0;
        const char* szNumFile = buildDupFileNameWithPrefixDir(pULS->szPathLog,"unitex_logging_parameters_count.txt");

        /* here : we will need protect with a mutex */
        ABSTRACTFILE *af_fin = af_fopen_unlogged(szNumFile,"rb");
        if (af_fin!=NULL)
        {
            size_t size_num_file=0;

            if (af_fseek(af_fin, 0, SEEK_END) == 0)
            {
	            size_num_file = af_ftell(af_fin);
                af_fseek(af_fin, 0, SEEK_SET);
            }

            char* buf_num_file=(char*)malloc(size_num_file+1);
            *(buf_num_file+size_num_file)=0;
            if (af_fread(buf_num_file,1,size_num_file,af_fin) == size_num_file)
            {
                sscanf(buf_num_file,"%u",&current_number);
            }
            af_fclose(af_fin);
            free(buf_num_file);        
        }

        current_number++;


        ABSTRACTFILE *af_fout = af_fopen_unlogged(szNumFile,"wb");
        if (af_fout!=NULL)
        {
            char szNumOut[32];
            sprintf(szNumOut,"%010u",current_number);
            af_fwrite(szNumOut,1,strlen(szNumOut),af_fout);
            af_fclose(af_fout);
        }
        free((void*)szNumFile);
        sprintf(szNumFileSuffix,"unitex_log_%08u.ulp",current_number);
    }
    else {
        sprintf(szNumFileSuffix,"%s",pULS->szNameLog);
    }
    SyncReleaseMutex(pALPD->pMutexLog);
    
    const char* szLogFileName = buildDupFileNameWithPrefixDir(pULS->szPathLog,szNumFileSuffix);

    pEL=BuildAllocInitExecutionLogging(privateLoggerPtr,szLogFileName);
    free((void*)szLogFileName);

    return pEL;
}
예제 #20
0
status _af_avr_write_init (AFfilesetup setup, AFfilehandle filehandle)
{
	_Track		*track;
	char		name[8];
	uint16_t	mono, resolution, sign, loop, midi;
	uint32_t	rate, size, loopStart, loopEnd;
	char		reserved[26];
	char		user[64];

	if (_af_filesetup_make_handle(setup, filehandle) == AF_FAIL)
		return AF_FAIL;

	filehandle->formatSpecific = NULL;

	track = _af_filehandle_get_track(filehandle, AF_DEFAULT_TRACK);

	if (af_fseek(filehandle->fh, 0, SEEK_SET) != 0)
	{
		_af_error(AF_BAD_LSEEK, "bad seek");
		return AF_FAIL;
	}

	af_fwrite("2BIT", 4, 1, filehandle->fh);
	memset(name, 0, 8);
	if (filehandle->fileName != NULL)
		strncpy(name, af_basename(filehandle->fileName), 8);
	af_fwrite(name, 8, 1, filehandle->fh);

	if (track->f.channelCount == 1)
		mono = 0x0;
	else
		mono = 0xffff;
	af_write_uint16_be(&mono, filehandle->fh);

	resolution = track->f.sampleWidth;
	af_write_uint16_be(&resolution, filehandle->fh);

	if (track->f.sampleFormat == AF_SAMPFMT_UNSIGNED)
		sign = 0x0;
	else
		sign = 0xffff;
	af_write_uint16_be(&sign, filehandle->fh);

	/* We do not currently support loops. */
	loop = 0;
	af_write_uint16_be(&loop, filehandle->fh);
	midi = 0xffff;
	af_write_uint16_be(&midi, filehandle->fh);

	rate = track->f.sampleRate;
	/* Set the high-order byte of rate to 0xff. */
	rate |= 0xff000000;
	size = track->totalfframes;
	loopStart = 0;
	loopEnd = size;

	af_write_uint32_be(&rate, filehandle->fh);
	af_write_uint32_be(&size, filehandle->fh);
	af_write_uint32_be(&loopStart, filehandle->fh);
	af_write_uint32_be(&loopEnd, filehandle->fh);

	memset(reserved, 0, 26);
	af_fwrite(reserved, 26, 1, filehandle->fh);

	memset(user, 0, 64);
	af_fwrite(user, 64, 1, filehandle->fh);

	if (track->fpos_first_frame == 0)
		track->fpos_first_frame = af_ftell(filehandle->fh);

	return AF_SUCCEED;
}