diff options
author | 2025-04-28 21:46:14 +0200 | |
---|---|---|
committer | 2025-04-28 21:46:47 +0200 | |
commit | d937adb6a3b60a839c08dabb399b069b150c55c3 (patch) | |
tree | c8bb02f05a84347bcac6719f8e42fbbfa481759c | |
parent | 8be5131548b1719db9fbabf6955dbb1583507328 (diff) |
cassette/misc: small cleanup
-rw-r--r-- | src/devices/imagedev/cassette.cpp | 61 | ||||
-rw-r--r-- | src/devices/sound/discrete.h | 8 | ||||
-rw-r--r-- | src/osd/modules/sound/direct_sound.cpp | 6 |
3 files changed, 34 insertions, 41 deletions
diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp index 21e5ab72b3f..cef022b57a5 100644 --- a/src/devices/imagedev/cassette.cpp +++ b/src/devices/imagedev/cassette.cpp @@ -40,8 +40,8 @@ cassette_image_device::cassette_image_device(const machine_config &mconfig, cons device_sound_interface(mconfig, *this), m_cassette(nullptr), m_state(CASSETTE_STOPPED), - m_position(0), - m_position_time(0), + m_position(0.0), + m_position_time(0.0), m_value(0), m_channel(0), m_speed(0), @@ -71,7 +71,7 @@ cassette_image_device::~cassette_image_device() void cassette_image_device::device_config_complete() { m_extension_list[0] = '\0'; - for (int i = 0; m_formats[i]; i++ ) + for (int i = 0; m_formats[i]; i++) image_specify_extension(m_extension_list, 256, m_formats[i]->extensions); } @@ -88,7 +88,7 @@ void cassette_image_device::update() { double new_position = m_position + (cur_time - m_position_time) * m_speed * m_direction; - switch (m_state & CASSETTE_MASK_UISTATE) // cast to int to suppress unhandled enum value warning + switch (m_state & CASSETTE_MASK_UISTATE) { case CASSETTE_RECORD: m_cassette->put_sample(m_channel, m_position, new_position - m_position, m_value); @@ -105,10 +105,10 @@ void cassette_image_device::update() m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED; new_position = length; } - else if (new_position < 0) + else if (new_position < 0.0) { m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED; - new_position = 0; + new_position = 0.0; } } break; @@ -141,12 +141,11 @@ void cassette_image_device::change_state(cassette_state state, cassette_state ma double cassette_image_device::input() { update(); - int32_t sample = m_value; - double double_value = sample / (double(0x7FFFFFFF)); + double value = m_value / (double(0x7fffffff)); - LOGMASKED(LOG_DETAIL, "cassette_input(): time_index=%g value=%g\n", m_position, double_value); + LOGMASKED(LOG_DETAIL, "cassette_input(): time_index=%g value=%g\n", m_position, value); - return double_value; + return value; } @@ -157,10 +156,8 @@ void cassette_image_device::output(double value) { update(); - value = std::min(value, 1.0); - value = std::max(value, -1.0); - - m_value = int32_t(value * 0x7FFFFFFF); + value = std::clamp(value, -1.0, 1.0); + m_value = int32_t(value * 0x7fffffff); } } @@ -209,7 +206,8 @@ void cassette_image_device::seek(double time, int origin) double length = get_length(); - switch(origin) { + switch (origin) + { case SEEK_SET: break; @@ -222,14 +220,8 @@ void cassette_image_device::seek(double time, int origin) break; } - /* clip position into legal bounds */ - if (time < 0) - time = 0; - else - if (time > length) - time = length; - - m_position = time; + // clip position into legal bounds + m_position = std::clamp(time, 0.0, length); } @@ -243,7 +235,7 @@ ALLOW_SAVE_TYPE(cassette_state); void cassette_image_device::device_start() { - /* set to default state */ + // set to default state m_cassette = nullptr; m_state = m_default_state; m_value = 0; @@ -281,6 +273,7 @@ bool cassette_image_device::has_any_extension(std::string_view candidate_extensi for (std::string extension; std::getline(extension_stream, extension, separator);) if (is_filetype(extension)) return true; + return false; } @@ -291,7 +284,7 @@ std::error_condition cassette_image_device::internal_load(bool is_create) interface(image); check_for_file(); - if (is_create || (length()==0)) // empty existing images are fine to write over. + if (is_create || (length() == 0)) // empty existing images are fine to write over. { auto io = util::random_read_write_fill(image_core_file(), 0x00); if (io) @@ -343,19 +336,19 @@ std::error_condition cassette_image_device::internal_load(bool is_create) retry = true; } } - while(retry); + while (retry); } if (err == cassette_image::error::SUCCESS) { - /* set to default state, but only change the UI state */ + // set to default state, but only change the UI state change_state(m_default_state, CASSETTE_MASK_UISTATE); - /* reset the position */ + // reset the position m_position = 0.0; m_position_time = machine().time().as_double(); - /* default channel to 0, speed multiplier to 1 */ + // default channel to 0, speed multiplier to 1 m_channel = 0; m_speed = 1; m_direction = 1; @@ -391,14 +384,14 @@ std::error_condition cassette_image_device::internal_load(bool is_create) void cassette_image_device::call_unload() { - /* if we are recording, write the value to the image */ + // if we are recording, write the value to the image if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD) update(); - /* close out the cassette */ + // close out the cassette m_cassette.reset(); - /* set to default state, but only change the UI state */ + // set to default state, but only change the UI state change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); } @@ -429,8 +422,8 @@ std::string cassette_image_device::call_display() // play or record const char *status_icon = (uistate == CASSETTE_PLAY) - ? u8"\u25BA" - : u8"\u25CF"; + ? u8"\u25ba" + : u8"\u25cf"; // create information string result = string_format("%s %s %02d:%02d (%04d) [%02d:%02d (%04d)]", diff --git a/src/devices/sound/discrete.h b/src/devices/sound/discrete.h index aa90b83b3f9..2a5b34dfef6 100644 --- a/src/devices/sound/discrete.h +++ b/src/devices/sound/discrete.h @@ -203,8 +203,8 @@ * DISCRETE_INPUT_NOT(NODE) * DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT) * DISCRETE_INPUT_PULSE(NODE,INIT) - * DISCRETE_INPUT_STREAM(NODE, NUM) - * DISCRETE_INPUTX_STREAM(NODE,NUM, GAIN,OFFSET) + * DISCRETE_INPUT_STREAM(NODE,NUM) + * DISCRETE_INPUTX_STREAM(NODE,NUM,GAIN,OFFSET) * * DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE) * DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE) @@ -442,8 +442,8 @@ * * Declaration syntax * - * DISCRETE_INPUT_STREAM (name of node, stream number, ) - * DISCRETE_INPUTX_STREAM(name of node, stream nubmer, gain, offset) + * DISCRETE_INPUT_STREAM (name of node, stream number) + * DISCRETE_INPUTX_STREAM(name of node, stream number, gain, offset) * * Note: The discrete system is floating point based. So when routing a stream * set it's gain to 100% and then use DISCRETE_INPUTX_STREAM to adjust diff --git a/src/osd/modules/sound/direct_sound.cpp b/src/osd/modules/sound/direct_sound.cpp index dd931988f30..7417def934c 100644 --- a/src/osd/modules/sound/direct_sound.cpp +++ b/src/osd/modules/sound/direct_sound.cpp @@ -310,7 +310,7 @@ void sound_direct_sound::stream_sink_update( if (DS_OK != result) return; -//DWORD orig_write = write_position; + //DWORD orig_write = write_position; // normalize the write position so it is always after the play position if (write_position < play_position) write_position += m_stream_buffer.size(); @@ -326,7 +326,7 @@ void sound_direct_sound::stream_sink_update( // if we're between play and write positions, then bump forward, but only in full chunks while (stream_in < write_position) { -//printf("Underflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)m_stream_buffer_in, (int)bytes_this_frame); + //printf("Underflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)m_stream_buffer_in, (int)bytes_this_frame); m_buffer_underflows++; stream_in += bytes_this_frame; } @@ -334,7 +334,7 @@ void sound_direct_sound::stream_sink_update( // if we're going to overlap the play position, just skip this chunk if ((stream_in + bytes_this_frame) > (play_position + m_stream_buffer.size())) { -//printf("Overflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)m_stream_buffer_in, (int)bytes_this_frame); + //printf("Overflow: PP=%d WP=%d(%d) SI=%d(%d) BTF=%d\n", (int)play_position, (int)write_position, (int)orig_write, (int)stream_in, (int)m_stream_buffer_in, (int)bytes_this_frame); m_buffer_overflows++; return; } |