Esempio n. 1
0
static void load_sample_info(int size, SFInfo *sf, FILE *fd)
{
	int i;
	int in_rom;

	/* the record size depends on the soundfont version */
	if (sf->version > 1) {
		/* SF2 includes sample name and other infos */
		sf->nsamples = size / 46;
		sf->sample = NEW(SFSampleInfo, sf->nsamples);
	} else  {
		/* SBK; sample name may be read already */
		int nsamples = size / 16;
		if (sf->sample == NULL) {
			sf->nsamples = nsamples;
			sf->sample = NEW(SFSampleInfo, sf->nsamples);
		} else if (sf->nsamples != nsamples) {
#if 0
			fprintf(stderr, "*** different # of infos ?? (%d : %d)\n",
			       sf->nsamples, nsamples);
			FSKIP(size, fd);
			return;
#endif
			/* overwrite it */
			sf->nsamples = nsamples;
		}
	}

	in_rom = 1;  /* data may start from ROM samples */
	for (i = 0; i < sf->nsamples; i++) {
		if (sf->version > 1) /* SF2 only */
			READSTR(sf->sample[i].name, fd);
		READDW(sf->sample[i].startsample, fd);
		READDW(sf->sample[i].endsample, fd);
		READDW(sf->sample[i].startloop, fd);
		READDW(sf->sample[i].endloop, fd);
		if (sf->version > 1) { /* SF2 only */
			READDW(sf->sample[i].samplerate, fd);
			READB(sf->sample[i].originalPitch, fd);
			READB(sf->sample[i].pitchCorrection, fd);
			READW(sf->sample[i].samplelink, fd);
			READW(sf->sample[i].sampletype, fd);
		} else { /* for SBK; set missing infos */
			sf->sample[i].samplerate = 44100;
			sf->sample[i].originalPitch = 60;
			sf->sample[i].pitchCorrection = 0;
			sf->sample[i].samplelink = 0;
			/* the first RAM data starts from address 0 */
			if (sf->sample[i].startsample == 0)
				in_rom = 0;
			if (in_rom)
				sf->sample[i].sampletype = 0x8001;
			else
				sf->sample[i].sampletype = 1;
		}
	}
}
Esempio n. 2
0
void Instruments::load_sample_info(int size, SFInfo *sf, struct timidity_file *fd)
{
	int i;
	int in_rom;

	/* the record size depends on the soundfont version */
	if (sf->version > 1) {
		/* SF2 includes sample name and other infos */
		sf->nsamples = size / 46;
		sf->sample = NEW(SFSampleInfo, sf->nsamples);
	}
	else {
		/* SBK; sample name may be read already */
		int nsamples = size / 16;
		if (sf->sample == NULL) {
			sf->nsamples = nsamples;
			sf->sample = NEW(SFSampleInfo, sf->nsamples);
		}
		else if (sf->nsamples != nsamples) {
			/* overwrite it */
			sf->nsamples = nsamples;
		}
	}

	in_rom = 1;  /* data may start from ROM samples */
	for (i = 0; i < sf->nsamples; i++) {
		if (sf->version > 1) /* SF2 only */
			READSTR(sf->sample[i].name, fd);
		READDW((uint32_t *)&sf->sample[i].startsample, fd);
		READDW((uint32_t *)&sf->sample[i].endsample, fd);
		READDW((uint32_t *)&sf->sample[i].startloop, fd);
		READDW((uint32_t *)&sf->sample[i].endloop, fd);
		if (sf->version > 1) { /* SF2 only */
			READDW((uint32_t *)&sf->sample[i].samplerate, fd);
			READB(sf->sample[i].originalPitch, fd);
			READB(sf->sample[i].pitchCorrection, fd);
			READW(&sf->sample[i].samplelink, fd);
			READW(&sf->sample[i].sampletype, fd);
		}
		else { /* for SBK; set missing infos */
			sf->sample[i].samplerate = 44100;
			sf->sample[i].originalPitch = 60;
			sf->sample[i].pitchCorrection = 0;
			sf->sample[i].samplelink = 0;
			/* the first RAM data starts from address 0 */
			if (sf->sample[i].startsample == 0)
				in_rom = 0;
			if (in_rom)
				sf->sample[i].sampletype = 0x8001;
			else
				sf->sample[i].sampletype = 1;
		}
	}
}
Esempio n. 3
0
int CRlePack::LoadFile( const char* a_pcFilename, int a_iNumColors )
{
	FILE* f;
	
	f = fopen( a_pcFilename, "rb" );
	if (f==NULL)
	{
		debug( "Can't open file '%s'.\n", a_pcFilename );
		return -1;
	}
	
	fseek( f, 0, SEEK_END );
	long iFileSize = ftell ( f );
	p->m_pData = malloc( iFileSize );
	if ( NULL == p->m_pData )
	{
		fclose( f );
		return -1;
	}
	
	fseek( f, 0, SEEK_SET );
	int iRead = fread( p->m_pData, 1, iFileSize, f );
	fclose( f );
	
	p->m_iColorCount = gamescreen->format->BitsPerPixel == 8 ? a_iNumColors : 256;
	
	if ( iFileSize != iRead )
	{
		debug( "Warning CRlePack(): iFileSize=%d, iRead=%d\n", iFileSize, iRead );
	}
	
	struct SHeader
	{
		char	acDummy[8];
		Uint32	iDatacount;
	} *poHeader = (SHeader*) p->m_pData;
	
	ChangeEndian32( poHeader->iDatacount );
	debug( "File '%s' contains %d entries.\n", a_pcFilename, poHeader->iDatacount );
	
	if (poHeader->iDatacount>MAXDATACOUNT) poHeader->iDatacount = MAXDATACOUNT;		// Sanity
	
	p->m_iArraysize = poHeader->iDatacount;
	p->m_pSprites = new SRleSprite*[ poHeader->iDatacount ];
	
	char* pcNext = ((char*)p->m_pData) + sizeof(SHeader);
	char* pcEnd = ((char*)p->m_pData) + iFileSize;
	
	while ( pcNext < pcEnd - 4 )
	{
		if ( 0 == strncmp( pcNext, "prop", 4 ) )
		{
			struct SProperty
			{
				char	acName[4];
				Uint32	iSize;
			} *poProperty = (SProperty*) (pcNext+4);
			ChangeEndian32( poProperty->iSize );
			
			pcNext += 4 + sizeof(SProperty) + poProperty->iSize;
		}
		else if ( 0 == strncmp( pcNext, "RLE ", 4 ) )
		{
			struct SRLE
			{
				SRleSprite	oSprite;
			} *poRle = (SRLE*) (pcNext+10);
			poRle->oSprite.color_depth = ConvertEndian16(poRle->oSprite.color_depth);
			poRle->oSprite.w = ConvertEndian16(poRle->oSprite.w);
			poRle->oSprite.h = ConvertEndian16(poRle->oSprite.h);
			poRle->oSprite.size = ConvertEndian32(poRle->oSprite.size);
			
			p->m_pSprites[p->m_iCount] = &(poRle->oSprite);
			p->m_iCount++;
			pcNext += 10 + sizeof( SRLE ) + poRle->oSprite.size;
		}
		else if ( 0 == strncmp( pcNext, "PAL ", 4 ) )
		{
			struct SPAL
			{
				Uint32		iLength1;
				Uint32		iLength;
				SDL_Color	aoColors[256];
			} *poPal = (SPAL*) (pcNext+4);
			ChangeEndian32( poPal->iLength );
			
			int iNumColors = poPal->iLength>1024 ? 1024 : poPal->iLength;
			iNumColors /= 4;
			
			for (int i=0; i< iNumColors; i++)
			{
				p->m_aoPalette[i].r = poPal->aoColors[i].r*4;
				p->m_aoPalette[i].g = poPal->aoColors[i].g*4;
				p->m_aoPalette[i].b = poPal->aoColors[i].b*4;
				p->m_aoPalette[i].unused = 0;
				p->m_aoTintedPalette[i] = p->m_aoPalette[i];
			}
			
			pcNext += 4 + 8 + poPal->iLength;
		}
		else
		{
			struct SUnknown
			{
				Uint32	iSize;
			} *poUnknown = (SUnknown*) (pcNext+4);
			ChangeEndian32( poUnknown->iSize );
			
			debug( "Unknown: '%4s', size: %d\n", pcNext, poUnknown->iSize );
			
			pcNext += 4 + sizeof(SUnknown) + poUnknown->iSize;
		}
	}
	
	return p->m_iCount;
	
#if 0
// #
// # Here's the old implementation or read, left here for reference only.
// #
	
	int datacount;
	
	#define READDW(I) {														\
		unsigned char data[4];														\
		fread( data, 4, 1, f );												\
		(I) = (data[0]<<24) + (data[1]<<16) + (data[2]<<8) + data[3]; }
	#define READW(I) {														\
		unsigned char data[2];														\
		fread( data, 2, 1, f );												\
		(I) = (data[0]<<8) + data[1]; }
	#define READCH(S,C) {													\
		fread( S, C, 1, f ); S[C] = 0; }
	
	fseek( f, 8, SEEK_SET );		// Skip header
	READDW( datacount );
	
	debug( "File '%s' contains %d entries.\n", filename, datacount );
	if (datacount>500) datacount = 500;			// Sanity
	
	p->arraysize = datacount;
	p->sprites = new SRleSprite*[ datacount ];
	
	while( (!feof(f)) && (!ferror(f)) && (datacount>0) )
	{
		char s[10];
		READCH( s, 4 );
		if ( !strcmp( s, "prop" ))				// Found a property
		{
			fseek( f, 4, SEEK_CUR );
			unsigned int propsize;
			READDW( propsize );
			fseek( f, propsize, SEEK_CUR );
		}
		else if (!strcmp( s, "RLE " ))			// Found an SRleSprite
		{
			datacount--;
			
			unsigned int length, bpp, width, height, size;
			
			READDW( length );
			READDW( length );
			READW( bpp );
			READW( width );
			READW( height );
			READDW( size );
			
			SRleSprite* sprite = (SRleSprite*) malloc( sizeof(SRleSprite) + size );
			p->sprites[ p->count ] = sprite;
			(p->count)++;
			sprite->w = width;
			sprite->h = height;
			sprite->color_depth = bpp;
			sprite->size = size;
			fread( sprite->dat, 1, size, f );
		}
		else if (!strcmp( s, "PAL "))			// Found a palette
		{
			datacount--;
			
			unsigned int length, pallength;
			READDW( length );
			READDW( length );
			pallength = length>1024 ? 1024 : length;
			pallength /= 4;
			
			for (unsigned int i=0; i< pallength; i++)
			{
				char c[4];
				fread( c, 4, 1, f );
				p->palette[i].r = c[0]*4;
				p->palette[i].g = c[1]*4;
				p->palette[i].b = c[2]*4;
				p->palette[i].unused = 0;
			}
			
			fseek( f, length - pallength*4, SEEK_CUR );
		}
		else									// Found something else
		{
			debug( "Unknown: %s.", s );
			datacount--;
		
			unsigned int length;
			READDW( length );
			READDW( length );
			fseek( f, length, SEEK_CUR );
		}
	}
	
	fclose( f );
#endif
}