Commit graph

82 commits

Author SHA1 Message Date
Ryan C. Gordon
50bb6473ed 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.

--HG--
extra : rebase_source : cab98b19216722eae3749cc1e1429d1c802e9782
2017-01-22 23:48:15 -05:00
Ryan C. Gordon
6ceacbdc4a audio: Added SSE3 implementation of SDL_ConvertStereoToMono().
--HG--
extra : rebase_source : 92882c4fdf5dc4a326057f577ccb4c29c32f938e
2017-01-23 00:57:19 -05:00
Ryan C. Gordon
8af7561815 audio: don't cast to double in SDL_ConvertStereoToMono().
It's expensive and (hopefully) unnecessary. If this becomes an overflow
problem, we could multiply both values by 0.5f before adding them, but let's
see if we can get by without the extra multiplication first.

--HG--
extra : rebase_source : b7b47e961eb974510e133882548ea36b40f6d7e3
2017-01-22 20:18:59 -05:00
Ryan C. Gordon
34fe29bc62 audio: removed conditional from simple resampler's inner loop.
We never seem to overflow the source buffer now; this might have been a
leftover from a bug that was covered by Vitaly's fixes?

Removing this conditional makes the resampler 10-20% faster. Left an
assert in there for debug builds, in case this still happens.

--HG--
extra : rebase_source : c05a536f5a80f065c0872b35d77d4f70a56b4e3e
2017-01-20 16:26:24 -05:00
Ryan C. Gordon
adb1d6888f audio: Several fixes to "simple" resampler (thanks, Vitaly!).
Fixes Bugzilla #3551.
2017-01-18 02:11:56 -05:00
Ryan C. Gordon
c40d568133 audio: Some fixes to the audio data type converter code.
Removed some needless things ("len / sizeof (Uint8)"), and made sure the
int32 -> float code uses doubles to avoid working with large integer values
in a 32-bit float.

--HG--
extra : rebase_source : c803b416ec487b8c0feba780ac06f8d11e90879b
2017-01-15 05:01:59 -05:00
Sam Lantinga
8eb437d4e7 Fixed bug 3552 - Building SDL in release mode fails under VS 2017 RC
Lukasz Biel

Tried to compile SDL2 using newest version of VS.

Got:
SDL_audiocvt.obj : error LNK2019: unresolved external symbol memcpy referenced in function SDL_ResampleCVT
1>E:\Users\dotPo\Lib\SDL\VisualC\x64\Release\SDL2.dll : fatal error LNK1120: 1 unresolved externals

whole compilation process: http://pastebin.com/eWDAvBce

Steps to reproduce:
clone http://hg.libsdl.org/SDL using tortoise hg,
open SDL\VisualC\SDL.sln,
when promted if should retarget solution click ok,
select release x64 build type,
Build/Build Solution

attempt 2, using Visual Studio cmake support:
open folder SDL\
select release x64 build type,
run CMake\Build CMakeLists.txt
build fails

When switched to debug build type, buils succeeds in both cases.
VS 2017 is still beta.
2017-01-09 20:37:52 -08:00
Ryan C. Gordon
27737db314 audio: Don't ever use libsamplerate in the SDL_AudioCVT codepath.
It causes audio pops if you're converting in chunks (and needs to
allocate/initialize/free on each convert). We'll either adjust this interface
when we break ABI for 2.1 to make this usable, or publish the SDL_AudioStream
API for those that want a streaming solution.

In the meantime, the "simple" resampler produces "good enough" audio without
pops and doesn't have to be initialized, so that'll do for now on the
SDL_AudioCVT interface.

--HG--
extra : rebase_source : 4c5656de3d1de9f88d6368e5ca363d834fc93af1
2017-01-09 16:31:57 -05:00
Ryan C. Gordon
2f283c2beb audio: Replaced older resamplers in SDL_AudioCVT with the new ones.
--HG--
extra : rebase_source : a4df0c56d61d9927e97bbd738c12a3043f44742e
2017-01-09 06:00:58 -05:00
Ryan C. Gordon
9268415b53 audio: Improvements in channel conversion code.
--HG--
extra : amend_source : 521d4d1f25bba02be473faa4d573928ea9007452
2017-01-08 16:18:49 -05:00
Ryan C. Gordon
d8f718f75d audio: Patched to compile with libsamplerate support. 2017-01-08 14:23:15 -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
Ryan C. Gordon
d81fb0038f Fixed coding style on a function signature.
--HG--
extra : rebase_source : ccbcdf0c433bac0ad213f4a377674363b1fab87e
2017-01-08 14:17:09 -05:00
Sam Lantinga
5a0aef995a Added configure and cmake support for libsamplerate 2017-01-06 20:43:53 -08:00
Ryan C. Gordon
8ab0ba202d audio: Don't call a NULL function pointer when clearing audio streams.
(Partially?) fixes Bugzilla #3547.
2017-01-06 21:23:51 -05:00
Sam Lantinga
376e6fa6f2 Added support for using libsamplerate to do audio resampling 2017-01-06 02:16:26 -08:00
Sam Lantinga
2373e22054 Don't do any audio conversion if none is necessary 2017-01-05 23:53:46 -08: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
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
Ryan C. Gordon
02fd7b4a1e audio: More effort to improve and simplify audio resamplers.
--HG--
extra : rebase_source : a46522900178929c58d4e5442f710eb1ae31e91e
2017-01-05 19:12:20 -05:00
Sam Lantinga
1b24bfad38 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Philipp Wiesemann
5665ff1e98 Fixed audio conversion for unsigned 16 bit data. 2016-11-07 21:10:01 +01:00
Sam Lantinga
a966c3035b Fixed Windows build 2016-11-05 01:52:28 -07:00
Ryan C. Gordon
6441c50b51 Also patched to compile on C89 compilers. 2016-11-05 03:56:55 -04:00
Ryan C. Gordon
a053163b55 Patched to compile on C89 compilers. 2016-11-05 03:53:59 -04:00
Ryan C. Gordon
9d3696362e Reworked audio converter code.
This no longer uses a script to generate code for every possible type
conversion or resampler. This caused a bloat in binary size and and compile
times. Now we use a handful of more generic functions and assume staying in
the CPU cache is the most important thing anyhow.

This shrinks the size of the final build (in this case: macOS X amd64, -Os to
optimize for size) by 15%. When compiling on a single core, build times drop
by about 15% too (although the previous cost was largely hidden by multicore
builds).

--HG--
extra : amend_source : ce9deadd24e237eb83d2ef900c493f25c7cf3a80
2016-11-05 02:34:38 -04:00
Sam Lantinga
7ee8dda270 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Sam Lantinga
56b58afdbe Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
James Legg
9c3587ee5d Fix audio conversion when channel count changes
- Use the SDL_AUDIO_MASK_DATATYPE bit when selecting an implementation
  where it matters. Previously two existing AUDIO_F32 cases had been
  written, but were unreachable.
- Add AUDIO_F32 case for SDL_ConvertSurround_4.
- Fix incorrect pointer arithmetic causing the 2 to 6 channel
  conversion for 4 byte audio formats to read and write beyond the end
  of the buffer.
2014-02-21 13:57:53 +00:00
Sam Lantinga
d7940a513e Fixed bug 2374 - Update copyright for 2014...
Is it that time already??
2014-02-02 00:53:27 -08:00
Ryan C. Gordon
82edee6971 Make internal SDL sources include SDL_internal.h instead of SDL_config.h
The new header will include SDL_config.h, but allows for other global stuff.

--HG--
extra : rebase_source : ddf4a4c0dc2c554b98c82700798f343cd91b16e3
2013-11-24 23:56:17 -05:00
Ryan C. Gordon
de2ec2b443 Fixed off-by-one error in SDL_ConvertStereo().
Fixes Bugzilla #561.

--HG--
extra : rebase_source : a21159567a0a8a9485c46d4c67e57224948952a0
2013-07-12 01:26:43 -04:00
Sam Lantinga
0cb6385637 File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00
Ryan C. Gordon
4f438b70a2 Make SDL_SetError and friends unconditionally return -1.
This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
2013-03-31 12:48:50 -04:00
Sam Lantinga
95dcfa4c28 Happy New Year! 2013-02-15 08:47:44 -08:00
Andreas Schiffler
b507ef3afa Add additional input validation to SDL_BuildAudioCVT; add additional tests to automation (audio, rwops) 2013-01-21 09:16:27 -08:00
Sam Lantinga
f380ecb137 Removed executable bit from source files 2012-09-27 14:35:28 -07:00
Ryan C. Gordon
df8784cd61 Replaced some assert macros with SDL_assert. 2012-02-07 02:11:15 -05:00
Sam Lantinga
17d38b0d37 Fixed issue where there was a garbage sample at the end of the buffer. 2012-01-12 21:42:35 -05:00
Sam Lantinga
7e2e5d34e6 Fixed bug 1091 - Hardcoded size in SDL_audiocvt.c may lead to heap/stack corruption
Markovtsev Vadim 2011-01-18 22:00:16 PST

SDL_audiocvt.c:

static void SDLCALL
SDL_ConvertStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format):

#define dup_chans_1_to_2(type) \
    { \
        const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
        type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \
        for (i = cvt->len_cvt / 2; i; --i, --src) { \
            const type val = *src; \
            dst -= 2; \
            dst[0] = dst[1] = val; \
        } \
    }

Pay attention to cvt->len_cvt / 2. 2 is the sizeof(Uint16), hovewer, below we
see that the conversion function supports Uint8 and Uint32:

switch (SDL_AUDIO_BITSIZE(format)) {
    case 8:
        dup_chans_1_to_2(Uint8);
        break;
    case 16:
        dup_chans_1_to_2(Uint16);
        break;
    case 32:
        dup_chans_1_to_2(Uint32);
        break;
    }

If type is Uint32, src will be decreased twice as it should be, memory being
written before the cvt->buf. If type is Uint8, the conversion will not be
complete. I suggest to change that define to

#define dup_chans_1_to_2(type) \
    { \
        const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
        type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \
        for (i = cvt->len_cvt / sizeof(type); i; --i, --src) { \
            const type val = *src; \
            dst -= 2; \
            dst[0] = dst[1] = val; \
        } \
    }

I tested that and now it's working fine. I did not consider the similar defines
in functions nearby.
2012-01-08 17:20:33 -05:00
Sam Lantinga
028e5dcdbd Happy New Year! 2011-12-31 09:28:07 -05:00
Sam Lantinga
b0660ba5ff SDL 1.3 is now under the zlib license. 2011-04-08 13:03:26 -07:00
Sam Lantinga
e5803d148c Happy 2011! :) 2011-02-11 22:37:15 -08:00
Sam Lantinga
4d3df8b3e3 Fixed bug #926
Updated copyright to LGPL version 2.1 and year 2010

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404453
2010-01-24 21:10:53 +00:00
Sam Lantinga
f0b63f9249 Add error messages for failure cases
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404232
2009-11-25 06:00:00 +00:00
Sam Lantinga
628262d3af indent
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403502
2009-01-14 04:25:32 +00:00
Sam Lantinga
e43f6d619e Fixed Visual C++ build
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403494
2009-01-12 08:46:28 +00:00
Ryan C. Gordon
fea75bcab7 First shot at new audio resampling code.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403483
2009-01-11 04:46:42 +00:00
Sam Lantinga
e32916c7f0 Fixed Visual C++ release build for Visual C++ 2005
* Some math functions become intrinsic in release mode, so we need to
  convert all the math functions into SDL math functions, like we did
  with the stdlib functions.
* Constant initializers of 8-bit values become calls to memset() in
  release mode, but memset() itself is an intrinsic when explicitly
  called.  So we'll just explicitly call memset() in those cases.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403474
2009-01-10 18:32:24 +00:00