Libav
psymodel.h
Go to the documentation of this file.
1 /*
2  * audio encoder psychoacoustic model
3  * Copyright (C) 2008 Konstantin Shishkov
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_PSYMODEL_H
23 #define AVCODEC_PSYMODEL_H
24 
25 #include "avcodec.h"
26 
28 #define PSY_MAX_BANDS 128
29 
30 #define PSY_MAX_CHANS 20
31 
35 typedef struct FFPsyBand {
36  int bits;
37  float energy;
38  float threshold;
39  float distortion;
41 } FFPsyBand;
42 
46 typedef struct FFPsyChannel {
48  float entropy;
49 } FFPsyChannel;
50 
54 typedef struct FFPsyChannelGroup {
59 
63 typedef struct FFPsyWindowInfo {
64  int window_type[3];
67  int grouping[8];
68  int *window_sizes;
70 
74 typedef struct FFPsyContext {
76  const struct FFPsyModel *model;
77 
80  int num_groups;
81 
83  int *num_bands;
84  int num_lens;
85 
86  struct {
87  int size;
88  int bits;
89  } bitres;
90 
92 } FFPsyContext;
93 
97 typedef struct FFPsyModel {
98  const char *name;
99  int (*init) (FFPsyContext *apc);
100 
112  FFPsyWindowInfo (*window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type);
113 
122  void (*analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi);
123 
124  void (*end) (FFPsyContext *apc);
125 } FFPsyModel;
126 
140 int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
141  const uint8_t **bands, const int *num_bands,
142  int num_groups, const uint8_t *group_map);
143 
153 
159 void ff_psy_end(FFPsyContext *ctx);
160 
161 
162 /**************************************************************************
163  * Audio preprocessing stuff. *
164  * This should be moved into some audio filter eventually. *
165  **************************************************************************/
167 
172 
180 void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels);
181 
186 
187 #endif /* AVCODEC_PSYMODEL_H */
#define PSY_MAX_BANDS
maximum possible number of bands
Definition: psymodel.h:28
int num_groups
number of channel groups
Definition: psymodel.h:80
void(* end)(FFPsyContext *apc)
Definition: psymodel.h:124
int grouping[8]
window grouping (for e.g. AAC)
Definition: psymodel.h:67
uint8_t ** bands
scalefactor band sizes for possible frame sizes
Definition: psymodel.h:82
FFPsyChannelGroup * group
channel group information
Definition: psymodel.h:79
FFPsyBand psy_bands[PSY_MAX_BANDS]
channel bands information
Definition: psymodel.h:47
psychoacoustic information for an arbitrary group of channels
Definition: psymodel.h:54
float perceptual_weight
Definition: psymodel.h:40
int * num_bands
number of scalefactor bands for possible frame sizes
Definition: psymodel.h:83
int * window_sizes
sequence of window sizes inside one frame (for eg. WMA)
Definition: psymodel.h:68
uint8_t
struct FFPsyPreprocessContext * ff_psy_preprocess_init(AVCodecContext *avctx)
psychoacoustic model audio preprocessing initialization
Definition: psymodel.c:95
int size
size of the bitresevoir in bits
Definition: psymodel.h:87
context used by psychoacoustic model
Definition: psymodel.h:74
single band psychoacoustic information
Definition: psymodel.h:35
struct FFPsyContext::@59 bitres
AVCodecContext * avctx
Definition: psymodel.c:87
single channel psychoacoustic information
Definition: psymodel.h:46
FFPsyChannel * ch[PSY_MAX_CHANS]
pointers to the individual channels in the group
Definition: psymodel.h:55
int bits
Definition: psymodel.h:36
int num_windows
number of windows in a frame
Definition: psymodel.h:66
float energy
Definition: psymodel.h:37
Libavcodec external API header.
codec-specific psychoacoustic model implementation
Definition: psymodel.h:97
int(* init)(FFPsyContext *apc)
Definition: psymodel.h:99
uint8_t num_ch
number of channels in this group
Definition: psymodel.h:56
void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
Definition: psymodel.c:130
float entropy
total PE for this channel
Definition: psymodel.h:48
main external API structure.
Definition: avcodec.h:1050
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
void * model_priv_data
psychoacoustic model implementation private data
Definition: psymodel.h:91
int bits
number of bits used in the bitresevoir
Definition: psymodel.h:88
#define PSY_MAX_CHANS
maximum number of channels
Definition: psymodel.h:30
FFPsyChannelGroup * ff_psy_find_group(FFPsyContext *ctx, int channel)
Determine what group a channel belongs to.
Definition: psymodel.c:66
int window_shape
window shape (sine/KBD/whatever)
Definition: psymodel.h:65
const struct FFPsyModel * model
encoder-specific model functions
Definition: psymodel.h:76
FFPsyWindowInfo(* window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type)
Suggest window sequence for channel.
Definition: psymodel.h:112
void ff_psy_end(FFPsyContext *ctx)
Cleanup model context at the end.
Definition: psymodel.c:76
uint8_t coupling[PSY_MAX_BANDS]
allow coupling for this band in the group
Definition: psymodel.h:57
float distortion
Definition: psymodel.h:39
const char * name
Definition: psymodel.h:98
windowing related information
Definition: psymodel.h:63
int num_lens
number of scalefactor band sets
Definition: psymodel.h:84
void(* analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi)
Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels...
Definition: psymodel.h:122
FFPsyChannel * ch
single channel information
Definition: psymodel.h:78
AVCodecContext * avctx
encoder context
Definition: psymodel.h:75
float threshold
Definition: psymodel.h:38
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
Preprocess several channel in audio frame in order to compress it better.
Definition: psymodel.c:118
int window_type[3]
window type (short/long/transitional, etc.) - current, previous and next
Definition: psymodel.h:64
int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, const uint8_t **bands, const int *num_bands, int num_groups, const uint8_t *group_map)
Initialize psychoacoustic model.
Definition: psymodel.c:31