Example #1
0
int     FM_Digital_Init()
{
    ConsolePrintf("%s ", Msg_Get(MSG_Sound_Init_YM2413_Digital));

	opll = OPLL_new(Z80_DEFAULT_CPU_CLOCK, Sound.SampleRate);
    if (opll == NULL)
    {
        ConsolePrintf("%s\n", Msg_Get(MSG_Failed));
        return (MEKA_ERR_FAIL);
    }
	// FIXME-NEWSOUND: FM init
	/*
    FM_Digital_saChannel = stream_init ("YM-2413 #0", g_sasound.audio_sample_rate, 16, 0, FM_Digital_Update);
    if (FM_Digital_saChannel == -1)
    {
        ConsolePrintf ("%s\n", Msg_Get(MSG_Failed));
        return (MEKA_ERR_FAIL); // FIXME: Error in channel creation
    }
    stream_set_volume (FM_Digital_saChannel, VOLUME_MAX);
	*/

    OPLL_reset(opll);

    ConsolePrintf("%s\n", Msg_Get(MSG_Ok));
    return (MEKA_ERR_OK);
}
Example #2
0
void CVRC7::SetSampleSpeed(uint32_t SampleRate, double ClockRate, uint32_t FrameRate)
{
	m_pOPLLInt.reset(OPLL_new(OPL_CLOCK, SampleRate));		// // //

	OPLL_reset(m_pOPLLInt.get());
	OPLL_reset_patch(m_pOPLLInt.get(), 1);

	m_iMaxSamples = (SampleRate / FrameRate) * 2;	// Allow some overflow

	m_iBuffer = std::vector<int16_t>(m_iMaxSamples);		// // //
}
Example #3
0
  void NES_VRC7::Reset ()
  {
    for (int i=0; i < 0x40; ++i)
    {
        Write(0x9010,i);
        Write(0x9030,0);
    }

    divider = 0;
    OPLL_reset_patch (opll, patch_set);
    OPLL_reset (opll);
  }
Example #4
0
void audio_init(int rate)
{
    /* Clear sound context */
    memset(&snd, 0, sizeof(t_snd));

    /* Reset logging data */
    snd.log = 0;
    snd.callback = NULL;

    /* Oops.. sound is disabled */
    if(!rate) return;

    /* Calculate buffer size in samples */
    snd.bufsize = 2048;

    /* Sound output */
#ifdef _3DS

    snd.buffer[0] = (signed short int *)linearAlloc(snd.bufsize * 2);
    snd.buffer[1] = (signed short int *)linearAlloc(snd.bufsize * 2);
#else
    snd.buffer[0] = (signed short int *)malloc(snd.bufsize * 2);
    snd.buffer[1] = (signed short int *)malloc(snd.bufsize * 2);
#endif
    if(!snd.buffer[0] || !snd.buffer[1]) return;
    memset(snd.buffer[0], 0, snd.bufsize * 2);
    memset(snd.buffer[1], 0, snd.bufsize * 2);

    /* YM2413 sound stream */
    snd.fm_buffer = (signed short int *)malloc(snd.bufsize * 2);
    if(!snd.fm_buffer) return;
    memset(snd.fm_buffer, 0, snd.bufsize * 2);

    /* SN76489 sound stream */
    snd.psg_buffer[0] = (signed short int *)malloc(snd.bufsize * 2);
    snd.psg_buffer[1] = (signed short int *)malloc(snd.bufsize * 2);
    if(!snd.psg_buffer[0] || !snd.psg_buffer[1]) return;
    memset(snd.psg_buffer[0], 0, snd.bufsize * 2);
    memset(snd.psg_buffer[1], 0, snd.bufsize * 2);

    /* Set up SN76489 emulation */
    SN76496_init(0, MASTER_CLOCK, 255, rate);

    /* Set up YM2413 emulation */
    OPLL_init(3579545, rate) ;
    opll = OPLL_new() ;
    OPLL_reset(opll) ;
    OPLL_reset_patch(opll,0) ;            /* if use default voice data. */

    /* Inform other functions that we can use sound */
    snd.enabled = 1;
}
Example #5
0
void system_reset(void)
{
    cpu_reset();
    vdp_reset();
    sms_reset();
    render_reset();
    system_load_sram();
    if(snd.enabled)
    {
        OPLL_reset(opll) ;
        OPLL_reset_patch(opll,0) ;            /* if use default voice data. */ 
    }
}
Example #6
0
void FM_Reset(void)
{
    switch(snd.fm_which)
    {
        case SND_EMU2413:
            OPLL_reset(opll);
            OPLL_reset_patch(opll, 0);
            break;

        case SND_YM2413:
            YM2413ResetChip(0);
            break;
        }
}
Example #7
0
void Nes_Vrc7_Apu::reset()
{
	addr      = 0;
	next_time = 0;
	mono.last_amp = 0;

	for ( int i = osc_count; --i >= 0; )
	{
		Vrc7_Osc& osc = oscs [i];
		osc.last_amp = 0;
		for ( int j = 0; j < 3; ++j )
			osc.regs [j] = 0;
	}

	OPLL_reset( (OPLL *) opll );
}
Example #8
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 #9
0
//static DEVICE_RESET( ym2413 )
void device_reset_ym2413(void *_info)
{
	//ym2413_state *info = get_safe_token(device);
	ym2413_state *info = (ym2413_state *)_info;
	switch(info->EMU_CORE)
	{
#ifdef ENABLE_ALL_CORES
	case EC_MAME:
		ym2413_reset_chip(info->chip);
		if (info->Mode)
			ym2413_override_patches(info->chip, vrc7_inst);
		break;
#endif
	case EC_EMU2413:
		OPLL_reset(info->chip);
		// EMU2413 doesn't reset the patch data in OPLL_reset
		//if (info->Mode)
		//	OPLL_setPatch(info->chip, vrc7_inst);
		break;
	}
}
Example #10
0
void system_load_state(void *fd)
{
    int i;
    uint8 reg[0x40];

    /* Initialize everything */
    cpu_reset();
    system_reset();

    /* Load VDP context */
    fread(&vdp, sizeof(t_vdp), 1, fd);

    /* Load SMS context */
    fread(&sms, sizeof(t_sms), 1, fd);

    /* Load Z80 context */
    fread(Z80_Context, sizeof(Z80_Regs), 1, fd);
    fread(&after_EI, sizeof(int), 1, fd);

    /* Load YM2413 registers */
    fread(reg, 0x40, 1, fd);

    /* Load SN76489 context */
    fread(&sn[0], sizeof(t_SN76496), 1, fd);

    /* Restore callbacks */
    z80_set_irq_callback(sms_irq_callback);

    cpu_readmap[0] = cart.rom + 0x0000; /* 0000-3FFF */
    cpu_readmap[1] = cart.rom + 0x2000;
    cpu_readmap[2] = cart.rom + 0x4000; /* 4000-7FFF */
    cpu_readmap[3] = cart.rom + 0x6000;
    cpu_readmap[4] = cart.rom + 0x0000; /* 0000-3FFF */
    cpu_readmap[5] = cart.rom + 0x2000;
    cpu_readmap[6] = sms.ram;
    cpu_readmap[7] = sms.ram;

    cpu_writemap[0] = sms.dummy;
    cpu_writemap[1] = sms.dummy;
    cpu_writemap[2] = sms.dummy;         
    cpu_writemap[3] = sms.dummy;
    cpu_writemap[4] = sms.dummy;         
    cpu_writemap[5] = sms.dummy;
    cpu_writemap[6] = sms.ram;           
    cpu_writemap[7] = sms.ram;

    sms_mapper_w(3, sms.fcr[3]);
    sms_mapper_w(2, sms.fcr[2]);
    sms_mapper_w(1, sms.fcr[1]);
    sms_mapper_w(0, sms.fcr[0]);

    /* Force full pattern cache update */
    is_vram_dirty = 1;
    memset(vram_dirty, 1, 0x200);

    /* Restore palette */
    for(i = 0; i < PALETTE_SIZE; i += 1)
        palette_sync(i);

    /* Restore sound state */
    if(snd.enabled)
    {
        /* Clear YM2413 context */
        OPLL_reset(opll) ;
        OPLL_reset_patch(opll,0) ;            /* if use default voice data. */ 

        /* Restore rhythm enable first */
        ym2413_write(0, 0, 0x0E);
        ym2413_write(0, 1, reg[0x0E]);

        /* User instrument settings */
        for(i = 0x00; i <= 0x07; i += 1)
        {
            ym2413_write(0, 0, i);
            ym2413_write(0, 1, reg[i]);
        }

        /* Channel frequency */
        for(i = 0x10; i <= 0x18; i += 1)
        {
            ym2413_write(0, 0, i);
            ym2413_write(0, 1, reg[i]);
        }

        /* Channel frequency + ctrl. */
        for(i = 0x20; i <= 0x28; i += 1)
        {
            ym2413_write(0, 0, i);
            ym2413_write(0, 1, reg[i]);
        }

        /* Instrument and volume settings  */
        for(i = 0x30; i <= 0x38; i += 1)
        {
            ym2413_write(0, 0, i);
            ym2413_write(0, 1, reg[i]);
        }
    }
}
Example #11
0
// Reset emulated YM-2413
void    FM_Digital_Reset()
{
    OPLL_reset(opll);
}
Example #12
0
int main(void){

  static char wave[DATALENGTH*2] ;
  char filename[16] = "temp.wav" ;
  char header[46] ;
  int i;
  clock_t start,finish ;

  FILE *fp ;
  OPLL *opll ;

  /* Create WAVE header */
  chunkID(header,"RIFF") ;
  DWORD(header+4,DATALENGTH*2+36) ;
  chunkID(header+8,"WAVE") ;
  chunkID(header+12,"fmt ") ;
  DWORD(header+16,16) ;
  WORD(header+20,1) ;                   /* WAVE_FORMAT_PCM */
  WORD(header+22,1) ;                   /* channel 1=mono,2=stereo */
  DWORD(header+24,SAMPLERATE) ;         /* samplesPerSec */
  DWORD(header+28,2*SAMPLERATE) ;       /* bytesPerSec */
  WORD(header+32,2) ;                   /* blockSize */
  WORD(header+34,16) ;                  /* bitsPerSample */
  chunkID(header+36,"data") ;
  DWORD(header+40,2*DATALENGTH) ;

  opll = OPLL_new(MSX_CLK,SAMPLERATE) ;
  OPLL_reset(opll);
  OPLL_writeReg(opll,0x30,0x30) ;   /* select PIANO Voice to ch1. */ 
  OPLL_writeReg(opll,0x10,0x80) ;   /* set F-Number(L). */
  OPLL_writeReg(opll,0x20,0x15) ;   /* set BLK & F-Number(H) and keyon. */

  start = clock() ;

  i=0;

  for(i=0;i<DATALENGTH;i++)
  {
    WORD(wave+i*2,OPLL_calc(opll));
  }

  finish = clock() ;
  OPLL_delete(opll) ;

  printf("It has been %f sec to calc %d waves.\n",
	 (double)(finish-start)/CLOCKS_PER_SEC, DATALENGTH) ;
  printf("%f times faster than real YM2413.\n",
	 ((double)DATALENGTH/SAMPLERATE)/((double)(finish-start)/CLOCKS_PER_SEC)) ;

  fp = fopen(filename,"wb") ;
  
  if(fp == NULL) return 1 ;

  fwrite(header,46,1,fp) ;
  fwrite(wave,DATALENGTH,2,fp) ;
  
  fclose(fp) ;

  printf("Wrote : %s\n",filename) ;

  return 0 ;
}