Proposed patch for bug #766 (Bad audio quality (possibly in resampling) in Linux)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Attached is a proposed patch for bug #766 (Bad audio quality (possibly in resampling) in Linux).

The cause is indeed in the resampling code (third_party/resample/src/resamplesubs.c):

    Yend = Ystart + (unsigned)(nx * pFactor);

where pFactor is a double holding the result of 1.0 * rate_out / rate_in, and nx is the size of a source frame (in samples).

Since pFactor holds only a binary floating-point approximation to the sample rate conversion factor (e.g. 1/6) and since the C-style cast (unsigned) performs truncation instead of rounding, the result is that sometimes Yend - Ystart is one sample less than intended, causing the last sample of the output frame to contain garbage (often a zero). Always be careful with floating-point calculations, especially in combination with looping constructs!

The attached patch fixes it by turning the above into proper rounding:

    Yend = Ystart + (unsigned)(nx * pFactor + 0.5);

Though the bug does not appear with my compiler (GCC 4.3.2 on Linux) when doing

    Yend = Ystart + (unsigned)(nx * 1.0 * dest_rate / source_rate);

this may still cause problems on other platforms since the correct outcome probably only results from the extra precision available in floating point registers (80-bit) compared to doubles (64-bit). Therefore, the patch also makes similar adjustments to code in conference.c and resample_resample.c.

Regards,

Bram
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: resample_patch.diff
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20100129/4fcc77be/attachment.diff>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux