Commit Graph

75 Commits

Author SHA1 Message Date
couriersud
fe1e26a9fb
sound.cpp: Fix missed samples due to state save (#9917) (#9918)
* sound.cpp: Fix missed samples due to state save (#9917)

The PR address #9917. A save state may occur between time slices.
Sound devices through sound.cpp are updated during a timer call every
20ms. When the state is saved, these devices are not updated to the
current machine time. Consequently after a state load the devices have
have a "time lag" since in postload buffer end time is forced to
machine time.
This change will save the last buffer end time so that all outstanding
samples are processed.

This is a core change. I tested it on some drivers. This needs a very
thorough review and I post the PR primarily to document a possible
solution.

* sound.cpp: use "stream.sound_stream" as module name for save_item

* sound.cpp: use presave handler to store end_time()
2022-06-15 12:39:00 +02:00
AJR
ca79d71af4 Remove void *ptr parameter from emu_timer, timer_device and all related callbacks 2022-01-26 08:56:03 -05:00
AJR
fab3259f43 sound.h: Suppress sound_assert errors for fill and copy-type operations when start index is out of range 2021-12-20 06:43:24 -05:00
hap
c9c3cac6c2 sound: make the compressor optional (clamp overdrive to -1.0-1.0 when off) 2021-09-24 19:40:10 +02:00
Aaron Giles
97d7bfab03 Add compile-time option to show visible annoying red border when sound is overdriven. Leaving it on for a bit at the start of the cycle so that devs might identify and fix some of these cases. 2021-08-23 10:47:54 -07:00
Vas Crabb
3715746131 API cleanups and miscellaneous fixes.
emu/ioport.cpp: Allow controller files to override input sequences for
inputs that don't use defaults, and to override the toggle setting for
digital inputs.

emu/config.cpp: Expose configuration level (mostly matters for
controller files), improved verbose diagnostic messages, and moved a few
things out of the global and preprocessor namespaces.

docs: Added documentation for some controller configuration file
features.  The device mapping feature documentation will be merged in at
some point.

util/unicode.cpp, emu/input.cpp: API cleanups.
2021-07-15 13:54:40 +10:00
Aaron Giles
20fceccf39 sound: Fix wrapping bug when using fill/copy/bulk-add on write_stream_views 2021-04-21 22:48:47 -07:00
AJR
bcf647342a Use std::clamp in various core functions 2021-02-03 17:45:21 -05:00
Vas Crabb
9e36b6a6d9 More Lua interface cleanup - it's simpler with cleaner underlyng APIs.
Made the sound manager mute controls readable, and got rid of system
enable since it just controls system mute anyway.  This was causing
confusion: phantom2 was trying to use both independentlyt casuing the
mute bit to be ignored.

THe Lua interface changes are mostly changing methods to properties,
some renames to make things clearer, and some additional properties for
better control over snapshots.
2020-12-27 01:32:37 +11:00
Aaron Giles
7b8913fefa
Complete sound modernization of remaining devices. Legacy callbacks and stream_sample_t removed. (#7297)
* a2mcms/coco_ssc/gus/cassette/floppy/8364_paula/laserdsc/s2636/spg2xx_audio/arcadia/channelf/cmi01a/cps3/dai_snd: Update to new stream callbacks

* dsbz80/elan_eu3a05/exidy/exidy440/flower/geebee/gomoku/gridlee: Update to new stream callbacks

* hyprolyb/lynx/micro3d/phoenix/pleiads/polepos: Update to new sound stream callback

* redbaron/segag80r/segausb/seibu/snk6502/socrates/special/svis_snd: Update to new stream callbacks.

* tiamc1/turrett/tvc/tx1/vboy/vc4000: Update to new stream callbacks

* warpwarp/wiping/wswan/xavix/esq1/istrebiteli/milton6805/pv1000/mega32x/gic: Update to new stream callback

* sound: Remove legacy stream support and stream_sample_t

* * gomoku/wiping: Remove silly mixer tables in favor of math

* micro3d: Remove tiny vectors in favor of fixed arrays

* phoenix: Went back to std::unique_ptr array for LFSR

* wiping: Fixed the scale factor.
2020-09-28 13:46:58 +10:00
Vas Crabb
6e807013c5 Disable SOUND_DEBUG for non-debug builds, and srcclean 2020-09-27 11:00:56 +10:00
Aaron Giles
4849a5aeba sound: Add a few new helpers to write_stream_view
* put_clamp - clamps the input value before writing
* put_int - takes an integer and coverts it to float
* put_int_clamp - converts and clamps an integer
* add_int - converts an int and adds to the current sample
2020-09-20 19:40:21 -07:00
Aaron Giles
aba8c220e8 sound: Some optimizations for common cases
* Reuse resamplers if routing the same output to multiple targets at the same rate
* Avoid copying when there's only one stream going through a mixer
2020-09-17 13:45:13 -07:00
Aaron Giles
8d7d01caef Revert "sound: Improved view interfaces to match usage patterns"
This reverts commit dc0ede3c90.
2020-09-17 01:24:17 -07:00
Aaron Giles
dc0ede3c90 sound: Improved view interfaces to match usage patterns
* read/write_stream_views now have an internal index
* get/put/add/fill/copy now implicitly use and advance this index
* new method reset() can (re)set the internal index
* new method done() checks if index is past the end
* new method remaining() indicates how many samples remain
* get_indexed/put_indexed/etc available for random access
* updated all consumers to new interfaces
2020-09-17 00:46:06 -07:00
Aaron Giles
949da6a0b0 sound: Fix edge case where pending sample rate matches output. 2020-09-14 15:24:22 -07:00
Aaron Giles
c1bd56f0d3
Significant internal changes to sound streams (#7169)
Significant internal changes to sound streams:

Abstracted buffers of sound data into an internal stream_buffer class, with helper classes read_stream_view and write_stream_view which offer readable/writable "views" into the buffers

Internal sound calculations are all done using stream_buffer::sample_t, which is a 32-bit float; existing callbacks are supported through an adapter that converts to/from signed 32-bit integers

Improved behavior of dynamic stream sample rate changes to resample a short runway of data to preserve continuity across transitions

Created a new stream update callback which passes a std::vector of read_stream_views for inputs, and a std::vector of write_stream_views for outputs

Updated core mixer and speaker devices to the new stream update callback

Updated the following sound cores to the new stream update callback: ay8910, dac, k054539, msm5205, namco, netlist, okim6295, pokey, samples, sn76496, sp0250, tms5220, tms57002, upd7759, vgm_visualizer, volt_reg

Changed existing stream update callback to make inputs explicitly const and the output pointers const as well, since they are re-used across calls; fixed several engines that violated this rule

Sound_manager::stream_alloc can no longer automatically connect to a device's sound_stream_update callback; instead, the stream_alloc() on the sound_device_interface should be called; updated many violators of this rule

Streams can be created with SAMPLE_RATE_OUTPUT_ADAPTIVE, which dynamically tracks the sample rate of its first downstream output, or with SAMPLE_RATE_INPUT_ADAPTIVE, which tracks the sample rate of its first input

Changed resampling to be a separate sound_stream that is invoked as needed, opening the path for selectable resampling implementations

Added a flags parameter to the new stream allocation method that allows you to specify a that input streams should not be resampled

Exposed stream_input and stream_output classes directly, simplifying access to user gains and stream names

Added a simple dynamic compressor to sound_manager to provide nicer results when overdriven sound happens; compression does not affect speaker_report results

Improved verbose speaker_report to print a graph of peaks over time

More aggressive debugging enabled for now even in release builds (should be disabled prior to next release) via SOUND_DEBUG define in sound.h; report any assertions for fixing
2020-09-13 10:18:44 -07:00
feos
b8986566ef Expose sound buffer and samplerate to luaengine (#5497)
* luaengine: manager:machine():sound():samples()

* luaengine: fix natural_keyboard docs

* tiny cleanup as requested in #5348

* fix clang build
2019-08-17 11:50:48 -04:00
smf-
2c31275f79 sound_stream::sample_rate() was broken since adding support for setting a zero rate, nothing appears to rely on it (nw) 2018-08-09 20:34:19 +01:00
Vas Crabb
ba5715596a This causes huge changes in behaviour that can't be hand-waved away.
Revert "Removal of voltage_regulator_device (nw)"

This reverts commit 1af133752a.

Revert "New way to provide DAC reference inputs (nw)"

This reverts commit 1c6a7ab40c.
2018-01-13 02:06:27 +11:00
AJR
1c6a7ab40c New way to provide DAC reference inputs (nw)
- Introduce MCFG_SOUND_REFERENCE_INPUT to provide fixed inputs through the resampler, eliminating the need for the "voltage regulator" device
- Replace memset use in sound.cpp with std::fill

This was my third implementation of this concept. The previous two involved attaching sound streams to the dummy device (which required giving it device_sound_interface and other modifications).
2018-01-10 02:11:14 -05:00
Vas Crabb
96c9112785 general cleanup:
* move rarely-used output and pty interfaces out of emu.h
* consolidate and de-duplicate forward declarations, also remove some obsolete ones
* clean up more #include guard macros
* scope down a few more things

(nw) Everyone, please keep forward declarations for src/emu in src/emu/emufwd.h -
this will make it far easier to keep them in sync with declarations than having
them scattered through all the other files.
2017-05-23 15:01:11 +10:00
Vas Crabb
c8f1954467 XML refactoring:
* move stuff to namespace util::xml
* scope down some enums
* split config load/save delegate types
* make config load take const so it can't mangle data
2016-12-11 18:15:41 +11:00
Vas Crabb
8179a84458 Introduce u8/u16/u32/u64/s8/s16/s32/s64
* New abbreviated types are in osd and util namespaces, and also in global namespace for things that #include "emu.h"
* Get rid of import of cstdint types to global namespace (C99 does this anyway)
* Remove the cstdint types from everything in emu
* Get rid of U64/S64 macros
* Fix a bug in dps16 caused by incorrect use of macro
* Fix debugcon not checking for "do " prefix case-insensitively
* Fix a lot of messed up tabulation
* More constexpr
* Fix up many __names
2016-11-19 05:38:48 +11:00
Miodrag Milanovic
ddb290d5f6 NOTICE (TYPE NAME CONSOLIDATION)
Use standard uint64_t, uint32_t, uint16_t or uint8_t instead of UINT64, UINT32, UINT16 or UINT8
also use standard int64_t, int32_t, int16_t or int8_t instead of INT64, INT32, INT16 or INT8
2016-10-22 13:13:17 +02:00
Miodrag Milanovic
025756c2d6 simple_list to vector in sound (nw) 2016-06-19 10:10:11 +02:00
AJR
ec2669cacf Machine management cleanups
- Boolean parameter to running_machine::run is no longer firstrun (which is now a member variable of mame_machine_manager) but quiet, which disables logging and audio recording without explicitly checking the system name.
- Sound recording is now turned on and off by explicit calls. The potential uses of this have not been explored.
- Dependencies reduced on drivenum.h, where the declaration for GAME_NAME(___empty) has been moved to.
2016-04-25 19:59:42 -04:00
AJR
b0e033146a Avoid auto return types; silence some unused variable warnings (nw) 2016-03-31 13:50:31 -04:00
AJR
a7e393b36b Iterate over core classes C++11 style
C++11 range-based for loops can now iterate over simple_list, tagged_list, core_options, device_t::subdevice_list, device_t::interface_list, render_primitive_list and all subclasses of the above, and much code has been refactored to use them. Most core classes that have these lists as members now have methods that return the lists themselves, replacing most of the methods that returned the object at an owned list's head. (A few have been retained due to their use in drivers or OSD.)

device_t now manages subdevice and interface lists through subclasses, but has given up the work of adding and removing subdevices to machine_config.

memory_manager has its tagged lists exposed, though the old rooted tag lookup methods have been removed (they were privatized already).
2016-03-31 09:43:53 -04:00
AJR
d5ea912ddd Have sound_stream::input_name return the std::string it constructs 2016-01-24 16:28:11 -05:00
Miodrag Milanovic
3e5ad46410 modernized configuration_manager (nw) 2016-01-10 15:17:18 +01:00
Miodrag Milanovic
91605d3f4d clang-modernize part 1 (nw) 2015-12-03 18:17:25 +01:00
Miodrag Milanovic
54f8b3ae5d moved all to std::string (nw) 2015-04-22 11:30:45 +02:00
Olivier Galibert
278cf84e55 Replace dynamic_array with std::vector [O. Galibert] 2015-04-14 19:58:17 +02:00
Miodrag Milanovic
87f705b984 string -> str rename due to future conflicts (nw) 2015-04-12 16:54:10 +02:00
Miodrag Milanovic
79246ab917 More cleanups, there is issue with srcclean that needs to be taken care as well, just doing now what we can 2014-07-22 06:21:54 +00:00
Miodrag Milanovic
40d14ae043 got rid of legacy STREAM_UPDATE, created stream_update_delegate and now
stub is no longer needed, also made easy to have stream with different
update call (nw)
2014-04-30 19:20:19 +00:00
Olivier Galibert
8a8028a891 konamigx: Reverb me harder baby! [O. Galibert] 2014-04-08 20:43:13 +00:00
Oliver Stöneberg
87bd8e7e7f flagged STREAM_UPDATE as legacy (nw) 2014-03-24 09:53:25 +00:00
Aaron Giles
5d0ce54f9e Bulk convert files that already had standard BSD license in my name
to new license tagged form.
2013-10-16 08:14:49 +00:00
Miodrag Milanovic
0e19f641d3 Cleanups and version bump 2013-01-11 07:32:46 +00:00
Aaron Giles
1a30184903 Final round of struct/union/enum normalization. 2012-09-16 05:24:30 +00:00
Aaron Giles
6105173076 Separated user gain from input gain. Added more functions to
map inputs and devices to outputs in sound streams. Some
general cleanups in the sound/streaming code.
2012-04-26 08:36:24 +00:00
Aaron Giles
9465d7393d Make all items connected to mixer inputs available in the UI, not just items
connected to speakers.
2012-02-28 09:21:05 +00:00
Aaron Giles
5e964d09ce Latest delegate changes removed the need for bindable_object, so
get rid of it across the board.
2011-04-29 20:45:40 +00:00
Aaron Giles
af94c692bb Switch to using delegates for some callbacks:
- non-device timer callbacks
 - machine state changing callbacks
 - configuration callbacks
 - per-screen VBLANK callbacks
 - DRC backend callbacks

For the timer case only, I added wrappers for the old-style functions.
Over time, drivers should switch to device timers instead, reducing the
number of timers that are directly allocated through the scheduler.
2011-04-27 20:34:45 +00:00
Aaron Giles
fecfc465df Switch from m_machine to machine() everywhere. In some cases this
meant adding a machine() accessor but it's worth it for consistency.
This will allow future changes from reference to pointer to happen
transparently for devices. [Aaron Giles]

Simple S&R:
m_machine( *[^ (!=;])
machine()\1
2011-04-18 20:06:43 +00:00
Aaron Giles
2ad5072023 BIG update.
Remove redundant machine items from address_space and device_t.
Neither machine nor m_machine are directly accessible anymore.
Instead a new getter machine() is available which returns a
machine reference. So:

  space->machine->xxx   ==>  space->machine().xxx
  device->machine->yyy  ==>  device->machine().yyy

Globally changed all running_machine pointers to running_machine
references. Any function/method that takes a running_machine takes
it as a required parameter (1 or 2 exceptions). Being consistent
here gets rid of a lot of odd &machine or *machine, but it does
mean a very large bulk change across the project.

Structs which have a running_machine * now have that variable
renamed to m_machine, and now have a shiny new machine() method
that works like the space and device methods above. Since most of
these are things that should eventually be devices anyway, consider
this a step in that direction.

98% of the update was done with regex searches. The changes are
architected such that the compiler will catch the remaining
errors:

// find things that use an embedded machine directly and replace
// with a machine() getter call
S: ->machine->
R: ->machine\(\)\.

// do the same if via a reference
S: \.machine->
R: \.machine\(\)\.

// convert function parameters to running_machine &
S: running_machine \*machine([^;])
R: running_machine \&machine\1

// replace machine-> with machine.
S: machine->
R: machine\.

// replace &machine() with machine()
S: \&([()->a-z0-9_]+machine\(\))
R: \1

// sanity check: look for this used as a cast
(running_machine &)
// and change to this:
*(running_machine *)
2011-03-29 15:50:04 +00:00
Aaron Giles
4fa610aa02 Cleanups and version bump. 2011-02-09 15:01:01 +00:00
Aaron Giles
1e88333178 Converted attotime to a class, with proper operators. Removed old
global functions which are now superceded by the operators and
methods on the class. [Aaron Giles]

Required mappings are:

attotime_make(a,b)            => attotime(a,b)
attotime_to_double(t)         => t.as_double()
double_to_attotime(d)         => attotime::from_double(d)
attotime_to_attoseconds(t)    => t.as_attoseconds()
attotime_to_ticks(t,f)        => t.as_ticks(f)
ticks_to_attotime(t,f)        => attotime::from_ticks(t,f)
attotime_add(a,b)             => a + b
attotime_add_attoseconds(a,b) => a + attotime(0, b)
attotime_sub(a,b)             => a - b
attotime_sub_attoseconds(a,b) => a - attotime(0, b)
attotime_compare(a,b) == 0    => a == b
attotime_compare(a,b) != 0    => a != b
attotime_compare(a,b) < 0     => a < b
attotime_compare(a,b) <= 0    => a <= b
attotime_compare(a,b) > 0     => a > b
attotime_compare(a,b) >= 0    => a >= b
attotime_mul(a,f)             => a * f
attotime_div(a,f)             => a / f
attotime_min(a,b)             => min(a,b)
attotime_max(a,b)             => max(a,b)
attotime_is_never(t)          => t.is_never()
attotime_string(t,p)          => t.as_string(p)

In addition, some existing #defines still exist but will go away:

attotime_zero                 => attotime::zero
attotime_never                => attotime::never
ATTOTIME_IN_SEC(s)            => attotime::from_seconds(s)
ATTOTIME_IN_MSEC(m)           => attotime::from_msec(m)
ATTOTIME_IN_USEC(u)           => attotime::from_usec(u)
ATTOTIME_IN_NSEC(n)           => attotime::from_nsec(n)
ATTOTIME_IN_HZ(h)             => attotime::from_hz(h)
2011-02-03 07:52:45 +00:00