Jan 22, 2017
mpdのHTTPストリーミング機能でflacを配信してみる(24日追記)
今回はこれ。
MPD Stream lossless flac or wav / Takla's Weblog
https://takla.wordpress.com/2014/04/01/mpd-stream-lossless-flac-or-wav/
MPD HTTP streaming reducing CPU load ! / raspberrypi.org forum
https://www.raspberrypi.org/forums/viewtopic.php?f=35&t=43670
MPD and high CPU usage / raspberrypi.org forum
https://www.raspberrypi.org/forums/viewtopic.php?f=35&t=47400
Music Player Daemon/Tips and tricks HTTP ストリーミング / ArchWiki
https://wiki.archlinuxjp.org/index.php/Music_Player_Daemon/Tips_and_tricks#HTTP_.E3.82.B9.E3.83.88.E3.83.AA.E3.83.BC.E3.83.9F.E3.83.B3.E3.82.B0
mpdをhttpサーバーに出来るという。flacでもストリーミングできるそうな。
よくよく読んだらvlcかmplayerじゃないと聴けないみたいなんだけど、まあ、試してみた。
使用したのはraspberry pi B+を2台。OSにはraspbian jessie。
まず1台にmpdをインストールしてhttpストリーミングサーバーにする。
流れは以下の通り。
sudo raspi-config
vi /etc/dhcpcd.conf
sudo reboot
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mpd mpc flac
chmod 777 /etc/mpd.conf
vi /etc/mpd.conf
#
music_directory "/var/lib/mpd/music"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/tag_cache"
log_file "/var/log/mpd/mpd.log"
pid_file "/run/mpd/pid"
state_file "/var/lib/mpd/state"
sticker_file "/var/lib/mpd/sticker.sql"
#
#user "mpd"
#group "nogroup"
#bind_to_address "localhost"
#bind_to_address "/run/mpd/socket"
#
#port "6600"
#
#### audio_output {
# type "alsa"
# name "My ALSA Device"
# device "hw:0,0" # optional
# mixer_type "hardware" # optional
# mixer_device "default" # optional
# mixer_control "PCM" # optional
# mixer_index "0" # optional
# }
#
audio_output {
type "httpd"
name "My HTTP Stream"
encoder "flac" # optional, vorbis or lame
port "8000"
#### bind_to_address "192.168.1.85" # optional, IPv4 or IPv6
# quality "5.0" # do not define if bitrate is defined
# bitrate "128" # do not define if quality is defined
format "44100:16:2"
# max_clients "0" # optional 0=no limit
}
#
#### samplerate_converter "Fastest Sinc Interpolator"
#### audio_output_format "96000:16:2"
#
sudo chmod -R 777 /var/log/mpd
sudo chmod -R 777 /run/mpd
sudo chmod -R 777 /var/lib/mpd
sudo mount -o addr=192.168.1.80,nolock -t nfs 192.168.1.80:/titan/jazz /var/lib/mpd/music
sudo mpd --kill
pstree
systemd-+-2*[agetty]
|-avahi-daemon---avahi-daemon
|-cron
|-dbus-daemon
|-dhcpcd
|-mpd-+-{decoder:flac}
| |-{io}
| |-{output:My HTTP }
| `-{player}
|-ntpd
|-rsyslogd-+-{in:imklog}
| |-{in:imuxsock) S 1
| `-{rs:main Q:Reg}
|-sshd---sshd---sshd---bash---pstree
|-systemd-journal
|-systemd-logind
|-systemd-udevd
`-thd
途中で何回かリブートしたけど、大体こんな感じ。
mpdをサーバーにできるので、ncmpcppでファイルや曲の選択ができるのが強み。データベースのアップデートはスピーディで、cue sheetも使える。
今回はなぜかapt-get update upgradeしなかったら、apt-get mpdができなかった。
samplerate_converterでアップサンプリングしたら処理能力を超える感じだったので止めた。
sudo mpd --kill でmpdを落としたら、数秒で再起動するようになっているようだ。
次にストリーミング受信機の設定。
mpdで受けれたらいいんだけど無理っぽい。
https://wiki.archlinuxjp.org/index.php/Music_Player_Daemon/Tips_and_tricks には mpc add http://192.168.1.86:8000 とかコマンドでできるみたいなことが書いてあるけど、多分、vorbis or lameじゃないといけないんだろう。
https://takla.wordpress.com/2014/04/01/mpd-stream-lossless-flac-or-wav/ こちらのリンク先などに書いてあるとおり、mplayerを使う。
以下、流れを記載。
あらかじめbootのconfig.txtにi2sDACの設定を書き込んでおく。
sudo raspi-config vi /etc/dhcpcd.conf sudo reboot sudo apt-get install alsa-base sudo apt-get update sudo apt-get upgrade
なんかalsaインストールが先になってる。ここらの流れで挙動が変わるかどうかは不明。
mplayerインストールする。
sudo apt-get install mplayer man mplayer mplayer -idle -cache 2048 http://192.168.1.86:8000
これで、httpサーバー192.168.1.86からのストリーミングを受信してras piのイヤホンジャックから音を聞ける。なかなかきれいな音だけど、再生開始までcache取り込みの時間がかかる。cacheはデフォルトだともっと少ないらしいのけど、ときに再生中に途切れたり、再生開始のときにノイズが乗るので、コマンドで2048にしている。
しかしi2sDACから音を出したい。
alsaを設定する。
cat /proc/asound/modules
0 snd_bcm2835
1 snd_soc_hifiberry_dac
cat /proc/asound/cards
0 [ALSA ]: bcm2835 - bcm2835 ALSA
bcm2835 ALSA
1 [sndrpihifiberry]: snd_rpi_hifiber - snd_rpi_hifiberry_dac
snd_rpi_hifiberry_dac
1 [sndrpihifiberry]をデフォルトにしないとi2sDACから音が出ないのでasound.confを作る。
sudo vi /etc/asound.conf
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
pi@raspberrypi:~ $ mplayer -idle -cache 2048 http://192.168.1.86:8000
MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
Cannot open file '/home/pi/.mplayer/input.conf': No such file or directory
Failed to open /home/pi/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.
Playing http://192.168.1.86:8000.
Resolving 192.168.1.86 for AF_INET6...
Couldn't resolve name for AF_INET6: 192.168.1.86
Connecting to server 192.168.1.86[192.168.1.86]: 8000...
Name : My HTTP Stream
Genre : Set genre in config
Website: Set website in config
Public : yes
Cache size set to 2048 KiB
Cache fill: 0.00% (0 bytes)
ICY Info: StreamTitle='NEBULA - Manabu Ohishi Trio - NEBULA';StreamUrl='';
Cache fill: 19.14% (401408 bytes)
Detected file format: Audio only
Selected audio codec: FLAC (Free Lossless Audio Codec) [libavcodec]
AUDIO: 44100 Hz, 2 ch, s16le, 524.3 kbit/37.15% (ratio: 65536->176400)
AO: [pulse] Init failed: Connection refused
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)
[AO_ALSA] Unable to find simple control 'Master',0.
Video: no video
Starting playback...
A: 4.5 (04.4) of 0.0 (00.0) 2.1% 12%
これでi2sDACから音が出る。終了は「q」キー。
問題は、前記コマンドでmplayerを起動しても、ストリーミング信号が受信できないと数秒で終了してしまうこと。つまり先にmpdサーバーから配信開始してから、mplayerを起動しないといけない。これって楽曲の冒頭が聞けないのだ。バックグラウンドで動作させる方法を発見できないのも地味に困る。なにか方法があるんじゃないかと思うんだけど。
例によって、現時点では音質の確認はしていない。
24日、追記。
普通にvolumio1.55にNASをマウントしたのと比較したら、そっちのほうが音がいい。
そしてやっぱり圧倒的に扱いやすかった。快適に扱えるというのは、やはり助かる。
writeback message:
Caution!!!
Now, Anyone cannot post a comment.