trunk/src/emu/sound/speaker.c
| r26047 | r26048 | |
| 133 | 133 | m_channel_next_sample_time = m_channel_last_sample_time + attotime(0, m_channel_sample_period); |
| 134 | 134 | m_next_interm_sample_time = m_channel_last_sample_time + attotime(0, m_interm_sample_period); |
| 135 | 135 | m_interm_sample_index = 0; |
| 136 | m_prevx = m_prevy = 0.0; |
| 136 | 137 | |
| 137 | 138 | /* Note: To avoid time drift due to floating point inaccuracies, |
| 138 | 139 | * it is good if the speaker time synchronizes itself with the stream timing regularly. |
| r26047 | r26048 | |
| 180 | 181 | save_item(NAME(m_channel_last_sample_time)); |
| 181 | 182 | save_item(NAME(m_interm_sample_index)); |
| 182 | 183 | save_item(NAME(m_last_update_time)); |
| 184 | save_item(NAME(m_prevx)); |
| 185 | save_item(NAME(m_prevy)); |
| 183 | 186 | |
| 184 | 187 | machine().save().register_postload(save_prepost_delegate(FUNC(speaker_sound_device::speaker_postload), this)); |
| 185 | 188 | } |
| 186 | 189 | |
| 190 | void speaker_sound_device::device_reset() |
| 191 | { |
| 192 | int i; |
| 193 | double x; |
| 194 | |
| 195 | m_level = 0; |
| 196 | for (i = 0; i < FILTER_LENGTH; i++) |
| 197 | m_composed_volume[i] = 0; |
| 198 | |
| 199 | m_composed_sample_index = 0; |
| 200 | m_last_update_time = machine().time(); |
| 201 | m_channel_sample_period = HZ_TO_ATTOSECONDS(machine().sample_rate()); |
| 202 | m_channel_sample_period_secfrac = ATTOSECONDS_TO_DOUBLE(m_channel_sample_period); |
| 203 | m_interm_sample_period = m_channel_sample_period / RATE_MULTIPLIER; |
| 204 | m_interm_sample_period_secfrac = ATTOSECONDS_TO_DOUBLE(m_interm_sample_period); |
| 205 | m_channel_last_sample_time = m_channel->sample_time(); |
| 206 | m_channel_next_sample_time = m_channel_last_sample_time + attotime(0, m_channel_sample_period); |
| 207 | m_next_interm_sample_time = m_channel_last_sample_time + attotime(0, m_interm_sample_period); |
| 208 | m_interm_sample_index = 0; |
| 209 | m_prevx = m_prevy = 0.0; |
| 210 | } |
| 211 | |
| 187 | 212 | void speaker_sound_device::speaker_postload() |
| 188 | 213 | { |
| 189 | 214 | m_channel_next_sample_time = m_channel_last_sample_time + attotime(0, m_channel_sample_period); |
| r26047 | r26048 | |
| 317 | 342 | |
| 318 | 343 | double speaker_sound_device::update_interm_samples_get_filtered_volume(int volume) |
| 319 | 344 | { |
| 320 | | double filtered_volume; |
| 345 | double filtered_volume, tempx; |
| 321 | 346 | |
| 322 | 347 | /* We may have one or more interm. samples to go */ |
| 323 | 348 | if (m_interm_sample_index < RATE_MULTIPLIER) |
| r26047 | r26048 | |
| 338 | 363 | /* Reset counter to next stream sample: */ |
| 339 | 364 | m_interm_sample_index = 0; |
| 340 | 365 | |
| 366 | /* simple DC blocker filter */ |
| 367 | tempx = filtered_volume; |
| 368 | filtered_volume = tempx - m_prevx + 0.995 * m_prevy; |
| 369 | m_prevx = tempx; |
| 370 | m_prevy = filtered_volume; |
| 371 | |
| 341 | 372 | return filtered_volume; |
| 342 | 373 | } |
| 343 | 374 | |
trunk/src/emu/sound/speaker.h
| r26047 | r26048 | |
| 39 | 39 | // device-level overrides |
| 40 | 40 | virtual void device_config_complete(); |
| 41 | 41 | virtual void device_start(); |
| 42 | virtual void device_reset(); |
| 42 | 43 | |
| 43 | 44 | // sound stream update overrides |
| 44 | 45 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| r26047 | r26048 | |
| 80 | 81 | attotime m_last_update_time; /* internal timestamp */ |
| 81 | 82 | |
| 82 | 83 | void speaker_postload(); |
| 84 | |
| 85 | // DC blocker state |
| 86 | double m_prevx, m_prevy; |
| 83 | 87 | }; |
| 84 | 88 | |
| 85 | 89 | extern const device_type SPEAKER_SOUND; |