示例#1
0
static void byteswap( ARParam *param )
{
    ARParam  wparam;
    int      i, j;

    byteSwapInt( &(param->xsize), &(wparam.xsize) );
    byteSwapInt( &(param->ysize), &(wparam.ysize) );

    for( j = 0; j < 3; j++ ) {
        for( i = 0; i < 4; i++ ) {
            byteSwapDouble( &(param->mat[j][i]), &(wparam.mat[j][i]) );
        }
    }

    for( i = 0; i < 4; i++ ) {
        byteSwapDouble( &(param->dist_factor[i]), &(wparam.dist_factor[i]) );
    }

    *param = wparam;
}
/* Put an int into the byte buffer */
int BbPutInt(PBYTE_BUFFER buff, int i) {
	if (buff->position + sizeof(i) > buff->length) {
		return 0;
	}

	i = byteSwapInt(buff, i);

	memcpy(&buff->buffer[buff->position], &i, sizeof(i));
	buff->position += sizeof(i);

	return 1;
}
/* Get an int from the byte buffer */
int BbGetInt(PBYTE_BUFFER buff, int *i) {
	if (buff->position + sizeof(*i) > buff->length) {
		return 0;
	}

	memcpy(i, &buff->buffer[buff->position], sizeof(*i));
	buff->position += sizeof(*i);

	*i = byteSwapInt(buff, *i);

	return 1;
}
示例#4
0
static void byteswap2( ARSParam *sparam )
{
    ARSParam wsparam;
    int      i, j;

    byteSwapInt( &(sparam->xsize), &(wsparam.xsize) );
    byteSwapInt( &(sparam->ysize), &(wsparam.ysize) );

    for( j = 0; j < 3; j++ ) {
        for( i = 0; i < 4; i++ ) {
            byteSwapDouble( &(sparam->matL[j][i]),   &(wsparam.matL[j][i]) );
            byteSwapDouble( &(sparam->matR[j][i]),   &(wsparam.matR[j][i]) );
            byteSwapDouble( &(sparam->matL2R[j][i]), &(wsparam.matL2R[j][i]) );
        } 
    }
    for( i = 0; i < 4; i++ ) {
        byteSwapDouble( &(sparam->dist_factorL[i]), &(wsparam.dist_factorL[i]) );
        byteSwapDouble( &(sparam->dist_factorR[i]), &(wsparam.dist_factorR[i]) );
    }

    *sparam = wsparam;
}
示例#5
0
int MIDIFile::initMIDIFile(const char* _fileName)
{
	m_pFileBuf = loadFile(_fileName, m_fileSize);
	if (!m_pFileBuf)
	{
		printf("something went wrong during file load.\n");
		return 1;
	}

	//1: process header
	m_pHeader = (MIDIHeaderInfo*)m_pFileBuf;
	int numTracks = byteSwapShort(m_pHeader->tracks);
	m_PulsesPerQuarterNote = byteSwapShort(m_pHeader->ticks);

	//2: process body
	unsigned char* pBody = m_pFileBuf += sizeof(MIDIHeaderInfo);
	auto pCurrentTrack = (char*) pBody;
	auto pCurrentTrackInfo = (MIDITrackInfo*)pCurrentTrack;
	for (int i = 0; i < numTracks; i++)
	{
		if (pCurrentTrackInfo->id != 0x6b72544d)//magic number: 0xkrTM  -> big endian MTrk
		{
			printf("Fatal Error: MTrk identifier not found when parsing file: %s\n", _fileName);
			return 1;
		}

		MIDITrack currentTrack;
		currentTrack.m_pTrackInfo = pCurrentTrackInfo;
		currentTrack.m_pBuffer = (unsigned char*)pCurrentTrack + sizeof(MIDITrackInfo);
		currentTrack.m_absTime = 0;
		currentTrack.m_lastEvent = 0;
		m_tracks.push_back(currentTrack);
		
		//increment pCurrentTrack to point to the next track
		pCurrentTrack += sizeof(MIDITrackInfo) + byteSwapInt(m_tracks[i].m_pTrackInfo->length);
	}
	return 0;
}