FFmpeg
Data Structures | Macros | Functions | Variables
nellymoserenc.c File Reference
#include "libavutil/common.h"
#include "libavutil/float_dsp.h"
#include "libavutil/mathematics.h"
#include "libavutil/thread.h"
#include "audio_frame_queue.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "fft.h"
#include "nellymoser.h"
#include "sinewin.h"
#include "put_bits.h"

Go to the source code of this file.

Data Structures

struct  NellyMoserEncodeContext
 

Macros

#define BITSTREAM_WRITER_LE
 
#define POW_TABLE_SIZE   (1<<11)
 
#define POW_TABLE_OFFSET   3
 
#define OPT_SIZE   ((1<<15) + 3000)
 
#define find_best(val, table, LUT, LUT_add, LUT_size)
 

Functions

static void apply_mdct (NellyMoserEncodeContext *s)
 
static av_cold int encode_end (AVCodecContext *avctx)
 
static av_cold void nellymoser_init_static (void)
 
static av_cold int encode_init (AVCodecContext *avctx)
 
static void get_exponent_greedy (NellyMoserEncodeContext *s, float *cand, int *idx_table)
 
static float distance (float x, float y, int band)
 
static void get_exponent_dynamic (NellyMoserEncodeContext *s, float *cand, int *idx_table)
 
static void encode_block (NellyMoserEncodeContext *s, unsigned char *output, int output_size)
 Encode NELLY_SAMPLES samples. More...
 
static int encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static float pow_table [POW_TABLE_SIZE]
 pow(2, -i / 2048.0 - 3.0); More...
 
static const uint8_t sf_lut [96]
 
static const uint8_t sf_delta_lut [78]
 
static const uint8_t quant_lut [230]
 
static const float quant_lut_mul [7] = { 0.0, 0.0, 2.0, 2.0, 5.0, 12.0, 36.6 }
 
static const float quant_lut_add [7] = { 0.0, 0.0, 2.0, 7.0, 21.0, 56.0, 157.0 }
 
static const uint8_t quant_lut_offset [8] = { 0, 0, 1, 4, 11, 32, 81, 230 }
 
const FFCodec ff_nellymoser_encoder
 

Detailed Description

Nellymoser encoder by Bartlomiej Wolowiec

Generic codec information: libavcodec/nellymoserdec.c

Some information also from: http://samples.mplayerhq.hu/A-codecs/Nelly_Moser/ASAO/ASAO.zip (Copyright Joseph Artsimovich and UAB "DKD")

for more information about nellymoser format, visit: http://wiki.multimedia.cx/index.php?title=Nellymoser

Definition in file nellymoserenc.c.

Macro Definition Documentation

◆ BITSTREAM_WRITER_LE

#define BITSTREAM_WRITER_LE

Definition at line 51 of file nellymoserenc.c.

◆ POW_TABLE_SIZE

#define POW_TABLE_SIZE   (1<<11)

Definition at line 54 of file nellymoserenc.c.

◆ POW_TABLE_OFFSET

#define POW_TABLE_OFFSET   3

Definition at line 55 of file nellymoserenc.c.

◆ OPT_SIZE

#define OPT_SIZE   ((1<<15) + 3000)

Definition at line 56 of file nellymoserenc.c.

◆ find_best

#define find_best (   val,
  table,
  LUT,
  LUT_add,
  LUT_size 
)
Value:
best_idx = \
LUT[av_clip ((lrintf(val) >> 8) + LUT_add, 0, LUT_size - 1)]; \
if (fabs(val - table[best_idx]) > fabs(val - table[best_idx + 1])) \
best_idx++;

Definition at line 204 of file nellymoserenc.c.

Function Documentation

◆ apply_mdct()

static void apply_mdct ( NellyMoserEncodeContext s)
static

Definition at line 121 of file nellymoserenc.c.

Referenced by encode_block().

◆ encode_end()

static av_cold int encode_end ( AVCodecContext avctx)
static

Definition at line 136 of file nellymoserenc.c.

◆ nellymoser_init_static()

static av_cold void nellymoser_init_static ( void  )
static

Definition at line 150 of file nellymoserenc.c.

Referenced by encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext avctx)
static

Definition at line 168 of file nellymoserenc.c.

◆ get_exponent_greedy()

static void get_exponent_greedy ( NellyMoserEncodeContext s,
float cand,
int idx_table 
)
static

Definition at line 210 of file nellymoserenc.c.

Referenced by encode_block().

◆ distance()

static float distance ( float  x,
float  y,
int  band 
)
inlinestatic

◆ get_exponent_dynamic()

static void get_exponent_dynamic ( NellyMoserEncodeContext s,
float cand,
int idx_table 
)
static

Definition at line 235 of file nellymoserenc.c.

Referenced by encode_block().

◆ encode_block()

static void encode_block ( NellyMoserEncodeContext s,
unsigned char *  output,
int  output_size 
)
static

Encode NELLY_SAMPLES samples.

It assumes, that samples contains 3 * NELLY_BUF_LEN values

Parameters
sencoder context
outputoutput buffer
output_sizesize of output buffer

Definition at line 304 of file nellymoserenc.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 378 of file nellymoserenc.c.

Variable Documentation

◆ pow_table

float pow_table[POW_TABLE_SIZE]
static

pow(2, -i / 2048.0 - 3.0);

Definition at line 71 of file nellymoserenc.c.

Referenced by encode_block(), and nellymoser_init_static().

◆ sf_lut

const uint8_t sf_lut[96]
static
Initial value:
= {
0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4,
5, 5, 5, 6, 7, 7, 8, 8, 9, 10, 11, 11, 12, 13, 13, 14,
15, 15, 16, 17, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 26,
27, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40,
41, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51, 52, 52, 53,
54, 55, 55, 56, 57, 57, 58, 59, 59, 60, 60, 60, 61, 61, 61, 62,
}

Definition at line 73 of file nellymoserenc.c.

Referenced by get_exponent_greedy().

◆ sf_delta_lut

const uint8_t sf_delta_lut[78]
static
Initial value:
= {
0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4,
4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10, 11, 11, 12,
13, 13, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 22, 23,
23, 24, 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 27, 28,
28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 30,
}

Definition at line 82 of file nellymoserenc.c.

Referenced by get_exponent_greedy().

◆ quant_lut

const uint8_t quant_lut[230]
static
Initial value:
= {
0,
0, 1, 2,
0, 1, 2, 3, 4, 5, 6,
0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11,
12, 13, 13, 13, 14,
0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8,
8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 29,
30,
0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3,
4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 9,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15,
15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20,
21, 21, 22, 22, 23, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 42, 43, 44, 44, 45, 45,
46, 47, 47, 48, 48, 49, 49, 50, 50, 50, 51, 51, 51, 52, 52, 52,
53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 57,
58, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, 61,
61, 61, 61, 61, 62,
}

Definition at line 90 of file nellymoserenc.c.

Referenced by encode_block().

◆ quant_lut_mul

const float quant_lut_mul[7] = { 0.0, 0.0, 2.0, 2.0, 5.0, 12.0, 36.6 }
static

Definition at line 117 of file nellymoserenc.c.

Referenced by encode_block().

◆ quant_lut_add

const float quant_lut_add[7] = { 0.0, 0.0, 2.0, 7.0, 21.0, 56.0, 157.0 }
static

Definition at line 118 of file nellymoserenc.c.

Referenced by encode_block().

◆ quant_lut_offset

const uint8_t quant_lut_offset[8] = { 0, 0, 1, 4, 11, 32, 81, 230 }
static

Definition at line 119 of file nellymoserenc.c.

Referenced by encode_block().

◆ ff_nellymoser_encoder

const FFCodec ff_nellymoser_encoder
Initial value:
= {
.p.name = "nellymoser",
.p.long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"),
.p.type = AVMEDIA_TYPE_AUDIO,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.priv_data_size = sizeof(NellyMoserEncodeContext),
.close = encode_end,
.p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
.p.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
}

Definition at line 416 of file nellymoserenc.c.

av_clip
#define av_clip
Definition: common.h:95
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:39
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: nellymoserenc.c:168
table
static const uint16_t table[]
Definition: prosumer.c:206
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:353
init
static int init
Definition: av_tx.c:47
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:263
NellyMoserEncodeContext
Definition: nellymoserenc.c:58
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:290
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: codec_internal.h:31
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:82
encode_end
static av_cold int encode_end(AVCodecContext *avctx)
Definition: nellymoserenc.c:136
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: nellymoserenc.c:378
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:87
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
AV_CODEC_ID_NELLYMOSER
@ AV_CODEC_ID_NELLYMOSER
Definition: codec_id.h:460