-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathffmpeg2grapheqd.sh
More file actions
executable file
·62 lines (52 loc) · 1.33 KB
/
Copy pathffmpeg2grapheqd.sh
File metadata and controls
executable file
·62 lines (52 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
export PATH=/usr/local/sbin:/usr/local/bin:$PATH
# grapheqd's raw "protocol" (little endian):
# c -> s: 'r'
# s -> c:
# # of channels (2 bytes)
# sampling rate (4 bytes)
# ...pcm data...
MYNAME=`basename "$0"`
SOUNDCARD="$1"
STDERR="$2"
sendpcm () {
cmd=`dd bs=1 count=1 status=none`
[ -z "$cmd" ] && exit
if [ "$cmd" != "r" ]; then
logmsg "Unsupported command: $cmd"
exit
fi
mixersettings=`mixer -o`
mixer pcm2.recsrc=set >/dev/null
rate=""
channels=""
ac="2"
probe=`ffprobe -hide_banner "$SOUNDCARD" 2>&1`
echo "$probe" | grep -q "44100 Hz" && rate='\104\254\0\0'
echo "$probe" | grep -q "48000 Hz" && rate='\200\273\0\0'
echo "$probe" | grep -q "mono" && ac="1"
if [ "$ac" = "1" ]; then
channels='\1\0'
elif [ "$ac" = "2" ]; then
channels='\2\0'
fi
if [ -n "$rate" -a -n "$ac" -a -n "$channels" ]; then
printf "${channels}${rate}"
ffmpeg -nostdin -abort_on empty_output -loglevel quiet -i "$SOUNDCARD" \
-ac "$ac" -c:a pcm_s16le -f s16le -
else
logmsg "Unsupported rate and/or channels: $probe"
fi
mixer $mixersettings >/dev/null
}
if [ -n "$STDERR" -a "$STDERR" = "stderr" ]; then
logmsg () {
echo "${MYNAME}[$$]: $@" >&2
}
sendpcm
else
logmsg () {
logger -i -p daemon.info -t "$MYNAME" "$@" >/dev/null
}
sendpcm 2>/dev/null
fi