From patchwork Fri Mar 10 18:47:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchit Sinha X-Patchwork-Id: 2870 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp190817vsy; Fri, 10 Mar 2017 10:55:48 -0800 (PST) X-Received: by 10.223.128.231 with SMTP id 94mr16384445wrl.165.1489172148243; Fri, 10 Mar 2017 10:55:48 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k20si302707wmc.118.2017.03.10.10.55.47; Fri, 10 Mar 2017 10:55:48 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@iiitd.ac.in; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 15D576882EC; Fri, 10 Mar 2017 20:55:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 517D96882CF for ; Fri, 10 Mar 2017 20:55:23 +0200 (EET) Received: by mail-wm0-f65.google.com with SMTP id v190so429131wme.3 for ; Fri, 10 Mar 2017 10:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; h=mime-version:from:date:message-id:subject:to; bh=v15Jv3CmPxqOnjlM0PtIxAaIorUAl6vUrFqu5eWbREs=; b=hdfcQtkmXGujAv4AxmrmfaCeTD5/isL99+5XdFLN9j3JE6aH1cUH+VzbSPEQDNHBU/ RBiJhk6jEO68ZREHW/OtmTW2rWcCvyhHzF6Sbgpf7tHXzoig4ws93xuAH5o/hwIcdBtY 5A2iVMReNYUD7U7e8aWKj6lddthg+qeGUzmbw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=v15Jv3CmPxqOnjlM0PtIxAaIorUAl6vUrFqu5eWbREs=; b=JFn+zUZYDYe52To6pkAd4NiYUI4uL8AvZMdZEnTLzfjo6H+Ql1seYpLYts8zKFG6s6 V3b+t96hFivI3OAJTrL26Tr2ogRlqoVvF7qZDjmW4UbUl2WSNR+gA10yxrWILo/uBnTv oq97x66g7V2fiHMZVaJ1d/uHdjOpCnkTHK9qLN37DHh5vn+5oxwn8Kor9HoRQRd2bMM7 zdg2UNsEvcsJftvisxDqi8MrcqPybEu8CpHle0ivfPShL6yUMEy48L4OOq0zXtVXiBUl OqRp4fViw/Fa1CaJYslvUx5Hh6sPgRaHrTr7AfzgmcTS/OkYwPMsmcIHaptTfCFl0kdv Sfbw== X-Gm-Message-State: AFeK/H38z7p3UHwM/uXX9dJsFVpvQFtKmBIQ5JK4trjSuZGtZsN3JUGethyB+tsEfS6K/bfDXpsOukyWYDCw/ake X-Received: by 10.28.148.143 with SMTP id w137mr373927wmd.72.1489171669296; Fri, 10 Mar 2017 10:47:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.139.131 with HTTP; Fri, 10 Mar 2017 10:47:48 -0800 (PST) From: Sanchit Sinha Date: Sat, 11 Mar 2017 00:17:48 +0530 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] libavfilter/af_ambisonic.c Added File for Ambisonic 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" libavfilter/af_ambisonic.c | 139 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 libavfilter/af_ambisonic.c + .query_formats = query_formats, + .priv_size = sizeof(AmbisonicContext), + .priv_class = &ambisonic_class, + // .uninit = uninit, + .inputs = inputs, + .outputs = outputs, +}; \ No newline at end of file diff --git a/libavfilter/af_ambisonic.c b/libavfilter/af_ambisonic.c new file mode 100644 index 0000000..98b0e44 --- /dev/null +++ b/libavfilter/af_ambisonic.c @@ -0,0 +1,139 @@ +/* + * 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/avstring.h" +#include "libavutil/channel_layout.h" +#include "libavutil/opt.h" +#include "audio.h" +#include "avfilter.h" +#include "formats.h" + +#define root8 2.828 + +typedef struct AmbisonicContext { + const AVClass *class; + /*Not needed, if any new variables are to be used, this struct can be populated*/ + +} AmbisonicContext; + +#define OFFSET(x) offsetof(AmbisonicContext, x) //Future use(maybe) + +static const AVOption ambisonic_options[] = { //square will be an option +{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]; + /*If variables used, this has to be created*/ + // AmbisonicContext *s = ctx->priv; + // const float *src = (const float *)in->data[0]; + // float *dst; + float *lf,*lb,*rb,*rf; + AVFrame *out; + int itr; + float *w,*x,*y; + + 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); + } + + /*If planar samples are used, output must be put in dst*/ + //dst = (float *)out->data[0]; + + lf = (float *)malloc(sizeof(float)); + lb = (float *)malloc(sizeof(float)); + rb = (float *)malloc(sizeof(float)); + rf = (float *)malloc(sizeof(float)); + + for(itr=0;itrnb_samples;itr++) + { + *lf=0,*lb=0,*rb=0,*rf=0; + /*Float pointers to the samples*/ + w=(float *)(*(in->extended_data)+itr); + x=(float *)(*(in->extended_data+1)+itr); + y=(float *)(*(in->extended_data+2)+itr); + + *lf = root8 * (2*(*w)+*x+*y); + *lb = root8 * (2*(*w)-*x+*y); + *rb = root8 * (2*(*w)-*x-*y); + *rf = root8 * (2*(*w)+*x-*y); + + /*Mathematical coefficients taken from : https://en.wikipedia.org/wiki/Ambisonics*/ + out->extended_data[0][itr]= *lf; + out->extended_data[1][itr]= *lb; + out->extended_data[2][itr]= *rb; + out->extended_data[3][itr]= *rf; + } + + 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, + // .config_props = config_input, + }, + { 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"),