BPI-R1 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:
    1
    pcm.!default {
    2
    type hw
    3
    card 0 # for headphone, turn 1 to 0
    4
    device 0
    5
    }
    6
    ctl.!default {
    7
    type hw
    8
    card 0 # for headphone, turn 1 to 0
    9
    }
    Copied!
  • 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:
    1
    # amixer
    2
    Simple mixer control 'Master',0
    3
    Capabilities: pvolume pvolume-joined
    4
    Playback channels: Mono
    5
    Limits: Playback 0 - 63
    6
    Mono: Playback 45 [71%]
    7
    Simple mixer control 'Master Capture Mute',0
    8
    Capabilities: pswitch pswitch-joined
    9
    Playback channels: Mono
    10
    Mono: Playback [off]
    11
    Simple mixer control 'LineL',0
    12
    Capabilities: pswitch pswitch-joined
    13
    Playback channels: Mono
    14
    Mono: Playback [on]
    15
    Simple mixer control 'LineR',0
    16
    Capabilities: pswitch pswitch-joined
    17
    Playback channels: Mono
    18
    Mono: Playback [on]
    19
    Simple mixer control 'Linein Pre-AMP',0
    20
    Capabilities: volume volume-joined
    21
    Playback channels: Mono
    22
    Capture channels: Mono
    23
    Limits: 0 - 7
    24
    Mono: 7 [100%]
    25
    Simple mixer control 'Mic Input Mux',0
    26
    Capabilities: volume volume-joined
    27
    Playback channels: Mono
    28
    Capture channels: Mono
    29
    Limits: 0 - 15
    30
    Mono: 15 [100%]
    31
    Simple mixer control 'Mic Power',0
    32
    Capabilities: pswitch pswitch-joined
    33
    Playback channels: Mono
    34
    Mono: Playback [on]
    35
    Simple mixer control 'Mic1 Boost',0
    36
    Capabilities: pswitch pswitch-joined
    37
    Playback channels: Mono
    38
    Mono: Playback [on]
    39
    Simple mixer control 'Mic1 gain',0
    40
    Capabilities: volume volume-joined
    41
    Playback channels: Mono
    42
    Capture channels: Mono
    43
    Limits: 0 - 3
    44
    Mono: 3 [100%]
    45
    Simple mixer control 'Mic2 Boost',0
    46
    Capabilities: pswitch pswitch-joined
    47
    Playback channels: Mono
    48
    Mono: Playback [on]
    49
    Simple mixer control 'Mic2 gain',0
    50
    Capabilities: volume volume-joined
    51
    Playback channels: Mono
    52
    Capture channels: Mono
    53
    Limits: 0 - 7
    54
    Mono: 0 [0%]
    55
    Simple mixer control 'MicL',0
    56
    Capabilities: volume volume-joined
    57
    Playback channels: Mono
    58
    Capture channels: Mono
    59
    Limits: 0 - 3
    60
    Mono: 1 [33%]
    61
    Simple mixer control 'MicR',0
    62
    Capabilities: volume volume-joined
    63
    Playback channels: Mono
    64
    Capture channels: Mono
    65
    Limits: 0 - 3
    66
    Mono: 3 [100%]
    67
    Simple mixer control 'Playback',0
    68
    Capabilities: pswitch pswitch-joined
    69
    Playback channels: Mono
    70
    Mono: Playback [on]
    71
    Simple mixer control 'Capture',0
    72
    Capabilities: cvolume cvolume-joined
    73
    Capture channels: Mono
    74
    Limits: Capture 0 - 7
    75
    Mono: Capture 7 [100%]
    76
    Simple mixer control 'ADC Input Mux',0
    77
    Capabilities: volume volume-joined
    78
    Playback channels: Mono
    79
    Capture channels: Mono
    80
    Limits: 0 - 7
    81
    Mono: 7 [100%]
    82
    Simple mixer control 'Fm output',0
    83
    Capabilities: volume volume-joined
    84
    Playback channels: Mono
    85
    Capture channels: Mono
    86
    Limits: 0 - 7
    87
    Mono: 7 [100%]
    88
    Simple mixer control 'FmL',0
    89
    Capabilities: pswitch pswitch-joined
    90
    Playback channels: Mono
    91
    Mono: Playback [on]
    92
    Simple mixer control 'FmR',0
    93
    Capabilities: pswitch pswitch-joined
    94
    Playback channels: Mono
    95
    Mono: Playback [on]
    96
    Simple mixer control 'LINEIN APM',0
    97
    Capabilities: volume volume-joined
    98
    Playback channels: Mono
    99
    Capture channels: Mono
    100
    Limits: 0 - 7
    101
    Mono: 7 [100%]
    102
    Simple mixer control 'Ldac Left Mixer',0
    103
    Capabilities: pswitch pswitch-joined
    104
    Playback channels: Mono
    105
    Mono: Playback [on]
    106
    Simple mixer control 'Ldac Right Mixer',0
    107
    Capabilities: pswitch pswitch-joined
    108
    Playback channels: Mono
    109
    Mono: Playback [on]
    110
    Simple mixer control 'Left Capture Mute',0
    111
    Capabilities: pswitch pswitch-joined
    112
    Playback channels: Mono
    113
    Mono: Playback [on]
    114
    Simple mixer control 'MIC output volume',0
    115
    Capabilities: volume volume-joined
    116
    Playback channels: Mono
    117
    Capture channels: Mono
    118
    Limits: 0 - 7
    119
    Mono: 7 [100%]
    120
    Simple mixer control 'Rdac Right Mixer',0
    121
    Capabilities: pswitch pswitch-joined
    122
    Playback channels: Mono
    123
    Mono: Playback [on]
    124
    Simple mixer control 'Right Capture Mute',0
    125
    Capabilities: pswitch pswitch-joined
    126
    Playback channels: Mono
    127
    Mono: Playback [on]
    Copied!
    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
    1
    # rec -c 2 -C 64 test.mp3
    Copied!
    -c 2 two channels
    -C 64 tell the encoder to produce a 64kbit/s mp3
    Stop it with ctr-c, check the output.
  • Listen to it live over LAN
    Banana:
    # rec -c 2 -C 64 -t mp3 - | netcat -l -p 9000
    -t mp3 - produce mp3 stream to stdout
    Client:
    # 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
    1
    # apt-get install openbsd-inetd tcpd
    Copied!
    Edit config file:
    1
    # nano /etc/inetd.conf
    Copied!
    Insert this at the end:
    1
    9000 stream tcp nowait nobody /usr/bin/tail tail -f /test.mp3
    Copied!
    Restart service
    1
    # service openbsd-inetd restart
    Copied!
    Start recording on banana:
    1
    # rec -c 2 -C 64 /test.mp3
    Copied!
    Connect via client:
    1
    # netcat <banana ip> 9000 | vlc -
    Copied!
C. Advanced Recording
  • Devide recording and postprocessing in two parts
    1
    # rec -t raw - remix - | sox -t raw -r 48000 -c 1 -b 16 -e signed-integer - -t mp3 -c 1 -C 32 test.mp3
    Copied!
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 noise
    The mic input is pretty bad, lot of white noise. Sox can deal with it.
    Make a sample "silent" file:
    1
    # rec -t raw test.raw remix - trim 0 10
    Copied!
    trim 0 10 record 10 seconds
    Test it at client pc:
    1
    # play -r 48000 -c 1 -b 16 -e signed-integer test.raw
    Copied!
    Create profile file:
    1
    # sox -r 48000 -c 1 -b 16 -e signed-integer test.raw -n trim 0 2 noiseprof raw-profile
    Copied!
    Record with noise canceld
    1
    # 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.mp3
    Copied!
    Play with the factor of 0.2 to regulate the intensity of cancellation.
D. Record 24/7
My goal of this....
Create a script:
1
# nano /root/record.sh
Copied!
Insert the following:
1
#!/bin/bash
2
3
# send sigterm and wait for exit of the process
4
function stop() { kill [email protected]; while kill -0 [email protected]; do sleep 1; done; }
5
function log() { echo $(date +%T) [email protected]; }
6
7
log "Stopping previus recording"
8
stop `pidof rec` &> /dev/null
9
10
DATE=`date "+%Y.%m.%d"`
11
log "Recording $DATE.mp3"
12
rec -q -t raw - remix - noisered /root/raw-profile 0.2 | \
13
sox -v 2.0 -t raw -r 48000 -c 1 -b 16 -e signed-integer - \
14
-t mp3 -r 22050 -c 1 -C -9.2 /root/$DATE.mp3
15
log "Done $DATE.mp3"
Copied!
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.
A very good article to sample rate: http://wiki.audacityteam.org/wiki/Sample_Rates
Make it executable
1
# chmod +x record.sh
Copied!
Edit crontab:
1
# env EDITOR=nano crontab -e
Copied!
Insert at the end the following:
1
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin
2
0 0 * * * /root/record.sh >> /root/re cord-mic.log
Copied!
A new recording should start every day at midnight.
Copy link