예제 #1
0
int YM2612_sh_start(const struct MachineSound *msound)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2612_NUMBUF][40];
	const char *name[YM2612_NUMBUF];

	intf = msound->sound_interface;
	if( intf->num > MAX_2612 ) return 1;

	/* FM init */
	/* Timer Handler set */
	FMTimerInit();
	/* stream system initialize */
	for (i = 0;i < intf->num;i++)
	{
		int vol[YM2612_NUMBUF];
		/* stream setup */
		for (j = 0 ; j < YM2612_NUMBUF ; j++)
		{
			vol[j] = intf->mixing_level[i];
			name[j] = buf[j];
			sprintf(buf[j],"YM2612(%s) #%d",j < 2 ? "FM" : "ADPCM",i);
		}
		stream[i] = stream_init_multi(YM2612_NUMBUF,
			name,vol,rate,FM_OUTPUT_BIT,
			i,YM2612UpdateOne);
	}

	/**** initialize YM2612 ****/
	if (YM2612Init(intf->num,intf->baseclock,rate,TimerHandler,IRQHandler) == 0)
	  return 0;
	/* error */
	return 1;
}
예제 #2
0
int exidy440_sh_start(const struct MachineSound *msound)
{
	const char *names[] =
	{
		"Exidy 440 sound left",
		"Exidy 440 sound right"
	};
	int i, length;
	int vol[2];

	/* reset the system */
	exidy440_sound_command = 0;
	exidy440_sound_command_ack = 1;

	/* reset the 6844 */
	for (i = 0; i < 4; i++)
	{
		m6844_channel[i].active = 0;
		m6844_channel[i].control = 0x00;
	}
	m6844_priority = 0x00;
	m6844_interrupt = 0x00;
	m6844_chain = 0x00;

	/* get stream channels */
	vol[0] = MIXER(100, MIXER_PAN_LEFT);
	vol[1] = MIXER(100, MIXER_PAN_RIGHT);
	sound_stream = stream_init_multi(2, names, vol, SAMPLE_RATE_FAST, 0, channel_update);

	/* allocate the sample cache */
	length = memory_region_length(REGION_SOUND1) * 16 + MAX_CACHE_ENTRIES * sizeof(sound_cache_entry);
	sound_cache = (struct sound_cache_entry*)malloc(length);
	if (!sound_cache)
		return 1;

	/* determine the hard end of the cache and reset */
	sound_cache_max = (sound_cache_entry *)((UINT8 *)sound_cache + length);
	reset_sound_cache();

	/* allocate the mixer buffer */
	mixer_buffer_left = (INT32*)malloc(2 * SAMPLE_RATE_FAST * sizeof(INT32));
	if (!mixer_buffer_left)
	{
		free(sound_cache);
		sound_cache = NULL;
		return 1;
	}
	mixer_buffer_right = mixer_buffer_left + SAMPLE_RATE_FAST;

	if (SOUND_LOG)
		debuglog = fopen("sound.log", "w");

	return 0;
}
예제 #3
0
static int AY8910_init(const char *chip_name,int chip,
		int clock,int volume,int sample_rate,
		mem_read_handler portAread,mem_read_handler portBread,
		mem_write_handler portAwrite,mem_write_handler portBwrite)
{
	struct AY8910 *PSG = &AYPSG[chip];
	int i;
#ifdef SINGLE_CHANNEL_MIXER
	char buf[40];
	int gain = MIXER_GET_GAIN(volume);
	int pan = MIXER_GET_PAN(volume);
#else
	char buf[3][40];
	const char *name[3];
	int vol[3];
#endif

	/* the step clock for the tone and noise generators is the chip clock    */
	/* divided by 8; for the envelope generator of the AY-3-8910, it is half */
	/* that much (clock/16), but the envelope of the YM2149 goes twice as    */
	/* fast, therefore again clock/8.                                        */
// causes crashes with YM2610 games - overflow?
//	if (options.use_filter)
		sample_rate = clock/8;

	memset(PSG,0,sizeof(struct AY8910));
	PSG->PortAread = portAread;
	PSG->PortBread = portBread;
	PSG->PortAwrite = portAwrite;
	PSG->PortBwrite = portBwrite;

#ifdef SINGLE_CHANNEL_MIXER
	for (i = 0;i < 3;i++)
		PSG->mix_vol[i] = MIXER_GET_LEVEL(volume);
	sprintf(buf,"%s #%d",chip_name,chip);
	PSG->Channel = stream_init(buf,MIXERG(100,gain,pan),sample_rate,chip,AY8910Update);
#else
	for (i = 0;i < 3;i++)
	{
		vol[i] = volume;
		name[i] = buf[i];
		sprintf(buf[i],"%s #%d Ch %c",chip_name,chip,'A'+i);
	}
	PSG->Channel = stream_init_multi(3,name,vol,sample_rate,chip,AY8910Update);
#endif

	if (PSG->Channel == -1)
		return 1;

	return 0;
}
예제 #4
0
int YM2610_sh_start(const struct MachineSound *msound)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2610_NUMBUF][40];
	const char *name[YM2610_NUMBUF];
	int mixed_vol,vol[YM2610_NUMBUF];
	void *pcmbufa[YM2610_NUMBUF],*pcmbufb[YM2610_NUMBUF];
	int  pcmsizea[YM2610_NUMBUF],pcmsizeb[YM2610_NUMBUF];

	intf = msound->sound_interface;
	if( intf->num > MAX_2610 ) return 1;

	if (AY8910_sh_start(msound)) return 1;

	/* Timer Handler set */
	FMTimerInit();

	/* stream system initialize */
	for (i = 0;i < intf->num;i++)
	{
		/* stream setup */
		mixed_vol = intf->volumeFM[i];
		/* stream setup */
		for (j = 0 ; j < YM2610_NUMBUF ; j++)
		{
			name[j]=buf[j];
			vol[j] = mixed_vol & 0xffff;
			mixed_vol>>=16;
			sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
		}
		stream[i] = stream_init_multi(YM2610_NUMBUF,name,vol,rate,i,YM2610UpdateOne);
		/* setup adpcm buffers */
		pcmbufa[i]  = (void *)(memory_region(intf->pcmroma[i]));
		pcmsizea[i] = memory_region_length(intf->pcmroma[i]);
		pcmbufb[i]  = (void *)(memory_region(intf->pcmromb[i]));
		pcmsizeb[i] = memory_region_length(intf->pcmromb[i]);
	}

	/**** initialize YM2610 ****/
	if (YM2610Init(intf->num,intf->baseclock,rate,
		           pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
		           TimerHandler,IRQHandler) == 0)
		return 0;

	/* error */
	return 1;
}
예제 #5
0
int YMF262_sh_start(const struct MachineSound *msound)
{
	int i,chip;
	int rate = Machine->sample_rate;

	intf_262 = msound->sound_interface;
	if( intf_262->num > MAX_262 ) return 1;

	if (options.use_filter)
		rate = intf_262->baseclock/288;

	/* Timer state clear */
	memset(Timer_262,0,sizeof(Timer_262));

	/* stream system initialize */
	if ( YMF262Init(intf_262->num,intf_262->baseclock,rate) != 0)
		return 1;

	for (chip = 0;chip < intf_262->num; chip++)
	{
		int mixed_vol;
		int vol[4];		/* four separate outputs */
		char buf[4][40];
		const char *name[4];

		mixed_vol = intf_262->mixing_levelAB[chip];
		for (i=0; i<4; i++)
		{
			if (i==2) /*channels C ad D use separate field */
				mixed_vol = intf_262->mixing_levelCD[chip];
			vol[i] = mixed_vol & 0xffff;
			mixed_vol >>= 16;
			name[i] = buf[i];
			sprintf(buf[i],"%s #%d ch%c",sound_name(msound),chip,'A'+i);
			logerror("%s #%d ch%c vol %d\n",sound_name(msound),chip,'A'+i,mixed_vol);
		}
		stream_262[chip] = stream_init_multi(4,name,vol,rate,chip,YMF262UpdateOne);

		/* YMF262 setup */
		YMF262SetTimerHandler (chip, TimerHandler_262, chip*2);
		YMF262SetIRQHandler   (chip, IRQHandler_262, chip);
		YMF262SetUpdateHandler(chip, stream_update, stream_262[chip]);

		Timer_262[chip*2+0] = timer_alloc(timer_callback_262);
		Timer_262[chip*2+1] = timer_alloc(timer_callback_262);
	}
	return 0;
}
예제 #6
0
static int sh_start(const struct MachineSound *msound)
{
	char buf[2][40];
	const char *name[2];
	int vol[2];

	sprintf(buf[0], "C352 L"); 
	sprintf(buf[1], "C352 R"); 
	name[0] = buf[0];
	name[1] = buf[1];
	vol[0]=100;
	vol[1]=100;
	stream_init_multi(2, name, vol, 44100, 0, hc352_update);

	return 0;
}
예제 #7
0
파일: ay8910.c 프로젝트: Bremma/pinmame
static int AY8910_init(const char *chip_name,int chip,
		int clock,int volume,int sample_rate,
		mem_read_handler portAread,mem_read_handler portBread,
		mem_write_handler portAwrite,mem_write_handler portBwrite)
{
	int i;
	struct AY8910 *PSG = &AYPSG[chip];
	char buf[3][40];
	const char *name[3];
	int vol[3];


// causes crashes with YM2610 games - overflow?
//	if (options.use_filter)
//		sample_rate = clock/8;

	memset(PSG,0,sizeof(struct AY8910));
	PSG->SampleRate = sample_rate;
	PSG->PortAread = portAread;
	PSG->PortBread = portBread;
	PSG->PortAwrite = portAwrite;
	PSG->PortBwrite = portBwrite;
	for (i = 0;i < 3;i++)
	{
		vol[i] = volume;
		name[i] = buf[i];
		sprintf(buf[i],"%s #%d Ch %c",chip_name,chip,'A'+i);
	}
	PSG->Channel = stream_init_multi(3,name,vol,sample_rate,chip,AY8910Update);

	if (PSG->Channel == -1)
		return 1;

	AY8910_set_clock(chip,clock);

	return 0;
}
예제 #8
0
static int
AY8910_init(int gcclock, int sample_rate,
	    mem_read_handler portAread,
	    mem_read_handler portBread,
	    mem_write_handler portAwrite, mem_write_handler portBwrite)
{
    struct AY8910 *PSG = &AYPSG;

    memset(PSG, 0, sizeof(struct AY8910));
    PSG->SampleRate = sample_rate;
    PSG->PortAread = portAread;
    PSG->PortBread = portBread;
    PSG->PortAwrite = portAwrite;
    PSG->PortBwrite = portBwrite;
    PSG->Channel = stream_init_multi(3, 0, AY8910Update);

    if (PSG->Channel == -1)
	return 1;

    AY8910_set_clock(gcclock);
    AY8910_reset();

    return 0;
}
예제 #9
0
int qsound_sh_start(const struct MachineSound *msound)
{
	int i;

	if (Machine->sample_rate == 0) return 0;

	intf = msound->sound_interface;

	qsound_sample_rom = (QSOUND_SRC_SAMPLE *)memory_region(intf->region);

	memset(qsound_channel, 0, sizeof(qsound_channel));

#if QSOUND_DRIVER1
	qsound_frq_ratio = ((float)intf->clock / (float)QSOUND_CLOCKDIV) /
						(float) Machine->sample_rate;
	qsound_frq_ratio *= 16.0;

	/* Create pan table */
	for (i=0; i<33; i++)
	{
		qsound_pan_table[i]=(int)((256/sqrt(32)) * sqrt(i));
	}
#else
	i=0;
#endif

#if LOG_QSOUND
	logerror("Pan table\n");
	for (i=0; i<33; i++)
		logerror("%02x ", qsound_pan_table[i]);
#endif
	{
		/* Allocate stream */
#define CHANNELS ( 2 )
		char buf[CHANNELS][40];
		const char *name[CHANNELS];
		int  vol[2];
		name[0] = buf[0];
		name[1] = buf[1];
		sprintf( buf[0], "%s L", sound_name(msound) );
		sprintf( buf[1], "%s R", sound_name(msound) );
		vol[0]=MIXER(intf->mixing_level[0], MIXER_PAN_LEFT);
		vol[1]=MIXER(intf->mixing_level[1], MIXER_PAN_RIGHT);
		qsound_stream = stream_init_multi(
			CHANNELS,
			name,
			vol,
			Machine->sample_rate,
			0,
			qsound_update );
	}

#if LOG_WAVE
	fpRawDataR=fopen("qsoundr.raw", "w+b");
	fpRawDataL=fopen("qsoundl.raw", "w+b");
	if (!fpRawDataR || !fpRawDataL)
	{
		return 1;
	}
#endif

	return 0;
}
예제 #10
0
파일: 2151intf.c 프로젝트: Bremma/pinmame
static int my_YM2151_sh_start(const struct MachineSound *msound,int mode)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2151_NUMBUF][40];
	const char *name[YM2151_NUMBUF];
	int mixed_vol,vol[YM2151_NUMBUF];

	if( rate == 0 ) rate = 1000;	/* kludge to prevent nasty crashes */

	intf = msound->sound_interface;

	if( mode ) FMMode = CHIP_YM2151_ALT;
	else       FMMode = CHIP_YM2151_DAC;

	switch(FMMode)
	{
#if (HAS_YM2151)
	case CHIP_YM2151_DAC:	/* Tatsuyuki's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			mixed_vol = intf->volume[i];
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				name[j]=buf[j];
				vol[j] = mixed_vol & 0xffff;
				mixed_vol>>=16;
				sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,vol,rate,i,OPMUpdateOne);
		}
		/* Set Timer handler */
		for (i = 0; i < intf->num; i++)
		{
			Timer[i][0] = timer_alloc(timer_callback_2151);
			Timer[i][1] = timer_alloc(timer_callback_2151);
		}
		if (OPMInit(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
		{
			/* set port handler */
			for (i = 0; i < intf->num; i++)
				OPMSetPortHander(i,intf->portwritehandler[i]);
			return 0;
		}
		/* error */
		return 1;
#endif
#if (HAS_YM2151_ALT)
	case CHIP_YM2151_ALT:	/* Jarek's */

		if (options.use_filter)
			rate = intf->baseclock/64;

		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			mixed_vol = intf->volume[i];
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				name[j]=buf[j];
				vol[j] = mixed_vol & 0xffff;
				mixed_vol>>=16;
				sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,vol,rate,i,YM2151UpdateOne);
		}

		if (YM2151Init(intf->num,intf->baseclock,rate) == 0)
		{
			for (i = 0; i < intf->num; i++)
			{
				YM2151SetIrqHandler(i,intf->irqhandler[i]);
				YM2151SetPortWriteHandler(i,intf->portwritehandler[i]);
			}
			return 0;
		}
		return 1;
#endif
	}
	return 1;
}
예제 #11
0
int discrete_sh_start (const struct MachineSound *msound)
{
	struct discrete_sound_block *intf;
	int loop=0,loop2=0,search=0,failed=0;
	int vol[2];
	const char *stereo_names[2] = { "Discrete Left", "Discrete Right" };
	vol[0] = MIXER(100,MIXER_PAN_LEFT);
	vol[1] = MIXER(100,MIXER_PAN_RIGHT);

	/* Initialise */
	intf=msound->sound_interface;
	node_count=0;

	/* Sanity check and node count */
	discrete_log("discrete_sh_start() - Doing node list sanity check");
	while(1)
	{
		/* Check the node parameter is a valid node */
		if(intf[node_count].node<NODE_START || intf[node_count].node>NODE_END)
		{
			logerror("discrete_sh_start() - Invalid node number on node %02d descriptor\n",node_count);
			return 1;
		}
		if(intf[node_count].type>DSO_OUTPUT)
		{
			logerror("discrete_sh_start() - Invalid function type on node %02d descriptor\n",node_count);
			return 1;
		}

		/* Node count must include the NULL node as well */
		if(intf[node_count].type==DSS_NULL)
		{
			node_count++;
			break;
		}

		node_count++;

		/* Sanity check */
		if(node_count>255)
		{
			logerror("discrete_sh_start() - Upper limit of 255 nodes exceeded, have you terminated the interface block.");
			return 1;
		}
	}
	discrete_log("discrete_sh_start() - Sanity check counted %d nodes", node_count);

	/* Allocate memory for the context array and the node execution order array */
	if((running_order=malloc(node_count*sizeof(struct node_description*)))==NULL)
	{
		logerror("discrete_sh_start() - Failed to allocate running order array.\n");
		return 1;
	}
	else
	{
		/* Initialise memory */
		memset(running_order,0,node_count*sizeof(struct node_description*));
	}

	if((node_list=malloc(node_count*sizeof(struct node_description)))==NULL)
	{
		logerror("discrete_sh_start() - Failed to allocate context list array.\n");
		return 1;
	}
	else
	{
		/* Initialise memory */
		memset(node_list,0,node_count*sizeof(struct node_description));
	}
	discrete_log("discrete_sh_start() - Malloc completed", node_count);

	/* Work out the execution order */
	/* FAKE IT FOR THE MOMENT, EXECUTE IN ORDER */
	for(loop=0;loop<node_count;loop++)
	{
		running_order[loop]=&node_list[loop];
	}
	discrete_log("discrete_sh_start() - Running order sort completed", node_count);

	/* Configure the input node pointers, the find_node function wont work without the node ID setup beforehand */
	for(loop=0;loop<node_count;loop++) node_list[loop].node=intf[loop].node;
	failed=0;

	/* Duplicate node number test */
	for(loop=0;loop<node_count;loop++)
	{
		for(loop2=0;loop2<node_count;loop2++)
		{
			if(node_list[loop].node==node_list[loop2].node && loop!=loop2)
			{
				logerror("discrete_sh_start - Node NODE_%02d defined more than once\n",node_list[loop].node-NODE_00);
				failed=1;
			}
		}
	}

	/* Initialise and start all of the objects */
	for(loop=0;loop<node_count;loop++)
	{
		/* Configure the input node pointers */
		node_list[loop].node=intf[loop].node;
		node_list[loop].output=0;
		node_list[loop].input0=intf[loop].initial0;
		node_list[loop].input1=intf[loop].initial1;
		node_list[loop].input2=intf[loop].initial2;
		node_list[loop].input3=intf[loop].initial3;
		node_list[loop].input4=intf[loop].initial4;
		node_list[loop].input5=intf[loop].initial5;
		node_list[loop].input_node0=find_node(intf[loop].input_node0);
		node_list[loop].input_node1=find_node(intf[loop].input_node1);
		node_list[loop].input_node2=find_node(intf[loop].input_node2);
		node_list[loop].input_node3=find_node(intf[loop].input_node3);
		node_list[loop].input_node4=find_node(intf[loop].input_node4);
		node_list[loop].input_node5=find_node(intf[loop].input_node5);

		/* Check that all referenced nodes have actually been found */
		if(node_list[loop].input_node0==NULL && intf[loop].input_node0>=NODE_START && intf[loop].input_node0<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node0-NODE_00);
			failed=1;
		}
		if(node_list[loop].input_node1==NULL && intf[loop].input_node1>=NODE_START && intf[loop].input_node1<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node1-NODE_00);
			failed=1;
		}
		if(node_list[loop].input_node2==NULL && intf[loop].input_node2>=NODE_START && intf[loop].input_node2<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node2-NODE_00);
			failed=1;
		}
		if(node_list[loop].input_node3==NULL && intf[loop].input_node3>=NODE_START && intf[loop].input_node3<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node3-NODE_00);
			failed=1;
		}
		if(node_list[loop].input_node4==NULL && intf[loop].input_node4>=NODE_START && intf[loop].input_node4<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node4-NODE_00);
			failed=1;
		}
		if(node_list[loop].input_node5==NULL && intf[loop].input_node5>=NODE_START && intf[loop].input_node5<=NODE_END)
		{
			logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node5-NODE_00);
			failed=1;
		}

		/* Try to find the simulation module in the module list table */
		search=0;
		while(1)
		{
			if(module_list[search].type==intf[loop].type)
			{
				node_list[loop].module=search;
				discrete_log("discrete_sh_start() - Calling init for %s",module_list[search].name);
				if(module_list[search].init)
					if(((*module_list[search].init)(&node_list[loop]))==1) failed=1;
				break;
			}
			else if(module_list[search].type==DSS_NULL)
			{
				if(intf[loop].type==DSS_NULL) break;
				else
				{
					logerror("discrete_sh_start() - Invalid DSS/DST/DSO module type specified in interface, item %02d\n",loop+1);
					failed=1;
					break;
				}
			}
			search++;
		}
	}
	/* Setup the output node */
	if((output_node=find_node(NODE_OP))==NULL)
	{
		logerror("discrete_sh_start() - Counldnt find an output node");
		failed=1;
	}

	discrete_log("discrete_sh_start() - Nodes initialised", node_count);

	/* Initialise a stereo, stream, we always use stereo even if only a mono system */
	discrete_stream=stream_init_multi(2,stereo_names,vol,Machine->sample_rate,0,discrete_stream_update);
	discrete_log("discrete_sh_start() - Audio Stream Initialised", node_count);

	/* Report success or fail */
	if(!failed) init_ok=1;
	return failed;
}
예제 #12
0
파일: discrete.c 프로젝트: mp-lee/pinmame
int discrete_sh_start (const struct MachineSound *msound)
{
	struct discrete_sound_block *intf;
	int loop=0,loop2=0,search=0,failed=0;

#ifdef DISCRETE_WAVELOG
	wav_file = wav_open("discrete.wav", Machine->sample_rate, ((Machine->drv->sound_attributes&SOUND_SUPPORTS_STEREO) == SOUND_SUPPORTS_STEREO) ? 2: 1);
#endif
#ifdef DISCRETE_DEBUGLOG
	if(!disclogfile) disclogfile=fopen("discrete.log", "w");
#endif

	/* Initialise */
	intf=msound->sound_interface;
	node_count=0;

	/* Sanity check and node count */
	discrete_log("discrete_sh_start() - Doing node list sanity check");
	while(1)
	{
		/* Check the node parameter is a valid node */
		if(intf[node_count].node<NODE_START || intf[node_count].node>NODE_END)
		{
			logerror("discrete_sh_start() - Invalid node number on node %02d descriptor\n",node_count);
			return 1;
		}
		if(intf[node_count].type>DSO_OUTPUT)
		{
			logerror("discrete_sh_start() - Invalid function type on node %02d descriptor\n",node_count);
			return 1;
		}

		/* Node count must include the NULL node as well */
		if(intf[node_count].type==DSS_NULL)
		{
			node_count++;
			break;
		}

		node_count++;

		/* Sanity check */
		if(node_count>DISCRETE_MAX_NODES)
		{
			logerror("discrete_sh_start() - Upper limit of %d nodes exceeded, have you terminated the interface block.",DISCRETE_MAX_NODES);
			return 1;
		}
	}
	discrete_log("discrete_sh_start() - Sanity check counted %d nodes", node_count);

	/* Allocate memory for the context array and the node execution order array */
	if((running_order=malloc(node_count*sizeof(struct node_description*)))==NULL)
	{
		logerror("discrete_sh_start() - Failed to allocate running order array.\n");
		return 1;
	}
	else
	{
		/* Initialise memory */
		memset(running_order,0,node_count*sizeof(struct node_description*));
	}

	if((node_list=malloc(node_count*sizeof(struct node_description)))==NULL)
	{
		logerror("discrete_sh_start() - Failed to allocate context list array.\n");
		return 1;
	}
	else
	{
		/* Initialise memory */
		memset(node_list,0,node_count*sizeof(struct node_description));

		/* Initialise structs */
		for(loop=0;loop<node_count;loop++)
		{
			for(loop2=0;loop2<DISCRETE_MAX_INPUTS;loop2++)
			{
				node_list[loop].input[loop2]=0.0;
				node_list[loop].input_node[loop2]=NULL;
			}
		}


	}
	discrete_log("discrete_sh_start() - Malloc completed", node_count);

	/* Work out the execution order */
	/* FAKE IT FOR THE MOMENT, EXECUTE IN ORDER */
	for(loop=0;loop<node_count;loop++)
	{
		running_order[loop]=&node_list[loop];
	}
	discrete_log("discrete_sh_start() - Running order sort completed", node_count);

	/* Configure the input node pointers, the find_node function wont work without the node ID setup beforehand */
	for(loop=0;loop<node_count;loop++) node_list[loop].node=intf[loop].node;
	failed=0;

	/* Duplicate node number test */
	for(loop=0;loop<node_count;loop++)
	{
		for(loop2=0;loop2<node_count;loop2++)
		{
			if(node_list[loop].node==node_list[loop2].node && loop!=loop2)
			{
				logerror("discrete_sh_start - Node NODE_%02d defined more than once\n",node_list[loop].node-NODE_00);
				failed=1;
			}
		}
	}

	/* Initialise and start all of the objects */
	for(loop=0;loop<node_count;loop++)
	{
		/* Configure the input node pointers */
		node_list[loop].node=intf[loop].node;
		node_list[loop].output=0;
		node_list[loop].active_inputs=intf[loop].active_inputs;
		for(loop2=0;loop2<intf[loop].active_inputs;loop2++)
		{
			node_list[loop].input[loop2]=intf[loop].initial[loop2];
			node_list[loop].input_node[loop2]=find_node(intf[loop].input_node[loop2]);
		}
		node_list[loop].name=intf[loop].name;
		node_list[loop].custom=intf[loop].custom;

		/* Check that all referenced nodes have actually been found */
		for(loop2=0;loop2<intf[loop].active_inputs;loop2++)
		{
			if(node_list[loop].input_node[loop2]==NULL && intf[loop].input_node[loop2]>=NODE_START && intf[loop].input_node[loop2]<=NODE_END)
			{
				logerror("discrete_sh_start - Node NODE_%02d referenced a non existant node NODE_%02d\n",node_list[loop].node-NODE_00,intf[loop].input_node[loop2]-NODE_00);
				failed=1;
			}
		}

		/* Try to find the simulation module in the module list table */
		search=0;
		while(1)
		{
			if(module_list[search].type==intf[loop].type)
			{
				node_list[loop].module=search;
				discrete_log("discrete_sh_start() - Calling init for %s",module_list[search].name);
				if(module_list[search].init)
					if(((*module_list[search].init)(&node_list[loop]))==1) failed=1;
				break;
			}
			else if(module_list[search].type==DSS_NULL)
			{
				if(intf[loop].type==DSS_NULL) break;
				else
				{
					logerror("discrete_sh_start() - Invalid DSS/DST/DSO module type specified in interface, item %02d\n",loop+1);
					failed=1;
					break;
				}
			}
			search++;
		}
	}
	/* Setup the output node */
	if((output_node=find_node(NODE_OP))==NULL)
	{
		logerror("discrete_sh_start() - Couldn't find an output node");
		failed=1;
	}

	discrete_log("discrete_sh_start() - Nodes initialised", node_count);

	/* Different setup for Mono/Stereo systems */
	if ((Machine->drv->sound_attributes&SOUND_SUPPORTS_STEREO) == SOUND_SUPPORTS_STEREO)
	{
		int vol[2];
		const char *stereo_names[2] = { "Discrete Left", "Discrete Right" };
		vol[0] = MIXER((int)output_node->input[2],MIXER_PAN_LEFT);
		vol[1] = MIXER((int)output_node->input[2],MIXER_PAN_RIGHT);
		/* Initialise a stereo, stream, we always use stereo even if only a mono system */
		discrete_stream=stream_init_multi(2,stereo_names,vol,Machine->sample_rate,0,discrete_stream_update_stereo);
		discrete_log("discrete_sh_start() - Stereo Audio Stream Initialised", node_count);
		discrete_stereo=1;
	}
	else
	{
		int vol = (int)output_node->input[2];
		/* Initialise a stereo, stream, we always use stereo even if only a mono system */
		discrete_stream=stream_init("Discrete Sound",vol,Machine->sample_rate,0,discrete_stream_update_mono);
		discrete_log("discrete_sh_start() - Mono Audio Stream Initialised", node_count);
	}

	if(discrete_stream==-1)
	{
		logerror("discrete_sh_start - Stream init returned an error\n");
		failed=1;
	}

	/* Report success or fail */
	if(!failed) init_ok=1;

	/* Now reset the system to a sensible state */
	discrete_sh_reset();
	discrete_log("discrete_sh_start() - Nodes reset", node_count);

	return failed;
}
예제 #13
0
int YM2151_sh_start(struct YM2151interface *interface,int mode)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2151_NUMBUF][40];
	const char *name[YM2151_NUMBUF];
	int vol;

	if( rate == 0 ) rate = 1000;	/* kludge to prevent nasty crashes */

	intf = interface;

	if( mode ) FMMode = CHIP_YM2151_ALT;
	else       FMMode = CHIP_YM2151_DAC;

	switch(FMMode)
	{
	case CHIP_YM2151_DAC:	/* Tatsuyuki's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				char *chname[2] = { "Lt", "Rt" };
				int ch;


				name[j] = buf[j];
				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;
				sprintf(buf[j],"YM2151 #%d %s",i,chname[ch]);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,(int)(((double)rate)/snd_opm_reduction),Machine->sample_bits,
				i,OPMUpdateOne);
			/* volume setup */
			vol = intf->volume[i] & 0xff;
			for( j=0 ; j < YM2151_NUMBUF ; j++ )
			{
				int ch;

				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;

				stream_set_volume(stream[i]+j,vol);
				stream_set_pan(stream[i]+j,ch ? OSD_PAN_RIGHT : OSD_PAN_LEFT);
			}
		}
		/* Set Timer handler */
		for (i = 0; i < intf->num; i++)
			Timer[i][0] =Timer[i][1] = 0;
		if (OPMInit(intf->num,
//			intf->baseclock,
			((100.0-((snd_opm_reduction-1.0)*10.0))*((double)intf->baseclock))/100.0,
//			Machine->sample_rate,
			((100.0-((snd_opm_reduction-1.0)*10.0))*((double)Machine->sample_rate))/100.0,
			Machine->sample_bits,TimerHandler,0) == 0)
		{
			/* set port handler */
			for (i = 0; i < intf->num; i++)
				OPMSetPortHander(i,intf->portwritehandler[i]);
			return 0;
		}
		/* error */
		return 1;
	case CHIP_YM2151_ALT:	/* Jarek's */
		/* stream system initialize */
		for (i = 0;i < intf->num;i++)
		{
			/* stream setup */
			for (j = 0 ; j < YM2151_NUMBUF ; j++)
			{
				char *chname[2] = { "Lt", "Rt" };
				int ch;


				name[j] = buf[j];
				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;
				sprintf(buf[j],"YM2151 #%d %s",i,chname[ch]);
			}
			stream[i] = stream_init_multi(YM2151_NUMBUF,
				name,rate,Machine->sample_bits,
				i,YM2151UpdateOne);
			/* volume setup */
			vol = intf->volume[i] & 0xff;
			for( j=0 ; j < YM2151_NUMBUF ; j++ )
			{
				int ch;

				ch = j & 1;
				if (intf->volume[i] & YM2151_STEREO_REVERSE)
					ch ^= 1;

				stream_set_volume(stream[i]+j,vol);
				stream_set_pan(stream[i]+j,ch ? OSD_PAN_RIGHT : OSD_PAN_LEFT);
			}
		}
		if (YM2151Init(intf->num,intf->baseclock,Machine->sample_rate,Machine->sample_bits) == 0)
		{
			for (i = 0; i < intf->num; i++)
			{
				YM2151SetIrqHandler(i,intf->irqhandler[i]);
				YM2151SetPortWriteHandler(i,intf->portwritehandler[i]);
			}
			return 0;
		}
		return 1;
	case CHIP_YM2151_OPL:
		break;
	}
	return 1;
}
예제 #14
0
int YM2608_sh_start(const struct MachineSound *msound)
{
	int i,j;
	int rate = Machine->sample_rate;
	char buf[YM2608_NUMBUF][40];
	const char *name[YM2608_NUMBUF];
	int mixed_vol,vol[YM2608_NUMBUF];
	void *pcmbufa[YM2608_NUMBUF];
	int  pcmsizea[YM2608_NUMBUF];
	int rhythm_pos[6+1];
	struct GameSamples	*psSamples;
	int total_size,r_offset,s_size;

	intf = (const struct YM2608interface *)msound->sound_interface;
	if( intf->num > MAX_2608 ) return 1;

	if (AY8910_sh_start(msound)) return 1;

	/* Timer Handler set */
	FMTimerInit();

	/* stream system initialize */
	for (i = 0;i < intf->num;i++)
	{
		/* stream setup */
		mixed_vol = intf->volumeFM[i];
		/* stream setup */
		for (j = 0 ; j < YM2608_NUMBUF ; j++)
		{
			name[j]=buf[j];
			vol[j] = mixed_vol & 0xffff;
			mixed_vol>>=16;
			sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
		}
		stream[i] = stream_init_multi(YM2608_NUMBUF,name,vol,rate,i,YM2608UpdateOne);
		/* setup adpcm buffers */
		pcmbufa[i]  = (void *)(memory_region(intf->pcmrom[i]));
		pcmsizea[i] = memory_region_length(intf->pcmrom[i]);
	}

	/* rythm rom build */
	rhythm_buf = 0;
#ifdef YM2608_USE_SAMPLES
	psSamples = readsamples(ym2608_pDrumNames,"ym2608");
#else
	psSamples = 0;
#endif
	if( psSamples )
	{
		/* calcrate total data size */
		total_size = 0;
		for( i=0;i<6;i++)
		{
			s_size = psSamples->sample[i]->length;
			total_size += s_size ? s_size : 1;
		}
		/* aloocate rythm data */
		rhythm_buf = (short int*)malloc(total_size * sizeof(signed short));
		if( rhythm_buf==0 ) return 0;

		r_offset = 0;
		/* merge sampling data */
		for(i=0;i<6;i++)
		{
			/* set start point */
			rhythm_pos[i] = r_offset*2;
			/* copy sample data */
			s_size = psSamples->sample[i]->length;
			if(s_size && psSamples->sample[i]->data)
			{
				if( psSamples->sample[i]->resolution==16 )
				{
					signed short *s_ptr = (signed short *)psSamples->sample[i]->data;
					for(j=0;j<s_size;j++) rhythm_buf[r_offset++] = *s_ptr++;
				}else{
					signed char *s_ptr = (signed char *)psSamples->sample[i]->data;
					for(j=0;j<s_size;j++) rhythm_buf[r_offset++] = (*s_ptr++)*0x0101;
				}
			}else rhythm_buf[r_offset++] = 0;
			/* set end point */
			rhythm_pos[i+1] = r_offset*2;
		}
		freesamples( psSamples );
	}else
	{
		/* aloocate rythm data */
		rhythm_buf = (short int*)malloc(6 * sizeof(signed short));
		if( rhythm_buf==0 ) return 0;
		for(i=0;i<6;i++)
		{
			/* set start point */
			rhythm_pos[i] = i*2;
			rhythm_buf[i] = 0;
			/* set end point */
			rhythm_pos[i+1] = (i+1)*2;
		}
	}

	/**** initialize YM2608 ****/
	if (YM2608Init(intf->num,intf->baseclock,rate,
		           pcmbufa,pcmsizea,rhythm_buf,rhythm_pos,
		           TimerHandler,IRQHandler) == 0)
		return 0;

	/* error */
	return 1;
}