Commit Graph

36 Commits

Author SHA1 Message Date
Martin Piatka
ef0806da14 audio dithering: Fix some problems
* Replace bit shift with integer division - Shifting doesn't behave
nicely for negative numbers, for example -2 >> 8 equals -1. This
introduces distortion

* Use rounding from 0.5 up - Truncating introduces distortion, because
the interval of numbers that round to 0 is disproportionaly big (-1, 1).

* Replace random number generation with a faster algorithm

With all theese changes, the code is also a bit faster.
2022-02-09 12:04:05 +01:00
Martin Pulec
505e648b8a chage_bps2: small fixes
- if in/out bps matches, use memcpy
- static assert implementation-defined behavior we depend on
  (right-shifting negative LHS)
2022-02-08 08:37:32 +01:00
Martin Pulec
5d1a5dc1ad audio utils: option to disable dithering
In special cases (eg. 8-bit audio), user may want to opt out from
dithering because the artifacts may be more acceptable than the noise.
2022-02-08 08:37:32 +01:00
Martin Pulec
c9c1152dec simplify flow in change_bps() 2022-02-08 08:37:29 +01:00
Martin Piatka
0230ed201d audio/utils: change_bps: add dithering
By reducing bit-depth of audio, quantization noise is introduced. If the
bit depth is reduced by consistent rounding (either always down, always
up, or always to nearest) the quantization noise is correlated with the
input signal and percieved as distortion. Adding a small amount of noise
to the input signal before reducing the bit-depth causes random
rounding, which makes the noise uncorrelated and uniformly spread
through the whole spectrum.
2022-01-13 11:54:46 +01:00
Martin Pulec
1b3b27eb7c Updated copyright dates for modified files 2021-11-08 15:43:14 +01:00
Martin Pulec
c35083fa91 Suppress clang warnings 2021-09-08 08:25:10 +02:00
Martin Pulec
8f557a97d6 Replaced audio/audio.h with audio/types.h includes
audio/audio.h should not be used as a catch-all header for audio.
2021-08-11 15:58:58 +02:00
Martin Pulec
e6515ed4ad audio conversions: fixed const casts 2021-08-10 08:44:05 +02:00
Martin Pulec
aea78bc1b9 format_from_in_bps, format_to_out_bps - improved
Use the templated loaders for format_from_in_bps and format_to_out_bps.
2021-08-06 14:55:41 +02:00
Martin Pulec
53770ce327 Audio utils: improved prototypes + docu 2021-08-06 11:12:17 +02:00
Martin Pulec
4f9a69d4f0 calculate_rms: improved and polished
Rewrite using the new templates to avoid custom code and increase
performance.
2021-08-06 11:06:48 +02:00
Martin Pulec
4dce7d3a87 get_avg_volume: improved performance 2021-08-05 08:53:11 +02:00
Martin Piatka
9d440a15e3 audio_utils: float2int: clamp input to valid range
This avoids pops and buzzing caused by integer overflow when the input
sample falls outside of the range [-1.0, 1.0] (I encountered this when
using jack capture).
2021-04-06 16:43:28 +02:00
Martin Pulec
04e1f472bd Pipe: support for audio 2020-05-20 16:20:08 +02:00
Martin Pulec
27edf9ad71 Fixes 2019-12-04 13:28:02 +01:00
Martin Pulec
cad9f18fff File cap.: use audo_frame::dispose
Use audo_frame::dispose and remove double buffering for audio.
2019-10-24 08:36:55 +02:00
Martin Pulec
ffec41208f Added initial file input 2019-10-23 09:54:49 +02:00
Martin Pulec
8a45c78314 Fixed warnings
- added (const char *) attribute to param_u union to avoid casting away
  const warnings
- added also (const void *) and (volatile void *) for the rest
- there was a typo in computing requested_mtu causing violating sequence
  point evaluation order
- alsa_get_pcm_state_name: added attribute unused
- audio/utils.cpp: different signdness
- audio/utils.cpp: different signdness
- split capture filter: useless dispose_frame
- video_compress: not copying whole string (with strncpy)
2019-06-14 08:55:07 +02:00
Martin Pulec
315749bbe5 RTP: fix sending of RFC-compilant OPUS stream
RTP timestamp was incorrectly computed from data_len/bps which confused VLC.

+ some cleanup
2018-10-18 16:27:42 +02:00
Martin Pulec
a7830d3bc2 Fixed few warnings 2018-07-24 09:38:47 +02:00
Martin Pulec
5b3488ff8b Audio: compute RMS - fixed
Fixed incorrectly computed normalized value of sample (depending on char
signedness).
2017-10-11 14:09:35 +02:00
Martin Pulec
54d45ba489 Audio: move audio types in separate header/src 2015-08-31 11:11:04 +02:00
Martin Pulec
343089e7b8 Audio decoder: return if we cannot find out output format 2015-08-31 11:11:04 +02:00
Martin Pulec
9672fcc20c audio_codec_decompress: return obj instead of pointer 2015-08-31 11:11:03 +02:00
Martin Pulec
899ca0b56f Audio sender: don't auto resample to 48000
+ some rework - audio_frame2 has now methods for changing bps and
resampling
2015-08-19 09:53:10 +02:00
Martin Pulec
e8a3d984f5 Another small (audio) fix 2015-03-26 15:26:09 +01:00
Martin Pulec
ccb2b7c36a Added AJA capture
TODO: figure out 50p/60p modes, 4K, Windows support etc.
2015-01-29 16:26:10 +01:00
Martin Pulec
f210fe037e Fixed audio bps and sample_rate handling 2014-11-27 11:25:31 +01:00
Martin Pulec
6890cb5a5d Libavcodec: fixed float audio samples handling 2014-10-02 15:12:24 +02:00
Martin Pulec
37f079da8d Fixed audio_frame2 sample computation 2014-08-26 19:52:30 +02:00
Martin Pulec
79b56ad8f7 GCC 4.6 compat 2014-08-26 10:42:11 +02:00
Martin Pulec
ef733c6f9e audio_frame2: added const semantics 2014-08-21 14:01:31 +02:00
Martin Pulec
abb0cd7a20 Added rate limiter for audio but disable it
Is it really needed??
2014-08-18 12:37:19 +02:00
Martin Pulec
13b3555c0a Rewrite audio_frame2 to C++ class 2014-08-18 12:37:14 +02:00
Martin Pulec
42504a3980 Use C++ compiler for files using audio_frame2 2014-08-13 13:37:52 +02:00