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); }
blargg_err_t Nes_Vrc7_Apu::init() { CHECK_ALLOC( opll = OPLL_new( 3579545, 3579545 / 72 ) ); OPLL_SetChipMode((OPLL *) opll, 1); OPLL_setPatch((OPLL *) opll, vrc7_inst); set_output( 0 ); volume( 1.0 ); reset(); return 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); // // // }
NES_VRC7::NES_VRC7 () { patch_set = OPLL_VRC7_RW_TONE; opll = OPLL_new ( 3579545, DEFAULT_RATE); OPLL_reset_patch (opll, patch_set); SetClock(DEFAULT_CLOCK); for(int c=0;c<2;++c) for(int t=0;t<6;++t) sm[c][t] = 128; }
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; }
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; } }
//static DEVICE_START( ym2413 ) int device_start_ym2413(void **_info, int EMU_CORE, int clock, int CHIP_SAMPLING_MODE, int CHIP_SAMPLE_RATE) { //ym2413_state *info = get_safe_token(device); ym2413_state *info; int rate; #ifdef ENABLE_ALL_CORES if (EMU_CORE >= 0x02) EMU_CORE = EC_EMU2413; #else EMU_CORE = EC_EMU2413; #endif info = (ym2413_state *) calloc(1, sizeof(ym2413_state)); *_info = (void*) info; info->EMU_CORE = EMU_CORE; info->Mode = (clock & 0x80000000) >> 31; clock &= 0x7FFFFFFF; rate = clock/72; if ((CHIP_SAMPLING_MODE == 0x01 && rate < CHIP_SAMPLE_RATE) || CHIP_SAMPLING_MODE == 0x02) rate = CHIP_SAMPLE_RATE; /* emulator create */ switch(EMU_CORE) { #ifdef ENABLE_ALL_CORES case EC_MAME: info->chip = ym2413_init(clock, rate); if (info->chip == NULL) return 0; //assert_always(info->chip != NULL, "Error creating YM2413 chip"); ym2413_set_chip_mode(info->chip, info->Mode); /* stream system initialize */ //info->stream = stream_create(device,0,2,rate,info,ym2413_stream_update); ym2413_set_update_handler(info->chip, _stream_update, info); break; #endif case EC_EMU2413: info->chip = OPLL_new(clock, rate); if (info->chip == NULL) return 0; OPLL_SetChipMode(info->chip, info->Mode); if (info->Mode) OPLL_setPatch(info->chip, vrc7_inst); break; } // Note: VRC7 instruments are set in device_reset if necessary. /*#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(device, 0, 1, device->clock/72, i, YM2413DAC_update); if (ym2413[i].DAC_stream == -1) return 1; } return 0; #endif*/ return rate; }
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 ; }