📜 ⬆️ ⬇️

Create a network sound card with preference and poetess

Inspired by the topics one and two , I decided to build something similar.

In stock:
- One amplifier with speakers
- One desktop computer
- One laptop
- The desire to listen to Internet radio, regardless of the two preceding paragraphs and poking wires

As a result, a plan was born to collect "audio card over ethernet". Examining the issue of hardware compatibility, I chose the TP-link MR3020 router and USB Creative SB Play audio card.
')
What came out of it:


How to receive it, welcome under kat.

I'll start immediately with the price. A router can be found for 700 rubles, a sound card for 800 rubles, a USB hub for 200 rubles. In the amount of 1700 rubles or $ 55. And why no one else put it on the stream?

All the flaws in the OpenWRT firmware (USB and package building) were related only to the previous version 10.03. The last stable 12.09 is almost perfect.

We transfer the section / overlay to USB flash

Free space on the router about 800 kb. So that it does not bother us, we connect to the USB flash router. The section on the flash card is preformatted in ext4. The instruction is already there , in brief:
opkg update
opkg install block-mount block-hotplug block-extroot kmod-usb-core kmod-usb2 kmod-usb-ohci kmod-usb-storage kmod-fs-ext4
mkdir / mnt / sda1
mount / dev / sda1 / mnt / sda1
tar -C / overlay -cvf -. | tar -C / mnt / sda1 -xf -


We register in / etc / config / fstab
config mount
option target / overlay
option device / dev / sda1
option fstype ext4
option options rw, sync
option enabled 1
option enabled_fsck 0

Reboot the router and check:
mount | grep sda
/ dev / sda1 on / overlay type ext4 (rw, sync, relatime, user_xattr, barrier = 1, data = ordered)


We connect USB audio card

Install the necessary modules
opkg install kmod-usb audio kmod-sound-core


To USB hub'u connect the sound card flash drive, check:
dmesg | grep -i audio
[41.080000] usbcore: registered new interface driver snd-usb-audio


Set up pulseaudio

opkg install pulseaudio-daemon

Rule /etc/pulse/system.pa:
load-module module-native-protocol-unix auth-anonymous = 1 # for software running from the router itself
load-module module-alsa-sink device = hw: 0.0 tsched = 0 # tsched = 0 is a dirty hack for eliminating crackles and wheezing
load-module module-simple-protocol-tcp port = 4712 rate = 44100 format = s16le channels = 2 # for playing sound with windows
load-module module-rtp-recv # for playing sound from linux devices over wifi
load-module-module-native-protocol-tcp auth-anonymous = 1 # to play sound from linux devices over ethernet


Pulseaudio is launched from the pulse user, so we’re correcting the init script to grant write access to the /etc/init.d/pulseaudio audio devices:
--- pulseaudio_old 2013-06-19 12:30:18.425539419 +0400 +++ pulseaudio 2013-06-19 12:30:04.077704388 +0400 @@ -19,6 +19,9 @@ chmod 0750 /var/lib/pulse chown pulse:pulse /var/lib/pulse } + [ -d /dev/snd ] && { + chown -R pulse:pulse /dev/snd + } service_start /usr/bin/pulseaudio --daemonize --system --disallow-exit --disallow-module-loading --disable-shm --exit-idle-time=-1 } 


Add pulseaudio to autoload and run:
/etc/init.d/pulseaudio enable
/etc/init.d/pulseaudio start

Add a freshly baked audio server at the sound source:
pacmd load-module-tunnel-sink server =% serverIP%
pacmd set-default-sink 1 # number may differ depending on the output of pacmd list-sink

We try to reproduce the sound.
Teach MPD to work with pulseaudio

Attention, hardcore! Compiling MPD can be easier, but I went the other way. Download the source OpenWRT:
svn co svn: //svn.openwrt.org/openwrt/tags/attitude_adjustment_12.09/

We compile the SDK (in make menuconfig, do not forget to specify your router and platform):
cd attitude_adjustment_12.09
make tools / install
make toolchain / install

We get feeds with applications and “install” them in our sandbox:
./scripts/feeds update
./scripts/feeds install pulseaudio
./scripts/feeds install mpd

Dev pulseaudio package does not install all libraries, so we’re correcting package / feeds / packages / pulseaudio / Makefile:
 --- Makefile_old 2013-06-19 12:12:00.458287669 +0400 +++ Makefile 2013-06-19 12:07:43.225298052 +0400 @@ -139,7 +139,8 @@ $(INSTALL_DIR) \ $(1)/usr/lib/pkgconfig \ $(1)/usr/include/pulse \ - $(1)/usr/lib + $(1)/usr/lib \ + $(1)/usr/lib/pulseaudio $(CP) \ $(PKG_INSTALL_DIR)/usr/include/pulse/* \ $(1)/usr/include/pulse @@ -149,6 +150,9 @@ $(CP) \ $(PKG_INSTALL_DIR)/usr/lib/*.so* \ $(1)/usr/lib/ + $(CP) \ + $(PKG_INSTALL_DIR)/usr/lib/pulseaudio/*.so* \ + $(1)/usr/lib/pulseaudio/ endef define Package/pulseaudio-daemon/install 

Rules for mpd Makefile (package / feeds / packages / mpd / Makefile):
 --- Makefile_old 2013-06-18 17:47:56.277865458 +0400 +++ Makefile 2013-06-18 17:37:35.037187159 +0400 @@ -49,7 +49,7 @@ DEPENDS+= \ +AUDIO_SUPPORT:alsa-lib \ +libaudiofile +BUILD_PATENTED:libfaad2 +libffmpeg +libid3tag \ - +libmms +libogg +libshout +libsndfile +libvorbis + +libmms +libogg +libshout +libsndfile +libvorbis +pulseaudio-daemon PROVIDES:=mpd VARIANT:=full endef @@ -137,7 +137,7 @@ $(if $(CONFIG_BUILD_PATENTED),MAD_LIBS="$(TARGET_LDFLAGS) -lmad") \ TARGET_CFLAGS += -std=gnu99 -TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib +TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib,-rpath-link=$(STAGING_DIR)/usr/lib/pulseaudio # use gcc instead of g++ to avoid unnecessary linking against libstdc++ TARGET_CXX:=$(TARGET_CC) @@ -160,6 +160,7 @@ --enable-sndfile \ --enable-vorbis \ --enable-vorbis-encoder \ + --enable-pulse \ --with-faad="$(STAGING_DIR)/usr" \ --with-tremor=no \ 

Run make menuconfig, select Sound / pulseaudio-daemon, Libraries / libffmpeg-mini, and then Sound / mpd-full

Final Stage:
make package / mpd / compile
make package / mpd / install


If everything went without errors, then we should get a ready-made package bin / ar71xx / packages / mpd-full_0.16.5-2_ar71xx.ipk . If the compiler swears at something, then run make package / mpd / compile V = 99 and see what exactly went wrong.

Copy the package to the scp bin / ar71xx / packages / mpd-full_0.16.5-2_ar71xx.ipk tplink_ip: / tmp router and install the mpd package:
opkg update
opkg install curl
rm / tmp / opkg-lists / attitude_adjustment
opkg install /tmp/mpd-full_0.16.5-2_ar71xx.ipk

Configuring MPD /etc/mpd.conf:
input {
plugin "curl"
}
audio_output {
type "pulse"
name "My Device"
}

We include in autoload and we start:
/etc/init.d/mpd enable
/etc/init.d/mpd start

We check on linux:
mpc add pub4.di.fm : 80 / di_latinhouse
mpc play


Or in Windows, installing QMPDClient (IMHO is the best multiplatform mpd client).

AAC problem

The standard library libfaad2 loses aac with a 100% load on the processor, since on routers, processors do not do well with floating point computing. For such cases, the library developers provided the FIXED_POINT option, but the OpenWRT developers did not have time to use it before the orientation_adjustment_12.09 release. The latest version of the faf2 Makefile added the ability to compile with FIXED_POINT. Just download the latest Makefile:
wget dev.openwrt.org/export/34527/packages/libs/faad2/Makefile

Select in make menuconfig Advanced configuration options -> Target options -> Use software floating point by default and recompile the package:
make package / faad2 / compile
make package / faad2install

We get the package bin / ar71xx / packages / libfaad2_2.7-2_ar71xx.ipk, install it in the same way as mpd (only in this case with the opkg upgrade command).
Enjoy the warm sound of aac.
We connect as a sound source Windows

The only workable solution to broadcast audio to pulseaudio from Windows I found here . But unfortunately for this you need to buy Virtual Audio Cable software.
It starts with my bat'nikom:
linco.exe -B 16 -C 2 -R 44100 | nc.exe tplink_IP 4712

Yes, there are sound delays, especially over WiFi, but when watching a video it is easily treated with player settings.

Instead of bat files, you can try running linco via srvany. Who will succeed - please unsubscribe in the comments.

Modding

Those who are friends with a soldering iron and hands (if you are reading this, then surely you are friends with your hands?), Can put everything in one body. I decided to disassemble the Chinese USB hub, unsolder the extra USB connectors from it, and the metal cases of the remaining two USB connectors. Thus it turned out to turn the connectors themselves to 90 degrees.

On the router itself, I soldered the contacts of the USB connector from the board, from the board itself stretched the wires to the USB hub, and already from the USB hub I ran the wires to an external USB connector. In the case of the router I drilled two holes for Jacks and I managed to fit everything quite compactly. Unfortunately, it is no longer possible to close the lid of the router tightly, but smart people have invented a blue electrical tape for these needs.

What it looks like:


Workplace at 2 am:


Stuck in the household irreplaceable. There are plans to make another such in the kitchen, as well as connect an OLED display via I2C , and an IR-receiver via a UART.

PS Notes and error messages accept in PM.

PPS Who does not want to compile, here are the assembled packages mpd and libfaad2
rghost.ru/46934574
rghost.ru/46934558

UPD:
10/06/2013 - rghost.net/49184760 Pulseaudio 4.0 for OpenWRT

Source: https://habr.com/ru/post/184110/


All Articles