Re: [FFmpeg-devel] [PATCH 2/2] opusenc: (WIP) add a new psychoacoustic system for the native Opus encoder

2017-09-23 Thread Rostislav Pehlivanov
On 23 September 2017 at 03:08, Ricardo Constantino 
wrote:

> On 23 September 2017 at 00:46, Rostislav Pehlivanov 
> wrote:
>
> > On 12 April 2017 at 23:26, Rostislav Pehlivanov 
> > wrote:
> >
> > >
> > >
> > Here's the latest version, which I consider to be non-WIP now.
> > I plan to push it tomorrow morning if there are no objections.
> >
>
> This commit implement a psychoacoustic system for the native Opus
>
> implements*
>
> > encoder. Its unlike any other psychoacoustic system known since its
> >
> It's unlike any other psychoacoustic system known, since it's
>
> > capable of using a lookahead to make better choices on how to treat the
> > current frame and how many bits to allocate for it (and future frames).
> > Also, whilst the main bulk of the analysis function has to run in a
> > single thread, the per-frame anaylsis functions do not modify the main
> >
> analysis*; does not*
>
> > psychoacoustic context, so in the future it will be fairly trivial to
> > run those as slice threads.
>
>
>
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


Pushed with your suggestions, thanks
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] opusenc: (WIP) add a new psychoacoustic system for the native Opus encoder

2017-09-22 Thread Ricardo Constantino
On 23 September 2017 at 00:46, Rostislav Pehlivanov 
wrote:

> On 12 April 2017 at 23:26, Rostislav Pehlivanov 
> wrote:
>
> >
> >
> Here's the latest version, which I consider to be non-WIP now.
> I plan to push it tomorrow morning if there are no objections.
>

This commit implement a psychoacoustic system for the native Opus

implements*

> encoder. Its unlike any other psychoacoustic system known since its
>
It's unlike any other psychoacoustic system known, since it's

> capable of using a lookahead to make better choices on how to treat the
> current frame and how many bits to allocate for it (and future frames).
> Also, whilst the main bulk of the analysis function has to run in a
> single thread, the per-frame anaylsis functions do not modify the main
>
analysis*; does not*

> psychoacoustic context, so in the future it will be fairly trivial to
> run those as slice threads.



> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] opusenc: (WIP) add a new psychoacoustic system for the native Opus encoder

2017-09-22 Thread Rostislav Pehlivanov
On 12 April 2017 at 23:26, Rostislav Pehlivanov  wrote:

>
>
Here's the latest version, which I consider to be non-WIP now.
I plan to push it tomorrow morning if there are no objections.
From 62dcd1e7e4db391c30c3893fde82bc205ebb7bfe Mon Sep 17 00:00:00 2001
From: Rostislav Pehlivanov 
Date: Sat, 23 Sep 2017 00:38:37 +0100
Subject: [PATCH] opusenc: implement a psychoacoustic system

This commit implement a psychoacoustic system for the native Opus
encoder. Its unlike any other psychoacoustic system known since its
capable of using a lookahead to make better choices on how to treat the
current frame and how many bits to allocate for it (and future frames).

Also, whilst the main bulk of the analysis function has to run in a
single thread, the per-frame anaylsis functions do not modify the main
psychoacoustic context, so in the future it will be fairly trivial to
run those as slice threads.

Signed-off-by: Rostislav Pehlivanov 
---
 libavcodec/Makefile|   3 +-
 libavcodec/opus_celt.h |   6 +
 libavcodec/opusenc.c   | 270 --
 libavcodec/opusenc.h   |  56 +
 libavcodec/opusenc_psy.c   | 556 +
 libavcodec/opusenc_psy.h   | 104 +
 libavcodec/opusenc_utils.h |  82 +++
 7 files changed, 951 insertions(+), 126 deletions(-)
 create mode 100644 libavcodec/opusenc.h
 create mode 100644 libavcodec/opusenc_psy.c
 create mode 100644 libavcodec/opusenc_psy.h
 create mode 100644 libavcodec/opusenc_utils.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b0c39ac040..ff862f2c81 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -454,7 +454,8 @@ OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o
 OBJS-$(CONFIG_ON2AVC_DECODER)  += on2avc.o on2avcdata.o
 OBJS-$(CONFIG_OPUS_DECODER)+= opusdec.o opus.o opus_celt.o opus_rc.o \
   opus_pvq.o opus_silk.o opustab.o vorbis_data.o
-OBJS-$(CONFIG_OPUS_ENCODER)+= opusenc.o opus_rc.o opustab.o opus_pvq.o
+OBJS-$(CONFIG_OPUS_ENCODER)+= opusenc.o opus_rc.o opustab.o opus_pvq.o \
+  opusenc_psy.o
 OBJS-$(CONFIG_PAF_AUDIO_DECODER)   += pafaudio.o
 OBJS-$(CONFIG_PAF_VIDEO_DECODER)   += pafvideo.o
 OBJS-$(CONFIG_PAM_DECODER) += pnmdec.o pnm.o
diff --git a/libavcodec/opus_celt.h b/libavcodec/opus_celt.h
index 31299912bd..45d50ab27b 100644
--- a/libavcodec/opus_celt.h
+++ b/libavcodec/opus_celt.h
@@ -120,6 +120,12 @@ struct CeltFrame {
 uint32_t seed;
 enum CeltSpread spread;
 
+/* Encoder PF coeffs */
+int pf_octave;
+int pf_period;
+int pf_tapset;
+float pf_gain;
+
 /* Bit allocation */
 int framebits;
 int remaining;
diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index 8f2da4a7ba..79d20dc6e6 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -19,8 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "opus_celt.h"
+#include "opusenc.h"
 #include "opus_pvq.h"
+#include "opusenc_psy.h"
 #include "opustab.h"
 
 #include "libavutil/float_dsp.h"
@@ -29,28 +30,10 @@
 #include "bytestream.h"
 #include "audio_frame_queue.h"
 
-/* Determines the maximum delay the psychoacoustic system will use for lookahead */
-#define FF_BUFQUEUE_SIZE 145
-#include "libavfilter/bufferqueue.h"
-
-#define OPUS_MAX_LOOKAHEAD ((FF_BUFQUEUE_SIZE - 1)*2.5f)
-
-#define OPUS_MAX_CHANNELS 2
-
-/* 120 ms / 2.5 ms = 48 frames (extremely improbable, but the encoder'll work) */
-#define OPUS_MAX_FRAMES_PER_PACKET 48
-
-#define OPUS_BLOCK_SIZE(x) (2 * 15 * (1 << ((x) + 2)))
-
-#define OPUS_SAMPLES_TO_BLOCK_SIZE(x) (ff_log2((x) / (2 * 15)) - 2)
-
-typedef struct OpusEncOptions {
-float max_delay_ms;
-} OpusEncOptions;
-
 typedef struct OpusEncContext {
 AVClass *av_class;
 OpusEncOptions options;
+OpusPsyContext psyctx;
 AVCodecContext *avctx;
 AudioFrameQueue afq;
 AVFloatDSPContext *dsp;
@@ -58,10 +41,10 @@ typedef struct OpusEncContext {
 CeltPVQ *pvq;
 struct FFBufQueue bufqueue;
 
-enum OpusMode mode;
-enum OpusBandwidth bandwidth;
-int pkt_framesize;
-int pkt_frames;
+uint8_t enc_id[64];
+int enc_id_bits;
+
+OpusPacketInfo packet;
 
 int channels;
 
@@ -100,18 +83,18 @@ static int opus_gen_toc(OpusEncContext *s, uint8_t *toc, int *size, int *fsize_n
 { {  3,  7, 11,  0,  0 }, {  0,  0,  0,  0,  0 }, {  0,  0,  0,  0,  0 } }, /*  40 ms */
 { {  4,  8, 12,  0,  0 }, {  0,  0,  0,  0,  0 }, {  0,  0,  0,  0,  0 } }, /*  60 ms */
 };
-int cfg = toc_cfg[s->pkt_framesize][s->mode][s->bandwidth];
+int cfg = toc_cfg[s->packet.framesize][s->packet.mode][s->packet.bandwidth];
 *fsize_needed = 0;
 if (!cfg)
 return 1;
-if (s->pkt_frames == 2) {