1 // license:GPL-2.0+ 2 // copyright-holders:Jarek Burczynski, Hiromitsu Shioya 3 #ifndef MAME_SOUND_MSM5232_H 4 #define MAME_SOUND_MSM5232_H 5 6 #pragma once 7 8 9 class msm5232_device : public device_t, 10 public device_sound_interface 11 { 12 public: 13 msm5232_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); 14 15 void set_capacitors(double cap1, double cap2, double cap3, double cap4, double cap5, double cap6, double cap7, double cap8); gate()16 auto gate() { return m_gate_handler_cb.bind(); } 17 18 void write(offs_t offset, uint8_t data); 19 void set_clock(int clock); 20 21 protected: 22 // device-level overrides 23 virtual void device_start() override; 24 virtual void device_stop() override; 25 virtual void device_reset() override; 26 virtual void device_post_load() override; 27 28 // sound stream update overrides 29 virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; 30 31 private: 32 struct VOICE { 33 uint8_t mode; 34 35 int TG_count_period; 36 int TG_count; 37 38 uint8_t TG_cnt; /* 7 bits binary counter (frequency output) */ 39 uint8_t TG_out16; /* bit number (of TG_cnt) for 16' output */ 40 uint8_t TG_out8; /* bit number (of TG_cnt) for 8' output */ 41 uint8_t TG_out4; /* bit number (of TG_cnt) for 4' output */ 42 uint8_t TG_out2; /* bit number (of TG_cnt) for 2' output */ 43 44 int egvol; 45 int eg_sect; 46 int counter; 47 int eg; 48 49 uint8_t eg_arm; /* attack/release mode */ 50 51 double ar_rate; 52 double dr_rate; 53 double rr_rate; 54 55 int pitch; /* current pitch data */ 56 57 int GF; 58 }; 59 60 // internal state 61 sound_stream *m_stream; 62 63 VOICE m_voi[8]; 64 65 uint32_t m_EN_out16[2]; /* enable 16' output masks for both groups (0-disabled ; ~0 -enabled) */ 66 uint32_t m_EN_out8[2]; /* enable 8' output masks */ 67 uint32_t m_EN_out4[2]; /* enable 4' output masks */ 68 uint32_t m_EN_out2[2]; /* enable 2' output masks */ 69 70 int m_noise_cnt; 71 int m_noise_step; 72 int m_noise_rng; 73 int m_noise_clocks; /* number of the noise_rng (output) level changes */ 74 75 unsigned int m_UpdateStep; 76 77 /* rate tables */ 78 double m_ar_tbl[8]; 79 double m_dr_tbl[16]; 80 81 uint8_t m_control1; 82 uint8_t m_control2; 83 84 int m_gate; /* current state of the GATE output */ 85 86 int m_chip_clock; /* chip clock in Hz */ 87 int m_rate; /* sample rate in Hz */ 88 89 double m_external_capacity[8]; /* in Farads, eg 0.39e-6 = 0.36 uF (microFarads) */ 90 devcb_write_line m_gate_handler_cb;/* callback called when the GATE output pin changes state */ 91 92 void init_tables(); 93 void init_voice(int i); 94 void gate_update(); 95 void init(int clock, int rate); 96 void EG_voices_advance(); 97 void TG_group_advance(int groupidx); 98 }; 99 100 DECLARE_DEVICE_TYPE(MSM5232, msm5232_device) 101 102 #endif // MAME_SOUND_MSM5232_H 103