aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* pcm_utils: always round up resampling buffer sizeMax Kellermann2008-12-081-1/+1
| | | | | | | libsamplerate produces cracks in the sound output when the destination buffer is too small. This is the case when pcm_convert_size() rounds down. Use ceil(x) instead of floor(0.5+x) there to prevent a buffer overrun.
* replaced mpd_likely/mpd_unlikely by G_LIKELY/G_UNLIKELYThomas Jansen2008-12-021-2/+3
| | | | | We want to remove gcc.h eventually. This takes care of all the G_LIKELY/G_UNLIKELY macros.
* pcm_utils: allow volume levels greater than 100% in pcm_volume()Max Kellermann2008-11-111-1/+1
| | | | Allow pcm_volume() to increase volume.
* pcm_volume: added constant PCM_VOLUME_1Max Kellermann2008-11-111-10/+13
| | | | | | | It may be desirable to change the range of integer volume levels (e.g. to 1024, which may utilize shifts instead of expensive integer divisions). Introduce the constant PCM_VOLUME_1 which describes the integer value for "100% volume". This is currently 1000.
* pcm_utils: added 24 bit conversion functionsMax Kellermann2008-10-231-0/+108
| | | | | | 24 bit output is as important as 16 bit output. Provide a pcm_convert() implementation which can convert to 24 bit with as little quality loss as possible.
* pcm_utils: generic pcm_convert_size() implementationMax Kellermann2008-10-231-21/+2
| | | | | | The old pcm_convert_size() ignored most of the destination format, e.g. it did not check its sample size, and assumed it is 16 bit. Simplify and universalize it by using audio_format_frame_size().
* pcm_utils: moved code to pcm_convert_16()Max Kellermann2008-10-231-21/+39
| | | | | pcm_convert() converted only to 16 bit. To be able to support other sample sizes, move that 16 bit specific code to a separate function.
* pcm_utils: moved channel conversion functions to pcm_channels.cMax Kellermann2008-10-231-82/+4
| | | | Separate code from pcm_utils.c to keep it small and simple.
* pcm_utils: moved code to pcm_resample.cMax Kellermann2008-10-231-162/+6
| | | | | | Separate the resampling code from the rest of pcm_utils.c. Create two sub-libraries: pcm_resample_libsamplerate.c and pcm_resample_fallback.c.
* pcm_dither: added generic 24 to 16 bit ditheringMax Kellermann2008-10-231-8/+10
| | | | | Copied and adapted code from the mp3 decoder plugin. This library now replaces the old and low-quality function pcm_convert_24_to_16().
* output_buffer: don't split framesMax Kellermann2008-10-231-0/+3
| | | | | | | Splitting a frame between two buffer chunks causes distortion in the output. MPD used to assume that the chunk size 1020 would never cause splitted frames, but that isn't the case for 24 bit stereo (127.5 frames), and even less for files with even more channels.
* pcm_utils: added pcm_convert_init()Max Kellermann2008-10-211-0/+5
| | | | | | Instead of manually calling memset(0) on the pcm_convert_state struct, client code should use a library function from pcm_utils.c. This way, we can change the semantics of the struct easily.
* pcm_utils: no CamelCaseMax Kellermann2008-10-211-64/+63
| | | | Renamed all functions which were still in CamelCase.
* pcm_utils: renamed ConvState to struct pcm_convert_stateMax Kellermann2008-10-211-3/+5
| | | | No CamelCase, and a struct instead of a typedef.
* pcm_utils: support any number of channels in pcm_sizeOfConvBuffer()Max Kellermann2008-10-121-11/+2
| | | | | When calculating the conversion buffer size, don't hard-code the formulas for only mono<->stereo.
* pcm_utils: support converting N channels to stereoMax Kellermann2008-10-121-0/+26
| | | | | | | Convert any number of channels to stereo. In fact, this isn't really stereo, it's rater mono blown up to stereo. This patch should only make it possible to play 5.1 files at all; "real" conversion to stereo should be implemented, but for now, this is better than nothing.
* pcm_utils: pass output channel count to pcm_convertChannels()Max Kellermann2008-10-121-35/+22
| | | | | | In order to be able to deal with non-trivial conversions, pcm_convertChannels() needs to know both the input and the output channel count. Simplify buffer allocation in that function.
* pcm_utils: moved code from pcm_convertChannels() to separate functionsMax Kellermann2008-10-121-20/+32
| | | | | | | Moved code from pcm_convertChannels() to pcm_convert_channels_1_to_2() and pcm_convert_channels_2_to_1(). Improved the quality of pcm_convert_channels_2_to_1() by calculating the arithmetic mean value of both samples.
* pcm_utils: pass int16_t* where appropriateMax Kellermann2008-10-121-12/+15
| | | | | Pass int16_t pointers instead of char pointers to functions which can deal with 16 bit audio only.
* audio_format: renamed sampleRate to sample_rateMax Kellermann2008-10-101-5/+5
| | | | | The last bit of CamelCase in audio_format.h. Additionally, rename a bunch of local variables.
* audio_format: unsigned integersMax Kellermann2008-10-101-3/+3
| | | | "bits" and "channels" cannot be negative.
* pcm: fix const flac in pcm_convertSampleRate()Max Kellermann2008-10-091-1/+1
| | | | In the libsamplerate fallback code, a "const" attribute was missing.
* pcm: fixed software volume, broken by unsigned integerMax Kellermann2008-10-091-6/+3
| | | | | | | "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.
* don't include os_compat.hMax Kellermann2008-10-081-1/+4
| | | | | When there are standardized headers, use these instead of the bloated os_compat.h.
* pcm_utils: 24 bit supportMax Kellermann2008-09-291-0/+67
| | | | | | | 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.
* pcm_utils: moved code to special 8/16 bit functionsMax Kellermann2008-09-291-72/+93
| | | | | | | 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()
* pcm_utils: pass only one buffer size to pcm_mix()Max Kellermann2008-09-291-17/+9
| | | | | | | | | 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().
* assume stdint.h and stddef.h are availableMax Kellermann2008-09-291-2/+0
| | | | | | 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.
* Switch to C99 types (retaining compat with old compilers)Eric Wong2008-09-291-32/+32
| | | | | | | | | | | | | | | 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.
* pcm_utils: added pcm_range()Max Kellermann2008-09-281-10/+18
| | | | | | | 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.
* pcm_utils: added inline function pcm_dither()Max Kellermann2008-09-281-8/+10
| | | | | Merge some code into an inline function, so we can optimize it later only once.
* audio_format: converted typedef AudioFormat to struct audio_formatMax Kellermann2008-09-071-7/+10
| | | | | Get rid of CamelCase, and don't use a typedef, so we can forward-declare it, and unclutter the include dependencies.
* fix -Wcast-qual -Wwrite-strings warningsMax Kellermann2008-09-071-9/+10
| | | | | | | | | 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.
* enable -Wpointer-arith, -Wstrict-prototypesMax Kellermann2008-08-261-2/+4
| | | | | | 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.
* more const pointers in pcm_utils.[ch]Max Kellermann2008-04-151-3/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@7360 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* decode: fix some uninitialized variable warningsEric Wong2008-04-121-1/+1
| | | | | 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
* missing const in disabled code pathMax Kellermann2008-04-121-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@7298 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* constant pointersMax Kellermann2008-04-121-5/+5
| | | | | | 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
* use constant pointers when possibleMax Kellermann2008-04-121-13/+12
| | | | | | 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
* use size_tMax Kellermann2008-03-261-1/+1
| | | | | | | | 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
* Cleanup #includes of standard system headers and put them in one placeEric Wong2008-01-031-4/+1
| | | | | | | | | | | | | 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
* pcm_utils: gcc 2.95 compile fix (extra semi-colon)Eric Wong2007-09-101-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6872 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a singleJ. Alexander Treuman2007-05-261-8/+4
| | | | | call to FATAL(). git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Cleaning up pcm_getSampleRateConverter.J. Alexander Treuman2007-05-261-23/+27
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6275 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Exit with an error if channel count isn't 1 or 2.J. Alexander Treuman2007-05-261-0/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6274 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Make pcm_convertAudioFormat return the buffer size. This is necessaryJ. Alexander Treuman2007-05-261-17/+20
| | | | | | | | 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
* Reverting to the full lsr API. Turns out the simple API needs all of theJ. Alexander Treuman2007-05-241-29/+52
| | | | | | | | 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
* Tidying up pcm_utils.c a bit more.J. Alexander Treuman2007-05-231-8/+9
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@6230 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Switching to the lsr simple API. The problem with the full API is that theJ. Alexander Treuman2007-05-231-19/+7
| | | | | | | | | | | 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
* Split pcm_convertAudioFormat into separate functions for bitrate, channel,J. Alexander Treuman2007-05-221-168/+207
| | | | | | 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