การเพิ่มคุณภาพของเสียงของ PulseAudio บน Ubuntu

ว่ากันว่าเพลงที่เปิดจาก Ubuntu เสียงดีกว่า Windows อีก จริงหรือเปล่าไม่ทราบนะครับ เพราะจำเสียงของ Windows ไม่ได้แล้ว พอดีมีโพสต์จากเพื่อนสมาชิกถึงการตั้งค่าของ PulseAudio ให้เสียงเทพขึ้นไปอีก ซึ่งผมทดลองแล้ว พบว่ามันดีขึ้นจริงนะครับ เลยขออนุญาติบันทึกไว้เป็นบทความเลยละกัน

การตั้งค่าของ PulseAudio อยู่ที่ไฟล์ /etc/pulse/daemon.conf ครับ เราจะเปิดไฟล์นี้มาแก้ไขกัน
sudo gedit /etc/pulse/daemon.conf

จะเห็นโค้ดประมาณนี้
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.

## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; local-server-type = user
; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

; realtime-scheduling = yes
; realtime-priority = 5

; exit-idle-time = 20
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

; resample-method = speex-float-1
; enable-remixing = yes
; enable-lfe-remixing = yes
; lfe-crossover-freq = 120

flat-volumes = no

; rlimit-fsize = -1
; rlimit-data = -1
; rlimit-stack = -1
; rlimit-core = -1
; rlimit-as = -1
; rlimit-rss = -1
; rlimit-nproc = -1
; rlimit-nofile = 256
; rlimit-memlock = -1
; rlimit-locks = -1
; rlimit-sigpending = -1
; rlimit-msgqueue = -1
; rlimit-nice = 31
; rlimit-rtprio = 9
; rlimit-rttime = 200000

; default-sample-format = s16le
; default-sample-rate = 44100
; alternate-sample-rate = 48000
; default-sample-channels = 2
; default-channel-map = front-left,front-right

; default-fragments = 4
; default-fragment-size-msec = 25

; enable-deferred-volume = yes
deferred-volume-safety-margin-usec = 1
; deferred-volume-extra-delay-usec = 0

เซมิโคลอน (;) หน้าข้อความ หมายถึงตัวแปรต่างๆที่สามารถตั้งค่าได้ แต่ปิดการตั้งค่านั้นๆไว้ โดยที่ค่าที่เห็นต่างๆเป็นค่าเริ่มต้นของโปรแกรมอยู่แล้ว การแก้ไขค่าเราจะต้องเอา ; และแทนที่ค่าหลัง = ด้วยค่าที่ต้องการ แต่วิธีนี้ไม่ค่อยปลอดภายเท่าไรครับ เนื่องจากหากเกิดข้อผิดพลาดใดๆ เราจะไม่สามารถกลับมาใช้การตั้งค่าเดิมได้เลย ถ้าไม่จดไว้ ผมแนะนำให้กำหนดค่าตัวแปรใหม่ที่ต้องการต่อท่ายไฟล์ไปเลย

วิธีการสุ่ม ได้แก่ src-sinc-best-quality, src-sinc-medium-quality, speex-float-1 (ค่าเริ่มต้น) ซึ่ง src-best-medium-quality จะดีที่สุด แต่ก็ใช้พลังของคอมพิวเตอร์สูงที่สุดเช่นกัน
resample-method = src-best-medium-quality


จำนวนบิทในการสุ่ม เช่น s16le (ค่าเริ่มต้น หรือ 16bit), s24le (24bit) และ s32le (32bit) ซึ่ง s32le จะมีประสิทธิภาพสูงที่สุด
default-sample-format = s24le


อัตตราการสุ่ม ค่านี้ยิ่งสูงยิ่งดี แต่ในการบันทึกจะทำให้ได้ไฟล์ที่ขนาดใหญ่มากและใช้ CPU มาก เช่น 48000 (ค่าเริ่มต้น หรือ 48Khz หรือ คุณภาพระดับ CD Audio) หรือ 96000 (96Khz หรือคุณภาพระดับ DVD Audio)
default-sample-rate = 96000


สรุปสุดท้าย ตัวแปรที่ผมแก้ไข คือ ข้อความที่ต่อจาก #my settings
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.

## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; local-server-type = user
; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no

; high-priority = yes
; nice-level = -11

; realtime-scheduling = yes
; realtime-priority = 5

; exit-idle-time = 20
; scache-idle-time = 20

; dl-search-path = (depends on architecture)

; load-default-script-file = yes
; default-script-file = /etc/pulse/default.pa

; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0

; resample-method = speex-float-1
; enable-remixing = yes
; enable-lfe-remixing = yes
; lfe-crossover-freq = 120

flat-volumes = no

; rlimit-fsize = -1
; rlimit-data = -1
; rlimit-stack = -1
; rlimit-core = -1
; rlimit-as = -1
; rlimit-rss = -1
; rlimit-nproc = -1
; rlimit-nofile = 256
; rlimit-memlock = -1
; rlimit-locks = -1
; rlimit-sigpending = -1
; rlimit-msgqueue = -1
; rlimit-nice = 31
; rlimit-rtprio = 9
; rlimit-rttime = 200000

; default-sample-format = s16le
; default-sample-rate = 44100
; alternate-sample-rate = 48000
; default-sample-channels = 2
; default-channel-map = front-left,front-right

; default-fragments = 4
; default-fragment-size-msec = 25

; enable-deferred-volume = yes
deferred-volume-safety-margin-usec = 1
; deferred-volume-extra-delay-usec = 0

# my settings
default-sample-format = float32ne
resample-method = src-sinc-best-quality
default-fragments = 2
default-fragment-size-msec = 125
enable-lfe-remixing = no
nice-level = -15

หลังจากแก้ไขแล้วให้ save แล้วตรวจสอบความถูกต้องของไฟล์ด้วยคำสั่งนี้
pulseaudio --check

ถ้าไม่พบข้อผิดพลาดใดๆ ให้ Restart เครื่องใหม่เลยครับ
หมายเหตุ การตั้งค่าเพิ่มเติมตามด้านบน เป็นการเพิ่มประสิทธิภาพการทำงานของโปรแกรม ซึ่งจะมีผลให้การทำงานของ CPU จะมีอัตราสูงขึ้นด้วย ใครใช้คอมเสปคต่ำๆ อาจได้ผลไม่คุ้มค่าได้ ซึ่งการกลับไปใช้การตั้งค่าเดิมด้วยการเปิดไฟล์มาแก้ไข และลบข้อความตั้งแต่ #my settings ออก และ Restart อีกครั้ง
ผู้เขียน goragod โพสต์เมื่อ 05 ก.ย. 2560 เปิดดู 3,791 ป้ายกำกับ Ubuntu
^