Ejemplo n.º 1
0
int org_init(FILE *fp, int org_volume)
{
   int i;
	
	SSReserveChannel(ORG_CHANNEL);
	OrgVolume = org_volume;
	
	// set all buffer pointers and things to NULL, so if something fails to load,
	// we won't crash on org_close.
	memset(drumtable, 0, sizeof(drumtable));
	for(i=0;i<16;i++)
      note_channel[i].outbuffer = NULL;
	for(i=0;i<2;i++)
      final_buffer[i].samples = NULL;

   extract_org(fp);

	init_pitch();
	if (load_drumtable(fp))
   {
      return 1;
   }
	
	song.playing = false;
	org_inited = true;
	return 0;
}
Ejemplo n.º 2
0
int org_init(const char *wavetable_fname, const char *drum_pxt_dir, int org_volume)
{
int i;
	
	SSReserveChannel(ORG_CHANNEL);
	OrgVolume = org_volume;
	
	// set all buffer pointers and things to NULL, so if something fails to load,
	// we won't crash on org_close.
	memset(drumtable, 0, sizeof(drumtable));
	for(i=0;i<16;i++) note_channel[i].outbuffer = NULL;
	for(i=0;i<2;i++) final_buffer[i].samples = NULL;
	
	init_pitch();
	if (load_wavetable(wavetable_fname)) return 1;
	if (load_drumtable(drum_pxt_dir)) return 1;
	
	song.playing = false;
	org_inited = true;
	return 0;
}
Ejemplo n.º 3
0
static bool load_drumtable(const char *pxt_path)		// pxt_path = the path where drum pxt files can be found
{
char fname[80];
int d;
FILE *fp;
static const char *drum_cache = "drum.pcm";

	#ifndef DRUM_PXT
		for(d=0;d<NUM_DRUMS;d++)
		{
			sprintf(fname, "./drums/%s.wav", drum_names[d]);
			if (load_drum(fname, d)) return 1;
		}
	#else
		
		// try and load the drums from cache instead of synthing them
		fp = fileopen(drum_cache, "rb");
		if (fp)
		{
			for(d=0;d<NUM_DRUMS;d++)
			{
				drumtable[d].nsamples = fgetl(fp);
				drumtable[d].samples = (signed short *)malloc(drumtable[d].nsamples * 2);
				fread(drumtable[d].samples, drumtable[d].nsamples*2, 1, fp);
			}
			fclose(fp);
			stat("-- Drums loaded from cache");
			return 0;
		}
		
		stat("load_drumtable: cache gone; rebuilding drums...");
		
		pxt_initsynth();
		
		for(d=0;d<NUM_DRUMS;d++)
		{
			if (drum_pxt[d])
			{
				sprintf(fname, "%sfx%02x.pxt", pxt_path, drum_pxt[d]);
				if (load_drum_pxt(fname, d)) return 1;
			}
		}
		
		// cache the drums for next time
		fp = fileopen(drum_cache, "wb");
		if (fp)
		{
			for(d=0;d<NUM_DRUMS;d++)
			{
				fputl(drumtable[d].nsamples, fp);
				fwrite(drumtable[d].samples, drumtable[d].nsamples*2, 1, fp);
			}
			fclose(fp);
		}
		
		load_drumtable(pxt_path);
	#endif
	
	//for(d=0;d<256;d++) { lprintf("%d ", drumtable[0].samples[d]); if (d%32==0) lprintf("\n"); }
	//lprintf("\n");
	
	return 0;
}
Ejemplo n.º 4
0
static bool load_drumtable(const char *pxt_path) {		// pxt_path = the path where drum pxt files can be found
	char fname[80];
	int d;
	FILE *fp;
	static const char *drum_cache = "drum.pcm";
#define DRUM_VERSION	0x0001
	uint16_t version;
	unsigned long error;

	#ifndef DRUM_PXT
		for(d=0;d<NUM_DRUMS;d++)
		{
			sprintf(fname, "./drums/%s.wav", drum_names[d]);
			if (load_drum(fname, d)) return 1;
		}
	#else
		
		// try and load the drums from cache instead of synthing them
		fp = fileopen(drum_cache, "rb");
		if (fp)
		{
			// this also checks for correct endianness
			error = fread(&version, sizeof(version), 1, fp);
			if (error != 1 ) {
				printf("org.cpp: expected to read 1 version, but read %lu\n",error);
			}
			if (version != DRUM_VERSION)
			{
				printf("%s: version incorrect\n", drum_cache);
			}
			else
			{
				for(d=0;d<NUM_DRUMS;d++)
				{
					drumtable[d].nsamples = fgetl(fp);
					drumtable[d].samples = (signed short *)malloc(drumtable[d].nsamples * 2);
					error = fread(drumtable[d].samples, drumtable[d].nsamples*2, 1, fp);
					if(error != 1) {
						printf("org.cpp: expected to read 1 drumtable sample, but read %lu\n",error);
					}
				}
				fclose(fp);
				stat("-- Drums loaded from cache");
				return 0;
			}
		}
		
		stat("load_drumtable: cache gone; rebuilding drums...");
		
		pxt_initsynth();
		
		for(d=0;d<NUM_DRUMS;d++)
		{
			if (drum_pxt[d])
			{
				sprintf(fname, "%sfx%02x.pxt", pxt_path, drum_pxt[d]);
				if (load_drum_pxt(fname, d)) return 1;
			}
		}
		
		// cache the drums for next time
		fp = fileopen(drum_cache, "wb");
		if (fp)
		{
			version = DRUM_VERSION;
			fwrite(&version, sizeof(version), 1, fp);
			for(d=0;d<NUM_DRUMS;d++)
			{
				fputl(drumtable[d].nsamples, fp);
				fwrite(drumtable[d].samples, drumtable[d].nsamples*2, 1, fp);
			}
			fclose(fp);
		}
		
		load_drumtable(pxt_path);
	#endif
	
	//for(d=0;d<256;d++) { lprintf("%d ", drumtable[0].samples[d]); if (d%32==0) lprintf("\n"); }
	//lprintf("\n");
	
	return 0;
}