diff mbox

[FFmpeg-devel] libavfilter/af_ambisonic.c Added File for Ambisonic Filter

Message ID CAMmhPEAwXuNEm5inG5O_Jme36LOCii0yWMQsFytxBR-NM0FLXA@mail.gmail.com
State Superseded
Headers show

Commit Message

Sanchit Sinha March 13, 2017, 3:12 a.m. UTC
On Mon, Mar 13, 2017 at 2:36 AM, Paul B Mahol <onemda@gmail.com> wrote:

> On 3/12/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> > Any changes required in this one?
>
> Please do not top post.
>
> Expect vertical alignment, no changes are needed.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Comments

Paul B Mahol March 13, 2017, 8:50 a.m. UTC | #1
On 3/13/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> On Mon, Mar 13, 2017 at 2:36 AM, Paul B Mahol <onemda@gmail.com> wrote:
>
>> On 3/12/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
>> > Any changes required in this one?
>>
>> Please do not top post.
>>
>> Expect vertical alignment, no changes are needed.

When you introduced tabs? That is unacceptable.
Please take look at other filters. Can you atleast try to mimic their style?
Sanchit Sinha March 13, 2017, 9:15 a.m. UTC | #2
Sir, I cannot find any tabs in the code. Can you point out where exactly?
Thank You


On Mon, Mar 13, 2017 at 2:20 PM, Paul B Mahol <onemda@gmail.com> wrote:

> On 3/13/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> > On Mon, Mar 13, 2017 at 2:36 AM, Paul B Mahol <onemda@gmail.com> wrote:
> >
> >> On 3/12/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> >> > Any changes required in this one?
> >>
> >> Please do not top post.
> >>
> >> Expect vertical alignment, no changes are needed.
>
> When you introduced tabs? That is unacceptable.
> Please take look at other filters. Can you atleast try to mimic their
> style?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Paul B Mahol March 13, 2017, 12:50 p.m. UTC | #3
On 3/13/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> Sir, I cannot find any tabs in the code. Can you point out where exactly?
> Thank You
>

Do not top post.

Yes, tabe are not present in latest patch, but overal style can still
much improve.
Just read other filters code and see their style.

What text editor are you using? Please use monospace font.

>
> On Mon, Mar 13, 2017 at 2:20 PM, Paul B Mahol <onemda@gmail.com> wrote:
>
>> On 3/13/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
>> > On Mon, Mar 13, 2017 at 2:36 AM, Paul B Mahol <onemda@gmail.com> wrote:
>> >
>> >> On 3/12/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
>> >> > Any changes required in this one?
>> >>
>> >> Please do not top post.
>> >>
>> >> Expect vertical alignment, no changes are needed.
>>
>> When you introduced tabs? That is unacceptable.
>> Please take look at other filters. Can you atleast try to mimic their
>> style?
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
>
> --
> Sanchit Sinha
> B.Tech- CSE
> IIIT-Delhi
> Roll-2015083
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Rostislav Pehlivanov March 18, 2017, 7:45 a.m. UTC | #4
> static const AVOption ambisonic_options[] = {
> {NULL}
> };

You're missing spaces on the second line here.

> if ((ret = ff_add_format     (&formats, AV_SAMPLE_FMT_FLTP   )) < 0 ||
> (ret = ff_set_common_formats     (ctx    , formats )) < 0 ||
> (ret = ff_add_channel_layout     (&layout , AV_CH_LAYOUT_4POINT0)) < 0 ||
> (ret = ff_set_common_channel_layouts (ctx    , layout   )) < 0)
> return ret;

No indentation.

> AVFilter ff_af_ambisonic = {
> .name      = "ambisonic",
> .description    = NULL_IF_CONFIG_SMALL("An ambisonic filter"),
> .query_formats  = query_formats,
> .priv_size    = sizeof(AmbisonicContext),
> .priv_class  = &ambisonic_class,
> .inputs  = inputs,
> .outputs    = outputs,
> };

Align such that all equal signs are in the same column, look at how other
filters do it.



On 13 March 2017 at 03:12, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:

> On Mon, Mar 13, 2017 at 2:36 AM, Paul B Mahol <onemda@gmail.com> wrote:
>
> > On 3/12/17, Sanchit Sinha <sanchit15083@iiitd.ac.in> wrote:
> > > Any changes required in this one?
> >
> > Please do not top post.
> >
> > Expect vertical alignment, no changes are needed.
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
>
>
> --
> Sanchit Sinha
> B.Tech- CSE
> IIIT-Delhi
> Roll-2015083
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
Carl Eugen Hoyos March 20, 2017, 8:46 a.m. UTC | #5
2017-03-13 10:15 GMT+01:00 Sanchit Sinha <sanchit15083@iiitd.ac.in>:
> Sir, I cannot find any tabs in the code.

For the future:
There is a script in tools/patcheck that helps you with some basic
issues.

Carl Eugen
diff mbox

Patch

From dbfed83e1f6ed215025878e3e0e27b55f86bb29c Mon Sep 17 00:00:00 2001
From: Sanchit Sinha <sanchit15083@iiitd.ac.in>
Date: Mon, 13 Mar 2017 08:39:43 +0530
Subject: [PATCH] lavf/af_ambisonic.c added lavf/Makefile and allfilters.c
 updated changelog update

Signed-off-by: Sanchit Sinha <sanchit15083@iiitd.ac.in>
---
 Changelog                  |   1 +
 libavfilter/Makefile       |   1 +
 libavfilter/af_ambisonic.c | 122 +++++++++++++++++++++++++++++++++++++++++++++
 libavfilter/allfilters.c   |   1 +
 4 files changed, 125 insertions(+)
 create mode 100644 libavfilter/af_ambisonic.c

diff --git a/Changelog b/Changelog
index 13628ca..b917ac2 100644
--- a/Changelog
+++ b/Changelog
@@ -26,6 +26,7 @@  version <next>:
 - native Opus encoder
 - ScreenPressor decoder
 - incomplete ClearVideo decoder
+- Ambisonic Decoder
 
 version 3.2:
 - libopenmpt demuxer
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0ba1c74..4ebbd5a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -44,6 +44,7 @@  OBJS-$(CONFIG_AINTERLEAVE_FILTER)            += f_interleave.o
 OBJS-$(CONFIG_ALIMITER_FILTER)               += af_alimiter.o
 OBJS-$(CONFIG_ALLPASS_FILTER)                += af_biquads.o
 OBJS-$(CONFIG_ALOOP_FILTER)                  += f_loop.o
+OBJS-$(CONFIG_AMBISONIC_FILTER)              += af_ambisonic.o
 OBJS-$(CONFIG_AMERGE_FILTER)                 += af_amerge.o
 OBJS-$(CONFIG_AMETADATA_FILTER)              += f_metadata.o
 OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
diff --git a/libavfilter/af_ambisonic.c b/libavfilter/af_ambisonic.c
new file mode 100644
index 0000000..59c99f3
--- /dev/null
+++ b/libavfilter/af_ambisonic.c
@@ -0,0 +1,122 @@ 
+/*
+ * Copyright (c) 2017 Sanchit Sinha
+ * Copyright (c) 2017 Paul B Mahol
+ * 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 <stdio.h>
+#include "libavutil/avstring.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "formats.h"
+#include <math.h>
+
+typedef struct AmbisonicContext {
+    const AVClass *class;
+} AmbisonicContext;
+
+static const AVOption ambisonic_options[] = {
+{NULL}
+};
+
+AVFILTER_DEFINE_CLASS(ambisonic);
+
+static int query_formats(AVFilterContext *ctx)
+{
+    AVFilterFormats *formats = NULL;
+    AVFilterChannelLayouts *layout = NULL;
+    int ret;
+
+    if ((ret = ff_add_format     (&formats, AV_SAMPLE_FMT_FLTP   )) < 0 ||
+    (ret = ff_set_common_formats     (ctx    , formats )) < 0 ||
+    (ret = ff_add_channel_layout     (&layout , AV_CH_LAYOUT_4POINT0)) < 0 ||
+    (ret = ff_set_common_channel_layouts (ctx    , layout   )) < 0)
+    return ret;
+
+    formats = ff_all_samplerates();
+    return ff_set_common_samplerates(ctx, formats);
+}
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *out;
+    int itr;
+    float *w,*x,*y,*c1,*c2,*c3,*c4;
+    float root8 = sqrt(8);
+    float lf=0,lb=0,rb=0,rf=0;
+
+    if (av_frame_is_writable(in)) {
+        out = in;
+    } else {
+        out = ff_get_audio_buffer(inlink, in->nb_samples);
+        if (!out){
+            av_frame_free(&in);
+            return AVERROR(ENOMEM);
+        }
+        av_frame_copy_props(out, in);
+    }
+
+    w=(float *)in->extended_data[0];
+    x=(float *)in->extended_data[1];
+    y=(float *)in->extended_data[2];
+    c1=(float *)out->extended_data[0];
+    c2=(float *)out->extended_data[1];
+    c3=(float *)out->extended_data[2];
+    c4=(float *)out->extended_data[3];
+
+    for(itr=0;itr<in->nb_samples;itr++){
+        lf = root8 * (2*(w[itr])+x[itr]+y[itr]);
+        lb = root8 * (2*(w[itr])-x[itr]+y[itr]);
+        rb = root8 * (2*(w[itr])-x[itr]-y[itr]);
+        rf = root8 * (2*(w[itr])+x[itr]-y[itr]);
+        c1[itr] = lf;
+        c2[itr] = rf;
+        c3[itr] = lb;
+        c4[itr] = rb;
+    }
+
+    if (out != in)
+        av_frame_free(&in);
+    return ff_filter_frame(outlink, out);
+}
+static const AVFilterPad inputs[] = {
+    {
+        .name    = "default",
+        .type    = AVMEDIA_TYPE_AUDIO,
+        .filter_frame = filter_frame,
+    },
+    { NULL }
+};
+static const AVFilterPad outputs[] = {
+    {
+        .name = "default",
+        .type = AVMEDIA_TYPE_AUDIO,
+    },
+    { NULL }
+};
+AVFilter ff_af_ambisonic = {
+    .name      = "ambisonic",
+    .description    = NULL_IF_CONFIG_SMALL("An ambisonic filter"),
+    .query_formats  = query_formats,
+    .priv_size    = sizeof(AmbisonicContext),
+    .priv_class  = &ambisonic_class,
+    .inputs  = inputs,
+    .outputs    = outputs,
+};
\ No newline at end of file
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index df1af8d..59aeb6d 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -56,6 +56,7 @@  static void register_all(void)
     REGISTER_FILTER(ALIMITER,       alimiter,       af);
     REGISTER_FILTER(ALLPASS,        allpass,        af);
     REGISTER_FILTER(ALOOP,          aloop,          af);
+    REGISTER_FILTER(AMBISONIC,      ambisonic,      af);
     REGISTER_FILTER(AMERGE,         amerge,         af);
     REGISTER_FILTER(AMETADATA,      ametadata,      af);
     REGISTER_FILTER(AMIX,           amix,           af);
-- 
2.7.4