diff options
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/resampler.cpp | 4 | ||||
-rw-r--r-- | src/emu/sound.cpp | 48 | ||||
-rw-r--r-- | src/emu/sound.h | 6 |
3 files changed, 33 insertions, 25 deletions
diff --git a/src/emu/resampler.cpp b/src/emu/resampler.cpp index b86e028ce04..18a5d9f4a21 100644 --- a/src/emu/resampler.cpp +++ b/src/emu/resampler.cpp @@ -231,7 +231,7 @@ u32 audio_resampler_hq::compute_gcd(u32 fs, u32 ft) u32 audio_resampler_hq::history_size() const { - return m_order_per_lane; + return m_order_per_lane + m_skip + 1; } void audio_resampler_hq::apply(const emu::detail::output_buffer_flat<sample_t> &src, std::vector<sample_t> &dest, u64 dest_sample, u32 srcc, float gain, u32 samples) const @@ -382,7 +382,7 @@ audio_resampler_lofi::audio_resampler_lofi(u32 fs, u32 ft) u32 audio_resampler_lofi::history_size() const { - return 5 * m_source_divide; + return 5 * m_source_divide + m_fs / m_ft + 1; } void audio_resampler_lofi::apply(const emu::detail::output_buffer_flat<sample_t> &src, std::vector<sample_t> &dest, u64 dest_sample, u32 srcc, float gain, u32 samples) const diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index 86e1858a7c9..32c341529e0 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -38,7 +38,7 @@ #define LOG_OSD_STREAMS (1U << 3) #define LOG_ORDER (1U << 4) -#define VERBOSE -1 +#define VERBOSE 0 #include "logmacro.h" @@ -498,12 +498,12 @@ u64 sound_stream::get_current_sample_index() const void sound_stream::update() { - if(!is_active() || m_in_update) + if(!is_active() || m_in_update || m_device.machine().phase() <= machine_phase::INIT) return; // Find out where we are and how much we have to do u64 idx = get_current_sample_index(); - m_samples_to_update = idx - m_output_buffer.write_sample(); + m_samples_to_update = !idx ? 0 : idx - m_output_buffer.write_sample() + 1; // We want to include the current sample, hence the +1 if(m_samples_to_update > 0) { m_in_update = true; @@ -520,12 +520,12 @@ void sound_stream::update() void sound_stream::update_nodeps() { - if(!is_active() || m_in_update) + if(!is_active() || m_in_update || m_device.machine().phase() <= machine_phase::INIT) return; // Find out where we are and how much we have to do u64 idx = get_current_sample_index(); - m_samples_to_update = idx - m_output_buffer.write_sample(); + m_samples_to_update = !idx ? 0 : idx - m_output_buffer.write_sample() + 1; // We want to include the current sample, hence the +1 if(m_samples_to_update > 0) { m_in_update = true; @@ -844,7 +844,8 @@ void sound_manager::after_devices_init() m_record_buffer.resize(m_outputs_count * machine().sample_rate(), 0); m_record_samples = 0; - // Resamplers will be created at config load time + // Create resamplers and setup history + rebuild_all_resamplers(); m_effects_done = false; @@ -858,7 +859,7 @@ void sound_manager::after_devices_init() void sound_manager::input_get(int id, sound_stream &stream) { u32 samples = stream.samples(); - u64 end_pos = stream.sample_index(); + u64 end_pos = stream.end_index(); u32 skip = stream.output_count(); for(const auto &step : m_microphones[id].m_input_mixing_steps) { @@ -1129,12 +1130,13 @@ void sound_manager::config_load(config_type cfg_type, config_level cfg_level, ut // and the resampler configuration util::xml::data_node const *rs_node = parentnode->get_child("resampler"); if(rs_node) { - m_resampler_type = rs_node->get_attribute_int("type", RESAMPLER_LOFI); m_resampler_hq_latency = rs_node->get_attribute_float("hq_latency", 0.0050); m_resampler_hq_length = rs_node->get_attribute_int("hq_length", 400); - m_resampler_hq_phases = rs_node->get_attribute_int("hq_phases", 200); + m_resampler_hq_phases = rs_node->get_attribute_int("hq_phases", 200); + + // this also applies the hq settings if resampler is hq + set_resampler_type(rs_node->get_attribute_int("type", RESAMPLER_LOFI)); } - rebuild_all_resamplers(); break; } @@ -2505,31 +2507,39 @@ void sound_manager::rebuild_all_resamplers() stream->create_resamplers(); for(auto &stream : m_stream_list) - stream->lookup_history_sizes(); + stream->lookup_history_sizes(); } void sound_manager::set_resampler_type(u32 type) { - m_resampler_type = type; - rebuild_all_resamplers(); + if(type != m_resampler_type) { + m_resampler_type = type; + rebuild_all_resamplers(); + } } void sound_manager::set_resampler_hq_latency(double latency) { - m_resampler_hq_latency = latency; - rebuild_all_resamplers(); + if(latency != m_resampler_hq_latency) { + m_resampler_hq_latency = latency; + rebuild_all_resamplers(); + } } void sound_manager::set_resampler_hq_length(u32 length) { - m_resampler_hq_length = length; - rebuild_all_resamplers(); + if(length != m_resampler_hq_length) { + m_resampler_hq_length = length; + rebuild_all_resamplers(); + } } void sound_manager::set_resampler_hq_phases(u32 phases) { - m_resampler_hq_phases = phases; - rebuild_all_resamplers(); + if(phases != m_resampler_hq_phases) { + m_resampler_hq_phases = phases; + rebuild_all_resamplers(); + } } const char *sound_manager::resampler_type_names(u32 type) const diff --git a/src/emu/sound.h b/src/emu/sound.h index 6d699dbb8d9..57c96683f0a 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -35,7 +35,7 @@ For example, if you have a 10Hz clock, and call stream.update() at t=0.91, it will compute 10 samples (for clock edges 0.0, 0.1, 0.2, ..., 0.7, 0.8, and 0.9). And then if you ask the stream what its - current end time is (via stream.sample_time()), it will say t=1.0, + current end time is (via stream.end_time()), it will say t=1.0, which is in the future, because it knows it will hold that last sample until 1.0s. @@ -210,11 +210,9 @@ public: // sample id and timing of the first and last sample of the current update block, and first of the next sample block u64 start_index() const { return m_output_buffer.write_sample(); } - u64 end_index() const { return m_output_buffer.write_sample() + samples() - 1; } - u64 sample_index() const { return m_output_buffer.write_sample() + samples(); } + u64 end_index() const { return m_output_buffer.write_sample() + samples(); } attotime start_time() const { return sample_to_time(start_index()); } attotime end_time() const { return sample_to_time(end_index()); } - attotime sample_time() const { return sample_to_time(sample_index()); } // convert from absolute sample index to time attotime sample_to_time(u64 index) const; |