Commit Graph

59 Commits

Author SHA1 Message Date
Max Kellermann
40f59cacda pcm: fixed software volume, broken by unsigned integer
"volume" was passed as an unsigned integer, which is correct.  It's
just that when it was multiplied with the sample value, the whole
operation was changed to unsigned, breaking the algorithm (and Qball's
ears).  Internally change "volume" to signed.
2008-10-09 15:18:09 +02:00
Max Kellermann
71351160b1 don't include os_compat.h
When there are standardized headers, use these instead of the bloated
os_compat.h.
2008-10-08 10:49:29 +02:00
Max Kellermann
6aec61637b pcm_utils: 24 bit support
Add support for 24 bit PCM samples to all functions.  Note that
pcm_convertAudioFormat() converts 24 bit samples to 16 bit; to
preserve full quality, support for "real" 24 bit conversion should be
added.
2008-09-29 17:26:07 +02:00
Max Kellermann
ac6bc76cdb pcm_utils: moved code to special 8/16 bit functions
Moved code into separate bit specific functions:
- pcm_volumeChange() -> pcm_volume_change_X()
- pcm_add() -> pcm_add_X()
- pcm_convertTo16bit() -> pcm_convert_8_to_16()
2008-09-29 17:25:45 +02:00
Max Kellermann
c85b570ad7 pcm_utils: pass only one buffer size to pcm_mix()
pcm_mix() might overflow the destination buffer if it is smaller than
the second buffer.  This is ok because the physical buffer size passed
by cross_fade_apply() is always big enough, but clutters pcm_mix()
with complicated length checks and contains a dangerous buffer
overflow pitfall.  Simplify pcm_mix()/pcm_add() and pass only the
smaller buffer size; let cross_fade_apply() do the memcpy().
2008-09-29 17:25:08 +02:00
Max Kellermann
a7651b9d30 assume stdint.h and stddef.h are available
Since we use a C99 compiler now, we can assert that the C99 standard
headers are available, no need for complicated compile time checks.
Kill mpd_types.h.
2008-09-29 15:53:53 +02:00
Eric Wong
0352766dca Switch to C99 types (retaining compat with old compilers)
Seeing the "mpd_" prefix _everywhere_ is mind-numbing as the
mind needs to retrain itself to skip over the first 4 tokens of
a type to get to its meaning.  So avoid having extra characters
on my terminal to make it easier to follow code at 2:30 am in
the morning.

Please report any new issues you may come across on Free
toolchains.  I realize how difficult it can be to build/maintain
cross-compiling toolchains and I have no intention of forcing
people to upgrade their toolchains to build mpd.

Tested with gcc 2.95.4 and and gcc 4.3.1 on x86-32.
2008-09-29 13:29:33 +02:00
Max Kellermann
88aaa6b759 pcm_utils: added pcm_range()
Make the code more readable by moving the range checks to pcm_range().
gcc does quite a good job at optimizing it: the resulting binary is
exactly the same, although it contains a parametrized shift instead of
hard-coded boundaries.
2008-09-28 18:37:43 +02:00
Max Kellermann
5b5e46f5ef pcm_utils: added inline function pcm_dither()
Merge some code into an inline function, so we can optimize it later
only once.
2008-09-28 18:35:42 +02:00
Max Kellermann
f1dd9c209c audio_format: converted typedef AudioFormat to struct audio_format
Get rid of CamelCase, and don't use a typedef, so we can
forward-declare it, and unclutter the include dependencies.
2008-09-07 19:19:55 +02:00
Max Kellermann
4dd9d4b2fd fix -Wcast-qual -Wwrite-strings warnings
The previous patch enabled these warnings.  In Eric's branch, they
were worked around with a generic deconst_ptr() function.  There are
several places where we can add "const" to pointers, and in others,
libraries want non-const strings.  In the latter, convert string
literals to "static char[]" variables - this takes the same space, and
seems safer than deconsting a string literal.
2008-09-07 19:14:39 +02:00
Max Kellermann
a383f45117 enable -Wpointer-arith, -Wstrict-prototypes
Also enable -Wunused-parameter - this forces us to add the gcc
"unused" attribute to a lot of parameters (mostly library callback
functions), but it's worth it during code refactorizations.
2008-08-26 08:27:02 +02:00
Max Kellermann
f201f2c922 more const pointers in pcm_utils.[ch]
git-svn-id: https://svn.musicpd.org/mpd/trunk@7360 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-15 05:56:35 +00:00
Eric Wong
9cfb4c0390 decode: fix some uninitialized variable warnings
They're probably not needed, but less noise => faster debugging

git-svn-id: https://svn.musicpd.org/mpd/trunk@7302 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:44 +00:00
Max Kellermann
dd20681daa missing const in disabled code path
git-svn-id: https://svn.musicpd.org/mpd/trunk@7298 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:16:18 +00:00
Max Kellermann
f7e97c9a89 constant pointers
There were some const pointers missing in the previous const-cleanup
patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7290 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:15:30 +00:00
Max Kellermann
623a86f389 use constant pointers when possible
It is a good practice to constify pointers when their dereferenced
data is not modified within the functions or its descendants.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7234 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:07:11 +00:00
Max Kellermann
27f12c173d use size_t
When dealing with in-memory lengths, the standard type "size_t" should
be used.  Missing one can be quite dangerous, because an attacker
could provoke an integer under-/overflow, which may provide an attack
vector.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7205 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:07 +00:00
Eric Wong
cb8f1af3bd Cleanup #includes of standard system headers and put them in one place
This will make refactoring features easier, especially now that
pthreads support and larger refactorings are on the horizon.

Hopefully, this will make porting to other platforms (even
non-UNIX-like ones for masochists) easier, too.

os_compat.h will house all the #includes for system headers
considered to be the "core" of MPD.  Headers for optional
features will be left to individual source files.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7130 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-01-03 07:29:49 +00:00
Eric Wong
54339dfbc2 pcm_utils: gcc 2.95 compile fix (extra semi-colon)
git-svn-id: https://svn.musicpd.org/mpd/trunk@6872 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-09-10 07:12:37 +00:00
J. Alexander Treuman
bba444524e Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a single
call to FATAL().

git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 18:15:54 +00:00
J. Alexander Treuman
dba45a5992 Cleaning up pcm_getSampleRateConverter.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6275 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 17:33:59 +00:00
J. Alexander Treuman
665ab83761 Exit with an error if channel count isn't 1 or 2.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6274 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 17:04:54 +00:00
J. Alexander Treuman
355d18a593 Make pcm_convertAudioFormat return the buffer size. This is necessary
because lsr may return less than the input buffer size, and the rest of the
audio code needs to know the new size.  This fixes the clicking that was
introduced with recent changes to the lsr code.  A huge thanks to remiss
for figuring this out.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6273 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-26 16:39:55 +00:00
J. Alexander Treuman
2814b7cfc6 Reverting to the full lsr API. Turns out the simple API needs all of the
audio at once, so it won't work for us.  The old full API code was still
heavily broken, as each call to pcm_convertSampleRate() used the same
state, even if it was processing two streams of audio.  The new code keeps
a separate state for each audio stream that's being converted.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6255 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-24 21:15:37 +00:00
J. Alexander Treuman
495e1b6cf9 Tidying up pcm_utils.c a bit more.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6230 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-23 11:04:04 +00:00
J. Alexander Treuman
fbb3a94f17 Switching to the lsr simple API. The problem with the full API is that the
number of channels is specified when the converter state is created.
Previously this was only done once, thus breaking horribly when the input
audio suddenly had a different channel count.  A new state could be created
every time the number of channels changes, but this could happen many times
a second if resampling to two different formats at once.  The simple API
doesn't have this problem, as channel count is an argument to the
conversion function itself.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6229 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-23 10:31:07 +00:00
J. Alexander Treuman
407497c40a Split pcm_convertAudioFormat into separate functions for bitrate, channel,
and samplerate conversion.  This makes the code much easier to read, and
fixes a few bugs that were previously there.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6224 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-22 23:11:36 +00:00
J. Alexander Treuman
e6d7663b10 Cleaning up/correcting some comments.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6200 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-22 15:21:56 +00:00
J. Alexander Treuman
f2850a66f0 Reindenting
git-svn-id: https://svn.musicpd.org/mpd/trunk@6199 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-05-22 15:02:25 +00:00
Avuton Olrich
a061da8fb5 The massive copyright update
git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-04-05 03:22:33 +00:00
Eric Wong
08a7a86be2 pcm_utils: fix libsamplerate compilation with non-C99 compilers
Mixing code and declarations is ugly, anyways.

We could probably get away with using alloca(), but I'm not sure
how good compiler support is for that, either.  It's probably
more supported than mixed declarations and code.  Nevertheless;
we'll trigger memory checkers on exit because we don't free
the buffers; but we won't actually leak because we reuse those
buffers (just like the non-SRC code path).

git-svn-id: https://svn.musicpd.org/mpd/trunk@5397 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-02-19 07:58:08 +00:00
J. Alexander Treuman
81fd135651 Fixing some weird floating point comparison issue. Not exactly sure why
this fixes it though.

git-svn-id: https://svn.musicpd.org/mpd/trunk@5338 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-02-13 23:47:41 +00:00
Avuton Olrich
79ef8ba248 Add libsamplerate support, old resampling is still an option, but this sounds much better for those who need it and don't want to use pulseaudio. Reviewed by shank/avuton.
git-svn-id: https://svn.musicpd.org/mpd/trunk@5316 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-02-02 03:51:07 +00:00
Eric Wong
b443363aa6 Don't initialize globals to zero (or NULL)
Some compilers and linkers aren't smart enough to optimize this,
as global variables are implictly initialized to zero.  As a
result, binaries are a bit smaller as more goes in the .bss and
less in the text section.

git-svn-id: https://svn.musicpd.org/mpd/trunk@5254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2007-01-14 03:07:53 +00:00
Eric Wong
90847fc881 Replace strdup and {c,re,m}alloc with x* variants to check for OOM errors
I'm checking for zero-size allocations and assert()-ing them,
so we can more easily get backtraces and debug problems, but we'll
also allow -DNDEBUG people to live on the edge if they wish.

We do not rely on errno when checking for OOM errors because
some implementations of malloc do not set it, and malloc
is commonly overridden by userspace wrappers.

I've spent some time looking through the source and didn't find any
obvious places where we would explicitly allocate 0 bytes, so we
shouldn't trip any of those assertions.

We also avoid allocating zero bytes because C libraries don't
handle this consistently (some return NULL, some not); and it's
dangerous either way.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-08-26 06:25:57 +00:00
Avuton Olrich
29a25b9933 Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-20 16:02:40 +00:00
Avuton Olrich
a8938c91ba [CLEANUP] Remove unused function
Cleanup whitespace->tabs

git-svn-id: https://svn.musicpd.org/mpd/trunk@4338 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14 20:08:35 +00:00
J. Alexander Treuman
2fa7125cce Change shank's email address
git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-14 19:37:45 +00:00
Avuton Olrich
a37348a74f Huge header update, update the copyright and add
the GPL header where necessary

git-svn-id: https://svn.musicpd.org/mpd/trunk@4317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-13 19:20:34 +00:00
Warren Dukes
23c59e8cda wee found the audioFormatConversion bug, was actually a bug in shout plugin
git-svn-id: https://svn.musicpd.org/mpd/trunk@2311 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-10-23 12:58:59 +00:00
Warren Dukes
480023201a ok, resampling and converting to mono no works
git-svn-id: https://svn.musicpd.org/mpd/trunk@2309 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-10-23 02:40:03 +00:00
Warren Dukes
12597322a2 configure shout encoding quality and audio format
git-svn-id: https://svn.musicpd.org/mpd/trunk@2307 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-10-23 01:04:58 +00:00
Warren Dukes
4e53282469 todo update
git-svn-id: https://svn.musicpd.org/mpd/trunk@1352 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-06-06 16:42:14 +00:00
Warren Dukes
69a0b86173 trash XMMS resampling, use ESD's instead, don't understand it, but it works
git-svn-id: https://svn.musicpd.org/mpd/trunk@979 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 22:31:23 +00:00
Warren Dukes
33d112499d some debug code
git-svn-id: https://svn.musicpd.org/mpd/trunk@978 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 20:49:35 +00:00
Warren Dukes
76af5b2f90 ???
git-svn-id: https://svn.musicpd.org/mpd/trunk@977 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 19:54:32 +00:00
Warren Dukes
85f2ce820f fix a bug in channel conversion
git-svn-id: https://svn.musicpd.org/mpd/trunk@975 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 19:30:56 +00:00
Warren Dukes
5b4a0a1821 fix computation of conversion buffer size
git-svn-id: https://svn.musicpd.org/mpd/trunk@974 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 17:15:04 +00:00
Warren Dukes
4f76ba5a42 format conversion for 8->16 bis and mono->stereo
git-svn-id: https://svn.musicpd.org/mpd/trunk@973 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2004-05-10 17:08:46 +00:00