Skip to contentSkip to conversation

audio surveilance

RFC In review John Sauter 2 participants 4 messages Jan 2, 2010 – Jan 8, 2010

lore
Share & tools
lore
#0 lore raw

RFC 1/1 audio surveilance

When doing audio surveillance, you want to record all the sound, but occasionally close the old output file and open a new one, so you can listen to a captured event without disturbing the recording of future sounds. I have some ideas for additions to aplay to meet the needs of audio surveillance, and would appreciate feedback from the alsa developers. My proposed patches are attached. They have been tested only on GNU/Linux 64-bit.
John Sauter ([email protected])

From c44e75708b045131967ab8b1dc78917b5e87f412 Mon Sep 17 00:00:00 2001
From: John Sauter <[email protected]>
Date: Fri, 1 Jan 2010 16:36:22 -0500
Subject: [PATCH - aplay extensions for audio surveilance 1/1] aplay - add features for audio surveilance.

When doing audio surveilance, you want to record
all the sound, but occasionally close the old
output file and open a new one, so you can listen
to a captured event without disturbing the
recording of future sounds. I have added three
new options and a new signal to facilitate this:

--max-file-time specifies the maximum time to
record in a file before closing it and opening
a new one.

--process-id-file specifies the file into which to write the process ID, so a controlling program can send signals to aplay.

Signal SIGUSR1 causes aplay to close the current
output file and open a new one.

--use-strftime causes the file name parameter to
be passed through strftime each time a file is
opened. The important strftime codes for this
application are as follows: %Y is the year,
%m is the month, %d is the day of the month,
%H is the hour, %M the minute, %S the second.
In addition, %v is the file number. Using
strftime replaces the default file naming
mechanism, which places the file number after
the file name, if there is more than one
output file. Using strftime also causes
intermediate directories to be created for
the output files. This allows for names like
sounds/%Y/%m/%d/%Y-%m-%d--%H_%M_%S.wav.

I have updated the manual file to include
all the old options and signals in addition to
those listed above.

---
 aplay/aplay.1 |   91 ++++++++++++++++--
 aplay/aplay.c |  308 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 367 insertions(+), 32 deletions(-)
aplay/aplay.1 +84 -7
index 7759347..b6caf0b 100644
@@ -1,4 +1,4 @@
-.TH APLAY 1 "2 August 2001"
+.TH APLAY 1 "1 January 2010"
 .SH NAME
 arecord, aplay \- command-line sound recorder and player for ALSA 
 soundcard driver
@@ -46,6 +46,7 @@ If this parameter is omitted the WAVE format is used.
 \fI\-c, \-\-channels=#\fP
 The number of channels.
 The default is one channel.
+Valid values are 1 through 32.
 .TP
 \fI\-f \-\-format=FORMAT\fP
 Sample format
@@ -53,19 +54,23 @@ Sample format
 Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE
 S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE
 FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW
-A_LAW IMA_ADPCM MPEG GSM
+A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE
+S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE
 .br
 Some of these may not be available on selected hardware
 .br
-There are also two format shortcuts available:
+The available format shortcuts are:
 .nf
-\-f cd (16 bit little endian, 44100, stereo [\-f S16_LE \-c2 \-r44100]
+\-f cd (16 bit little endian, 44100, stereo) [\-f S16_LE \-c2 \-r44100]
+\-f cdr (16 bit big endian, 44100, stereo) [\-f S16_BE \-c2 \-f44100]
 \-f dat (16 bit little endian, 48000, stereo) [\-f S16_LE \-c2 \-r48000]
 .fi
 If no format is given U8 is used.
 .TP
 \fI\-r, \-\-rate=#<Hz>\fP
 Sampling rate in Hertz. The default rate is 8000 Hertz.
+If the value specified is less than 300, it is taken as the rate in kilohertz.
+Valid values are 2000 through 192000 Hertz.
 .TP
 \fI\-d, \-\-duration=#\fP
 Interrupt after # seconds.
@@ -120,10 +125,69 @@ The stereo VU-meter is available only for 2-channel stereo samples
 with interleaved format.
 .TP
 \fI\-I, \-\-separate\-channels\fP 
-One file for each channel
+One file for each channel.  This option disables max\-file\-time
+and use\-strftime, and ignores SIGUSR1.  The stereo VU meter is
+not available with separate channels.
+.TP
+\fI\-P\fP
+Playback.  This is the default if the program is invoked
+by typing aplay.
+.TP
+\fI\-C\fP
+Record.  This is the default if the program is invoked
+by typing arecord.
+.TP
+\fI\-\-disable\-resample\fP
+Disable automatic rate resample.
+.TP
+\fI\-\-disable\-channels\fP
+Disable automatic channel conversions.
+.TP
+\fI\-\-disable\-format\fP
+Disable automatic format conversions.
+.TP
+\fI\-\-disable\-softvol\fP
+Disable software volume control (softvol).
+.TP
+\fI\-\-test\-position\fP
+Test ring buffer position.
+.TP
+\fI\-\-test\-coef=<coef>\fP
+Test coefficient for ring buffer position; default is 8.
+Expression for validation is: coef * (buffer_size / 2).
+Minimum value is 1.
+.TP
+\fI\-\-test\-nowait\fP
+Do not wait for the ring buffer--eats the whole CPU.
+.TP
+\fI\-\-max\-file\-time\fP
+While recording, when the output file has been accumulating
+sound for this long,
+close it and open a new output file.  Default is the maximum
+size supported by the file format: 2 GiB for WAV files.
+This option has no effect if  \-\-separate\-channels is
+specified.
+.TP
+\fI\-\-process\-id\-file <file name>\fP
+aplay writes its process ID here, so other programs can
+send signals to it.
+.TP
+\fI\-\-use\-strftime\fP
+When recording, interpret %-codes in the file name parameter using
+the strftime facility whenever the output file is opened.  The
+important strftime codes are: %Y is the year, %m month, %d day of
+the month, %H hour, %M minute and %S second.  In addition, %v is
+the file number, starting at 1.  When this option is specified,
+intermediate directories for the output file are created automatically.
+This option has no effect if \-\-separate\-channels is specified.
 
-.SS
-Example:
+.SH SIGNALS
+When recording, SIGINT, SIGTERM and SIGABRT will close the output 
+file and exit.  SIGUSR1 will close the output file, open a new one,
+and continue recording.  However, SIGUSR1 does not work with
+\-\-separate\-channels.
+
+.SH EXAMPLES
 
 .TP
 \fBaplay \-c 1 \-t raw \-r 22050 \-f mu_law foobar\fR
@@ -144,6 +208,19 @@ pcm.copy {
 }
 .fi
 
+.TP
+\fBarecord \-t wav \-max-file_time 30 mon.wav\fP
+Record from the default audio source in monaural, 8,000 samples
+per second, 8 bits per sample.  Start a new file every
+30 seconds.  File names are mon-nn.wav, where nn increases
+from 01.  The file after mon-99.wav is mon-100.wav.
+
+.TP
+\fBarecord \-f cd \-t wav \-max-file-time 3600 --use-strftime %Y/%m/%d/listen-%H-%M-%v.wav\fP
+Record in stereo from the default audio source.  Create a new file
+every hour.  The files are placed in directories based on their start dates
+and have names which include their start times and file numbers.
+
 .SH SEE ALSO
 \fB
 alsamixer(1),
aplay/aplay.c +283 -25

793 lines not on this page · raw message

Signature · 1 line
1.6.3.3

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#1 lore raw

Mr. Kysela,

I have some patches to aplay to make it more useful for audio surveillance. I have submitted the patches to the devel mailing list for comment here:
<http://mailman.alsa-project.org/pipermail/alsa-devel/2010-January/024278.html>.

I have received no negative comments, so I would like to propose these patches for inclusion in mainline. What is the procedure for submitting patches for alsa-util?
John Sauter ([email protected])

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw
Quoted 10 lines · John Sauter

Mr. Kysela,

I have some patches to aplay to make it more useful for audio surveillance. I have submitted the patches to the devel mailing list for comment here:
<http://mailman.alsa-project.org/pipermail/alsa-devel/2010-January/024278.html>.

I have received no negative comments, so I would like to propose these patches for inclusion in mainline. What is the procedure for submitting patches for alsa-util?

Could you, please, a bit clean up your patch?

- There are a lot of "if (pidfile_written) remove (pidfile_name)" lines. It would be better to create another function like prg_exit() and add this code there.

- Many C expressions are not splitted to more lines:
"if (max_file_size && (rest > max_file_size)) rest = max_file_size;"

- Check all conditions. Use && and || operators instead bit-like AND (&) and OR (|). Like "if (filecount | use_strftime) {" etc.

- I would also appreciate, if you can split '--process-id-file' code changes and rest of implementation to two standalone patches for more easier review. Also, your patch contains some "space/tab replacements" - it might be moved to another patch too.

Thanks,
Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

#3 lore raw
Quoted 31 lines · Jaroslav Kysela
Quoted 10 lines · John Sauter

Mr. Kysela,

I have some patches to aplay to make it more useful for audio surveillance. I have submitted the patches to the devel mailing list for comment here:
<http://mailman.alsa-project.org/pipermail/alsa-devel/2010-January/024278.html>.

I have received no negative comments, so I would like to propose these patches for inclusion in mainline. What is the procedure for submitting patches for alsa-util?

Could you, please, a bit clean up your patch?

- There are a lot of "if (pidfile_written) remove (pidfile_name)" lines. It would be better to create another function like prg_exit() and add this code there.

- Many C expressions are not splitted to more lines:

   "if (max_file_size && (rest > max_file_size)) rest = max_file_size;"

- Check all conditions. Use && and || operators instead bit-like AND (&) and OR (|). Like "if (filecount | use_strftime) {" etc.

- I would also appreciate, if you can split '--process-id-file' code changes and rest of implementation to two standalone patches for more easier review. Also, your patch contains some "space/tab replacements" - it might be moved to another patch too.

Review

Quoted 2 lines
(quoted diff) +0 -0
 					Thanks,
 						Jaroslav

Thank you, Jaroslav. I will make those changes and re-submit.
John Sauter ([email protected])

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel