static void *ym2608_start(int sndindex, int clock, const void *config) { static const struct YM2608interface generic_2608 = { { AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT, AY8910_DEFAULT_LOADS, NULL, NULL, NULL, NULL }, NULL, 0, }; const struct YM2608interface *intf = config ? config : &generic_2608; int rate = clock/72; void *pcmbufa; int pcmsizea; struct ym2608_info *info; info = auto_malloc(sizeof(*info)); memset(info, 0, sizeof(*info)); info->intf = intf; /* FIXME: Force to use simgle output */ info->psg = ay8910_start_ym(SOUND_YM2608, sndindex, clock, &intf->ay8910_intf); if (!info->psg) return NULL; /* Timer Handler set */ info->timer[0] = timer_alloc(timer_callback_2608_0, info); info->timer[1] = timer_alloc(timer_callback_2608_1, info); /* stream system initialize */ info->stream = stream_create(0,2,rate,info,ym2608_stream_update); /* setup adpcm buffers */ pcmbufa = (void *)(memory_region(info->intf->pcmrom)); pcmsizea = memory_region_length(info->intf->pcmrom); /* initialize YM2608 */ info->chip = YM2608Init(info,sndindex,clock,rate, pcmbufa,pcmsizea, timer_handler,IRQHandler,&psgintf); state_save_register_postload(Machine, ym2608_postload, info); if (info->chip) return info; /* error */ return NULL; }
static void *ym2608_start(int sndindex, int clock, const void *config) { static const struct YM2608interface generic_2608 = { 0 }; const struct YM2608interface *intf = config ? config : &generic_2608; int rate = Machine->sample_rate; void *pcmbufa; int pcmsizea; struct ym2608_info *info; info = auto_malloc(sizeof(*info)); memset(info, 0, sizeof(*info)); info->intf = intf; info->psg = ay8910_start_ym(SOUND_YM2608, sndindex, clock, 1, intf->portAread, intf->portBread, intf->portAwrite, intf->portBwrite); if (!info->psg) return NULL; /* Timer Handler set */ info->timer[0] =timer_alloc_ptr(timer_callback_2608_0, info); info->timer[1] =timer_alloc_ptr(timer_callback_2608_1, info); /* stream system initialize */ info->stream = stream_create(0,2,rate,info,ym2608_stream_update); /* setup adpcm buffers */ pcmbufa = (void *)(memory_region(info->intf->pcmrom)); pcmsizea = memory_region_length(info->intf->pcmrom); /* initialize YM2608 */ info->chip = YM2608Init(info,sndindex,clock,rate, pcmbufa,pcmsizea, TimerHandler,IRQHandler,&psgintf); state_save_register_func_postload_ptr(ym2608_postload, info); if (info->chip) return info; /* error */ return NULL; }
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; }