본문 바로가기
Development/Free Topic

Raspberry Pi Realtime Audio Processing

by IMCOMKING 2020. 6. 14.


RtAudio

완전히 C++기반으로 구현된 오디오 라이브러리.


설치방법 on Raspberry Pi

sudo apt-get install autoconf libtool automake
sudo apt install libasound2 libasound2-dev
git clone https://github.com/thestk/rtaudio.git
./autogen.sh
make

설치확인

(* 라즈베리파이의 jack에 스피커를 연결하고, USB mic를 연결한다.)
cd rtaudio/tests
./audioprobe     --> input device id와 output device id확인

./testall

./duplex 1 44100 [input device id] [output device id]



Extreme Latency Improving

불필요한 service제거, 오버클럭, headless RPi, On-board audio, USB audio interface





PortAudio

설치방법 on Raspberry Pi

라즈베리파이에 설치하기 위해서는 반드시 직접 빌드를 해야한다. 그리고 OSS보다는 ALSA를 backend API로 쓰는게 좋다고한다.
(The OSS sound API is very old and not well supported. It is recommended that you use the ALSA sound API)

소스부터 직접 빌드하기

sudo apt-get install libasound2-dev
wget http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz
tar -xvzf pa_stable_v190600_20161030.tgz
cd portaudio
./configure --with-alsa
make
sudo make install
sudo ldconfig

(정상 설치 확인: device list보기)
cd bin
./pa_devs


기존에 설치된 portaudio 삭제하기

sudo apt autoremove libportaudio2
(만약 소스부터 직접 빌드했다면)
cd portaudio
sudo make clean
sudo make uninstall
sudo make -n uninstall
sudo make -B uninstall


라즈베리파이 오디오 세팅하기


ALSA 정상 동작 확인하기: 원본

sudo apt-get install alsa-utils
sudo apt-get install lame
sudo apt-get install mpg321


sudo modprobe snd-bcm2835
(To check if the driver is loaded you can type:)

sudo lsmod | grep 2835
(Select the output device for sound (0=auto, 1=analog, 2=HDMI):)

sudo amixer cset numid=2

* Test the installation:

aplay /usr/share/sounds/alsa/Front_Center.wav
speaker-test -t sine -f 440 -c 2 -s 1
mpg321 “Mannish Boy.mp3”

* It you get the following error message:
-> ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front

Edit the file /usr/share/alsa/alsa.conf:
sudo vim /usr/share/alsa/alsa.conf
change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”

* If you are using HDMI and cannot hear any audio at all change the following PI configuration setting:

edit the RasPI configuration file:
sudo vim /boot/config.txt
uncomment the line:
hdmi_drive=2

save the file and reboot the PI
Resources:

http://jeffskinnerbox.wordpress.com/2012/11/15/getting-audio-out-working-on-the-raspberry-pi/
http://elinux.org/R-Pi_Troubleshooting









JACK




PyAudio

git clone https://people.csail.mit.edu/hubert/git/pyaudio.git

http://people.csail.mit.edu/hubert/pyaudio/

* rpi에 pyaudio구현 사례: https://github.com/CharlieHouse/RPi_SISO_ANC/blob/master/python_tonal_anc.py



댓글