Ejemplo n.º 1
0
/*
	Parse voice header chunk.
*/
static status ParseVHDR (AFfilehandle file, AFvirtualfile *fh, u_int32_t type,
                         size_t size)
{
    _Track		*track;
    u_int32_t	oneShotSamples, repeatSamples, samplesPerRepeat;
    u_int16_t	sampleRate;
    u_int8_t	octaves, compression;
    u_int32_t	volume;

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

    track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

    af_read_uint32_be(&oneShotSamples, fh);
    af_read_uint32_be(&repeatSamples, fh);
    af_read_uint32_be(&samplesPerRepeat, fh);
    af_read_uint16_be(&sampleRate, fh);
    af_fread(&octaves, 1, 1, fh);
    af_fread(&compression, 1, 1, fh);
    af_read_uint32_be(&volume, fh);

    track->f.sampleWidth = 8;
    track->f.sampleRate = sampleRate;
    track->f.sampleFormat = AF_SAMPFMT_TWOSCOMP;
    track->f.compressionType = AF_COMPRESSION_NONE;
    track->f.byteOrder = AF_BYTEORDER_BIGENDIAN;
    track->f.channelCount = 1;

    _af_set_sample_format(&track->f, track->f.sampleFormat, track->f.sampleWidth);

    return AF_SUCCEED;
}
Ejemplo n.º 2
0
/*
	Parse marker chunks, which contain the positions and names of loop markers.
*/
static status ParseMARK (AFfilehandle file, AFvirtualfile *fh, u_int32_t type,
	size_t size)
{
	_Track		*track;
	int		i;
	u_int16_t	numMarkers;

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

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	af_fread(&numMarkers, sizeof (u_int16_t), 1, fh);
	numMarkers = BENDIAN_TO_HOST_INT16(numMarkers);

	track->markerCount = numMarkers;
	if (numMarkers)
		track->markers = _af_marker_new(numMarkers);

	for (i=0; i<numMarkers; i++)
	{
		u_int16_t	markerID = 0;
		u_int32_t	markerPosition = 0;
		u_int8_t	sizeByte = 0;
		char		*markerName = NULL;

		af_fread(&markerID, sizeof (u_int16_t), 1, fh);
		markerID = BENDIAN_TO_HOST_INT16(markerID);
		af_fread(&markerPosition, sizeof (u_int32_t), 1, fh);
		markerPosition = BENDIAN_TO_HOST_INT32(markerPosition);
		af_fread(&sizeByte, sizeof (unsigned char), 1, fh);
		markerName = _af_malloc(sizeByte + 1);
		af_fread(markerName, sizeof (unsigned char), sizeByte, fh);

		markerName[sizeByte] = '\0';

#ifdef DEBUG
		printf("marker id: %d, position: %d, name: %s\n",
			markerID, markerPosition, markerName);

		printf("size byte: %d\n", sizeByte);
#endif

		/*
			If sizeByte is even, then 1+sizeByte (the length
			of the string) is odd.	Skip an extra byte to
			make it even.
		*/

		if ((sizeByte % 2) == 0)
			af_fseek(fh, 1, SEEK_CUR);

		track->markers[i].id = markerID;
		track->markers[i].position = markerPosition;
		track->markers[i].name = markerName;
		track->markers[i].comment = _af_strdup("");
	}

	return AF_SUCCEED;
}
Ejemplo n.º 3
0
bool _af_iff_recognize (AFvirtualfile *fh)
{
    u_int8_t	buffer[8];

    af_fseek(fh, 0, SEEK_SET);

    if (af_fread(buffer, 1, 8, fh) != 8 || memcmp(buffer, "FORM", 4) != 0)
        return AF_FALSE;
    if (af_fread(buffer, 1, 4, fh) != 4 || memcmp(buffer, "8SVX", 4) != 0)
        return AF_FALSE;

    return AF_TRUE;
}
Ejemplo n.º 4
0
bool _af_iff_recognize (AFvirtualfile *fh)
{
	uint8_t	buffer[8];

	af_fseek(fh, 0, SEEK_SET);

	if (af_fread(buffer, 1, 8, fh) != 8 || memcmp(buffer, "FORM", 4) != 0)
		return false;
	if (af_fread(buffer, 1, 4, fh) != 4 || memcmp(buffer, "8SVX", 4) != 0)
		return false;

	return true;
}
Ejemplo n.º 5
0
/*
	Parse miscellaneous data chunks such as name, author, copyright,
	and annotation chunks.
*/
static status ParseMiscellaneous (AFfilehandle file, AFvirtualfile *fh,
	uint32_t type, size_t size)
{
	int	misctype = AF_MISC_UNRECOGNIZED;

	assert(!memcmp(&type, "NAME", 4) || !memcmp(&type, "AUTH", 4) ||
		!memcmp(&type, "(c) ", 4) || !memcmp(&type, "ANNO", 4));

	/* Skip zero-length miscellaneous chunks. */
	if (size == 0)
		return AF_FAIL;

	file->miscellaneousCount++;
	file->miscellaneous = _af_realloc(file->miscellaneous,
		file->miscellaneousCount * sizeof (_Miscellaneous));

	if (!memcmp(&type, "NAME", 4))
		misctype = AF_MISC_NAME;
	else if (!memcmp(&type, "AUTH", 4))
		misctype = AF_MISC_AUTH;
	else if (!memcmp(&type, "(c) ", 4))
		misctype = AF_MISC_COPY;
	else if (!memcmp(&type, "ANNO", 4))
		misctype = AF_MISC_ANNO;

	file->miscellaneous[file->miscellaneousCount - 1].id = file->miscellaneousCount;
	file->miscellaneous[file->miscellaneousCount - 1].type = misctype;
	file->miscellaneous[file->miscellaneousCount - 1].size = size;
	file->miscellaneous[file->miscellaneousCount - 1].position = 0;
	file->miscellaneous[file->miscellaneousCount - 1].buffer = _af_malloc(size);
	af_fread(file->miscellaneous[file->miscellaneousCount - 1].buffer,
		size, 1, file->fh);

	return AF_SUCCEED;
}
Ejemplo n.º 6
0
int ComputeFileCrc(const char* filename,unsigned int*size_done,unsigned long*crc)
{
    size_t size_buf=0x10000;
    char*buf;
    int ret=1;

    if (size_done != NULL)
        *size_done =0;

    if (crc != NULL)
        *crc=0;

    if (filename==NULL)
        return 0;
    if ((*filename)==0)
        return 0;

    buf = (char*)malloc(size_buf);
    ABSTRACTFILE*fin;
    int err;
    size_t size_read;

    fin = af_fopen_unlogged(filename,"rb");
    if (fin==NULL)
    {
        err=ZIP_ERRNO;
        
        free(buf);
        return 0;
    }

    if ((crc != NULL) || (size_done != NULL))
    {
        do
        {
            size_read = af_fread(buf,1,size_buf,fin);
            if (size_read < size_buf)
                if (af_feof(fin)==0)
            {
                /*
                printf("error in reading %s\n",filenameinzip);
                */
                ret = 0;
            }

            if (size_read>0)
            {
                if (size_done != NULL)
                    *size_done += (unsigned int)size_read;
                if (crc != NULL)
                    *crc = crc32(*crc,buf,size_read);
            }
        } while ((size_read>0));
    }

    af_fclose_unlogged(fin);
    free(buf);
    return ret;
}
Ejemplo n.º 7
0
status af_read_pstring (char s[256], AFvirtualfile *vf)
{
	uint8_t length;
	/* Read the Pascal-style string containing the name. */
	af_read_uint8(&length, vf);
	af_fread(s, length, 1, vf);
	s[length] = '\0';
	return AF_SUCCEED;
}
Ejemplo n.º 8
0
status af_read_uint16_le (uint16_t *value, AFvirtualfile *vf)
{
	uint16_t	v;

	if (af_fread(&v, sizeof (v), 1, vf) != 1)
		return AF_FAIL;
	*value = LENDIAN_TO_HOST_INT16(v);
	return AF_SUCCEED;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
/*
	FVER chunks are only present in AIFF-C files.
*/
static status ParseFVER (AFfilehandle file, AFvirtualfile *fh, u_int32_t type, size_t size)
{
	u_int32_t	timestamp;

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

	af_fread(&timestamp, sizeof (u_int32_t), 1, fh);
	timestamp = BENDIAN_TO_HOST_INT32(timestamp);
	/* timestamp holds the number of seconds since January 1, 1904. */

	return AF_SUCCEED;
}
Ejemplo n.º 11
0
uLong ZCALLBACK afread_file_func (
   voidpf opaque,
   voidpf stream,
   void* buf,
   uLong size)
{
    uLong ret;

    (void)opaque;

    ret = (uLong)af_fread(buf, 1, (size_t)size, (ABSTRACTFILE *)stream);
    return ret;
}
Ejemplo n.º 12
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;
}
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);        
    }
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
/*
	Parse AES recording data.
*/
static status ParseAESD (AFfilehandle file, AFvirtualfile *fh, u_int32_t type, size_t size)
{
	_Track		*track;
	unsigned char	aesChannelStatusData[24];

	assert(!memcmp(&type, "AESD", 4));
	assert(size == 24);

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	track->hasAESData = AF_TRUE;

	/*
		Try to read 24 bytes of AES nonaudio data from the file.
		Fail if the file disappoints.
	*/
	if (af_fread(aesChannelStatusData, 1, 24, fh) != 24)
		return AF_FAIL;

	memcpy(track->aesData, aesChannelStatusData, 24);

	return AF_SUCCEED;
}
Ejemplo n.º 16
0
status _af_aiff_read_init (AFfilesetup setup, AFfilehandle file)
{
	u_int32_t	type, size, formtype;
	size_t		index = 0;
	bool		hasCOMM, hasFVER, hasSSND, hasMARK, hasINST;
	bool		hasAESD, hasNAME, hasAUTH, hasCOPY;
	_Track		*track;

	hasCOMM = AF_FALSE;
	hasFVER = AF_FALSE;
	hasSSND = AF_FALSE;
	hasMARK = AF_FALSE;
	hasINST = AF_FALSE;
	hasAESD = AF_FALSE;
	hasNAME = AF_FALSE;
	hasAUTH = AF_FALSE;
	hasCOPY = AF_FALSE;

	assert(file != NULL);
	assert(file->fh != NULL);

	af_fseek(file->fh, 0, SEEK_SET);

	af_fread(&type, 4, 1, file->fh);
	af_fread(&size, 4, 1, file->fh);
	size = BENDIAN_TO_HOST_INT32(size);
	af_fread(&formtype, 4, 1, file->fh);

	if (memcmp(&type, "FORM", 4) != 0 ||
		(memcmp(&formtype, "AIFF", 4) && memcmp(&formtype, "AIFC", 4)))
		return AF_FAIL;

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

	file->instrumentCount = 0;
	file->instruments = NULL;
	file->miscellaneousCount = 0;
	file->miscellaneous = NULL;

	/* AIFF files have only one track. */
	track = _af_track_new();
	file->trackCount = 1;
	file->tracks = track;

	/* Include the offset of the form type. */
	index += 4;

	while (index < size)
	{
		u_int32_t	chunkid = 0, chunksize = 0;
		status		result = AF_SUCCEED;

#ifdef DEBUG
		printf("index: %d\n", index);
#endif
		af_fread(&chunkid, 4, 1, file->fh);
		af_fread(&chunksize, 4, 1, file->fh);
		chunksize = BENDIAN_TO_HOST_INT32(chunksize);

#ifdef DEBUG
		_af_printid(chunkid);
		printf(" size: %d\n", chunksize);
#endif

		if (!memcmp("COMM", &chunkid, 4))
		{
			hasCOMM = AF_TRUE;
			result = ParseCOMM(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("FVER", &chunkid, 4))
		{
			hasFVER = AF_TRUE;
			ParseFVER(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("INST", &chunkid, 4))
		{
			hasINST = AF_TRUE;
			ParseINST(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("MARK", &chunkid, 4))
		{
			hasMARK = AF_TRUE;
			ParseMARK(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("AESD", &chunkid, 4))
		{
			hasAESD = AF_TRUE;
			ParseAESD(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("NAME", &chunkid, 4) ||
			!memcmp("AUTH", &chunkid, 4) ||
			!memcmp("(c) ", &chunkid, 4) ||
			!memcmp("ANNO", &chunkid, 4) ||
			!memcmp("APPL", &chunkid, 4) ||
			!memcmp("MIDI", &chunkid, 4))
		{
			ParseMiscellaneous(file, file->fh, chunkid, chunksize);
		}
		/*
			The sound data chunk is required if there are more than
			zero sample frames.
		*/
		else if (!memcmp("SSND", &chunkid, 4))
		{
			if (hasSSND)
			{
				_af_error(AF_BAD_AIFF_SSND, "AIFF file has more than one SSND chunk");
				return AF_FAIL;
			}
			hasSSND = AF_TRUE;
			result = ParseSSND(file, file->fh, chunkid, chunksize);
		}

		if (result == AF_FAIL)
			return AF_FAIL;

		index += chunksize + 8;

		/* all chunks must be aligned on an even number of bytes */
		if ((index % 2) != 0)
			index++;

		af_fseek(file->fh, index + 8, SEEK_SET);
	}

	if (!hasCOMM)
	{
		_af_error(AF_BAD_AIFF_COMM, "bad AIFF COMM chunk");
	}

	/* The file has been successfully parsed. */
	return AF_SUCCEED;
}
Ejemplo n.º 17
0
status af_read_uint8 (uint8_t *value, AFvirtualfile *vf)
{
	if (af_fread(value, 1, 1, vf) != 1)
		return AF_FAIL;
	return AF_SUCCEED;
}
Ejemplo n.º 18
0
status _af_iff_read_init (AFfilesetup setup, AFfilehandle file)
{
	uint32_t	type, size, formtype;
	size_t		index;
	_Track		*track;

	assert(file != NULL);
	assert(file->fh != NULL);

	af_fseek(file->fh, 0, SEEK_SET);

	af_fread(&type, 4, 1, file->fh);
	af_read_uint32_be(&size, file->fh);
	af_fread(&formtype, 4, 1, file->fh);

	if (memcmp(&type, "FORM", 4) != 0 || memcmp(&formtype, "8SVX", 4) != 0)
		return AF_FAIL;

	file->instrumentCount = 0;
	file->instruments = NULL;
	file->miscellaneousCount = 0;
	file->miscellaneous = NULL;

	/* IFF/8SVX files have only one track. */
	track = _af_track_new();
	file->trackCount = 1;
	file->tracks = track;

	/* Set the index to include the form type ('8SVX' in this case). */
	index = 4;

	while (index < size)
	{
		uint32_t	chunkid = 0, chunksize = 0;
		status		result = AF_SUCCEED;

		af_fread(&chunkid, 4, 1, file->fh);
		af_read_uint32_be(&chunksize, file->fh);

		if (!memcmp("VHDR", &chunkid, 4))
		{
			result = ParseVHDR(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("BODY", &chunkid, 4))
		{
			result = ParseBODY(file, file->fh, chunkid, chunksize);
		}
		else if (!memcmp("NAME", &chunkid, 4) ||
			!memcmp("AUTH", &chunkid, 4) ||
			!memcmp("(c) ", &chunkid, 4) ||
			!memcmp("ANNO", &chunkid, 4))
		{
			ParseMiscellaneous(file, file->fh, chunkid, chunksize);
		}

		if (result == AF_FAIL)
			return AF_FAIL;

		/*
			Increment the index by the size of the chunk
			plus the size of the chunk header.
		*/
		index += chunksize + 8;

		/* All chunks must be aligned on an even number of bytes. */
		if ((index % 2) != 0)
			index++;

		/* Set the seek position to the beginning of the next chunk. */
		af_fseek(file->fh, index + 8, SEEK_SET);
	}

	/* The file has been successfully parsed. */
	return AF_SUCCEED;
}
Ejemplo n.º 19
0
/*
	Parse instrument chunks, which contain information about using
	sound data as a sampled instrument.
*/
static status ParseINST (AFfilehandle file, AFvirtualfile *fh, u_int32_t type,
	size_t size)
{
	_Instrument	*instrument;
	u_int8_t	baseNote;
	int8_t		detune;
	u_int8_t	lowNote, highNote, lowVelocity, highVelocity;
	int16_t		gain;

	u_int16_t	sustainLoopPlayMode, sustainLoopBegin, sustainLoopEnd;
	u_int16_t	releaseLoopPlayMode, releaseLoopBegin, releaseLoopEnd;

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

	instrument = _af_calloc(1, sizeof (_Instrument));
	instrument->id = AF_DEFAULT_INST;
	instrument->values = _af_calloc(_AF_AIFF_NUM_INSTPARAMS, sizeof (AFPVu));
	instrument->loopCount = 2;
	instrument->loops = _af_calloc(2, sizeof (_Loop));

	file->instrumentCount = 1;
	file->instruments = instrument;

	af_fread(&baseNote, 1, 1, fh);
	af_fread(&detune, 1, 1, fh);
	af_fread(&lowNote, 1, 1, fh);
	af_fread(&highNote, 1, 1, fh);
	af_fread(&lowVelocity, 1, 1, fh);
	af_fread(&highVelocity, 1, 1, fh);
	af_fread(&gain, 2, 1, fh);
	gain = BENDIAN_TO_HOST_INT16(gain);

#ifdef DEBUG
	printf("baseNote/detune/lowNote/highNote/lowVelocity/highVelocity/gain:"
		" %d %d %d %d %d %d %d\n",
		baseNote, detune, lowNote, highNote, lowVelocity, highVelocity,
		gain);
#endif

	instrument->values[0].l = baseNote;
	instrument->values[1].l = detune;
	instrument->values[2].l = lowVelocity;
	instrument->values[3].l = highVelocity;
	instrument->values[4].l = lowNote;
	instrument->values[5].l = highNote;
	instrument->values[6].l = gain;

	instrument->values[7].l = 1;	/* sustain loop id */
	instrument->values[8].l = 2;	/* release loop id */

	af_fread(&sustainLoopPlayMode, sizeof (u_int16_t), 1, fh);
	sustainLoopPlayMode = BENDIAN_TO_HOST_INT16(sustainLoopPlayMode);
	af_fread(&sustainLoopBegin, sizeof (u_int16_t), 1, fh);
	sustainLoopBegin = BENDIAN_TO_HOST_INT16(sustainLoopBegin);
	af_fread(&sustainLoopEnd, sizeof (u_int16_t), 1, fh);
	sustainLoopEnd = BENDIAN_TO_HOST_INT16(sustainLoopEnd);

	af_fread(&releaseLoopPlayMode, sizeof (u_int16_t), 1, fh);
	releaseLoopPlayMode = BENDIAN_TO_HOST_INT16(releaseLoopPlayMode);
	af_fread(&releaseLoopBegin, sizeof (u_int16_t), 1, fh);
	releaseLoopBegin = BENDIAN_TO_HOST_INT16(releaseLoopBegin);
	af_fread(&releaseLoopEnd, sizeof (u_int16_t), 1, fh);
	releaseLoopEnd = BENDIAN_TO_HOST_INT16(releaseLoopEnd);

#ifdef DEBUG
	printf("sustain loop: mode %d, begin %d, end %d\n",
		sustainLoopPlayMode, sustainLoopBegin, sustainLoopEnd);

	printf("release loop: mode %d, begin %d, end %d\n",
		releaseLoopPlayMode, releaseLoopBegin, releaseLoopEnd);
#endif

	instrument->loops[0].id = 1;
	instrument->loops[0].mode = sustainLoopPlayMode;
	instrument->loops[0].beginMarker = sustainLoopBegin;
	instrument->loops[0].endMarker = sustainLoopEnd;

	instrument->loops[1].id = 2;
	instrument->loops[1].mode = releaseLoopPlayMode;
	instrument->loops[1].beginMarker = releaseLoopBegin;
	instrument->loops[1].endMarker = releaseLoopEnd;

	return AF_SUCCEED;
}
Ejemplo n.º 20
0
/*
	Parse common data chunks, which contain information regarding the
	sampling rate, the number of sample frames, and the number of
	sound channels.
*/
static status ParseCOMM (AFfilehandle file, AFvirtualfile *fh, u_int32_t type,
	size_t size)
{
	_Track		*track;
	u_int16_t	numChannels;
	u_int32_t	numSampleFrames;
	u_int16_t	sampleSize;
	unsigned char	sampleRate[10];

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

	track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK);

	af_fread(&numChannels, sizeof (u_int16_t), 1, fh);
	track->f.channelCount = BENDIAN_TO_HOST_INT16(numChannels);

	af_fread(&numSampleFrames, sizeof (u_int32_t), 1, fh);
	track->totalfframes = BENDIAN_TO_HOST_INT32(numSampleFrames);

	af_fread(&sampleSize, sizeof (u_int16_t), 1, fh);
	track->f.sampleWidth = BENDIAN_TO_HOST_INT16(sampleSize);

	af_fread(sampleRate, 10, 1, fh);
	track->f.sampleRate = _af_convert_from_ieee_extended(sampleRate);

	track->f.compressionType = AF_COMPRESSION_NONE;
	track->f.sampleFormat = AF_SAMPFMT_TWOSCOMP;
	track->f.byteOrder = AF_BYTEORDER_BIGENDIAN;

	if (file->fileFormat == AF_FILE_AIFFC)
	{
		u_int8_t	compressionID[4];
		/* Pascal strings are at most 255 bytes long. */
		unsigned char	compressionName[256];
		unsigned char	compressionNameLength;

		af_fread(compressionID, 4, 1, fh);

		/* Read the Pascal-style string containing the name. */
		af_fread(&compressionNameLength, 1, 1, fh);
		af_fread(compressionName, compressionNameLength, 1, fh);
		compressionName[compressionNameLength] = '\0';

		if (!memcmp(compressionID, "NONE", 4))
			track->f.compressionType = AF_COMPRESSION_NONE;
		else if (!memcmp(compressionID, "ACE2", 4) ||
			!memcmp(compressionID, "ACE8", 4) ||
			!memcmp(compressionID, "MAC3", 4) ||
			!memcmp(compressionID, "MAC6", 4))
		{
			_af_error(AF_BAD_NOT_IMPLEMENTED, "AIFF-C format does not support Apple's proprietary %s compression format", compressionName);
			return AF_FAIL;
		}
		else if (!memcmp(compressionID, "ulaw", 4) ||
			!memcmp(compressionID, "ULAW", 4))
		{
			track->f.compressionType = AF_COMPRESSION_G711_ULAW;
		}
		else if (!memcmp(compressionID, "alaw", 4) ||
			!memcmp(compressionID, "ALAW", 4))
		{
			track->f.compressionType = AF_COMPRESSION_G711_ALAW;
		}
		else if (!memcmp(compressionID, "fl32", 4) ||
			!memcmp(compressionID, "FL32", 4))
		{
			track->f.sampleFormat = AF_SAMPFMT_FLOAT;
			track->f.sampleWidth = 32;
			track->f.compressionType = AF_COMPRESSION_NONE;
		}
		else if (!memcmp(compressionID, "fl64", 4) ||
			!memcmp(compressionID, "FL64", 4))
		{
			track->f.sampleFormat = AF_SAMPFMT_DOUBLE;
			track->f.sampleWidth = 64;
			track->f.compressionType = AF_COMPRESSION_NONE;
		}
		else if (!memcmp(compressionID, "sowt", 4))
		{
			track->f.compressionType = AF_COMPRESSION_NONE;
			track->f.byteOrder = AF_BYTEORDER_LITTLEENDIAN;
		}
		else
		{
			_af_error(AF_BAD_NOT_IMPLEMENTED, "AIFF-C compression type '%c%c%c%c' not currently supported",
				compressionID[0],
				compressionID[1],
				compressionID[2],
				compressionID[3]);
			return AF_FAIL;
		}
	}

	_af_set_sample_format(&track->f, track->f.sampleFormat, track->f.sampleWidth);

	return AF_SUCCEED;
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
0
int DumpFileToPack(struct ExecutionLogging* pEL,const char* filename,const char* prefix,unsigned int*size_done,unsigned long*crc)
{
    char* name_to_store;
    size_t size_buf=0x10000;
    char*buf;
    *size_done =0;
    *crc=0;

    if (filename==NULL)
        return 0;
    if ((*filename)==0)
        return 0;

    buf = (char*)malloc(size_buf+ strlen(filename)+ ((prefix == NULL) ? 0 : strlen(prefix))+0x10);
    name_to_store = buf +size_buf;

    if (prefix != NULL)
        strcpy(name_to_store,prefix);
    else
        *name_to_store=0;

    const char* filenamecpy=GetFileNameRemovePrefixIfFound(filename,pEL->portion_ignore_pathname);

    filenamecpy = ExtractUsablePortionOfFileNameForPack(filenamecpy);

    strcat(name_to_store,filenamecpy);

    char* name_to_store_browse=name_to_store;
    while ((*name_to_store_browse)!=0)
    {
        if ((*name_to_store_browse)=='\\')
            (*name_to_store_browse)='/';
        name_to_store_browse++;
    }

    zip_fileinfo zi;

    zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
    zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
    zi.dosDate = 0;
    zi.internal_fa = 0;
    zi.external_fa = 0;

    zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
    zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = 9;
    zi.tmz_date.tm_year = 2009;
    zi.tmz_date.tm_mon--;

    ABSTRACTFILE*fin;
    int err;

    fin = af_fopen_unlogged(filename,"rb");
    if (fin==NULL)
    {
        err=ZIP_ERRNO;
        
        free(buf);
        return 0;
    }

    err = zipOpenNewFileInZip(pEL->zf,name_to_store,&zi,NULL,0,NULL,0,NULL /* param_list */,
                                 0,0);

    if (err==0)
    {
        size_t size_read;
        if (err == ZIP_OK)
            do
            {
                err = ZIP_OK;
                size_read = af_fread(buf,1,size_buf,fin);
                if (size_read < size_buf)
                    if (af_feof(fin)==0)
                {
                    /*
                    printf("error in reading %s\n",filenameinzip);
                    */
                    err = ZIP_ERRNO;
                }

                if (size_read>0)
                {
                    err = zipWriteInFileInZip (pEL->zf,buf,(unsigned int)size_read);
                    if (err<0)
                    {
                        /*
                        printf("error in writing %s in the zipfile\n",
                                         filenameinzip);*/
                    }
                    else 
                    {
                        *size_done += (unsigned int)size_read;
                        *crc = crc32(*crc,buf,size_read);
                    }

                }
            } while ((err == ZIP_OK) && (size_read>0));



            if (err<0)
            {
                err=ZIP_ERRNO;
                zipCloseFileInZip(pEL->zf);
            }
            else
            {
                err = zipCloseFileInZip(pEL->zf);
                /*
                if (err!=ZIP_OK)
                    printf("error in closing %s in the zipfile\n",
                                filenameinzip);
                                */
            }
    }
    af_fclose_unlogged(fin);
    free(buf);
    return 1;
}