From patchwork Fri Mar 13 13:49:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marshall Murmu X-Patchwork-Id: 18175 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 643E444B381 for ; Fri, 13 Mar 2020 15:51:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F96F68B0BD; Fri, 13 Mar 2020 15:51:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B30D168A9CE for ; Fri, 13 Mar 2020 15:51:26 +0200 (EET) Received: by mail-pj1-f45.google.com with SMTP id bo3so2947291pjb.5 for ; Fri, 13 Mar 2020 06:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=RqQbGMKS7asYpoLC/ai4xVeVFogftRdXLII7dbf85m8=; b=Qigjc2aiw1AsJxELxx5PTSddhXeZVJ5g2l4HOQMgs+MRzu/GSdU3c14XipdIjvbQG7 OgpUbe+JSOC/o9lGX4dpuUGo2k8k5wpukKfqMVT+NMqV8FxA1Mj/ak0rlQTZNMkEH8Ly ZUmTj+XL2btFmtcxpj9mHQIxA/v8Kp6+SyItwqNoudjdfMgbtIJ8LQME4aTSpI8MfJzw BfNqFA2U/Td3zuZg4FVtdzZImdQW/J9TlnXgNOqMTBPszt2wpB3H+v1Bld9dQ06C41KJ O53h1LDjRbyisH00huboa55vA8vnVayB99cZvAw8LiklLuM70L3y68xSMb7WtT7ZWrCV +/GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=RqQbGMKS7asYpoLC/ai4xVeVFogftRdXLII7dbf85m8=; b=AiGjrMFd8tJSFUVmiay7fITKi/4s/2vzx+uIM0bJVoJn/Olr5vwq5CrK2rl4qicq1r 9KF8RP7PD+u/Q8jfeCreP+lv2Odqb+kL9cOV8ep35x2pguGkPtdUcvbjientGEEVTH3W ugpsGSfVmi1J4mFpUMhF75DK0l8RmstoT1UQHuhH8YGC8xqDnjJlNV/Ob1sVc9154v6g CSGvMZ8GrVqkOiJvCK1oHRJAUqEYfZh1MsZs+p8Xdu07s8ftY/7bHD0VcyXhQ9Erz+7M XKKXcgXoxxrUrKdSuiGz1ZSOo+mHZRoVnMrQrtdyntyQRRIrrqanBa/651YBP+8Fx9Ew iYrA== X-Gm-Message-State: ANhLgQ0X8kU0RgmCa7O2od9rsxfPpn3ezNEdIofwzzORI23wLkVYz8j4 oaGDRiq4dEHMpfNN4Y+hxfei1S65 X-Google-Smtp-Source: ADFU+vu2m814EOnQOJD91tUuJT5U/VCzW+67mFNrnfb0bD6upbFB0dLAmULPECyRkITHrMWp3u4yRw== X-Received: by 2002:a17:90a:5d85:: with SMTP id t5mr9916147pji.126.1584107483931; Fri, 13 Mar 2020 06:51:23 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:a80:3964:a4ab:b4cd:d604:c40c]) by smtp.gmail.com with ESMTPSA id i4sm556341pfq.82.2020.03.13.06.51.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 06:51:23 -0700 (PDT) From: Marshall Murmu To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Mar 2020 19:19:12 +0530 Message-Id: <20200313134912.3702-1-marshallmax1991@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2][GSOC] Audio Tones Source Filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Renamed the filter from fluidsynth to atone --- Changelog | 2 +- configure | 2 +- doc/filters.texi | 5 +- libavfilter/Makefile | 2 +- libavfilter/allfilters.c | 2 +- .../{asrc_fluidsynth.c => asrc_atone.c} | 47 +++++++++---------- 6 files changed, 29 insertions(+), 31 deletions(-) rename libavfilter/{asrc_fluidsynth.c => asrc_atone.c} (86%) diff --git a/Changelog b/Changelog index 2a22599969..f9770f8857 100644 --- a/Changelog +++ b/Changelog @@ -46,7 +46,7 @@ version : - High Voltage Software ADPCM decoder - LEGO Racers ALP (.tun & .pcm) demuxer - AMQP 0-9-1 protocol (RabbitMQ) -- fluidsynth filter +- atone filter version 4.2: diff --git a/configure b/configure index b22a09fac1..23c0ea6df3 100755 --- a/configure +++ b/configure @@ -3466,6 +3466,7 @@ asr_filter_deps="pocketsphinx" ass_filter_deps="libass" atempo_filter_deps="avcodec" atempo_filter_select="rdft" +atone_filter_deps="libfluidsynth" avgblur_opencl_filter_deps="opencl" avgblur_vulkan_filter_deps="vulkan libglslang" azmq_filter_deps="libzmq" @@ -3511,7 +3512,6 @@ find_rect_filter_deps="avcodec avformat gpl" firequalizer_filter_deps="avcodec" firequalizer_filter_select="rdft" flite_filter_deps="libflite" -fluidsynth_filter_deps="libfluidsynth" framerate_filter_select="scene_sad" freezedetect_filter_select="scene_sad" frei0r_filter_deps="frei0r libdl" diff --git a/doc/filters.texi b/doc/filters.texi index cdf96d1ba1..92f132ec9a 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -6010,7 +6010,7 @@ ffplay -f lavfi flite=text='No more be grieved for which that thou hast done.' For more information about libflite, check: @url{http://www.festvox.org/flite/} -@section fluidsynth +@section atone Synthesize random notes using libfluidsynth library. @@ -6034,6 +6034,9 @@ Enter the location of the soundfont. Without loading the soundfont fluidsynth wo @item chan Set the MIDI channel. Default value is 0. + +@item seed +Set the seed value for the PRNG @end table @section anoisesrc diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 626d7c0f09..020c4553cb 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -147,8 +147,8 @@ OBJS-$(CONFIG_AEVALSRC_FILTER) += aeval.o OBJS-$(CONFIG_AFIRSRC_FILTER) += asrc_afirsrc.o OBJS-$(CONFIG_ANOISESRC_FILTER) += asrc_anoisesrc.o OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o +OBJS-$(CONFIG_ATONE_FILTER) += asrc_atone.o OBJS-$(CONFIG_FLITE_FILTER) += asrc_flite.o -OBJS-$(CONFIG_FLUIDSYNTH_FILTER) += asrc_fluidsynth.o OBJS-$(CONFIG_HILBERT_FILTER) += asrc_hilbert.o OBJS-$(CONFIG_SINC_FILTER) += asrc_sinc.o OBJS-$(CONFIG_SINE_FILTER) += asrc_sine.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index a1e812093c..d167499cf1 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -141,8 +141,8 @@ extern AVFilter ff_asrc_aevalsrc; extern AVFilter ff_asrc_afirsrc; extern AVFilter ff_asrc_anoisesrc; extern AVFilter ff_asrc_anullsrc; +extern AVFilter ff_asrc_atone; extern AVFilter ff_asrc_flite; -extern AVFilter ff_asrc_fluidsynth; extern AVFilter ff_asrc_hilbert; extern AVFilter ff_asrc_sinc; extern AVFilter ff_asrc_sine; diff --git a/libavfilter/asrc_fluidsynth.c b/libavfilter/asrc_atone.c similarity index 86% rename from libavfilter/asrc_fluidsynth.c rename to libavfilter/asrc_atone.c index be98815c56..f3ebab906e 100644 --- a/libavfilter/asrc_fluidsynth.c +++ b/libavfilter/asrc_atone.c @@ -26,7 +26,7 @@ #include "formats.h" #include "internal.h" -typedef struct FluidSynthContext { +typedef struct AToneContext { const AVClass *class; fluid_settings_t *settings; fluid_synth_t *synth; @@ -37,13 +37,14 @@ typedef struct FluidSynthContext { char *soundfont; int64_t pts; int64_t duration; + int64_t seed; AVLFG c; -} FluidSynthContext; +} AToneContext; -#define OFFSET(x) offsetof(FluidSynthContext, x) +#define OFFSET(x) offsetof(AToneContext, x) #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM -static const AVOption fluidsynth_options[] = { +static const AVOption atone_options[] = { {"sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT_MAX, FLAGS}, {"r", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT_MAX, FLAGS}, {"nb_samples", "set number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT64_MAX, FLAGS}, @@ -52,14 +53,15 @@ static const AVOption fluidsynth_options[] = { {"d", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=10000000}, 0, INT64_MAX, FLAGS}, {"soundfont", "location of soundfont", OFFSET(soundfont), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS}, {"chan", "set MIDI channel", OFFSET(chan), AV_OPT_TYPE_INT, {.str=0}, 0, 15, FLAGS}, + {"seed", "set random seed", OFFSET(seed), AV_OPT_TYPE_INT64, {.i64=-1}, -1, INT64_MAX, FLAGS}, { NULL } }; -AVFILTER_DEFINE_CLASS(fluidsynth); +AVFILTER_DEFINE_CLASS(atone); static av_cold int init(AVFilterContext *ctx) { - FluidSynthContext *fluidsynth = ctx->priv; + AToneContext *fluidsynth = ctx->priv; fluidsynth->soundfont_id = -1; /// Initialize the fluidsynth setting fluidsynth->settings = new_fluid_settings(); @@ -78,26 +80,21 @@ static av_cold int init(AVFilterContext *ctx) if(fluidsynth->soundfont_id < 0) { av_log(ctx, AV_LOG_ERROR, "Failed to load soundfont\n"); } - return 0; } static av_cold void uninit(AVFilterContext *ctx) { - FluidSynthContext *fluidsynth = ctx->priv; - + AToneContext *fluidsynth = ctx->priv; delete_fluid_synth(fluidsynth->synth); delete_fluid_settings(fluidsynth->settings); - } static int query_formats(AVFilterContext *ctx) { - FluidSynthContext *fluidsynth = ctx->priv; - + AToneContext *fluidsynth = ctx->priv; AVFilterChannelLayouts *chanlayout = NULL; int64_t chanlayouts = av_get_default_channel_layout(2*fluid_synth_count_audio_channels(fluidsynth->synth)); - AVFilterFormats *formats = NULL; AVFilterFormats *sample_rate = NULL; int ret; @@ -112,13 +109,14 @@ static int query_formats(AVFilterContext *ctx) return 0; } - static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; - FluidSynthContext *fluidsynth = ctx->priv; + AToneContext *fluidsynth = ctx->priv; - av_lfg_init(&fluidsynth->c, av_get_random_seed()); + if(fluidsynth->seed == -1) + fluidsynth->seed = av_get_random_seed(); + av_lfg_init(&fluidsynth->c, fluidsynth->seed); outlink->sample_rate = fluidsynth->sample_rate; fluidsynth->duration = av_rescale(fluidsynth->duration, fluidsynth->sample_rate, AV_TIME_BASE); @@ -129,7 +127,7 @@ static int config_output(AVFilterLink *outlink) static int request_frame(AVFilterLink *outlink) { AVFrame *frame; - FluidSynthContext *fluidsynth = outlink->src->priv; + AToneContext *fluidsynth = outlink->src->priv; int nb_samples, key; if (fluidsynth->duration) { @@ -143,18 +141,15 @@ static int request_frame(AVFilterLink *outlink) return AVERROR(ENOMEM); key = av_lfg_get(&fluidsynth->c) % 128 ; - fluid_synth_noteon(fluidsynth->synth, fluidsynth->chan, key, 100); fluid_synth_write_float(fluidsynth->synth, nb_samples, frame->data[0], 0, 2, frame->data[0], 1, 2); fluid_synth_noteoff(fluidsynth->synth, fluidsynth->chan, key); - frame->pts = fluidsynth->pts; fluidsynth->pts += nb_samples; - return ff_filter_frame(outlink, frame); } -static const AVFilterPad fluidsynth_outputs[] = { +static const AVFilterPad atone_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, @@ -164,14 +159,14 @@ static const AVFilterPad fluidsynth_outputs[] = { { NULL } }; -AVFilter ff_asrc_fluidsynth = { - .name = "fluidsynth", +AVFilter ff_asrc_atone = { + .name = "atone", .description = NULL_IF_CONFIG_SMALL("Synthesize tones using libfluidsynth."), .query_formats = query_formats, .init = init, .uninit = uninit, - .priv_size = sizeof(FluidSynthContext), + .priv_size = sizeof(AToneContext), .inputs = NULL, - .outputs = fluidsynth_outputs, - .priv_class = &fluidsynth_class, + .outputs = atone_outputs, + .priv_class = &atone_class, };