Commit Graph

959 Commits

Author SHA1 Message Date
Brick
88123a5109 The history buffer should always have the maximum possible padding frames 2023-08-21 16:02:54 -04:00
Brick
96e47f1657 Clamp results of GetResampler(AvailableOutput|NeededInput)Frames 2023-08-21 16:02:54 -04:00
Brick
14e38b17d6 Removed assertions from inner ResampleAudio loop 2023-08-21 16:02:54 -04:00
Brick
9d413dfdc2 The history buffer doesn't need to be so large 2023-08-21 16:02:54 -04:00
Brick
2788e848f8 Allow resampling less than 1 frame of input 2023-08-21 16:02:54 -04:00
Brick
383084e0ad Pre-calculate resampling rate, and use it instead of .freq in most places 2023-08-21 16:02:54 -04:00
Brick
40a6a445ce Update resample_offset inside ResampleAudio 2023-08-21 16:02:54 -04:00
Brick
47fea7f06b Used fixed-point arithmetic in ResampleAudio 2023-08-21 16:02:54 -04:00
Brick
7bb4e806ea Clear resample_offset in SDL_ClearAudioStream, not SetAudioStreamFormat
Not entirely sure if ClearAudioStream is the right place, but SetAudioStreamFormat was the wrong place
2023-08-21 16:02:54 -04:00
Brick
b9541b9eab Improved ResampleAudio
* filterindex2 was off-by-one
* Generate ResamplerFilter using doubles
* Transpose ResamplerFilter to improve access patterns
2023-08-21 16:02:54 -04:00
Brick
cdaa19869d Track offset within the current sample when resampling 2023-08-21 16:02:54 -04:00
Ryan C. Gordon
789ce17e11 audio: Don't resample in chunks for now.
This needs a little reworking to not lose sample frames.

Reference Issue #8036.
2023-08-16 10:26:08 -04:00
Ryan C. Gordon
cbab33482a audio: Don't call SDL_AudioStream callbacks for empty data sets.
Fixes #8095.
2023-08-14 18:16:58 -04:00
Brick
f4520821ef Removed some unnecessary integer casts 2023-08-14 15:07:18 -04:00
Brick
0989b7e86d Avoid using designated initializers 2023-08-14 15:07:18 -04:00
Brick
c6c1e673c0 Optimized SDL_Convert_*_to_*_Scalar
They are now all branch-less and avoid float multiplication/conversion where possible
2023-08-14 15:07:18 -04:00
Brick
f97b920b31 Optimized SDL_Convert_*_to_*_SSE2
Some of the SDL_Convert_F32_to_*_SSE2 do not explicitly clamp the input,
but instead rely on saturating casts.
Inputs very far outside the valid [-1.0, 1.0] range may produce
an incorrect result, but I believe that is an acceptable trade-off.
2023-08-14 15:07:18 -04:00
Brick
33f11e21ee Removed assertions in AudioConvert(To|From)Float 2023-08-14 15:07:18 -04:00
Ikko Eltociear Ashimine
a44338cbc1 Fix typo in SDL_audiocvt.c
accomodate -> accommodate
2023-08-14 10:13:53 -07:00
capehill
c3f7a7dc46 Convert audio using SDL_AUDIO_F32SYS format instead of SDL_AUDIO_F32
This fixes audio playback noise on big endian systems
as SDL_AUDIO_F32 means SDL_AUDIO_F32LSB.
2023-08-13 14:08:18 -07:00
Ryan C. Gordon
91cd5478be audio: Fix resampler overflowing input buffer.
This usually manifests as a clicking sound, because it often produces
a value outside the range -1.0f to 1.0f based on whatever random data
is past the buffer, which later stages of audio conversion will clamp
to a maximum value for the audio format. Since this tends to be a single
bad sample generated at the end of the resampled buffer, it sounds like
a repeating click in streamed data.

I'd like a more efficient means to clamp this value to not overflow the
buffer, but this puts out the immediate fire.
2023-08-12 00:57:35 -04:00
Ryan C. Gordon
5735d2b03b coreaudio: Fixed assertion when device fails/quits mid-iteration.
Fixes #8094.
2023-08-08 23:57:42 -04:00
Ryan C. Gordon
0714da37a4 audio: Fix audio stream callback calculations when future buffer has space.
We were subtracting backwards.  :/
2023-08-08 21:42:48 -04:00
Sam Lantinga
b903ccf945 SDL_rwops read/write functions return size_t again
The current status is stored in the SDL_rwops 'status' field to be able to determine whether a 0 return value is caused by end of file, an error, or a non-blocking source not being ready.

The functions to read sized datatypes now return SDL_bool so you can detect read errors.

Fixes https://github.com/libsdl-org/SDL/issues/6729
2023-08-07 20:36:21 -07:00
Ryan C. Gordon
e7d56dd0b2 audio: Renamed new API SDL_UnpauseAudioDevice to SDL_ResumeAudioDevice. 2023-08-05 19:20:14 -04:00
Mathieu Eyraud
2b0c0f5b6b Don't pass NULL to strncmp 2023-08-05 18:17:21 -04:00
Mathieu Eyraud
778e8185cd Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked
And add diagnostic that allows to find this kind of issue in clang-tidy
2023-08-05 14:14:45 -04:00
meyraud705
3a752ce650 Reapply "Changed 'freesrc' parameter from int to SDL_bool" to SDL_wave.c
Commit bea99d4 was partially reverted by 905c4ff "audio: First shot at the SDL3 audio subsystem redesign!"
2023-08-05 13:44:48 -04:00
Ryan C. Gordon
87eae9a0a1 aaudio: We need a mixbuf on capture devices, too. 2023-07-30 20:24:27 -04:00
Ryan C. Gordon
ae3090c387 androidaudio: Move Init/bootstrap code to bottom of source code.
I can't ever find this when it's in the middle! It's a "me" problem.  :)
2023-07-30 11:56:43 -04:00
Ryan C. Gordon
18fc0db9e5 aaudio: Rearranged source code to match other backends. 2023-07-30 11:56:43 -04:00
Ryan C. Gordon
2507c1d68b aaudio: Disconnect playing devices if error callback fires. 2023-07-30 11:56:42 -04:00
Ryan C. Gordon
32a3fc3783 aaudio: Use the callback interface.
This is allegedly lower-latency than the AAudioStream_write interface,
but more importantly, it let me set this up to block in WaitDevice.

Also turned on the low-latency performance mode, which trades battery life
for a more efficient audio thread to some unspecified degree.
2023-07-30 11:56:42 -04:00
Ryan C. Gordon
b49ce86765 audio: Fixed compiler warning on Android NDK. 2023-07-30 11:56:42 -04:00
Ryan C. Gordon
1c074e8d97 android: Fixed audio device detection. 2023-07-30 11:56:42 -04:00
Ryan C. Gordon
82ce05ad01 pulseaudio: Be more aggressive with hotplug thread synchronization.
(Borrowed from the SDL2 branch.)
2023-07-30 11:56:41 -04:00
Ryan C. Gordon
ab68428a64 aaudio: Fixed for older SDKs and Android releases. 2023-07-30 11:56:41 -04:00
Ryan C. Gordon
5ff87c6d4a android: Reworked audio backends for SDL3 audio API.
This involved moving an `#ifdef` out of SDL_audio.c for thread priority,
so the default ThreadInit now does the usual stuff for non-Android platforms,
the Android platforms provide an implementatin of ThreadInit with their
side of the `#ifdef` and other platforms that implement ThreadInit
incorporated the appropriate code...which is why WASAPI is touched in here.

The Android bits compile, but have not been tested, and there was some
reworkings in the Java bits, so this might need some further fixes still.
2023-07-30 11:56:41 -04:00
Ryan C. Gordon
7f4488f625 wasapi: More fixes for Clang warnings. 2023-07-30 11:56:40 -04:00
Ryan C. Gordon
29a0c689c9 wasapi: Patched to compile with Clang. 2023-07-30 11:56:40 -04:00
Ryan C. Gordon
4aa95c21bc pspaudio: Patched to compile. 2023-07-30 11:56:40 -04:00
Ryan C. Gordon
9a2a0a1463 ps2audio: Delete errant character that got inserted before previous commit. 2023-07-30 11:56:39 -04:00
Ryan C. Gordon
2c578bd0d5 qnxaudio: Rewrite for SDL3 audio APIs.
I have no way to compile or test this atm, so this will likely need
further attention. I ended up cleaning this up a ton and adding missing
features, so the code changes are pretty dramatic vs a simple conversion
to SDL3...so tread carefully in here.
2023-07-30 11:56:39 -04:00
Ryan C. Gordon
455eef4cd9 audio: Use AtomicAdd for device counts, don't treat as a refcount. 2023-07-30 11:56:39 -04:00
Ryan C. Gordon
095ea57f94 pspaudio: Patched to compile. 2023-07-30 11:56:39 -04:00
Ryan C. Gordon
d7cf63db67 ps2audio: Patched to compile. 2023-07-30 11:56:38 -04:00
Ryan C. Gordon
027b9e8787 coreaudio: (maybe) patched to compile on iOS. 2023-07-30 11:56:38 -04:00
Ryan C. Gordon
4836c2db07 pspaudio: Patched to compile. 2023-07-30 11:56:38 -04:00
Ryan C. Gordon
86ca412436 n3dsaudio: Patched to compile. 2023-07-30 11:56:38 -04:00
Ryan C. Gordon
dbf993d358 vitaaudio: patched to compile. 2023-07-30 11:56:37 -04:00