trunk/src/mess/drivers/channelf.c
| r21509 | r21510 | |
| 133 | 133 | WRITE8_MEMBER( channelf_state::channelf_port_5_w ) |
| 134 | 134 | { |
| 135 | 135 | m_latch[3] = data; |
| 136 | | channelf_sound_w(machine().device("custom"), (data>>6)&3); |
| 136 | m_custom->sound_w((data>>6)&3); |
| 137 | 137 | m_row_reg = (data | 0xc0) ^ 0xff; |
| 138 | 138 | } |
| 139 | 139 | |
| r21509 | r21510 | |
| 277 | 277 | |
| 278 | 278 | /* sound hardware */ |
| 279 | 279 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 280 | | MCFG_SOUND_ADD("custom", CHANNELF, 0) |
| 280 | MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0) |
| 281 | 281 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 282 | 282 | |
| 283 | 283 | MCFG_FRAGMENT_ADD( channelf_cart ) |
| r21509 | r21510 | |
| 303 | 303 | |
| 304 | 304 | /* sound hardware */ |
| 305 | 305 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 306 | | MCFG_SOUND_ADD("custom", CHANNELF, 0) |
| 306 | MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0) |
| 307 | 307 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 308 | 308 | |
| 309 | 309 | MCFG_FRAGMENT_ADD( channelf_cart ) |
| r21509 | r21510 | |
| 330 | 330 | |
| 331 | 331 | /* sound hardware */ |
| 332 | 332 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 333 | | MCFG_SOUND_ADD("custom", CHANNELF, 0) |
| 333 | MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0) |
| 334 | 334 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 335 | 335 | |
| 336 | 336 | MCFG_FRAGMENT_ADD( channelf_cart ) |
| r21509 | r21510 | |
| 357 | 357 | |
| 358 | 358 | /* sound hardware */ |
| 359 | 359 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 360 | | MCFG_SOUND_ADD("custom", CHANNELF, 0) |
| 360 | MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0) |
| 361 | 361 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 362 | 362 | |
| 363 | 363 | MCFG_FRAGMENT_ADD( channelf_cart ) |
trunk/src/mess/audio/channelf.c
| r21509 | r21510 | |
| 1 | | #include "includes/channelf.h" |
| 1 | #include "emu.h" |
| 2 | #include "audio/channelf.h" |
| 2 | 3 | |
| 3 | 4 | |
| 4 | | static const int max_amplitude = 0x7fff; |
| 5 | #define MAX_AMPLITUDE 0x7fff |
| 5 | 6 | |
| 6 | | struct channelf_sound_state |
| 7 | | { |
| 8 | | sound_stream *channel; |
| 9 | | int sound_mode; |
| 10 | | int incr; |
| 11 | | float decay_mult; |
| 12 | | int envelope; |
| 13 | | UINT32 sample_counter; |
| 14 | | int forced_ontime; // added for improved sound |
| 15 | | int min_ontime; // added for improved sound |
| 16 | | }; |
| 7 | const device_type CHANNELF_SOUND = &device_creator<channelf_sound_device>; |
| 17 | 8 | |
| 18 | | INLINE channelf_sound_state *get_safe_token(device_t *device) |
| 9 | channelf_sound_device::channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 10 | : device_t(mconfig, CHANNELF_SOUND, "Channel F Sound", tag, owner, clock), |
| 11 | device_sound_interface(mconfig, *this), |
| 12 | m_channel(NULL), |
| 13 | m_sound_mode(0), |
| 14 | m_incr(0), |
| 15 | m_decay_mult(0), |
| 16 | m_envelope(0), |
| 17 | m_sample_counter(0), |
| 18 | m_forced_ontime(0), |
| 19 | m_min_ontime(0) |
| 19 | 20 | { |
| 20 | | assert(device != NULL); |
| 21 | | assert(device->type() == CHANNELF); |
| 22 | | return (channelf_sound_state *)downcast<channelf_sound_device *>(device)->token(); |
| 21 | |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | | void channelf_sound_w(device_t *device, int mode) |
| 26 | | { |
| 27 | | channelf_sound_state *state = get_safe_token(device); |
| 28 | | if (mode == state->sound_mode) |
| 29 | | return; |
| 24 | //------------------------------------------------- |
| 25 | // device_config_complete - perform any |
| 26 | // operations now that the configuration is |
| 27 | // complete |
| 28 | //------------------------------------------------- |
| 30 | 29 | |
| 31 | | state->channel->update(); |
| 32 | | state->sound_mode = mode; |
| 33 | | |
| 34 | | switch(mode) |
| 35 | | { |
| 36 | | case 0: |
| 37 | | state->envelope = 0; |
| 38 | | state->forced_ontime = 0; // added for improved sound |
| 39 | | break; |
| 40 | | case 1: |
| 41 | | case 2: |
| 42 | | case 3: |
| 43 | | state->envelope = max_amplitude; |
| 44 | | state->forced_ontime = state->min_ontime; // added for improved sound |
| 45 | | break; |
| 46 | | } |
| 47 | | } |
| 48 | | |
| 49 | | |
| 50 | | |
| 51 | | static STREAM_UPDATE( channelf_sh_update ) |
| 30 | void channelf_sound_device::device_config_complete() |
| 52 | 31 | { |
| 53 | | channelf_sound_state *state = get_safe_token(device); |
| 54 | | UINT32 mask = 0, target = 0; |
| 55 | | stream_sample_t *buffer = outputs[0]; |
| 56 | | stream_sample_t *sample = buffer; |
| 57 | | |
| 58 | | switch( state->sound_mode ) |
| 59 | | { |
| 60 | | case 0: /* sound off */ |
| 61 | | memset(buffer,0,sizeof(*buffer)*samples); |
| 62 | | return; |
| 63 | | |
| 64 | | case 1: /* high tone (2V) - 1000Hz */ |
| 65 | | mask = 0x00010000; |
| 66 | | target = 0x00010000; |
| 67 | | break; |
| 68 | | case 2: /* medium tone (4V) - 500Hz */ |
| 69 | | mask = 0x00020000; |
| 70 | | target = 0x00020000; |
| 71 | | break; |
| 72 | | case 3: /* low (weird) tone (32V & 8V) */ |
| 73 | | mask = 0x00140000; |
| 74 | | target = 0x00140000; |
| 75 | | break; |
| 76 | | } |
| 77 | | |
| 78 | | while (samples-- > 0) |
| 79 | | { |
| 80 | | if ((state->forced_ontime > 0) || ((state->sample_counter & mask) == target)) // change made for improved sound |
| 81 | | *sample++ = state->envelope; |
| 82 | | else |
| 83 | | *sample++ = 0; |
| 84 | | state->sample_counter += state->incr; |
| 85 | | state->envelope *= state->decay_mult; |
| 86 | | if (state->forced_ontime > 0) // added for improved sound |
| 87 | | state->forced_ontime -= 1; // added for improved sound |
| 88 | | } |
| 89 | 32 | } |
| 90 | 33 | |
| 34 | //------------------------------------------------- |
| 35 | // device_start - device-specific startup |
| 36 | //------------------------------------------------- |
| 91 | 37 | |
| 92 | | |
| 93 | | static DEVICE_START(channelf_sound) |
| 38 | void channelf_sound_device::device_start() |
| 94 | 39 | { |
| 95 | | channelf_sound_state *state = get_safe_token(device); |
| 96 | 40 | int rate; |
| 97 | 41 | |
| 98 | | state->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, channelf_sh_update); |
| 99 | | rate = device->machine().sample_rate(); |
| 42 | m_channel = stream_alloc(0, 1, machine().sample_rate()); |
| 43 | rate = machine().sample_rate(); |
| 100 | 44 | |
| 101 | 45 | /* |
| 102 | 46 | * 2V = 1000Hz ~= 3579535/224/16 |
| r21509 | r21510 | |
| 117 | 61 | */ |
| 118 | 62 | |
| 119 | 63 | /* This is the proper value to add per sample */ |
| 120 | | state->incr = 65536.0/(rate/1000.0/2.0); |
| 64 | m_incr = 65536.0/(rate/1000.0/2.0); |
| 121 | 65 | |
| 122 | 66 | // added for improved sound |
| 123 | 67 | /* This is the minimum forced ontime, in samples */ |
| 124 | | state->min_ontime = rate/1000*2; /* approx 2ms - estimated, not verified on HW */ |
| 68 | m_min_ontime = rate/1000*2; /* approx 2ms - estimated, not verified on HW */ |
| 125 | 69 | |
| 126 | 70 | /* This was measured, decay envelope with half life of ~9ms */ |
| 127 | 71 | /* (this is decay multiplier per sample) */ |
| 128 | | state->decay_mult = exp((-0.693/9e-3)/rate); |
| 72 | m_decay_mult = exp((-0.693/9e-3)/rate); |
| 129 | 73 | |
| 130 | 74 | /* initial conditions */ |
| 131 | | state->envelope = 0; |
| 75 | m_envelope = 0; |
| 132 | 76 | } |
| 133 | 77 | |
| 134 | | const device_type CHANNELF = &device_creator<channelf_sound_device>; |
| 135 | | |
| 136 | | channelf_sound_device::channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 137 | | : device_t(mconfig, CHANNELF, "Channel F", tag, owner, clock), |
| 138 | | device_sound_interface(mconfig, *this) |
| 139 | | { |
| 140 | | m_token = global_alloc_clear(channelf_sound_state); |
| 141 | | } |
| 142 | | |
| 143 | 78 | //------------------------------------------------- |
| 144 | | // device_config_complete - perform any |
| 145 | | // operations now that the configuration is |
| 146 | | // complete |
| 79 | // sound_stream_update - handle a stream update |
| 147 | 80 | //------------------------------------------------- |
| 148 | 81 | |
| 149 | | void channelf_sound_device::device_config_complete() |
| 82 | void channelf_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 150 | 83 | { |
| 151 | | } |
| 84 | UINT32 mask = 0, target = 0; |
| 85 | stream_sample_t *buffer = outputs[0]; |
| 86 | stream_sample_t *sample = buffer; |
| 152 | 87 | |
| 153 | | //------------------------------------------------- |
| 154 | | // device_start - device-specific startup |
| 155 | | //------------------------------------------------- |
| 88 | switch( m_sound_mode ) |
| 89 | { |
| 90 | case 0: /* sound off */ |
| 91 | memset(buffer,0,sizeof(*buffer)*samples); |
| 92 | return; |
| 156 | 93 | |
| 157 | | void channelf_sound_device::device_start() |
| 158 | | { |
| 159 | | DEVICE_START_NAME( channelf_sound )(this); |
| 94 | case 1: /* high tone (2V) - 1000Hz */ |
| 95 | mask = 0x00010000; |
| 96 | target = 0x00010000; |
| 97 | break; |
| 98 | case 2: /* medium tone (4V) - 500Hz */ |
| 99 | mask = 0x00020000; |
| 100 | target = 0x00020000; |
| 101 | break; |
| 102 | case 3: /* low (weird) tone (32V & 8V) */ |
| 103 | mask = 0x00140000; |
| 104 | target = 0x00140000; |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | while (samples-- > 0) |
| 109 | { |
| 110 | if ((m_forced_ontime > 0) || ((m_sample_counter & mask) == target)) // change made for improved sound |
| 111 | *sample++ = m_envelope; |
| 112 | else |
| 113 | *sample++ = 0; |
| 114 | m_sample_counter += m_incr; |
| 115 | m_envelope *= m_decay_mult; |
| 116 | if (m_forced_ontime > 0) // added for improved sound |
| 117 | m_forced_ontime -= 1; // added for improved sound |
| 118 | } |
| 160 | 119 | } |
| 161 | 120 | |
| 162 | | //------------------------------------------------- |
| 163 | | // sound_stream_update - handle a stream update |
| 164 | | //------------------------------------------------- |
| 165 | | |
| 166 | | void channelf_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 121 | void channelf_sound_device::sound_w(int mode) |
| 167 | 122 | { |
| 168 | | // should never get here |
| 169 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
| 123 | if (mode == m_sound_mode) |
| 124 | return; |
| 125 | |
| 126 | m_channel->update(); |
| 127 | m_sound_mode = mode; |
| 128 | |
| 129 | switch(mode) |
| 130 | { |
| 131 | case 0: |
| 132 | m_envelope = 0; |
| 133 | m_forced_ontime = 0; // added for improved sound |
| 134 | break; |
| 135 | case 1: |
| 136 | case 2: |
| 137 | case 3: |
| 138 | m_envelope = MAX_AMPLITUDE; |
| 139 | m_forced_ontime = m_min_ontime; // added for improved sound |
| 140 | break; |
| 141 | } |
| 170 | 142 | } |
trunk/src/mess/includes/channelf.h
| r21509 | r21510 | |
| 10 | 10 | #include "emu.h" |
| 11 | 11 | #include "cpu/f8/f8.h" |
| 12 | 12 | #include "imagedev/cartslot.h" |
| 13 | #include "audio/channelf.h" |
| 13 | 14 | |
| 14 | 15 | |
| 15 | 16 | /* SKR - 2102 RAM chip on carts 10 and 18 I/O ports */ |
| r21509 | r21510 | |
| 27 | 28 | { |
| 28 | 29 | public: |
| 29 | 30 | channelf_state(const machine_config &mconfig, device_type type, const char *tag) |
| 30 | | : driver_device(mconfig, type, tag) { } |
| 31 | : driver_device(mconfig, type, tag), |
| 32 | m_custom(*this,"custom") { } |
| 31 | 33 | |
| 32 | 34 | DECLARE_READ8_MEMBER(channelf_port_0_r); |
| 33 | 35 | DECLARE_READ8_MEMBER(channelf_port_1_r); |
| r21509 | r21510 | |
| 52 | 54 | virtual void palette_init(); |
| 53 | 55 | UINT32 screen_update_channelf(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 54 | 56 | DECLARE_DEVICE_IMAGE_LOAD_MEMBER( channelf_cart ); |
| 57 | required_device<channelf_sound_device> m_custom; |
| 55 | 58 | }; |
| 56 | 59 | |
| 57 | | |
| 58 | | /*----------- defined in video/channelf.c -----------*/ |
| 59 | | |
| 60 | | |
| 61 | | |
| 62 | | |
| 63 | | |
| 64 | | |
| 65 | | /*----------- defined in audio/channelf.c -----------*/ |
| 66 | | |
| 67 | | class channelf_sound_device : public device_t, |
| 68 | | public device_sound_interface |
| 69 | | { |
| 70 | | public: |
| 71 | | channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 72 | | ~channelf_sound_device() { global_free(m_token); } |
| 73 | | |
| 74 | | // access to legacy token |
| 75 | | void *token() const { assert(m_token != NULL); return m_token; } |
| 76 | | protected: |
| 77 | | // device-level overrides |
| 78 | | virtual void device_config_complete(); |
| 79 | | virtual void device_start(); |
| 80 | | |
| 81 | | // sound stream update overrides |
| 82 | | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 83 | | private: |
| 84 | | // internal state |
| 85 | | void *m_token; |
| 86 | | }; |
| 87 | | |
| 88 | | extern const device_type CHANNELF; |
| 89 | | |
| 90 | | |
| 91 | | void channelf_sound_w(device_t *device, int mode); |
| 92 | | |
| 93 | | |
| 94 | 60 | #endif /* CHANNELF_H_ */ |