Add missing files from ffmpeg, write a README.rockbox and a makefile.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27742 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Mohamed Tarek 2010-08-07 13:06:05 +00:00
parent e3a6610ae7
commit fb26f52697
22 changed files with 2709 additions and 21 deletions

View file

@ -0,0 +1,65 @@
CC = gcc -o
INC = -I.
OUTPUT = wmavoice
STD = c99
LIBS = -lm
CFLAGS = -Wall -ggdb -std=$(STD) $(INC)
SOURCES = \
acelp_filters.c\
acelp_vectors.c\
avfft.c\
bitstream.c\
celp_filters.c\
celp_math.c\
dct.c\
fft.c\
lsp.c\
mdct.c\
rdft.c\
utils.c\
wmavoice.c\
libavutil/log.c\
libavutil/lzo.c\
libavutil/mem.c\
libavutil/mathematics.c
HEADERS = \
acelp_vectors.h\
celp_math.h\
get_bits.h\
wmavoice_data.h\
avcodec.h\
fft.h\
dsputil.h\
acelp_filters.h\
celp_filters.h\
put_bits.h\
lsp.h\
internal.h\
avfft.h\
mathops.h\
mdct_tablegen.h\
dct32.c\
libavutil/avutil.h\
libavutil/attributes.h\
libavutil/lzo.h\
libavutil/mem.h\
libavutil/log.h\
libavutil/internal.h\
libavutil/common.h\
libavutil/intreadwrite.h\
libavutil/bswap.h\
libavutil/mathematics.h
OBJECTS = $(SOURCES:.c=.o)
all:$(OUTPUT)
$(OUTPUT):$(SOURCES) $(HEADERS)
$(CC) $@ $(CFLAGS) $(SOURCES) $(LIBS)
@echo "Done."
clean:
rm -f *.o $(OUTPUT) *~

View file

@ -0,0 +1,23 @@
Library: libwmavoice
Imported: 2010-08-07 by Mohamed Tarek
This set of files form the files needed from ffmpeg's libavcodec and libavutil
to build a standalone wma voice decoder.
LICENSING INFORMATION
ffmpeg is licensed under the Lesser GNU General Public License and the file
wmavoice.c is copyright (c) 2009 Ronald S. Bultje.
IMPORT DETAILS
Based on ffmpeg svn r24734 dated 7 August 2010.
As of 7 August 2010, libwmavoice contains just the files from ffmpeg with
minimum modifications to comile standalone. The decoder isn't still used in
rockbox in anyway.
COMPILING
the decoder can be compiled by issuing the "make" command from witin the
libwmavoice directory in any unix-line environment.

View file

@ -45,7 +45,7 @@ void ff_acelp_interpolate(int16_t* out, const int16_t* in,
{ {
int n, i; int n, i;
assert(frac_pos >= 0 && frac_pos < precision); //assert(frac_pos >= 0 && frac_pos < precision);
for (n = 0; n < length; n++) { for (n = 0; n < length; n++) {
int idx = 0; int idx = 0;

View file

@ -0,0 +1,270 @@
/*
* adaptive and fixed codebook vector operations for ACELP-based codecs
*
* Copyright (c) 2008 Vladimir Voroshilov
*
* 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 <inttypes.h>
#include "avcodec.h"
#include "acelp_vectors.h"
#include "celp_math.h"
const uint8_t ff_fc_2pulses_9bits_track1[16] =
{
1, 3,
6, 8,
11, 13,
16, 18,
21, 23,
26, 28,
31, 33,
36, 38
};
const uint8_t ff_fc_2pulses_9bits_track1_gray[16] =
{
1, 3,
8, 6,
18, 16,
11, 13,
38, 36,
31, 33,
21, 23,
28, 26,
};
const uint8_t ff_fc_2pulses_9bits_track2_gray[32] =
{
0, 2,
5, 4,
12, 10,
7, 9,
25, 24,
20, 22,
14, 15,
19, 17,
36, 31,
21, 26,
1, 6,
16, 11,
27, 29,
32, 30,
39, 37,
34, 35,
};
const uint8_t ff_fc_4pulses_8bits_tracks_13[16] =
{
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
};
const uint8_t ff_fc_4pulses_8bits_track_4[32] =
{
3, 4,
8, 9,
13, 14,
18, 19,
23, 24,
28, 29,
33, 34,
38, 39,
43, 44,
48, 49,
53, 54,
58, 59,
63, 64,
68, 69,
73, 74,
78, 79,
};
#if 0
static uint8_t gray_decode[32] =
{
0, 1, 3, 2, 7, 6, 4, 5,
15, 14, 12, 13, 8, 9, 11, 10,
31, 30, 28, 29, 24, 25, 27, 26,
16, 17, 19, 18, 23, 22, 20, 21
};
#endif
const float ff_pow_0_7[10] = {
0.700000, 0.490000, 0.343000, 0.240100, 0.168070,
0.117649, 0.082354, 0.057648, 0.040354, 0.028248
};
const float ff_pow_0_75[10] = {
0.750000, 0.562500, 0.421875, 0.316406, 0.237305,
0.177979, 0.133484, 0.100113, 0.075085, 0.056314
};
const float ff_pow_0_55[10] = {
0.550000, 0.302500, 0.166375, 0.091506, 0.050328,
0.027681, 0.015224, 0.008373, 0.004605, 0.002533
};
const float ff_b60_sinc[61] = {
0.898529 , 0.865051 , 0.769257 , 0.624054 , 0.448639 , 0.265289 ,
0.0959167 , -0.0412598 , -0.134338 , -0.178986 , -0.178528 , -0.142609 ,
-0.0849304 , -0.0205078 , 0.0369568 , 0.0773926 , 0.0955200 , 0.0912781 ,
0.0689392 , 0.0357056 , 0. , -0.0305481 , -0.0504150 , -0.0570068 ,
-0.0508423 , -0.0350037 , -0.0141602 , 0.00665283, 0.0230713 , 0.0323486 ,
0.0335388 , 0.0275879 , 0.0167847 , 0.00411987, -0.00747681, -0.0156860 ,
-0.0193481 , -0.0183716 , -0.0137634 , -0.00704956, 0. , 0.00582886 ,
0.00939941, 0.0103760 , 0.00903320, 0.00604248, 0.00238037, -0.00109863 ,
-0.00366211, -0.00497437, -0.00503540, -0.00402832, -0.00241089, -0.000579834,
0.00103760, 0.00222778, 0.00277710, 0.00271606, 0.00213623, 0.00115967 ,
0.
};
void ff_acelp_fc_pulse_per_track(
int16_t* fc_v,
const uint8_t *tab1,
const uint8_t *tab2,
int pulse_indexes,
int pulse_signs,
int pulse_count,
int bits)
{
int mask = (1 << bits) - 1;
int i;
for(i=0; i<pulse_count; i++)
{
fc_v[i + tab1[pulse_indexes & mask]] +=
(pulse_signs & 1) ? 8191 : -8192; // +/-1 in (2.13)
pulse_indexes >>= bits;
pulse_signs >>= 1;
}
fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192;
}
void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
AMRFixed *fixed_sparse,
const uint8_t *gray_decode,
int half_pulse_count, int bits)
{
int i;
int mask = (1 << bits) - 1;
fixed_sparse->no_repeat_mask = 0;
fixed_sparse->n = 2 * half_pulse_count;
for (i = 0; i < half_pulse_count; i++) {
const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i;
const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i;
const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
fixed_sparse->x[2*i+1] = pos1;
fixed_sparse->x[2*i ] = pos2;
fixed_sparse->y[2*i+1] = sign;
fixed_sparse->y[2*i ] = pos2 < pos1 ? -sign : sign;
}
}
void ff_acelp_weighted_vector_sum(
int16_t* out,
const int16_t *in_a,
const int16_t *in_b,
int16_t weight_coeff_a,
int16_t weight_coeff_b,
int16_t rounder,
int shift,
int length)
{
int i;
// Clipping required here; breaks OVERFLOW test.
for(i=0; i<length; i++)
out[i] = av_clip_int16((
in_a[i] * weight_coeff_a +
in_b[i] * weight_coeff_b +
rounder) >> shift);
}
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
float weight_coeff_a, float weight_coeff_b, int length)
{
int i;
for(i=0; i<length; i++)
out[i] = weight_coeff_a * in_a[i]
+ weight_coeff_b * in_b[i];
}
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
int size, float alpha, float *gain_mem)
{
int i;
float postfilter_energ = ff_dot_productf(in, in, size);
float gain_scale_factor = 1.0;
float mem = *gain_mem;
if (postfilter_energ)
gain_scale_factor = sqrt(speech_energ / postfilter_energ);
gain_scale_factor *= 1.0 - alpha;
for (i = 0; i < size; i++) {
mem = alpha * mem + gain_scale_factor;
out[i] = in[i] * mem;
}
*gain_mem = mem;
}
void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
float sum_of_squares, const int n)
{
int i;
float scalefactor = ff_dot_productf(in, in, n);
if (scalefactor)
scalefactor = sqrt(sum_of_squares / scalefactor);
for (i = 0; i < n; i++)
out[i] = in[i] * scalefactor;
}
void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size)
{
int i;
for (i=0; i < in->n; i++) {
int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
float y = in->y[i] * scale;
do {
out[x] += y;
y *= in->pitch_fac;
x += in->pitch_lag;
} while (x < size && repeats);
}
}
void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size)
{
int i;
for (i=0; i < in->n; i++) {
int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
do {
out[x] = 0.0;
x += in->pitch_lag;
} while (x < size && repeats);
}
}

View file

@ -0,0 +1,264 @@
/*
* adaptive and fixed codebook vector operations for ACELP-based codecs
*
* Copyright (c) 2008 Vladimir Voroshilov
*
* 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
*/
#ifndef AVCODEC_ACELP_VECTORS_H
#define AVCODEC_ACELP_VECTORS_H
#include <stdint.h>
/** Sparse representation for the algebraic codebook (fixed) vector */
typedef struct {
int n;
int x[10];
float y[10];
int no_repeat_mask;
int pitch_lag;
float pitch_fac;
} AMRFixed;
/**
* Track|Pulse| Positions
* -------------------------------------------------------------------------
* 1 | 0 | 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75
* -------------------------------------------------------------------------
* 2 | 1 | 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76
* -------------------------------------------------------------------------
* 3 | 2 | 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77
* -------------------------------------------------------------------------
*
* Table contains only first the pulse indexes.
*
* Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
*/
extern const uint8_t ff_fc_4pulses_8bits_tracks_13[16];
/**
* Track|Pulse| Positions
* -------------------------------------------------------------------------
* 4 | 3 | 3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78
* | | 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79
* -------------------------------------------------------------------------
*
* @remark Track in the table should be read top-to-bottom, left-to-right.
*
* Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
*/
extern const uint8_t ff_fc_4pulses_8bits_track_4[32];
/**
* Track|Pulse| Positions
* -----------------------------------------
* 1 | 0 | 1, 6, 11, 16, 21, 26, 31, 36
* | | 3, 8, 13, 18, 23, 28, 33, 38
* -----------------------------------------
*
* @remark Track in the table should be read top-to-bottom, left-to-right.
*
* @note (EE) Reference G.729D code also uses gray decoding for each
* pulse index before looking up the value in the table.
*
* Used in G.729 @@6.4k (with gray coding), AMR @@5.9k (without gray coding)
*/
extern const uint8_t ff_fc_2pulses_9bits_track1[16];
extern const uint8_t ff_fc_2pulses_9bits_track1_gray[16];
/**
* Track|Pulse| Positions
* -----------------------------------------
* 2 | 1 | 0, 7, 14, 20, 27, 34, 1, 21
* | | 2, 9, 15, 22, 29, 35, 6, 26
* | | 4,10, 17, 24, 30, 37, 11, 31
* | | 5,12, 19, 25, 32, 39, 16, 36
* -----------------------------------------
*
* @remark Track in the table should be read top-to-bottom, left-to-right.
*
* @note (EE.1) This table (from the reference code) does not comply with
* the specification.
* The specification contains the following table:
*
* Track|Pulse| Positions
* -----------------------------------------
* 2 | 1 | 0, 5, 10, 15, 20, 25, 30, 35
* | | 1, 6, 11, 16, 21, 26, 31, 36
* | | 2, 7, 12, 17, 22, 27, 32, 37
* | | 4, 9, 14, 19, 24, 29, 34, 39
*
* -----------------------------------------
*
* @note (EE.2) Reference G.729D code also uses gray decoding for each
* pulse index before looking up the value in the table.
*
* Used in G.729 @@6.4k (with gray coding)
*/
extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32];
/**
* b60 hamming windowed sinc function coefficients
*/
extern const float ff_b60_sinc[61];
/**
* Table of pow(0.7,n)
*/
extern const float ff_pow_0_7[10];
/**
* Table of pow(0.75,n)
*/
extern const float ff_pow_0_75[10];
/**
* Table of pow(0.55,n)
*/
extern const float ff_pow_0_55[10];
/**
* Decode fixed-codebook vector (3.8 and D.5.8 of G.729, 5.7.1 of AMR).
* @param[out] fc_v decoded fixed codebook vector (2.13)
* @param tab1 table used for first pulse_count pulses
* @param tab2 table used for last pulse
* @param pulse_indexes fixed codebook indexes
* @param pulse_signs signs of the excitation pulses (0 bit value
* means negative sign)
* @param bits number of bits per one pulse index
* @param pulse_count number of pulses decoded using first table
* @param bits length of one pulse index in bits
*
* Used in G.729 @@8k, G.729 @@4.4k, G.729 @@6.4k, AMR @@7.95k, AMR @@7.40k
*/
void ff_acelp_fc_pulse_per_track(int16_t* fc_v,
const uint8_t *tab1,
const uint8_t *tab2,
int pulse_indexes,
int pulse_signs,
int pulse_count,
int bits);
/**
* Decode the algebraic codebook index to pulse positions and signs and
* construct the algebraic codebook vector for MODE_12k2.
*
* @note: The positions and signs are explicitly coded in MODE_12k2.
*
* @param fixed_index positions of the ten pulses
* @param fixed_sparse pointer to the algebraic codebook vector
* @param gray_decode gray decoding table
* @param half_pulse_count number of couples of pulses
* @param bits length of one pulse index in bits
*/
void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
AMRFixed *fixed_sparse,
const uint8_t *gray_decode,
int half_pulse_count, int bits);
/**
* weighted sum of two vectors with rounding.
* @param[out] out result of addition
* @param in_a first vector
* @param in_b second vector
* @param weight_coeff_a first vector weight coefficient
* @param weight_coeff_a second vector weight coefficient
* @param rounder this value will be added to the sum of the two vectors
* @param shift result will be shifted to right by this value
* @param length vectors length
*
* @note It is safe to pass the same buffer for out and in_a or in_b.
*
* out[i] = (in_a[i]*weight_a + in_b[i]*weight_b + rounder) >> shift
*/
void ff_acelp_weighted_vector_sum(int16_t* out,
const int16_t *in_a,
const int16_t *in_b,
int16_t weight_coeff_a,
int16_t weight_coeff_b,
int16_t rounder,
int shift,
int length);
/**
* float implementation of weighted sum of two vectors.
* @param[out] out result of addition
* @param in_a first vector
* @param in_b second vector
* @param weight_coeff_a first vector weight coefficient
* @param weight_coeff_a second vector weight coefficient
* @param length vectors length
*
* @note It is safe to pass the same buffer for out and in_a or in_b.
*/
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
float weight_coeff_a, float weight_coeff_b,
int length);
/**
* Adaptive gain control (as used in AMR postfiltering)
*
* @param out output buffer for filtered speech data
* @param in the input speech buffer (may be the same as out)
* @param speech_energ input energy
* @param size the input buffer size
* @param alpha exponential filter factor
* @param gain_mem a pointer to the filter memory (single float of size)
*/
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
int size, float alpha, float *gain_mem);
/**
* Set the sum of squares of a signal by scaling
*
* @param out output samples
* @param in input samples
* @param sum_of_squares new sum of squares
* @param n number of samples
*
* @note If the input is zero (or its energy underflows), the output is zero.
* This is the behavior of AGC in the AMR reference decoder. The QCELP
* reference decoder seems to have undefined behavior.
*
* TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6
* 3GPP TS 26.090 6.1 (6)
*/
void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
float sum_of_squares, const int n);
/**
* Add fixed vector to an array from a sparse representation
*
* @param out fixed vector with pitch sharpening
* @param in sparse fixed vector
* @param scale number to multiply the fixed vector by
* @param size the output vector size
*/
void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size);
/**
* Clear array values set by set_fixed_vector
*
* @param out fixed vector to be cleared
* @param in sparse fixed vector
* @param size the output vector size
*/
void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size);
#endif /* AVCODEC_ACELP_VECTORS_H */

View file

@ -1114,7 +1114,7 @@ typedef struct AVCodecContext {
* - encoding: MUST be set by user. * - encoding: MUST be set by user.
* - decoding: Set by libavcodec. * - decoding: Set by libavcodec.
*/ */
AVRational time_base; //AVRational time_base;
/* video only */ /* video only */
/** /**
@ -1142,7 +1142,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user. * - encoding: Set by user.
* - decoding: Set by user if known, overridden by libavcodec if known * - decoding: Set by user if known, overridden by libavcodec if known
*/ */
enum PixelFormat pix_fmt; //enum PixelFormat pix_fmt;
/** /**
* Frame rate emulation. If not zero, the lower layer (i.e. format handler) * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
@ -1693,7 +1693,7 @@ typedef struct AVCodecContext {
* - encoding: Set by user. * - encoding: Set by user.
* - decoding: Set by libavcodec. * - decoding: Set by libavcodec.
*/ */
AVRational sample_aspect_ratio; //AVRational sample_aspect_ratio;
/** /**
* the picture in the bitstream * the picture in the bitstream
@ -2738,8 +2738,8 @@ typedef struct AVCodec {
* Will be called when seeking * Will be called when seeking
*/ */
void (*flush)(AVCodecContext *); void (*flush)(AVCodecContext *);
const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} //const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 //const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
/** /**
* Descriptive name for the codec, meant to be more human readable than name. * Descriptive name for the codec, meant to be more human readable than name.
* You should use the NULL_IF_CONFIG_SMALL() macro to define it. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
@ -2781,7 +2781,7 @@ typedef struct AVHWAccel {
* *
* Only hardware accelerated formats are supported here. * Only hardware accelerated formats are supported here.
*/ */
enum PixelFormat pix_fmt; //enum PixelFormat pix_fmt;
/** /**
* Hardware accelerated codec capabilities. * Hardware accelerated codec capabilities.
@ -3976,7 +3976,7 @@ attribute_deprecated int av_parse_video_frame_size(int *width_ptr, int *height_p
* *
* @deprecated Deprecated in favor of av_parse_video_rate(). * @deprecated Deprecated in favor of av_parse_video_rate().
*/ */
attribute_deprecated int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); //attribute_deprecated int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
#endif #endif
/** /**

View file

@ -66,7 +66,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
if(length==0) return; if(length==0) return;
if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ if(/*CONFIG_SMALL ||*/ words < 16 || put_bits_count(pb)&7){
for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i)); for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
}else{ }else{
for(i=0; put_bits_count(pb)&31; i++) for(i=0; put_bits_count(pb)&31; i++)

View file

@ -0,0 +1,226 @@
/*
* (I)DCT Transforms
* Copyright (c) 2009 Peter Ross <pross@xvid.org>
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
* Copyright (c) 2010 Vitor Sessak
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* (Inverse) Discrete Cosine Transforms. These are also known as the
* type II and type III DCTs respectively.
*/
#include <math.h>
#include "libavutil/mathematics.h"
#include "fft.h"
//#include "x86/fft.h"
#define DCT32_FLOAT
#include "dct32.c"
/* sin((M_PI * x / (2*n)) */
#define SIN(s,n,x) (s->costab[(n) - (x)])
/* cos((M_PI * x / (2*n)) */
#define COS(s,n,x) (s->costab[x])
static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data)
{
int n = 1 << ctx->nbits;
int i;
data[0] = 0;
for(i = 1; i < n/2; i++) {
float tmp1 = data[i ];
float tmp2 = data[n - i];
float s = SIN(ctx, n, 2*i);
s *= tmp1 + tmp2;
tmp1 = (tmp1 - tmp2) * 0.5f;
data[i ] = s + tmp1;
data[n - i] = s - tmp1;
}
data[n/2] *= 2;
ff_rdft_calc(&ctx->rdft, data);
data[0] *= 0.5f;
for(i = 1; i < n-2; i += 2) {
data[i + 1] += data[i - 1];
data[i ] = -data[i + 2];
}
data[n-1] = 0;
}
static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
{
int n = 1 << ctx->nbits;
int i;
float next = -0.5f * (data[0] - data[n]);
for(i = 0; i < n/2; i++) {
float tmp1 = data[i ];
float tmp2 = data[n - i];
float s = SIN(ctx, n, 2*i);
float c = COS(ctx, n, 2*i);
c *= tmp1 - tmp2;
s *= tmp1 - tmp2;
next += c;
tmp1 = (tmp1 + tmp2) * 0.5f;
data[i ] = tmp1 - s;
data[n - i] = tmp1 + s;
}
ff_rdft_calc(&ctx->rdft, data);
data[n] = data[1];
data[1] = next;
for(i = 3; i <= n; i += 2)
data[i] = data[i - 2] - data[i];
}
static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data)
{
int n = 1 << ctx->nbits;
int i;
float next = data[n - 1];
float inv_n = 1.0f / n;
for (i = n - 2; i >= 2; i -= 2) {
float val1 = data[i ];
float val2 = data[i - 1] - data[i + 1];
float c = COS(ctx, n, i);
float s = SIN(ctx, n, i);
data[i ] = c * val1 + s * val2;
data[i + 1] = s * val1 - c * val2;
}
data[1] = 2 * next;
ff_rdft_calc(&ctx->rdft, data);
for (i = 0; i < n / 2; i++) {
float tmp1 = data[i ] * inv_n;
float tmp2 = data[n - i - 1] * inv_n;
float csc = ctx->csc2[i] * (tmp1 - tmp2);
tmp1 += tmp2;
data[i ] = tmp1 + csc;
data[n - i - 1] = tmp1 - csc;
}
}
static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data)
{
int n = 1 << ctx->nbits;
int i;
float next;
for (i=0; i < n/2; i++) {
float tmp1 = data[i ];
float tmp2 = data[n - i - 1];
float s = SIN(ctx, n, 2*i + 1);
s *= tmp1 - tmp2;
tmp1 = (tmp1 + tmp2) * 0.5f;
data[i ] = tmp1 + s;
data[n-i-1] = tmp1 - s;
}
ff_rdft_calc(&ctx->rdft, data);
next = data[1] * 0.5;
data[1] *= -1;
for (i = n - 2; i >= 0; i -= 2) {
float inr = data[i ];
float ini = data[i + 1];
float c = COS(ctx, n, i);
float s = SIN(ctx, n, i);
data[i ] = c * inr + s * ini;
data[i+1] = next;
next += s * inr - c * ini;
}
}
static void dct32_func(DCTContext *ctx, FFTSample *data)
{
ctx->dct32(data, data);
}
void ff_dct_calc(DCTContext *s, FFTSample *data)
{
s->dct_calc(s, data);
}
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
{
int n = 1 << nbits;
int i;
s->nbits = nbits;
s->inverse = inverse;
ff_init_ff_cos_tabs(nbits+2);
s->costab = ff_cos_tabs[nbits+2];
s->csc2 = av_malloc(n/2 * sizeof(FFTSample));
if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) {
av_free(s->csc2);
return -1;
}
for (i = 0; i < n/2; i++)
s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1)));
switch(inverse) {
case DCT_I : s->dct_calc = ff_dct_calc_I_c; break;
case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break;
case DCT_III: s->dct_calc = ff_dct_calc_III_c; break;
case DST_I : s->dct_calc = ff_dst_calc_I_c; break;
}
if (inverse == DCT_II && nbits == 5)
s->dct_calc = dct32_func;
s->dct32 = dct32;
//if (HAVE_MMX) ff_dct_init_mmx(s);
return 0;
}
av_cold void ff_dct_end(DCTContext *s)
{
ff_rdft_end(&s->rdft);
av_free(s->csc2);
}

View file

@ -0,0 +1,267 @@
/*
* Template for the Discrete Cosine Transform for 32 samples
* Copyright (c) 2001, 2002 Fabrice Bellard
*
* 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
*/
#ifdef DCT32_FLOAT
# define FIXHR(x) ((float)(x))
# define MULH3(x, y, s) ((s)*(y)*(x))
# define INTFLOAT float
#endif
/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
/* cos(i*pi/64) */
#define COS0_0 FIXHR(0.50060299823519630134/2)
#define COS0_1 FIXHR(0.50547095989754365998/2)
#define COS0_2 FIXHR(0.51544730992262454697/2)
#define COS0_3 FIXHR(0.53104259108978417447/2)
#define COS0_4 FIXHR(0.55310389603444452782/2)
#define COS0_5 FIXHR(0.58293496820613387367/2)
#define COS0_6 FIXHR(0.62250412303566481615/2)
#define COS0_7 FIXHR(0.67480834145500574602/2)
#define COS0_8 FIXHR(0.74453627100229844977/2)
#define COS0_9 FIXHR(0.83934964541552703873/2)
#define COS0_10 FIXHR(0.97256823786196069369/2)
#define COS0_11 FIXHR(1.16943993343288495515/4)
#define COS0_12 FIXHR(1.48416461631416627724/4)
#define COS0_13 FIXHR(2.05778100995341155085/8)
#define COS0_14 FIXHR(3.40760841846871878570/8)
#define COS0_15 FIXHR(10.19000812354805681150/32)
#define COS1_0 FIXHR(0.50241928618815570551/2)
#define COS1_1 FIXHR(0.52249861493968888062/2)
#define COS1_2 FIXHR(0.56694403481635770368/2)
#define COS1_3 FIXHR(0.64682178335999012954/2)
#define COS1_4 FIXHR(0.78815462345125022473/2)
#define COS1_5 FIXHR(1.06067768599034747134/4)
#define COS1_6 FIXHR(1.72244709823833392782/4)
#define COS1_7 FIXHR(5.10114861868916385802/16)
#define COS2_0 FIXHR(0.50979557910415916894/2)
#define COS2_1 FIXHR(0.60134488693504528054/2)
#define COS2_2 FIXHR(0.89997622313641570463/2)
#define COS2_3 FIXHR(2.56291544774150617881/8)
#define COS3_0 FIXHR(0.54119610014619698439/2)
#define COS3_1 FIXHR(1.30656296487637652785/4)
#define COS4_0 FIXHR(0.70710678118654752439/2)
/* butterfly operator */
#define BF(a, b, c, s)\
{\
tmp0 = val##a + val##b;\
tmp1 = val##a - val##b;\
val##a = tmp0;\
val##b = MULH3(tmp1, c, 1<<(s));\
}
#define BF0(a, b, c, s)\
{\
tmp0 = tab[a] + tab[b];\
tmp1 = tab[a] - tab[b];\
val##a = tmp0;\
val##b = MULH3(tmp1, c, 1<<(s));\
}
#define BF1(a, b, c, d)\
{\
BF(a, b, COS4_0, 1);\
BF(c, d,-COS4_0, 1);\
val##c += val##d;\
}
#define BF2(a, b, c, d)\
{\
BF(a, b, COS4_0, 1);\
BF(c, d,-COS4_0, 1);\
val##c += val##d;\
val##a += val##c;\
val##c += val##b;\
val##b += val##d;\
}
#define ADD(a, b) val##a += val##b
/* DCT32 without 1/sqrt(2) coef zero scaling. */
static void dct32(INTFLOAT *out, const INTFLOAT *tab)
{
INTFLOAT tmp0, tmp1;
INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,
val8 , val9 , val10, val11, val12, val13, val14, val15,
val16, val17, val18, val19, val20, val21, val22, val23,
val24, val25, val26, val27, val28, val29, val30, val31;
/* pass 1 */
BF0( 0, 31, COS0_0 , 1);
BF0(15, 16, COS0_15, 5);
/* pass 2 */
BF( 0, 15, COS1_0 , 1);
BF(16, 31,-COS1_0 , 1);
/* pass 1 */
BF0( 7, 24, COS0_7 , 1);
BF0( 8, 23, COS0_8 , 1);
/* pass 2 */
BF( 7, 8, COS1_7 , 4);
BF(23, 24,-COS1_7 , 4);
/* pass 3 */
BF( 0, 7, COS2_0 , 1);
BF( 8, 15,-COS2_0 , 1);
BF(16, 23, COS2_0 , 1);
BF(24, 31,-COS2_0 , 1);
/* pass 1 */
BF0( 3, 28, COS0_3 , 1);
BF0(12, 19, COS0_12, 2);
/* pass 2 */
BF( 3, 12, COS1_3 , 1);
BF(19, 28,-COS1_3 , 1);
/* pass 1 */
BF0( 4, 27, COS0_4 , 1);
BF0(11, 20, COS0_11, 2);
/* pass 2 */
BF( 4, 11, COS1_4 , 1);
BF(20, 27,-COS1_4 , 1);
/* pass 3 */
BF( 3, 4, COS2_3 , 3);
BF(11, 12,-COS2_3 , 3);
BF(19, 20, COS2_3 , 3);
BF(27, 28,-COS2_3 , 3);
/* pass 4 */
BF( 0, 3, COS3_0 , 1);
BF( 4, 7,-COS3_0 , 1);
BF( 8, 11, COS3_0 , 1);
BF(12, 15,-COS3_0 , 1);
BF(16, 19, COS3_0 , 1);
BF(20, 23,-COS3_0 , 1);
BF(24, 27, COS3_0 , 1);
BF(28, 31,-COS3_0 , 1);
/* pass 1 */
BF0( 1, 30, COS0_1 , 1);
BF0(14, 17, COS0_14, 3);
/* pass 2 */
BF( 1, 14, COS1_1 , 1);
BF(17, 30,-COS1_1 , 1);
/* pass 1 */
BF0( 6, 25, COS0_6 , 1);
BF0( 9, 22, COS0_9 , 1);
/* pass 2 */
BF( 6, 9, COS1_6 , 2);
BF(22, 25,-COS1_6 , 2);
/* pass 3 */
BF( 1, 6, COS2_1 , 1);
BF( 9, 14,-COS2_1 , 1);
BF(17, 22, COS2_1 , 1);
BF(25, 30,-COS2_1 , 1);
/* pass 1 */
BF0( 2, 29, COS0_2 , 1);
BF0(13, 18, COS0_13, 3);
/* pass 2 */
BF( 2, 13, COS1_2 , 1);
BF(18, 29,-COS1_2 , 1);
/* pass 1 */
BF0( 5, 26, COS0_5 , 1);
BF0(10, 21, COS0_10, 1);
/* pass 2 */
BF( 5, 10, COS1_5 , 2);
BF(21, 26,-COS1_5 , 2);
/* pass 3 */
BF( 2, 5, COS2_2 , 1);
BF(10, 13,-COS2_2 , 1);
BF(18, 21, COS2_2 , 1);
BF(26, 29,-COS2_2 , 1);
/* pass 4 */
BF( 1, 2, COS3_1 , 2);
BF( 5, 6,-COS3_1 , 2);
BF( 9, 10, COS3_1 , 2);
BF(13, 14,-COS3_1 , 2);
BF(17, 18, COS3_1 , 2);
BF(21, 22,-COS3_1 , 2);
BF(25, 26, COS3_1 , 2);
BF(29, 30,-COS3_1 , 2);
/* pass 5 */
BF1( 0, 1, 2, 3);
BF2( 4, 5, 6, 7);
BF1( 8, 9, 10, 11);
BF2(12, 13, 14, 15);
BF1(16, 17, 18, 19);
BF2(20, 21, 22, 23);
BF1(24, 25, 26, 27);
BF2(28, 29, 30, 31);
/* pass 6 */
ADD( 8, 12);
ADD(12, 10);
ADD(10, 14);
ADD(14, 9);
ADD( 9, 13);
ADD(13, 11);
ADD(11, 15);
out[ 0] = val0;
out[16] = val1;
out[ 8] = val2;
out[24] = val3;
out[ 4] = val4;
out[20] = val5;
out[12] = val6;
out[28] = val7;
out[ 2] = val8;
out[18] = val9;
out[10] = val10;
out[26] = val11;
out[ 6] = val12;
out[22] = val13;
out[14] = val14;
out[30] = val15;
ADD(24, 28);
ADD(28, 26);
ADD(26, 30);
ADD(30, 25);
ADD(25, 29);
ADD(29, 27);
ADD(27, 31);
out[ 1] = val16 + val24;
out[17] = val17 + val25;
out[ 9] = val18 + val26;
out[25] = val19 + val27;
out[ 5] = val20 + val28;
out[21] = val21 + val29;
out[13] = val22 + val30;
out[29] = val23 + val31;
out[ 3] = val24 + val20;
out[19] = val25 + val21;
out[11] = val26 + val22;
out[27] = val27 + val23;
out[ 7] = val28 + val18;
out[23] = val29 + val19;
out[15] = val30 + val17;
out[31] = val31;
}

View file

@ -103,9 +103,11 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
s->mdct_calc = ff_mdct_calc_c; s->mdct_calc = ff_mdct_calc_c;
#endif #endif
#if 0
if (ARCH_ARM) ff_fft_init_arm(s); if (ARCH_ARM) ff_fft_init_arm(s);
if (HAVE_ALTIVEC) ff_fft_init_altivec(s); if (HAVE_ALTIVEC) ff_fft_init_altivec(s);
if (HAVE_MMX) ff_fft_init_mmx(s); if (HAVE_MMX) ff_fft_init_mmx(s);
#endif
for(j=4; j<=nbits; j++) { for(j=4; j<=nbits; j++) {
ff_init_ff_cos_tabs(j); ff_init_ff_cos_tabs(j);

View file

@ -23,7 +23,7 @@
#define AVCODEC_FFT_H #define AVCODEC_FFT_H
#include <stdint.h> #include <stdint.h>
#include "config.h" //#include "config.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "avfft.h" #include "avfft.h"

View file

@ -79,11 +79,11 @@ enum AVMediaType {
}; };
#include "common.h" #include "common.h"
#include "error.h" //#include "error.h"
#include "mathematics.h" #include "mathematics.h"
#include "rational.h" //#include "rational.h"
#include "intfloat_readwrite.h" //#include "intfloat_readwrite.h"
#include "log.h" #include "log.h"
#include "pixfmt.h" //#include "pixfmt.h"
#endif /* AVUTIL_AVUTIL_H */ #endif /* AVUTIL_AVUTIL_H */

View file

@ -130,6 +130,7 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c){
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
} }
#if 0
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
int64_t b= bq.num * (int64_t)cq.den; int64_t b= bq.num * (int64_t)cq.den;
int64_t c= cq.num * (int64_t)bq.den; int64_t c= cq.num * (int64_t)bq.den;
@ -143,6 +144,7 @@ int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1; if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
return 0; return 0;
} }
#endif
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){ int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){
int64_t c= (a-b) & (mod-1); int64_t c= (a-b) & (mod-1);

View file

@ -24,7 +24,7 @@
#include <stdint.h> #include <stdint.h>
#include <math.h> #include <math.h>
#include "attributes.h" #include "attributes.h"
#include "rational.h" //#include "rational.h"
#ifndef M_E #ifndef M_E
#define M_E 2.7182818284590452354 /* e */ #define M_E 2.7182818284590452354 /* e */
@ -87,7 +87,7 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons
/** /**
* Rescale a 64-bit integer by 2 rational numbers. * Rescale a 64-bit integer by 2 rational numbers.
*/ */
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; //int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
/** /**
* Compare 2 timestamps each in its own timebases. * Compare 2 timestamps each in its own timebases.
@ -95,7 +95,7 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
* is outside the int64_t range when represented in the others timebase. * is outside the int64_t range when represented in the others timebase.
* @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
*/ */
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b); //int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
/** /**
* Compare 2 integers modulo mod. * Compare 2 integers modulo mod.

View file

@ -24,7 +24,7 @@
* default memory allocator for libavutil * default memory allocator for libavutil
*/ */
#include "config.h" //#include "config.h"
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -150,7 +150,7 @@ void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order)
double pa[MAX_LP_HALF_ORDER+1], qa[MAX_LP_HALF_ORDER+1]; double pa[MAX_LP_HALF_ORDER+1], qa[MAX_LP_HALF_ORDER+1];
float *lpc2 = lpc + (lp_half_order << 1) - 1; float *lpc2 = lpc + (lp_half_order << 1) - 1;
assert(lp_half_order <= MAX_LP_HALF_ORDER); //assert(lp_half_order <= MAX_LP_HALF_ORDER);
ff_lsp2polyf(lsp, pa, lp_half_order); ff_lsp2polyf(lsp, pa, lp_half_order);
ff_lsp2polyf(lsp + 1, qa, lp_half_order); ff_lsp2polyf(lsp + 1, qa, lp_half_order);

View file

@ -0,0 +1,182 @@
/*
* simple math operations
* Copyright (c) 2001, 2002 Fabrice Bellard
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
*
* 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
*/
#ifndef AVCODEC_MATHOPS_H
#define AVCODEC_MATHOPS_H
#include "libavutil/common.h"
#if ARCH_ARM
# include "arm/mathops.h"
#elif ARCH_AVR32
# include "avr32/mathops.h"
#elif ARCH_BFIN
# include "bfin/mathops.h"
#elif ARCH_MIPS
# include "mips/mathops.h"
#elif ARCH_PPC
# include "ppc/mathops.h"
#elif ARCH_X86
# include "x86/mathops.h"
#endif
/* generic implementation */
#ifndef MULL
# define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
#endif
#ifndef MULH
//gcc 3.4 creates an incredibly bloated mess out of this
//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
static av_always_inline int MULH(int a, int b){
return ((int64_t)(a) * (int64_t)(b))>>32;
}
#endif
#ifndef UMULH
static av_always_inline unsigned UMULH(unsigned a, unsigned b){
return ((uint64_t)(a) * (uint64_t)(b))>>32;
}
#endif
#ifndef MUL64
# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
#endif
#ifndef MAC64
# define MAC64(d, a, b) ((d) += MUL64(a, b))
#endif
#ifndef MLS64
# define MLS64(d, a, b) ((d) -= MUL64(a, b))
#endif
/* signed 16x16 -> 32 multiply add accumulate */
#ifndef MAC16
# define MAC16(rt, ra, rb) rt += (ra) * (rb)
#endif
/* signed 16x16 -> 32 multiply */
#ifndef MUL16
# define MUL16(ra, rb) ((ra) * (rb))
#endif
#ifndef MLS16
# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
#endif
/* median of 3 */
#ifndef mid_pred
#define mid_pred mid_pred
static inline av_const int mid_pred(int a, int b, int c)
{
#if 0
int t= (a-b)&((a-b)>>31);
a-=t;
b+=t;
b-= (b-c)&((b-c)>>31);
b+= (a-b)&((a-b)>>31);
return b;
#else
if(a>b){
if(c>b){
if(c>a) b=a;
else b=c;
}
}else{
if(b>c){
if(c>a) b=c;
else b=a;
}
}
return b;
#endif
}
#endif
#ifndef sign_extend
static inline av_const int sign_extend(int val, unsigned bits)
{
return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
}
#endif
#ifndef zero_extend
static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
{
return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
}
#endif
#ifndef COPY3_IF_LT
#define COPY3_IF_LT(x, y, a, b, c, d)\
if ((y) < (x)) {\
(x) = (y);\
(a) = (b);\
(c) = (d);\
}
#endif
#ifndef NEG_SSR32
# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
#endif
#ifndef NEG_USR32
# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
#endif
#if HAVE_BIGENDIAN
# ifndef PACK_2U8
# define PACK_2U8(a,b) (((a) << 8) | (b))
# endif
# ifndef PACK_4U8
# define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
# endif
# ifndef PACK_2U16
# define PACK_2U16(a,b) (((a) << 16) | (b))
# endif
#else
# ifndef PACK_2U8
# define PACK_2U8(a,b) (((b) << 8) | (a))
# endif
# ifndef PACK_4U2
# define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
# endif
# ifndef PACK_2U16
# define PACK_2U16(a,b) (((b) << 16) | (a))
# endif
#endif
#ifndef PACK_2S8
# define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)
#endif
#ifndef PACK_4S8
# define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)
#endif
#ifndef PACK_2S16
# define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)
#endif
#endif /* AVCODEC_MATHOPS_H */

View file

@ -39,7 +39,7 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n)
double local_window[FF_KBD_WINDOW_MAX]; double local_window[FF_KBD_WINDOW_MAX];
double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
assert(n <= FF_KBD_WINDOW_MAX); //assert(n <= FF_KBD_WINDOW_MAX);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
tmp = i * (n - i) * alpha2; tmp = i * (n - i) * alpha2;

View file

@ -0,0 +1,60 @@
/*
* Header file for hardcoded MDCT tables
*
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
* 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 <assert.h>
// do not use libavutil/libm.h since this is compiled both
// for the host and the target and config.h is only valid for the target
#include <math.h>
#include "libavutil/attributes.h"
#if !CONFIG_HARDCODED_TABLES
SINETABLE( 32);
SINETABLE( 64);
SINETABLE( 128);
SINETABLE( 256);
SINETABLE( 512);
SINETABLE(1024);
SINETABLE(2048);
SINETABLE(4096);
#else
#include "libavcodec/mdct_tables.h"
#endif
SINETABLE_CONST float * const ff_sine_windows[] = {
NULL, NULL, NULL, NULL, NULL, // unused
ff_sine_32 , ff_sine_64 ,
ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
};
// Generate a sine window.
av_cold void ff_sine_window_init(float *window, int n) {
int i;
for(i = 0; i < n; i++)
window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
}
av_cold void ff_init_ff_sine_windows(int index) {
assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows));
#if !CONFIG_HARDCODED_TABLES
ff_sine_window_init(ff_sine_windows[index], 1 << index);
#endif
}

View file

@ -0,0 +1,133 @@
/*
* (I)RDFT transforms
* Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com>
*
* 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 <stdlib.h>
#include <math.h>
#include "libavutil/mathematics.h"
#include "fft.h"
/**
* @file
* (Inverse) Real Discrete Fourier Transforms.
*/
/* sin(2*pi*x/n) for 0<=x<n/4, followed by n/2<=x<3n/4 */
#if !CONFIG_HARDCODED_TABLES
SINTABLE(16);
SINTABLE(32);
SINTABLE(64);
SINTABLE(128);
SINTABLE(256);
SINTABLE(512);
SINTABLE(1024);
SINTABLE(2048);
SINTABLE(4096);
SINTABLE(8192);
SINTABLE(16384);
SINTABLE(32768);
SINTABLE(65536);
#endif
SINTABLE_CONST FFTSample * const ff_sin_tabs[] = {
NULL, NULL, NULL, NULL,
ff_sin_16, ff_sin_32, ff_sin_64, ff_sin_128, ff_sin_256, ff_sin_512, ff_sin_1024,
ff_sin_2048, ff_sin_4096, ff_sin_8192, ff_sin_16384, ff_sin_32768, ff_sin_65536,
};
/** Map one real FFT into two parallel real even and odd FFTs. Then interleave
* the two real FFTs into one complex FFT. Unmangle the results.
* ref: http://www.engineeringproductivitytools.com/stuff/T0001/PT10.HTM
*/
static void ff_rdft_calc_c(RDFTContext* s, FFTSample* data)
{
int i, i1, i2;
FFTComplex ev, od;
const int n = 1 << s->nbits;
const float k1 = 0.5;
const float k2 = 0.5 - s->inverse;
const FFTSample *tcos = s->tcos;
const FFTSample *tsin = s->tsin;
if (!s->inverse) {
ff_fft_permute(&s->fft, (FFTComplex*)data);
ff_fft_calc(&s->fft, (FFTComplex*)data);
}
/* i=0 is a special case because of packing, the DC term is real, so we
are going to throw the N/2 term (also real) in with it. */
ev.re = data[0];
data[0] = ev.re+data[1];
data[1] = ev.re-data[1];
for (i = 1; i < (n>>2); i++) {
i1 = 2*i;
i2 = n-i1;
/* Separate even and odd FFTs */
ev.re = k1*(data[i1 ]+data[i2 ]);
od.im = -k2*(data[i1 ]-data[i2 ]);
ev.im = k1*(data[i1+1]-data[i2+1]);
od.re = k2*(data[i1+1]+data[i2+1]);
/* Apply twiddle factors to the odd FFT and add to the even FFT */
data[i1 ] = ev.re + od.re*tcos[i] - od.im*tsin[i];
data[i1+1] = ev.im + od.im*tcos[i] + od.re*tsin[i];
data[i2 ] = ev.re - od.re*tcos[i] + od.im*tsin[i];
data[i2+1] = -ev.im + od.im*tcos[i] + od.re*tsin[i];
}
data[2*i+1]=s->sign_convention*data[2*i+1];
if (s->inverse) {
data[0] *= k1;
data[1] *= k1;
ff_fft_permute(&s->fft, (FFTComplex*)data);
ff_fft_calc(&s->fft, (FFTComplex*)data);
}
}
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
{
int n = 1 << nbits;
int i;
const double theta = (trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/n;
s->nbits = nbits;
s->inverse = trans == IDFT_C2R || trans == DFT_C2R;
s->sign_convention = trans == IDFT_R2C || trans == DFT_C2R ? 1 : -1;
if (nbits < 4 || nbits > 16)
return -1;
if (ff_fft_init(&s->fft, nbits-1, trans == IDFT_C2R || trans == IDFT_R2C) < 0)
return -1;
ff_init_ff_cos_tabs(nbits);
s->tcos = ff_cos_tabs[nbits];
s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2);
#if !CONFIG_HARDCODED_TABLES
for (i = 0; i < (n>>2); i++) {
s->tsin[i] = sin(i*theta);
}
#endif
s->rdft_calc = ff_rdft_calc_c;
//if (ARCH_ARM) ff_rdft_init_arm(s);
return 0;
}
av_cold void ff_rdft_end(RDFTContext *s)
{
ff_fft_end(&s->fft);
}

File diff suppressed because it is too large Load diff

View file

@ -2015,7 +2015,7 @@ static av_cold void wmavoice_flush(AVCodecContext *ctx)
memset(s->denoise_filter_cache, 0, sizeof(s->denoise_filter_cache)); memset(s->denoise_filter_cache, 0, sizeof(s->denoise_filter_cache));
} }
} }
#if 0
AVCodec wmavoice_decoder = { AVCodec wmavoice_decoder = {
"wmavoice", "wmavoice",
AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_AUDIO,
@ -2029,3 +2029,9 @@ AVCodec wmavoice_decoder = {
.flush = wmavoice_flush, .flush = wmavoice_flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"), .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
}; };
#endif
int main(void)
{
return 0;
}