USB-Audio für den Raspberry Pi

In der Konsole: Audio per externer USB-Soundkarte

Folgende Vorgehensweise hat bei mir funktioniert:

pi@pi4:~ $ lsusb
Bus 001 Device 005: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 004: ID 0461:0010 Primax Electronics, Ltd HP Keyboard
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@pi4:~ $ dmesg | grep C-Media
[ 117.125521] usb 1-1.4: Manufacturer: C-Media Electronics Inc.
[ 117.133255] input: C-Media Electronics Inc. USB PnP Sound Device as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:0D8C:013C.0003/input/input2
[ 117.198372] hid-generic 0003:0D8C:013C.0003: input,hidraw2: USB HID v1.00 Device [C-Media Electronics Inc. USB PnP Sound Device] on usb-3f980000.usb-1.4/input3
pi@pi4:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@pi4:~ $ sudo touch /etc/asound.conf
pi@pi4:~ $ sudo nano /etc/asound.conf

Folgendes in die Datei einfügen:

pcm.!default {
  type hw
  card 1
}
ctl.!default {
  type hw
  card 1
}

Default in /usr/share/alsa/pcm/default.conf ?

Testen: (geht nicht, in einer ersten Installation ging es)
aplay /usr/share/sounds/alsa/Front_Center.wav
aplay -D default /usr/share/sounds/alsa/Front_Center.wav
aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Center.wav
aplay -D hw:1,0 /usr/share/sounds/alsa/Front_Center.wav

Save settings: sudo alsactl store

MPlayer
sudo apt-get install mplayer alsa-base alsa-utils pulseaudio mpg123
Hiervon wurden nur mplayer2 und mpg123 installiert, alle anderen waren schon vorhanden und aktuell.

Erster Test, Musik wird abgespielt
pi@pi4:~/smb/Musik/D/Dire Straits/1988 – Money for Nothing $ mplayer '10 - Telegraph Road ­ Live (Remix).mp3
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 10 – Telegraph Road ­ Live (Remix).mp3.
Detected file format: MP2/3 (MPEG audio layer 2/3) (libavformat)
[mp3 @ 0x75b325b8]max_analyze_duration 5000000 reached
[lavf] stream 0: audio (mp3), -aid 0
[lavf] stream 1: video (mjpeg), -vid 0,
Clip info:
title: Telegraph Road (live) (remix)
artist: Dire Straits
track: 10/12
album: Money for Nothing
disc: 1/1
genre: Progressive Rock
TMED: CD
SCRIPT: Latn
originalyear: 1988
MusicBrainz Album Type: album/compilation
MusicBrainz Album Artist Id: 614e3804-7d34-41ba-857f-811bad7c2b7a
MusicBrainz Artist Id: 614e3804-7d34-41ba-857f-811bad7c2b7a
BARCODE: 042283641921
TSO2: Dire Straits
album_artist: Dire Straits
CATALOGNUMBER: 836 419-2
MusicBrainz Release Group Id: 8af3b92c-34b7-3182-b132-1b952637f7a6
Artists: Dire Straits
MusicBrainz Release Track Id: 710ad7e0-2c99-3312-be2c-44c70078e8c4
TORY: 1988
artist-sort: Dire Straits
TSRC: GBF088400793
MusicBrainz Album Status: official
MusicBrainz Album Id: d077483a-c2b8-3a1e-b0e6-33454184191d
publisher: Vertigo
MusicBrainz Album Release Country: GB
date: 1996
Load subtitles in .
Selected audio codec: MPEG 1.0/2.0/2.5 layers I, II, III [mpg123]
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->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…

Interessante Links:
https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Set_the_default_sound_card
https://rasspberrypi.wordpress.com/2012/09/02/audio-and-video-playback-on-raspberry-pi/
https://www.pcwelt.de/ratgeber/Besserer_Sound_fuer_den_Raspberry_Pi_-Upgrade-8640702.html

Verwendung: http://www.instructables.com/id/Raspberry-Pi-Radio/

Für MP3-Playlist: Verzeichnisbaum ausgeben: (tree)
https://stackoverflow.com/questions/14352290/listing-only-directories-using-ls-in-bash-an-examination
Die dann noch in eine Datei schreiben und im Skript in das Array einlesen.