Linuxで組もう!DIY PC Audio 全過程 Vol.3

Bitperfect Player の実現に向けたDebian セットアップ 
- 全コマンドライン


(2020/8/14訂正: NASデータを直接MPDのディレクトリにマウントさせることで、マウント過程を簡略化)

(2020/8/13訂正: cifs-utilsのインストール ~$ sudo apt install cifs-utils を追加)


Debian “buster” のHi-Fi Network Audio Player化全過程紹介、今日はその第3回。DebianへのReal Time Kernelの実装と、MPDを含めたシステムのカスタマイズです。


なおここでは、ネットワークプレイヤー化までにCUI上で必要な全コマンドラインを、解説は最小限に留めて、non-stopで記述します。

Voyage MPDに慣れ親しんだ方であれば、この情報で十分参考になるかと。


ただ、LinuxやMPDに初めて接する方のため、以下のそれぞれの呪文(笑)は「いったい何をやっているのか?」に関して、後日のブログで、数回に分けて解説していく予定です。


何にせよ、このセッテイングさえ済ましてしまえば、普段の音源再生から、新規音源追加後のライブラリのアップデートまで、今後は全てスマホ操作だけで完結するようになります。LinuxのCUIを開く必要はもうありません。


では、最新Debian環境でのbit accurateな音出しに向け、Here We Go!!


:~$ sudo apt install nano

:~$ sudo apt install net-tools

:~$ netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

0.0.0.0         192.168.1.254   0.0.0.0         UG        0 0          0 eno1

192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eno1

# Gateway数値とNetmask値の確認


:~$ sudo nano /etc/network/interfaces

# iface eno1 inet dhcp

iface eno1 inet static

address 192.168.1.176

netmask 255.255.255.0

gateway 192.168.1.254

# DHCPの行をコメントアウト

# 上記で確認した数値を元に、新たに3行を追加。176の部分には、2-253の範囲で好きな数字を。100以上を推奨


:~$ sudo apt-get install openssh-server

:~$ sudo reboot


:~$ sudo ifconfig

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.176  netmask 255.255.255.0  broadcast 192.168.1.255
        ….

# 固定IP Addressへの変更確認


# 以降は、無線LANで接続された作業用母艦のMac「ターミナル」からの作業となります


# NUCに繋いでいた有線キーボードとかは、そのままにしておくと邪魔だし、見た目にきちゃないしで、カミさんに怒られたりするので(笑)、この時点で外して押入れに仕舞い、NUC本体はオーディオラックにカッコよく鎮座させませう


$ rm known_hosts

# SSH接続エラー回避のための、「ターミナル」上の既存設定消去


$ ssh usbaudio@192.168.1.176

usbaudio@192.168.1.176’s password:


# 以降、SSH接続を介したusbaudio@debianmusic:~$での作業


:~$ sudo apt update

:~$ sudo apt install linux-image-rt-amd64

:~$ sudo uname -a

Linux debianmusic 4.19.0-9-rt-amd64 #1 SMP PREEMPT RT Debian 4.19.118-2 (2020-04-29) x86_64 GNU/Linux

#  Real Time Kernel化、完了の確認表示。いやあー、ホントにあっけないですねー


:~$ sudo apt install alsa-utils alsa-tools

:~$ sudo nano /etc/security/limits.conf

@audio           -       rtprio          99

@audio           -       memlock         unlimited

@audio           -       nice            -10

# End of file

# Real Time Kernel最適化のため、最後に3行新規追加


:~$ sudo apt install mpd mpc

# 更新マウントを毎回自動で行わせるため、MPDと一緒にmpcも一緒に入れておきましょう


:~$ mpd -V

Music Player Daemon 0.21.5 (0.21.5)

# MPDは、無事、最新のver.0.21です。ヤタ!


:~$ sudo cat /etc/mpd.conf

# An example configuration file for MPD.

# Read the user manual for documentation: http://www.musicpd.org/doc/user/

# or /usr/share/doc/mpd/html/user.html

# Files and directories #######################################################

#

# This setting controls the top directory which MPD will search to discover the

# available audio files and add them to the daemon's online database. This

# setting defaults to the XDG directory, otherwise the music directory will be

# be disabled and audio files will only be accepted over ipc socket (using

# file:// protocol) or streaming files over an accepted protocol.

#

music_directory "/var/lib/mpd/music"

# MPDのmusic_directory(”/var/lib/mpd/music”) の確認


:~$ sudo adduser mpd audio


:~$ sudo apt install lighttpd

:~$ sudo cat /etc/lighttpd/lighttpd.conf

server.modules = (

        "mod_indexfile",

        "mod_access",

        "mod_alias",

        "mod_redirect",

)


server.document-root       = "/var/www/html"

server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )

server.errorlog             = "/var/log/lighttpd/error.log"

server.pid-file             = "/var/run/lighttpd.pid"

server.username             = "www-data"

server.groupname            = "www-data"

server.port                 = 80

# “server.document-root = "/var/www/html””と”server.port = 80”の確認


:~$ sudo ln -s /var/lib/mpd/music /var/www/html/Music

:~$ sudo apt install tree

:~$ tree /var/www/html

/var/www/html

└── Music -> /var/lib/mpd/music

# シンボリックリンクの作成確認


:~$ sudo apt install avahi-daemon

:~$ sudo nano /etc/avahi/avahi-daemon.conf

#use-iff-running=no

enable-dbus=yes

#disallow-other-stacks=no

# ”enable-dbus=yes”部分の#(コメントアウト)を外して、有効化


:~$ sudo apt install acpi acpid

:~$ sudo nano /etc/acpi/powerbtn.sh

/sbin/shutdown -h now "Power button pressed"

exit 0

# 2行を新たに記述して保存


:~$ sudo nano ./.bashrc

  fi


mpc update


fi

# 最後の”fi”前に”mpc update”を追加


:~$ sudo reboot


:~$ sudo apt update

:~$ sudo apt upgrade

:~$ sudo cat /proc/asound/cards

 0 [PCH ]: HDA-Intel - HDA Intel PCH

                      HDA Intel PCH at 0xdc240000 irq 128

 1 [W2             ]: USB-Audio - Creative Bluetooth Audio W2

                      Creative Bluetooth Audio W2 at usb-0000:00:14.0-2, full speed

 2 [PMA2500NE ]: USB-Audio - PMA-2500NE

                      D&M Holdings Inc. PMA-2500NE at usb-0000:00:14.0-3, high speed


# 筆者環境では、メインオーディオのDENON PMA-2500NEに加えて、Bluetoothオーディオ再生のための通信用USBドングル(優れもの!)が装着されており、「W2」の名称でALSA機器として認識されています。
# 上記1と2の[  ]内の機器名称を、mpd.confのALSA機器設定に使用します。控えておきましょう。


:~$ sudo apt install lame


# 以下、”mpd.conf”の修正箇所

:~$ sudo nano /etc/mpd.conf

# General music daemon options ################################################

#

# This setting specifies the user that MPD will run as. MPD should never run as

# root and you may use this setting to make MPD change its user ID after

# initialization. This setting is disabled by default and MPD is run as the

# current user.

#

user "mpd"

#

# This setting specifies the group that MPD will run as. If not specified

# primary group of user specified with "user" setting will be used (if set).

# This is useful if MPD needs to be a member of group such as "audio" to

# have permission to use sound card.

#

group                          "audio"

#

# This setting sets the address for the daemon to listen on. Careful attention

# should be paid if this is assigned to anything other then the default, any.

# This setting can deny access to control of the daemon. Choose any if you want

# to have mpd listen on every address. Not effective if systemd socket

# activation is in use.

#

# For network

#bind_to_address "localhost"

#

# And for Unix Socket

#bind_to_address "/run/mpd/socket"

#

# This setting enables automatic update of MPD's database when files in

# music_directory are changed.

#

auto_update    "yes"

#

#

###############################################################################


# Zeroconf / Avahi Service Discovery ##########################################

#

# If this setting is set to "yes", service information will be published with

# Zeroconf / Avahi.

#

zeroconf_enabled "yes"

#

# The argument to this setting will be the Zeroconf / Avahi unique name for

# this MPD server on the network. %h will be replaced with the hostname.

#

zeroconf_name "debianmusic"

#

###############################################################################


# Audio Output ################################################################

#

# MPD supports various audio output types, as well as playing through multiple

# audio outputs at the same time, through multiple audio_output settings

# blocks. Setting this block is optional, though the server will only attempt

# autodetection for one sound card.

#

# An example of an ALSA output:

#

audio_output {

type "alsa"

name "DENON PMA2500NE"

device "hw:PMA2500NE,0"     # optional

# mixer_type      "hardware"          # optional

# mixer_device "default"     # optional

# mixer_control "PCM"     # optional

# mixer_index "0"     # optional

        dsd_usb         "yes"

}

#

audio_output {

        type          "alsa"

        name        "Bluetooth"

        device       "hw:W2,0"                        # optional

#      mixer_type      "hardware"                        # optional

#      mixer_device "default"       # optional

#      mixer_control "PCM"           # optional

#      mixer_index     "0"             # optional

}

#

# An example of a httpd output (built-in HTTP streaming server):

#

audio_output {

type "httpd"

name "My HTTP Stream"

encoder "lame" # optional, vorbis or lame

port "8000"

# bind_to_address "0.0.0.0"              # optional, IPv4 or IPv6

# quality "5.0" # do not define if bitrate is defined

bitrate "256" # do not define if quality is defined

format "44100:16:2"

# max_clients       "0"                     # optional 0=no limit

}

#

###############################################################################


:~$ sudo systemctl restart mpd


:~$ sudo apt install cifs-utils

:~$ sudo nano /etc/fstab

# /etc/fstab: static file system information.

#

# Use 'blkid' to print the universally unique identifier for a

# device; this may be used with UUID= as a more robust way to name devices

# that works even if disks are added and removed. See fstab(5).

#

# <file system> <mount point>   <type>  <options>       <dump>  <pass>

# / was on /dev/sda2 during installation

UUID=xxxxxxxx /               ext4    errors=remount-ro 0       1

# /boot/efi was on /dev/sda1 during installation

UUID=xxxx  /boot/efi       vfat    umask=0077      0       1

# swap was on /dev/sda3 during installation

UUID=xxxxxxxx  none            swap    sw              0       0

//192.168.1.132/Multimedia /var/lib/mpd/music cifs vers=1.0,username=hoge,password=xxxx,uid=mpd,iocharset=utf8  0   0


#最終行の新規記述は、長いですが、1行です。入力時は改行しないで下さい

# ”192.168.1.132/Multimedia”部分を各自のNAS環境に合わせて適宜変更。”hoge”と”xxxx”部分には、各自のNASにアクセス可能なユーザー名とPWをそれぞれ記入


:~$ sudo mount -a

:~$ findmnt

└─/var/lib/mpd/music                  //192.168.1.132/Multimedia   cifs       rw,relatime,vers=1.0,cache=strict,username=hoge,uid=105,forceui


# ”music”ディレクトリへのNASマウント確認


# さあこれでDebianマシンは準備完了ですね。MPD Client設定前に、mpcを使ってNAS音源を鳴らしてみましょう。鳴るかなー。


:~$ mpc ls | mpc add
:~$ mpc play


# ステレオ(笑・死語)から音が出ると、ちょっと感動しますよね。


:~$ mpc stop

:~$ mpc clear


# 以下、オマケ。shutdownコマンドのWoL対応


:~$ sudo visudo


# “vi”ではなく、ちゃんと“nano”環境で編集画面が開きます。以下の部分に新規に1行記入

# Allow members of group sudo to execute any command

%sudo   ALL=(ALL:ALL) ALL

usbaudio    ALL=NOPASSWD: /sbin/shutdown



お疲れ様でした。これでDebianネットワークプレイヤー、完全家電化完了です。

次回は設定の最終プロセス、MPD Clientの設定に進みます。


Linuxで組もう!DIY PC Audio  目次

全過程  Vol.1: Debian buster インストール準備編

全過程  Vol.2: Debian buster インストール

全過程  Vol.3: Debian設定 全コマンドライン

全過程  Vol.4: MPDクライアント設定


詳細解説 Vol.1: PCオーディオのススメ

詳細解説 Vol.2: Linux / MPD / Real Time Kernelについて

詳細解説 Vol.3: コマンドライン(1) Linux テキストエディタのインストール

詳細解説 Vol.4: コマンドライン(2) 固定IPアドレス設定

詳細解説 Vol.5: コマンドライン(3) リモート作業環境の確立

詳細解説 Vol.6: コマンドライン(4) リアルタイムカーネルの実装と設定

詳細解説 Vol.7: コマンドライン(5) MPD / mpc / ALSA / Avahi Daemon + Safety Shutdown設定

詳細解説 Vol.8: コマンドライン(6) ジャケ写表示設定

詳細解説 Vol.9: コマンドライン(7) MPD詳細設定

詳細解説 Vol.10: コマンドライン(8) NAS上の楽曲データのマウント

詳細解説 Vol.11: コマンドライン(9) おまけ - WoL設定


(21/08/29更新)Debian bullseye & MPD 0.22.6 アップグレード!+ DSD再生情報

コメント

このブログの人気の投稿

Linuxで組もう!DIY PC Audio 全過程 Vol.1

Linuxで組もう!DIY PC Audio / INDEX