From 7170b7fcb21b44e00ec77128b1214d8bc4c613c9 Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 15:57:45 +0800 Subject: [PATCH 1/6] change dmix to plughw to playback --- asound_4mic.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asound_4mic.conf b/asound_4mic.conf index a5c9edb..6732667 100644 --- a/asound_4mic.conf +++ b/asound_4mic.conf @@ -9,7 +9,7 @@ pcm.!default { pcm.playback { type plug - slave.pcm "dmixed" + slave.pcm "hw:0,0" } From 8b84b891cd61a9befcee5629f999013431fcd53f Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 15:58:36 +0800 Subject: [PATCH 2/6] use seeed-voicecard service to manager all the card Changes to be committed: modified: install.sh modified: uninstall.sh --- install.sh | 68 ++++++++++++++---------------------------- uninstall.sh | 84 ++++++++++------------------------------------------ 2 files changed, 39 insertions(+), 113 deletions(-) diff --git a/install.sh b/install.sh index 9430dbd..b19535d 100755 --- a/install.sh +++ b/install.sh @@ -11,13 +11,8 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then exit 1 fi -ver="0.2" -card=$1 +ver="0.3" -if [ "x${card}" = "x" ] ; then - echo "Usage: ./install 2mic|4mic" - exit 1 -fi # we create a dir with this version to ensure that 'dkms remove' won't delete # the sources during kernel updates @@ -51,21 +46,25 @@ function install_module { mkdir -p /var/lib/dkms/$mod/$ver/$marker } -if [ ! -f "/boot/overlays/seeed-4mic-voicecard.dtbo" ] && [ ! -f "/lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko" ] ; then - install_module "./" "seeed-voicecard" - cp seeed-2mic-voicecard.dtbo /boot/overlays - cp seeed-4mic-voicecard.dtbo /boot/overlays - install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so -else - echo "card driver already installed" -fi +install_module "./" "seeed-voicecard" + + +# install dtbos +cp seeed-2mic-voicecard.dtbo /boot/overlays +cp seeed-4mic-voicecard.dtbo /boot/overlays + +#install alsa plugins +install -D ac108_plugin/libasound_module_pcm_ac108.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so + +#set kernel moduels grep -q "snd-soc-ac108" /etc/modules || \ echo "snd-soc-ac108" >> /etc/modules grep -q "snd-soc-wm8960" /etc/modules || \ echo "snd-soc-wm8960" >> /etc/modules - +#set dtoverlays +sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/config.txt || true grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \ echo "dtoverlay=i2s-mmap" >> /boot/config.txt @@ -73,36 +72,15 @@ grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \ grep -q "dtparam=i2s=on" /boot/config.txt || \ echo "dtparam=i2s=on" >> /boot/config.txt -has_2mic=$(grep seeed-2mic-voicecard /boot/config.txt) -has_4mic=$(grep seeed-4mic-voicecard /boot/config.txt) -case "${card}" in - "2mic") - echo "cp wm8960_asound.state /var/lib/alsa/asound.state" - cp wm8960_asound.state /var/lib/alsa/asound.state - cp asound_2mic.conf /etc/asound.conf - if [ "x${has_4mic}" != x ] ; then - echo "has 4mic before, now remove it" - sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt - fi - grep -q "dtoverlay=seeed-2mic-voicecard" /boot/config.txt || \ - echo "dtoverlay=seeed-2mic-voicecard" >> /boot/config.txt - - ;; - "4mic") - echo "cp ac108_asound.state /var/lib/alsa/asound.state" - cp ac108_asound.state /var/lib/alsa/asound.state - cp asound_4mic.conf /etc/asound.conf - if [ "x${has_2mic}" != x ] ; then - echo "has 2mic before, now remove it" - sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt - fi - grep -q "dtoverlay=seeed-4mic-voicecard" /boot/config.txt || \ - echo "dtoverlay=seeed-4mic-voicecard" >> /boot/config.txt - ;; - *) - echo "Please use 2mic or 4mic" - ;; -esac +#install config files +mkdir /etc/voicecard || true +cp *.conf /etc/voicecard +cp *.state /etc/voicecard + + +cp seeed-voicecard /usr/bin/ +cp seeed-voicecard.service /lib/systemd/system/ +systemctl enable seeed-voicecard.service echo "------------------------------------------------------" echo "Please reboot your raspberry pi to apply all settings" diff --git a/uninstall.sh b/uninstall.sh index 1dc401c..3746923 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -12,81 +12,29 @@ if [ "x${is_Raspberry}" != "xRaspberry" ] ; then fi uname_r=$(uname -r) -card=$1 -if [ x${card} = "x" ] ; then - echo "Usage: ./uninstall 2mic|4mic" - exit 1 -fi -if [ x${card} = "x2mic" ] ; then - echo "delete dtoverlay=seeed-2mic-voicecard in /boot/config.txt" - sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt - if [ -f /boot/overlays/seeed-2mic-voicecard.dtbo ] ; then - echo "remove seeed-2mic-voicecard.dtbo in /boot/overlays" - rm /boot/overlays/seeed-2mic-voicecard.dtbo - fi - if [ -f /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko ] ; then - echo "remove snd-soc-wm8960.ko" - rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko - fi +echo "remove dtbos" +rm /boot/overlays/seeed-2mic-voicecard.dtbo || true +rm /boot/overlays/seeed-4mic-voicecard.dtbo || true +rm /boot/overlays/seeed-6mic-voicecard.dtbo || true - if [ -d /var/lib/dkms/seeed-voicecard ] ; then - echo "remove seeed-voicecard dkms" - rm -rf /var/lib/dkms/seeed-voicecard - fi +echo "remove alsa configs" +rm -rf /etc/voicecard/ || true - echo "delete snd-soc-wm8960 in /etc/modules" - sed -i "s/snd-soc-wm8960//g" /etc/modules +echo "disabled seeed-voicecard.service " +systemctl disable seeed-voicecard.service - if [ -f /var/lib/alsa/asound.state ] ; then - echo "remove wm8960_asound.state" - rm /var/lib/alsa/asound.state - fi +echo "remove seeed-vocecard" +rm /usr/bin/seeed-voicecard || true +rm /lib/systemd/system/seeed-voicecard.service || true - if [ -f /etc/asound.conf ] ; then - echo "remove asound_2mic.conf" - rm /etc/asound.conf - fi -fi +echo "remove dkms" +rm -rf /var/lib/dkms/seeed-voicecard || true -if [ x${card} = "x4mic" ] ; then - echo "delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt" - sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt - - if [ -f /boot/overlays/seeed-4mic-voicecard.dtbo ] ; then - echo "remove seeed-4mic-voicecard.dtbo in /boot/overlays" - rm /boot/overlays/seeed-4mic-voicecard.dtbo - fi - - if [ -f /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko ] ; then - echo "remove snd-soc-ac108.ko" - rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko - fi - - if [ -d /var/lib/dkms/seeed-voicecard ] ; then - echo "remove seeed-voicecard dkms" - rm -rf /var/lib/dkms/seeed-voicecard - fi - - echo "delete snd-soc-ac108 in /etc/modules" - sed -i "s/snd-soc-ac108//g" /etc/modules - - if [ -f /var/lib/alsa/asound.state ] ; then - echo "remove ac108_asound.state" - rm /var/lib/alsa/asound.state - fi - - if [ -f /etc/asound.conf ] ; then - echo "remove asound_4mic.conf" - rm /etc/asound.conf - fi - - if [ -f /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so ] ; then - echo "remove libasound_module_pcm_ac108.so in /usr/lib/arm-linux-gnueabihf/alsa-lib/ " - rm /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_ac108.so - fi -fi +echo "remove kernel modules" +rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-wm8960.ko || true +rm /lib/modules/${uname_r}/kernel/sound/soc/codecs/snd-soc-ac108.ko || true echo "------------------------------------------------------" echo "Please reboot your raspberry pi to apply all settings" From 73ff8fe11433b1bb6ed7c156109dd9fa3fe2d9f1 Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 16:07:02 +0800 Subject: [PATCH 3/6] add seeed-voicecard manger service --- seeed-voicecard | 84 +++++++++++++++++++++++++++++++++++++++++ seeed-voicecard.service | 12 ++++++ 2 files changed, 96 insertions(+) create mode 100755 seeed-voicecard create mode 100644 seeed-voicecard.service diff --git a/seeed-voicecard b/seeed-voicecard new file mode 100755 index 0000000..8f5c4f8 --- /dev/null +++ b/seeed-voicecard @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Copyright (c) 2018 Baozhu Zuo +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +is_1a=$(i2cdetect -y 1 0x1a 0x1a | grep 1a | awk '{print $2}') +is_35=$(i2cdetect -y 1 0x35 0x35 | grep 35 | awk '{print $2}') +is_3b=$(i2cdetect -y 1 0x3b 0x3b | grep 3b | awk '{print $2}') + +if [ "x${is_1a}" == "x1a" ] && [ "x${is_35}" == "x" ] ; then + echo "install 2mic" + dtoverlay seeed-2mic-voicecard + sleep 1 + hw=$(aplay -l | grep seeed2micvoicec | awk '{print $2}' | sed 's/://') + + cp /etc/voicecard/asound_2mic.conf /etc/asound.conf + + echo "get old hw number" + old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g') + + echo "replace new hw:${hw},0" + sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf + + cp /etc/voicecard/wm8960_asound.state /var/lib/alsa/asound.state +fi + +if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x" ] ; then + echo "install 4mic" + dtoverlay seeed-4mic-voicecard + sleep 1 + hw=$(arecord -l | grep seeed4micvoicec | awk '{print $2}' | sed 's/://') + + cp /etc/voicecard/asound_4mic.conf /etc/asound.conf + + echo "get slavepcm line number" + line=$(grep -n slavepcm /etc/asound.conf | awk '{print $1}' | sed 's/://') + + echo "delete ${line} slavepcm hw number" + sed -i -e "${line}d" /etc/asound.conf + + echo "inset slavepcm hw:${hw},0" + sed -i "${line}i slavepcm \"hw:${hw},0\"" /etc/asound.conf + + cp /etc/voicecard/ac108_asound.state /var/lib/alsa/asound.state +fi + +if [ "x${is_3b}" == "x3b" ] && [ "x${is_35}" == "x35" ] ; then + echo "install 6mic" + dtoverlay seeed-8mic-voicecard + sleep 1 + hw=$(aplay -l | grep seeed8micvoicec | awk '{print $2}' | sed 's/://') + + cp /etc/voicecard/asound_6mic.conf /etc/asound.conf + + old=$(cat /etc/asound.conf | grep hw: | awk 'NR==1 {print $2}' | sed 's/\"//g') + + sed -i -e "s/${old}/hw:${hw},0/g" /etc/asound.conf + + cp /etc/voicecard/ac101-ok-20180119.state /var/lib/alsa/asound.state +fi + +alsactl restore + +#Fore 3.5mm ('headphone') jack +amixer cset numid=3 1 + + diff --git a/seeed-voicecard.service b/seeed-voicecard.service new file mode 100644 index 0000000..298fac6 --- /dev/null +++ b/seeed-voicecard.service @@ -0,0 +1,12 @@ +[Unit] +Description=Seeed Voicecard service +After=alsa-restore.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/seeed-voicecard +User=root + +[Install] +WantedBy=sysinit.target From f49d8966130c41334f8294601d83f6a82714d458 Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 16:07:26 +0800 Subject: [PATCH 4/6] update readme add dkms version --- README.md | 42 ++++++++++++++---------------------------- dkms.conf | 2 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 599ffa3..147de9e 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,21 @@ The drivers of [ReSpeaker Mic Hat](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html) and [ReSpeaker 4 Mic Array](https://www.seeedstudio.com/ReSpeaker-4-Mic-Array-for-Raspberry-Pi-p-2941.html) for Raspberry Pi. +### Install seeed-voicecard +Get the seeed voice card source code. and install all linux kernel drivers +```bash +git clone https://github.com/respeaker/seeed-voicecard +cd seeed-voicecard +sudo ./install.sh +sudo reboot +``` + ## ReSpeaker Mic Hat [![](https://github.com/SeeedDocument/MIC_HATv1.0_for_raspberrypi/blob/master/img/mic_hatv1.0.png?raw=true)](https://www.seeedstudio.com/ReSpeaker-2-Mics-Pi-HAT-p-2874.html) - While the upstream wm8960 codec is not currently supported by current Pi kernel builds, upstream wm8960 has some bugs, we had fixed it. we must it build manually. -Get the seeed voice card source code. -```bash -git clone https://github.com/respeaker/seeed-voicecard -cd seeed-voicecard -#for ReSpeaker 2-mic -sudo ./install.sh 2mic -sudo reboot -``` - Check that the sound card name matches the source code seeed-voicecard. ```bash @@ -49,6 +48,9 @@ card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hif Subdevice #0: subdevice #0 pi@raspberrypi:~/seeed-voicecard $ ``` +If you want to change the alsa settings, You can use `sudo alsactl --file=/etc/voicecard/wm8960_asound.state store` to save it. + + #### Next step Go to https://github.com/respeaker/mic_hat to build voice enabled projects with Google Assistant SDK or Alexa Voice Service. @@ -59,15 +61,6 @@ Go to https://github.com/respeaker/mic_hat to build voice enabled projects with The 4 Mic Array uses ac108 which includes 4 ADCs, we also write ac108 rapberry pi linux kernel driver. -```bash -git clone https://github.com/respeaker/seeed-voicecard -cd seeed-voicecard -sudo ./install.sh 4mic - -#reboot your Raspbian OS -sudo reboot -``` - Check that the sound card name matches the source code seeed-voicecard. ```bash @@ -100,7 +93,7 @@ plughw:CARD=seeed4micvoicec,DEV=0 Hardware device with all software conversions pi@raspberrypi:~ $ ``` -If you want to change the alsa settings, You can use `sudo alsactl --file=asound.state store` to save it. +If you want to change the alsa settings, You can use `sudo alsactl --file=/etc/voicecard/ac108_asound.state store` to save it. Test: ```bash @@ -118,7 +111,7 @@ arecord -Dac108 -f S32_LE -r 16000 -c 4 a.wav If you want to upgrade the driver , you need uninstall the driver first. ``` -pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh 4mic +pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt delete snd-soc-ac108 in /etc/modules ------------------------------------------------------ @@ -136,14 +129,7 @@ Thank you! ------------------------------------------------------ ``` -### with Google Assistant -if you run the assistant but the playback is speed up considerably, try to configure alsa: -```bash -sudo cp asound.conf /etc/asound.conf -``` - -If the alsa configuration doesn't solve the issue, try to use pulseaudio. See [#4](https://github.com/respeaker/seeed-voicecard/issues/4) Enjoy ! diff --git a/dkms.conf b/dkms.conf index 5904bf6..da7ace9 100644 --- a/dkms.conf +++ b/dkms.conf @@ -1,5 +1,5 @@ PACKAGE_NAME="seeed-voicecard" -PACKAGE_VERSION="0.2" +PACKAGE_VERSION="0.3" BUILT_MODULE_NAME[0]="snd-soc-wm8960" BUILT_MODULE_NAME[1]="snd-soc-ac108" DEST_MODULE_LOCATION[0]="/kernel/sound/soc/codecs" From 3a0a0e8b57409a71ff088195c5cce5a88a79fe41 Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 16:42:49 +0800 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 147de9e..abe1d7f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ pi@raspberrypi:~ $ ``` If you want to change the alsa settings, You can use `sudo alsactl --file=/etc/voicecard/ac108_asound.state store` to save it. -Test: +#### Test: ```bash #for ReSpeaker 2-mic #It will capture sound an playback on hw:1 From 3fdc0c4345d930e9a85aa6b7d1d95c155cac4db2 Mon Sep 17 00:00:00 2001 From: Baozhu Zuo Date: Thu, 1 Feb 2018 16:52:35 +0800 Subject: [PATCH 6/6] Update README.md --- README.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index abe1d7f..20a6144 100644 --- a/README.md +++ b/README.md @@ -112,17 +112,7 @@ If you want to upgrade the driver , you need uninstall the driver first. ``` pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh -delete dtoverlay=seeed-4mic-voicecard in /boot/config.txt -delete snd-soc-ac108 in /etc/modules ------------------------------------------------------- -Please reboot your raspberry pi to apply all settings -Thank you! ------------------------------------------------------- -pi@raspberrypi:~/seeed-voicecard $ sudo ./uninstall.sh 2mic -delete dtoverlay=seeed-2mic-voicecard in /boot/config.txt -remove seeed-2mic-voicecard.dtbo in /boot/overlays -remove snd-soc-wm8960.ko -delete snd-soc-wm8960 in /etc/modules +... ------------------------------------------------------ Please reboot your raspberry pi to apply all settings Thank you!