Previous 199869 Revisions Next

r26048 Friday 8th November, 2013 at 03:03:18 UTC by R. Belmont
Added a simple DC blocker filter to the speaker toggle device [R. Belmont]
[src/emu/sound]speaker.c speaker.h

trunk/src/emu/sound/speaker.c
r26047r26048
133133   m_channel_next_sample_time = m_channel_last_sample_time + attotime(0, m_channel_sample_period);
134134   m_next_interm_sample_time = m_channel_last_sample_time + attotime(0, m_interm_sample_period);
135135   m_interm_sample_index = 0;
136   m_prevx = m_prevy = 0.0;
136137
137138   /* Note: To avoid time drift due to floating point inaccuracies,
138139    * it is good if the speaker time synchronizes itself with the stream timing regularly.
r26047r26048
180181   save_item(NAME(m_channel_last_sample_time));
181182   save_item(NAME(m_interm_sample_index));
182183   save_item(NAME(m_last_update_time));
184   save_item(NAME(m_prevx));
185   save_item(NAME(m_prevy));
183186
184187   machine().save().register_postload(save_prepost_delegate(FUNC(speaker_sound_device::speaker_postload), this));
185188}
186189
190void 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
187212void speaker_sound_device::speaker_postload()
188213{
189214   m_channel_next_sample_time = m_channel_last_sample_time + attotime(0, m_channel_sample_period);
r26047r26048
317342
318343double speaker_sound_device::update_interm_samples_get_filtered_volume(int volume)
319344{
320   double filtered_volume;
345   double filtered_volume, tempx;
321346
322347   /* We may have one or more interm. samples to go */
323348   if (m_interm_sample_index < RATE_MULTIPLIER)
r26047r26048
338363   /* Reset counter to next stream sample: */
339364   m_interm_sample_index = 0;
340365
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
341372   return filtered_volume;
342373}
343374
trunk/src/emu/sound/speaker.h
r26047r26048
3939   // device-level overrides
4040   virtual void device_config_complete();
4141   virtual void device_start();
42   virtual void device_reset();
4243
4344   // sound stream update overrides
4445   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
r26047r26048
8081   attotime      m_last_update_time;                 /* internal timestamp */
8182
8283   void speaker_postload();
84
85   // DC blocker state
86   double   m_prevx, m_prevy;
8387};
8488
8589extern const device_type SPEAKER_SOUND;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team