BPI-M1 MIC
thank chaos.dennis do this test:
i write about this, because i found very few sources and had to tumble a lot around to get it working. This is a quick walk through to give you a hint where to start. I asume for simplicity that you stay always in /root directory as root user. If something fails, look if the files are written and paths are right. It is adressed for more advanced users who know what they are basically doing.
This is done with bananian 15.08 on Kernel 3.4. Other kernels < 4.4 do not work. It is a headless server with no HDMI pluged in.
A. Basic Setup
- Install alsa (renove pulseaudio if present):
# apt-get install alsa-base alsa-utils
- Configure asound.conf
# nano /etc/asound.conf
- Should look like:pcm.!default {type hwcard 0 # for headphone, turn 1 to 0device 0}ctl.!default {type hwcard 0 # for headphone, turn 1 to 0}
- Shutdown, make a cold boot
- Call the alsamixer
# alsamixer
Press F5. Your channels should be setup like the attached file at the bottom of this post, or compare it to amixer output:# amixerSimple mixer control 'Master',0Capabilities: pvolume pvolume-joinedPlayback channels: MonoLimits: Playback 0 - 63Mono: Playback 45 [71%]Simple mixer control 'Master Capture Mute',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [off]Simple mixer control 'LineL',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'LineR',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Linein Pre-AMP',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 7 [100%]Simple mixer control 'Mic Input Mux',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 15Mono: 15 [100%]Simple mixer control 'Mic Power',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Mic1 Boost',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Mic1 gain',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 3Mono: 3 [100%]Simple mixer control 'Mic2 Boost',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Mic2 gain',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 0 [0%]Simple mixer control 'MicL',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 3Mono: 1 [33%]Simple mixer control 'MicR',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 3Mono: 3 [100%]Simple mixer control 'Playback',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Capture',0Capabilities: cvolume cvolume-joinedCapture channels: MonoLimits: Capture 0 - 7Mono: Capture 7 [100%]Simple mixer control 'ADC Input Mux',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 7 [100%]Simple mixer control 'Fm output',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 7 [100%]Simple mixer control 'FmL',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'FmR',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'LINEIN APM',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 7 [100%]Simple mixer control 'Ldac Left Mixer',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Ldac Right Mixer',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Left Capture Mute',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'MIC output volume',0Capabilities: volume volume-joinedPlayback channels: MonoCapture channels: MonoLimits: 0 - 7Mono: 7 [100%]Simple mixer control 'Rdac Right Mixer',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]Simple mixer control 'Right Capture Mute',0Capabilities: pswitch pswitch-joinedPlayback channels: MonoMono: Playback [on]This step is critical. One false muted channel and you are out of the game. - Test recording.
# arecord -L
Should show a device.# arecord -f S16_LE -r 44100 -t wav test.wav
Should make kind of Sound. Stop it with ctr-c and check the file.
B. SoX Recording / Streaming
- Install SoX
# apt-get install sox libsox-fmt-all
Sox gives you tools like: sox, rec and play. I would suggest you install it on the client pc too. - Record striaght to mp3# rec -c 2 -C 64 test.mp3-c 2 two channels-C 64 tell the encoder to produce a 64kbit/s mp3Stop it with ctr-c, check the output.
- Listen to it live over LANBanana:
# rec -c 2 -C 64 -t mp3 - | netcat -l -p 9000
-t mp3 - produce mp3 stream to stdoutClient:# netcat <banana ip> 9000 | vlc
Works? Great! Live listening is important to play around and test the mic. - Listen and record at same time
# rec -c 2 -C 64 -t mp3 - | tee test.mp3 | netcat -l -p 9000
- Poor man's streaming server# apt-get install openbsd-inetd tcpdEdit config file:# nano /etc/inetd.confInsert this at the end:9000 stream tcp nowait nobody /usr/bin/tail tail -f /test.mp3Restart service# service openbsd-inetd restartStart recording on banana:# rec -c 2 -C 64 /test.mp3Connect via client:# netcat <banana ip> 9000 | vlc -
C. Advanced Recording
- Devide recording and postprocessing in two parts# rec -t raw - remix - | sox -t raw -r 48000 -c 1 -b 16 -e signed-integer - -t mp3 -c 1 -C 32 test.mp3
Recording:
-t raw - forward raw input to pipe
remix - Mix the two channels to one
Encoding:
-t raw -r 48000 -c 1 -b 16 -e signed-integer - tell sox what kind of strean comes from stdin
-t mp3 -c 1 -C 32 test.mp3 and what goes out
Note that it is switched to mono from here with -c 1 and the mp3 bitrate is cut in half. Live listening to the strean does not work anymore, i asume it is because of the non regulare output from pipeing and processing in a second step.
- Reduce noiseThe mic input is pretty bad, lot of white noise. Sox can deal with it.Make a sample "silent" file:# rec -t raw test.raw remix - trim 0 10trim 0 10 record 10 secondsTest it at client pc:# play -r 48000 -c 1 -b 16 -e signed-integer test.rawCreate profile file:# sox -r 48000 -c 1 -b 16 -e signed-integer test.raw -n trim 0 2 noiseprof raw-profileRecord with noise canceld# rec -t raw - remix - noisered raw-profile 0.2 | sox -t raw -r 48000 -c 1 -b 16 -e signed-integer - -t mp3 -c 1 -C 32 test.mp3Play with the factor of 0.2 to regulate the intensity of cancellation.
D. Record 24/7
My goal of this....
Create a script:
# nano /root/record.sh
Insert the following:
#!/bin/bash
# send sigterm and wait for exit of the process
function stop() { kill [email protected]; while kill -0 [email protected]; do sleep 1; done; }
function log() { echo $(date +%T) [email protected]; }
log "Stopping previus recording"
stop `pidof rec` &> /dev/null
DATE=`date "+%Y.%m.%d"`
log "Recording $DATE.mp3"
rec -q -t raw - remix - noisered /root/raw-profile 0.2 | \
sox -v 2.0 -t raw -r 48000 -c 1 -b 16 -e signed-integer - \
-t mp3 -r 22050 -c 1 -C -9.2 /root/$DATE.mp3
log "Done $DATE.mp3"
Recording:
-q less output
Encoding: -v 2.0 Make the input stream louder
-r 22050 encode to a lower sample rate
-C -9.2 Create a low quality VBR mp3
Fileszie ~100mb per day. If you want smaller files, a 8000 sanple rate gives you a gsm grade quality.
Make it executable
# chmod +x record.sh
Edit crontab:
# env EDITOR=nano crontab -e
Insert at the end the following:
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin
0 0 * * * /root/record.sh >> /root/record-mic.log
A new recording should start every day at midnight.

Last modified 3yr ago