Commit graph

225 commits

Author SHA1 Message Date
Ryan C. Gordon
3a641f7b0b 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
Sam Lantinga
89e73e7c17 differentiate between capture / playback audio thread names 2017-03-14 07:16:56 -07:00
Ryan C. Gordon
45e302d5bc Patched to compile on C89 compilers. 2017-02-26 00:56:13 -05:00
Ryan C. Gordon
ca264fd374 audio: Try to keep callbacks firing at normal pace when device is lost.
--HG--
extra : histedit_source : 6af6e582c33b800c543fd1f4d73e99fe4cbba824
2017-02-26 00:39:22 -05:00
Ryan C. Gordon
0e1aaaeceb 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.

--HG--
extra : rebase_source : 8d6cf4c4e88a98cc85558693aff30fac25a8ed7e
2017-02-26 00:12:33 -05:00
Ryan C. Gordon
80cffbfbb1 audio: Make sure the disk and dummy targets are the last ones we try to init.
--HG--
extra : rebase_source : 68fbb52bf496d1430aba671e047b90be5cc524b7
2017-02-26 00:10:02 -05:00
Ryan C. Gordon
d862693a74 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
554e4ad86b audio: Added a ThreadDeinit() method to match ThreadInit.
Not used by any targets at the moment, but will be shortly!

--HG--
extra : rebase_source : 0c60a1caf9cefe05d50ea48aa67bf571e2590a60
2017-02-13 16:55:00 -05:00
Sam Lantinga
923867b8c8 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/5a77f977ad95/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
4fad2b3b61 Generalized the audio resampling hint for other resampling methods in the future 2017-01-24 19:38:01 -08:00
Ryan C. Gordon
0dc13f56ec 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.

--HG--
extra : amend_source : 804f3d3dc636b5f28f7194b48b492c6c3fe05bf5
2017-01-24 15:52:22 -05:00
Ryan C. Gordon
f025391f8c audio: Implemented SIMD support for audio data type converters.
This currently adds an SSE2 implementation (but it's #ifdef'd out for now,
until it's hooked up to the configure script and such).
2017-01-16 00:58:28 -05:00
Ryan C. Gordon
575a388ff4 audio: Patched to compile if linking directly to libsamplerate.
--HG--
extra : rebase_source : 32676dd43d1d33c1985c4dc6cef969ddbc082935
2017-01-09 05:59:30 -05:00
Ryan C. Gordon
ba27cf3fc1 audio: Patched to compile with libsamplerate support (again). 2017-01-08 14:28:44 -05:00
Ryan C. Gordon
f904fecce3 audio: libsamplerate loading now happens once at init time.
--HG--
extra : rebase_source : b88014744534e382d6b6ea004554ffcebe5caffe
2017-01-08 14:18:03 -05:00
Sam Lantinga
b2161da809 Fixed confusion between Ryan's new audio stream and the audio buffer we were calling stream in the callback 2017-01-06 00:47:42 -08:00
Ryan C. Gordon
70c33e0441 audio: Add an assert to make sure non-streaming audio uses good buffer sizes.
--HG--
extra : rebase_source : 80db5ce8cde0774915b7bc68542e1a58a49d6f18
2017-01-06 03:38:14 -05:00
Ryan C. Gordon
d8788062d4 audio: rename fake_stream to work_buffer.
It's more than an alternative for when the OS can't provide a DMA buffer, now.
2017-01-06 01:07:34 -05:00
Ryan C. Gordon
29fb138f51 audio: Fixed SDL_AudioStreamGet() function parameters.
There was a draft of this where it did audio conversion into the final buffer,
if there was enough room available past what you asked for, but that interface
got removed, so the parameters didn't make sense (and we were using the
wrong one in any case, too!).
2017-01-06 01:02:58 -05:00
Ryan C. Gordon
bd307581b6 emscriptenaudio: Reworked to use SDL_AudioStream.
--HG--
extra : amend_source : ef370fe4cb3d7446d1af21a0d452bd4393909e7a
2017-01-05 21:31:02 -05:00
Ryan C. Gordon
591dff71c2 Fixed a few compiler warnings. 2017-01-05 20:11:19 -05:00
Ryan C. Gordon
70608017eb audio: Added SDL_AudioStream. Non-power-of-two resampling now works!
--HG--
extra : rebase_source : f6b2eb0c8a4d8869879112d60abe32962839fe7a
2017-01-05 19:29:38 -05:00
Sam Lantinga
1b24bfad38 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga
88c9dd30ad Fixed bus error when converting 16-bit to float for non-integral-multiple sample rates 2016-12-19 11:15:53 -08:00
Ryan C. Gordon
887f7da383 audio: Fixed compiler warnings. 2016-12-06 12:23:17 -05:00
Ryan C. Gordon
1f9dbc5f66 Refactored the audio queueing code to a generic SDL_DataQueue interface.
This is not a public API (at the moment), but we will be needing this for
other internal things soon.

--HG--
extra : rebase_source : a9cc678783f19b02978f9b09f77b6a4ae9759a92
2016-12-06 02:23:54 -05:00
Sam Lantinga
dae32409e9 Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
Ryan C. Gordon
593954247f audio: Backed out the audio-thread detaching changes.
It added a ton of complexity. A simpler solution might arise at some
point though.

--HG--
extra : rebase_source : 954c49df5e14292b459bbd8cbb550c7c40ff7645
2016-10-07 19:39:43 -04:00
Ryan C. Gordon
ff255ca66e audio: Don't trust audio drivers to drain pending audio.
This tends to be a frequent spot where drivers hang, and the waits were
often unreliable in any case.

Instead, our audio thread now alerts the driver that we're done streaming audio
(which currently XAudio2 uses to alert the system not to warn about the
impending underflow) and then SDL_Delay()'s for a duration that's reasonable
to drain the DMA buffers before closing the device.
2016-10-07 15:13:46 -04:00
Ryan C. Gordon
ae70bcd0f5 audio: better way to calculate buffer drain wait times. 2016-10-07 14:42:24 -04:00
Ryan C. Gordon
764d03666b audio: threading and device hang improvements.
This tries to make SDL robust against device drivers that have hung up,
apps don't freeze in catastrophic (but not necessarily uncommon) conditions.

Now we detach the audio thread and let it clean up and don't care if it
never actually runs to completion.
2016-10-07 14:35:25 -04:00
Sam Lantinga
069b980b6e Backed out a very unsafe change that was trying to prevent audio hang at quit.
Ryan and I have ideas on a better way to handle this.
2016-10-05 00:12:16 -07:00
Sam Lantinga
c0ceb21c52 ensure SDL_AUDIODEVICEREMOVED gets sent when hotplug removes a device
James Zipperer

The problem I was seeing was that the the ALSA hotplug thread would call SDL_RemoveAudioDevice, but my application code was not seeing an SDL_AUDIODEVICEREMOVED event to go along with it.   To fix it, I added some code into SDL_RemoveAudioDevice to call SDL_OpenedAudioDeviceDisconnected on the corresponding open audio device.  There didn't appear to be a way to cross reference the handle that SDL_RemoveAudioDevice gets and the SDL_AudioDevice pointer that SDL_OpenedAudioDeviceDisconnected needs, so I ended up adding a void *handle field to struct SDL_AudioDevice so that I could do the cross reference.

Is there some other way beside adding a void *handle field to the struct to get the proper information for SDL_OpenedAudioDeviceDisconnected?
2016-10-04 06:48:07 -07:00
Sam Lantinga
09ecd06e3f fix deadlock on close device
James Zipperer

snd_pcm_drain doesn't always drain when you unplug a usb device.  Use snd_pcm_drop instead
2016-10-04 06:46:46 -07:00
Sam Lantinga
0b40668408 fix audio deadlock
James Zipperer

Close the audio device before waiting for the audio thread to complete, which fixes a situation where the audio thread never completes

Add an additional check in the audio thread to see if the device is enabled and bail out if the device is no longer enabled
2016-10-04 06:45:28 -07:00
Ryan C. Gordon
fd200e01ab audio: Cleaned up "extern AudioBootStrap" list. 2016-08-11 22:26:58 -04:00
Ryan C. Gordon
7ab6161c20 audio: Renamed some internal driver symbols in various targets.
--HG--
extra : histedit_source : 3fcfd8a18486901531c00b5440a619ae22cc423d%2Ca85f21071e16f001b28ecee20ca8c9fa38e5b215
2016-08-11 22:22:09 -04:00
Ryan C. Gordon
f2e2d65d66 audio: Patched to compile on C89 compilers. 2016-08-10 14:14:14 -04:00
Ryan C. Gordon
d64862530f audio: Only allocate fake_stream if we're using the standard audio threads. 2016-08-09 00:44:59 -04:00
Ryan C. Gordon
6d4ba05bf6 audio: simplifed check for internal callback.
Easier to check when it's NULL instead of a list of known internal functions.
2016-08-09 00:44:05 -04:00
Ryan C. Gordon
602c1026e0 disk audio: Implemented "capture" support, cleaned up some things. 2016-08-06 03:39:15 -04:00
Ryan C. Gordon
42e7791e9e audio: Implemented buffer queueing for capture devices (SDL_DequeueAudio()). 2016-08-06 02:47:27 -04:00
Ryan C. Gordon
b441df53cc audio: SDL_ClearQueuedAudio() should free everything but two packets.
Otherwise, if you had a massive, one-time queue buildup, the memory from that
remains allocated until you close the device. Also, if you are just using a
reasonable amount of space, this would previously cause you to reallocate it
over and over instead of keeping a little bit of memory around.
2016-08-06 02:27:55 -04:00
Ryan C. Gordon
18b414baa6 audio: Changed OnlyHasDefaultInputDevice to OnlyHasDefaultCaptureDevice. 2016-08-05 02:04:48 -04:00
Ryan C. Gordon
26a75839f4 audio: Removed internal SDL_audiomem.h and macros.
I think this was important for SDL 1.2 because some targets needed
special device memory for DMA buffers or locked memory buffers for use in
hardware interrupts or something, but since it just defines to SDL_malloc
and SDL_free now, I took it out for clarity's sake.

--HG--
extra : histedit_source : 57b48e44e65de9ce4e16604167db325df05bdf98%2C31d881e4d1b5eeba771f04bb43be0d23c3e605ce
2016-08-05 01:44:15 -04:00
Ryan C. Gordon
84e966c070 audio: Clean up some CloseDevice() interface details.
- It's now always called if device->hidden isn't NULL, even if OpenDevice()
  failed halfway through. This lets implementation code not have to clean up
  itself on every possible failure point; just return an error and SDL will
  handle it for you.

- Implementations can assume this->hidden != NULL and not check for it.

- implementations don't have to set this->hidden = NULL when done, because
  the caller is always about to free(this).

- Don't reset other fields that are in a block of memory about to be free()'d.

- Implementations all now free things like internal mix buffers last, after
  closing devices and such, to guarantee they definitely aren't in use anymore
  at the point of deallocation.

--HG--
extra : histedit_source : 03a1d12c89ebcc01743777ec68663a227265a7c6%2C722b053ebe4647a9e601d4e2c42e4050366b7f7d
2016-08-05 01:44:41 -04:00
Ryan C. Gordon
c715b1b009 audio: a little more robustness in the capture device's thread. 2016-08-02 15:04:33 -04:00
Ryan C. Gordon
7793384ffc audio: implemented higher level infrastructure for running capture devices. 2016-08-02 13:50:21 -04:00
Ryan C. Gordon
ff065554db audio: Made some SDL_AudioDevice fields atomic.
This makes sure they're properly communicated to the audio threads.
2016-08-02 13:48:52 -04:00
Ryan C. Gordon
0a21fedf8e audio: changed some internal ints to be SDL_bools. 2016-08-01 13:32:27 -04:00