Re: [FFmpeg-devel] [PATCHv3] avfilter: add anoisesrc

2015-11-06 Thread Paul B Mahol
On 11/6/15, Kyle Swanson  wrote:
> Here's v3. Uses AV_OPT_TYPE_CONST now. Just sent this with the wrong subject
> line, here it is again. (sorry!)
>
> Signed-off-by: Kyle Swanson 
> ---
>  Changelog|   1 +
>  doc/filters.texi |  36 
>  libavfilter/Makefile |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/asrc_anoisesrc.c | 208
> +++
>  libavfilter/version.h|   4 +-
>  6 files changed, 249 insertions(+), 2 deletions(-)
>  create mode 100644 libavfilter/asrc_anoisesrc.c
>
> diff --git a/Changelog b/Changelog
> index 91955da..ca477de 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -30,6 +30,7 @@ version :
>  - innoHeim/Rsupport Screen Capture Codec decoder
>  - ADPCM AICA decoder
>  - Interplay ACM demuxer and audio decoder
> +- anoisesrc audio source
>
>
>  version 2.8:
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 15ea77a..8287b5e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3193,6 +3193,42 @@ ffplay -f lavfi flite=text='No more be grieved for
> which that thou hast done.'
>  For more information about libflite, check:
>  @url{http://www.speech.cs.cmu.edu/flite/}
>
> +@section anoisesrc
> +
> +Generate a noise audio signal.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +
> +@item color, colour, c
> +Specify the color of noise. Available noise colors are white, pink, and
> brown. Default color is white.
> +
> +@item sample_rate, r
> +Specify the sample rate. Default value is 48000 Hz.
> +
> +@item duration, d
> +Specify the duration of the generated audio stream. Not specifying this
> option results in noise with an infinite length.
> +
> +@item amplitude, a
> +Specify the amplitude (0.0 - 1.0) of the generated audio stream. Default
> value is 1.0.
> +
> +@item seed, s
> +Specify a value used to seed the PRNG.
> +
> +@end table
> +
> +@subsection Examples
> +
> +@itemize
> +
> +@item
> +Generate 60 seconds of pink noise, with a 44.1 kHz sampling rate and an
> amplitude of 0.5:
> +@example
> +anoisesrc=d=60:c=pink:r=44100:a=0.5
> +@end example
> +@end itemize
> +
>  @section sine
>
>  Generate an audio signal made of a sine wave with amplitude 1/8.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 1b23085..560118c 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -91,6 +91,7 @@ OBJS-$(CONFIG_VOLUME_FILTER) +=
> af_volume.o
>  OBJS-$(CONFIG_VOLUMEDETECT_FILTER)   += af_volumedetect.o
>
>  OBJS-$(CONFIG_AEVALSRC_FILTER)   += aeval.o
> +OBJS-$(CONFIG_ANOISESRC_FILTER)  += asrc_anoisesrc.o
>  OBJS-$(CONFIG_ANULLSRC_FILTER)   += asrc_anullsrc.o
>  OBJS-$(CONFIG_FLITE_FILTER)  += asrc_flite.o
>  OBJS-$(CONFIG_SINE_FILTER)   += asrc_sine.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index a538b81..c80ea4c 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -113,6 +113,7 @@ void avfilter_register_all(void)
>  REGISTER_FILTER(VOLUMEDETECT,   volumedetect,   af);
>
>  REGISTER_FILTER(AEVALSRC,   aevalsrc,   asrc);
> +REGISTER_FILTER(ANOISESRC,  anoisesrc,  asrc);
>  REGISTER_FILTER(ANULLSRC,   anullsrc,   asrc);
>  REGISTER_FILTER(FLITE,  flite,  asrc);
>  REGISTER_FILTER(SINE,   sine,   asrc);
> diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
> new file mode 100644
> index 000..9e1ead0
> --- /dev/null
> +++ b/libavfilter/asrc_anoisesrc.c
> @@ -0,0 +1,208 @@
> +/*
> + * Copyright (c) 2015 Kyle Swanson .
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public License
> + * as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg 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 Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include 
> +
> +#include "libavutil/opt.h"
> +#include "audio.h"
> +#include "avfilter.h"
> +#include "internal.h"
> +#include "libavutil/lfg.h"
> +#include "libavutil/random_seed.h"
> +
> +typedef struct {
> +const AVClass *class;
> +int sample_rate;
> +double amplitude;
> +int64_t dur;
> +int64_t color;
> +int64_t seed;
> +
> +int infinite;
> +double (*filter)(double white, double *buf);
> +   

[FFmpeg-devel] [PATCHv3] avfilter: add anoisesrc

2015-11-05 Thread Kyle Swanson
Here's v3. Uses AV_OPT_TYPE_CONST now. Just sent this with the wrong subject 
line, here it is again. (sorry!)

Signed-off-by: Kyle Swanson 
---
 Changelog|   1 +
 doc/filters.texi |  36 
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/asrc_anoisesrc.c | 208 +++
 libavfilter/version.h|   4 +-
 6 files changed, 249 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/asrc_anoisesrc.c

diff --git a/Changelog b/Changelog
index 91955da..ca477de 100644
--- a/Changelog
+++ b/Changelog
@@ -30,6 +30,7 @@ version :
 - innoHeim/Rsupport Screen Capture Codec decoder
 - ADPCM AICA decoder
 - Interplay ACM demuxer and audio decoder
+- anoisesrc audio source
 
 
 version 2.8:
diff --git a/doc/filters.texi b/doc/filters.texi
index 15ea77a..8287b5e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3193,6 +3193,42 @@ ffplay -f lavfi flite=text='No more be grieved for which 
that thou hast done.'
 For more information about libflite, check:
 @url{http://www.speech.cs.cmu.edu/flite/}
 
+@section anoisesrc
+
+Generate a noise audio signal.
+
+The filter accepts the following options:
+
+@table @option
+
+@item color, colour, c
+Specify the color of noise. Available noise colors are white, pink, and brown. 
Default color is white.
+
+@item sample_rate, r
+Specify the sample rate. Default value is 48000 Hz.
+
+@item duration, d
+Specify the duration of the generated audio stream. Not specifying this option 
results in noise with an infinite length.
+
+@item amplitude, a
+Specify the amplitude (0.0 - 1.0) of the generated audio stream. Default value 
is 1.0.
+
+@item seed, s
+Specify a value used to seed the PRNG.
+
+@end table
+
+@subsection Examples
+
+@itemize
+
+@item
+Generate 60 seconds of pink noise, with a 44.1 kHz sampling rate and an 
amplitude of 0.5:
+@example
+anoisesrc=d=60:c=pink:r=44100:a=0.5
+@end example
+@end itemize
+
 @section sine
 
 Generate an audio signal made of a sine wave with amplitude 1/8.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1b23085..560118c 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -91,6 +91,7 @@ OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o
 OBJS-$(CONFIG_VOLUMEDETECT_FILTER)   += af_volumedetect.o
 
 OBJS-$(CONFIG_AEVALSRC_FILTER)   += aeval.o
+OBJS-$(CONFIG_ANOISESRC_FILTER)  += asrc_anoisesrc.o
 OBJS-$(CONFIG_ANULLSRC_FILTER)   += asrc_anullsrc.o
 OBJS-$(CONFIG_FLITE_FILTER)  += asrc_flite.o
 OBJS-$(CONFIG_SINE_FILTER)   += asrc_sine.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index a538b81..c80ea4c 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -113,6 +113,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(VOLUMEDETECT,   volumedetect,   af);
 
 REGISTER_FILTER(AEVALSRC,   aevalsrc,   asrc);
+REGISTER_FILTER(ANOISESRC,  anoisesrc,  asrc);
 REGISTER_FILTER(ANULLSRC,   anullsrc,   asrc);
 REGISTER_FILTER(FLITE,  flite,  asrc);
 REGISTER_FILTER(SINE,   sine,   asrc);
diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
new file mode 100644
index 000..9e1ead0
--- /dev/null
+++ b/libavfilter/asrc_anoisesrc.c
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2015 Kyle Swanson .
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/opt.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "internal.h"
+#include "libavutil/lfg.h"
+#include "libavutil/random_seed.h"
+
+typedef struct {
+const AVClass *class;
+int sample_rate;
+double amplitude;
+int64_t dur;
+int64_t color;
+int64_t seed;
+
+int infinite;
+double (*filter)(double white, double *buf);
+double buf[7];
+AVLFG c;
+} ANoiseSrcContext;
+
+#define OFFSET(x) offsetof(ANoiseSrcContext, x)
+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption anoisesrc_options[] = {
+{ "sample_rate",  "set sample rate",  OFFSET(sample_rate),  
AV_OPT_TYPE_INT,   {.i64 = 48000},