cassette/misc: small cleanup

This commit is contained in:
hap 2025-04-28 21:46:14 +02:00
parent 8be5131548
commit d937adb6a3
3 changed files with 34 additions and 41 deletions

View File

@ -40,8 +40,8 @@ cassette_image_device::cassette_image_device(const machine_config &mconfig, cons
device_sound_interface(mconfig, *this), device_sound_interface(mconfig, *this),
m_cassette(nullptr), m_cassette(nullptr),
m_state(CASSETTE_STOPPED), m_state(CASSETTE_STOPPED),
m_position(0), m_position(0.0),
m_position_time(0), m_position_time(0.0),
m_value(0), m_value(0),
m_channel(0), m_channel(0),
m_speed(0), m_speed(0),
@ -71,7 +71,7 @@ cassette_image_device::~cassette_image_device()
void cassette_image_device::device_config_complete() void cassette_image_device::device_config_complete()
{ {
m_extension_list[0] = '\0'; 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); 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; 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: case CASSETTE_RECORD:
m_cassette->put_sample(m_channel, m_position, new_position - m_position, m_value); 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; m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED;
new_position = length; new_position = length;
} }
else if (new_position < 0) else if (new_position < 0.0)
{ {
m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED; m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED;
new_position = 0; new_position = 0.0;
} }
} }
break; break;
@ -141,12 +141,11 @@ void cassette_image_device::change_state(cassette_state state, cassette_state ma
double cassette_image_device::input() double cassette_image_device::input()
{ {
update(); update();
int32_t sample = m_value; double value = m_value / (double(0x7fffffff));
double double_value = sample / (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(); update();
value = std::min(value, 1.0); value = std::clamp(value, -1.0, 1.0);
value = std::max(value, -1.0); m_value = int32_t(value * 0x7fffffff);
m_value = int32_t(value * 0x7FFFFFFF);
} }
} }
@ -209,7 +206,8 @@ void cassette_image_device::seek(double time, int origin)
double length = get_length(); double length = get_length();
switch(origin) { switch (origin)
{
case SEEK_SET: case SEEK_SET:
break; break;
@ -222,14 +220,8 @@ void cassette_image_device::seek(double time, int origin)
break; break;
} }
/* clip position into legal bounds */ // clip position into legal bounds
if (time < 0) m_position = std::clamp(time, 0.0, length);
time = 0;
else
if (time > length)
time = length;
m_position = time;
} }
@ -243,7 +235,7 @@ ALLOW_SAVE_TYPE(cassette_state);
void cassette_image_device::device_start() void cassette_image_device::device_start()
{ {
/* set to default state */ // set to default state
m_cassette = nullptr; m_cassette = nullptr;
m_state = m_default_state; m_state = m_default_state;
m_value = 0; 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);) for (std::string extension; std::getline(extension_stream, extension, separator);)
if (is_filetype(extension)) if (is_filetype(extension))
return true; return true;
return false; return false;
} }
@ -291,7 +284,7 @@ std::error_condition cassette_image_device::internal_load(bool is_create)
interface(image); interface(image);
check_for_file(); 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); auto io = util::random_read_write_fill(image_core_file(), 0x00);
if (io) if (io)
@ -343,19 +336,19 @@ std::error_condition cassette_image_device::internal_load(bool is_create)
retry = true; retry = true;
} }
} }
while(retry); while (retry);
} }
if (err == cassette_image::error::SUCCESS) 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); change_state(m_default_state, CASSETTE_MASK_UISTATE);
/* reset the position */ // reset the position
m_position = 0.0; m_position = 0.0;
m_position_time = machine().time().as_double(); 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_channel = 0;
m_speed = 1; m_speed = 1;
m_direction = 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() 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) if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD)
update(); update();
/* close out the cassette */ // close out the cassette
m_cassette.reset(); 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); change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
} }
@ -429,8 +422,8 @@ std::string cassette_image_device::call_display()
// play or record // play or record
const char *status_icon = (uistate == CASSETTE_PLAY) const char *status_icon = (uistate == CASSETTE_PLAY)
? u8"\u25BA" ? u8"\u25ba"
: u8"\u25CF"; : u8"\u25cf";
// create information string // create information string
result = string_format("%s %s %02d:%02d (%04d) [%02d:%02d (%04d)]", result = string_format("%s %s %02d:%02d (%04d) [%02d:%02d (%04d)]",

View File

@ -203,8 +203,8 @@
* DISCRETE_INPUT_NOT(NODE) * DISCRETE_INPUT_NOT(NODE)
* DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT) * DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT)
* DISCRETE_INPUT_PULSE(NODE,INIT) * DISCRETE_INPUT_PULSE(NODE,INIT)
* DISCRETE_INPUT_STREAM(NODE, NUM) * DISCRETE_INPUT_STREAM(NODE,NUM)
* DISCRETE_INPUTX_STREAM(NODE,NUM, GAIN,OFFSET) * DISCRETE_INPUTX_STREAM(NODE,NUM,GAIN,OFFSET)
* *
* DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE) * DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE)
* DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE) * DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE)
@ -442,8 +442,8 @@
* *
* Declaration syntax * Declaration syntax
* *
* DISCRETE_INPUT_STREAM (name of node, stream number, ) * DISCRETE_INPUT_STREAM (name of node, stream number)
* DISCRETE_INPUTX_STREAM(name of node, stream nubmer, gain, offset) * DISCRETE_INPUTX_STREAM(name of node, stream number, gain, offset)
* *
* Note: The discrete system is floating point based. So when routing a stream * 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 * set it's gain to 100% and then use DISCRETE_INPUTX_STREAM to adjust

View File

@ -310,7 +310,7 @@ void sound_direct_sound::stream_sink_update(
if (DS_OK != result) if (DS_OK != result)
return; return;
//DWORD orig_write = write_position; //DWORD orig_write = write_position;
// normalize the write position so it is always after the play position // normalize the write position so it is always after the play position
if (write_position < play_position) if (write_position < play_position)
write_position += m_stream_buffer.size(); 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 // if we're between play and write positions, then bump forward, but only in full chunks
while (stream_in < write_position) 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++; m_buffer_underflows++;
stream_in += bytes_this_frame; 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 we're going to overlap the play position, just skip this chunk
if ((stream_in + bytes_this_frame) > (play_position + m_stream_buffer.size())) 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++; m_buffer_overflows++;
return; return;
} }