Skip to content

Commit

Permalink
Add an aubiolevel CLI tool to compute the sound pressure level
Browse files Browse the repository at this point in the history
Aubio enables users to compute the sound pressure level of a buffer
using miscutils.h, but there is no way to get that information from CLI
tools right now.

This adds support for a standalone CLI tool so that extracting sound
pressure level information does not require building a program against
the library.
  • Loading branch information
delthas committed Oct 15, 2022
1 parent 8a05420 commit 3e19f91
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Additional command line tools are included along with the library:
- `aubioonset` outputs the time stamp of detected note onsets
- `aubiopitch` attempts to identify a fundamental frequency, or pitch, for
each frame of the input sound
- `aubiolevel` outputs audio sound pressure level (volume) information, for
each frame of the input sound
- `aubiomfcc` computes Mel-frequency Cepstrum Coefficients
- `aubiotrack` outputs the time stamp of detected beats
- `aubionotes` emits midi-like notes, with an onset, a pitch, and a duration
Expand Down
1 change: 1 addition & 0 deletions doc/aubiocut.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SEE ALSO

aubioonset(1),
aubiopitch(1),
aubiolevel(1),
aubiotrack(1),
aubionotes(1),
aubioquiet(1),
Expand Down
64 changes: 64 additions & 0 deletions doc/aubiolevel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
NAME
aubiolevel - a command line tool to extract audio sound pressure level

SYNOPSIS

aubiolevel source
aubiolevel [[-i] source]
[-r rate] [-B win] [-H hop]
[-T time-format]
[-v] [-h]

DESCRIPTION

aubiolevel outputs audio sound pressure level information.

The sound pressure level is printed on the console, prefixed by a timestamp
in seconds. The level is in dB SPL, which is ten times the log10 of the
average of the square amplitudes.

The sound pressure level is either a negative number, or negative infinity
(printed as -inf) when there is no sound.

OPTIONS

This program follows the usual GNU command line syntax, with long options
starting with two dashes (--). A summary of options is included below.

-i, --input source Run analysis on this audio file. Most uncompressed and
compressed are supported, depending on how aubio was built.

-r, --samplerate rate Fetch the input source, resampled at the given
sampling rate. The rate should be specified in Hertz as an integer. If 0,
the sampling rate of the original source will be used. Defaults to 0.

-B, --bufsize win The size of the buffer to analyze, that is the length
of the window used for spectral and temporal computations. Defaults to 2048.

-H, --hopsize hop The number of samples between two consecutive analysis.
Defaults to 256.

-T, --timeformat format Set time format (samples, ms, seconds). Defaults to
seconds.

-h, --help Print a short help message and exit.

-v, --verbose Be verbose.

SEE ALSO

aubiopitch(1),
aubioonset(1),
aubiotrack(1),
aubionotes(1),
aubioquiet(1),
aubiomfcc(1),
and
aubiocut(1).

AUTHOR

This manual page was written by Paul Brossier <[email protected]>. Permission is
granted to copy, distribute and/or modify this document under the terms of
the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
1 change: 1 addition & 0 deletions doc/aubiomfcc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SEE ALSO

aubioonset(1),
aubiopitch(1),
aubiolevel(1),
aubiotrack(1),
aubionotes(1),
aubioquiet(1),
Expand Down
1 change: 1 addition & 0 deletions doc/aubionotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ SEE ALSO

aubioonset(1),
aubiopitch(1),
aubiolevel(1),
aubiotrack(1),
aubioquiet(1),
aubiomfcc(1),
Expand Down
1 change: 1 addition & 0 deletions doc/aubioonset.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ ONSET METHODS
SEE ALSO

aubiopitch(1),
aubiolevel(1),
aubiotrack(1),
aubionotes(1),
aubioquiet(1),
Expand Down
1 change: 1 addition & 0 deletions doc/aubiopitch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ PITCH METHODS
SEE ALSO

aubioonset(1),
aubiolevel(1),
aubiotrack(1),
aubionotes(1),
aubioquiet(1),
Expand Down
1 change: 1 addition & 0 deletions doc/aubioquiet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SEE ALSO

aubioonset(1),
aubiopitch(1),
aubiolevel(1),
aubiotrack(1),
aubionotes(1),
aubiomfcc(1),
Expand Down
1 change: 1 addition & 0 deletions doc/aubiotrack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ SEE ALSO

aubioonset(1),
aubiopitch(1),
aubiolevel(1),
aubionotes(1),
aubioquiet(1),
aubiomfcc(1),
Expand Down
8 changes: 8 additions & 0 deletions doc/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ More command line tools are included along with the library.
- ``aubioonset`` outputs the time stamp of detected note onsets
- ``aubiopitch`` attempts to identify a fundamental frequency, or pitch, for
each frame of the input sound
- ``aubiolevel`` outputs audio sound pressure level (volume) information, for
each frame of the input sound
- ``aubiomfcc`` computes Mel-frequency Cepstrum Coefficients
- ``aubiotrack`` outputs the time stamp of detected beats
- ``aubionotes`` emits midi-like notes, with an onset, a pitch, and a duration
Expand Down Expand Up @@ -45,6 +47,12 @@ More command line tools are included along with the library.
.. literalinclude:: aubiopitch.txt
:language: text

``aubiolevel``
--------------

.. literalinclude:: aubiolevel.txt
:language: text

``aubiomfcc``
--------------

Expand Down
46 changes: 23 additions & 23 deletions doc/cli_features.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
Command line features
---------------------

+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| feat vs. prg | onset | pitch | mfcc | track | notes | quiet | cut1 | short options |
+==============+=======+=======+======+=======+=======+=======+======+==================+
| input | Y | Y | Y | Y | Y | Y | Y | -i |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| output | Y | Y | N | Y | Y | N | Y!1 | -o,-m,-f |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| Hz/buf/hop | Y | Y | Y | Y | Y | Y!2 | Y | -r,-B-,H |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| jack | Y | Y | N | Y | Y | N!3 | N | -j |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| onset | Y | N | N | Y!8 | Y!6 | N | Y | -O,-t,-M |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| pitch | N | Y | N | N | Y!6 | N | N!5 | -p,-u,-l |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| silence | Y | Y | N | Y | Y!7 | Y | N!4 | -s |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| timefmt | Y | Y | Y | Y | Y | Y | ! | -T |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| help | Y | Y | Y | Y | Y | Y | Y | -h |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
| verbose | Y | Y | Y | Y | Y | Y | Y | -v |
+--------------+-------+-------+------+-------+-------+-------+------+------------------+
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| feat vs. prg | onset | pitch | level | mfcc | track | notes | quiet | cut1 | short options |
+==============+=======+=======+=======+======+=======+=======+=======+======+==================+
| input | Y | Y | Y | Y | Y | Y | Y | Y | -i |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| output | Y | Y | N | N | Y | Y | N | Y!1 | -o,-m,-f |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| Hz/buf/hop | Y | Y | Y | Y | Y | Y | Y!2 | Y | -r,-B,-H |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| jack | Y | Y | N | N | Y | Y | N!3 | N | -j |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| onset | Y | N | N | N | Y!8 | Y!6 | N | Y | -O,-t,-M |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| pitch | N | Y | N | N | N | Y!6 | N | N!5 | -p,-u,-l |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| silence | Y | Y | N | N | Y | Y!7 | Y | N!4 | -s |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| timefmt | Y | Y | Y | Y | Y | Y | Y | ! | -T |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| help | Y | Y | Y | Y | Y | Y | Y | Y | -h |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+
| verbose | Y | Y | Y | Y | Y | Y | Y | Y | -v |
+--------------+-------+-------+-------+------+-------+-------+-------+------+------------------+

1. ``aubiocut --output`` is used to specify a directory, not a file.

Expand Down
54 changes: 54 additions & 0 deletions examples/aubiolevel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright (C) 2022 Paul Brossier <[email protected]>
This file is part of aubio.
aubio is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
aubio is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with aubio. If not, see <http://www.gnu.org/licenses/>.
*/

#include "utils.h"
#include "parse_args.h"

smpl_t level;

void process_block(fvec_t * ibuf, fvec_t * obuf)
{
level = aubio_db_spl (ibuf);
}

void process_print (void)
{
print_time(blocks * hop_size);
outmsg(" %f\n", level);
}

int main(int argc, char **argv) {
int ret = 0;

buffer_size = 2048;

examples_common_init(argc,argv);

verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);

verbmsg ("buffer_size: %d, ", buffer_size);
verbmsg ("hop_size: %d, ", hop_size);

examples_common_process(process_block, process_print);

beach:
examples_common_del();
return ret;
}

0 comments on commit 3e19f91

Please sign in to comment.