Commit Graph

4540 Commits

Author SHA1 Message Date
David Reid c8c11615e3 Try fixing the Emscripten build. 2026-02-14 20:55:02 +10:00
David Reid dbf391611d Add resampling test. 2026-02-14 20:26:20 +10:00
David Reid d286a97ab1 Fix some warnings with MSVC. 2026-02-14 20:24:52 +10:00
David Reid 5ffa29a80b Clear out an out of date test. 2026-02-14 20:20:28 +10:00
David Reid ec69cafef8 Fix a typo. 2026-02-14 17:08:26 +10:00
David Reid 6adcbf9034 API CHANGE: Remove some functions relating to resampling.
The following functions are removed:

    ma_linear_resampler_get_required_input_frame_count()
    ma_linear_resampler_get_expected_output_frame_count()
    ma_resampler_get_required_input_frame_count()
    ma_resampler_get_expected_output_frame_count()
    ma_data_converter_get_required_input_frame_count()
    ma_data_converter_get_expected_output_frame_count()

These functions were used for calculating the required number of input
frames given an output capacity, and the number of expected number of
output frames given an input frame count. In practice these have proven
to be extremely annoying and finicky to get right. I myself have had
trouble keeping this working consistently as I make changes to the
processing function and I have zero confidence custom resampling
backends will implement this correctly.

If you need this functionality, take a copy of the resampler from
miniaudio 0.11.x and maintain that yourself.
2026-02-14 17:08:11 +10:00
David Reid fd1369b3fc Resampler: Revert and earlier experiment. 2026-02-14 15:37:52 +10:00
David Reid a8dd56fbbe Remove some unused functions. 2026-02-14 15:01:01 +10:00
David Reid 0f1ead0873 Remove a TODO. 2026-02-14 14:56:49 +10:00
David Reid e2e6bb6334 Resampler: Optimization to the LPF > 0 path.
This moves the channel count checks outside of the loop.
2026-02-14 14:22:06 +10:00
David Reid 5ae52e1a0a Cleanup. 2026-02-14 13:52:23 +10:00
David Reid c39ace1604 Disable filtering for pitch shifting on sounds by design. 2026-02-14 13:29:27 +10:00
David Reid 0615ce28f1 Resampler: Optimization to the no-LPF path.
This moves some checks outside the loop. A bit more code duplication,
but does improve speed.
2026-02-14 13:22:42 +10:00
David Reid 0fe2f7effd Resampler: Remove some now well out of date code. 2026-02-14 08:58:33 +10:00
David Reid c456a2f432 Resampler: Experiment with some timer management optimizations.
The idea here is to only update the resampler object once at the end.
This improves speeds up the problematic s16 mono upsampling path with
Clang, but that same path with GCC is still slow somehow.
2026-02-14 08:54:13 +10:00
David Reid 6d20358df1 Resampler: More work on filter decoupling.
This makes the s16 mono upsampling path slower somehow. This seems to be
the problem code path for some reason. Other paths don't seem to be so
sensitive to seemingly harmless changes.
2026-02-14 08:21:56 +10:00
David Reid 459fc19304 Resampler: Decouple the filtering step from the main resampler object.
The idea here is to have a more clearly defined data dependency
separation between the resampler and the filtering state which I'm
hoping might open up more optimization opportunities. The problem with
this theory, is that this commit makes the GCC build slower on the s16
mono upsampling path. It appears to be slightly fast with Clang though.
2026-02-14 07:10:34 +10:00
David Reid d4382ce478 Resampler: Optimization to the filtering stage.
This seems to trigger a fast optimization strategy when compiling with
GCC. With this change the filtered s16 mono path is almost 2x faster.
2026-02-14 06:20:37 +10:00
David Reid b3340e629a Remove a TODO.
I tried addressing this, but upon doing so the build was slower. It was
especially bad with Clang where is was 2x slower(!), and just slightly
slower with GCC.

Not sure exactly what's going on here, but I guess the compiler is
hitting some edge case that's prevent efficient optimization. What's
weirder, is the slowness only affects the mono s16 code path. Other
code paths are totally fine.
2026-02-13 20:54:38 +10:00
David Reid 9d0f4a4103 Rename a macro. 2026-02-13 19:10:53 +10:00
David Reid db1bc8c4b7 Resampler: Remove dependency on ma_lpf.
This makes the resampler a bit more self-contained and allows us to do
some resampler-specific optimizations to the filtering process. It also
reduces the size of the `ma_linear_resampler` struct.
2026-02-13 18:54:32 +10:00
David Reid cbbe317adc Resampler: Miscellaneous optimizations to the linear resampler. 2026-02-13 18:33:29 +10:00
David Reid 172f8beae6 Resampler: Optimization for floating point stereo.
This applies only to the f32 no-LPF code path. Other code paths will be
integrated later.
2026-02-08 22:01:23 +10:00
David Reid cd02ebe39c Resampler: A loop unrolling optimization experiment.
My idea here is to make it easier to for the compiler to SIMD-ify some
of the interpolation code. I have not confirmed that it is actually
being SIMD-ified by the compiler, but it is still significantly faster
in both debug and release builds.

There is a mono specialization here which further improves performance.
I have not yet experimented with a stereo specialization, but if it
works it'll be added in a future commit.

This applies only to the f32 no-LPF code path. Other paths will come
later once I'm done with this round of experiments.
2026-02-08 20:12:57 +10:00
David Reid 20180b0ae5 Resampler: For LPF orders to be a multiple of 2.
This is in preparation for an implementation simplification for the
purpose of some upcoming optimizations.
2026-02-08 19:21:10 +10:00
David Reid a04f300821 Stop encouraging the use of some resampling functions.
These functions are not reliably implemented by all backends and as such
I'd rather not encourage these use of these. These might be removed in
the future.
2026-02-07 17:09:51 +10:00
David Reid 2ea55eaeaf Resampler: Optimization to f32, no LPF code path. 2026-02-07 15:40:10 +10:00
David Reid c0b57c3aea Resampler: Optimization to s16, no LPF code path. 2026-02-07 11:26:05 +10:00
David Reid 4b8eb8588d Resampler: Stop allowing NULL input and output buffers. 2026-02-07 10:48:42 +10:00
David Reid b6467f3cd0 Resampler: Stop invoking the LPF when the order is zero. 2026-02-05 20:22:34 +10:00
David Reid 848025b9c0 Resampler: Fix a bug where the LPF is not being applied. 2026-02-05 20:17:46 +10:00
David Reid 5ea8bbf701 Minor change to a debugging function. 2026-02-05 20:02:01 +10:00
David Reid cff6c7e28a Resampler: Convert a double to a float.
This saves a a few bytes in `ma_linear_resampler`.
2026-02-05 10:18:20 +10:00
David Reid 445aefae06 Resampler: Optimization to the s16 path in the linear resampler.
The main thing here is moving an integer division out of the inner loop.
2026-02-05 08:06:52 +10:00
David Reid 2c14e2e5a7 Resampler: Move a division out of an inner loop. 2026-02-04 17:00:09 +10:00
David Reid 2683601481 Update the linear resampler in preparation for some optimizing. 2026-02-04 16:59:05 +10:00
David Reid 1e2427f5f7 Tighten up the audio thread.
This should close a hole that could possibly result in the audio thread
getting stuck if the `MA_DEVICE_OP_UNINIT` operation posted from
`ma_device_uninit()` fails.
2026-02-04 14:20:42 +10:00
David Reid 93e74aaf91 Reduce the size of the ma_device_op_queue struct.
This in turn reduces the size of the `ma_device` struct by about half
a kilobyte or so.
2026-02-04 14:18:08 +10:00
David Reid 89fea8a39f Remove channelMap and internalChannelMap arrays from ma_device.
This information is already stored in the data converter and can be
retrieved with `ma_device_get_channel_map()` and
`ma_device_get_internal_channel_map()`.

This reduces the size of the `ma_device` struct by ~1KB.
2026-02-04 13:32:14 +10:00
David Reid 9b66a480c7 Fix a bug with channel map retrieval with the channel converter.
This had the input and output channel maps the wrong way around.
2026-02-04 12:45:20 +10:00
David Reid cb26c7ec52 Remove an unnecessary function.
This removes the horrendously named `ma_device__post_init_setup()` which
I've been meaning to remove for years.
2026-02-04 12:44:35 +10:00
David Reid 02f8a6b952 Set up some infrastructure for some future optimizations.
This changes the way backends update the internal data format in
response to a device reroute. With this change we'll be able to remove
the `channelMap` and `internalChannel` map members from the `ma_device`
struct which should reduce its size by ~1KB.
2026-02-04 11:46:05 +10:00
David Reid dc72a5683b Add some getters:
ma_device_get_format()
  ma_device_get_channels()
  ma_device_get_sample_rate()
  ma_device_get_internal_format()
  ma_device_get_internal_channels()
  ma_device_get_internal_sample_rate()
  ma_device_get_internal_channel_map()
2026-02-04 10:52:08 +10:00
David Reid 5c4cb49ad8 Add ma_device_get_channel_map(). 2026-02-01 16:59:13 +10:00
David Reid d929fafb34 Add a specialized path for deinterleaving u8 samples.
This is not yet optimized.
2026-02-01 11:04:07 +10:00
David Reid 53fce8453c Rename a variable. 2026-02-01 11:03:46 +10:00
David Reid ac12fa70e0 Fix Dreamcast/KallistiOS build. 2026-01-29 16:29:14 +10:00
David Reid 3ab152afb3 audio(4): Failed context initialization if /dev/audioctl does not exist.
This allows initialization to abort at an earlier stage which gives the
fallback logic a chance to try a different backend.
2026-01-28 16:33:30 +10:00
David Reid 38e35935d7 Get the audio(4) backend compiling with Solaris.
I have not been able to figure out how to get audio working with my VM
so this is currently untested.
2026-01-28 16:20:09 +10:00
David Reid bbc7ad1921 audio(4): Make format encoding stuff more robust. 2026-01-28 14:47:24 +10:00