static SID6581 *get_sid(int indx) { SID6581 *sid = NULL; #if HAS_SID6581 if (!sid) sid = sndti_token(SOUND_SID6581, indx); #endif #if HAS_SID8580 if (!sid) sid = sndti_token(SOUND_SID8580, indx); #endif return sid; }
void namco_63701x_write(int offset, int data) { struct namco_63701x *chip = sndti_token(SOUND_NAMCO_63701X, 0); int ch = offset / 2; if (offset & 1) chip->voices[ch].select = data; else { /* should we stop the playing sample if voice_select[ch] == 0 ? originally we were, but this makes us lose a sample in genpeitd, after the continue counter reaches 0. Either we shouldn't stop the sample, or genpeitd is returning to the title screen too soon. */ if (chip->voices[ch].select & 0x1f) { int rom_offs; /* update the streams */ stream_update(chip->stream); chip->voices[ch].playing = 1; chip->voices[ch].base_addr = 0x10000 * ((chip->voices[ch].select & 0xe0) >> 5); rom_offs = chip->voices[ch].base_addr + 2 * ((chip->voices[ch].select & 0x1f) - 1); chip->voices[ch].position = (chip->rom[rom_offs] << 8) + chip->rom[rom_offs+1]; /* bits 6-7 = volume */ chip->voices[ch].volume = data >> 6; /* bits 0-5 = counter to indicate new sample start? we don't use them */ chip->voices[ch].silence_counter = 0; } }
void filter_rc_set_RC(int num, int R1, int R2, int R3, int C) { struct filter_rc_info *info = sndti_token(SOUND_FILTER_RC, num); float f_R1,f_R2,f_R3,f_C; float Req; if(!info) return; stream_update(info->stream); if (C == 0) { /* filter disabled */ info->k = 0; return; } f_R1 = R1; f_R2 = R2; f_R3 = R3; f_C = (float)C * 1E-12; /* convert pF to F */ /* Cut Frequency = 1/(2*Pi*Req*C) */ Req = (f_R1 * (f_R2 + f_R3)) / (f_R1 + f_R2 + f_R3); /* k = (1-(EXP(-TIMEDELTA/RC))) */ info->k = 0x10000 * (1 - (exp(-1 / (Req * f_C) / Machine->sample_rate))); }
/* mixer_play_sample() */ void sample_start_n(int num,int channel,int samplenum,int loop) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; struct loaded_sample *sample; assert( info->samples != NULL ); assert( samplenum < info->samples->total ); assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); /* update the parameters */ sample = &info->samples->sample[samplenum]; chan->source = sample->data; chan->source_length = sample->length; chan->source_num = sample->data ? samplenum : -1; chan->pos = 0; chan->frac = 0; chan->basefreq = sample->frequency; chan->step = ((INT64)chan->basefreq << FRAC_BITS) / Machine->sample_rate; chan->loop = loop; }
void MSM5205_playmode_w(int num,int select) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); static const int prescaler_table[4] = {96,48,64,0}; int prescaler = prescaler_table[select & 3]; int bitwidth = (select & 4) ? 4 : 3; if( voice->prescaler != prescaler ) { stream_update(voice->stream,0); voice->prescaler = prescaler; /* timer set */ if( prescaler ) { double period = TIME_IN_HZ(voice->clock / prescaler); timer_adjust_ptr(voice->timer, period, period); } else timer_adjust_ptr(voice->timer, TIME_NEVER, 0); } if( voice->bitwidth != bitwidth ) { stream_update(voice->stream,0); voice->bitwidth = bitwidth; } }
void MSM5205_data_w (int num, int data) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); if( voice->bitwidth == 4) voice->data = data & 0x0f; else voice->data = (data & 0x07)<<1; /* unknown */ }
void ay8910_set_volume(int chip,int channel,int volume) { ay8910_context *psg = sndti_token(SOUND_AY8910, chip); int ch; for (ch = 0; ch < psg->streams; ch++) if (channel == ch || psg->streams == 1 || channel == ALL_8910_CHANNELS) stream_set_output_gain(psg->channel, ch, volume / 100.0); }
void AY8910_set_volume(int chip,int channel,int volume) { struct AY8910 *PSG = sndti_token(SOUND_AY8910, chip); int ch; for (ch = 0; ch < PSG->streams; ch++) if (channel == ch || PSG->streams == 1 || channel == ALL_8910_CHANNELS) stream_set_output_gain(PSG->Channel, ch, volume / 100.0); }
void beep_set_volume(int num, int volume) { struct beep_sound *info = sndti_token(SOUND_BEEP, num); stream_update(info->stream); volume = 100 * volume / 7; sndti_set_output_gain(SOUND_BEEP, num, 0, volume ); }
void sample_set_volume_n(int num,int channel,float volume) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; stream_set_output_gain(chan->stream, 0, volume); }
void DAC_signed_data_w(int num,UINT8 data) { struct dac_info *info = sndti_token(SOUND_DAC, num); INT16 out = info->SignedVolTable[data]; if (info->output != out) { /* update the output buffer before changing the registers */ stream_update(info->channel); info->output = out; } }
void DAC_data_16_w(int num,UINT16 data) { struct dac_info *info = sndti_token(SOUND_DAC, num); INT16 out = data >> 1; /* range 0..32767 */ if (info->output != out) { /* update the output buffer before changing the registers */ stream_update(info->channel); info->output = out; } }
void beep_set_frequency(int num,int frequency) { struct beep_sound *info = sndti_token(SOUND_BEEP, num); if (info->frequency == frequency) return; stream_update(info->stream); info->frequency = frequency; info->signal = 0x07fff; info->incr = 0; }
int sample_get_base_freq_n(int num,int channel) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); return chan->basefreq; }
int sample_playing_n(int num,int channel) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); return (chan->source != NULL); }
void DAC_signed_data_16_w(int num,UINT16 data) { struct dac_info *info = sndti_token(SOUND_DAC, num); INT16 out = (INT32)data - (INT32)0x08000; /* range -32768..32767 */ /* casts avoid potential overflow on some ABIs */ if (info->output != out) { /* update the output buffer before changing the registers */ stream_update(info->channel); info->output = out; } }
void sample_stop_n(int num,int channel) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); chan->source = NULL; chan->source_num = -1; }
void sample_set_freq_n(int num,int channel,int freq) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); chan->step = ((INT64)freq << FRAC_BITS) / Machine->sample_rate; }
int sample_loaded_n(int num,int samplenum) { int ret = 0; struct samples_info *info = sndti_token(SOUND_SAMPLES, num); if (info->samples != NULL) { assert( samplenum < info->samples->total ); ret = (info->samples->sample[samplenum].data != NULL); } return ret; }
void sample_set_pause_n(int num,int channel,int pause) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); chan->paused = pause; }
void beep_set_state( int num, int on ) { struct beep_sound *info = sndti_token(SOUND_BEEP, num); /* only update if new state is not the same as old state */ if (info->enable == on) return; stream_update(info->stream); info->enable = on; /* restart wave from beginning */ info->incr = 0; info->signal = 0x07fff; }
/* * Handle an update of the vclk status of a chip (1 is reset ON, 0 is reset OFF) * This function can use selector = MSM5205_SEX only */ void MSM5205_vclk_w (int num, int vclk) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); if( voice->prescaler != 0 ) { logerror("error: MSM5205_vclk_w() called with chip = %d, but VCLK selected master mode\n", num); } else { if( voice->vclk != vclk) { voice->vclk = vclk; if( !vclk ) MSM5205_vclk_callback(voice); } } }
void mm6221aa_tune_w(int chip, int tune) { struct TMS36XX *tms = sndti_token(SOUND_TMS36XX, chip); /* which tune? */ tune &= 3; if( tune == tms->tune_num ) return; LOG(("%s tune:%X\n", tms->subtype, tune)); /* update the stream before changing the tune */ stream_update(tms->channel); tms->tune_num = tune; tms->tune_ofs = 0; tms->tune_max = 96; /* fixed for now */ }
static void saa1099_control_port_w( int chip, int reg, int data ) { struct SAA1099 *saa = sndti_token(SOUND_SAA1099, chip); if ((data & 0xff) > 0x1c) { /* Error! */ logerror("%04x: (SAA1099 #%d) Unknown register selected\n",activecpu_get_pc(), chip); } saa->selected_reg = data & 0x1f; if (saa->selected_reg == 0x18 || saa->selected_reg == 0x19) { /* clock the envelope channels */ if (saa->env_clock[0]) saa1099_envelope(saa,0); if (saa->env_clock[1]) saa1099_envelope(saa,1); } }
void tms36xx_note_w(int chip, int octave, int note) { struct TMS36XX *tms = sndti_token(SOUND_TMS36XX, chip); octave &= 3; note &= 15; if (note > 12) return; LOG(("%s octave:%X note:%X\n", tms->subtype, octave, note)); /* update the stream before changing the tune */ stream_update(tms->channel); /* play a single note from 'tune 4', a list of the 13 tones */ tms36xx_reset_counters(tms); tms->octave = octave; tms->tune_num = 4; tms->tune_ofs = note; tms->tune_max = note + 1; }
void sample_start_raw_n(int num,int channel,INT16 *sampledata,int samples,int frequency,int loop) { struct samples_info *info = sndti_token(SOUND_SAMPLES, num); struct sample_channel *chan; assert( channel < info->numchannels ); chan = &info->channel[channel]; /* force an update before we start */ stream_update(chan->stream); /* update the parameters */ chan->source = sampledata; chan->source_length = samples; chan->source_num = -1; chan->pos = 0; chan->frac = 0; chan->basefreq = frequency; chan->step = ((INT64)chan->basefreq << FRAC_BITS) / Machine->sample_rate; chan->loop = loop; }
static void saa1099_write_port_w( int chip, int offset, int data ) { struct SAA1099 *saa = sndti_token(SOUND_SAA1099, chip); int reg = saa->selected_reg; int ch; /* first update the stream to this point in time */ stream_update(saa->stream); switch (reg) { /* channel i amplitude */ case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: ch = reg & 7; saa->channels[ch].amplitude[LEFT] = amplitude_lookup[data & 0x0f]; saa->channels[ch].amplitude[RIGHT] = amplitude_lookup[(data >> 4) & 0x0f]; break; /* channel i frequency */ case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: ch = reg & 7; saa->channels[ch].frequency = data & 0xff; break; /* channel i octave */ case 0x10: case 0x11: case 0x12: ch = (reg - 0x10) << 1; saa->channels[ch + 0].octave = data & 0x07; saa->channels[ch + 1].octave = (data >> 4) & 0x07; break; /* channel i frequency enable */ case 0x14: saa->channels[0].freq_enable = data & 0x01; saa->channels[1].freq_enable = data & 0x02; saa->channels[2].freq_enable = data & 0x04; saa->channels[3].freq_enable = data & 0x08; saa->channels[4].freq_enable = data & 0x10; saa->channels[5].freq_enable = data & 0x20; break; /* channel i noise enable */ case 0x15: saa->channels[0].noise_enable = data & 0x01; saa->channels[1].noise_enable = data & 0x02; saa->channels[2].noise_enable = data & 0x04; saa->channels[3].noise_enable = data & 0x08; saa->channels[4].noise_enable = data & 0x10; saa->channels[5].noise_enable = data & 0x20; break; /* noise generators parameters */ case 0x16: saa->noise_params[0] = data & 0x03; saa->noise_params[1] = (data >> 4) & 0x03; break; /* envelope generators parameters */ case 0x18: case 0x19: ch = reg - 0x18; saa->env_reverse_right[ch] = data & 0x01; saa->env_mode[ch] = (data >> 1) & 0x07; saa->env_bits[ch] = data & 0x10; saa->env_clock[ch] = data & 0x20; saa->env_enable[ch] = data & 0x80; /* reset the envelope */ saa->env_step[ch] = 0; break; /* channels enable & reset generators */ case 0x1c: saa->all_ch_enable = data & 0x01; saa->sync_state = data & 0x02; if (data & 0x02) { int i; /* Synch & Reset generators */ logerror("%04x: (SAA1099 #%d) -reg 0x1c- Chip reset\n",activecpu_get_pc(), chip); for (i = 0; i < 6; i++) { saa->channels[i].level = 0; saa->channels[i].counter = 0.0; } } break; default: /* Error! */ logerror("%04x: (SAA1099 #%d) Unknown operation (reg:%02x, data:%02x)\n",activecpu_get_pc(), chip, reg, data); } }
void CDDA_set_cdrom(int num, void *file) { struct cdda_info *info = sndti_token(SOUND_CDDA, num); info->disc = (cdrom_file *)file; }
void MSM5205_reset_w (int num, int reset) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); voice->reset = reset; }
void MSM5205_set_volume(int num,int volume) { struct MSM5205Voice *voice = sndti_token(SOUND_MSM5205, num); stream_set_output_gain(voice->stream,0,volume / 100.0); }