Example #1
0
void sound_init( void )
{
    /* Initialize FM chip */
    if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
    {
        /* YM2612 */
        YM2612Init();
        YM2612Config(config.dac_bits);
        YM_Reset = YM2612ResetChip;
        YM_Update = YM2612Update;
        YM_Write = YM2612Write;

        /* chip is running a VCLK / 144 = MCLK / 7 / 144 */
        fm_cycles_ratio = 144 * 7;
    }
    else
    {
        /* YM2413 */
        YM2413Init();
        YM_Reset = YM2413ResetChip;
        YM_Update = YM2413Update;
        YM_Write = YM2413Write;

        /* chip is running a ZCLK / 72 = MCLK / 15 / 72 */
        fm_cycles_ratio = 72 * 15;
    }

    /* Initialize PSG chip */
    SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff);
}
Example #2
0
void FM_Init(void)
{
    switch(snd.fm_which)
    {
        case SND_EMU2413:
            OPLL_init(snd.fm_clock, snd.sample_rate);
            opll = OPLL_new();
            OPLL_reset(opll);
            OPLL_reset_patch(opll, 0);
            break;

        case SND_YM2413:
            YM2413Init(1, snd.fm_clock, snd.sample_rate);
            YM2413ResetChip(0);
            break;
    }
}
Example #3
0
static void *ym2413_start(int sndindex, int clock, const void *config)
{
	int rate = clock/72;
	struct ym2413_info *info;

	info = auto_malloc(sizeof(*info));
	memset(info, 0, sizeof(*info));

	/* emulator create */
	info->chip = YM2413Init(clock, rate, sndindex);
	if (!info->chip)
		return NULL;

	/* stream system initialize */
	info->stream = stream_create(0,2,rate,info,ym2413_stream_update);

	YM2413SetUpdateHandler(info->chip, _stream_update, info);

	return info;




#if 0
	int i, tst;
	char name[40];

	num = intf->num;

	tst = YM3812_sh_start (msound);
	if (tst)
		return 1;

	for (i=0;i<num;i++)
	{
		ym2413_reset (i);

		ym2413[i].DAC_stream = stream_create(0, 1, clock/72, i, YM2413DAC_update);

		if (ym2413[i].DAC_stream == -1)
			return 1;
	}
	return 0;
#endif

}
Example #4
0
/* Initialize sound chips emulation */
void sound_init(void)
{
    /* Number of M-cycles executed per second.                                              */
    /*                                                                                      */
    /* All emulated chips are kept in sync by using a common oscillator (MCLOCK)            */
    /*                                                                                      */
    /* The original console would run exactly 53693175 M-cycles (53203424 for PAL), with    */
    /* 3420 M-cycles per line and 262 (313 for PAL) lines per frame, which gives an exact   */
    /* framerate of 59.92 (49.70 for PAL) fps.                                              */
    /*                                                                                      */
    /* Since audio samples are generated at the end of the frame, to prevent audio skipping */
    /* or lag between emulated frames, number of samples rendered per frame must be set to  */
    /* output samplerate (number of samples played per second) divided by output framerate  */
    /* (number of frames emulated per seconds).                                             */
    /*                                                                                      */
    /* On some systems, we may want to achieve 100% smooth video rendering by synchronizing */
    /* frame emulation with VSYNC, which frequency is generally not exactly those values.   */
    /* In that case, number of frames emulated per seconds is the same as the number of     */
    /* frames rendered per seconds by the host system video hardware.                       */
    /*                                                                                      */
    /* When no framerate is specified, base clock is original master clock value.           */
    /* Otherwise, it is based on the output framerate.                                      */
    /*                                                                                      */
    double mclk = snd.frame_rate ? (MCYCLES_PER_LINE * lines_per_frame * snd.frame_rate) : system_clock;

    /* For maximal accuracy, sound chips run in synchronization with 68k and Z80 cpus       */
    /* These values give the exact number of M-cycles executed per internal sample clock:   */
    /* . PSG chip runs at original rate and audio is resampled internally after each update */
    /* . FM chips run by default (if HQ mode disabled) at the output rate directly          */
    /* We use 21.11 fixed point precision (max. mcycle value is 3420*313 i.e 21 bits max)   */
    psg_cycles_ratio  = 16 * 15 * (1 << 11);
    fm_cycles_ratio   = (unsigned int)(mclk / (double) snd.sample_rate * 2048.0);
    psg_cycles_count  = 0;
    fm_cycles_count   = 0;

    /* Initialize PSG core (input clock should be based on emulated system clock) */
    SN76489_Init(mclk/15.0,snd.sample_rate);

    /* Initialize FM cores (input clock and samplerate are only used when HQ mode is disabled) */
    if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
    {
        /* YM2612 */
        YM2612Init(mclk/7.0,snd.sample_rate);
        YM_Reset = YM2612ResetChip;
        YM_Update = YM2612Update;
        YM_Write = YM2612Write;

        /* In HQ mode, YM2612 is running at original rate (one sample each 144*7 M-cycles) */
        /* Audio is resampled externally at the end of a frame. */
        if (config.hq_fm)
        {
            fm_cycles_ratio = 144 * 7 * (1 << 11);
            Fir_Resampler_time_ratio(mclk / (double)snd.sample_rate / (144.0 * 7.0), config.rolloff);
        }
    }
    else
    {
        /* YM2413 */
        YM2413Init(mclk/15.0,snd.sample_rate);
        YM_Reset = YM2413ResetChip;
        YM_Update = YM2413Update;
        YM_Write = YM2413Write;

        /* In HQ mode, YM2413 is running at original rate (one sample each 72*15 M-cycles)  */
        /* Audio is resampled externally at the end of a frame. */
        if (config.hq_fm)
        {
            fm_cycles_ratio = 72 * 15 * (1 << 11);
            Fir_Resampler_time_ratio(mclk / (double)snd.sample_rate / (72.0 * 15.0), config.rolloff);
        }
    }

#ifdef LOGSOUND
    error("%f mcycles per second\n", mclk);
    error("%d mcycles per PSG sample\n", psg_cycles_ratio);
    error("%d mcycles per FM sample\n", fm_cycles_ratio);
#endif
}