OpenWrt Forum Archive

Topic: [HowTo] Openwrt cheap Digital Stereo WiFi Internet Radio & MP3 Player

The content of this topic has been archived between 7 Apr 2018 and 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

edited: 07/01/2017

This is my personal contribution how to create a very cheap digital internet radio and MP3 player, just by using an OpenWRT router e some few other components, without needing to solder anything.

In three years I added here a lot of ideas and examples to improve and to enrich the Radio.

I hope you like it smile

Enjoy listening!

Check also my last How To's:
[How To] Openwrt + Asterisk11 + GSM/SMS channel (chan_dongle):
https://forum.openwrt.org/viewtopic.php … 90#p253590

and
[How To] Control a simple DIY relay board via internet Web page or SMS:
https://forum.openwrt.org/viewtopic.php … 91#p258891

and
[How To] Web SMS server with OpenWRT:
https://forum.openwrt.org/viewtopic.php?id=60910

-------------------------------------------------------------------------------------------------------------------------------
[Updated 16/10/2014] - Added support for Barrier Breaker 14.07 - tested on TP-Link TL-WR710N
-------------------------------------------------------------------------------------------------------------------------------

OpenWRT is simply fantastic!

Wi-Fi Internet radio using small Wi-Fi AP/Router (30 €) , 4 port USB Switch (10 € with clock), 2 GB USB memory stick (5 €) and USB stereo audio adapter (5 €).
No hardware mods needed.

Note: the router maintains full Wi-Fi/LAN/WAN/3G functionality smile

http://www.lovisolo.com/asterisk/software/openwrt/radio-mp3/P1070077.JPG

http://www.lovisolo.com/asterisk/software/openwrt/radio-mp3/P1070089.JPG

http://www.lovisolo.com/asterisk/software/openwrt/radio-mp3/P1070140.JPG

http://www.lovisolo.com/asterisk/software/openwrt/radio-mp3/P1070245.JPG

http://i55.tinypic.com/315hjig.jpg
USB audio adapter (see https://mightyohm.com/forum/viewtopic.p … p;start=20 for other compatible models)

http://www.memorystock.it/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/h/u/hub-nortek-422.jpg
USB hub 4 ports (this is unpowered but I would suggest you to use instead a HUB powered with external power supply)


- VIDEO:

http://www.youtube.com/watch?v=i5_o6L1c … e=youtu.be

Italian audio:
https://www.youtube.com/watch?v=QfGRs9CtcHQ



- Instructions to install USB Overlay on TL-MR3020

note: for OpenWrt 12.09 'Attitude Adjustment'

Start from fresh install or reset to default with command: "mtd -r erase rootfs_data" (*** WARNING - this command will erase all your existing data and configurations! ***)

Prerequisites:
- Set root password and enable ssh
- configure network
- USB memory key > 1 GB - ext4 formatted

note: I used a USB key with only one partition (/dev/sda1):

opkg update
opkg install kmod-usb-uhci
opkg install kmod-usb-ohci
opkg install kmod-usb2
opkg install kmod-usb-core kmod-usb-storage usbutils block-mount kmod-fs-ext4

   insmod usbcore
   insmod uhci 
   insmod usb-ohci 
   insmod ehci-hcd 

now reboot the router

than

mkdir -p /mnt/share
mount -t ext4 /dev/sda1 /mnt/share -o rw,sync
tar -C /overlay -cvf - . | tar -C /mnt/share -xf -

now with "vi" (the most stupid and prehistoric editor in the whole universe) edit "fstab":

vi /etc/config/fstab

delete everything and insert the following lines (ESC+i):

config global automount
        option from_fstab 1
        option anon_mount 1

config global autoswap
        option from_fstab 1
        option anon_swap 0

config mount
        option target   /overlay
        option device   /dev/sda1
        option fstype   ext4
        option options  rw,sync
        option enabled  1
        option enabled_fsck 0

config swap
        option device   /dev/sda2
        option enabled  0


press "esc" and then type " :wq " followed by "enter" to save.

Reboot and check if everything is OK with the "df -kh" command:

root@OpenWrt:~#df -kh
Filesystem                Size      Used Available Use% Mounted on
rootfs                    3.5G    122.5M      3.2G   4% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M    388.0K     13.9M   3% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 3.5G    122.5M      3.2G   4% /overlay
overlayfs:/overlay        3.5G    122.5M      3.2G   4% /

-------------------------------------------------------------------------------------------------------------

NEW: Instructions for Barrier Breaker 14.07
note: 8 Mbytes of Flash needed!

opkg update
opkg install kmod-usb-uhci
opkg install kmod-usb-ohci
opkg install kmod-usb2
opkg install kmod-usb-core kmod-usb-storage usbutils block-mount kmod-fs-ext4

Mount the filesystem:

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1

Copy contents from /overlay to usb device:

tar -C /overlay -cvf - . | tar -C /mnt/sda1 -xf -

Generate fstab file:

block detect > /etc/config/fstab

Edit fstab file:

vi /etc/config/fstab

change the target to '/overlay'
change enabled option from '0' to '1'

Do not change UUID or other settings!

Reboot and check if everything is OK with the "df -kh" command

(Last edited by pilovis on 9 Jan 2017, 00:10)

http://cdn.computeruniverse.net/media/images/300/90481695F2494D0A46D0402F808957CE.jpg

I've just connected a small USB numeric keypad to the router so I can change radio stations just by pressing numbers on keypad (0-9), adjust audio volume with "+" and "-" keys and also a Key to stop playing (the "BS" key).

References:
http://h-wrt.com/en/doc/sound
http://h-wrt.com/en/doc/kb
http://wiki.openwrt.org/doc/howto/hardware.button
http://wiki.openwrt.org/doc/howto/usb.essentials
http://store.jpgottech.com/support/tp-l … ing-guide/
https://mightyohm.com/forum/viewtopic.p … p;start=20

http://www.listenlive.eu/index.html source for online radio streaming URLs

-------------------------------------------------------------------------------

- Instructions (tested on ATTITUDE ADJUSTMENT 12.09 STABLE, r36088 and Barrier Breaker 14.07):

Note: preconfigured external Overlay USB memory stick of 1 GB or more needed if FLASH < 8 Mbytes!

Preliminary steps:
note: not needed for Barrier Breaker 14.07

The first step is to make Hotplug execute scripts in /etc/hotplug.d/button when a button is clicked. Modify /etc/hotplug2.rules — remove '^' before 'button' as follow:

vi /etc/hotplug2.rules

[$include /etc/hotplug2-common.rules
SUBSYSTEM ~~ (^net$|^input$|button$|^usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
    exec /sbin/hotplug-call %SUBSYSTEM%
}
DEVICENAME == watchdog {
    exec /sbin/watchdog -t 5 /dev/watchdog
    next-event

press "esc" and then type " :wq " followed by "enter" to save.


Installation instructions:

1) Install triggerhappy:

    opkg update
    opkg install kmod-usb-hid
    opkg install kmod-hid kmod-hid-generic
    opkg install triggerhappy

also install (some packages might be already installed):

   opkg install kmod-usb-hid kmod-usb-core kmod-ledtrig-usbdev kmod-hid kmod-hid-generic
   opkg install kmod-sound-core kmod-usb-audio madplay usbutils kmod-sound-cs5535audio
   opkg install kmod-sound-i8x0 kmod-sound-soc-core usb-modeswitch
   opkg install kmod-usb-uhci
   opkg install kmod-button-hotplug
   opkg install kmod-gpio-button-hotplug
   opkg install kmod-usb-ohci
   opkg install kmod-usb2
   opkg install alsa-utils
   opkg install alsa-lib   

   insmod usbcore
note: not needed for Barrier Breaker 14.07

   insmod uhci
note: not needed for Barrier Breaker 14.07

   insmod usb-ohci
note: not needed for Barrier Breaker 14.07

   insmod ehci-hcd
note: not needed for Barrier Breaker 14.07

2) launch the following command to find "eventcodes" for available buttons (KEY_LABEL):

    thd --dump /dev/input/event*

example:

root@OpenWrt:~# thd --dump /dev/input/event*
EV_KEY    KEY_KP5    1    /dev/input/event0
# KEY_KP5    1    command
EV_KEY    KEY_KP5    2    /dev/input/event0
# KEY_KP5    2    command
EV_KEY    KEY_KP5    2    /dev/input/event0
# KEY_KP5    2    command
EV_KEY    KEY_KP5    2    /dev/input/event0
# KEY_KP5    2    command
EV_KEY    KEY_KP5    0    /dev/input/event0
# KEY_KP5    0    command
EV_KEY    KEY_KP1    1    /dev/input/event0
# KEY_KP1    1    command
EV_KEY    KEY_KP1    0    /dev/input/event0
# KEY_KP1    0    command
EV_KEY    KEY_KP1    1    /dev/input/event0
# KEY_KP1    1    command
EV_KEY    KEY_KP1    0    /dev/input/event0
# KEY_KP1    0    command

Note: A value of 1 corresponds to pressing a key, while 2 is generated by holding it; releasing it yields a value of 0.

3) edit "/etc/triggerhappy/triggers.d/example.conf"  as follow (you may need to adjust the"KEY_LABELS" if you use a different keyboard, and change device "PCM" if you use a different USB sound device):


#
KEY_KP0 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://icestreaming.rai.it/4.mp3 | /usr/bin/madplay - &
KEY_KP1 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://str30.creacast.com/r101_thema4 | /usr/bin/madplay - &
KEY_KP2 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1203 | /usr/bin/madplay - &
KEY_KP3 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1513 | /usr/bin/madplay - &
KEY_KP4 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk | /usr/bin/madplay - &
KEY_KP5 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://server-10.stream-server.nl:8300 | /usr/bin/madplay - &
KEY_KP6 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://91.121.164.186:8600 | /usr/bin/madplay - &
KEY_KP7 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsj/mp3_128 | /usr/bin/madplay - &
KEY_KP8 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsc_it/mp3_128 | /usr/bin/madplay - &
KEY_KP9 1 /usr/bin/killall madplay ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsp/mp3_128 | /usr/bin/madplay - &
KEY_KPMINUS 1 /usr/bin/amixer -q set PCM 2%-
KEY_KPPLUS 1 /usr/bin/amixer -q set PCM 2%+
#KEY_KPENTER 1
#KEY_KPDOT 1
#KEY_KPSLASH 1
KEY_BACKSPACE 1 /usr/bin/killall madplay
#KEY_KPASTERISK 1
#
# eof

- Notes:
Keys KEY_KPENTER, KEY_KPDOT, KEY_KPSLASH, KEY_KPASTERISK, are not used in this example but you can use all of them to add more stations or functions, just uncomment them (remove #) and add after "1 " the commands to be executed (with full path!) - if you use more than one command per line, use ";" to separate them.
Key "000" cannot be used since it is the same as pressing 0 three times! big_smile
Key "Num Lock" cannot be used, it does not influence the functionality of other keys if enabled or not, it just switches on/off the led smile (... actually it does something more)
"/usr/bin/killall madplay" is needed to stop all running instances of madplay (if any) before starting the new madplay istance.

- Enable triggerhappy on boot with the following command:

  /etc/init.d/triggerhappy enable

------------------------------------------------------

Extra stuffs.

To save anytime your current audio volume level, launch the following command (you could associate it with a key on the keypad):

/usr/sbin/alsactl -f /etc/alsa0.state store 0

and then to restore this on boot, insert the following line in "/etc/rc.local" file, right before the "exit 0" line
           
  /usr/sbin/alsactl -f /etc/alsa0.state restore 0

then finally reboot and enjoy your new Digital Stereo Wi-Fi Internet Radio smile

Note:
to manually "start" and "stop" the Internet Radio, use the following commands:

  /etc/init.d/triggerhappy start
to start the radio (mute) waiting for any input from the keypad

  /usr/bin/killall madplay; etc/init.d/triggerhappy stop
to stop playing anything and kill triggerhappy daemon

------------------------------------------------------

There's no need to mpc or mpd daemon, nor firewall rules, just USB audio/HID drivers and madplay installed and you have a complete wifi internet radio.

(Last edited by pilovis on 18 Aug 2016, 21:46)

-------------------------------------------------------------------------------------------------------------------------------
[Updated 16/10/2014] - Added support for Barrier Breaker 14.07 - tested on TP-Link TL-WR710N
-------------------------------------------------------------------------------------------------------------------------------

I've just added another function to my Internet Radio: MP3 player
Note: preconfigured external Overlay USB memory stick of 1 GB or more is needed!

I added this feature because I want to be able to listen to some music also when an internet connection is not available wink

note: there are a lot of how-to's on this subject, eg. https://forum.openwrt.org/viewtopic.php … 96#p125196

I added/updated  the following functions:

- MPD MP3 Player:

Key "0" = Start MPD and play the first song in playlist
Key "."  = jump to next song in playlist and start playing it

note: You may add "jump to prev song" function on the MP3 player ( "/usr/bin/mpc prev" command) sacrificing one radio channel.

- Volume:

Key "Enter" = set the volume at the minimum audible level (about 3%, NIGHT mode)
Key "+" increase volume +2%
Key  "-" decrease volume -2%
Key "BS" stop playing

- Internet Radio:

added Keys "/" and "*" = two more stations (11 total)

- Extra feature:

the MP3 songs can be uploaded into the router using Vsftp server or Samba share (to be installed).

You can switch anytime from Internet Radio to MP3 player (and vice versa) just by choosing one radio channel or press "0" key for MP3 player cool

Note: pressing the "." key (next song - MP3 player) when you are listening to Internet Radio, does nothing, it works only when you are in MP3 player mode.

----------------------------------------------------------------------
- Instructions for ATTITUDE ADJUSTMENT 12.09 STABLE, r36088:

cd /root
opkg update
opkg install nano
opkg install mpd-mini
opkg install mpc
mkdir music
mkdir playlist


than edit the "/etc/mpd.conf" to match the following configuration:

nano /etc/mpd.conf

#
music_directory         "~/music"
playlist_directory              "~/playlist"
db_file                 "~/mpd.db"
bind_to_address         "127.0.0.1"
port                            "6600"
input {
        plugin "curl"
}

audio_output {
        type            "oss"
        name            "My OSS Device"
        device          "/dev/dsp"      # optional
}
# eof

Ctrl+x to save


TriggerHappy configuration file modified "etc/triggerhappy/triggers.d/example.conf":

nano etc/triggerhappy/triggers.d/example.conf

# begin of file
#
## prerequisites: USB support, USB audio, USB hid, usb-modeswitch, sound-core, triggerhappy, madplay, mpd/mpc, asa, alsa-utils, alsa-lib
#
#
## - MP3 Player -
#
## kill all active players, start MPD, update playlist and play the first song:
KEY_KP0 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/mpd ; /usr/bin/mpc listall | /usr/bin/mpc add ; /usr/bin/mpc play
#
## jump to next song in playlist and start playing it:
KEY_KPDOT 1 /usr/bin/mpc next
#
## You may add "jump to prev song" function on the MP3 player ( "/usr/bin/mpc prev" command) sacrificing one radio channel
#
##  - Internet Radio  -
#
## kill all active players, launch madplay and start playing selected streaming URL:
KEY_KP1 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://str30.creacast.com/r101_thema4 | /usr/bin/madplay - &
KEY_KP2 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1203 | /usr/bin/madplay - &
KEY_KP3 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1513 | /usr/bin/madplay - &
KEY_KP4 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk | /usr/bin/madplay - &
KEY_KP5 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://server-10.stream-server.nl:8300 | /usr/bin/madplay - &
KEY_KP6 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://91.121.164.186:8600 | /usr/bin/madplay - &
KEY_KP7 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsj/mp3_128 | /usr/bin/madplay - &
KEY_KP8 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsc_it/mp3_128 | /usr/bin/madplay - &
KEY_KP9 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://stream.srg-ssr.ch/m/rsp/mp3_128 | /usr/bin/madplay - &
KEY_KPASTERISK 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1115 | /usr/bin/madplay - &
KEY_KPSLASH 1 /usr/bin/killall madplay mpd ; sleep 1 ; /usr/bin/wget -O - http://shoutcast.unitedradio.it:1103 | /usr/bin/madplay - &
#
## - Volume controls -
#
## decrease volume -2%:
KEY_KPMINUS 1 /usr/bin/amixer -q set PCM 2%-
#
##  increase volume +2%:
KEY_KPPLUS 1 /usr/bin/amixer -q set PCM 2%+
#
##  set the volume at the minimum audible level (about 3%, NIGHT mode):
KEY_KPENTER 1 amixer -q set PCM 4
#
## - STOP music -
#
## Kill all active players and stop music:
KEY_BACKSPACE 1 /usr/bin/killall madplay mpd
#
#end of file

Ctrl+x to save
note: you may need to adjust the"KEY_LABELS" if you use a different keyboard and "PCM" if you use a different USB sound device
"/usr/bin/killall madplay ; /usr/bin/killall mpd ; sleep 1" is needed to stop all running instances of madplay or mpd (if any) before starting the new madplay or mpd istance.

Note: put all .mp3 files (filenames without spaces!) in the "/root/music" directory

In case this is a little "single command line" (not recursive) to remove spaces from filenames:
for f in *\ *; do mv "$f" "${f// /_}"; done
-----------------------------------------------------------------------------------------------------

NEW: Instructions for Barrier Breaker 14.07
Note: preconfigured external Overlay USB memory stick of 1 GB or more is needed!

opkg update
opkg install nano
opkg install mpd
opkg install mpc

nano /root/mp3-player

insert the following lines:

#!/bin/bash
cd /root
/usr/bin/mpd
/usr/bin/mpc listall
/usr/bin/mpc add *.mp3
/usr/bin/mpc play

Ctrl+x to save, than

chmod 777 /root/mp3-player


nano /root/next

insert the following lines:

#!/bin/bash
cd /root/music
/usr/bin/mpc next

Ctrl+x to save, than

chmod 777 /root/next


nano /root/prev

insert the following lines:

#!/bin/bash
cd /root/music
/usr/bin/mpc prev

Ctrl+x to save, than

chmod 777 /root/prev


nano /etc/triggerhappy/triggers.d/example.conf

## prerequisites: USB support, USB audio, USB hid, usb-modeswitch, sound-core, triggerhappy, madplay, mpd/mpc, asa, alsa-utils, alsa-lib
#
#
## - MP3 Player - opkg install mpd mpc
#
## kill all active players, start MPD, update playlist and play the first song:
KEY_NUMLOCK 1 /usr/bin/killall madplay ; /usr/bin/killall mpd ; sleep 1 ; /bin/sh /root/mp3-player - &
#
## jump to next song in playlist and start playing it:
KEY_KPSLASH 1 /bin/sh /root/next - &
#
## jump to prev song in playlist and start playing it:
KEY_KPASTERISK 1 /bin/sh /root/prev - &
#

Ctrl+x to save


nano mpd.conf

delete everything inside the file and insert the following:

music_directory         "~/"
playlist_directory              "~/"
db_file                 "~/mpd.db"
user                            "root"
group                           "root"
bind_to_address         "127.0.0.1"
port                            "6600"
input {
        plugin "curl"
}
audio_output {
        type            "oss"
        name            "My OSS Device"
        device          "/dev/dsp"      # optional
        mixer_device    "/dev/mixer"    # optional
        mixer_control   "PCM"           # optional
}
buffer_before_play              "20%"
connection_timeout              "60"
max_connections         "10"
max_playlist_length             "16384"
max_command_list_size           "2048"
max_output_buffer_size          "8192"

Ctrl+x to save and reboot.
note: you may need to adjust "PCM" value in mixer_control if you use a different USB sound device

Note: put all .mp3 files (filenames without spaces!) in the "/root" directory

In case this is a little "single command line" (not recursive) to remove spaces from filenames:
for f in *\ *; do mv "$f" "${f// /_}"; done

(Last edited by pilovis on 18 Jan 2018, 19:32)

Nice, nice work :-)

Next feature will be audio recording and storing in MP3 format, either from the input connector of USB audio stick or directly from an internet radio streaming, just by pressing a key! smile

Stay tuned! big_smile

(Last edited by pilovis on 20 Oct 2014, 20:21)

MPD high CPU load problem.

MPD (in conjunction with Alsa) has some high CPU load issues due to "sample rate conversion", this may cause intermittent hangs with consequent router restart, it also has some issues with buffer size too small for the limited transfer rate of the flash memory (audio file skipping):

This is my "/etc/mpd.conf" file, tuned for best preformances on OpenWrt:

#
music_directory         "~/music"
playlist_directory              "~/playlist"
db_file                 "~/mpd.db"
bind_to_address         "127.0.0.1"
port                            "6600"
input {
        plugin "curl"
}

audio_output {
        type            "oss"
        name            "My OSS Device"
        device          "/dev/dsp"      # optional
}
samplerate_converter            "internal"
audio_buffer_size                   "8192"
buffer_before_play                  "25%" # about 2 seconds delay before playing

# eof

----------------------------------------------

To monitor CPU usage use "cpusage" command.

- Install:
opkg update
opkg install cpusage

- Use:
cpusage

- Output:
root@OpenWrt:~# cpusage
timestamp: 2014-02-19 14.19.13, user:  14.0%, nice:   0.0%, system:   0.0%, idle:  86.0%, iowait:   0.0%, irq:   0.0%, softirq:   0.0%,
timestamp: 2014-02-19 14.19.14, user:  12.0%, nice:   0.0%, system:   0.0%, idle:  88.0%, iowait:   0.0%, irq:   0.0%, softirq:   0.0%,
timestamp: 2014-02-19 14.19.15, user:  11.0%, nice:   0.0%, system:   1.0%, idle:  87.0%, iowait:   0.0%, irq:   0.0%, softirq:   1.0%,
timestamp: 2014-02-19 14.19.16, user:   9.0%, nice:   0.0%, system:   3.0%, idle:  88.0%, iowait:   0.0%, irq:   0.0%, softirq:   0.0%,
timestamp: 2014-02-19 14.19.17, user:  12.0%, nice:   0.0%, system:   1.0%, idle:  86.0%, iowait:   0.0%, irq:   0.0%, softirq:   1.0%,
timestamp: 2014-02-19 14.19.18, user:  13.9%, nice:   0.0%, system:   0.0%, idle:  85.1%, iowait:   0.0%, irq:   0.0%, softirq:   1.0%,
timestamp: 2014-02-19 14.19.19, user:  11.0%, nice:   0.0%, system:   0.0%, idle:  88.0%, iowait:   0.0%, irq:   0.0%, softirq:   1.0%,
timestamp: 2014-02-19 14.19.19, user:  10.0%, nice:   0.0%, system:   2.5%, idle:  85.0%, iowait:   0.0%, irq:   0.0%, softirq:   2.5%,
.
.
.
^C

use Ctrl+c to stop reading data, then you will see the summary report:

---Summary----
Min: timestamp: 2014-02-19 14.19.19, user:   9.0%, nice:   0.0%, system:   0.0%, idle:  85.0%, iowait:   0.0%, irq:   0.0%, softirq:   0.0%,
Max: timestamp: 2014-02-19 14.19.19, user:  14.0%, nice:   0.0%, system:   3.0%, idle:  88.0%, iowait:   0.0%, irq:   0.0%, softirq:   2.5%,
Avg: timestamp: 2014-02-19 14.19.19, user:  11.4%, nice:  -0.0%, system:   0.9%, idle:  86.9%, iowait:  -0.0%, irq:  -0.0%, softirq:   0.8%,

(Last edited by pilovis on 1 Mar 2014, 11:02)

-----------------
Audio recorder
-----------------

I want to share with you my progress smile

opkg update
opkg install ffmpeg

Note: [BUG] ffmpeg can't install if you have already installed mpd/mpc, you should install ffmpeg first! sad sad sad

After a long searching I came up with this "full path & single line" command to be associated to a key to record MP3 audio coming from the input connector of the USB audio device (mic input) and also with adding the timestamp to the filename:

now=$(date +"%Y-%m-%d----%H-%M-%S") ; /usr/bin/ffmpeg -f  oss -ar 44100 -i /dev/dsp -acodec mp2 -ab  128k record.$now.mp3

The out file name is:  "record.year-month-day---hours-minutes-seconds.mp3" (eg. record.2014-02-21---11-29-51.mp3)


command to stop recording:

/usr/bin/killall - ffmpeg

note: "killall -" = Sends a SIGTERM signal initially and then sends a SIGKILL signal to all processes that survive for 30 seconds after receipt of the signal first sent. This gives processes that catch the SIGTERM signal an opportunity to clean up.

(Last edited by pilovis on 12 Nov 2015, 09:44)

Another discovery smile

if you connect a USB mouse you'll have two or three more buttons (it depends on how many buttons the mouse has):

BTN_LEFT
BTN_RIGHT
BTN_MIDDLE

(Last edited by pilovis on 29 Oct 2014, 14:04)

Here is a picture of my internet radio build:

$80 shipped on sale. I have a Pogoplug running Logitech Media Server to serve up Pandora and local mp3/flac.

http://ecx.images-amazon.com/images/I/81BQDT9GgcL.jpg

Joking aside. Awesome work, but a little dated now considering the cost of brand name manufactured internet radio now.

However I understand you didn't do this for practical reasons. smile

(Last edited by King0fK0ng on 20 Feb 2014, 23:56)

I will use this project in conjunction with my hand-made Hi-Fi vacuum tube ampilfiers smile
Future and past tecnologies together!

All designed and hand made by myself using almost all recovered parts (except tubes) wink

"WiFi Internet Digital Vacuum Tubes Radio", I'm sure you can't buy anything similar lol
No LCD or super LED display, just old style original "Magic Eye" tubes.

http://www.lovisolo.com/valvole/ampli1.jpg

http://www.lovisolo.com/valvole/ampli3.jpg

http://i44.servimg.com/u/f44/17/14/70/27/p1040416.jpg

http://i44.servimg.com/u/f44/17/14/70/27/p1040415.jpg

http://www.lovisolo.com/valvole/807.jpg

http://i34.servimg.com/u/f34/17/14/70/27/ampli-10.jpg

http://i44.servimg.com/u/f44/17/14/70/27/p1030721.jpg

http://i44.servimg.com/u/f44/17/14/70/27/p1030818.jpg
Note the USB connector on the tube board big_smile


http://i44.servimg.com/u/f44/17/14/70/27/stereo11.jpg

(Last edited by pilovis on 21 Feb 2014, 01:18)

Concerning the recording function.  Have you considered using the opus codec (http://www.opus-codec.org)?  It has a fixed point implementation which is promising.  When I tried to stream recorded audio a couple of years ago,  the codec I tried to use (vorbis) was too taxing for the poor little router, but it wasn't a fixed point codec. 

You might be more successful.

Best of luck!

This How-To has been reviewed and updated today, I corrected some typos, added more instructions and detailed configurations. smile

(Last edited by pilovis on 1 Mar 2014, 11:08)

Wow I am impressed. I am planning to replicate your setup. My Modem is Huawei E3531s-2...
Can you please post instructions how to make this setup.

Also is it possible to use old USB stick (128MB) to be used as storage for file system (openwrt) ?

smile

I've just updated the How To, I added instructions for Barrier Breaker 14.07 (tested on TP-Link TL-WR710N) and corrected some typos.
smile

P.S.: I also successfully tested this audio device:

http://www.music4company.com/images/Products/0-5ce1deb0-500.jpg

please note you need to modify configuration files to adapt device name (from "PCM" to "Speaker") , check it with command "alsamixer".

(Last edited by pilovis on 22 Oct 2014, 17:13)

Addendum:

in case you use Tp-Link TL-WR710N or any other router that has at least 8 MB of flash, and you don't want or can't use an external HDD overlay, but you want to add the MP3 player functionality to your OpenWrt Internet Radio, you can also use "madplay" for this function.

This "single line command" searches for .mp3 files in "/root" directory (or anywhere else if you adapt the path) and plays mp3 files in sequence:

find /root/ -name \*[mM][Pp]3 | awk '{print "\""$0"\""}' | xargs madplay

The bad news is there aren't the "prev" and "next" functions that you can have with mpd/mpc,
the good news is that madplay uses much less resources than mpd/mpc.

(Last edited by pilovis on 20 Oct 2014, 20:09)

-----------------------------
Another extra-feature smile
-----------------------------

1) connect anytime an USB flash drive, fat32 formatted, with a lot of mp3 inside
2) press a "key" to start playing all mp3 in sequence
3) listen ... big_smile

Note: I choosed Fat32 to have full Windows/Mac/Linux compatibility and to avoid any file permission problems I could have with EXT or NTFS partitions (FAT32 formatted drives do not support file permissions wink ).


Instructions:

opkg update
opkg install kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1

create and edit the "/root/mount.sh" file:

nano /root/mount.sh

mkdir -p /mnt/music
mount -t vfat /dev/sdb1 /mnt/music
find /mnt/music -name \*[mM][Pp]3 | awk '{print "\""$0"\""}' | xargs madplay

Ctrl+x to save

Note: adapt "/dev/sdb1" to match your configuration.

chmod 777 /root/mount.sh

than attach the following "single command line MP3 player" to a key:

/bin/sh /root/mount.sh - &

triggerhappy configuration example:

KEY_BACKSPACE 1 /usr/bin/killall madplay ; /usr/bin/killall mpd ; sleep 2 ; /bin/sh /root/mount.sh - &

Note:  "/usr/bin/killall madplay ; /usr/bin/killall mpd ; sleep 2" is needed to stop all running instances of madplay or mpd (if any) before starting the new madplay istance.

(Last edited by pilovis on 21 Oct 2014, 19:53)

------------------------
Audio normalization
------------------------
I noticed that Internet Streaming Radio Stations use different audio volume levels one from each other, some of them have audio volume too high, some others too low, in consequence of that I have to adjust volume level too much frequently, same for MP3 files. sad

So, I came up with the idea to normalize the audio level on the fly smile

Actually it is quite simple, for madplay it is enough to add two options in the command line, for MPD/MPC it is just a matter to enable an option in the config file.

- Example to enable audio normalization for madplay:

/usr/bin/wget -O - http://205.164.62.15:9010/ | /usr/bin/madplay --replay-gain=audiophile --attenuate=-0 - &

note: you can also do some fine tuning for each preset station by using "attenuate" or "amplify" options:

ex:
/usr/bin/wget -O - http://205.164.62.15:9010/ | /usr/bin/madplay --replay-gain=audiophile --attenuate=-2 - &

/usr/bin/wget -O - http://205.164.62.15:9010/ | /usr/bin/madplay --replay-gain=audiophile --amplify=+1 - &

just to be safe:
opkg update
opkg install lame

- Enable normalization for MPD/MPC:

nano /etc/mpd.conf

change the following line:
#volume_normalization            "no"

to:
volume_normalization           "yes"

--------------------------

Note: Audio normalization is the application of a constant amount of gain to an audio recording to bring the average or peak amplitude to a target level.
The standard used to normalize audio is "ReplayGain.
ReplayGain is a proposed standard published by David Robinson in 2001 to measure the perceived loudness of audio in computer audio formats such as MP3 and Ogg Vorbis. It allows players to normalize loudness for individual tracks or albums. This avoids the common problem of having manually to adjust volume levels between tracks when playing audio files from albums that have been mastered at different loudness levels"

(Last edited by pilovis on 29 Oct 2014, 15:56)

---------------
Suggestions
---------------

If you have problems playing mp3s with spaces in the file name, this is a little "single command line" (not recursive) to remove spaces from filenames and convert them to underscores:

for f in *\ *; do mv "$f" "${f// /_}"; done

To upload mp3s to the router you can use samba share or ftp, I would suggest ftp, samba is too heavy.

Install ftp server:

opkg update
opkg install vsftpd

/etc/init.d/vsftpd enable
/etc/init.d/vsftpd start

connect to ftp server using the following credentials:

ftp server: router_IP
port: 21 tcp (passive mode)
user id: root
password: root_password

note: destination directory = /root

-----------------------------------------------

[BUG - OpenWrt 12.09 'Attitude Adjustment']

I wanted to disable "watchdog" because the router rebooted too frequently.
I tried to "killall watchdog" or execute the "/etc/init.d/watchdog stop" in command line, but it didn't work.
Also /etc/init.d/watchdog disable had no effect, after rebooting watchdog were still running.

Solution:
-----------

Comment out (#) the watchdog lines in '/etc/hotplug2.rules':

#DEVICENAME == watchdog {
#        exec /sbin/watchdog -t 5 /dev/watchdog
#        next-event
#}

Than:

/etc/init.d/watchdog disable
/etc/init.d/watchdog stop

In case you want to enable again watchdog on startup use:

/etc/init.d/watchdog enable

--------------------------------------------------------------

Still to do:

1) Web page or Luci module to easily modify preset radio stations and upload/rename/delete MP3 files (next)
2) Simple and cheap USB LCD display to show stations and songs informations (near)
3) FM and/or DVB-T radio OpenWrt functionality (far away)

Any help will be greatly appreciated! smile

I also wanted to add bluetooth speakers but I abandoned the idea after weeks of testing, bluetooth does not work in OpenWrt, is badly broken, there is no way to pair and connect any device! mad (dead)

(Last edited by pilovis on 29 Oct 2014, 15:18)

You'll find my "ready to use" configuration files here:

http://www.lovisolo.com/openwrt

(Last edited by pilovis on 22 Oct 2014, 10:35)

Another discovery smile

Up to now to increase or decrease the audio volume you should press the + or - buttons several times, for each press you can change about 1% of it, but if you keep the buttons pressed nothing happens.

To increase or decrease audio volume continuously by keeping pressed the + and - keys you need to add the following two lines to the triggerhappy configuration file (/etc/triggerhappy/triggers.d/example.conf):

KEY_KPPLUS 2 /usr/bin/amixer -q set Speaker 1dB+
KEY_KPMINUS  2 /usr/bin/amixer -q set Speaker 1dB-

this is the complete section of audio volume controls:

# set volume control to minumun addible level
KEY_BACKSPACE 1 /usr/bin/amixer -q set Speaker 4
#
# Volume controls
KEY_KPMINUS 1 /usr/bin/amixer -q set Speaker 1%-
KEY_KPPLUS 1 /usr/bin/amixer -q set Speaker 1%+
KEY_KPPLUS 2 /usr/bin/amixer -q set Speaker 1dB+
KEY_KPMINUS 2 /usr/bin/amixer -q set Speaker 1dB-
#
# Stop playing
KEY_KPENTER 1 /usr/bin/killall madplay ; /usr/bin/killall mpd

Note: A value of KEY_xxxxx 1 corresponds to pressing a key, while 2 is generated by holding it; releasing it yields a value of 0.
By using of set 1% value, instead of 2% as per my previous posts, allows a more granular control over the audio volume level. 

You might need to change "Speaker" device name if you use a different USB sound card.

(Last edited by pilovis on 30 Oct 2014, 21:55)

Summarizing:

this audio device needs "Speaker" device name:

http://www.music4company.com/images/Products/0-5ce1deb0-500.jpg

this other needs "PCM" device name:

http://i55.tinypic.com/315hjig.jpg

Other USB audio devices might need different device name (check it with command alsamixer under "Item:.....")

A good list of USB-audio adapters known to work with OpenWrt/mpd:
https://mightyohm.com/forum/viewtopic.php?f=2&t=232

(Last edited by pilovis on 29 Oct 2014, 14:22)