2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
20 void BEEP::write_signal(int id, uint32_t data, uint32_t mask)
22 if(id == SIG_BEEP_ON) {
24 on = ((data & mask) != 0);
25 } else if(id == SIG_BEEP_MUTE) {
27 mute = ((data & mask) != 0);
31 void BEEP::mix(int32_t* buffer, int cnt)
34 for(int i = 0; i < cnt; i++) {
35 int sample = (count < 1024) ? (gen_vol * (count - 512)) / 512 : gen_vol;
36 int vol_l = apply_volume(sample, volume_l);
37 int vol_r = apply_volume(sample, volume_r);
38 *buffer++ += signal ? vol_l : -vol_l; // L
39 *buffer++ += signal ? vol_r : -vol_r; // R
40 if((count -= 1024) < 0) {
48 void BEEP::set_volume(int ch, int decibel_l, int decibel_r)
50 volume_l = decibel_to_volume(decibel_l);
51 volume_r = decibel_to_volume(decibel_r);
54 void BEEP::initialize_sound(int rate, double frequency, int volume)
58 set_frequency(frequency);
61 void BEEP::set_frequency(double frequency)
63 diff = (int)(1024.0 * gen_rate / frequency / 2.0 + 0.5);
66 #define STATE_VERSION 1
68 bool BEEP::process_state(FILEIO* state_fio, bool loading)
70 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
73 if(!state_fio->StateCheckInt32(this_device_id)) {
76 state_fio->StateBool(signal);
77 state_fio->StateInt32(count);
78 state_fio->StateBool(on);
79 state_fio->StateBool(mute);