Commit graph

604 commits

Author SHA1 Message Date
Kp 058ad139e4 Return earlier if no sound data is available
There is no point to retrieving the SDL_mixer output settings if the
sound data is missing, since they are only used when the data is
present.
2023-01-07 22:17:31 +00:00
Kp 5ce4d49004 Use enum class for sound_sample_rate 2023-01-07 22:17:31 +00:00
Kp 60adb6ecd8 Hold digi_sample_rate const
In any given run of the program, either the SDL_mixer code will be used,
or it will not be used.  `digi_sample_rate` only needs to vary if a
single run both uses SDL_mixer and avoids it.  Make `digi_sample_rate` a
`static const` with an appropriate value for each path.
2023-01-07 22:17:31 +00:00
Kp d9241c2d69 Add back old SDL_mixer-based resampler
Add the SDL_mixer-based resampler as a compile-time alternative, which
can be chosen by setting `-DDXX_FEATURE_INTERNAL_RESAMPLER=0`.  Keep the
new internal resampler as the default.
2023-01-07 22:17:31 +00:00
Kp 9e3ebdb1f7 Add static asserts that the custom resampler does not truncate input 2023-01-07 22:17:31 +00:00
Kp f002678974 Fix integer overflow in mixer resampler 2023-01-07 22:17:31 +00:00
Kp 05eea350a0 Move unique_span to d_uspan.h 2023-01-07 22:17:31 +00:00
Kp 1148aceabd Store ranges::subrange in m3u_bytes 2022-12-31 16:21:47 +00:00
Kp e3553586c1 Use enum class for bitmap_index 2022-12-31 16:21:47 +00:00
Kp 4257391a47 Use enum class for polygon_model_index 2022-12-18 18:32:14 +00:00
Kp 5f39ffc2f5 Use enum class for sound_channel 2022-12-17 13:16:28 +00:00
Kp 1b92a56648 Use unique_ptr to manage digi_sound allocation 2022-12-10 18:09:54 +00:00
Kp 6da1956337 Defer allocating resample output until replicateChannel begins
This allows `stage1` to be freed before `output` is allocated.
2022-11-12 19:31:52 +00:00
Kp 754ecafee5 Use unique_span to provide a span over allocated memory 2022-11-12 19:31:52 +00:00
Kp 5c6cb90b62 Use fill_n in sound resample replicateChannel
Prefer a standard library function over an open-coded loop.
2022-11-12 19:31:52 +00:00
Kp 14e7b2a4ee Make sound resample coefficients constant 2022-11-12 19:31:52 +00:00
Kp 48fd582698 Simplify filter_fir max_idx
Observe that `nn` is at most `signal.size() - 1`, which occurs on the
final pass of the loop.  Therefore, `std::min` will always pick `nn`
instead of `signal.size() - 1`, so simplify out the call.
2022-11-12 19:31:52 +00:00
Kp fcfd237954 Use std::span for sound resample buffers 2022-11-12 19:31:52 +00:00
Kp 10d0bbc4e8 Adjust filter_fir to work with unsigned lengths 2022-11-12 19:31:52 +00:00
Kp 527263d81e Allocate output buffer in filter_fir
Take the length from the caller and allocate it locally, rather than
requiring the caller to provide the buffer.
2022-11-12 19:31:52 +00:00
Kp 7ddc095c9c Fix misspelling in filter_fir comment 2022-11-12 19:31:52 +00:00
Kp f6eb8edd59 Remove unnecessary zero fill in upsample
`std::make_unique` already value-initializes the array.
2022-11-12 19:31:52 +00:00
Kp d21ea16d2b Allocate output buffer in upsample
Take the length from the caller and allocate it locally, rather than
requiring the caller to provide the buffer.
2022-11-12 19:31:52 +00:00
Kp 4eff9d3ffc Merge master into pull/651
Pull #651 predates the switch to C++20.  Pull in master to provide the
C++20 support needed by some tuning commits.
2022-11-12 19:02:17 +00:00
Kp e42cd300af Use auto & for coeffs, since it is never changed 2022-11-12 19:00:21 +00:00
Kp 713b3baf99 Remove unnecessary commented variable 2022-11-12 19:00:21 +00:00
Kp 7a6870d610 Move buffer pointer directly from unique_ptr to RAIIMix_Chunk
Avoid transferring the pointer into a local variable, so that there are
no points where a stack unwind could lose the pointer to the allocated
memory.
2022-11-12 19:00:21 +00:00
Kp fe5dacb759 Move resample code into namespace dcx 2022-11-12 19:00:21 +00:00
Kp 7effca68f0 Use RAII_SDL_Surface to track SDL-only main canvas surface
The Rebirth main screen grd_curscreen borrows the memory allocated by
SDL_CreateRGBSurface to store its data.  Store the pointer to that
surface inside grd_curscreen and make grd_curscreen responsible for
freeing the surface.
2022-11-06 18:18:57 +00:00
Kp ae46a5b3b0 Simplify SDL gr_flip: nullptr implies copy all
Per the header comments, passing nullptr for source or destination
copies the entire region.  Use that instead of explicitly requesting the
entire region.  This should be more efficient, since it bypasses the
source rectangle clipping code that SDL would otherwise run.
2022-11-06 18:18:57 +00:00
Kp 90d3d82d8e Default disable VR side-by-side for OpenGL ES
VR requires glDrawBuffer, which Mesa OpenGL ES does not offer.  Default
VR to disabled for OpenGL ES users.  Users who want to try it anyway can
still set use_stereo_render=1 in the SCons environment.
2022-10-09 23:15:20 +00:00
Kp 73bcfb6d63 Simplify ogl_ubitblt_i GL array initialization
- Avoid zero-filling arrays that can be directly initialized with real
  values.
- Hold color_array const so it can be stored statically.
2022-10-02 19:51:35 +00:00
Kp 8c08dcc20f Merge branch 'refs/pull/633/head' into master 2022-10-02 19:50:49 +00:00
Kp 9a8c49ccbf Fix OpenGL ES build on SDL1
The preceding commit breaks OpenGLES + SDL1 support, by referencing
SDL_GL_* constants that are new in SDL2.  Add a preprocessor guard to
skip over the new constants when using SDL1.

Fixes: c90ac3e611 ("Fix OpenGL ES build on SDL2.")
2022-10-02 19:50:32 +00:00
Kp 9cad6c0eaa Use std::span for sound_slot samples 2022-09-24 17:47:52 +00:00
Kp a48e6ab56b Pass std::span to _g3_draw_tmap 2022-09-24 17:47:52 +00:00
Kp ad8325b63c Pass std::span to _g3_draw_tmap_2 2022-09-24 17:47:52 +00:00
Kp 491d23e2d9 Pass std::span to _g3_draw_poly 2022-09-24 17:47:52 +00:00
JohnnyonFlame c90ac3e611 Fix OpenGL ES build on SDL2. 2022-09-18 21:35:55 -03:00
Kp 232c648024 Add Windows version resource for Windows build 2022-09-11 17:00:45 +00:00
raptor 5165efbc46 Use custom fixed-point audio resampler:
- Hopefully fixes issues with poor quality resampling when using SDL_AudioCVT
- Converts 11025 Hz or 22050 Hz samples to the default 44100 Hz outputs
- Uses high order brick wall filter like Sound Blaster 16
2022-08-09 22:10:13 -06:00
Kp 78fd6550ea Avoid unnecessary allocation in jukebox_play
If the song originates in an m3u playlist, no temporary buffer is
needed.  Avoid allocating and initializing one, and instead pass the
pointer directly from the CMLevelMusicPath field.
2022-07-02 18:10:45 +00:00
Kp 173d5559d7 Tighten TGA generation code
- Skip reading unused alpha channel in TGA screenshot path.  The alpha
  channel is discarded, so skip even retrieving it from OpenGL.
- Perform the red/blue swap in place, instead of copying into an
  additional buffer.
2022-07-02 18:10:45 +00:00
Kp 4fd412b2ea Precompute g3_draw_line GL color data 2022-06-05 17:44:52 +00:00
Kp e54338ce4e Combine canvas+color into g3_draw_line_context 2022-06-05 17:44:52 +00:00
Kp 9e0431b861 digi_win32_play_midi_song: write hmp_open result directly to global
Commit 3b5b69cb97 changed the logic to store the result of hmp_open
into a local that was destroyed at the end of the function.  This was
incorrect, as destruction of the returned value will immediately halt
the music.  Revert to the previous behavior, where the result is written
to the global `cur_hmp` so that it persists past the end of the
function.

Reported-by: norbert79 <https://github.com/dxx-rebirth/dxx-rebirth/issues/634>
Analyzed-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Proposed-fix-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Fixes: 3b5b69cb97 ("Improve error reporting for hmp_open / hmp2mid")
2022-04-28 02:19:26 +00:00
Kp 9cdf9152bc Always check return value of PHYSFSX_getRealPath
The contents of the output buffer are undefined if PHYSFSX_getRealPath
fails, so mark the function as [[nodiscard]] and modify all callers to
check that the function succeeded.
2022-03-19 22:55:58 +00:00
Kp 3b5b69cb97 Improve error reporting for hmp_open / hmp2mid
Rework the error paths to return path-specific status codes so that the
caller can report exactly which step caused an HMP file to be rejected.
On error, print this reason numerically and, if the reason was a PhysFS
error, also print the PhysFS error code numerically and symbolically.
2022-03-19 22:55:58 +00:00
Kp b8ae2c5e55 Remove unused-but-set variables in ogl_texture_stats 2022-01-15 20:39:10 +00:00
Kp d2478d0708 Require support for C++17 attribute [[fallthrough]] 2022-01-09 15:25:42 +00:00