2013年2月3日日曜日

Raspberry Pi:MPD(Music Player Daemon)の導入だぜ~♪


Raspberry PiにMPD(http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki)を導入して、
リモコン操作するぜぇ~。
NAS(楽曲)→Raspberry Pi(演奏:MPD:オーディオへ出力)←PC(操作)
こんな感じで~す。
「Raspberry Pi+MPDの設定」http://www.ns.n-mmra.net/audio/raspimpd/raspimpd.html
を参考にして導入しました。m(_ _)m

1.mpdのインストール
pi@raspberrypi ~ $ sudo apt-get install mpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libao-common libao4 libaudiofile1 libavformat53 libcurl3-gnutls libfaad2
  libmms0 libmpcdec6 libshout3 libwavpack1
Suggested packages:
  libesd0 libesd-alsa0 avahi-daemon icecast2 mpd-client
The following NEW packages will be installed:
  libao-common libao4 libaudiofile1 libavformat53 libcurl3-gnutls libfaad2
  libmms0 libmpcdec6 libshout3 libwavpack1 mpd
0 upgraded, 11 newly installed, 0 to remove and 99 not upgraded.
Need to get 1,413 kB of archives.
After this operation, 3,176 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libavformat53 armhf 6:0.8.4-1+rpi1
  404  Not Found
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libaudiofile1 armhf 0.3.4-2 [86.3 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcurl3-gnutls armhf 7.26.0-1 [306 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libfaad2 armhf 2.7-8 [177 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libmms0 armhf 0.6.2-3 [43.2 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libmpcdec6 armhf 2:0.1~r459-4 [38.1 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libshout3 armhf 2.2.2-8 [37.2 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libwavpack1 armhf 4.60.1-3 [80.3 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libao-common armhf 1.1.0-2 [11.3 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libao4 armhf 1.1.0-2 [40.1 kB]
Get:10 http://mirrordirector.raspbian.org/raspbian/ wheezy/main mpd armhf 0.16.7-2 [195 kB]
Fetched 1,014 kB in 6s (158 kB/s)
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/liba/libav/libavformat53_0.8.4-1+rpi1_armhf.deb  404  Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
→アップデートしろ!と言われた。。。

pi@raspberrypi ~ $ sudo apt-get update
Get:1 http://mirrordirector.raspbian.org wheezy InRelease [12.5 kB]
Get:2 http://archive.raspberrypi.org wheezy InRelease [7,737 B]
Get:3 http://archive.raspberrypi.org wheezy/main armhf Packages [6,421 B]
Get:4 http://mirrordirector.raspbian.org wheezy/main armhf Packages [7,403 kB]
Ign http://archive.raspberrypi.org wheezy/main Translation-en_GB
Ign http://archive.raspberrypi.org wheezy/main Translation-en
Get:5 http://mirrordirector.raspbian.org wheezy/contrib armhf Packages [23.3 kB]
Get:6 http://mirrordirector.raspbian.org wheezy/non-free armhf Packages [47.8 kB]
Get:7 http://mirrordirector.raspbian.org wheezy/rpi armhf Packages [14 B]
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en
Fetched 7,500 kB in 54s (138 kB/s)
Reading package lists... Done

→再度チャレンジ!
pi@raspberrypi ~ $ sudo apt-get install mpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libao-common libao4 libaudiofile1 libavformat53 libcurl3-gnutls libfaad2
  libmms0 libmpcdec6 libshout3 libwavpack1
Suggested packages:
  libesd0 libesd-alsa0 avahi-daemon icecast2 mpd-client
The following NEW packages will be installed:
  libao-common libao4 libaudiofile1 libavformat53 libcurl3-gnutls libfaad2
  libmms0 libmpcdec6 libshout3 libwavpack1 mpd
0 upgraded, 11 newly installed, 0 to remove and 124 not upgraded.
Need to get 399 kB/1,414 kB of archives.
After this operation, 3,176 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libavformat53 armhf 6:0.8.5-1+rpi1 [399 kB]
Fetched 399 kB in 2s (136 kB/s)
Selecting previously unselected package libaudiofile1:armhf.
(Reading database ... 60097 files and directories currently installed.)
Unpacking libaudiofile1:armhf (from .../libaudiofile1_0.3.4-2_armhf.deb) ...
Selecting previously unselected package libavformat53:armhf.
Unpacking libavformat53:armhf (from .../libavformat53_6%3a0.8.5-1+rpi1_armhf.deb) ...
Selecting previously unselected package libcurl3-gnutls:armhf.
Unpacking libcurl3-gnutls:armhf (from .../libcurl3-gnutls_7.26.0-1_armhf.deb) ...
Selecting previously unselected package libfaad2:armhf.
Unpacking libfaad2:armhf (from .../libfaad2_2.7-8_armhf.deb) ...
Selecting previously unselected package libmms0:armhf.
Unpacking libmms0:armhf (from .../libmms0_0.6.2-3_armhf.deb) ...
Selecting previously unselected package libmpcdec6:armhf.
Unpacking libmpcdec6:armhf (from .../libmpcdec6_2%3a0.1~r459-4_armhf.deb) ...
Selecting previously unselected package libshout3:armhf.
Unpacking libshout3:armhf (from .../libshout3_2.2.2-8_armhf.deb) ...
Selecting previously unselected package libwavpack1:armhf.
Unpacking libwavpack1:armhf (from .../libwavpack1_4.60.1-3_armhf.deb) ...
Selecting previously unselected package libao-common.
Unpacking libao-common (from .../libao-common_1.1.0-2_armhf.deb) ...
Selecting previously unselected package libao4.
Unpacking libao4 (from .../libao4_1.1.0-2_armhf.deb) ...
Selecting previously unselected package mpd.
Unpacking mpd (from .../mpd_0.16.7-2_armhf.deb) ...
Processing triggers for man-db ...
Setting up libaudiofile1:armhf (0.3.4-2) ...
Setting up libavformat53:armhf (6:0.8.5-1+rpi1) ...
Setting up libcurl3-gnutls:armhf (7.26.0-1) ...
Setting up libfaad2:armhf (2.7-8) ...
Setting up libmms0:armhf (0.6.2-3) ...
Setting up libmpcdec6:armhf (2:0.1~r459-4) ...
Setting up libshout3:armhf (2.2.2-8) ...
Setting up libwavpack1:armhf (4.60.1-3) ...
Setting up libao-common (1.1.0-2) ...
Setting up libao4 (1.1.0-2) ...
Setting up mpd (0.16.7-2) ...
[....] Starting Music Player Daemon: mpdlisten: bind to '[::1]:6600' failed: Failed to create socket: Address family not supported by protocol (continuing anyway, because binding to '127.0.0.1:6600' succeeded)
Failed to load database: Failed to open database file "/var/lib/mpd/tag_cache": No such file or directory
. ok

2.mpd起動確認
pi@raspberrypi ~ $ ps ax
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:01 init [2]
・・・
 2151 pts/0    Ss     0:00 -bash
 2675 ?        Ssl    0:00 /usr/bin/mpd /etc/mpd.conf
 2700 pts/0    R+     0:00 ps ax
→とりあえず動いてる(^^)

3.サウンドカードの確認
pi@raspberrypi ~ $ cat /proc/asound/cards
 0 [ALSA           ]: BRCM bcm2835 ALSbcm2835 ALSA - bcm2835 ALSA
                      bcm2835 ALSA
→ちゃんと動作しているようだ。

4.mpdの設定
4.1.mpd.confのミュージックディレクトリを確認

# 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"

4.2.mpdの設定に合わせてnasにシンボリックリンクを張る
pi@raspberrypi ~ $ sudo ln -s /mnt/nas/music /var/lib/mpd/music/nas
pi@raspberrypi ~ $ ls -l /var/lib/mpd/music/
total 0
lrwxrwxrwx 1 root root 14 Jan 22 01:14 nas -> /mnt/nas/music
pi@raspberrypi ~ $ ls -l /var/lib/mpd/music/nas
lrwxrwxrwx 1 root root 14 Jan 22 01:14 /var/lib/mpd/music/nas -> /mnt/nas/music
pi@raspberrypi ~ $ ls -l /var/lib/mpd/music/nas/cd/
total 0
drwxrwxrwx 0 root root 0 Jan 26  2013 classic
drwxrwxrwx 0 root root 0 Jan 12 15:32 etc
drwxrwxrwx 0 root root 0 Jan 12 15:17 jazz
drwxrwxrwx 0 root root 0 Jan 12 15:30 jpop
drwxrwxrwx 0 root root 0 Jan 12 15:20 pops
drwxrwxrwx 0 root root 0 Jan 12 16:19 test

4.3.再起動して設定を反映させる
pi@raspberrypi ~ $ sudo /etc/init.d/mpd restart
[ ok ] Stopping Music Player Daemon: mpd.
[....] Starting Music Player Daemon: mpdlisten: bind to '[::1]:6600' failed: Failed to create socket: Address family not supported by protocol (continuing anyway, because binding to '127.0.0.1:6600' succeeded)
. ok
→アドレスが違うよと怒られた。。。
→リスナーアドレスを指定する
pi@raspberrypi ~ $ sudo vi /etc/mpd.conf
# For network
#bind_to_address                "localhost"
bind_to_address         "192.168.1.41"

pi@raspberrypi ~ $ sudo /etc/init.d/mpd restart
[ ok ] Stopping Music Player Daemon: mpd.
[ ok ] Starting Music Player Daemon: mpd.
→再起動完了!!

5.リモコンソフト GMPC(Gnome Music Player Client)をWin7に導入
http://gmpclient.org/ からダウンロードしてインストール
・サーバ設定
・アップデート MPD データベース
・再生!
→音が出ない。。。(T_T)

6.音声の出力先の設定
3.5mmジャックから出力するにはミキサーで出力先を変更する必要があった。
sudo amixer cset numid=3
where n is 0=auto, 1=headphones, 2=hdmi.
Change to 1 to force sound through the 3.5mm headphone jack

pi@raspberrypi ~ $ sudo amixer cset numid=3 1
numid=3,iface=MIXER,name='PCM Playback Route'
  ; type=INTEGER,access=rw------,values=1,min=0,max=2,step=0
  : values=1
→音が出た!!が、音が小さ過ぎ。。。(T_T)

7.ボリューム調整
今回はここがポイント。サーフィンしまくってやっとできた^^;

7.1.現在の状態を調べてみた。
pi@raspberrypi ~ $ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 26215 [40%] [on]
  Front Right: Playback 26215 [40%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 65536 [100%] [on]
  Front Right: Capture 65536 [100%] [on]

7.2.コントロール番号を調べる
pi@raspberrypi ~ $ amixer controls
numid=4,iface=MIXER,name='Master Playback Switch'
numid=3,iface=MIXER,name='Master Playback Volume'
numid=2,iface=MIXER,name='Capture Switch'
numid=1,iface=MIXER,name='Capture Volume'
→ボリュームはnumid=3だと分かる

7.3.ボリュームを最大にする
pi@raspberrypi ~ $ amixer cset numid=3 100%
numid=3,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
  : values=65536,65536

pi@raspberrypi ~ $ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 65536 [100%] [on]
  Front Right: Playback 65536 [100%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 65536 [100%] [on]
  Front Right: Capture 65536 [100%] [on]
→100%に設定できた。

今度はそれなりの音量になった。
やったね、リモコン環境できあがり(^^)/

0 件のコメント:

コメントを投稿