Commit Graph

401 Commits

Author SHA1 Message Date
Sam Lantinga
8325df25aa Fixed bug 4169 - Crash due to audio session observer race condition
Jona

The following explains why this bug was happening:
This crash was caused because the audio session was being set as active [session setActive:YES error:&err] when the audio device was actually being CLOSED. Certain cases the audio session being set to active would fail and the method would return right away. Because of the way the error was handled we never removed the SDLInterruptionListener thus leaking it. Later when an interruption was received the THIS_ object would contain a pointer to an already released device causing the crash.

The fix:
When only one device remained open and it was being closed we needed to set the audio session as NOT active and completely ignore the returned error to successfully release the SDLInterruptionListener. I think the user assumed that the open_playback_devices and open_capture_devices would equal 0 when all of them where closed but the truth is that at the end of the closing process that the open devices count is decremented.
2018-05-24 07:30:24 -07:00
Ryan C. Gordon
101544d6f0 audio: Needed to fix two more instances for Visual Studio. 2018-05-21 12:05:17 -04:00
Ryan C. Gordon
49881861b1 audio: Patched to compile on Visual Studio.
(It gets upset at the -2147483648, thinking this should be an unsigned value
because 2147483648 is too large for an int32, so the negative sign upsets the
compiler.)
2018-05-21 11:54:09 -04:00
Ryan C. Gordon
b7e88aaae0 audio: Added ARM NEON versions of audio converters.
These are _much_ faster than the scalar equivalents on the Raspberry Pi that
I tested on. Often 3x to 4x as fast!
2018-05-16 02:03:06 -04:00
Ryan C. Gordon
cb0e614fb1 audio: SSE2 float-to-int converters should clamp input.
The scalar versions already do this.
2018-05-15 02:29:35 -04:00
Ryan C. Gordon
a07e5815a5 audio: Fix range on float-to-int data clamping.
I can't tell if there was a good reason for this or it was just me getting
numbers wrong due to exhaustion.
2018-05-15 01:40:05 -04:00
Ryan C. Gordon
7832cb652e audio: float to int converters should clamp inclusively.
If we have to test if a sample is > 1.0f anyhow, we might as well use this
to avoid the unnecessary multiplication when it's == 1.0f, too. (etc).
2018-05-15 01:35:53 -04:00
Ryan C. Gordon
e2ec1eb12e audio: converting int32 to/from float shouldn't use doubles.
The concern is that a massive int sample, like 0x7FFFFFFF, won't fit in a
float32, which doesn't have enough bits to hold a whole number this large,
just to divide it to get a value between 0 and 1.
Previously we would convert to double, to get more bits, do the division, and
cast back to a float, but this is expensive.

Casting to double is more accurate, but it's 2x to 3x slower. Shifting out
the least significant byte of an int32, so it'll definitely fit in a float,
and dividing by 0x7FFFFF is still accurate to about 5 decimal places, and the
difference doesn't appear to be perceptable.
2018-05-15 01:04:11 -04:00
Sam Lantinga
f521b22eb5 Added SDL_THREAD_PRIORITY_TIME_CRITICAL 2018-04-23 22:07:56 -07:00
Ryan C. Gordon
dc8b55e50b coreaudio: Use the standard SDL audio thread instead of spinning a new one.
Fixes corner cases, like the audio callback not firing if the device is
disconnected, etc.
2018-04-16 02:11:09 -04:00
Sam Lantinga
99a0c0f0e2 Fixed MinGW-w64 build 2018-02-24 08:23:44 -08:00
Ryan C. Gordon
c7e4366530 wasapi: let Windows do the resampling for us if possible. 2018-02-21 21:34:06 -05:00
Ryan C. Gordon
7e1fa0ce53 wasapi: fixed typo in an assert message. 2018-02-21 21:34:35 -05:00
Ryan C. Gordon
97494f5374 pulseaudio: Just read/dump captured data in FlushCapture.
Apparently pa_stream_flush() doesn't work as expected:

https://lists.freedesktop.org/archives/pulseaudio-discuss/2012-April/013328.html

Fixes Bugzilla #4087.
2018-02-17 18:30:21 -05:00
sezero
ba0ecc6712 fix building SDL_audiotypecvt.c with gcc < 4.0 2018-02-12 10:47:00 +03:00
sezero
40b27fd51b revert the recent typecast assignment changes (see bug #4079)
also change the void* typedefs for the two vulkan function
pointers added in vulkan_internal.h  into generic function
pointer typedefs.
2018-02-12 17:00:00 +03:00
Sam Lantinga
90e72bf4e2 Fixed ISO C99 compatibility
SDL now builds with gcc 7.2 with the following command line options:
-Wall -pedantic-errors -Wno-deprecated-declarations -Wno-overlength-strings --std=c99
2018-01-30 18:08:34 -08:00
Ryan C. Gordon
488824017a wasapi: Fixed some compiler warnings. 2018-01-22 09:36:40 -05:00
Sam Lantinga
e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Ryan C. Gordon
77bb49b7a7 wasapi: Patched to compile on non-UWP WinRT builds. 2017-12-31 03:34:16 -05:00
Ryan C. Gordon
ab4695f48f wasapi: switched to event-driven interface.
This reduces latency and improves battery life.
2017-12-13 14:35:55 -05:00
Ryan C. Gordon
351d6d4784 audio: Port WASAPI to WinRT, remove XAudio2 backend.
XAudio2 doesn't have capture support, so WASAPI was to replace it; the holdout
was WinRT, which still needed it as its primary audio target until the WASAPI
code code be made to work.

The support matrix now looks like:

WinXP: directsound by default, winmm as a fallback for buggy drivers.
Vista+: WASAPI (directsound and winmm as fallbacks for debugging).
WinRT: WASAPI
2017-12-06 12:24:32 -05:00
Sam Lantinga
e830ef3458 Fixed typo converting 4 channel audio to 2 channel 2017-10-20 16:53:42 -07:00
Sam Lantinga
9a291c1e59 Added a note about adjusting channel weights when converting to fewer channels 2017-10-20 14:51:22 -07:00
Ryan C. Gordon
729329068b audio: Added SDL_AudioStreamFlush(). 2017-10-19 18:05:42 -04:00
Ryan C. Gordon
e98920f5f3 Check correct variable for malloc() results. 2017-10-18 23:49:46 -04:00
Sam Lantinga
afefcbfeba Fixed bug 3876 - Resampling of certain sounds adds heavy distortion
Simon Hug

Patch that adds [-1, 1] clamping to the scalar audio type conversions.

This may come from the SDL_Convert_F32_to_X_Scalar functions. They don't clamp the float value to [-1, 1] and when they cast it to the target integer it may be too large or too small for the type and get truncated, causing horrible noise.

The attached patch throws clamping in, but I don't know if that's the preferred way to fix this. For x86 (without SSE) the compiler (I tested MSVC) seems to throw a horrible amount of x87 code in it. It's a bit better with SSE, but probably still quite the performance hit. And SSE2 uses a branchless approach with maxss and minss.
2017-10-18 19:30:47 -07:00
Sam Lantinga
653ab5d9c4 Added a staging buffer to the audio stream so that we can accumulate small amounts of data if needed when resampling 2017-10-18 19:26:36 -07:00
Sam Lantinga
80f8464d97 Added audio stream conversion functions:
SDL_NewAudioStream
    SDL_AudioStreamPut
    SDL_AudioStreamGet
    SDL_AudioStreamAvailable
    SDL_AudioStreamClear
    SDL_FreeAudioStream
2017-10-18 15:54:05 -07:00
Ryan C. Gordon
fa15674134 coreaudio: changed device close procedure to prevent long hangs in some cases.
The audioqueue thread needs to keep running, and processing the CFRunLoop
until the AudioQueue is disposed of, otherwise CoreAudio will hang waiting for
final data to feed the device.

At least, I think this is how it all works. It definitely fixes the bug here!

Since AudioQueueDispose() calls AudioQueueStop() internally, there's no need
for our thread to handle this, either, which is good because the AudioQueue
would be disposed by this point. So now the AudioQueue is disposed first, and
then our thread is joined, and everything works out okay.

Just in case, we mark the device "paused" before setting everything in motion,
so any further callbacks from CoreAudio will write silence and not fire the
app's audio callback again.

Fixes Bugzilla #3868.
2017-10-13 01:15:29 -04:00
Sam Lantinga
ba10d2b654 Fixed compiler warning 2017-10-12 13:55:35 -07:00
Ryan C. Gordon
5e5f2290f2 audio: Turns out the accumulation errors sound better. :/
Moving to double fixed the overflows, but using "time = i * incr" instead of
"time += incr" causes clicks in the output.
2017-10-11 12:07:43 -04:00
Ryan C. Gordon
9bd2c6b491 audio: Moved the resampler state up to double precision.
Fixes more buffer overflows.
2017-10-11 11:51:14 -04:00
Ryan C. Gordon
b2f5123b65 audio: calculate resampling time directly, don't increment (thanks, Eric!).
Fixes buffer overruns as floating point errors accumulate.

Partially fixes Bugzilla #3848.
2017-10-11 11:43:35 -04:00
Ryan C. Gordon
763c387149 audio: clamp resampler interpolation values to prevent buffer overflow.
Partially fixes Bugzilla #3848.
2017-10-11 02:33:55 -04:00
Ryan C. Gordon
0085f917e0 audio: Moved unchanging variable out of loop. 2017-10-11 02:31:58 -04:00
Ryan C. Gordon
cb8bf6bbaf audio: Make sure audio stream resampling doesn't overflow buffers. 2017-10-11 02:03:05 -04:00
Ryan C. Gordon
459e2b0bbe audio: Fixed check for minimum audio stream put size. 2017-10-11 01:37:11 -04:00
Ryan C. Gordon
903ff6414e audio: SDL_ResampleCVT() should use memmove instead of memcpy.
This copy can overlap.

Fixes Bugzilla #3849.
2017-10-10 22:31:02 -04:00
Ryan C. Gordon
42fff7ce2b audio: Don't stack-allocate resampler padding.
(I thought padding size ranged from 5 frames to ~30 frames (based around
RESAMPLER_ZERO_CROSSINGS, which is 5), but it's actually between 512 and
several thousands (based on RESAMPLER_SAMPLES_PER_ZERO_CROSSING)). It gets
big fast when downsampling.
2017-10-10 22:18:46 -04:00
Ryan C. Gordon
37d89aa10f audio: reworked audio streams to have right-hand resampling padding available.
Fixes Bugzilla #3851.
2017-10-10 16:12:56 -04:00
Ryan C. Gordon
099ae43e81 audio: Fixed compiler warning on Visual Studio. 2017-09-22 22:28:21 -04:00
Sam Lantinga
fe6b8f1c31 Fixed Mac OS X build 2017-09-22 11:25:52 -07:00
Sam Lantinga
407e1693ae Fixed audio being silent on older iOS devices
Tested on an iPod running iOS 6.1
2017-09-22 11:15:14 -07:00
Sam Lantinga
d74c00e67d Fixed memory leak when HAVE_ALLOCA isn't defined 2017-09-22 08:51:45 -07:00
Ryan C. Gordon
6d206a7b28 audio: Stream resampling now saves some samples from previous run for padding.
Previously, the padding was silence, which was a problem when streaming since
you would sample a little bit of this silence between each buffer.

We still need a means to get padding data for the right hand side, but this
patch makes the resampler output more correct.
2017-09-22 07:42:24 -04:00
Sam Lantinga
8b660c5046 Added some missing "extern" declarations 2017-09-21 00:55:29 -07:00
Ryan C. Gordon
f40bd5ee24 audio: removed my perl experiment script. 2017-09-21 02:06:53 -04:00
Ryan C. Gordon
1a3b95a11e audio: Replaced the resampler. Again.
This time it's using real math from a real whitepaper instead of my previous
amateur, fast-but-low-quality attempt. The new resampler does "bandlimited
interpolation," as described here: https://ccrma.stanford.edu/~jos/resample/

The output appears to sound cleaner, especially at high frequencies, and of
course works with non-power-of-two rate conversions.

There are some obvious optimizations to be done to this still, and there is
other fallout: this doesn't resample a buffer in-place, the 2-channels-Sint16
fast path is gone because this resampler does a _lot_ of floating point math.
There is a nasty hack to make it work with SDL_AudioCVT.

It's possible these issues are solvable, but they aren't solved as of yet.
Still, I hope this effort is slouching in the right direction.
2017-09-21 02:51:14 -04:00
Sam Lantinga
c08a7a74a5 Added a hint SDL_HINT_AUDIO_CATEGORY to control the audio category,
determining whether the phone mute switch affects the audio
2017-09-15 17:27:32 -07:00
Ryan C. Gordon
93583d461c alsa: removed snd_pcm_wait() call before writing to playback device.
This would cause playback problems in certain situations, such as on the
Raspberry Pi. The device that the wait was added for seems to not benefit from
it in modern times, and standard desktop Linux seems to do the right thing
when a USB device is unplugged now, without this patch.

Fixes Bugzilla #3599.
2017-09-09 21:17:46 -04:00
Ryan C. Gordon
ca15c7d67f wave: SDL_LoadWAV now supports 24-bit audio. 2017-09-07 10:56:08 -04:00
Ryan C. Gordon
3267398d15 sndio: Patched to compile if SIO_DEVANY isn't defined.
(It isn't in whatever Raspbian is currently shipping.)
2017-09-02 16:41:14 -04:00
Sam Lantinga
d619d88560 Fixed bug 3662 - Error message when using the audio conversion setup without an initialized audio subsystem is a bit vague
Simon Hug

This issue actually raises the question if this API change (requirement of initialized audio subsystem) is breaking backwards compatibility. I don't see the documentation saying it is needed in 2.0.5.
2017-08-28 21:42:39 -07:00
Ryan C. Gordon
b128e8802d audio: A whole bunch of improvements to audio conversion (thanks, Solra!).
"Major changes, roughly in order of appearance:

- Use float math everywhere, instead of promoting to double and casting back
all the time.
- Conserve sound energy when downmixing any channel into two other channels.
- Add a QuadToStereo filter. (The previous technique of reusing StereoToMono
never worked, since it assumed an incorrect channel layout for 4.0.)
- Add a 71to51 filter. This removes just under half of the cases the previous
code would silently break in.
- Add a QuadTo51 filter. More silent breakage fixed.
- Add a 51to71 filter, removing another almost-half of the silently broken
cases.
- Add 8 to the list of values SDL_SupportedChannelCount will accept.
- Change SDL_BuildAudioCVT's channel-related logic to handle every case, and
to actually fail if it fails instead of silently corrupting sound data and/or
crashing down the road."

(Note that SDL doesn't otherwise support 7.1 audio yet, but hopefully it will
soon and the 7.1 converters are an important piece of that.  --ryan.)

Fixes Bugzilla #3727.
2017-08-29 00:41:45 -04:00
Ryan C. Gordon
a0cd7d6bce audio: Converting audio samples from int to float was using wrong equation.
Fixes Bugzilla #3775.
2017-08-29 00:02:04 -04:00
Sam Lantinga
6dd3f55d55 Fixed WinRT build after changing the header guard preprocessor symbol 2017-08-28 01:59:53 -07:00
Sam Lantinga
0d011ec66d Renaming of guard header names to quiet -Wreserved-id-macro 2017-08-28 00:22:23 -07:00
Sam Lantinga
8e7998e19d Fixed bug 3710 - SDL_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL
David Ludwig

I've created a new set of patches.  I am happy to create more, if it would help.

One version only copies 'size'.

A second version copies both 'size' and 'silence'.  When looking over the documentation for SDL_OpenAudio in SDL_audio.h, it mentioned that both 'size' and 'silence' were things that SDL_OpenAudio would calculate.

Regarding *both* patches, I did notice that SDL 1.2 appears to have always modified desired's size and silence fields.  The SDL wiki, at https://wiki.libsdl.org/SDL_OpenAudio#Remarks , does note:
2017-08-27 19:10:30 -07:00
Sam Lantinga
bcf0e07107 Added WASAPI audio target to autoconf build process 2017-08-18 17:29:44 -07:00
Ryan C. Gordon
e3e6b4fd35 audio: better docs on conversion APIs, error if not init'd (thanks, Simon!).
Fixes Bugzilla #3662.
2017-08-18 16:52:19 -04:00
Sam Lantinga
fb835f9e3b Fixed bug 2330 - Debian bug report: SDL2 X11 driver buffer overflow with large X11 file descriptor
manuel.montezelo

Original bug report (note that it was against 2.0.0, it might have been fixed in between):  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733015

--------------------------------------------------------
Package: libsdl2-2.0-0
Version: 2.0.0+dfsg1-3
Severity: normal
Tags: patch

I have occasional crashes here caused by the X11 backend of SDL2. It seems to
be caused by the X11_Pending function trying to add a high number (> 1024)
file descriptor to a fd_set before doing a select on it to avoid busy waiting
on X11 events. This causes a buffer overflow because the file descriptor is
larger (or equal) than the limit FD_SETSIZE.

Attached is a possible workaround patch.

Please also keep in mind that fd_set are also used in following files which
may have similar problems.

src/audio/bsd/SDL_bsdaudio.c
src/audio/paudio/SDL_paudio.c
src/audio/qsa/SDL_qsa_audio.c
src/audio/sun/SDL_sunaudio.c
src/joystick/linux/SDL_sysjoystick.c


--------------------------------------------------------

On Tuesday 24 December 2013 00:43:13 Sven Eckelmann wrote:
> I have occasional crashes here caused by the X11 backend of SDL2. It seems
> to be caused by the X11_Pending function trying to add a high number (>
> 1024) file descriptor to a fd_set before doing a select on it to avoid busy
> waiting on X11 events. This causes a buffer overflow because the file
> descriptor is larger (or equal) than the limit FD_SETSIZE.


I personally experienced this problem while hacking on the python bindings
package for SDL2 [1] (while doing make runtest). But it easier to reproduce in
a smaller, synthetic testcase.
2017-08-14 20:22:19 -07:00
Sam Lantinga
96305832bc Fixed bug 3702 - Clear error messages of SDL_LoadObject for optional libraries
Simon Hug

Some code in SDL loads libraries with SDL_LoadObject to get more information or use newer APIs. SDL_LoadObject may fail, set an error message and SDL will continue with some fallback code. Since SDL will overwrite the error or exit the function with a return value that indicates success, the error form SDL_LoadObject for the optional stuff might as well be cleared right away.
2017-08-11 10:21:19 -07:00
Ryan C. Gordon
9dde37eadb sndio: Fix for some platforms (Linux, for example) that don't define INFTIM.
Fixes Bugzilla #3712.
2017-08-07 00:25:18 -04:00
Ryan C. Gordon
a09efc73d2 psp: Force audio channels to stereo if > 2 channels requested (thanks, Solra!).
Fixes Bugzilla #3726.
2017-08-04 16:18:34 -04:00
Philipp Wiesemann
68ca9d9ed1 qnx: Fixed error message. 2017-07-29 23:00:45 +02:00
Philipp Wiesemann
cea33bf5b8 aix: Removed unused local variable.
Found by Cppcheck.
2017-07-29 23:00:34 +02:00
Sam Lantinga
77ca0f273c Fixed crash if the WASAPI audio device couldn't be recovered 2017-07-27 22:55:18 -07:00
Sam Lantinga
4a734209a3 Fixed infinite recursion if the WASAPI audio device couldn't be recovered 2017-07-27 22:52:19 -07:00
Sam Lantinga
f033ce61e1 Fixed typo in WASAPI shutdown code 2017-07-27 02:41:58 -07:00
Ryan C. Gordon
03eaddcad4 Fixed compiler warnings on QNX. 2017-07-23 19:25:16 -04:00
Ryan C. Gordon
8ac17a2ae6 sndio: fixed poll() call (thanks, kdrakehp!).
Fixes Bugzilla #3705.
2017-07-20 20:40:17 -04:00
Ryan C. Gordon
ee9cc32493 sndio: More improvements to the OpenBSD audio target (thanks, kdrakehp!).
Fixes Bugzilla #3705.
2017-07-20 18:16:02 -04:00
Sam Lantinga
2cc6806472 Fixed bug 3705 - Add capture support to the sndio backend
kdrakehp

The attached patch adds capture support to the sndio backend.

The patch also allows the `OpenDevice' function to accept arbitrary device names.
2017-07-20 10:39:47 -07:00
Philipp Wiesemann
fb9c2939c2 qnx: Fixed setting a field twice. 2017-07-07 23:00:10 +02:00
Ryan C. Gordon
1683a0c106 audio: trying to pacify static analysis. 2017-07-05 12:04:37 -04:00
Philipp Wiesemann
9f99b3d7ee aix: Fixed audio debug output.
DEBUG_AUDIO is checked with #ifdef not #if.
2017-07-02 22:46:49 +02:00
Philipp Wiesemann
4366721b46 qnx: Removed unused bootstrap declaration.
QNX_bootstrap is the VideoBootStrap. QSAAUDIO_bootstrap is still there.
2017-07-02 22:46:00 +02:00
Ryan C. Gordon
22241ed0b0 Support for QNX 7.0 (thanks, Elad!).
Fixes Bugzilla #3686.
2017-07-01 17:50:47 -04:00
Philipp Wiesemann
380e0693b1 aix: Fixed compile error. 2017-07-01 23:01:49 +02:00
Philipp Wiesemann
4c190ce584 netbsd: Fixed comment. 2017-07-01 23:00:07 +02:00
Philipp Wiesemann
4c48260ca2 netbsd: Removed unused field. 2017-06-29 23:00:18 +02:00
Philipp Wiesemann
7bb6b402c2 netbsd: Fixed compile error. 2017-06-29 23:00:09 +02:00
Ryan C. Gordon
a509719fc3 audio: Converter now checks a strict list of channels and formats we support. 2017-06-12 21:35:24 -04:00
Sam Lantinga
553b328664 Fixed bug 3668 - Overflow of SDL_AudioCVT.filters with some downmixes
Simon Hug

There's a chance that an audio conversion from many channels to a few can use more than 9 audio filters. SDL_AudioCVT has 10 SDL_AudioFilter pointers of which one has to be the terminating NULL pointer. The SDL code has no checks for this limit. If it overflows there can be stack or heap corruption or a call to 0xa.

Attached patch adds a function that checks for this limit and throws an error if it is reached. Also adds some documentation.

Test parameters that trigger this issue:
AUDIO_U16MSB with 224 channels at 46359 Hz
                 V
AUDIO_S16MSB with 6 channels at 27463 Hz

The fuzzer program I uploaded in bug 3667 has more of them.
2017-06-12 16:39:15 -07:00
Ryan C. Gordon
325330efdb jack: removed accidental copy/paste. 2017-06-09 17:37:43 -04:00
Ryan C. Gordon
58f08af46c jack: added capture support. 2017-06-09 00:47:47 -04:00
Ryan C. Gordon
c39fd5777d jack: Move jack_client_t into the audio device instead a global variable. 2017-06-09 00:14:50 -04:00
Ryan C. Gordon
b65e0777ce jack: Remove BROKEN_MULTI_DEVICE code. 2017-06-08 22:20:49 -04:00
Ryan C. Gordon
d9039f2396 jack: Initial shot at a JACK audio target.
http://jackaudio.org/

Fixes Bugzilla #2163.
(with several more commits following to improve this code.)
2017-06-08 13:27:58 -04:00
Philipp Wiesemann
63b3e06f75 Corrected names of header file guards. 2017-06-03 23:00:15 +02:00
Philipp Wiesemann
fc510bd798 nacl: Fixed crash if allocating memory for audio device failed. 2017-05-28 21:50:47 +02:00
Philipp Wiesemann
7c5078d8bd qnx: Removed unnecessary check for available audio devices. 2017-05-28 21:50:37 +02:00
Philipp Wiesemann
1e60ea76db qnx: Removed unnecessary call to SDL_zerop() after SDL_calloc(). 2017-05-28 21:50:27 +02:00
Ryan C. Gordon
e5918acf46 wasapi: properly report init failure if on pre-Vista version of Windows.
We really should change the Init interface to return 0 on success and -1 on
error, like everything else, to avoid this sort of confusion.
2017-05-28 00:41:55 -04:00
Philipp Wiesemann
3639895eac Removed unused errno includes. 2017-05-27 23:30:07 +02:00
Philipp Wiesemann
759319729c emscripten: Fixed compiling on C89 compilers. 2017-05-26 22:45:40 +02:00
Ryan C. Gordon
a7fc2822d4 audio: rename bsd target to netbsd.
Apparently this is no longer a generic BSD audio target, and hasn't been for
years, so rename it for NetBSD.
2017-05-24 19:56:59 -04:00
Ryan C. Gordon
6844d92c23 coreaudio: we don't need to track number of allocated audio buffers anymore.
CoreAudio takes care of iterating through the buffers and freeing them now,
so we don't have to manage this ourselves.
2017-05-24 13:28:13 -04:00
Ryan C. Gordon
fc4402e5ff coreaudio: Better handling of audio buffer queue management.
We don't fill buffers just to throw them away during shutdown now, we let the
AudioQueue free its own buffers during disposal (which fixes possible warnings
getting printed to stderr by CoreAudio), and we stop the queue after running
any queued audio during shutdown, which prevents dropping the end of the
audio playback if you opened the device with an enormous sample buffer.

Fixes Bugzilla #3555.
2017-05-24 13:25:31 -04:00
Ryan C. Gordon
3fd35f6bb0 coreaudio: looks like we need more like a 10ms buffer minimum, not 50ms. 2017-05-24 01:28:03 -04:00
Ryan C. Gordon
793c788b1c coreaudio: dynamically allocate AudioQueueBuffers.
We need more than two buffers to flip between if they are small, or CoreAudio
won't make any sound; apparently it needs X milliseconds of audio queued when
it needs to play more or it drops any queued buffers. We are currently
guessing 50 milliseconds as a minimum, but there's probably a more proper
way to get the minimum time period from the system.

Fixes Bugzilla #3656.
2017-05-24 00:12:22 -04:00
Ryan C. Gordon
91e6054b03 wasapi: don't mark capture devices as failed for AUDCLNT_S_BUFFER_EMPTY.
Fixes Bugzilla #3633.
2017-05-19 12:40:55 -04:00
Ryan C. Gordon
81ab6c98fd Patched to compile on Windows. 2017-05-18 16:27:36 -04:00
Ryan C. Gordon
13b6d9959a wasapi: Replace tabs with strings in source code. 2017-05-18 15:46:06 -04:00
Ryan C. Gordon
adabc38439 wasapi: Deal with AUDCLNT_S_BUFFER_EMPTY when flushing audio device. 2017-05-18 15:43:51 -04:00
Ryan C. Gordon
4073a6694f audio: One more callbackspec fix (thanks, Simon!). 2017-05-18 15:33:17 -04:00
Ryan C. Gordon
c878b59bbe audio: fixed more "spec" references that should have been "callbackspec".
This should catch all the ones for audio targets that have provided their
own audio threads.
2017-05-10 16:18:43 -04:00
Alex Szpakowski
75fb07a6d2 iOS: Only mark interrupted audio devices as non-interrupted if AudioQueueStart is successful. 2017-05-03 18:05:29 -03:00
Ryan C. Gordon
226541cb5b audio: another wrong struct that causes NULL pointer crash (thanks, Simon!).
Fixes Bugzilla #3632.
2017-04-26 01:43:40 -04:00
Juha Kuikka
7382cebb41 audio: Fix audio queue functions to use new spec structure.
Using the old spec structure causes the audio queueing functions to fail
due to bad callback pointers being checked.
2017-04-20 21:25:29 -04:00
Sam Lantinga
d20d426c3a Fix crash in SDL audio thread, by Juha Kuikka
Wrong audio spec structure was populated with the internal callback, causing the audio thread to call a NULL pointer.
2017-04-18 22:17:40 -07:00
Ryan C. Gordon
028716e79f wasapi: deal with default device changes, and more robust failure recovery. 2017-03-30 16:33:47 -04:00
Ryan C. Gordon
c85c57a05d wasapi: Handle lost audio device endpoints.
This gracefully recovers when a device format is changed, and will switch
to the new default device if the current one is unplugged, etc.

This does not handle when a new default device is added; it only notices
if the current default goes away. That will be fixed by implementing the
stubbed-out MMNotificationClient_OnDefaultDeviceChanged() function.
2017-03-29 14:23:39 -04:00
Philipp Wiesemann
266816b4aa Removed newlines from error messages. 2017-03-26 21:00:19 +02:00
Sam Lantinga
6814f5dbc0 ALSA driver improvements:
* alsa hotplug thread is low priority
* give a chance for other threads to catch up when audio playback is not progressing
* use nonblocking for alsa audio capture
  There is a bug with SDL hanging when an audio capture USB device is removed, because poll never returns
2017-03-14 07:20:14 -07:00
Sam Lantinga
c4d54504fa differentiate between capture / playback audio thread names 2017-03-14 07:16:56 -07:00
Ryan C. Gordon
ca0bf151d5 Fix some more compiler warnings on armcc. 2017-03-03 16:38:17 -05:00
Ryan C. Gordon
d526b8a1e9 Some patches to make SDL compile with armcc (ARM's C compiler). 2017-03-02 13:33:04 -05:00
Ryan C. Gordon
a4249b48ee Patched to compile on C89 compilers. 2017-02-26 00:56:13 -05:00
Ryan C. Gordon
3b9e4d0a6c audio: Try to keep callbacks firing at normal pace when device is lost. 2017-02-26 00:39:22 -05:00
Ryan C. Gordon
a366c35f37 audio: run the audio callback even if device was lost.
We will throw away the data anyhow, but some apps depend on the callback
firing to make progress; testmultiaudio.c, if nothing else, is an example
of this.

Capture also will now fire the callback in these conditions, offering nothing
but silence.

Apps can check SDL_GetAudioDeviceStatus() or listen for the
SDL_AUDIODEVICEREMOVED event if they want to gracefully deal with
an opened audio device that has been unexpectedly lost.
2017-02-26 00:12:33 -05:00
Ryan C. Gordon
5728cb2025 audio: Make sure the disk and dummy targets are the last ones we try to init. 2017-02-26 00:10:02 -05:00
Sam Lantinga
71a4e8ed13 Stop CoreAudio from doing expensive audio rate conversion 2017-02-23 12:10:02 -08:00
Philipp Wiesemann
cfcec57f42 Fixed comment. 2017-02-19 21:05:09 +01:00
Ryan C. Gordon
e8677a1bd2 audio: Added basic WAVE_FORMAT_EXTENSIBLE support to .wav loader.
This is just enough to get you through a file that just used the extended
header for float or int data. It doesn't handle all the other things that
you expect from this header, like 24-bit samples inside a 32-bit container
or speaker masks.
2017-02-17 02:25:37 -05:00
Ryan C. Gordon
1ed41d6d0d Patched to compile on Windows. 2017-02-14 03:12:09 -05:00
Ryan C. Gordon
6046fd4cb0 wasapi: Initial WASAPI support, for Windows Vista and later.
This should remain binary compatible with Windows XP, as we dynamically
load anything we need and fall back to DirectSound/WinMM/XAudio2 if not
available.
2017-02-14 03:03:27 -05:00
Ryan C. Gordon
e5fc93baca audio: Don't wrap bootstrap declarations in preprocessor macros.
They are harmless and ignored if we don't actually link against them. The
preprocessor checks elsewhere if they're actually used.
2017-02-13 16:59:02 -05:00
Ryan C. Gordon
ad9c702f6a audio: SDL_AudioStream's *_sample_frame_size should be in bytes, not bits.
Fixes failures where SDL_AudioStreamGet() incorrectly thinks it got a partial
sample frame request.
2017-02-13 16:56:41 -05:00
Ryan C. Gordon
175f1e8f4a audio: Added a ThreadDeinit() method to match ThreadInit.
Not used by any targets at the moment, but will be shortly!
2017-02-13 16:55:00 -05:00
Sam Lantinga
886736a2c8 Fixed bug 3584 - Small stack size for audio callback thread
Walter van Niftrik

We have found that since SDL 2.0.5 the audio callback thread is created with a very small stack size. In our application this is leading to stack overflows.

We believe there is a bug at http://hg.libsdl.org/SDL/file/391fd532f79e/src/audio/SDL_audio.c#l1132, where the is_internal_thread flag appears to be inverted.
2017-02-11 16:38:16 -08:00
Sam Lantinga
107c19daad Log the error returned by XAudio2Create() 2017-02-09 06:01:14 -08:00
Sam Lantinga
ede5c73484 Generalized the audio resampling hint for other resampling methods in the future 2017-01-24 19:38:01 -08:00
Ryan C. Gordon
47e2f4e950 audio: libsamplerate can't resample in-place; make space for a copy if needed. 2017-01-24 20:30:48 -05:00
Ryan C. Gordon
c7f9dcb6fc audio: Offer a hint for libsamplerate quality/speed tradeoff.
This defaults to the internal SDL resampler, since that's the likely default
without a system-wide install of libsamplerate, but those that need more can
tweak this.
2017-01-24 15:52:22 -05:00
Ryan C. Gordon
1da3a33773 audio: Fix static analysis concerns about a dead assignment. 2017-01-24 10:09:29 -05:00
Ryan C. Gordon
8f627c1cd8 audio: Make sure SDL_AudioStream's work buffer is 16-byte aligned, for SIMD.
Note the giantic FIXME, though!
2017-01-24 00:51:33 -05:00
Ryan C. Gordon
17dcee20c1 audio: Streams now resample in-place. Removed second allocated buffer. 2017-01-24 00:17:40 -05:00
Ryan C. Gordon
b5eeab779f audio: allow stereo Sint16 resampling fast path in SDL_AudioStream.
This currently favors libsamplerate over the fast path (quality over speed),
but I'm not sure that's the correct approach, as there may be surprising
changes in performance metrics depending on what packages are available on
a user's system. That being said, currently, the only thing with access to
SDL_AudioStream is an SDL audio device's thread, and it might be mostly idle
otherwise, so maybe this is generally good.
2017-01-24 00:08:24 -05:00
Ryan C. Gordon
a80cb672e3 audio: Fixed off-by-one error in upsampling. 2017-01-24 00:03:36 -05:00
Ryan C. Gordon
dad07f960b audio: Resampler now special-cases stereo and mono processing.
Turns out that iterating from 0 to channels-1 was a serious performance hit!

These cases now tend to match or beat the original audio resampler's speed!
2017-01-23 16:45:50 -05:00
Ryan C. Gordon
8ce6ddf125 audio: Fixed incorrect pointer in SDL_ResampleCVT_si16_c2().
Forgot to update this when we changed this to process in-place. Whoops!
2017-01-23 16:42:47 -05:00
Ryan C. Gordon
ecdc6c1207 audio: Fixed copy/paste bug in float32->sint16/SSE2 scalar leftover code. 2017-01-23 12:14:28 -05:00
Ryan C. Gordon
4b8f354668 audio: Fix same bug as last commit, but for _mm_bslli_si128 vs _mm_slli_si128. 2017-01-23 12:06:10 -05:00
Ryan C. Gordon
fab4501811 audio: use _mm_srli_si128 instead of _mm_bsrli_si128.
They're the same thing (one is generally a #define of the other), but some
toolchains don't offer the 'b' version.
2017-01-23 12:02:02 -05:00
Ryan C. Gordon
3594bf8eeb audio: Wired up new SSE code to build system. 2017-01-23 01:05:44 -05:00
Ryan C. Gordon
202ab30c16 audio: Special case for resampling stereo AUDIO_S16SYS audio data.
This is a fairly common case, so we avoid the conversion to/from float here.
2017-01-22 20:27:48 -05:00
Ryan C. Gordon
8855daac66 audio: Make the simple resampler operate in-place.
This allows us to avoid an extra copy, allocate less memory and reduce cache
pressure. On the downside: we have to do a lot of tapdancing to resample the
buffer in reverse when the output is growing.
2017-01-22 23:48:15 -05:00
Ryan C. Gordon
64056e81cd audio: Added SSE3 implementation of SDL_ConvertStereoToMono(). 2017-01-23 00:57:19 -05:00