Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
* Changed the default target sampling rate from 44.1 kHz to 48 kHz because YTM recently changed its streaming format from AAC (141; 44.1 kHz & 256 kbps stereo) to Opus (774; 48 kHz & 256 kbps vbr stereo), Am@zon music had already changed its SD format from AAC (44.1 kHz & 256 kbps stereo) to Opus (48 kHz & 192 kbps vbr stereo) and YT had adopted Opus (251; 48 kHz & 160 kbps vbr stereo); Though this change affects very little for 44.1 kHz tracks (of which cut-off changes 20 kHz to 19 kHz)
* Note that Opus encoders enforce low-pass filtering (cut-off: 20 kHz), but their decoders output ultra sonic noise by noise-shaping dithering when 16 bit depth outputting
  • Loading branch information
yzyhk904 authored Jul 25, 2024
1 parent 7bc17ce commit cef993f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## A Magisk module resampling for cheapies

This module has been developed for casual users to overide re-sampling parameters of AudioFlinger (the system-wide mixer) in my other modules (["Audio misc. settings"](https://github.com/Magisk-Modules-Alt-Repo/audio-misc-settings) and ["Hifi Maximizer"](https://github.com/yzyhk904/hifi-maximizer-mod)) so as to significantly improve audio quality of LDAC Bluetooth earphones and DAC's under $30 (probably) especially when replaying 44.1 kHz tracks up-sampled over or equal to 96 kHz & 24 or 32 bits by AudioFlinger, but also the quality of internal speakers and a 3.5 mm jack receiving 48 kHz & 24 or 32 bits audio data (except 48 kHz & 16 bits) up-sampled by AudioFlinger. If you are an audiophile expert, please use "extras/change-resampling-quality.sh" in ["USB SampleRate Changer"](https://github.com/yzyhk904/USB_SampleRate_Changer) which can change the parameters on the fly flexibly.
This module has been developed for casual users to overide re-sampling parameters of AudioFlinger (the system-wide mixer) in my other modules (["Audio misc. settings"](https://github.com/Magisk-Modules-Alt-Repo/audio-misc-settings) and ["Hifi Maximizer"](https://github.com/yzyhk904/hifi-maximizer-mod)) so as to significantly improve audio quality of LDAC Bluetooth earphones and DAC's under $30 (probably) especially when replaying 48 kHz tracks up-sampled over or equal to 96 kHz & 24 or 32 bits by AudioFlinger, but also the quality of internal speakers and a 3.5 mm jack receiving 48 kHz & 24 or 32 bits audio data (except 48 kHz & 16 bits) re-sampled (i.e., low-pass filtered) by AudioFlinger. If you are an audiophile expert, please use "extras/change-resampling-quality.sh" in ["USB SampleRate Changer"](https://github.com/yzyhk904/USB_SampleRate_Changer) which can change the parameters on the fly flexibly.

By the way, although most people might wonder how this module improve the audio quality of such devices, it is accomplished by very long filter length re-sampling near ideally (almost without pre-echo, ringing (post-echo) and aliasing noise) cutting off a frequency zone from just above 20 kHz filled with ultrasonic noise generated by high frequency dithering and deteriorating audible sound by intermodulation significantly amplified by large amplification non-linearity of LDAC Bluetooth earphones and DAC's under $30. Furthermore this can be considered to be a kind of decimation filtering from 44.1 kHz & 16 bits samples to 40 kHz & 24 or 32 bits ones except the ultrasonic noise by hight frequency dithering. So it has little effect when using AAC and SBC codecs which transmit audio data by 44.1 kHz & 16 bits.
By the way, although most people might wonder how this module improve the audio quality of such devices, it is accomplished by very long filter length re-sampling near ideally (almost without pre-echo, ringing (post-echo) and aliasing noise) cutting off a frequency zone from just above 20 kHz filled with ultrasonic noise (although most people believe part of natural sound) generated by high frequency dithering (also called delta-sigma modulation, noise-shaping, super bit-mapping, etc.) at recording time and even 16 bits noise-shaping rounding output time (e.g., Opus decoders), and deteriorating audible sound like smoke by intermodulation significantly amplified by large amplification non-linearity of LDAC Bluetooth earphones and DAC's under $30. Furthermore this can be considered to be a kind of decimation filtering from 48 kHz & 16 bits samples (having dynamic range larger than usual 16 bits limit with ultrasonic noise) to 40 kHz & 24 or 32 bits ones except the ultrasonic noise by hight frequency dithering. So it has little effect when using AAC and SBC codecs which transmit audio data by 44.1 kHz & 16 bits.

However, as the noise has a merit adding mellowness into audible sound in the case of none cheap DAC's having very small amplification non-linearity, please use this module only when using LDAC Bluetooth earphones (any devices, as far as I know) and DAC's under $30 (typically using DAC chip CX31993, ALC5686, KT0210, etc.).

Finally, this module is designed to override re-sampling parameters set by my other modules, but can be used by itself only. You can install this module and enjoy its effect whether you are using one of them together or not.


Notes:
* If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound good at all, try editting "service.sh" script in the installed place or its ZIP archive so as to replace "94" in it with one of "93" down to "87" for appropriately cutting off ultrasonic noise causing intermodulation.
* This module doesn't have the effect for Hires. tracks (greater than 44.1 kHz sample rate) which not having large pre-echo and ringing, and high frequency dithering noise, except ultrasonic noise added on purpose for mellowness. Anyhow, if you want to improve the quality of only Hires. tracks on "cheapie" devices, edit "service.sh" script in the installed place or its ZIP archive as described in the script.
* If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound good at all, try editting "service.sh" script in the installed place or its ZIP archive so as to replace "85" in it with "86" or "87" for appropriately cutting off ultrasonic noise causing intermodulation.
* This module doesn't have the effect for Hires. tracks (greater than 48 kHz sample rate) which not having large pre-echo and ringing, and high frequency dithering noise, except ultrasonic noise added on purpose for mellowness. Anyhow, if you want to improve the quality of only Hires. tracks on "cheapie" devices, edit "service.sh" script in the installed place or its ZIP archive as described in the script.
* LDAC earphones and DAC's deteriorate the quality more or less by their internal over-sampling filtering when receiving low sample rate data.
* Don't forget disabling "A2DP hardware offload" on Snapdragon devices (if you can), because it forces double re-sampling (44.1 kHz to 48 kHz, and 48 kHz to 96 kHz) and it is so much worse that the latter re-sampling guts the former one at all.
* Don't forget disabling "A2DP hardware offload" on Snapdragon devices (if you can), because it forces double re-sampling (48 kHz to 48 kHz (i.e., a low-pass filter), and 48 kHz to 96 kHz) and it is so much worse that the latter re-sampling guts the former one at all.

<br/>
<br/>
Expand All @@ -33,19 +33,21 @@ Notes:
| 165 | 360 | | 104 | Low performance devices of A12 and later with audio ones having small amp. non-linearity |
| 179 | 408 | | 99 | General purpose on A12 and later for audio devices having small amp. non-linearity |
| Parameters of this module: | - | - | - | - |
| 179 | 520 | 94, 93, ... , 87 | | for LDAC BT earphones and DAC's under $30 both having large amp. non-linearity |
| 179 | 520 | 95,94,93 | | AAC or Flac 44.1kHz; for LDAC BT earphones and DAC's under $30 both having large amp. non-linearity |
| 194 | 520 | 87,86,85 | | Opus 48kHz; for LDAC BT earphones and DAC's under $30 both having large amp. non-linearity |
| 194 | 520 | 44,43 | | Hires. 96kHz; for LDAC BT earphones and DAC's under $30 both having large amp. non-linearity |
| External examples: | - | - | - | - |
| 100 | 29 | (91) | 109 | AK4493 (Sharp roll-off N-fold over-sampling) |
| 150 | 42 | (91) | 109 | AK4191EQ (Sharp roll-off N-fold over-sampling) |
| 120 | 35 | (97) | 110 | ES9038PRO (Fast roll-off N-fold over-sampling) |
| vary 50 ~ 118 | 34 | 96 | (398) | ES9039PRO (Fast roll-off N-fold over-sampling) |
| 110 | 40 | (96) | 109 | CX43131 (Fast roll-off N-fold over-sampling) |
| 110 | 40 | (96) | 109 | CS43131 (Fast roll-off N-fold over-sampling) |
| 98 | 130 | 98.5 | | MacOS Leopard (guess) |
| 159 | 240 | | 99 | iZotope, No-Alias (guess) |
| 100 | 64 | | 99 | SoX HQ linear phase (guess) |
| 170 | 520 | | 99 | SoX VHQ linear phase (guess) |

* % in "Cut-off" and "Stop band" (starting from) fields means the proportion to the Nyquist frefuency.
* % in "Cut-off" and "Stop band" (starting from) fields means the proportion to the Nyquist frequency.
<br/>

- Appendix B. Characteristics of Re-sampling Parameters :
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Change logs

# v2.0.0
* Changed the default target sampling rate from 44.1 kHz to 48 kHz because YTM recently changed its streaming format from AAC (141; 44.1 kHz & 256 kbps stereo) to Opus (774; 48 kHz & 256 kbps vbr stereo), Am@zon music had already changed its SD format from AAC (44.1 kHz & 256 kbps stereo) to Opus (48 kHz & 192 kbps vbr stereo) and YT had adopted Opus (251; 48 kHz & 160 kbps vbr stereo); Though this change affects very little for 44.1 kHz tracks (of which cut-off changes 20 kHz to 19 kHz)
* Note that Opus encoders enforce low-pass filtering (cut-off: 20 kHz), but their decoders output ultra sonic noise by noise-shaping dithering when 16 bit depth outputting

# v1.0.3
* Changed the cut-off frequency from 94% to 93% for casual people to be appealed by its transparent

# v1.0.2
* Added a note for adjusting the cut-off for your devices

Expand Down
6 changes: 3 additions & 3 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=resampling-for-cheapies
name=Resampling for cheapies
version=v1.0.2
versionCode=1002
version=v2.0.0
versionCode=2000
author=zyhk
description=For avoiding muddy distortion specific to LDAC Bluetooth earphones and DAC's under $30 (probably), this sets special re-sampling at the system-wide mixer.
description=For avoiding smoky distortion specific to LDAC Bluetooth earphones and DAC's under $30 (probably), this sets special re-sampling at the system-wide mixer.
29 changes: 22 additions & 7 deletions service.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/system/bin/sh

# Changed the default target sampling rate from 44.1 kHz to 48 kHz because YTM recently changed its streaming format
# from AAC (141; 44.1 kHz & 256 kbps stereo) to Opus (774; 48 kHz & 256 kbps vbr stereo), Am@zon music had already changed its SD format from
# AAC (44.1 kHz & 256 kbps stereo) to Opus (48 kHz & 192 kbps vbr stereo) and YT had adopted Opus(251; 48 kHz & 160 kbps vbr stereo)

function reloadAudioserver()
{
# wait for system boot completion and audiosever boot up
Expand Down Expand Up @@ -49,17 +53,28 @@ function setResamplingParameters()
resetprop --delete ro.audio.resampler.psd.tbwcheat
# End of workaround

resetprop ro.audio.resampler.psd.stopband 179
resetprop ro.audio.resampler.psd.halflength 520
resetprop ro.audio.resampler.psd.enable_at_samplerate 44100
resetprop ro.audio.resampler.psd.stopband 194
resetprop ro.audio.resampler.psd.halflength 520

# If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound good at all,
# try replacing "94" (below) with one of "93" down to "87" for appropriately cutting off ultrasonic noise causing intermodulation
resetprop ro.audio.resampler.psd.cutoff_percent 94
# If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound well or loses mellowness at all,
# try replacing "85" (below) with "86" or "87" for appropriately cutting off ultrasonic noise causing intermodulation
#
resetprop ro.audio.resampler.psd.cutoff_percent 85

# Uncomment the following lines if you intend to replay only 96 kHz & 24 bits Hires. tracks
# Uncomment the following resetprop lines if you intend to replay only 44.1 kHz & 16 and 24 bit tracks;
# If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound well or loses mellowness at all,
# try replacing "93" (below) with "94" or "95" for appropriately cutting off ultrasonic noise causing intermodulation
#
#resetprop ro.audio.resampler.psd.stopband 179
#resetprop ro.audio.resampler.psd.cutoff_percent 93

# Uncomment the following resetprop lines if you intend to replay only 96 kHz & 24 bit Hires. tracks.
# If you feel your LDAC earphones or "cheapie" DAC wouldn't become to sound well,
# try replacing "43" (below) with "44" for appropriately cutting off ultrasonic noise causing intermodulation
#
#resetprop ro.audio.resampler.psd.enable_at_samplerate 96000
#resetprop ro.audio.resampler.psd.cutoff_percent 44
#resetprop ro.audio.resampler.psd.cutoff_percent 43

reloadAudioserver
}
Expand Down

0 comments on commit cef993f

Please sign in to comment.