├── .gitignore ├── CHANGELOG ├── COPYRIGHT ├── Makefile ├── aacplusenc.1 ├── aacplusenc.c ├── adts.h ├── au_channel.h ├── configure ├── debian ├── changelog ├── compat ├── control └── rules ├── libaacenc ├── Makefile ├── aac_ram.c ├── aac_ram.h ├── aac_rom.c ├── aac_rom.h ├── aacenc.c ├── aacenc.h ├── adj_thr.c ├── adj_thr.h ├── adj_thr_data.h ├── band_nrg.c ├── band_nrg.h ├── bit_cnt.c ├── bit_cnt.h ├── bitenc.c ├── bitenc.h ├── block_switch.c ├── block_switch.h ├── channel_map.c ├── channel_map.h ├── counters.h ├── dyn_bits.c ├── dyn_bits.h ├── grp_data.c ├── grp_data.h ├── interface.c ├── interface.h ├── line_pe.c ├── line_pe.h ├── minmax.h ├── ms_stereo.c ├── ms_stereo.h ├── pre_echo_control.c ├── pre_echo_control.h ├── psy_configuration.c ├── psy_configuration.h ├── psy_const.h ├── psy_data.h ├── psy_main.c ├── psy_main.h ├── qc_data.h ├── qc_main.c ├── qc_main.h ├── quantize.c ├── quantize.h ├── sf_estim.c ├── sf_estim.h ├── spreading.c ├── spreading.h ├── stat_bits.c ├── stat_bits.h ├── stprepro.c ├── stprepro.h ├── tns.c ├── tns.h ├── tns_func.h ├── tns_param.c ├── tns_param.h ├── transform.c └── transform.h ├── libbitbuf ├── FFR_bitbuffer.h ├── Makefile └── bitbuffer.c ├── libfr ├── FloatFR.h ├── Makefile ├── cfftn.c ├── cfftn.h ├── counters.h └── transcendent.c ├── libresamp ├── Makefile ├── iir32resample.c ├── iir32resample.h ├── resampler.c └── resampler.h └── libsbrenc ├── Makefile ├── bit_sbr.c ├── bit_sbr.h ├── cmondata.h ├── code_env.c ├── code_env.h ├── env_bit.c ├── env_bit.h ├── env_est.c ├── env_est.h ├── fram_gen.c ├── fram_gen.h ├── freq_sca.c ├── freq_sca.h ├── hybrid.c ├── hybrid.h ├── invf_est.c ├── invf_est.h ├── mh_det.c ├── mh_det.h ├── nf_est.c ├── nf_est.h ├── ps_bitenc.c ├── ps_bitenc.h ├── ps_enc.c ├── ps_enc.h ├── qmf_enc.c ├── qmf_enc.h ├── sbr.h ├── sbr_def.h ├── sbr_main.c ├── sbr_main.h ├── sbr_misc.c ├── sbr_misc.h ├── sbr_ram.c ├── sbr_ram.h ├── sbr_rom.c ├── sbr_rom.h ├── ton_corr.c ├── ton_corr.h ├── tran_det.c └── tran_det.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | /aacplusenc 4 | /config.* 5 | /test-* 6 | /*.aac 7 | /*.wav 8 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | debian/changelog -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | AAC encoder and SBR algorithm 2 | Copyright (c) Coding Technologies 2003 3 | All Rights Reserved 4 | 5 | Wav and ADTS header handling routines 6 | Copyright (c) Matteo Croce 2006-2007 7 | All Rights Reserved -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include config.mak 2 | TOPDIR=$(CURDIR) 3 | export CFLAGS=-Wall -pedantic -O3 -ftree-vectorize -I$(TOPDIR)/libaacenc -I$(TOPDIR)/libbitbuf -I$(TOPDIR)/libfr -I$(TOPDIR)/libsbrenc -I$(TOPDIR)/libresamp $(EXTRACFLAGS) 4 | SUBDIRS=libaacenc libbitbuf libfr libsbrenc libresamp 5 | LIBS=libaacenc/libaacenc.a libbitbuf/libbitbuf.a libfr/libfr.a libsbrenc/libsbrenc.a libresamp/libresamp.a 6 | TARGET=aacplusenc 7 | 8 | LDFLAGS=-L$(TOPDIR)/libaacenc -L$(TOPDIR)/libbitbuf -L$(TOPDIR)/libfr -L$(TOPDIR)/libsbrenc -L$(TOPDIR)/libresamp 9 | LDLIBS=-laacenc -lbitbuf -lfr -lsbrenc -lresamp -lm 10 | 11 | ifdef FFTW3 12 | LDLIBS+=-lfftw3f 13 | endif 14 | 15 | 16 | INSTDIR=/usr/local 17 | 18 | %.a: 19 | $(MAKE) -C $$(dirname $*) 20 | 21 | all: config.h $(TARGET) 22 | 23 | $(TARGET): $(LIBS) au_channel.h adts.h aacplusenc.c 24 | for i in $(LIBS) ; do \ 25 | $(MAKE) $$i ;\ 26 | done 27 | $(CC) $(CFLAGS) -o $(TARGET) aacplusenc.c $(LDFLAGS) $(LDLIBS) 28 | 29 | .PHONY: clean test 30 | clean: 31 | rm -f $(ofiles) $(TARGET) config.* test-* 32 | for i in $(SUBDIRS) ; do \ 33 | $(MAKE) -C $$i clean ;\ 34 | done 35 | 36 | install: all 37 | mkdir -p $(INSTDIR)/bin 38 | cp aacplusenc $(INSTDIR)/bin 39 | strip -s -R.comment $(INSTDIR)/bin/aacplusenc 40 | 41 | MONO:=pan=1:0.5:0.5:channels=1 42 | MPLAYER:=mplayer -msglevel all=0:statusline=5 43 | AO:=-ao pcm:fast:file 44 | 45 | test: all 46 | $(MPLAYER) -af lavcresample=32000:$(MONO) $(AO)=test32m.wav test.wav 47 | $(MPLAYER) -af lavcresample=44100:$(MONO) $(AO)=test44m.wav test.wav 48 | $(MPLAYER) -af lavcresample=48000:$(MONO) $(AO)=test48m.wav test.wav 49 | 50 | $(MPLAYER) -af lavcresample=32000 $(AO)=test32s.wav test.wav 51 | $(MPLAYER) -af lavcresample=44100 $(AO)=test44s.wav test.wav 52 | $(MPLAYER) -af lavcresample=48000 $(AO)=test48s.wav test.wav 53 | 54 | ./aacplusenc test32m.wav test32m.aac 18 55 | ./aacplusenc test44m.wav test44m.aac 40 56 | ./aacplusenc test48m.wav test48m.aac 40 57 | 58 | ./aacplusenc test32s.wav test32s.aac 18 59 | ./aacplusenc test44s.wav test44s.aac 48 60 | ./aacplusenc test48s.wav test48s.aac 48 61 | 62 | $(MPLAYER) test32m.aac 63 | $(MPLAYER) test44m.aac 64 | $(MPLAYER) test48m.aac 65 | 66 | $(MPLAYER) test32s.aac 67 | $(MPLAYER) test44s.aac 68 | $(MPLAYER) test48s.aac 69 | 70 | config.mak: 71 | ./configure 72 | -------------------------------------------------------------------------------- /aacplusenc.1: -------------------------------------------------------------------------------- 1 | .TH "AACPLUSENC" "1" "19 January 2008" "Matteo Croce" "Debian GNU/Linux" 2 | .SH "NAME" 3 | aacplusenc \- AAC+ encoder 4 | .SH "SYNOPSIS" 5 | .B aacplusenc 6 | .I inputfile.wav outputfile.aac bitrate 7 | .PP 8 | .SH "DESCRIPTION" 9 | \fBaacplusenc\fP is an \fIHE\-AACv2\fP encoder. 10 | 11 | It accepts as input a \fIWAV\fP file and outputs an \fIAAC\fP file, with \fIRAW ADTS\fP header. 12 | .PP 13 | .SH "OPTIONS" 14 | .TP 8 15 | .B inputfile.wav 16 | The file to encode 17 | .TP 8 18 | .B outputfile.aac 19 | The desired filename of the encoded file 20 | .TP 8 21 | .B bitrate 22 | The encoding bitrate, in kbps 23 | .TP 8 24 | both inputfile and outputfile can be \fI"\-"\fP to specify stdin and stdout respectively 25 | .SH "NOTES" 26 | On 64 bit platform there are issues with Parametric Stereo (PS) an algorithm to give 27 | better quality on stereo tracks. 28 | .PP 29 | As PS is enabled for bitrates lower than 45 kbps, a 64 bit build of \fBaacplusenc\fP can only encode 30 | mono tracks or stereo tracks encoded with bitrates of 45 kbps and over 31 | .SH "AUTHOR" 32 | \fBaacplusenc\fP is written by Matteo Croce <\fIrootkit85@yahoo.it\fP> and its based on 3GPP sources. 33 | 34 | Get the latest version from \fIhttps://github.com/teknoraver/aacplusenc\fP 35 | 36 | The 3GPP project used by \fBaacplusenc\fP: for more info visit \fIhttp://www.3gpp.org/ftp/Specs/archive/26_series/26.410/\fP 37 | 38 | AAC+ is licensed by Coding Technologies, for info read: \fIhttp://codtech.vhost.noris.net/products/aacPlus.htm\fP 39 | 40 | This manpage was written by Matteo Croce <\fIrootkit85@yahoo.it\fP> and licensed under the terms of the GNU General Public License. 41 | -------------------------------------------------------------------------------- /adts.h: -------------------------------------------------------------------------------- 1 | /* 2 | adts 3 | 4 | Copyright (C) Matteo Croce 5 | 6 | */ 7 | 8 | #define ADTS_HEADER_SIZE 7 9 | 10 | #include "aacenc.h" 11 | 12 | static const int aac_sampling_freq[16] = {96000, 88200, 64000, 48000, 44100, 32000, 13 | 24000, 22050, 16000, 12000, 11025, 8000}; 14 | static const char id = 0, profile = 1; 15 | 16 | void adts_hdr(char *adts, AACENC_CONFIG *config) { 17 | char srate_idx = 15, i; 18 | 19 | /* sync word, 12 bits */ 20 | adts[0] = (char)0xff; 21 | adts[1] = (char)0xf0; 22 | 23 | /* ID, 1 bit */ 24 | adts[1] |= id << 3; 25 | /* layer: 2 bits = 00 */ 26 | 27 | /* protection absent: 1 bit = 1 (ASSUMPTION!) */ 28 | adts[1] |= 1; 29 | 30 | /* profile, 2 bits */ 31 | adts[2] = profile << 6; 32 | 33 | for (i = 0; i < 16; i++) 34 | if (config->sampleRate >= (aac_sampling_freq[i] - 1000)) { 35 | srate_idx = i; 36 | break; 37 | } 38 | 39 | /* sampling frequency index, 4 bits */ 40 | adts[2] |= srate_idx << 2; 41 | 42 | /* private, 1 bit = 0 (ASSUMPTION!) */ 43 | 44 | /* channels, 3 bits */ 45 | adts[2] |= (config->nChannelsOut & 4) >> 2; 46 | adts[3] = (config->nChannelsOut & 3) << 6; 47 | 48 | /* adts buffer fullness, 11 bits, 0x7ff = VBR (ASSUMPTION!) */ 49 | adts[6] = (char)0xfc; 50 | } 51 | 52 | void adts_hdr_up(char *adts, unsigned short len) 53 | { 54 | /* frame length, 13 bits */ 55 | len += 7; 56 | adts[3] = (adts[3] & 0xfc) | (len >> 11); 57 | adts[4] = len >> 3; 58 | adts[5] = (len & 7) << 5 | (char)0x1f; 59 | } 60 | -------------------------------------------------------------------------------- /au_channel.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "config.h" 5 | 6 | #define b2l(A) ((((unsigned short)(A) & 0xff00) >> 8) | (((unsigned short)(A) & 0x00ff) << 8)) 7 | 8 | #define WAV_HEADER_SIZE 44 9 | 10 | typedef struct { 11 | int sampleRate; 12 | int nChannels; 13 | long nSamples; 14 | } WavInfo; 15 | 16 | FILE* AuChannelOpen (const char* filename, WavInfo* info) 17 | { 18 | unsigned char header[WAV_HEADER_SIZE]; 19 | FILE *handle; 20 | 21 | if (!strcmp(filename,"-")) 22 | handle = stdin; 23 | else 24 | handle = fopen(filename, "rb"); 25 | 26 | if(!handle) 27 | return NULL; 28 | 29 | if(fread(header, 1, WAV_HEADER_SIZE, handle) != WAV_HEADER_SIZE) 30 | return 0; 31 | 32 | info->nSamples = (header[4] | (header[5] << 8) | (header[6] << 16) | (header[7] << 24)) + 8; 33 | info->nChannels = header[22] | header[23] << 8; 34 | info->sampleRate = header[24] | header[25] << 8 | header[26] << 12 | header[27] << 16; 35 | return handle; 36 | } 37 | 38 | void AuChannelClose (FILE *audioChannel) 39 | { 40 | fclose(audioChannel); 41 | } 42 | 43 | size_t AuChannelReadShort(FILE *audioChannel, short *samples, int nSamples, int *readed) 44 | { 45 | *readed = fread(samples, 2, nSamples, audioChannel); 46 | #ifdef _BE_ARCH 47 | { 48 | int i; 49 | for(i = 0; i < *readed; i++) 50 | samples[i] = b2l(samples[i]); 51 | } 52 | #endif 53 | return *readed <= 0; 54 | } 55 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | >config.mak 4 | cat >config.h <<'EOF' 5 | #ifndef _CONFIG_H 6 | #define _CONFIG_H 7 | EOF 8 | 9 | echo -n 'Checking for libfftw3f...' 10 | 11 | gcc -o test-fft -Wall -x c -I/usr/local/include -L/usr/local/lib - -lfftw3f <<'EOF' 12 | #include 13 | 14 | #define N 128 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | fftwf_complex *data; 19 | fftwf_plan p; 20 | 21 | data = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * N); 22 | p = fftwf_plan_dft_1d(N, data, data, FFTW_FORWARD, FFTW_ESTIMATE); 23 | 24 | fftwf_execute(p); 25 | 26 | fftwf_destroy_plan(p); 27 | fftwf_free(data); 28 | return 0; 29 | } 30 | EOF 31 | 32 | if ./test-fft 33 | then 34 | echo OK 35 | echo '#define _FFTW3' >> config.h 36 | echo 'export FFTW3=1' >> config.mak 37 | fi 38 | 39 | echo -n 'Detecting endianness...' 40 | 41 | gcc -o test-endian -Wall -x c - <<'EOF' 42 | #include 43 | #include 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | uint32_t dword = 0x11223344; 48 | uint8_t *byte = (uint8_t*)&dword; 49 | 50 | if(byte[0] == 0x44 && byte[1] == 0x33 && byte[2] == 0x22 && byte[3] == 0x11) { 51 | printf("EL"); 52 | return 0; 53 | } 54 | 55 | if(byte[0] == 0x11 && byte[1] == 0x22 && byte[2] == 0x33 && byte[3] == 0x44) { 56 | printf("BE"); 57 | return 0; 58 | } 59 | return 1; 60 | } 61 | EOF 62 | 63 | if ./test-endian > /dev/null 64 | then 65 | ENDIAN=$(./test-endian) 66 | if [ $ENDIAN = EL ] 67 | then 68 | echo 'Little Endian' 69 | echo '#define _EL_ARCH' >> config.h 70 | elif [ $ENDIAN = BE ] 71 | then 72 | echo 'Big Endian' 73 | echo '#define _BE_ARCH' >> config.h 74 | fi 75 | fi 76 | 77 | echo '#endif' >> config.h 78 | 79 | echo 'Now run make' 80 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | aacplusenc (0.17.4) jaunty; urgency=low 2 | 3 | * Fix ppc encoding 4 | * Jaunty upload 5 | 6 | -- Matteo Croce Mon, 18 May 2009 18:08:17 +0200 7 | 8 | aacplusenc (0.17.3) intrepid; urgency=low 9 | 10 | * Fix possibly corrupted ADTS header 11 | * Intrepid upload 12 | 13 | -- Matteo Croce Wed, 29 Oct 2008 23:50:12 +0100 14 | 15 | aacplusenc (0.17.2) intrepid; urgency=low 16 | 17 | * Intrepid upload 18 | 19 | -- Matteo Croce Sat, 13 Sep 2008 01:22:11 +0200 20 | 21 | aacplusenc (0.17.1) hardy; urgency=low 22 | 23 | * Updated homepage URL 24 | 25 | -- Matteo Croce Thu, 17 Jul 2008 16:44:46 +0200 26 | 27 | aacplusenc (0.17) hardy; urgency=high 28 | 29 | * Fixed 64 bit encoding 30 | 31 | -- Matteo Croce Wed, 04 Jun 2008 00:42:44 +0200 32 | 33 | aacplusenc (0.16.3) hardy; urgency=low 34 | 35 | * Fix type in au_channel.h 36 | 37 | -- Matteo Croce Sun, 17 Feb 2008 15:55:51 +0100 38 | 39 | aacplusenc (0.16.2) hardy; urgency=low 40 | 41 | * Added compile time checks for endiannes and FFTW3 42 | 43 | -- Matteo Croce Thu, 14 Feb 2008 16:32:42 +0100 44 | 45 | aacplusenc (0.16.1) hardy; urgency=low 46 | 47 | * Fix BSD build 48 | 49 | -- Matteo Croce Tue, 12 Feb 2008 17:39:16 +0100 50 | 51 | aacplusenc (0.16) hardy; urgency=low 52 | 53 | * Added support for bitrate up to 64 and 63 kbit for 44.1 and 48 kHz 54 | 55 | -- Matteo Croce Thu, 31 Jan 2008 18:48:17 +0100 56 | 57 | aacplusenc (0.15) hardy; urgency=low 58 | 59 | * Full 64 bit support 60 | 61 | -- Matteo Croce Wed, 23 Jan 2008 20:14:58 +0100 62 | 63 | aacplusenc (0.14.2) hardy; urgency=low 64 | 65 | * Rebuild ubuntu package with sane dpkg-deb arguments 66 | 67 | -- Matteo Croce Wed, 23 Jan 2008 16:01:31 +0100 68 | 69 | aacplusenc (0.14.1) hardy; urgency=low 70 | 71 | * Fix endiannes under BSD 72 | 73 | -- Matteo Croce Wed, 23 Jan 2008 01:20:42 +0100 74 | 75 | aacplusenc (0.14) hardy; urgency=low 76 | 77 | * Small speedup (~9%) 78 | * Better packaging 79 | 80 | -- Matteo Croce Tue, 22 Jan 2008 03:26:28 +0100 81 | 82 | aacplusenc (0.13.2) hardy; urgency=low 83 | 84 | * Fix manpage path 85 | 86 | -- Matteo Croce Sun, 20 Jan 2008 04:18:55 +0100 87 | 88 | aacplusenc (0.13.1-1~gutsy1) gutsy; urgency=low 89 | 90 | * Gutsy upload 91 | 92 | -- Matteo Croce Sun, 20 Jan 2008 00:15:31 +0100 93 | 94 | aacplusenc (0.13.1) hardy; urgency=low 95 | 96 | * Added changelog 97 | 98 | -- Matteo Croce Sat, 19 Jan 2008 23:56:44 +0100 99 | 100 | aacplusenc (0.13) gutsy; urgency=low 101 | 102 | * All channels/samplerates/bitrates combinations works now 103 | * A 64 bit build can encode a mono track, or an high bitrate one (> 44kbit) 104 | 105 | -- Matteo Croce Tue, 15 Jan 2008 01:23:42 +0100 106 | 107 | aacplusenc (0.12.1) gutsy; urgency=low 108 | 109 | * Fix Win32 build 110 | 111 | -- Matteo Croce Mon, 17 Dec 2007 17:36:39 +0100 112 | 113 | aacplusenc (0.12) gutsy; urgency=low 114 | 115 | * Fixed encodings higher tha 44 kbit/s 116 | 117 | -- Matteo Croce Thu, 06 Dec 2007 02:16:07 +0100 118 | 119 | aacplusenc (0.11) gutsy; urgency=low 120 | 121 | * Enable 64 bit builds, but only for mono encodings 122 | 123 | -- Matteo Croce Tue, 04 Dec 2007 17:53:59 +0100 124 | 125 | aacplusenc (0.10) gutsy; urgency=low 126 | 127 | * Good speed increase (25-33%) against older version 128 | * Keep legacy builtin FFT, enable it with the NOFFTW3 make flag 129 | 130 | -- Matteo Croce Sat, 01 Dec 2007 18:10:30 +0100 131 | 132 | aacplusenc (0.9) gutsy; urgency=low 133 | 134 | * Trashed the builtin FFT and used the GPL one FFTW3 which is faster 135 | 136 | -- Matteo Croce Fri, 30 Nov 2007 02:16:58 +0100 137 | 138 | aacplusenc (0.8) gutsy; urgency=low 139 | 140 | * removed the last m/s parameter. Stereo or mono encoding 141 | is done according to source number of channels 142 | * now the target bitrate is expressed in kbit, not bits 143 | 144 | -- Matteo Croce Tue, 20 Nov 2007 18:35:37 +0100 145 | 146 | aacplusenc (0.7) gutsy; urgency=low 147 | 148 | * Adding safety code to avoid encoder runtime-assertion 149 | 150 | -- Matteo Croce Fri, 19 Oct 2007 02:09:05 +0200 151 | 152 | aacplusenc (0.6) feisty; urgency=low 153 | 154 | * fixed percentage display 155 | * copied missing b2l macro from old libaudio/au_channel.h 156 | * removed unneeded libaudio and fixed CFLAGS, one -ftree-vectorize should be 157 | enough in Makefile 158 | 159 | -- Bernhard Geier Thu, 19 Apr 2007 23:38:24 +0200 160 | 161 | aacplusenc (0.5) feisty; urgency=low 162 | 163 | * Ported the I/O read/write to fread/fwrite 164 | * Reduced I/O calls, it encodes much faster now 165 | * Removed unused au_channel functions 166 | * Added percent indicator, needed to use aacplusenc as backend 167 | 168 | -- Matteo Croce Mon, 19 Mar 2007 17:40:13 +0100 169 | 170 | aacplusenc (0.4) unstable; urgency=low 171 | 172 | * New bitrate tables from 3gpp.org 173 | 174 | -- Matteo Croce Thu, 14 Dec 2006 00:26:01 +0100 175 | 176 | mp4tools (0.3) unstable; urgency=low 177 | 178 | * Removed libisomediafile, now aacplusenc saves raw ADTS streams 179 | * Removed unused downsampling library 180 | * Now encoding parameters are taken from the WAV header 181 | 182 | -- Matteo Croce Wed, 7 Jun 2006 20:28:35 +0200 183 | 184 | mp4tools (0.2) unstable; urgency=low 185 | 186 | * Replaced real's encoder with an opensource, better one 187 | 188 | -- Matteo Croce Tue, 6 Jun 2006 18:44:48 +0200 189 | 190 | mp4tools (0.1) unstable; urgency=low 191 | 192 | * Initial release 193 | 194 | -- Matteo Croce Tue, 23 May 2006 15:02:07 +0200 195 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: aacplusenc 2 | Build-Depends: debhelper, fftw3-dev 3 | Section: sound 4 | Priority: optional 5 | Standards-Version: 3.7.3 6 | Homepage: http://teknoraver.net/software/mp4tools/ 7 | Maintainer: Matteo Croce 8 | 9 | Package: aacplusenc 10 | Architecture: any 11 | Section: sound 12 | Priority: optional 13 | Depends: ${shlibs:Depends} 14 | Description: High-Efficency AAC (AAC+) Encoder 15 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | version := $(shell awk '/Package/{print$$2}' debian/control) 4 | 5 | build: 6 | $(MAKE) -j$(shell grep -c ^processor /proc/cpuinfo) 7 | 8 | binary: binary-arch 9 | 10 | binary-arch: build install 11 | 12 | binary-indep: 13 | 14 | install: build 15 | $(MAKE) INSTDIR=$(CURDIR)/debian/${version}/usr install 16 | dh_testdir 17 | dh_testroot 18 | dh_installchangelogs 19 | dh_installman aacplusenc.1 20 | dh_strip 21 | dh_installdeb 22 | dh_shlibdeps 23 | dh_gencontrol 24 | dh_md5sums 25 | dh_compress 26 | dh_builddeb -- -Zbzip2 27 | 28 | clean: 29 | $(MAKE) clean 30 | dh_clean 31 | -------------------------------------------------------------------------------- /libaacenc/Makefile: -------------------------------------------------------------------------------- 1 | #################################################################### 2 | # 3 | # Makefile for aac encoder - library 4 | # 5 | #################################################################### 6 | ################## user section: insert objlist here ####### 7 | LIB = libaacenc.a 8 | 9 | SRCS=$(wildcard *.c) 10 | 11 | OBJS = $(SRCS:.c=.o) 12 | 13 | $(LIB): $(OBJS) 14 | ar r $@ $(OBJS) 15 | 16 | all: $(LIB) 17 | 18 | clean: 19 | rm -f $(OBJS) $(LIB) 20 | -------------------------------------------------------------------------------- /libaacenc/aac_ram.c: -------------------------------------------------------------------------------- 1 | /* 2 | memory requirement in dynamic and static RAM 3 | */ 4 | 5 | #include 6 | #include "aac_ram.h" 7 | #include "aacenc.h" 8 | #include "psy_const.h" 9 | #include "FloatFR.h" 10 | #include "sbr_ram.h" 11 | 12 | /* 13 | Static memory areas, must not be overwritten in other sections of the encoder 14 | */ 15 | 16 | /* aac Encoder mdct delay buffer */ 17 | float mdctDelayBuffer[MAX_CHANNELS*BLOCK_SWITCHING_OFFSET]; 18 | 19 | /* 20 | these tables are initialized once at application start 21 | and are not touched thereafter 22 | */ 23 | 24 | int sideInfoTabLong[MAX_SFB_LONG + 1]; 25 | int sideInfoTabShort[MAX_SFB_SHORT + 1]; 26 | 27 | /* 28 | Dynamic memory areas, might be reused in other algorithm sections, 29 | */ 30 | 31 | 32 | /* quantized spectrum */ 33 | short *quantSpec = (short*)PsBuf3; 34 | 35 | /* scratch space for quantization */ 36 | float *expSpec = sbr_envIBuffer; /* FRAME_LEN_LONG values */ 37 | short *quantSpecTmp = (short*) &sbr_envIBuffer[FRAME_LEN_LONG]; 38 | 39 | /* scalefactors */ 40 | short *scf= (short*) &sbr_envIBuffer[2*FRAME_LEN_LONG]; /*[MAX_CHANNELS*MAX_GROUPED_SFB];*/ 41 | 42 | /* max spectral values pre sfb */ 43 | unsigned short *maxValueInSfb = (unsigned short*) &sbr_envIBuffer[2*FRAME_LEN_LONG+MAX_CHANNELS*MAX_GROUPED_SFB]; /* [MAX_CHANNELS*MAX_GROUPED_SFB]; */ 44 | 45 | -------------------------------------------------------------------------------- /libaacenc/aac_ram.h: -------------------------------------------------------------------------------- 1 | /* 2 | memory requirement in dynamic and static RAM 3 | */ 4 | 5 | #ifndef AAC_RAM_H 6 | #define AAC_RAM_H 7 | 8 | #include "psy_const.h" 9 | 10 | extern float mdctDelayBuffer[MAX_CHANNELS*BLOCK_SWITCHING_OFFSET]; 11 | 12 | extern int sideInfoTabLong[MAX_SFB_LONG + 1]; 13 | extern int sideInfoTabShort[MAX_SFB_SHORT + 1]; 14 | 15 | extern short *quantSpec; 16 | extern float *expSpec; 17 | extern short *quantSpecTmp; 18 | 19 | extern short *scf; 20 | extern unsigned short *maxValueInSfb; 21 | 22 | /* dynamic buffers of SBR that can be reused by the core */ 23 | extern float sbr_envRBuffer[]; 24 | extern float sbr_envIBuffer[]; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libaacenc/aac_rom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Declaration of constant tables 3 | */ 4 | #ifndef AAC_ROM_H 5 | #define AAC_ROM_H 6 | 7 | #include "psy_const.h" 8 | #include "tns_param.h" 9 | 10 | #define LD_FFT_TWIDDLE_TABLE_SIZE 9 11 | #define FFT_TWIDDLE_TABLE_SIZE (1 << LD_FFT_TWIDDLE_TABLE_SIZE) 12 | 13 | 14 | /* 15 | mdct 16 | */ 17 | extern const float LongWindowSine [FRAME_LEN_LONG]; 18 | extern const float ShortWindowSine [FRAME_LEN_SHORT]; 19 | extern const float LongWindowKBD [FRAME_LEN_LONG]; 20 | extern const float fftTwiddleTab[FFT_TWIDDLE_TABLE_SIZE+1]; 21 | 22 | 23 | 24 | /* 25 | quantizer 26 | */ 27 | extern const float quantTableQ[16]; 28 | extern const float quantTableE[17]; 29 | extern const float invQuantTableQ[16]; 30 | extern const float invQuantTableE[17]; 31 | #define MAX_POW4_3_TABLE 64 32 | extern const float pow4_3_tab[MAX_POW4_3_TABLE]; 33 | 34 | 35 | 36 | /* 37 | huffman 38 | */ 39 | extern const unsigned short huff_ltab1_2[3][3][3][3]; 40 | extern const unsigned short huff_ltab3_4[3][3][3][3]; 41 | extern const unsigned short huff_ltab5_6[9][9]; 42 | extern const unsigned short huff_ltab7_8[8][8]; 43 | extern const unsigned short huff_ltab9_10[13][13]; 44 | extern const unsigned short huff_ltab11[17][17]; 45 | extern const unsigned short huff_ltabscf[121]; 46 | extern const unsigned short huff_ctab1[3][3][3][3]; 47 | extern const unsigned short huff_ctab2[3][3][3][3]; 48 | extern const unsigned short huff_ctab3[3][3][3][3]; 49 | extern const unsigned short huff_ctab4[3][3][3][3]; 50 | extern const unsigned short huff_ctab5[9][9]; 51 | extern const unsigned short huff_ctab6[9][9]; 52 | extern const unsigned short huff_ctab7[8][8]; 53 | extern const unsigned short huff_ctab8[8][8]; 54 | extern const unsigned short huff_ctab9[13][13]; 55 | extern const unsigned short huff_ctab10[13][13]; 56 | extern const unsigned short huff_ctab11[17][17]; 57 | extern const unsigned long huff_ctabscf[121]; 58 | 59 | 60 | 61 | /* 62 | misc 63 | */ 64 | 65 | extern const unsigned char sfb_11025_long_1024[]; 66 | extern const unsigned char sfb_11025_short_128[]; 67 | extern const unsigned char sfb_12000_long_1024[]; 68 | extern const unsigned char sfb_12000_short_128[]; 69 | extern const unsigned char sfb_16000_long_1024[]; 70 | extern const unsigned char sfb_16000_short_128[]; 71 | extern const unsigned char sfb_22050_long_1024[]; 72 | extern const unsigned char sfb_22050_short_128[]; 73 | extern const unsigned char sfb_24000_long_1024[]; 74 | extern const unsigned char sfb_24000_short_128[]; 75 | 76 | /* 77 | TNS 78 | */ 79 | 80 | extern const TNS_MAX_TAB_ENTRY tnsMaxBandsTab[9]; 81 | extern const TNS_CONFIG_TABULATED p_8000_mono_long; 82 | extern const TNS_CONFIG_TABULATED p_8000_mono_short; 83 | extern const TNS_CONFIG_TABULATED p_8000_stereo_long; 84 | extern const TNS_CONFIG_TABULATED p_8000_stereo_short; 85 | extern const TNS_CONFIG_TABULATED p_16000_mono_long; 86 | extern const TNS_CONFIG_TABULATED p_16000_mono_short; 87 | extern const TNS_CONFIG_TABULATED p_16000_stereo_long; 88 | extern const TNS_CONFIG_TABULATED p_16000_stereo_short; 89 | extern const TNS_CONFIG_TABULATED p_24000_mono_long; 90 | extern const TNS_CONFIG_TABULATED p_24000_mono_short; 91 | extern const TNS_CONFIG_TABULATED p_24000_stereo_long; 92 | extern const TNS_CONFIG_TABULATED p_24000_stereo_short; 93 | extern const TNS_CONFIG_TABULATED p_32000_mono_long; 94 | extern const TNS_CONFIG_TABULATED p_32000_mono_short; 95 | extern const TNS_CONFIG_TABULATED p_32000_stereo_long; 96 | extern const TNS_CONFIG_TABULATED p_32000_stereo_short; 97 | extern const TNS_INFO_TAB tnsInfoTab[4]; 98 | 99 | extern const float tnsCoeff3[8]; 100 | extern const float tnsCoeff3Borders[8]; 101 | extern const float tnsCoeff4[16]; 102 | extern const float tnsCoeff4Borders[16]; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /libaacenc/aacenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | fast aac coder interface library functions 3 | */ 4 | 5 | #ifndef _aacenc_h_ 6 | #define _aacenc_h_ 7 | 8 | /* here we distinguish between stereo and the mono only encoder */ 9 | #ifdef MONO_ONLY 10 | #define MAX_CHANNELS 1 11 | #else 12 | #define MAX_CHANNELS 2 13 | #endif 14 | 15 | #define AACENC_BLOCKSIZE 1024 /*! encoder only takes BLOCKSIZE samples at a time */ 16 | #define AACENC_TRANS_FAC 8 /*! encoder short long ratio */ 17 | #define AACENC_PCM_LEVEL 1.0 /*! encoder pcm 0db refernence */ 18 | 19 | 20 | /*-------------------------- defines --------------------------------------*/ 21 | 22 | #define BUFFERSIZE 1024 /* anc data */ 23 | 24 | /*-------------------- structure definitions ------------------------------*/ 25 | 26 | typedef struct { 27 | int sampleRate; /* audio file sample rate */ 28 | int bitRate; /* encoder bit rate in bits/sec */ 29 | int nChannelsIn; /* number of channels on input (1,2) */ 30 | int nChannelsOut; /* number of channels on output (1,2) */ 31 | int bandWidth; /* core coder audio bandwidth in Hz */ 32 | } AACENC_CONFIG; 33 | 34 | struct AAC_ENCODER; 35 | 36 | /* 37 | * p u b l i c a n c i l l a r y 38 | * 39 | */ 40 | 41 | 42 | /*----------------------------------------------------------------------------- 43 | 44 | functionname: AacInitDefaultConfig 45 | description: gives reasonable default configuration 46 | returns: --- 47 | 48 | ------------------------------------------------------------------------------*/ 49 | void AacInitDefaultConfig(AACENC_CONFIG *config); 50 | 51 | /*--------------------------------------------------------------------------- 52 | 53 | functionname:AacEncOpen 54 | description: allocate and initialize a new encoder instance 55 | returns: AACENC_OK if success 56 | 57 | ---------------------------------------------------------------------------*/ 58 | 59 | int AacEncOpen 60 | ( struct AAC_ENCODER** phAacEnc, /* pointer to an encoder handle, initialized on return */ 61 | const AACENC_CONFIG config /* pre-initialized config struct */ 62 | ); 63 | 64 | int AacEncEncode(struct AAC_ENCODER *hAacEnc, 65 | float *timeSignal, 66 | unsigned int timeInStride, 67 | const unsigned char *ancBytes, /*!< pointer to ancillary data bytes */ 68 | unsigned int *numAncBytes, /*!< number of ancillary Data Bytes, send as fill element */ 69 | unsigned int *outBytes, /*!< pointer to output buffer */ 70 | int *numOutBytes /*!< number of bytes in output buffer */ 71 | ); 72 | 73 | 74 | /*--------------------------------------------------------------------------- 75 | 76 | functionname:AacEncClose 77 | description: deallocate an encoder instance 78 | 79 | ---------------------------------------------------------------------------*/ 80 | 81 | void AacEncClose (struct AAC_ENCODER* hAacEnc); /* an encoder handle */ 82 | 83 | #endif /* _aacenc_h_ */ 84 | -------------------------------------------------------------------------------- /libaacenc/adj_thr.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADJ_THR_H 2 | #define __ADJ_THR_H 3 | 4 | #include "adj_thr_data.h" 5 | #include "qc_data.h" 6 | #include "interface.h" 7 | 8 | float bits2pe(const float bits); 9 | 10 | int AdjThrNew(ADJ_THR_STATE** phAdjThr, 11 | int nElements); 12 | 13 | void AdjThrDelete(ADJ_THR_STATE *hAdjThr); 14 | 15 | void AdjThrInit(ADJ_THR_STATE *hAdjThr, 16 | const float peMean, 17 | int chBitrate); 18 | 19 | void AdjustThresholds(ADJ_THR_STATE *adjThrState, 20 | ATS_ELEMENT* AdjThrStateElement, 21 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 22 | PSY_OUT_ELEMENT* psyOutElement, 23 | float *chBitDistribution, 24 | float sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB], 25 | const int nChannels, 26 | QC_OUT_ELEMENT* qcOE, 27 | const int avgBits, 28 | const int bitresBits, 29 | const int maxBitresBits, 30 | const float maxBitFac, 31 | const int sideInfoBits); 32 | 33 | void AdjThrUpdate(ATS_ELEMENT *AdjThrStateElement, 34 | const int dynBitsUsed); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /libaacenc/adj_thr_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | threshold calculations 3 | */ 4 | #ifndef __ADJ_THR_DATA_H 5 | #define __ADJ_THR_DATA_H 6 | 7 | #include "psy_const.h" 8 | 9 | typedef struct { 10 | float clipSaveLow, clipSaveHigh; 11 | float minBitSave, maxBitSave; 12 | float clipSpendLow, clipSpendHigh; 13 | float minBitSpend, maxBitSpend; 14 | } BRES_PARAM; 15 | 16 | typedef struct { 17 | unsigned char modifyMinSnr; 18 | int startSfbL, startSfbS; 19 | } AH_PARAM; 20 | 21 | typedef struct { 22 | float maxRed; 23 | float startRatio, maxRatio; 24 | float redRatioFac, redOffs; 25 | } MINSNR_ADAPT_PARAM; 26 | 27 | typedef struct { 28 | float peMin, peMax; 29 | float peOffset; 30 | AH_PARAM ahParam; 31 | MINSNR_ADAPT_PARAM minSnrAdaptParam; 32 | float peLast; 33 | int dynBitsLast; 34 | float peCorrectionFactor; 35 | } ATS_ELEMENT; 36 | 37 | typedef struct { 38 | BRES_PARAM bresParamLong, bresParamShort; 39 | ATS_ELEMENT adjThrStateElem; 40 | } ADJ_THR_STATE; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libaacenc/band_nrg.c: -------------------------------------------------------------------------------- 1 | /* 2 | calculation of band energies 3 | */ 4 | #include "band_nrg.h" 5 | 6 | #include "counters.h" /* the 3GPP instrumenting tool */ 7 | 8 | void CalcBandEnergy(const float *mdctSpectrum, 9 | const int *bandOffset, 10 | const int numBands, 11 | float *bandEnergy, 12 | float *bandEnergySum) { 13 | int i, j; 14 | 15 | COUNT_sub_start("CalcBandEnergy"); 16 | 17 | MOVE(2); 18 | j = 0; 19 | *bandEnergySum = 0.0f; 20 | 21 | PTR_INIT(3); /* pointers for bandEnergy[], 22 | bandOffset[], 23 | mdctSpectrum[] 24 | */ 25 | LOOP(1); 26 | for(i=0; i 5 | #include "FFR_bitbuffer.h" 6 | #define INVALID_BITCOUNT (INT_MAX/4) 7 | 8 | /* 9 | code book number table 10 | */ 11 | 12 | enum codeBookNo{ 13 | CODE_BOOK_ZERO_NO= 0, 14 | CODE_BOOK_1_NO= 1, 15 | CODE_BOOK_2_NO= 2, 16 | CODE_BOOK_3_NO= 3, 17 | CODE_BOOK_4_NO= 4, 18 | CODE_BOOK_5_NO= 5, 19 | CODE_BOOK_6_NO= 6, 20 | CODE_BOOK_7_NO= 7, 21 | CODE_BOOK_8_NO= 8, 22 | CODE_BOOK_9_NO= 9, 23 | CODE_BOOK_10_NO= 10, 24 | CODE_BOOK_ESC_NO= 11, 25 | CODE_BOOK_RES_NO= 12, 26 | CODE_BOOK_PNS_NO= 13 27 | }; 28 | 29 | /* 30 | code book index table 31 | */ 32 | 33 | enum codeBookNdx{ 34 | CODE_BOOK_ZERO_NDX, 35 | CODE_BOOK_1_NDX, 36 | CODE_BOOK_2_NDX, 37 | CODE_BOOK_3_NDX, 38 | CODE_BOOK_4_NDX, 39 | CODE_BOOK_5_NDX, 40 | CODE_BOOK_6_NDX, 41 | CODE_BOOK_7_NDX, 42 | CODE_BOOK_8_NDX, 43 | CODE_BOOK_9_NDX, 44 | CODE_BOOK_10_NDX, 45 | CODE_BOOK_ESC_NDX, 46 | CODE_BOOK_RES_NDX, 47 | CODE_BOOK_PNS_NDX, 48 | NUMBER_OF_CODE_BOOKS 49 | }; 50 | 51 | /* 52 | code book lav table 53 | */ 54 | 55 | enum codeBookLav{ 56 | CODE_BOOK_ZERO_LAV=0, 57 | CODE_BOOK_1_LAV=1, 58 | CODE_BOOK_2_LAV=1, 59 | CODE_BOOK_3_LAV=2, 60 | CODE_BOOK_4_LAV=2, 61 | CODE_BOOK_5_LAV=4, 62 | CODE_BOOK_6_LAV=4, 63 | CODE_BOOK_7_LAV=7, 64 | CODE_BOOK_8_LAV=7, 65 | CODE_BOOK_9_LAV=12, 66 | CODE_BOOK_10_LAV=12, 67 | CODE_BOOK_ESC_LAV=16, 68 | CODE_BOOK_SCF_LAV=60, 69 | CODE_BOOK_PNS_LAV=60 70 | }; 71 | 72 | int bitCount(const short *aQuantSpectrum, 73 | const int noOfSpecLines, 74 | int maxVal, 75 | int *bitCountLut); 76 | 77 | int codeValues(short *values, int width, int codeBook, HANDLE_BIT_BUF hBitstream); 78 | 79 | int bitCountScalefactorDelta(signed int delta); 80 | int codeScalefactorDelta(signed int scalefactor, HANDLE_BIT_BUF hBitstream); 81 | 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /libaacenc/bitenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Bitstream encoder 3 | */ 4 | #ifndef _BITENC_H 5 | #define _BITENC_H 6 | 7 | #include "qc_data.h" 8 | #include "tns.h" 9 | #include "channel_map.h" 10 | #include "interface.h" 11 | 12 | struct BITSTREAMENCODER_INIT 13 | { 14 | int nChannels; 15 | int bitrate; 16 | int sampleRate; 17 | int profile; 18 | }; 19 | 20 | 21 | 22 | int WriteBitstream (HANDLE_BIT_BUF hBitstream, 23 | ELEMENT_INFO elInfo, 24 | QC_OUT* qcOut, 25 | PSY_OUT* psyOut, 26 | int* globUsedBits, 27 | const unsigned char *ancBytes 28 | ); 29 | 30 | #endif /* _BITENC_H */ 31 | -------------------------------------------------------------------------------- /libaacenc/block_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Block Switching 3 | */ 4 | #ifndef _BLOCK_SWITCH_H 5 | #define _BLOCK_SWITCH_H 6 | 7 | #define BLOCK_SWITCHING_IIR_LEN 2 8 | #define BLOCK_SWITCH_WINDOWS TRANS_FAC /* number of windows for energy calculation */ 9 | #define BLOCK_SWITCH_WINDOW_LEN FRAME_LEN_SHORT /* minimal granularity of energy calculation */ 10 | 11 | 12 | typedef struct{ 13 | float invAttackRatio; 14 | int windowSequence; 15 | int nextwindowSequence; 16 | int attack; 17 | int lastattack; 18 | int attackIndex; 19 | int lastAttackIndex; 20 | int noOfGroups; 21 | int groupLen[TRANS_FAC]; 22 | float windowNrg[2][BLOCK_SWITCH_WINDOWS]; /* time signal energy in Subwindows (last and current) */ 23 | float windowNrgF[2][BLOCK_SWITCH_WINDOWS]; /* filtered time signal energy in segments (last and current) */ 24 | float iirStates[BLOCK_SWITCHING_IIR_LEN]; /* filter delay-line */ 25 | float maxWindowNrg; /* max energy in subwindows */ 26 | float accWindowNrg; /* recursively accumulated windowNrgF */ 27 | }BLOCK_SWITCHING_CONTROL; 28 | 29 | int InitBlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControl, 30 | const int bitRate, const int nChannels); 31 | 32 | int BlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControl, 33 | float *timeSignal, 34 | int chIncrement); 35 | 36 | int SyncBlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControlLeft, 37 | BLOCK_SWITCHING_CONTROL *blockSwitchingControlRight, 38 | const int noOfChannels); 39 | 40 | #endif /* #ifndef _BLOCK_SWITCH_H */ 41 | -------------------------------------------------------------------------------- /libaacenc/channel_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | Channel Mapping 3 | */ 4 | #include "channel_map.h" 5 | #include "bitenc.h" 6 | #include "psy_const.h" 7 | #include "qc_data.h" 8 | #include 9 | 10 | #include "counters.h" /* the 3GPP instrumenting tool */ 11 | 12 | 13 | static int initElement (ELEMENT_INFO* elInfo, ELEMENT_TYPE elType) { 14 | 15 | int error=0; 16 | 17 | COUNT_sub_start("initElement"); 18 | 19 | MOVE(1); /* counting previous operations */ 20 | 21 | INDIRECT(1); MOVE(1); 22 | elInfo->elType=elType; 23 | 24 | BRANCH(2); 25 | switch(elInfo->elType) { 26 | 27 | case ID_SCE: 28 | INDIRECT(1); MOVE(1); 29 | elInfo->nChannelsInEl=1; 30 | 31 | INDIRECT(1); MOVE(1); 32 | elInfo->ChannelIndex[0]=0; 33 | 34 | INDIRECT(2); STORE(1); 35 | elInfo->instanceTag=0; 36 | break; 37 | 38 | case ID_CPE: 39 | 40 | INDIRECT(1); MOVE(1); 41 | elInfo->nChannelsInEl=2; 42 | 43 | INDIRECT(2); MOVE(2); 44 | elInfo->ChannelIndex[0]=0; 45 | elInfo->ChannelIndex[1]=1; 46 | 47 | INDIRECT(1); STORE(1); 48 | elInfo->instanceTag=0; 49 | break; 50 | 51 | default: 52 | MOVE(1); 53 | error=1; 54 | } 55 | 56 | COUNT_sub_end(); 57 | 58 | return error; 59 | } 60 | 61 | int InitElementInfo (int nChannels, ELEMENT_INFO* elInfo) { 62 | 63 | int error=0; 64 | 65 | COUNT_sub_start("InitChannelMapping"); 66 | 67 | MOVE(1); /* counting previous operation */ 68 | 69 | 70 | BRANCH(2); 71 | switch(nChannels) { 72 | 73 | case 1: 74 | FUNC(2); 75 | initElement(elInfo, ID_SCE); 76 | break; 77 | 78 | case 2: 79 | FUNC(5); 80 | initElement(elInfo, ID_CPE); 81 | break; 82 | 83 | default: 84 | MOVE(1); 85 | error=1; 86 | 87 | COUNT_sub_end(); 88 | return error; 89 | } 90 | 91 | COUNT_sub_end(); 92 | 93 | return 0; 94 | } 95 | 96 | 97 | int InitElementBits(ELEMENT_BITS* elementBits, 98 | ELEMENT_INFO elInfo, 99 | int bitrateTot, 100 | int averageBitsTot, 101 | int staticBitsTot) 102 | { 103 | int error=0; 104 | 105 | COUNT_sub_start("InitElementBits"); 106 | 107 | MOVE(1); /* counting previous operation */ 108 | 109 | INDIRECT(1); BRANCH(2); 110 | switch(elInfo.nChannelsInEl) { 111 | 112 | case 1: 113 | MOVE(1); PTR_INIT(1); 114 | elementBits->chBitrate = bitrateTot; 115 | 116 | ADD(1); STORE(1); 117 | elementBits->averageBits = (averageBitsTot - staticBitsTot); 118 | 119 | MOVE(1); 120 | elementBits->maxBits = MAX_CHANNEL_BITS; 121 | 122 | ADD(1); STORE(1); 123 | elementBits->maxBitResBits = MAX_CHANNEL_BITS - averageBitsTot; 124 | 125 | LOGIC(1); ADD(1); STORE(1); 126 | elementBits->maxBitResBits -= (elementBits[0].maxBitResBits%8); 127 | 128 | MOVE(2); 129 | elementBits->bitResLevel = elementBits[0].maxBitResBits; 130 | elementBits->relativeBits = 1.0f; 131 | break; 132 | 133 | case 2: 134 | MULT(1); STORE(1); 135 | elementBits->chBitrate = (int)(bitrateTot*0.5f); 136 | 137 | ADD(1); STORE(1); 138 | elementBits->averageBits = (averageBitsTot - staticBitsTot); 139 | 140 | MULT(1); STORE(1); 141 | elementBits->maxBits = 2*MAX_CHANNEL_BITS; 142 | 143 | MULT(1); ADD(1); STORE(1); 144 | elementBits->maxBitResBits = 2*MAX_CHANNEL_BITS - averageBitsTot; 145 | 146 | LOGIC(1); ADD(1); STORE(1); 147 | elementBits->maxBitResBits -= (elementBits[0].maxBitResBits%8); 148 | 149 | MOVE(2); 150 | elementBits->bitResLevel = elementBits[0].maxBitResBits; 151 | elementBits->relativeBits = 1.0f; 152 | break; 153 | 154 | default: 155 | MOVE(2); 156 | error=1; 157 | } 158 | 159 | COUNT_sub_end(); 160 | 161 | return error; 162 | } 163 | 164 | -------------------------------------------------------------------------------- /libaacenc/channel_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | Channel Mapping 3 | */ 4 | #ifndef _CHANNEL_MAP_H 5 | #define _CHANNEL_MAP_H 6 | 7 | #include "psy_const.h" 8 | #include "qc_data.h" 9 | 10 | 11 | int InitElementInfo (int nChannels, 12 | ELEMENT_INFO *elInfo); 13 | 14 | int InitElementBits(ELEMENT_BITS* elementBits, 15 | ELEMENT_INFO elInfo, 16 | int bitrateTot, 17 | int averageBitsTot, 18 | int staticBitsTot); 19 | 20 | #endif /* CHANNEL_MAP_H */ 21 | -------------------------------------------------------------------------------- /libaacenc/counters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Provides dummy functions/macros to be able to compile the code. 3 | It is planned to provide a complexity measuring tool that allows 4 | to actually exploit the instrumentation lateron. 5 | */ 6 | 7 | #ifndef COUNT_H 8 | #define COUNT_H 9 | 10 | #include 11 | 12 | #define ADD(c) 13 | #define MULT(c) 14 | #define MAC(c) 15 | #define MOVE(c) 16 | #define STORE(c) 17 | #define LOGIC(c) 18 | #define SHIFT(c) 19 | #define BRANCH(c) 20 | #define DIV(c) 21 | #define SQRT(c) 22 | #define TRANS(c) 23 | #define FUNC(c) 24 | #define LOOP(c) 25 | #define INDIRECT(c) 26 | #define PTR_INIT(c) 27 | #define MISC(c) 28 | 29 | /* external function prototypes */ 30 | #define COUNT_init() 31 | #define COUNT_end() 32 | #define COUNT_sub_start(name) 33 | #define COUNT_sub_end() 34 | #define COUNT_frame_update() 35 | #define COUNT_ops(op, count) 36 | #define COUNT_mem(op, count) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libaacenc/dyn_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | Noiseless coder module 3 | */ 4 | #ifndef __DYN_BITS_H 5 | #define __DYN_BITS_H 6 | 7 | #include "psy_const.h" 8 | #include "tns.h" 9 | #include "bit_cnt.h" 10 | 11 | #define MAX_SECTIONS MAX_GROUPED_SFB 12 | #define SECT_ESC_VAL_LONG 31 13 | #define SECT_ESC_VAL_SHORT 7 14 | #define CODE_BOOK_BITS 4 15 | #define SECT_BITS_LONG 5 16 | #define SECT_BITS_SHORT 3 17 | 18 | typedef struct 19 | { 20 | int codeBook; 21 | int sfbStart; 22 | int sfbCnt; 23 | int sectionBits; /* huff + si ! */ 24 | } 25 | SECTION_INFO; 26 | 27 | typedef struct 28 | { 29 | int blockType; 30 | int noOfGroups; 31 | int sfbCnt; 32 | int maxSfbPerGroup; 33 | int sfbPerGroup; 34 | int noOfSections; 35 | SECTION_INFO section[MAX_SECTIONS]; 36 | int sideInfoBits; /* sectioning bits */ 37 | int huffmanBits; /* huffman coded bits */ 38 | int scalefacBits; /* scalefac coded bits */ 39 | int firstScf; /* first scf to be coded */ 40 | } 41 | SECTION_DATA; 42 | 43 | 44 | int BCInit(void); 45 | 46 | int dynBitCount(const short *quantSpectrum, 47 | const unsigned short *maxValueInSfb, 48 | const signed short *scalefac, 49 | const int blockType, 50 | const int sfbCnt, 51 | const int maxSfbPerGroup, 52 | const int sfbPerGroup, 53 | const int *sfbOffset, 54 | SECTION_DATA * sectionData); 55 | 56 | int RecalcSectionInfo(SECTION_DATA * sectionData, 57 | const unsigned short *maxValueInSfb, 58 | const signed short *scalefac, 59 | const int blockType); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libaacenc/grp_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | Short block grouping 3 | */ 4 | #include "psy_const.h" 5 | #include "interface.h" 6 | #include "minmax.h" 7 | #include "grp_data.h" 8 | 9 | #include "counters.h" /* the 3GPP instrumenting tool */ 10 | 11 | /* 12 | * this routine does not work in-place 13 | */ 14 | 15 | void 16 | groupShortData(float *mdctSpectrum, 17 | float *tmpSpectrum, 18 | SFB_THRESHOLD *sfbThreshold, 19 | SFB_ENERGY *sfbEnergy, 20 | SFB_ENERGY *sfbEnergyMS, 21 | SFB_ENERGY *sfbSpreadedEnergy, 22 | const int sfbCnt, 23 | const int *sfbOffset, 24 | const float *sfbMinSnr, 25 | int *groupedSfbOffset, 26 | int *maxSfbPerGroup, 27 | float *groupedSfbMinSnr, 28 | const int noOfGroups, 29 | const int *groupLen) 30 | { 31 | int i,j; 32 | int line; 33 | int sfb; 34 | int grp; 35 | int wnd; 36 | int offset; 37 | int highestSfb; 38 | 39 | COUNT_sub_start("groupShortData"); 40 | 41 | 42 | 43 | /* for short: regroup and */ 44 | /* cumulate energies und thresholds group-wise . */ 45 | 46 | 47 | /* calculate sfbCnt */ 48 | MOVE(1); 49 | highestSfb = 0; 50 | 51 | LOOP(1); 52 | for (wnd = 0; wnd < TRANS_FAC; wnd++) 53 | { 54 | PTR_INIT(1); /* sfbOffset[] */ 55 | LOOP(1); 56 | for (sfb = sfbCnt-1; sfb >= highestSfb; sfb--) 57 | { 58 | PTR_INIT(1); /* mdctSpectrum[] */ 59 | LOOP(1); 60 | for (line = sfbOffset[sfb+1]-1; line >= sfbOffset[sfb]; line--) 61 | { 62 | BRANCH(1); 63 | if (mdctSpectrum[wnd*FRAME_LEN_SHORT+line] != 0.0) break; // this band is not completely zero 64 | } 65 | ADD(1); BRANCH(1); 66 | if (line >= sfbOffset[sfb]) break; // this band was not completely zero 67 | } 68 | ADD(1); BRANCH(1); MOVE(1); 69 | highestSfb = max(highestSfb, sfb); 70 | } 71 | BRANCH(1); MOVE(1); 72 | highestSfb = highestSfb > 0 ? highestSfb : 0; 73 | 74 | ADD(1); STORE(1); 75 | *maxSfbPerGroup = highestSfb+1; 76 | 77 | /* calculate sfbOffset */ 78 | MOVE(2); 79 | i = 0; 80 | offset = 0; 81 | 82 | PTR_INIT(2); /* groupedSfbOffset[] 83 | groupLen[] 84 | */ 85 | LOOP(1); 86 | for (grp = 0; grp < noOfGroups; grp++) 87 | { 88 | PTR_INIT(1); /* sfbOffset[] */ 89 | LOOP(1); 90 | for (sfb = 0; sfb < sfbCnt; sfb++) 91 | { 92 | MULT(1); ADD(1); STORE(1); 93 | groupedSfbOffset[i++] = offset + sfbOffset[sfb] * groupLen[grp]; 94 | } 95 | 96 | MAC(1); 97 | offset += groupLen[grp] * FRAME_LEN_SHORT; 98 | } 99 | MOVE(1); 100 | groupedSfbOffset[i++] = FRAME_LEN_LONG; 101 | 102 | /* calculate minSnr */ 103 | 104 | MOVE(2); 105 | i = 0; 106 | offset = 0; 107 | 108 | PTR_INIT(1); /* groupedSfbMinSnr[] */ 109 | for (grp = 0; grp < noOfGroups; grp++) 110 | { 111 | PTR_INIT(1); /* sfbMinSnr[] */ 112 | LOOP(1); 113 | for (sfb = 0; sfb < sfbCnt; sfb++) 114 | { 115 | MOVE(1); 116 | groupedSfbMinSnr[i++] = sfbMinSnr[sfb]; 117 | } 118 | 119 | MAC(1); 120 | offset += groupLen[grp] * FRAME_LEN_SHORT; 121 | } 122 | 123 | 124 | 125 | /* sum up sfbThresholds */ 126 | MOVE(2); 127 | wnd = 0; 128 | i = 0; 129 | 130 | PTR_INIT(2); /* groupLen[] 131 | sfbThreshold->Long[] 132 | */ 133 | LOOP(1); 134 | for (grp = 0; grp < noOfGroups; grp++) 135 | { 136 | PTR_INIT(1); /* sfbThreshold->Short[][] */ 137 | LOOP(1); 138 | for (sfb = 0; sfb < sfbCnt; sfb++) 139 | { 140 | float thresh = sfbThreshold->Short[wnd][sfb]; 141 | 142 | MOVE(1); /* counting previous operation */ 143 | 144 | LOOP(1); 145 | for (j=1; jShort[wnd+j][sfb]; 149 | } 150 | 151 | MOVE(1); 152 | sfbThreshold->Long[i++] = thresh; 153 | } 154 | wnd += groupLen[grp]; 155 | } 156 | 157 | /* sum up sfbEnergies left/right */ 158 | MOVE(2); 159 | wnd = 0; 160 | i = 0; 161 | 162 | PTR_INIT(2); /* groupLen[] 163 | sfbEnergy->Long[] 164 | */ 165 | LOOP(1); 166 | for (grp = 0; grp < noOfGroups; grp++) 167 | { 168 | PTR_INIT(1); /* sfbEnergy->Short[][] */ 169 | LOOP(1); 170 | for (sfb = 0; sfb < sfbCnt; sfb++) 171 | { 172 | float energy = sfbEnergy->Short[wnd][sfb]; 173 | 174 | MOVE(1); /* counting previous operation */ 175 | 176 | LOOP(1); 177 | for (j=1; jShort[wnd+j][sfb]; 181 | } 182 | MOVE(1); 183 | sfbEnergy->Long[i++] = energy; 184 | } 185 | wnd += groupLen[grp]; 186 | } 187 | 188 | /* sum up sfbEnergies mid/side */ 189 | MOVE(1); 190 | wnd = 0; 191 | i = 0; 192 | 193 | PTR_INIT(2); /* groupLen[] 194 | sfbEnergy->Long[] 195 | */ 196 | LOOP(1); 197 | for (grp = 0; grp < noOfGroups; grp++) 198 | { 199 | PTR_INIT(1); /* sfbEnergy->Short[][] */ 200 | LOOP(1); 201 | for (sfb = 0; sfb < sfbCnt; sfb++) 202 | { 203 | float energy = sfbEnergyMS->Short[wnd][sfb]; 204 | 205 | MOVE(1); /* counting previous operation */ 206 | 207 | LOOP(1); 208 | for (j=1; jShort[wnd+j][sfb]; 212 | } 213 | MOVE(1); 214 | sfbEnergyMS->Long[i++] = energy; 215 | } 216 | wnd += groupLen[grp]; 217 | } 218 | 219 | /* sum up sfbSpreadedEnergies */ 220 | MOVE(2); 221 | wnd = 0; 222 | i = 0; 223 | 224 | PTR_INIT(2); /* groupLen[] 225 | sfbEnergy->Long[] 226 | */ 227 | LOOP(1); 228 | for (grp = 0; grp < noOfGroups; grp++) 229 | { 230 | PTR_INIT(1); /* sfbEnergy->Short[][] */ 231 | LOOP(1); 232 | for (sfb = 0; sfb < sfbCnt; sfb++) 233 | { 234 | float energy = sfbSpreadedEnergy->Short[wnd][sfb]; 235 | 236 | MOVE(1); /* counting previous operation */ 237 | 238 | LOOP(1); 239 | for (j=1; jShort[wnd+j][sfb]; 243 | } 244 | MOVE(1); 245 | sfbSpreadedEnergy->Long[i++] = energy; 246 | } 247 | wnd += groupLen[grp]; 248 | } 249 | 250 | /* re-group spectrum */ 251 | MOVE(2); 252 | wnd = 0; 253 | i = 0; 254 | 255 | PTR_INIT(2); /* groupLen[] 256 | tmpSpectrum[] 257 | */ 258 | LOOP(1); 259 | for (grp = 0; grp < noOfGroups; grp++) 260 | { 261 | PTR_INIT(1); /* sfbOffset[] */ 262 | LOOP(1); 263 | for (sfb = 0; sfb < sfbCnt; sfb++) 264 | { 265 | LOOP(1); 266 | for (j = 0; j < groupLen[grp]; j++) 267 | { 268 | PTR_INIT(1); /* mdctSpectrum[] */ 269 | LOOP(1); 270 | for (line = sfbOffset[sfb]; line < sfbOffset[sfb+1]; line++) 271 | { 272 | MOVE(1); 273 | tmpSpectrum[i++] = mdctSpectrum[(wnd+j)*FRAME_LEN_SHORT+line]; 274 | } 275 | } 276 | } 277 | wnd += groupLen[grp]; 278 | } 279 | 280 | PTR_INIT(2); /* mdctSpectrum[] 281 | tmpSpectrum[] 282 | */ 283 | LOOP(1); 284 | for(i=0;imaxSfbPerGroup = maxSfbPerGroup; 38 | psyOutCh->sfbCnt = groupedSfbCnt; 39 | psyOutCh->sfbPerGroup = groupedSfbCnt / noOfGroups; 40 | psyOutCh->windowSequence = windowSequence; 41 | psyOutCh->windowShape = windowShape; 42 | psyOutCh->mdctSpectrum = groupedMdctSpectrum; 43 | psyOutCh->sfbEnergy = groupedSfbEnergy->Long; 44 | psyOutCh->sfbThreshold = groupedSfbThreshold->Long; 45 | psyOutCh->sfbSpreadedEnergy = groupedSfbSpreadedEnergy->Long; 46 | 47 | 48 | PTR_INIT(2); /* psyOutCh->sfbOffsets[] 49 | groupedSfbOffset[] 50 | */ 51 | LOOP(1); 52 | for(j=0; jsfbOffsets[j]=groupedSfbOffset[j]; 56 | } 57 | 58 | PTR_INIT(2); /* psyOutCh->sfbMinSnr[] 59 | groupedSfbMinSnr[] 60 | */ 61 | for(j=0;jsfbMinSnr[j] = groupedSfbMinSnr[j]; 65 | } 66 | 67 | /* generate grouping mask */ 68 | MOVE(1); 69 | mask = 0; 70 | 71 | PTR_INIT(1); /* groupLen[grp] */ 72 | LOOP(1); 73 | for (grp = 0; grp < noOfGroups; grp++) 74 | { 75 | SHIFT(1); 76 | mask <<= 1; 77 | 78 | LOOP(1); 79 | for (j=1; jsfbEnSumLR = sfbEnergySumLR.Long; 93 | psyOutCh->sfbEnSumMS = sfbEnergySumMS.Long; 94 | } 95 | else { 96 | int i; 97 | 98 | INDIRECT(2); MOVE(2); 99 | psyOutCh->sfbEnSumMS=0; 100 | psyOutCh->sfbEnSumLR=0; 101 | 102 | PTR_INIT(2); /* sfbEnergySumLR.Short[] 103 | sfbEnergySumMS.Short[] 104 | */ 105 | LOOP(1); 106 | for (i=0;i< TRANS_FAC; i++) { 107 | 108 | ADD(2); 109 | psyOutCh->sfbEnSumLR += sfbEnergySumLR.Short[i]; 110 | psyOutCh->sfbEnSumMS += sfbEnergySumMS.Short[i]; 111 | } 112 | INDIRECT(2); STORE(2); 113 | } 114 | 115 | INDIRECT(1); MOVE(1); 116 | psyOutCh->groupingMask = mask; 117 | 118 | COUNT_sub_end(); 119 | } 120 | -------------------------------------------------------------------------------- /libaacenc/interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Interface psychoaccoustic/quantizer 3 | */ 4 | #ifndef _INTERFACE_H 5 | #define _INTERFACE_H 6 | 7 | #include "psy_const.h" 8 | #include "psy_data.h" 9 | 10 | enum 11 | { 12 | MS_NONE = 0, 13 | MS_SOME = 1, 14 | MS_ALL = 2 15 | }; 16 | 17 | enum 18 | { 19 | MS_ON = 1 20 | }; 21 | 22 | struct TOOLSINFO { 23 | int msDigest; /* 0 = no MS; 1 = some MS, 2 = all MS */ 24 | int msMask[MAX_GROUPED_SFB]; 25 | }; 26 | 27 | 28 | typedef struct { 29 | int sfbCnt; 30 | int sfbPerGroup; 31 | int maxSfbPerGroup; 32 | int windowSequence; 33 | int windowShape; 34 | int groupingMask; 35 | int sfbOffsets[MAX_GROUPED_SFB+1]; 36 | float *sfbEnergy; 37 | float *sfbSpreadedEnergy; 38 | float *sfbThreshold; 39 | float *mdctSpectrum; 40 | 41 | float sfbEnSumLR; 42 | float sfbEnSumMS; 43 | float pe; /* pe sum for stereo preprocessing */ 44 | 45 | float sfbMinSnr[MAX_GROUPED_SFB]; 46 | TNS_INFO tnsInfo; 47 | }PSY_OUT_CHANNEL; 48 | 49 | typedef struct { 50 | struct TOOLSINFO toolsInfo; 51 | float weightMsLrPeRatio; /*! factor to weight PE dependent on ms vs. lr PE ratio */ 52 | } PSY_OUT_ELEMENT; 53 | 54 | typedef struct { 55 | /* information shared by both channels */ 56 | PSY_OUT_ELEMENT psyOutElement; 57 | /* information specific to each channel */ 58 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS]; 59 | }PSY_OUT; 60 | 61 | void BuildInterface(float *mdctSpectrum, 62 | SFB_THRESHOLD *sfbThreshold, 63 | SFB_ENERGY *sfbEnergy, 64 | SFB_ENERGY *sfbSpreadedEnergy, 65 | const SFB_ENERGY_SUM sfbEnergySumLR, 66 | const SFB_ENERGY_SUM sfbEnergySumMS, 67 | const int windowSequence, 68 | const int windowShape, 69 | const int sfbCnt, 70 | const int *sfbOffset, 71 | const int maxSfbPerGroup, 72 | const float *groupedSfbMinSnr, 73 | const int noOfGroups, 74 | const int *groupLen, 75 | PSY_OUT_CHANNEL *psyOutCh); 76 | 77 | #endif /* _INTERFACE_H */ 78 | -------------------------------------------------------------------------------- /libaacenc/line_pe.c: -------------------------------------------------------------------------------- 1 | /* 2 | Perceptual entropie module 3 | */ 4 | #include 5 | #include "float.h" 6 | #include "line_pe.h" 7 | 8 | #include "counters.h" /* the 3GPP instrumenting tool */ 9 | 10 | #define LOG2_1 1.442695041f 11 | #define C1 3.0f /* log(8.0)/log(2) */ 12 | #define C2 1.3219281f /* log(2.5)/log(2) */ 13 | #define C3 0.5593573f /* 1-C2/C1 */ 14 | 15 | 16 | /* constants that do not change during successive pe calculations */ 17 | void prepareSfbPe(PE_CHANNEL_DATA *peChanData, 18 | const float *sfbEnergy, 19 | const float *sfbThreshold, 20 | const float *sfbFormFactor, 21 | const int *sfbOffset, 22 | const int sfbCnt, 23 | const int sfbPerGroup, 24 | const int maxSfbPerGroup) 25 | { 26 | int sfbGrp,sfb; 27 | int sfbWidth; 28 | float avgFormFactor; 29 | 30 | COUNT_sub_start("prepareSfbPe"); 31 | 32 | LOOP(1); 33 | for(sfbGrp = 0;sfbGrp < sfbCnt;sfbGrp+=sfbPerGroup){ 34 | 35 | PTR_INIT(6); /* pointers for sfbEnergy[], 36 | sfbThreshold[], 37 | sfbOffset[], 38 | sfbFormFactor[], 39 | peChanData->sfbNLines[], 40 | peChanData->sfbLdEnergy[] 41 | */ 42 | LOOP(1); 43 | for (sfb=0; sfb sfbThreshold[sfbGrp+sfb]) { 47 | 48 | ADD(1); 49 | sfbWidth = sfbOffset[sfbGrp+sfb+1] - sfbOffset[sfbGrp+sfb]; 50 | 51 | /* estimate number of active lines */ 52 | DIV(1); TRANS(1); 53 | avgFormFactor = (float) pow(sfbEnergy[sfbGrp+sfb]/(float)sfbWidth, 0.25f); 54 | 55 | DIV(1); STORE(1); 56 | peChanData->sfbNLines[sfbGrp+sfb] = 57 | 58 | sfbFormFactor[sfbGrp+sfb]/avgFormFactor; 59 | 60 | /* ld(sfbEn) */ 61 | TRANS(1); MULT(1); STORE(1); 62 | peChanData->sfbLdEnergy[sfbGrp+sfb] = (float) (log(sfbEnergy[sfbGrp+sfb]) * LOG2_1); 63 | } 64 | else { 65 | 66 | MOVE(2); 67 | peChanData->sfbNLines[sfbGrp+sfb] = 0.0f; 68 | peChanData->sfbLdEnergy[sfbGrp+sfb] = 0.0f; 69 | } 70 | } 71 | } 72 | 73 | COUNT_sub_end(); 74 | } 75 | 76 | 77 | void calcSfbPe(PE_CHANNEL_DATA *peChanData, 78 | const float *sfbEnergy, 79 | const float *sfbThreshold, 80 | const int sfbCnt, 81 | const int sfbPerGroup, 82 | const int maxSfbPerGroup) 83 | { 84 | int sfbGrp,sfb; 85 | float nLines; 86 | float ldThr, ldRatio; 87 | 88 | COUNT_sub_start("calcSfbPe"); 89 | 90 | INDIRECT(3); MOVE(3); 91 | peChanData->pe = 0.0f; 92 | peChanData->constPart = 0.0f; 93 | peChanData->nActiveLines = 0.0f; 94 | 95 | LOOP(1); 96 | for(sfbGrp = 0;sfbGrp < sfbCnt;sfbGrp+=sfbPerGroup){ 97 | 98 | PTR_INIT(8); /* pointers for sfbEnergy[] 99 | sfbThreshold[] 100 | peChanData->sfbLdEnergy[] 101 | peChanData->sfbNLines[] 102 | peChanData->sfbPe[] 103 | peChanData->sfbConstPart[] 104 | peChanData->sfbLdEnergy[] 105 | peChanData->sfbNActiveLines[] 106 | */ 107 | LOOP(1); 108 | for (sfb=0; sfb sfbThreshold[sfbGrp+sfb]) { 112 | 113 | TRANS(1); MULT(1); 114 | ldThr = (float)log(sfbThreshold[sfbGrp+sfb]) * LOG2_1; 115 | 116 | ADD(1); 117 | ldRatio = peChanData->sfbLdEnergy[sfbGrp+sfb] - ldThr; 118 | 119 | MOVE(1); 120 | nLines = peChanData->sfbNLines[sfbGrp+sfb]; 121 | 122 | ADD(1); BRANCH(1); 123 | if (ldRatio >= C1) { 124 | 125 | MULT(1); STORE(1); 126 | peChanData->sfbPe[sfbGrp+sfb] = nLines * ldRatio; 127 | 128 | MULT(1); STORE(1); 129 | peChanData->sfbConstPart[sfbGrp+sfb] = nLines*peChanData->sfbLdEnergy[sfbGrp+sfb]; 130 | } 131 | else { 132 | 133 | MULT(2); ADD(1); STORE(1); 134 | peChanData->sfbPe[sfbGrp+sfb] = nLines * (C2 + C3 * ldRatio); 135 | 136 | MULT(2); ADD(1); STORE(1); 137 | peChanData->sfbConstPart[sfbGrp+sfb] = nLines * 138 | (C2 + C3 * peChanData->sfbLdEnergy[sfbGrp+sfb]); 139 | 140 | MULT(1); 141 | nLines = nLines * C3; 142 | } 143 | 144 | MOVE(1); 145 | peChanData->sfbNActiveLines[sfbGrp+sfb] = nLines; 146 | } 147 | else { 148 | 149 | MOVE(3); 150 | peChanData->sfbPe[sfbGrp+sfb] = 0.0f; 151 | peChanData->sfbConstPart[sfbGrp+sfb] = 0.0f; 152 | peChanData->sfbNActiveLines[sfbGrp+sfb] = 0.0; 153 | } 154 | 155 | INDIRECT(3); ADD(3); STORE(3); 156 | peChanData->pe += peChanData->sfbPe[sfbGrp+sfb]; 157 | peChanData->constPart += peChanData->sfbConstPart[sfbGrp+sfb]; 158 | peChanData->nActiveLines += peChanData->sfbNActiveLines[sfbGrp+sfb]; 159 | } 160 | } 161 | 162 | COUNT_sub_end(); 163 | } 164 | -------------------------------------------------------------------------------- /libaacenc/line_pe.h: -------------------------------------------------------------------------------- 1 | /* 2 | Perceptual entropie module 3 | */ 4 | #ifndef __LINE_PE_H 5 | #define __LINE_PE_H 6 | 7 | 8 | #include "psy_const.h" 9 | 10 | 11 | typedef struct { 12 | /* these two are calculated by prepareSfbPe */ 13 | float sfbLdEnergy[MAX_GROUPED_SFB]; /* log(sfbEnergy)/log(2) */ 14 | float sfbNLines[MAX_GROUPED_SFB]; /* number of relevant lines in sfb */ 15 | /* the rest is calculated by calcSfbPe */ 16 | float sfbPe[MAX_GROUPED_SFB]; /* pe for each sfb */ 17 | float sfbConstPart[MAX_GROUPED_SFB]; /* constant part for each sfb */ 18 | float sfbNActiveLines[MAX_GROUPED_SFB]; /* number of active lines in sfb */ 19 | float pe; /* sum of sfbPe */ 20 | float constPart; /* sum of sfbConstPart */ 21 | float nActiveLines; /* sum of sfbNActiveLines */ 22 | } PE_CHANNEL_DATA; 23 | 24 | 25 | void prepareSfbPe(PE_CHANNEL_DATA *peChanData, 26 | const float *sfbEnergy, 27 | const float *sfbThreshold, 28 | const float *sfbFormFactor, 29 | const int *sfbOffset, 30 | const int sfbCnt, 31 | const int sfbPerGroup, 32 | const int maxSfbPerGroup); 33 | 34 | void calcSfbPe(PE_CHANNEL_DATA *peChanData, 35 | const float *sfbEnergy, 36 | const float *sfbThreshold, 37 | const int sfbCnt, 38 | const int sfbPerGroup, 39 | const int maxSfbPerGroup); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libaacenc/minmax.h: -------------------------------------------------------------------------------- 1 | #ifndef MINMAX__H 2 | #define MINMAX__H 3 | /* Makros to determine the smaller/bigger value of two integers or doubles or floats. 4 | Watch the expanding process: min(rst++, xyz) will cause problems. */ 5 | #ifndef min 6 | #define min(a, b) ((a) < (b) ? (a) : (b)) 7 | #endif 8 | #ifndef max 9 | #define max(a, b) ((a) > (b) ? (a) : (b)) 10 | #endif 11 | #endif 12 | -------------------------------------------------------------------------------- /libaacenc/ms_stereo.c: -------------------------------------------------------------------------------- 1 | /* 2 | MS stereo processing 3 | */ 4 | #include "psy_const.h" 5 | #include "ms_stereo.h" 6 | #include "minmax.h" 7 | #include /* for atan() */ 8 | 9 | #include "counters.h" /* the 3GPP instrumenting tool */ 10 | 11 | void MsStereoProcessing(float *sfbEnergyLeft, 12 | float *sfbEnergyRight, 13 | const float *sfbEnergyMid, 14 | const float *sfbEnergySide, 15 | float *mdctSpectrumLeft, 16 | float *mdctSpectrumRight, 17 | float *sfbThresholdLeft, 18 | float *sfbThresholdRight, 19 | float *sfbSpreadedEnLeft, 20 | float *sfbSpreadedEnRight, 21 | int *msDigest, 22 | int *msMask, 23 | const int sfbCnt, 24 | const int sfbPerGroup, 25 | const int maxSfbPerGroup, 26 | const int *sfbOffset, 27 | float *weightMsLrPeRatio) 28 | { 29 | int sfb,sfboffs, j, cnt = 0; 30 | int msMaskTrueSomewhere = 0; 31 | int msMaskFalseSomewhere = 0; 32 | float sumMsLrPeRatio = 0; 33 | 34 | COUNT_sub_start("MsStereoProcessing"); 35 | 36 | MOVE(4); /* counting previous operations */ 37 | 38 | PTR_INIT(10); /* pointers for sfbThresholdLeft[sfb+sfboffs] 39 | sfbThresholdRight[sfb+sfboffs] 40 | sfbEnergyLeft[sfb+sfboffs] 41 | sfbEnergyRight[sfb+sfboffs] 42 | sfbEnergyMid[sfb+sfboffs] 43 | sfbEnergySide[sfb+sfboffs] 44 | sfbSpreadedEnLeft[sfb+sfboffs] 45 | sfbSpreadedEnRight[sfb+sfboffs] 46 | sfbOffset[sfb+sfboffs] 47 | msMask[sfb+sfboffs] 48 | */ 49 | LOOP(1); 50 | for(sfb=0; sfb= pnlr); 78 | 79 | BRANCH(1); 80 | if(useMS){ 81 | 82 | MOVE(2); 83 | msMask[sfb+sfboffs] = 1; 84 | msMaskTrueSomewhere = 1; 85 | 86 | PTR_INIT(2); /* pointers for mdctSpectrumLeft[], 87 | mdctSpectrumRight[] 88 | */ 89 | LOOP(1); 90 | for(j=sfbOffset[sfb+sfboffs]; j 5 | #include "pre_echo_control.h" 6 | 7 | #include "counters.h" /* the 3GPP instrumenting tool */ 8 | 9 | void InitPreEchoControl(float *pbThresholdNm1, 10 | int numPb, 11 | float *pbThresholdQuiet) 12 | { 13 | int pb; 14 | 15 | COUNT_sub_start("InitPreEchoControl"); 16 | 17 | PTR_INIT(2); /* pbThresholdNm1[] 18 | pbThresholdQuiet[] 19 | */ 20 | LOOP(1); 21 | for(pb=0;pb tmpThreshold1) { 59 | 60 | MOVE(1); 61 | pbThreshold[i] = tmpThreshold1; 62 | } 63 | 64 | ADD(1); BRANCH(1); 65 | if(tmpThreshold2 > pbThreshold[i]) { 66 | 67 | MOVE(1); 68 | pbThreshold[i] = tmpThreshold2; 69 | } 70 | 71 | } 72 | 73 | COUNT_sub_end(); 74 | } 75 | -------------------------------------------------------------------------------- /libaacenc/pre_echo_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | Pre echo control 3 | */ 4 | #ifndef __PRE_ECHO_CONTROL_H 5 | #define __PRE_ECHO_CONTROL_H 6 | 7 | void InitPreEchoControl(float *pbThresholdnm1, 8 | int numPb, 9 | float *pbThresholdQuiet); 10 | 11 | 12 | void PreEchoControl(float *pbThresholdNm1, 13 | int numPb, 14 | float maxAllowedIncreaseFactor, 15 | float minRemainingThresholdFactor, 16 | float *pbThreshold); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /libaacenc/psy_configuration.h: -------------------------------------------------------------------------------- 1 | /* 2 | Psychoaccoustic configuration 3 | */ 4 | #ifndef _PSY_CONFIGURATION_H 5 | #define _PSY_CONFIGURATION_H 6 | 7 | #include "psy_const.h" 8 | #include "tns.h" 9 | 10 | typedef struct{ 11 | 12 | int sfbCnt; 13 | int sfbActive; 14 | int sfbOffset[MAX_SFB_LONG+1]; 15 | 16 | float sfbThresholdQuiet[MAX_SFB_LONG]; 17 | 18 | float maxAllowedIncreaseFactor; /* preecho control */ 19 | float minRemainingThresholdFactor; 20 | 21 | int lowpassLine; 22 | float clipEnergy; /* for level dependend tmn */ 23 | 24 | float ratio; 25 | float sfbMaskLowFactor[MAX_SFB_LONG]; 26 | float sfbMaskHighFactor[MAX_SFB_LONG]; 27 | 28 | float sfbMaskLowFactorSprEn[MAX_SFB_LONG]; 29 | float sfbMaskHighFactorSprEn[MAX_SFB_LONG]; 30 | 31 | 32 | float sfbMinSnr[MAX_SFB_LONG]; 33 | 34 | TNS_CONFIG tnsConf; 35 | 36 | } PSY_CONFIGURATION_LONG; 37 | 38 | 39 | typedef struct{ 40 | 41 | int sfbCnt; 42 | int sfbActive; 43 | int sfbOffset[MAX_SFB_SHORT+1]; 44 | 45 | float sfbThresholdQuiet[MAX_SFB_SHORT]; 46 | 47 | float maxAllowedIncreaseFactor; /* preecho control */ 48 | float minRemainingThresholdFactor; 49 | 50 | int lowpassLine; 51 | float clipEnergy; /* for level dependend tmn */ 52 | 53 | float ratio; 54 | float sfbMaskLowFactor[MAX_SFB_SHORT]; 55 | float sfbMaskHighFactor[MAX_SFB_SHORT]; 56 | 57 | float sfbMaskLowFactorSprEn[MAX_SFB_SHORT]; 58 | float sfbMaskHighFactorSprEn[MAX_SFB_SHORT]; 59 | 60 | 61 | float sfbMinSnr[MAX_SFB_SHORT]; 62 | 63 | TNS_CONFIG tnsConf; 64 | 65 | } PSY_CONFIGURATION_SHORT; 66 | 67 | 68 | int InitPsyConfiguration(long bitrate, 69 | long samplerate, 70 | int bandwidth, 71 | PSY_CONFIGURATION_LONG *psyConf); 72 | 73 | int InitPsyConfigurationShort(long bitrate, 74 | long samplerate, 75 | int bandwidth, 76 | PSY_CONFIGURATION_SHORT *psyConf); 77 | 78 | #endif /* _PSY_CONFIGURATION_H */ 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /libaacenc/psy_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | Global psychoaccoustic constants 3 | */ 4 | #ifndef _PSYCONST_H 5 | #define _PSYCONST_H 6 | 7 | #include "aacenc.h" 8 | 9 | #define TRUE 1 10 | #define FALSE 0 11 | 12 | #define FRAME_LEN_LONG AACENC_BLOCKSIZE 13 | #define TRANS_FAC 8 14 | #define FRAME_LEN_SHORT (FRAME_LEN_LONG/TRANS_FAC) 15 | 16 | /* Block types */ 17 | enum 18 | { 19 | LONG_WINDOW = 0, 20 | START_WINDOW, 21 | SHORT_WINDOW, 22 | STOP_WINDOW 23 | }; 24 | 25 | /* Window shapes */ 26 | enum 27 | { 28 | SINE_WINDOW = 0, 29 | KBD_WINDOW = 1 30 | }; 31 | 32 | /* 33 | MS stuff 34 | */ 35 | enum 36 | { 37 | SI_MS_MASK_NONE = 0, 38 | SI_MS_MASK_SOME = 1, 39 | SI_MS_MASK_ALL = 2 40 | }; 41 | 42 | 43 | #define MAX_NO_OF_GROUPS 4 44 | 45 | #define MAX_SFB_SHORT 15 46 | #define MAX_SFB_LONG 51 47 | #define MAX_SFB (MAX_SFB_SHORT > MAX_SFB_LONG ? MAX_SFB_SHORT : MAX_SFB_LONG) /* = MAX_SFB_LONG */ 48 | #define MAX_GROUPED_SFB (MAX_NO_OF_GROUPS*MAX_SFB_SHORT > MAX_SFB_LONG ? \ 49 | MAX_NO_OF_GROUPS*MAX_SFB_SHORT : MAX_SFB_LONG) 50 | 51 | #define BLOCK_SWITCHING_OFFSET (1*1024+3*128+64+128) 52 | #define BLOCK_SWITCHING_DATA_SIZE FRAME_LEN_LONG 53 | 54 | #define MAX_CHANNEL_BITS 6144 55 | 56 | #define TRANSFORM_OFFSET_LONG 0 57 | #define TRANSFORM_OFFSET_SHORT 448 58 | 59 | 60 | #define PCM_LEVEL 1.0f 61 | #define NORM_PCM (PCM_LEVEL) 62 | #define NORM_PCM_ENERGY (NORM_PCM*NORM_PCM) 63 | 64 | 65 | 66 | #endif /* _PSYCONST_H */ 67 | -------------------------------------------------------------------------------- /libaacenc/psy_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | Psychoaccoustic data 3 | */ 4 | #ifndef _PSY_DATA_H 5 | #define _PSY_DATA_H 6 | 7 | #include "block_switch.h" 8 | #include "tns.h" 9 | 10 | /* 11 | the structs can be implemented as unions 12 | */ 13 | 14 | typedef struct{ 15 | float Long[MAX_GROUPED_SFB]; 16 | float Short[TRANS_FAC][MAX_SFB_SHORT]; 17 | }SFB_THRESHOLD; 18 | 19 | typedef struct{ 20 | float Long[MAX_GROUPED_SFB]; 21 | float Short[TRANS_FAC][MAX_SFB_SHORT]; 22 | }SFB_ENERGY; 23 | 24 | typedef struct{ 25 | float Long; 26 | float Short[TRANS_FAC]; 27 | }SFB_ENERGY_SUM; 28 | 29 | typedef struct{ 30 | BLOCK_SWITCHING_CONTROL blockSwitchingControl; /* block switching */ 31 | float *mdctDelayBuffer; /* mdct delay buffer [BLOCK_SWITCHING_OFFSET]*/ 32 | float sfbThresholdnm1[MAX_SFB]; /* PreEchoControl */ 33 | 34 | SFB_THRESHOLD sfbThreshold; /* adapt */ 35 | SFB_ENERGY sfbEnergy; /* sfb Energy */ 36 | SFB_ENERGY sfbEnergyMS; 37 | SFB_ENERGY_SUM sfbEnergySum; 38 | SFB_ENERGY_SUM sfbEnergySumMS; 39 | SFB_ENERGY sfbSpreadedEnergy; 40 | 41 | float *mdctSpectrum; /* mdct spectrum [FRAME_LEN_LONG] */ 42 | }PSY_DATA; 43 | 44 | #endif /* _PSY_DATA_H */ 45 | -------------------------------------------------------------------------------- /libaacenc/psy_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Psychoaccoustic main module 3 | */ 4 | #ifndef _PSYMAIN_H 5 | #define _PSYMAIN_H 6 | 7 | #include "psy_configuration.h" 8 | #include "qc_data.h" 9 | 10 | 11 | /* 12 | psy kernel 13 | */ 14 | typedef struct { 15 | PSY_CONFIGURATION_LONG psyConfLong; 16 | PSY_CONFIGURATION_SHORT psyConfShort; 17 | PSY_DATA psyData[MAX_CHANNELS]; 18 | TNS_DATA tnsData[MAX_CHANNELS]; 19 | float* pScratchTns; 20 | }PSY_KERNEL; 21 | 22 | 23 | int PsyNew( PSY_KERNEL *hPsy, int nChan); 24 | int PsyDelete( PSY_KERNEL *hPsy); 25 | 26 | int PsyOutNew( PSY_OUT *hPsyOut); 27 | int PsyOutDelete( PSY_OUT *hPsyOut); 28 | 29 | int psyMainInit( PSY_KERNEL *hPsy, 30 | int sampleRate, 31 | int bitRate, 32 | int channels, 33 | int tnsMask, 34 | int bandwidth); 35 | 36 | 37 | int psyMain(int nChannels, /*! total number of channels */ 38 | ELEMENT_INFO *elemInfo, 39 | float *timeSignal, /*! interleaved time signal */ 40 | PSY_DATA psyData[MAX_CHANNELS], 41 | TNS_DATA tnsData[MAX_CHANNELS], 42 | PSY_CONFIGURATION_LONG *psyConfLong, 43 | PSY_CONFIGURATION_SHORT *psyConfShort, 44 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 45 | PSY_OUT_ELEMENT *psyOutElement, 46 | float *pScratchTns); 47 | 48 | #endif /* _PSYMAIN_H */ 49 | 50 | -------------------------------------------------------------------------------- /libaacenc/qc_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | Quantizing & coding data 3 | */ 4 | #ifndef _QC_DATA_H 5 | #define _QC_DATA_H 6 | 7 | #include "psy_const.h" 8 | #include "dyn_bits.h" 9 | #include "adj_thr_data.h" 10 | 11 | 12 | typedef enum { 13 | ID_SCE=0, /* Single Channel Element */ 14 | ID_CPE=1, /* Channel Pair Element */ 15 | ID_FIL=6, 16 | ID_END=7 17 | } ELEMENT_TYPE; 18 | 19 | typedef struct { 20 | ELEMENT_TYPE elType; 21 | int instanceTag; 22 | int nChannelsInEl; 23 | int ChannelIndex[MAX_CHANNELS]; 24 | } ELEMENT_INFO; 25 | 26 | typedef struct { 27 | int paddingRest; 28 | } PADDING; 29 | 30 | 31 | /* Quantizing & coding stage */ 32 | 33 | struct QC_INIT{ 34 | ELEMENT_INFO* elInfo; 35 | int maxBits; /* maximum number of bits in reservoir */ 36 | int averageBits; /* average number of bits we should use */ 37 | int bitRes; 38 | float meanPe; 39 | int chBitrate; 40 | int invQuant; 41 | float maxBitFac; 42 | int bitrate; 43 | 44 | PADDING padding; 45 | }; 46 | 47 | typedef struct 48 | { 49 | short *quantSpec; /* [FRAME_LEN_LONG]; */ 50 | unsigned short *maxValueInSfb; /* [MAX_GROUPED_SFB]; */ 51 | short *scf; /* [MAX_GROUPED_SFB]; */ 52 | int globalGain; 53 | int groupingMask; 54 | SECTION_DATA sectionData; 55 | int windowShape; /* doesn't really belong here. Convenient, though. */ 56 | } QC_OUT_CHANNEL; 57 | 58 | typedef struct 59 | { 60 | int staticBitsUsed; /* for verification purposes */ 61 | int dynBitsUsed; /* for verification purposes */ 62 | float pe; 63 | int ancBitsUsed; 64 | int fillBits; 65 | } QC_OUT_ELEMENT; 66 | 67 | typedef struct 68 | { 69 | QC_OUT_CHANNEL qcChannel[MAX_CHANNELS]; 70 | QC_OUT_ELEMENT qcElement; 71 | int totStaticBitsUsed; /* for verification purposes */ 72 | int totDynBitsUsed; /* for verification purposes */ 73 | int totAncBitsUsed; /* for verification purposes */ 74 | int totFillBits; 75 | int alignBits; 76 | int bitResTot; 77 | int averageBitsTot; 78 | } QC_OUT; 79 | 80 | typedef struct { 81 | int chBitrate; 82 | int averageBits; /* brutto -> look ancillary.h */ 83 | int maxBits; 84 | int bitResLevel; 85 | int maxBitResBits; 86 | float relativeBits; /* Bits relative to total Bits*/ 87 | } ELEMENT_BITS; 88 | 89 | typedef struct 90 | { 91 | /* this is basically struct QC_INIT */ 92 | int averageBitsTot; 93 | int maxBitsTot; 94 | int globStatBits; 95 | int nChannels; 96 | int bitResTot; 97 | 98 | float maxBitFac; 99 | 100 | PADDING padding; 101 | 102 | ELEMENT_BITS elementBits; 103 | ADJ_THR_STATE adjThr; 104 | 105 | } QC_STATE; 106 | 107 | #endif /* _QC_DATA_H */ 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /libaacenc/qc_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Quantizing & coding main module 3 | */ 4 | #ifndef _QC_MAIN_H 5 | #define _QC_MAIN_H 6 | 7 | #include "qc_data.h" 8 | #include "interface.h" 9 | 10 | 11 | int QCOutNew(QC_OUT *hQC, int nChannels); 12 | 13 | void QCOutDelete(QC_OUT *hQC); 14 | 15 | int QCNew(QC_STATE *hQC); 16 | 17 | int QCInit(QC_STATE *hQC, struct QC_INIT *init); 18 | void QCDelete(QC_STATE *hQC); 19 | 20 | 21 | int QCMain(QC_STATE *hQC, 22 | int nChannels, 23 | ELEMENT_BITS* elBits, 24 | ATS_ELEMENT* adjThrStateElement, 25 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 26 | PSY_OUT_ELEMENT* psyOutElement, 27 | QC_OUT_CHANNEL qcOutChannel[MAX_CHANNELS], 28 | QC_OUT_ELEMENT* qcOutElement, 29 | int ancillaryDataBytes); 30 | 31 | void UpdateBitres(QC_STATE* qcKernel, 32 | QC_OUT* qcOut); 33 | 34 | int FinalizeBitConsumption(QC_STATE *hQC, 35 | QC_OUT* qcOut); 36 | 37 | int AdjustBitrate(QC_STATE *hQC, 38 | int bitRate, 39 | int sampleRate); 40 | 41 | #endif /* _QC_MAIN_H */ 42 | -------------------------------------------------------------------------------- /libaacenc/quantize.c: -------------------------------------------------------------------------------- 1 | /* 2 | Quantization submodule 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "minmax.h" 9 | #include "quantize.h" 10 | #include "float.h" 11 | #include "aac_rom.h" 12 | #include "FloatFR.h" 13 | 14 | #include "counters.h" /* the 3GPP instrumenting tool */ 15 | 16 | 17 | 18 | 19 | 20 | /***************************************************************************** 21 | 22 | functionname:quantizeLines 23 | description: quantizes spectrum lines 24 | quaSpectrum = mdctSpectrum^3/4*2^(-(3/16)*gain) 25 | input: global gain, number of lines to process, spectral data 26 | output: quantized spectrum 27 | 28 | *****************************************************************************/ 29 | static void quantizeLines(const int gain, 30 | const int noOfLines, 31 | const float *mdctSpectrum, 32 | signed short *quaSpectrum) 33 | { 34 | float quantizer; 35 | float k = (-0.0946f+ 0.5f)/8192.0f; 36 | int line; 37 | 38 | COUNT_sub_start("quantizeLines"); 39 | 40 | MOVE(1); /* counting previous operation */ 41 | 42 | PTR_INIT(2); /* mdctSpectrum[line] 43 | quaSpectrum[line] 44 | */ 45 | LOOP(1); 46 | for (line = 0; line < noOfLines; line++) 47 | { 48 | float tmp = mdctSpectrum[line]; 49 | 50 | MOVE(1); /* counting previous operation */ 51 | 52 | MOVE(1); 53 | k = -0.0946f + 0.5f; 54 | 55 | SHIFT(1); ADD(1); LOGIC(1); INDIRECT(2); MULT(1); 56 | quantizer=quantTableE[(gain>>4)+8] * quantTableQ[gain & 15]; 57 | 58 | BRANCH(1); 59 | if (tmp < 0.0f) { 60 | 61 | MULT(1); TRANS(1); 62 | tmp = (float)sqrt(-tmp); 63 | 64 | TRANS(1); MULT(1); 65 | tmp *= (float)sqrt(tmp); /* x^(3/4) */ 66 | 67 | ADD(1); MULT(2); STORE(1); 68 | quaSpectrum[line] = -(int)(k + quantizer * tmp); 69 | } 70 | else { 71 | TRANS(1); 72 | tmp = (float)sqrt(tmp); 73 | 74 | TRANS(1); MULT(1); 75 | tmp *= (float)sqrt(tmp); /* x^(3/4) */ 76 | 77 | MULT(1); ADD(1); STORE(1); 78 | quaSpectrum[line] = (int)(k + quantizer * tmp); 79 | } 80 | } 81 | 82 | COUNT_sub_end(); 83 | } 84 | 85 | 86 | /***************************************************************************** 87 | 88 | functionname: QuantizeSpectrum 89 | description: quantizes the entire spectrum 90 | returns: 91 | input: number of scalefactor bands to be quantized, ... 92 | output: quantized spectrum 93 | 94 | *****************************************************************************/ 95 | void QuantizeSpectrum(int sfbCnt, 96 | int maxSfbPerGroup, 97 | int sfbPerGroup, 98 | int *sfbOffset, 99 | float *mdctSpectrum, 100 | int globalGain, 101 | short *scalefactors, 102 | short *quantizedSpectrum) 103 | { 104 | int sfbOffs,sfb; 105 | 106 | COUNT_sub_start("QuantizeSpectrum"); 107 | 108 | LOOP(1); 109 | for(sfbOffs=0;sfbOffs>4)+8]*quantTableQ[gain & 15]; 178 | float invQuantizer = invQuantTableE[(gain>>4)+8]*invQuantTableQ[gain & 15]; 179 | 180 | COUNT_sub_start("calcSfbDist"); 181 | 182 | MOVE(2); SHIFT(1); INDIRECT(4); MULT(2); /* counting previous operations */ 183 | 184 | PTR_INIT(3); /* pointer for quantSpec[], 185 | expSpec[], 186 | spec[] 187 | */ 188 | LOOP(1); 189 | for(i=0;i 5 | #include 6 | #include 7 | #include "spreading.h" 8 | #include "minmax.h" 9 | 10 | #include "counters.h" /* the 3GPP instrumenting tool */ 11 | 12 | 13 | 14 | void SpreadingMax(const int pbCnt, 15 | const float *maskLowFactor, 16 | const float *maskHighFactor, 17 | float *pbSpreadedEnergy) 18 | { 19 | int i; 20 | 21 | COUNT_sub_start("SpreadingMax"); 22 | 23 | /* slope to higher frequencies */ 24 | PTR_INIT(2); /* pointers for pbSpreadedEnergy[], 25 | maskHighFactor[] 26 | */ 27 | LOOP(1); 28 | for (i=1; i=0; i--) { 41 | 42 | MULT(1); ADD(1); BRANCH(1); MOVE(1); 43 | pbSpreadedEnergy[i] = max(pbSpreadedEnergy[i], 44 | maskLowFactor[i] * pbSpreadedEnergy[i+1]); 45 | } 46 | 47 | COUNT_sub_end(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /libaacenc/spreading.h: -------------------------------------------------------------------------------- 1 | /* 2 | Spreading of energy and weighted tonality 3 | */ 4 | #ifndef _SPREADING_H 5 | #define _SPREADING_H 6 | 7 | void SpreadingMax(const int pbCnt, 8 | const float *maskLowFactor, 9 | const float *maskHighFactor, 10 | float *pbSpreadedEnergy); 11 | 12 | #endif /* #ifndef _SPREADING_H */ 13 | -------------------------------------------------------------------------------- /libaacenc/stat_bits.c: -------------------------------------------------------------------------------- 1 | /* 2 | Static bit counter $Revision 3 | */ 4 | #include "stat_bits.h" 5 | #include "bitenc.h" 6 | #include "tns.h" 7 | 8 | #include "counters.h" /* the 3GPP instrumenting tool */ 9 | 10 | typedef enum{ 11 | SI_ID_BITS =(3), 12 | SI_FILL_COUNT_BITS =(4), 13 | SI_FILL_ESC_COUNT_BITS =(8), 14 | SI_FILL_EXTENTION_BITS =(4), 15 | SI_FILL_NIBBLE_BITS =(4), 16 | SI_SCE_BITS =(4), 17 | SI_CPE_BITS =(5), 18 | SI_CPE_MS_MASK_BITS =(2) , 19 | SI_ICS_INFO_BITS_LONG =(1+2+1+6+1), 20 | SI_ICS_INFO_BITS_SHORT =(1+2+1+4+7), 21 | SI_ICS_BITS =(8+1+1+1), 22 | }SI_BITS; 23 | 24 | 25 | 26 | static int countMsMaskBits(int sfbCnt, 27 | int sfbPerGroup, 28 | int maxSfbPerGroup, 29 | struct TOOLSINFO *toolsInfo) 30 | { 31 | 32 | int msBits=0,sfbOff,sfb; 33 | 34 | COUNT_sub_start("countMsMaskBits"); 35 | 36 | MOVE(1); /* counting previous operation */ 37 | 38 | INDIRECT(1); BRANCH(2); 39 | switch(toolsInfo->msDigest) 40 | { 41 | case MS_NONE: 42 | case MS_ALL: 43 | break; 44 | 45 | case MS_SOME: 46 | 47 | LOOP(1); 48 | for(sfbOff = 0; sfbOff < sfbCnt; sfbOff+=sfbPerGroup) 49 | { 50 | LOOP(1); 51 | for(sfb=0; sfbnumOfFilters[] */ 88 | LOOP(1); 89 | for (i=0; itnsActive[i]==1) { 93 | 94 | MOVE(1); 95 | tnsPresent=1; 96 | } 97 | } 98 | 99 | BRANCH(1); 100 | if (tnsPresent==0) { 101 | /* count+=1; */ 102 | } 103 | else{ /* there is data to be written*/ 104 | /*count += 1; */ 105 | 106 | PTR_INIT(2); /* tnsInfo->tnsActive[] 107 | tnsInfo->coefRes[] 108 | */ 109 | LOOP(1); 110 | for (i=0; itnsActive[i]) { 117 | 118 | ADD(1); 119 | count += 1; 120 | 121 | ADD(1); BRANCH(1); /* .. == .. ? */ ADD(2); 122 | count +=(blockType==SHORT_WINDOW?4:6); 123 | count +=(blockType==SHORT_WINDOW?3:5); 124 | 125 | BRANCH(1); 126 | if (tnsInfo->order[i]){ 127 | 128 | ADD(2); 129 | count +=1; /*direction*/ 130 | count +=1; /*coef_compression */ 131 | 132 | ADD(1); BRANCH(1); 133 | if(tnsInfo->coefRes[i] == 4) { 134 | 135 | MOVE(1); 136 | coefBits=3; 137 | 138 | PTR_INIT(1); /* tnsInfo->coef[]*/ 139 | LOOP(1); 140 | for(k=0; korder[i]; k++) { 141 | 142 | ADD(2); LOGIC(1); BRANCH(1); 143 | if (tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]> 3 || 144 | tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]< -4) { 145 | 146 | MOVE(1); 147 | coefBits = 4; 148 | break; 149 | } 150 | } 151 | } 152 | else { 153 | 154 | MOVE(1); 155 | coefBits = 2; 156 | 157 | PTR_INIT(1); /* tnsInfo->coef[]*/ 158 | LOOP(1); 159 | for(k=0; korder[i]; k++) { 160 | 161 | ADD(2); LOGIC(1); BRANCH(1); 162 | if (tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]> 1 || 163 | tnsInfo->coef[i*TNS_MAX_ORDER_SHORT+k]< -2) { 164 | 165 | MOVE(1); 166 | coefBits = 3; 167 | break; 168 | } 169 | } 170 | } 171 | 172 | LOOP(1); 173 | for (k=0; korder[i]; k++ ) { 174 | 175 | ADD(1); 176 | count +=coefBits; 177 | } 178 | } 179 | } 180 | } 181 | } 182 | 183 | COUNT_sub_end(); 184 | 185 | return count; 186 | } 187 | 188 | 189 | static int countTnsBits(TNS_INFO *tnsInfo,int blockType) 190 | { 191 | COUNT_sub_start("countTnsBits"); 192 | FUNC(2); 193 | COUNT_sub_end(); 194 | 195 | return(tnsCount(tnsInfo, blockType)); 196 | } 197 | 198 | 199 | 200 | 201 | 202 | int countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 203 | PSY_OUT_ELEMENT *psyOutElement, 204 | int channels) 205 | { 206 | 207 | int statBits=0; 208 | int ch; 209 | 210 | COUNT_sub_start("countStaticBitdemand"); 211 | 212 | MOVE(1); /* counting previous operation */ 213 | 214 | BRANCH(2); 215 | switch(channels) { 216 | 217 | case 1: 218 | 219 | ADD(1); 220 | statBits+=SI_ID_BITS+SI_SCE_BITS+SI_ICS_BITS; 221 | 222 | PTR_INIT(1); FUNC(2); ADD(1); 223 | statBits+=countTnsBits(&(psyOutChannel[0].tnsInfo), 224 | psyOutChannel[0].windowSequence); 225 | 226 | BRANCH(2); 227 | switch(psyOutChannel[0].windowSequence){ 228 | case LONG_WINDOW: 229 | case START_WINDOW: 230 | case STOP_WINDOW: 231 | 232 | ADD(1); 233 | statBits+=SI_ICS_INFO_BITS_LONG; 234 | break; 235 | case SHORT_WINDOW: 236 | 237 | ADD(1); 238 | statBits+=SI_ICS_INFO_BITS_SHORT; 239 | break; 240 | } 241 | break; 242 | 243 | case 2: 244 | ADD(1); 245 | statBits+=SI_ID_BITS+SI_CPE_BITS+2*SI_ICS_BITS; 246 | 247 | ADD(1); 248 | statBits+=SI_CPE_MS_MASK_BITS; 249 | 250 | INDIRECT(1); PTR_INIT(1); FUNC(4); ADD(1); 251 | statBits+=countMsMaskBits(psyOutChannel[0].sfbCnt, 252 | psyOutChannel[0].sfbPerGroup, 253 | psyOutChannel[0].maxSfbPerGroup, 254 | &psyOutElement->toolsInfo); 255 | 256 | PTR_INIT(1); /* psyOutChannel[] */ 257 | 258 | switch(psyOutChannel[0].windowSequence) { 259 | 260 | case LONG_WINDOW: 261 | case START_WINDOW: 262 | case STOP_WINDOW: 263 | 264 | ADD(1); 265 | statBits+=SI_ICS_INFO_BITS_LONG; 266 | break; 267 | 268 | case SHORT_WINDOW: 269 | 270 | ADD(1); 271 | statBits+=SI_ICS_INFO_BITS_SHORT; 272 | break; 273 | } 274 | 275 | PTR_INIT(1); /* psyOutChannel[ch] */ 276 | LOOP(1); 277 | for(ch=0;ch<2;ch++) { 278 | 279 | PTR_INIT(1); FUNC(2); ADD(1); 280 | statBits+=countTnsBits(&(psyOutChannel[ch].tnsInfo), 281 | psyOutChannel[ch].windowSequence); 282 | } 283 | 284 | break; 285 | } 286 | 287 | COUNT_sub_end(); 288 | 289 | return statBits; 290 | } 291 | 292 | -------------------------------------------------------------------------------- /libaacenc/stat_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | Static bit counter 3 | */ 4 | #ifndef __STAT_BITS_H 5 | #define __STAT_BITS_H 6 | 7 | #include "psy_const.h" 8 | #include "interface.h" 9 | 10 | int countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 11 | PSY_OUT_ELEMENT *psyOutElement, 12 | int nChannels); 13 | 14 | 15 | #endif /* __STAT_BITS_H */ 16 | 17 | -------------------------------------------------------------------------------- /libaacenc/stprepro.h: -------------------------------------------------------------------------------- 1 | /* 2 | stereo preprocessing struct and prototypes 3 | */ 4 | #ifndef __STPREPRO_H 5 | #define __STPREPRO_H 6 | 7 | struct STEREO_PREPRO; 8 | typedef struct STEREO_PREPRO *HANDLE_STEREO_PREPRO; 9 | 10 | #include "interface.h" 11 | #include "channel_map.h" 12 | 13 | struct STEREO_PREPRO { 14 | 15 | float normPeFac; /*! factor to normalize input PE, depends on bitrate and bandwidth */ 16 | float stereoAttenuationInc; /*! att. increment parameter */ 17 | float stereoAttenuationDec; /*! att. decrement parameter */ 18 | 19 | float avrgFreqEnergyL; /*! energy left */ 20 | float avrgFreqEnergyR; /*! energy right */ 21 | float avrgFreqEnergyM; /*! energy mid */ 22 | float avrgFreqEnergyS; /*! energy side */ 23 | float smoothedPeSumSum; /*! time-smoothed PE */ 24 | float avgStoM; /*! time-smoothed energy ratio S/M [dB] */ 25 | float lastLtoR; /*! previous frame energy ratio L/R [dB] */ 26 | float lastNrgLR; /*! previous frame energy L+R */ 27 | 28 | float ImpactFactor; /*! bitrate dependent parameter */ 29 | float stereoAttenuation; /*! the actual attenuation of this frame */ 30 | float stereoAttFac; /*! the actual attenuation factor of this frame */ 31 | 32 | /* tuning parameters that are not varied from frame to frame but initialized at init */ 33 | int stereoAttenuationFlag; /*! flag to indicate usage */ 34 | float ConstAtt; /*! if not zero, a constant att. will be applied [dB]*/ 35 | float stereoAttMax; /*! the max. attenuation [dB]*/ 36 | 37 | float LRMin; /*! tuning parameter [dB] */ 38 | float LRMax; /*! tuning parameter [dB] */ 39 | float SMMin; /*! tuning parameter [dB] */ 40 | float SMMid; /*! tuning parameter [dB] */ 41 | float SMMax; /*! tuning parameter [dB] */ 42 | 43 | float PeMin; /*! tuning parameter */ 44 | float PeCrit; /*! tuning parameter */ 45 | float PeImpactMax; /*! tuning parameter */ 46 | }; 47 | 48 | int InitStereoPreProcessing(HANDLE_STEREO_PREPRO hStPrePro, 49 | int nChannels, 50 | int bitRate, 51 | int sampleRate, 52 | float usedScfRatio); 53 | 54 | void ApplyStereoPreProcess(HANDLE_STEREO_PREPRO hStPrePro, 55 | int nChannels, /*! total number of channels */ 56 | ELEMENT_INFO *elemInfo, 57 | float *timeData, 58 | int granuleLen); 59 | 60 | void UpdateStereoPreProcess(PSY_OUT_CHANNEL psyOutChan[MAX_CHANNELS], 61 | QC_OUT_ELEMENT* qcOutElement, 62 | HANDLE_STEREO_PREPRO hStPrePro, 63 | float weightPeFac); 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /libaacenc/tns.h: -------------------------------------------------------------------------------- 1 | /* 2 | Temporal Noise Shaping 3 | */ 4 | #ifndef _TNS_H 5 | #define _TNS_H 6 | 7 | #include "psy_const.h" 8 | #include "math.h" 9 | 10 | #define TNS_MAX_ORDER 12 11 | #define TNS_MAX_ORDER_SHORT 5 12 | #define FILTER_DIRECTION 0 13 | 14 | typedef struct{ 15 | float threshOn; 16 | int lpcStartFreq; 17 | int lpcStopFreq; 18 | float tnsTimeResolution; 19 | }TNS_CONFIG_TABULATED; 20 | 21 | 22 | typedef struct { 23 | char tnsActive; 24 | int tnsMaxSfb; 25 | 26 | int maxOrder; 27 | int tnsStartFreq; 28 | int coefRes; 29 | 30 | TNS_CONFIG_TABULATED confTab; 31 | 32 | float acfWindow[TNS_MAX_ORDER+1]; 33 | int tnsStartBand; 34 | int tnsStartLine; 35 | 36 | int tnsStopBand; 37 | int tnsStopLine; 38 | 39 | int lpcStartBand; 40 | int lpcStartLine; 41 | 42 | int lpcStopBand; 43 | int lpcStopLine; 44 | 45 | int tnsRatioPatchLowestCb; 46 | int tnsModifyBeginCb; 47 | 48 | float threshold; 49 | 50 | }TNS_CONFIG; 51 | 52 | 53 | typedef struct { 54 | char tnsActive; 55 | float parcor[TNS_MAX_ORDER]; 56 | float predictionGain; 57 | } TNS_SUBBLOCK_INFO; 58 | 59 | typedef struct{ 60 | TNS_SUBBLOCK_INFO subBlockInfo[TRANS_FAC]; 61 | } TNS_DATA_SHORT; 62 | 63 | typedef struct{ 64 | TNS_SUBBLOCK_INFO subBlockInfo; 65 | } TNS_DATA_LONG; 66 | 67 | /* 68 | can be implemented as union 69 | */ 70 | typedef struct{ 71 | TNS_DATA_LONG Long; 72 | TNS_DATA_SHORT Short; 73 | }TNS_DATA_RAW; 74 | 75 | typedef struct{ 76 | int numOfSubblocks; 77 | TNS_DATA_RAW dataRaw; 78 | }TNS_DATA; 79 | 80 | typedef struct{ 81 | char tnsActive[TRANS_FAC]; 82 | char coefRes[TRANS_FAC]; 83 | int length[TRANS_FAC]; 84 | int order[TRANS_FAC]; 85 | /* for Long: length TNS_MAX_ORDER (12 for LC) is required -> 12 */ 86 | /* for Short: length TRANS_FAC*TNS_MAX_ORDER_SHORT (only 5 for short LC) is required -> 8*5=40 */ 87 | int coef[TRANS_FAC*TNS_MAX_ORDER_SHORT]; 88 | }TNS_INFO; 89 | 90 | #endif /* _TNS_H */ 91 | -------------------------------------------------------------------------------- /libaacenc/tns_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | Temporal Noise Shaping 3 | */ 4 | #ifndef _TNS_FUNC_H 5 | #define _TNS_FUNC_H 6 | #include "psy_configuration.h" 7 | 8 | int InitTnsConfiguration(int bitrate, 9 | long samplerate, 10 | int channels, 11 | TNS_CONFIG *tnsConfig, 12 | PSY_CONFIGURATION_LONG psyConfig, 13 | int active); 14 | 15 | int InitTnsConfigurationShort(int bitrate, 16 | long samplerate, 17 | int channels, 18 | TNS_CONFIG *tnsConfig, 19 | PSY_CONFIGURATION_SHORT psyConfig, 20 | int active); 21 | 22 | int TnsDetect(TNS_DATA* tnsData, 23 | TNS_CONFIG tC, 24 | float* pScratchTns, 25 | const int sfbOffset[], 26 | float* spectrum, 27 | int subBlockNumber, 28 | int blockType, 29 | float * sfbEnergy); 30 | 31 | void TnsSync(TNS_DATA *tnsDataDest, 32 | const TNS_DATA *tnsDataSrc, 33 | const TNS_CONFIG tC, 34 | const int subBlockNumber, 35 | const int blockType); 36 | 37 | int TnsEncode(TNS_INFO* tnsInfo, 38 | TNS_DATA* tnsData, 39 | int numOfSfb, 40 | TNS_CONFIG tC, 41 | int lowPassLine, 42 | float* spectrum, 43 | int subBlockNumber, 44 | int blockType); 45 | 46 | void ApplyTnsMultTableToRatios(int startCb, 47 | int stopCb, 48 | float *thresholds); 49 | 50 | 51 | #endif /* _TNS_FUNC_H */ 52 | -------------------------------------------------------------------------------- /libaacenc/tns_param.c: -------------------------------------------------------------------------------- 1 | /* 2 | Temporal Noise Shaping parameters 3 | */ 4 | #include 5 | #include "aac_rom.h" 6 | 7 | #include "counters.h" /* the 3GPP instrumenting tool */ 8 | 9 | 10 | /***************************************************************************** 11 | 12 | functionname: GetTnsParam 13 | description: Get threshold calculation parameter set that best matches 14 | the bit rate 15 | returns: the parameter set 16 | input: blockType, bitRate 17 | output: the parameter set 18 | 19 | *****************************************************************************/ 20 | int GetTnsParam(TNS_CONFIG_TABULATED *tnsConfigTab, int bitRate, int channels, int blockType) { 21 | 22 | unsigned int i; 23 | 24 | COUNT_sub_start("GetTnsParam"); 25 | 26 | PTR_INIT(1); /* tnsInfoTab[] */ 27 | 28 | BRANCH(1); LOGIC(1); 29 | if (tnsConfigTab == NULL) 30 | return 1; 31 | 32 | MOVE(1); 33 | tnsConfigTab->threshOn = -1.0f; 34 | 35 | LOOP(1); 36 | for(i = 0; i < sizeof(tnsInfoTab)/sizeof(TNS_INFO_TAB); i++) { 37 | 38 | ADD(2); LOGIC(1); BRANCH(1); 39 | if((bitRate >= tnsInfoTab[i].bitRateFrom) && bitRate <= tnsInfoTab[i].bitRateTo) { 40 | 41 | BRANCH(2); 42 | switch(blockType) { 43 | 44 | case LONG_WINDOW : 45 | BRANCH(2); 46 | switch(channels) { 47 | case 1 : 48 | MOVE(1); 49 | *tnsConfigTab=*tnsInfoTab[i].paramMono_Long; 50 | break; 51 | case 2 : 52 | MOVE(1); 53 | *tnsConfigTab=*tnsInfoTab[i].paramStereo_Long; 54 | break; 55 | } 56 | break; 57 | 58 | case SHORT_WINDOW : 59 | BRANCH(2); 60 | switch(channels) { 61 | case 1 : 62 | BRANCH(1); 63 | MOVE(1); 64 | *tnsConfigTab=*tnsInfoTab[i].paramMono_Short; 65 | break; 66 | case 2 : 67 | MOVE(1); 68 | *tnsConfigTab=*tnsInfoTab[i].paramStereo_Short; 69 | break; 70 | } 71 | 72 | break; 73 | } 74 | } 75 | } 76 | 77 | BRANCH(1); LOGIC(1); 78 | if (tnsConfigTab->threshOn == -1.0f) { 79 | return 1; 80 | } 81 | 82 | COUNT_sub_end(); 83 | return 0; 84 | } 85 | 86 | /***************************************************************************** 87 | 88 | functionname: GetTnsMaxBands 89 | description: sets tnsMaxSfbLong, tnsMaxSfbShort according to sampling rate 90 | returns: 91 | input: samplingRate, profile, granuleLen 92 | output: tnsMaxSfbLong, tnsMaxSfbShort 93 | 94 | *****************************************************************************/ 95 | void GetTnsMaxBands(int samplingRate, int blockType, int* tnsMaxSfb){ 96 | unsigned int i; 97 | 98 | COUNT_sub_start("GetTnsMaxBands"); 99 | 100 | MULT(1); STORE(1); 101 | *tnsMaxSfb=-1; 102 | 103 | PTR_INIT(1); /* tnsMaxBandsTab[] */ 104 | LOOP(1); 105 | for(i=0;i increment cntBits 36 | read bits from bitstream buffer => decrement cntBits */ 37 | int size; /* size of bitbuffer in bits */ 38 | int isValid; /* indicates whether the instance has been initialized */ 39 | }; 40 | 41 | /* Define pointer to bit buffer structure */ 42 | typedef struct BIT_BUF *HANDLE_BIT_BUF; 43 | 44 | 45 | HANDLE_BIT_BUF CreateBitBuffer(HANDLE_BIT_BUF hBitBuf, 46 | unsigned char *pBitBufBase, 47 | unsigned int bitBufSize); 48 | 49 | void DeleteBitBuffer(HANDLE_BIT_BUF *hBitBuf); 50 | 51 | unsigned long ReadBits(HANDLE_BIT_BUF hBitBuf, 52 | unsigned char noBitsToRead); 53 | 54 | unsigned char WriteBits(HANDLE_BIT_BUF hBitBuf, 55 | unsigned long writeValue, 56 | unsigned char noBitsToWrite); 57 | 58 | void ResetBitBuf(HANDLE_BIT_BUF hBitBuf, 59 | unsigned char *pBitBufBase, 60 | unsigned int bitBufSize); 61 | 62 | void CopyBitBuf(HANDLE_BIT_BUF hBitBufSrc, 63 | HANDLE_BIT_BUF hBitBufDst); 64 | 65 | void WindBitBufferBidirectional(HANDLE_BIT_BUF hBitBuf, 66 | long offset); 67 | 68 | int GetBitsAvail(HANDLE_BIT_BUF hBitBuf); 69 | 70 | #endif /* FFR_BITBUFFER_H */ 71 | -------------------------------------------------------------------------------- /libbitbuf/Makefile: -------------------------------------------------------------------------------- 1 | #################################################################### 2 | # 3 | # Makefile for bit buffer management library 4 | # $Id: Makefile,v 1.2.4.1 2004/02/03 17:40:04 ehr Exp $ 5 | # 6 | #################################################################### 7 | ################## user section: insert objlist here ####### 8 | LIB=libbitbuf.a 9 | 10 | SRCS=$(wildcard *.c) 11 | 12 | OBJS = $(SRCS:.c=.o) 13 | 14 | $(LIB): $(OBJS) 15 | ar r $@ $(OBJS) 16 | 17 | all: $(LIB) 18 | 19 | clean: 20 | rm -f $(OBJS) $(LIB) 21 | -------------------------------------------------------------------------------- /libbitbuf/bitbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Bit Buffer Management 3 | */ 4 | 5 | #include "stdio.h" 6 | #include "assert.h" 7 | #include "FFR_bitbuffer.h" 8 | #include "FloatFR.h" 9 | 10 | #include "counters.h" /* the 3GPP instrumenting tool */ 11 | 12 | /* 13 | The pointer will be incremented if the parameter cnt is positive. Otherwise, 14 | the read pointer will be decremented. 15 | 16 | return none 17 | */ 18 | static void updateBitBufWordPtr(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 19 | unsigned char **pBitBufWord, /* pointer to pointer to bitsteam buffer */ 20 | long cnt) /* number of words */ 21 | { 22 | COUNT_sub_start("updateBitBufWordPtr"); 23 | 24 | ADD(1); STORE(1); 25 | *pBitBufWord += cnt; 26 | 27 | PTR_INIT(2); /* hBitBuf->pBitBufEnd 28 | hBitBuf->pBitBufBase 29 | */ 30 | 31 | ADD(1); BRANCH(1); 32 | if(*pBitBufWord > hBitBuf->pBitBufEnd) { 33 | 34 | ADD(3); STORE(1); 35 | *pBitBufWord -= (hBitBuf->pBitBufEnd - hBitBuf->pBitBufBase + 1); 36 | } 37 | 38 | ADD(1); BRANCH(1); 39 | if(*pBitBufWord < hBitBuf->pBitBufBase) { 40 | 41 | ADD(3); STORE(1); 42 | *pBitBufWord += (hBitBuf->pBitBufEnd - hBitBuf->pBitBufBase + 1); 43 | } 44 | 45 | COUNT_sub_end(); 46 | } 47 | 48 | 49 | /* 50 | Creates and initializes a bit buffer instance; 51 | 52 | returns pointer to bit buffer instance 53 | */ 54 | HANDLE_BIT_BUF CreateBitBuffer(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 55 | unsigned char *pBitBufBase, /* pointer to bitstream buffer */ 56 | unsigned int bitBufSize) /* size of bitstream buffer in words */ 57 | { 58 | COUNT_sub_start("CreateBitBuffer"); 59 | 60 | INDIRECT(1); PTR_INIT(1); 61 | hBitBuf->pBitBufBase = pBitBufBase; 62 | 63 | INDIRECT(1); ADD(2); STORE(1); 64 | hBitBuf->pBitBufEnd = pBitBufBase+bitBufSize-1; 65 | 66 | INDIRECT(2); PTR_INIT(2); 67 | hBitBuf->pReadNext = pBitBufBase; 68 | hBitBuf->pWriteNext = pBitBufBase; 69 | 70 | INDIRECT(2); MOVE(2); 71 | hBitBuf->wBitPos = 7; 72 | hBitBuf->rBitPos = 7; 73 | 74 | INDIRECT(1); MOVE(1); 75 | hBitBuf->cntBits = 0; 76 | 77 | INDIRECT(1); MULT(1); STORE(1); 78 | hBitBuf->size = bitBufSize * 8; 79 | 80 | INDIRECT(1); MOVE(1); 81 | hBitBuf->isValid = 1; 82 | 83 | COUNT_sub_end(); 84 | 85 | return hBitBuf; 86 | } 87 | 88 | 89 | /* 90 | Deletes a bit buffer instance 91 | */ 92 | void DeleteBitBuffer(HANDLE_BIT_BUF *hBitBuf) /* handle to pointer to bit buffer structure */ 93 | { 94 | COUNT_sub_start("DeleteBitBuffer"); 95 | 96 | INDIRECT(1); MOVE(1); 97 | (*hBitBuf)->isValid = 0; 98 | 99 | PTR_INIT(1); 100 | *hBitBuf = NULL; 101 | 102 | COUNT_sub_end(); 103 | } 104 | 105 | /* 106 | Resets elements of a bit buffer instance 107 | */ 108 | void ResetBitBuf(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 109 | unsigned char *pBitBufBase, /* pointer to bitstream buffer */ 110 | unsigned int bitBufSize) /* size of bitstream buffer in words */ 111 | { 112 | COUNT_sub_start("ResetBitBuf"); 113 | 114 | INDIRECT(1); PTR_INIT(1); 115 | hBitBuf->pBitBufBase = pBitBufBase; 116 | 117 | INDIRECT(1); ADD(2); STORE(1); 118 | hBitBuf->pBitBufEnd = pBitBufBase+bitBufSize-1; 119 | 120 | INDIRECT(2); PTR_INIT(2); 121 | hBitBuf->pReadNext = pBitBufBase; 122 | hBitBuf->pWriteNext = pBitBufBase; 123 | 124 | INDIRECT(2); MOVE(2); 125 | hBitBuf->rBitPos = 7; 126 | hBitBuf->wBitPos = 7; 127 | 128 | INDIRECT(1); MOVE(1); 129 | hBitBuf->cntBits = 0; 130 | 131 | COUNT_sub_end(); 132 | } 133 | 134 | 135 | /* 136 | Copy source bit buffer instance to destination bit buffer instance 137 | */ 138 | void CopyBitBuf(HANDLE_BIT_BUF hBitBufSrc, /* handle to source bit buffer structure */ 139 | HANDLE_BIT_BUF hBitBufDst) /* handle to destination bit buffer structure */ 140 | { 141 | int i; 142 | int bytesToGoSrc = (hBitBufSrc->pBitBufEnd - hBitBufSrc->pBitBufBase); 143 | int bytesToGoDst = (hBitBufDst->pBitBufEnd - hBitBufDst->pBitBufBase); 144 | 145 | COUNT_sub_start("CopyBitBuf"); 146 | 147 | INDIRECT(4); ADD(2); /* counting previous operations */ 148 | 149 | assert (bytesToGoSrc==bytesToGoDst); 150 | 151 | PTR_INIT(2); /* hBitBufDst->pBitBufBase[] 152 | hBitBufSrc->pBitBufBase[] 153 | */ 154 | LOOP(1); 155 | for (i=0; ipBitBufBase[i] = hBitBufSrc->pBitBufBase[i]; 159 | } 160 | 161 | INDIRECT(4); MOVE(2); 162 | hBitBufDst->pReadNext = hBitBufSrc->pReadNext; 163 | hBitBufDst->pWriteNext = hBitBufSrc->pWriteNext; 164 | 165 | INDIRECT(4); MOVE(2); 166 | hBitBufDst->rBitPos = hBitBufSrc->rBitPos; 167 | hBitBufDst->wBitPos = hBitBufSrc->wBitPos; 168 | 169 | INDIRECT(2); MOVE(1); 170 | hBitBufDst->cntBits = hBitBufSrc->cntBits; 171 | 172 | INDIRECT(2); MOVE(1); 173 | hBitBufDst->isValid = hBitBufSrc->isValid; 174 | 175 | COUNT_sub_end(); 176 | } 177 | 178 | 179 | int GetBitsAvail(HANDLE_BIT_BUF hBitBuf) 180 | { 181 | return hBitBuf->cntBits; 182 | } 183 | /* 184 | Read a certain number of bits from the bitstream buffer. The read direction is from left to right. 185 | The element cntBits will be decremented with the number of read bits. The element rBitPos will 186 | be set to the new "bit position" 187 | 188 | returns number of bits read 189 | */ 190 | unsigned long ReadBits(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 191 | unsigned char noBitsToRead) /* number of bits to read */ 192 | { 193 | unsigned long returnValue; 194 | 195 | COUNT_sub_start("ReadBits"); 196 | 197 | /* return value is of type unsigned int, it can hold up to 32 bits 198 | this optimized code can read upto 25 Bits a time*/ 199 | ADD(1); BRANCH(1); 200 | if (noBitsToRead >= 25) { 201 | COUNT_sub_end(); 202 | return 0; 203 | } 204 | 205 | 206 | INDIRECT(2); ADD(2); STORE(2); 207 | hBitBuf->cntBits -= noBitsToRead; 208 | hBitBuf->rBitPos -= noBitsToRead; 209 | 210 | PTR_INIT(4); /* hBitBuf->rBitPos 211 | hBitBuf->pReadNext 212 | hBitBuf->pBitBufEnd 213 | hBitBuf->pBitBufBase 214 | */ 215 | 216 | MOVE(1); 217 | returnValue = (unsigned long)*hBitBuf->pReadNext; 218 | 219 | LOOP(1); 220 | while (hBitBuf->rBitPos < 0) 221 | { 222 | ADD(2); STORE(2); 223 | hBitBuf->rBitPos += 8; 224 | hBitBuf->pReadNext++; 225 | 226 | ADD(1); BRANCH(1); 227 | if(hBitBuf->pReadNext > hBitBuf->pBitBufEnd) { 228 | 229 | MOVE(1); 230 | hBitBuf->pReadNext = hBitBuf->pBitBufBase; 231 | } 232 | 233 | SHIFT(1); 234 | returnValue <<= 8; 235 | 236 | LOGIC(1); 237 | returnValue |= (unsigned long)*hBitBuf->pReadNext; 238 | } 239 | 240 | ADD(3); SHIFT(2); 241 | returnValue = returnValue << (31 - noBitsToRead - hBitBuf->rBitPos) >> (32 - noBitsToRead); 242 | 243 | COUNT_sub_end(); 244 | return (returnValue); 245 | } 246 | 247 | 248 | /* 249 | Write a certain number of bits to the bitstream buffer. The write direction is from left to right. 250 | The element cntBits will be incremented with the number of written bits. It is actually irrelevant 251 | if the bits are really written to the bitstream buffer or only to the wCache. 252 | 253 | returns number of bits to write 254 | */ 255 | unsigned char WriteBits(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 256 | unsigned long writeValue, /* write bits in word right bounded */ 257 | unsigned char noBitsToWrite) /* number of bits to write */ 258 | { 259 | int bitsToWrite; 260 | unsigned char bitsWritten = noBitsToWrite; 261 | 262 | assert(noBitsToWrite <= LongSize); 263 | 264 | COUNT_sub_start("WriteBits"); 265 | 266 | MOVE(1); /* counting previous operation */ 267 | 268 | INDIRECT(1); ADD(1); STORE(1); 269 | hBitBuf->cntBits += noBitsToWrite; 270 | 271 | /* Bit Buffer Management: do not write more bits to input buffer than possible */ 272 | assert ( hBitBuf->cntBits <= (hBitBuf->pBitBufEnd - hBitBuf->pBitBufBase + 1) * 8); 273 | 274 | PTR_INIT(4); /* hBitBuf->wBitPos 275 | hBitBuf->pWriteNext 276 | hBitBuf->pBitBufEnd 277 | hBitBuf->pBitBufBase 278 | */ 279 | LOOP(1); 280 | while (noBitsToWrite) { 281 | unsigned char tmp,msk; 282 | 283 | ADD(2); BRANCH(1); MOVE(1); 284 | bitsToWrite = min(hBitBuf->wBitPos + 1, noBitsToWrite); 285 | 286 | ADD(4); SHIFT(3); 287 | tmp = (unsigned char) ( writeValue << (32 - noBitsToWrite) >> (32 - bitsToWrite) << (hBitBuf->wBitPos + 1 - bitsToWrite) ); 288 | 289 | ADD(1); SHIFT(2); LOGIC(1); /* (hBitBuf->wBitPos + 1 - bitsToWrite) --> already calculated */ 290 | msk = ~(((1 << bitsToWrite) - 1) << (hBitBuf->wBitPos + 1 - bitsToWrite)); 291 | 292 | LOGIC(2); STORE(1); 293 | *hBitBuf->pWriteNext &= msk; 294 | *hBitBuf->pWriteNext |= tmp; 295 | 296 | ADD(1); STORE(1); 297 | hBitBuf->wBitPos -= bitsToWrite; 298 | 299 | ADD(1); 300 | noBitsToWrite -= bitsToWrite; 301 | 302 | BRANCH(1); 303 | if (hBitBuf->wBitPos < 0) { 304 | 305 | ADD(2); STORE(2); 306 | hBitBuf->wBitPos += 8; 307 | hBitBuf->pWriteNext++; 308 | 309 | ADD(1); BRANCH(1); 310 | if (hBitBuf->pWriteNext > hBitBuf->pBitBufEnd) { 311 | 312 | MOVE(1); 313 | hBitBuf->pWriteNext= hBitBuf->pBitBufBase; 314 | } 315 | } 316 | 317 | } 318 | 319 | COUNT_sub_end(); 320 | 321 | return(bitsWritten); 322 | } 323 | 324 | 325 | /* 326 | The read pointer will be winded a certain number of bits in forward or backward direction. The forward direction 327 | is chosen if the offset is positive, and the backward direction is chosen of the offset is negative. The pointer 328 | pReadNext and the elements rCache and rBitsLeft will be updated. The element cntBits will be decremented if the 329 | read pointer is updated in forward direction, and incremented if the read pointer is updated in backward direction. 330 | */ 331 | void WindBitBufferBidirectional(HANDLE_BIT_BUF hBitBuf, /* handle to bit buffer structure */ 332 | long offset) /* positive number => wind offset in forward direction 333 | negative number => wind offset in backward direction */ 334 | { 335 | COUNT_sub_start("WindBitBufferBidirectional"); 336 | 337 | BRANCH(1); 338 | if (offset != 0) 339 | { 340 | int bOffset; 341 | 342 | INDIRECT(1); ADD(1); STORE(1); 343 | hBitBuf->rBitPos -= offset; 344 | 345 | SHIFT(1); 346 | bOffset = hBitBuf->rBitPos >> 3; 347 | 348 | SHIFT(1); ADD(1); STORE(1); 349 | hBitBuf->rBitPos -= bOffset << 3; 350 | 351 | BRANCH(1); 352 | if (bOffset) { 353 | 354 | MULT(1); INDIRECT(1); PTR_INIT(1); FUNC(3); 355 | updateBitBufWordPtr(hBitBuf, &hBitBuf->pReadNext, -bOffset); 356 | } 357 | 358 | INDIRECT(1); ADD(1); STORE(1); 359 | hBitBuf->cntBits -= offset; 360 | } 361 | 362 | COUNT_sub_end(); 363 | } 364 | -------------------------------------------------------------------------------- /libfr/FloatFR.h: -------------------------------------------------------------------------------- 1 | /* 2 | Floating Point Reference Library 3 | */ 4 | 5 | #ifndef __FLOATFR_H 6 | #define __FLOATFR_H 7 | 8 | #include 9 | 10 | 11 | #define LOG_DUALIS_TABLE_SIZE 65 12 | 13 | #define INV_TABLE_BITS 8 14 | #define INV_TABLE_SIZE (1< (b) ? (a) : (b)) 22 | #endif 23 | 24 | 25 | void FloatFR_Init ( void ); 26 | float FloatFR_logDualis(int a); 27 | float FloatFR_getNumOctaves(int a, int b); 28 | #endif 29 | -------------------------------------------------------------------------------- /libfr/Makefile: -------------------------------------------------------------------------------- 1 | #################################################################### 2 | # 3 | # Makefile for fractional arithmetic library 4 | # $Id: Makefile,v 1.7.2.3 2004/12/22 09:04:53 ehr Exp $ 5 | # 6 | #################################################################### 7 | ################## user section: insert objlist here ####### 8 | LIB=libfr.a 9 | 10 | SRCS=$(wildcard *.c) 11 | 12 | OBJS = $(SRCS:.c=.o) 13 | 14 | $(LIB): $(OBJS) 15 | ar r $(LIB) $(OBJS) 16 | 17 | all: $(LIB) 18 | 19 | clean: 20 | rm -f $(OBJS) $(LIB) 21 | -------------------------------------------------------------------------------- /libfr/cfftn.h: -------------------------------------------------------------------------------- 1 | /* 2 | CFFTN header file 3 | */ 4 | 5 | #ifndef __cfftn_h 6 | #define __cfftn_h 7 | 8 | #include "../config.h" 9 | 10 | #ifdef _FFTW3 11 | 12 | void init_plans(); 13 | void destroy_plans(); 14 | 15 | #else 16 | 17 | #define init_plans() 18 | #define destroy_plans() 19 | 20 | int cfftn(float Re[], float Im[], int nTotal, int nPass, int nSpan, int iSign); 21 | 22 | #endif 23 | 24 | int CFFTN(float *afftData, int len, int isign); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libfr/counters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Provides dummy functions/macros to be able to compile the code. 3 | It is planned to provide a complexity measuring tool that allows 4 | to actually exploit the instrumentation lateron. 5 | */ 6 | 7 | #ifndef COUNT_H 8 | #define COUNT_H 9 | 10 | #include 11 | 12 | #define ADD(c) 13 | #define MULT(c) 14 | #define MAC(c) 15 | #define MOVE(c) 16 | #define STORE(c) 17 | #define LOGIC(c) 18 | #define SHIFT(c) 19 | #define BRANCH(c) 20 | #define DIV(c) 21 | #define SQRT(c) 22 | #define TRANS(c) 23 | #define FUNC(c) 24 | #define LOOP(c) 25 | #define INDIRECT(c) 26 | #define PTR_INIT(c) 27 | #define MISC(c) 28 | 29 | /* external function prototypes */ 30 | #define COUNT_init() 31 | #define COUNT_end() 32 | #define COUNT_sub_start(name) 33 | #define COUNT_sub_end() 34 | #define COUNT_frame_update() 35 | #define COUNT_ops(op, count) 36 | #define COUNT_mem(op, count) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libfr/transcendent.c: -------------------------------------------------------------------------------- 1 | /* 2 | Implementation of math functions 3 | */ 4 | 5 | #include 6 | #include 7 | #include "FloatFR.h" 8 | 9 | #include "counters.h" /* the 3GPP instrumenting tool */ 10 | 11 | static float logDualisTable[LOG_DUALIS_TABLE_SIZE]; 12 | 13 | /* 14 | Creates lookup tables for some arithmetic functions 15 | */ 16 | void FloatFR_Init(void) 17 | { 18 | int i; 19 | 20 | COUNT_sub_start("FloatFR_Init"); 21 | 22 | MULT(1); STORE(1); 23 | logDualisTable[0] = -1.0f; /* actually, ld 0 is not defined */ 24 | 25 | PTR_INIT(1); /* logDualisTable[] */ 26 | LOOP(1); 27 | for (i=1; i=0 && a 2 | #include 3 | #include /* memmove() */ 4 | #include "FloatFR.h" 5 | #include "iir32resample.h" 6 | 7 | #include "counters.h" /* the 3GPP instrumenting tool */ 8 | 9 | #define IIR_UPSAMPLE_FAC 2 10 | 11 | 12 | #define IIR_32_ORDER 8 13 | 14 | static const float coeffNum[IIR_32_ORDER] = 15 | {2.129719423e-03f*IIR_UPSAMPLE_FAC, -9.219380130e-04f*IIR_UPSAMPLE_FAC, 3.859704087e-03f*IIR_UPSAMPLE_FAC, 1.218339222e-03f*IIR_UPSAMPLE_FAC, 16 | 1.218339222e-03f*IIR_UPSAMPLE_FAC, 3.859704087e-03f*IIR_UPSAMPLE_FAC, -9.219380130e-04f*IIR_UPSAMPLE_FAC, 2.129719423e-03f*IIR_UPSAMPLE_FAC}; 17 | static const float coeffDen[IIR_32_ORDER] = 18 | {-1.000000000e+00f, 4.917738074e+00f, -1.129019179e+01f, 1.541498076e+01f, 19 | -1.342576947e+01f, 7.432055685e+00f, -2.419025499e+00f, 3.576405931e-01f}; 20 | 21 | 22 | 23 | #define IIR_CHANNELS 2 24 | #define IIR_DOWNSAMPLE_FAC 3 25 | #define IIR_INTERNAL_BUFSIZE (IIR_UPSAMPLE_FAC*IIR_DOWNSAMPLE_FAC + IIR_32_ORDER) 26 | 27 | static float statesIIR[IIR_32_ORDER * IIR_CHANNELS]; 28 | 29 | 30 | int 31 | IIR32Resample( float *inbuf, 32 | float *outbuf, 33 | int inSamples, 34 | int outSamples, 35 | int stride) 36 | { 37 | int i, k, s, ch, r; 38 | double accu; 39 | float scratch[IIR_INTERNAL_BUFSIZE]; 40 | int nProcessRuns = outSamples >> 1; 41 | 42 | COUNT_sub_start("IIR32Resample"); 43 | 44 | SHIFT(1); /* counting previous operation */ 45 | 46 | assert( stride <= IIR_CHANNELS); 47 | 48 | LOOP(1); 49 | for (ch=0; ch 6 | #include 7 | #include 8 | #include "resampler.h" 9 | 10 | #include "counters.h" /* the 3GPP instrumenting tool */ 11 | 12 | #define MAX_COEFF 32 13 | //#define NEWIIR 14 | 15 | struct IIR_PARAM{ 16 | const float *coeffIIRa; 17 | const float *coeffIIRb; 18 | int noOffCoeffs; 19 | int transitionFactor; 20 | int delay; 21 | }; 22 | 23 | static const float set1_a[] = { 24 | 0.004959855f, 0.025814206f, 0.080964205f, 0.182462303f, 25 | 0.322109621f, 0.462709927f, 0.552160404f, 0.552160404f, 26 | 0.462709927f, 0.322109621f, 0.182462303f, 0.080964205f, 27 | 0.025814206f, 0.004959855f 28 | }; 29 | 30 | static const float set1_b[] = { 31 | 0.0f, -1.038537170f, 2.627279635f, -1.609574122f, 32 | 2.205922661f, -0.751928739f, 0.787128253f, -0.105573173f, 33 | 0.131638380f, 0.003884641f, 0.010544805f, 0.001232040f, 34 | 0.000320798f, 0.000023031f 35 | }; 36 | 37 | 38 | static struct IIR_PARAM const set1 = { 39 | set1_a, 40 | set1_b, 41 | 14, 42 | 218, 43 | 6 44 | }; 45 | 46 | 47 | 48 | /* 49 | Reset downsampler instance and clear delay lines 50 | 51 | returns status 52 | */ 53 | int 54 | InitIIR21_Resampler(IIR21_RESAMPLER *ReSampler) 55 | 56 | { 57 | COUNT_sub_start("InitDownsampler"); 58 | 59 | INDIRECT(1); MOVE(1); 60 | ReSampler->iirFilter.ptr = 0; 61 | 62 | INDIRECT(8); MOVE(4); 63 | ReSampler->iirFilter.coeffIIRa = set1.coeffIIRa; 64 | ReSampler->iirFilter.coeffIIRb = set1.coeffIIRb; 65 | ReSampler->iirFilter.noOffCoeffs = set1.noOffCoeffs; 66 | ReSampler->delay=set1.delay; 67 | 68 | assert(ReSampler->iirFilter.noOffCoeffs <= BUFFER_SIZE); 69 | 70 | INDIRECT(1); MOVE(1); 71 | ReSampler->ratio = 2; 72 | 73 | INDIRECT(1); STORE(1); 74 | ReSampler->pending = 1; 75 | 76 | COUNT_sub_end(); 77 | 78 | return 1; 79 | } 80 | 81 | 82 | 83 | /* 84 | NOTE: enabling NEWIIR would save us some wMOPS, but result in 1 LSB diffs, it is worth a CR 85 | */ 86 | 87 | #ifdef NEWIIR 88 | static float 89 | AdvanceMAFilter( IIR_FILTER *iirFilter 90 | ) 91 | { 92 | float y; 93 | int j; 94 | int ptr = iirFilter->ptr; 95 | int i = ptr + (BUFFER_SIZE-1); 96 | 97 | COUNT_sub_start("AdvanceMAFilter"); 98 | 99 | INDIRECT(1); /* MOVE(1); --> ptr isn't needed */ ADD(1); /* counting previous operations */ 100 | 101 | INDIRECT(2); MULT(1); 102 | y = (iirFilter->coeffIIRa[0] * iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]); 103 | 104 | PTR_INIT(3); /* iirFilter->noOffCoeffs 105 | iirFilter->coeffIIRa[] 106 | iirFilter->ring_buf_2[] 107 | */ 108 | LOOP(1); 109 | for (j=1; jnoOffCoeffs; j++) { 110 | i--; 111 | 112 | MAC(1); 113 | y += (iirFilter->coeffIIRa[j] * iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)]); 114 | } 115 | 116 | COUNT_sub_end(); 117 | 118 | return y; 119 | } 120 | 121 | 122 | static void 123 | AdvanceARFilter( IIR_FILTER *iirFilter, 124 | float input 125 | ) 126 | 127 | { 128 | int j; 129 | float y; 130 | int ptr = iirFilter->ptr; 131 | int i = ptr + (BUFFER_SIZE-1); 132 | 133 | COUNT_sub_start("AdvanceARFilter"); 134 | 135 | INDIRECT(1); MOVE(1); ADD(1); /* counting previous operations */ 136 | 137 | INDIRECT(2); MULT(1); ADD(1); 138 | y = input + (iirFilter->coeffIIRb[1] * (-iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)])); 139 | 140 | PTR_INIT(4); /* iirFilter->noOffCoeffs 141 | iirFilter->coeffIIRb[] 142 | iirFilter->ring_buf_2[i] 143 | iirFilter->ring_buf_2[ptr] 144 | */ 145 | 146 | LOOP(1); 147 | for (j=2; jnoOffCoeffs; j++) { 148 | i--; 149 | 150 | MULT(1); MAC(1); 151 | y += (iirFilter->coeffIIRb[j] * (-iirFilter->ring_buf_2[i & (BUFFER_SIZE-1)])); 152 | } 153 | 154 | MOVE(1); 155 | iirFilter->ring_buf_2[ptr] = y; 156 | 157 | /* pointer update */ 158 | iirFilter->ptr = (ptr+1) & (BUFFER_SIZE-1); 159 | 160 | COUNT_sub_end(); 161 | 162 | } 163 | #else //NEWIIR 164 | 165 | 166 | 167 | /* 168 | faster simple folding operation 169 | 170 | returns filtered value 171 | */ 172 | 173 | 174 | static float 175 | AdvanceIIRFilter(IIR_FILTER *iirFilter, 176 | float input 177 | ) 178 | 179 | { 180 | float y = 0.0f; 181 | int j = 0; 182 | int i; 183 | 184 | COUNT_sub_start("AdvanceIIRFilter"); 185 | 186 | MOVE(2); /* counting previous operations */ 187 | 188 | INDIRECT(1); MOVE(1); 189 | iirFilter->ring_buf_1[iirFilter->ptr] = input; 190 | 191 | PTR_INIT(4); /* pointer for iirFilter->ring_buf_1, 192 | iirFilter->ring_buf_2, 193 | iirFilter->coeffIIRa, 194 | iirFilter->coeffIIRb 195 | */ 196 | ADD(1); LOOP(1); 197 | for (i = iirFilter->ptr; i > iirFilter->ptr - iirFilter->noOffCoeffs; i--, j++) { 198 | MULT(2); ADD(1); 199 | y += iirFilter->coeffIIRa[j] * iirFilter->ring_buf_1[i & (BUFFER_SIZE - 1)] - iirFilter->coeffIIRb[j] * iirFilter->ring_buf_2[i & (BUFFER_SIZE - 1)]; 200 | } 201 | 202 | MOVE(1); 203 | iirFilter->ring_buf_2[(iirFilter->ptr) & (BUFFER_SIZE - 1)] = y; 204 | 205 | iirFilter->ptr = ++iirFilter->ptr & (BUFFER_SIZE - 1); 206 | 207 | COUNT_sub_end(); 208 | 209 | return y; 210 | } 211 | #endif //NEWIIR 212 | 213 | 214 | 215 | 216 | 217 | 218 | /* 219 | Downsample numInSamples of type short 220 | 221 | returns success of operation 222 | */ 223 | 224 | int 225 | IIR21_Downsample(IIR21_RESAMPLER *DownSampler, 226 | float *inSamples, 227 | int numInSamples, 228 | int inStride, 229 | float *outSamples, 230 | int *numOutSamples, 231 | int outStride 232 | ) 233 | { 234 | int i; 235 | *numOutSamples=0; 236 | 237 | COUNT_sub_start("Downsample"); 238 | 239 | MOVE(1); /* counting previous operations */ 240 | 241 | PTR_INIT(2); /* pointer for inSamples[], 242 | outSamples[] 243 | */ 244 | LOOP(1); 245 | for(i=0;iiirFilter), inSamples[i*inStride]); 251 | #else 252 | FUNC(2); 253 | iirOut = AdvanceIIRFilter(&(DownSampler->iirFilter), inSamples[i*inStride]); 254 | #endif 255 | 256 | ADD(1); 257 | DownSampler->pending++; 258 | 259 | ADD(1); BRANCH(1); 260 | if(DownSampler->pending == DownSampler->ratio){ 261 | 262 | #ifdef NEWIIR 263 | FUNC(1); 264 | outSamples[(*numOutSamples)*outStride] = AdvanceMAFilter(&(DownSampler->iirFilter));; 265 | #else 266 | MOVE(1); 267 | outSamples[(*numOutSamples)*outStride] = iirOut; 268 | #endif 269 | 270 | (*numOutSamples)++; 271 | 272 | MOVE(1); 273 | DownSampler->pending=0; 274 | } 275 | } 276 | 277 | COUNT_sub_end(); 278 | 279 | return 1; 280 | } 281 | 282 | 283 | int 284 | IIR21_Upsample(IIR21_RESAMPLER *UpSampler, 285 | float *inSamples, 286 | int numInSamples, 287 | int inStride, 288 | float *outSamples, 289 | int *numOutSamples, 290 | int outStride 291 | ) 292 | { 293 | int i,k; 294 | int idxOut=0; 295 | 296 | COUNT_sub_start("Upsample"); 297 | 298 | MOVE(1); /* counting previous operations */ 299 | 300 | PTR_INIT(2); /* pointer for inSamples[], 301 | outSamples[] 302 | */ 303 | LOOP(1); 304 | for(i=0;iiirFilter), inSamples[i*inStride] * UpSampler->ratio); 308 | 309 | idxOut += outStride; 310 | 311 | LOOP(1); 312 | for (k=0; kratio-1; k++) { 313 | 314 | FUNC(2); STORE(1); 315 | outSamples[idxOut] = AdvanceIIRFilter(&(UpSampler->iirFilter), 0.0f); 316 | 317 | idxOut += outStride; 318 | } 319 | } 320 | 321 | MULT(1); STORE(1); 322 | *numOutSamples=numInSamples*UpSampler->ratio; 323 | 324 | COUNT_sub_end(); 325 | 326 | return 1; 327 | } 328 | -------------------------------------------------------------------------------- /libresamp/resampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Resampler Tool Box 3 | */ 4 | 5 | #ifndef __RESAMPLER_H 6 | #define __RESAMPLER_H 7 | 8 | #define BUFFER_SIZE 32 9 | 10 | 11 | typedef struct 12 | { 13 | const float *coeffIIRa; 14 | const float *coeffIIRb; 15 | int noOffCoeffs; 16 | float ring_buf_1[BUFFER_SIZE]; 17 | float ring_buf_2[BUFFER_SIZE]; 18 | int ptr; 19 | } IIR_FILTER; 20 | 21 | 22 | typedef struct 23 | { 24 | IIR_FILTER iirFilter; 25 | int ratio; 26 | int delay; 27 | int pending; 28 | } IIR21_RESAMPLER; 29 | 30 | 31 | 32 | int 33 | InitIIR21_Resampler(IIR21_RESAMPLER *ReSampler); 34 | 35 | int 36 | IIR21_Downsample(IIR21_RESAMPLER *DownSampler, 37 | float *inSamples, 38 | int numInSamples, 39 | int inStride, 40 | float *outSamples, 41 | int *numOutSamples, 42 | int outstride); 43 | 44 | int 45 | IIR21_Upsample( IIR21_RESAMPLER *UpSampler, 46 | float *inSamples, 47 | int numInSamples, 48 | int inStride, 49 | float *outSamples, 50 | int *numOutSamples, 51 | int outstride); 52 | #endif 53 | 54 | 55 | -------------------------------------------------------------------------------- /libsbrenc/Makefile: -------------------------------------------------------------------------------- 1 | #################################################################### 2 | # 3 | # Makefile for SBR encoder - library 4 | # 5 | #################################################################### 6 | ################## user section: insert objlist here ####### 7 | LIB=libsbrenc.a 8 | 9 | SRCS=$(wildcard *.c) 10 | 11 | OBJS = $(SRCS:.c=.o) 12 | 13 | $(LIB): $(OBJS) 14 | ar r $@ $(OBJS) 15 | 16 | all: $(LIB) 17 | 18 | clean: 19 | rm -f $(OBJS) $(LIB) 20 | -------------------------------------------------------------------------------- /libsbrenc/bit_sbr.h: -------------------------------------------------------------------------------- 1 | /* 2 | SBR bit writing 3 | */ 4 | #ifndef __BIT_SBR_H 5 | #define __BIT_SBR_H 6 | 7 | 8 | struct SBR_HEADER_DATA; 9 | struct SBR_BITSTREAM_DATA; 10 | struct SBR_ENV_DATA; 11 | struct COMMON_DATA; 12 | struct PS_ENC; 13 | 14 | 15 | int WriteEnvSingleChannelElement(struct SBR_HEADER_DATA *sbrHeaderData, 16 | struct SBR_BITSTREAM_DATA *sbrBitstreamData, 17 | struct SBR_ENV_DATA *sbrEnvData, 18 | struct PS_ENC *h_ps_e, 19 | struct COMMON_DATA *cmonData); 20 | 21 | 22 | int WriteEnvChannelPairElement(struct SBR_HEADER_DATA *sbrHeaderData, 23 | struct SBR_BITSTREAM_DATA *sbrBitstreamData, 24 | struct SBR_ENV_DATA *sbrEnvDataLeft, 25 | struct SBR_ENV_DATA *sbrEnvDataRight, 26 | struct COMMON_DATA *cmonData); 27 | 28 | 29 | 30 | int CountSbrChannelPairElement (struct SBR_HEADER_DATA *sbrHeaderData, 31 | struct SBR_BITSTREAM_DATA *sbrBitstreamData, 32 | struct SBR_ENV_DATA *sbrEnvDataLeft, 33 | struct SBR_ENV_DATA *sbrEnvDataRight, 34 | struct COMMON_DATA *cmonData); 35 | 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libsbrenc/cmondata.h: -------------------------------------------------------------------------------- 1 | /* 2 | Core Coder's and SBR's shared data structure definition 3 | */ 4 | #ifndef __SBR_CMONDATA_H 5 | #define __SBR_CMONDATA_H 6 | 7 | #include "FFR_bitbuffer.h" 8 | 9 | 10 | struct COMMON_DATA { 11 | int sbrHdrBits; 12 | int sbrCrcLen; 13 | int sbrDataBits; 14 | int sbrFillBits; 15 | struct BIT_BUF sbrBitbuf; 16 | struct BIT_BUF tmpWriteBitbuf; 17 | int sbrNumChannels; 18 | struct BIT_BUF sbrBitbufPrev; 19 | 20 | }; 21 | 22 | typedef struct COMMON_DATA *HANDLE_COMMON_DATA; 23 | 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libsbrenc/code_env.h: -------------------------------------------------------------------------------- 1 | /* 2 | DPCM Envelope coding 3 | */ 4 | 5 | #ifndef __CODE_ENV_H 6 | #define __CODE_ENV_H 7 | 8 | #include "sbr_main.h" 9 | #include "sbr_def.h" 10 | #include "fram_gen.h" 11 | 12 | typedef struct 13 | { 14 | int offset; 15 | int upDate; 16 | int nSfb[2]; 17 | int sfb_nrg_prev[MAX_FREQ_COEFFS]; 18 | int deltaTAcrossFrames; 19 | float dF_edge_1stEnv; 20 | float dF_edge_incr; 21 | int dF_edge_incr_fac; 22 | 23 | int codeBookScfLavTime; 24 | int codeBookScfLavFreq; 25 | 26 | int codeBookScfLavLevelTime; 27 | int codeBookScfLavLevelFreq; 28 | int codeBookScfLavBalanceTime; 29 | int codeBookScfLavBalanceFreq; 30 | 31 | int start_bits; 32 | int start_bits_balance; 33 | 34 | 35 | const unsigned char *hufftableTimeL; 36 | const unsigned char *hufftableFreqL; 37 | 38 | const unsigned char *hufftableLevelTimeL; 39 | const unsigned char *hufftableBalanceTimeL; 40 | const unsigned char *hufftableLevelFreqL; 41 | const unsigned char *hufftableBalanceFreqL; 42 | } 43 | SBR_CODE_ENVELOPE; 44 | typedef SBR_CODE_ENVELOPE *HANDLE_SBR_CODE_ENVELOPE; 45 | 46 | 47 | 48 | void 49 | codeEnvelope (int *sfb_nrg, 50 | const FREQ_RES *freq_res, 51 | SBR_CODE_ENVELOPE * h_sbrCodeEnvelope, 52 | int *directionVec, int coupling, int nEnvelopes, int channel, 53 | int headerActive); 54 | 55 | int 56 | CreateSbrCodeEnvelope (HANDLE_SBR_CODE_ENVELOPE h_sbrCodeEnvelope, 57 | int *nSfb, 58 | int deltaTAcrossFrames, 59 | float dF_edge_1stEnv, 60 | float dF_edge_incr); 61 | 62 | void deleteSbrCodeEnvelope (HANDLE_SBR_CODE_ENVELOPE h_sbrCodeEnvelope); 63 | 64 | struct SBR_ENV_DATA; 65 | 66 | int 67 | InitSbrHuffmanTables (struct SBR_ENV_DATA* sbrEnvData, 68 | HANDLE_SBR_CODE_ENVELOPE henv, 69 | HANDLE_SBR_CODE_ENVELOPE hnoise, 70 | AMP_RES amp_res); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libsbrenc/env_bit.c: -------------------------------------------------------------------------------- 1 | /* 2 | Remaining SBR Bit Writing Routines 3 | */ 4 | 5 | #include 6 | #include 7 | #include "env_bit.h" 8 | #include "cmondata.h" 9 | 10 | #include "counters.h" /* the 3GPP instrumenting tool */ 11 | 12 | #ifndef min 13 | #define min(a,b) ( a < b ? a:b) 14 | #endif 15 | 16 | #ifndef max 17 | #define max(a,b) ( a > b ? a:b) 18 | #endif 19 | 20 | /* ***************************** crcAdvance **********************************/ 21 | /** 22 | * @brief updates crc data register 23 | * 24 | */ 25 | static void crcAdvance(unsigned short crcPoly, 26 | unsigned short crcMask, 27 | unsigned short *crc, 28 | unsigned long bValue, 29 | int bBits 30 | ) 31 | { 32 | int i; 33 | 34 | COUNT_sub_start("crcAdvance"); 35 | 36 | ADD(1); LOOP(1); 37 | for (i=bBits-1; i>=0; i--) 38 | { 39 | unsigned short flag = (*crc) & crcMask ? 1:0; 40 | 41 | LOGIC(1); BRANCH(1); MOVE(1); /* counting previous operation */ 42 | 43 | SHIFT(1); LOGIC(1); BRANCH(1); /* .. ? */ LOGIC(1); 44 | flag ^= (bValue & (1<sbrBitbuf,memoryBase,memorySize); 77 | 78 | INDIRECT(2); MOVE(1); 79 | hCmonData->tmpWriteBitbuf = hCmonData->sbrBitbuf; 80 | 81 | INDIRECT(1); PTR_INIT(1); FUNC(3); 82 | WriteBits (&hCmonData->sbrBitbuf, 0, SI_FILL_EXTENTION_BITS); 83 | 84 | BRANCH(1); 85 | if(CRCActive) 86 | { 87 | INDIRECT(1); PTR_INIT(1); FUNC(3); 88 | WriteBits (&hCmonData->sbrBitbuf, 0,SI_SBR_CRC_BITS); 89 | } 90 | 91 | 92 | 93 | COUNT_sub_end(); 94 | } 95 | 96 | 97 | /* ************************** AssembleSbrBitstream *******************************/ 98 | /** 99 | * @brief Formats the SBR payload 100 | * @return nothing 101 | * 102 | */ 103 | 104 | void 105 | AssembleSbrBitstream( HANDLE_COMMON_DATA hCmonData) 106 | { 107 | 108 | unsigned short crcReg = SBR_CRCINIT; 109 | int numCrcBits,i; 110 | int sbrLoad=0; 111 | 112 | COUNT_sub_start("AssembleSbrBitstream"); 113 | 114 | MOVE(2); /* counting previous operations */ 115 | 116 | BRANCH(1); 117 | if ( hCmonData==NULL ) 118 | { 119 | COUNT_sub_end(); 120 | return; 121 | } 122 | 123 | 124 | INDIRECT(2); ADD(1); 125 | sbrLoad = hCmonData->sbrHdrBits + hCmonData->sbrDataBits; 126 | 127 | ADD(1); 128 | sbrLoad += SI_FILL_EXTENTION_BITS; 129 | 130 | INDIRECT(1); BRANCH(1); 131 | if ( hCmonData->sbrCrcLen ) 132 | { 133 | ADD(1); 134 | sbrLoad += SI_SBR_CRC_BITS; 135 | } 136 | 137 | INDIRECT(1); ADD(1); LOGIC(2); STORE(1); 138 | hCmonData->sbrFillBits = (8 - (sbrLoad) % 8) % 8; 139 | 140 | ADD(1); 141 | sbrLoad += hCmonData->sbrFillBits; 142 | 143 | INDIRECT(2); FUNC(3); 144 | WriteBits(&hCmonData->sbrBitbuf, 0, hCmonData->sbrFillBits ); 145 | 146 | 147 | INDIRECT(1); BRANCH(1); 148 | if ( hCmonData->sbrCrcLen ){ 149 | struct BIT_BUF tmpCRCBuf = hCmonData->sbrBitbuf; 150 | 151 | MOVE(1); /* counting previous operation */ 152 | 153 | PTR_INIT(1); FUNC(2); 154 | ReadBits (&tmpCRCBuf, SI_FILL_EXTENTION_BITS); 155 | 156 | PTR_INIT(1); FUNC(2); 157 | ReadBits (&tmpCRCBuf, SI_SBR_CRC_BITS); 158 | 159 | 160 | INDIRECT(2); ADD(2); 161 | numCrcBits = hCmonData->sbrHdrBits + hCmonData->sbrDataBits + hCmonData->sbrFillBits; 162 | 163 | LOOP(1); 164 | for(i=0;isbrCrcLen ) { 181 | 182 | INDIRECT(1); PTR_INIT(1); FUNC(3); 183 | WriteBits (&hCmonData->tmpWriteBitbuf, AAC_SI_FIL_SBR_CRC, SI_FILL_EXTENTION_BITS); 184 | 185 | FUNC(3); 186 | WriteBits (&hCmonData->tmpWriteBitbuf, crcReg,SI_SBR_CRC_BITS); 187 | 188 | } 189 | else { 190 | 191 | INDIRECT(1); PTR_INIT(1); FUNC(3); 192 | WriteBits (&hCmonData->tmpWriteBitbuf, AAC_SI_FIL_SBR, SI_FILL_EXTENTION_BITS); 193 | } 194 | 195 | 196 | 197 | 198 | COUNT_sub_end(); 199 | } 200 | 201 | -------------------------------------------------------------------------------- /libsbrenc/env_bit.h: -------------------------------------------------------------------------------- 1 | /* 2 | Remaining SBR Bit Writing Routines 3 | */ 4 | 5 | #ifndef BIT_ENV_H 6 | #define BIT_ENV_H 7 | 8 | #include "FFR_bitbuffer.h" 9 | 10 | #define SBR_CRC_POLY (0x0233) 11 | #define SBR_CRC_MASK (0x0200) 12 | #define SBR_CRC_RANGE (0x03FF) 13 | #define SBR_CRC_MAXREGS 1 14 | #define SBR_CRCINIT (0x0) 15 | 16 | #define AAC_SI_FIL_SBR 13 17 | #define AAC_SI_FIL_SBR_CRC 14 18 | 19 | 20 | #define SI_SBR_CRC_ENABLE_BITS 0 21 | #define SI_SBR_CRC_BITS 10 22 | 23 | 24 | 25 | 26 | 27 | #define SI_ID_BITS_AAC 3 28 | #define SI_FILL_COUNT_BITS 4 29 | #define SI_FILL_ESC_COUNT_BITS 8 30 | #define SI_FILL_EXTENTION_BITS 4 31 | #define ID_FIL 6 32 | 33 | 34 | 35 | 36 | 37 | 38 | struct COMMON_DATA; 39 | 40 | void InitSbrBitstream(struct COMMON_DATA *hCmonData, 41 | unsigned char *memoryBase, 42 | int memorySize, 43 | int CRCActive); 44 | 45 | void 46 | AssembleSbrBitstream(struct COMMON_DATA *hCmonData); 47 | 48 | 49 | 50 | 51 | 52 | #endif /* #ifndef BIT_ENV_H */ 53 | -------------------------------------------------------------------------------- /libsbrenc/env_est.h: -------------------------------------------------------------------------------- 1 | /* 2 | Envelope estimation structs and prototypes 3 | */ 4 | #ifndef __ENV_EST_H 5 | #define __ENV_EST_H 6 | 7 | #include "sbr_def.h" 8 | #include "aacenc.h" 9 | #include "qmf_enc.h" 10 | 11 | typedef struct 12 | { 13 | int pre_transient_info[2]; 14 | float *rBuffer[QMF_TIME_SLOTS]; 15 | float *iBuffer[QMF_TIME_SLOTS]; 16 | float *YBuffer[QMF_TIME_SLOTS*2]; 17 | 18 | char envelopeCompensation[MAX_FREQ_COEFFS]; 19 | 20 | int YBufferWriteOffset; 21 | 22 | int no_cols; 23 | int no_rows; 24 | int start_index; 25 | 26 | int time_slots; 27 | int time_step; 28 | } 29 | SBR_EXTRACT_ENVELOPE; 30 | typedef SBR_EXTRACT_ENVELOPE *HANDLE_SBR_EXTRACT_ENVELOPE; 31 | 32 | 33 | /************ Function Declarations ***************/ 34 | 35 | int 36 | CreateExtractSbrEnvelope (int chan, 37 | HANDLE_SBR_EXTRACT_ENVELOPE hSbr, 38 | 39 | 40 | int start_index 41 | 42 | 43 | ); 44 | 45 | void deleteExtractSbrEnvelope (HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut); 46 | 47 | 48 | 49 | struct SBR_CONFIG_DATA; 50 | struct SBR_HEADER_DATA; 51 | struct SBR_BITSTREAM_DATA; 52 | struct ENV_CHANNEL; 53 | struct COMMON_DATA; 54 | struct PS_ENC; 55 | 56 | 57 | void 58 | extractSbrEnvelope(float *timeInPtr, 59 | float *pCoreBuffer, 60 | unsigned int timeInStride, 61 | struct SBR_CONFIG_DATA *h_con, 62 | struct SBR_HEADER_DATA *sbrHeaderData, 63 | struct SBR_BITSTREAM_DATA *sbrBitstreamData, 64 | struct ENV_CHANNEL *h_envChan[MAX_CHANNELS], 65 | struct PS_ENC *hPsEnc, 66 | HANDLE_SBR_QMF_FILTER_BANK hSynthesisQmfBank, 67 | struct COMMON_DATA *cmonData); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libsbrenc/fram_gen.h: -------------------------------------------------------------------------------- 1 | /* 2 | Framing generator prototypes and structs 3 | */ 4 | #ifndef _FRAM_GEN_H 5 | #define _FRAM_GEN_H 6 | 7 | #include "sbr_def.h" 8 | #include "sbr_main.h" 9 | 10 | #define MAX_ENVELOPES_VARVAR MAX_ENVELOPES 11 | #define MAX_ENVELOPES_FIXVAR_VARFIX 4 12 | #define MAX_NUM_REL 3 13 | 14 | /* SBR frame class definitions */ 15 | typedef enum { 16 | FIXFIX = 0, 17 | FIXVAR, 18 | VARFIX, 19 | VARVAR 20 | }FRAME_CLASS; 21 | 22 | 23 | #define DC 4711 24 | #define EMPTY (-99) 25 | 26 | 27 | 28 | typedef struct 29 | { 30 | 31 | 32 | FRAME_CLASS frameClass; 33 | int bs_num_env; 34 | int bs_abs_bord; 35 | int n; 36 | int p; 37 | int bs_rel_bord[MAX_NUM_REL]; 38 | FREQ_RES v_f[MAX_ENVELOPES_FIXVAR_VARFIX]; 39 | 40 | int bs_abs_bord_0; 41 | int bs_abs_bord_1; 42 | int bs_num_rel_0; 43 | int bs_num_rel_1; 44 | int bs_rel_bord_0[MAX_NUM_REL]; 45 | int bs_rel_bord_1[MAX_NUM_REL]; 46 | FREQ_RES v_fLR[MAX_ENVELOPES_VARVAR]; 47 | 48 | } 49 | SBR_GRID; 50 | typedef SBR_GRID *HANDLE_SBR_GRID; 51 | 52 | 53 | /*! 54 | \struct SBR_FRAME_INFO 55 | */ 56 | typedef struct 57 | { 58 | int nEnvelopes; 59 | int borders[MAX_ENVELOPES+1]; 60 | FREQ_RES freqRes[MAX_ENVELOPES]; 61 | int shortEnv; 62 | int nNoiseEnvelopes; 63 | int bordersNoise[MAX_NOISE_ENVELOPES+1]; 64 | } 65 | SBR_FRAME_INFO; 66 | 67 | typedef SBR_FRAME_INFO *HANDLE_SBR_FRAME_INFO; 68 | 69 | /*! 70 | \struct SBR_ENVELOPE_FRAME 71 | */ 72 | typedef struct 73 | { 74 | int staticFraming; 75 | int numEnvStatic; 76 | FREQ_RES freq_res_fixfix; 77 | 78 | int *v_tuningSegm; 79 | int *v_tuningFreq; 80 | int dmin; 81 | int dmax; 82 | int allowSpread; 83 | 84 | FRAME_CLASS frameClassOld; 85 | int spreadFlag; 86 | 87 | int v_bord[2 * MAX_ENVELOPES_VARVAR + 1]; 88 | int length_v_bord; 89 | FREQ_RES v_freq[2 * MAX_ENVELOPES_VARVAR + 1]; 90 | int length_v_freq; 91 | 92 | int v_bordFollow[MAX_ENVELOPES_VARVAR]; 93 | int length_v_bordFollow; 94 | int i_tranFollow; 95 | int i_fillFollow; 96 | FREQ_RES v_freqFollow[MAX_ENVELOPES_VARVAR]; 97 | int length_v_freqFollow; 98 | 99 | SBR_GRID SbrGrid; 100 | SBR_FRAME_INFO SbrFrameInfo; 101 | } 102 | SBR_ENVELOPE_FRAME; 103 | typedef SBR_ENVELOPE_FRAME *HANDLE_SBR_ENVELOPE_FRAME; 104 | 105 | 106 | 107 | void 108 | CreateFrameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame, 109 | int allowSpread, 110 | int numEnvStatic, 111 | int staticFraming, 112 | 113 | FREQ_RES freq_res_fixfix); 114 | 115 | void 116 | deleteFrameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame); 117 | 118 | HANDLE_SBR_FRAME_INFO 119 | frameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame, 120 | int *v_pre_transient_info, 121 | int *v_transient_info, 122 | int *v_tuning); 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /libsbrenc/freq_sca.h: -------------------------------------------------------------------------------- 1 | /* 2 | frequency scale prototypes 3 | */ 4 | #ifndef __FREQ_SCA2_H 5 | #define __FREQ_SCA2_H 6 | #include "sbr_def.h" 7 | 8 | #define MAX_OCTAVE 29 9 | #define MAX_SECOND_REGION 50 10 | 11 | 12 | int 13 | UpdateFreqScale(unsigned char *v_k_master, int *h_num_bands, 14 | const int k0, const int k2, 15 | const int freq_scale, 16 | const int alter_scale); 17 | 18 | int 19 | UpdateHiRes(unsigned char *h_hires, 20 | int *num_hires, 21 | unsigned char *v_k_master, 22 | int num_master , 23 | int *xover_band, 24 | SR_MODE drOrSr, 25 | int noQMFChannels); 26 | 27 | void UpdateLoRes(unsigned char * v_lores, 28 | int *num_lores, 29 | unsigned char * v_hires, 30 | int num_hires); 31 | 32 | int 33 | FindStartAndStopBand(const int samplingFreq, 34 | const int noChannels, 35 | const int startFreq, 36 | const int stop_freq, 37 | const SR_MODE sampleRateMode, 38 | int *k0, 39 | int *k2); 40 | 41 | int getSbrStartFreqRAW (int startFreq, int QMFbands, int fs ); 42 | int getSbrStopFreqRAW (int stopFreq, int QMFbands, int fs); 43 | #endif 44 | -------------------------------------------------------------------------------- /libsbrenc/hybrid.h: -------------------------------------------------------------------------------- 1 | /* 2 | Hybrid Filter Bank header file 3 | */ 4 | 5 | #ifndef _HYBRID_H 6 | #define _HYBRID_H 7 | 8 | #define HYBRID_FILTER_LENGTH 13 9 | #define QMF_BUFFER_MOVE (HYBRID_FILTER_LENGTH - 1) 10 | #define HYBRID_FILTER_DELAY 6 11 | #define NO_QMF_BANDS_IN_HYBRID 3 12 | #define NO_HYBRID_BANDS 16 13 | 14 | typedef enum { 15 | 16 | HYBRID_2_REAL = 2, 17 | HYBRID_4_CPLX = 4, 18 | HYBRID_8_CPLX = 8 19 | 20 | } HYBRID_RES; 21 | 22 | typedef struct 23 | { 24 | float *pWorkReal; 25 | float *pWorkImag; 26 | 27 | float **mQmfBufferReal; 28 | float **mQmfBufferImag; 29 | } HYBRID; 30 | 31 | typedef HYBRID *HANDLE_HYBRID; 32 | 33 | void 34 | HybridAnalysis ( const float **mQmfReal, 35 | const float **mQmfImag, 36 | float **mHybridReal, 37 | float **mHybridImag, 38 | HANDLE_HYBRID hHybrid ); 39 | void 40 | HybridSynthesis ( const float **mHybridReal, 41 | const float **mHybridImag, 42 | float **mQmfReal, 43 | float **mQmfImag, 44 | HANDLE_HYBRID hHybrid ); 45 | 46 | int 47 | CreateHybridFilterBank ( HANDLE_HYBRID hHybrid, 48 | float **pPtr); 49 | 50 | void 51 | DeleteHybridFilterBank ( HANDLE_HYBRID *phHybrid ); 52 | 53 | 54 | 55 | #endif /* _HYBRID_H */ 56 | 57 | -------------------------------------------------------------------------------- /libsbrenc/invf_est.h: -------------------------------------------------------------------------------- 1 | /* 2 | Inverse Filtering detection prototypes 3 | */ 4 | #ifndef _INV_FILT_DET_H 5 | #define _INV_FILT_DET_H 6 | 7 | #include "sbr_main.h" 8 | #include "sbr_def.h" 9 | 10 | 11 | #define INVF_SMOOTHING_LENGTH 2 12 | 13 | typedef struct 14 | { 15 | float *quantStepsSbr; 16 | float *quantStepsOrig; 17 | float *nrgBorders; 18 | int numRegionsSbr; 19 | int numRegionsOrig; 20 | int numRegionsNrg; 21 | INVF_MODE regionSpace[5][5]; 22 | INVF_MODE regionSpaceTransient[5][5]; 23 | int EnergyCompFactor[5]; 24 | 25 | }DETECTOR_PARAMETERS; 26 | 27 | 28 | 29 | typedef struct 30 | { 31 | float origQuotaMean[INVF_SMOOTHING_LENGTH+1]; 32 | float sbrQuotaMean[INVF_SMOOTHING_LENGTH+1]; 33 | float origQuotaMeanFilt; 34 | float sbrQuotaMeanFilt; 35 | float avgNrg; 36 | 37 | }DETECTOR_VALUES; 38 | 39 | 40 | 41 | typedef struct 42 | { 43 | 44 | int prevRegionSbr[MAX_NUM_NOISE_VALUES]; 45 | int prevRegionOrig[MAX_NUM_NOISE_VALUES]; 46 | 47 | float nrgAvg; 48 | 49 | int freqBandTableInvFilt[MAX_NUM_NOISE_VALUES]; 50 | int noDetectorBands; 51 | int noDetectorBandsMax; 52 | 53 | DETECTOR_PARAMETERS *detectorParams; 54 | INVF_MODE prevInvfMode[MAX_NUM_NOISE_VALUES]; 55 | DETECTOR_VALUES detectorValues[MAX_NUM_NOISE_VALUES]; 56 | 57 | 58 | float wmQmf[MAX_NUM_NOISE_VALUES]; 59 | } 60 | SBR_INV_FILT_EST; 61 | 62 | typedef SBR_INV_FILT_EST *HANDLE_SBR_INV_FILT_EST; 63 | 64 | 65 | void 66 | qmfInverseFilteringDetector (HANDLE_SBR_INV_FILT_EST hInvFilt, 67 | float ** quotaMatrix, 68 | float *nrgVector, 69 | char * indexVector, 70 | int startIndex, 71 | int stopIndex, 72 | int transientFlag, 73 | INVF_MODE* infVec); 74 | 75 | 76 | 77 | int 78 | createInvFiltDetector (HANDLE_SBR_INV_FILT_EST hInvFilt, 79 | int* freqBandTableDetector, 80 | int numDetectorBands, 81 | int numberOfEstimatesPerFrame, 82 | unsigned int useSpeechConfig); 83 | 84 | void 85 | deleteInvFiltDetector (HANDLE_SBR_INV_FILT_EST hInvFilt); 86 | 87 | 88 | int 89 | resetInvFiltDetector(HANDLE_SBR_INV_FILT_EST hInvFilt, 90 | int* freqBandTableDetector, 91 | int numDetectorBands); 92 | 93 | 94 | 95 | #endif /* _QMF_INV_FILT_H */ 96 | 97 | -------------------------------------------------------------------------------- /libsbrenc/mh_det.h: -------------------------------------------------------------------------------- 1 | /* 2 | missing harmonics detection header file 3 | */ 4 | 5 | #ifndef __MH_DETECT_H 6 | #define __MH_DETECT_H 7 | 8 | 9 | #include "sbr_main.h" 10 | #include "fram_gen.h" 11 | 12 | 13 | 14 | typedef struct 15 | { 16 | float* guideVectorDiff; 17 | float* guideVectorOrig; 18 | unsigned char* guideVectorDetected; 19 | }GUIDE_VECTORS; 20 | 21 | 22 | 23 | 24 | 25 | typedef struct 26 | { 27 | int qmfNoChannels; 28 | int nSfb; 29 | int sampleFreq; 30 | int previousTransientFlag; 31 | int previousTransientFrame; 32 | int previousTransientPos; 33 | 34 | int noVecPerFrame; 35 | int transientPosOffset; 36 | 37 | int move; 38 | int totNoEst; 39 | int noEstPerFrame; 40 | int timeSlots; 41 | 42 | unsigned char* guideScfb; 43 | char *prevEnvelopeCompensation; 44 | unsigned char* detectionVectors[NO_OF_ESTIMATES]; 45 | float* tonalityDiff[NO_OF_ESTIMATES]; 46 | float* sfmOrig[NO_OF_ESTIMATES]; 47 | float* sfmSbr[NO_OF_ESTIMATES]; 48 | GUIDE_VECTORS guideVectors[NO_OF_ESTIMATES]; 49 | } 50 | SBR_MISSING_HARMONICS_DETECTOR; 51 | 52 | typedef SBR_MISSING_HARMONICS_DETECTOR *HANDLE_SBR_MISSING_HARMONICS_DETECTOR; 53 | 54 | 55 | 56 | void 57 | SbrMissingHarmonicsDetectorQmf(HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector, 58 | float ** pQuotaBuffer, 59 | char *indexVector, 60 | const SBR_FRAME_INFO *pFrameInfo, 61 | const int* pTranInfo, 62 | int* pAddHarmonicsFlag, 63 | unsigned char* pAddHarmonicsScaleFactorBands, 64 | const unsigned char* freqBandTable, 65 | int nSfb, 66 | char * envelopeCompensation); 67 | 68 | 69 | int 70 | CreateSbrMissingHarmonicsDetector(int chan, 71 | HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector, 72 | int sampleFreq, 73 | unsigned char* freqBandTable, 74 | int nSfb, 75 | int qmfNoChannels, 76 | int totNoEst, 77 | int move, 78 | int noEstPerFrame); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /libsbrenc/nf_est.h: -------------------------------------------------------------------------------- 1 | /* 2 | Noise floor estimation structs and prototypes 3 | */ 4 | 5 | #ifndef __NF_EST_H 6 | #define __NF_EST_H 7 | 8 | #include "sbr_main.h" 9 | #include "sbr_def.h" 10 | #include "fram_gen.h" 11 | 12 | 13 | #define NF_SMOOTHING_LENGTH 4 14 | 15 | 16 | typedef struct 17 | { 18 | float prevNoiseLevels[NF_SMOOTHING_LENGTH][MAX_NUM_NOISE_VALUES]; 19 | int freqBandTableQmf[MAX_NUM_NOISE_VALUES + 1]; 20 | float ana_max_level; 21 | float weightFac; 22 | int noNoiseBands; 23 | int noiseBands; 24 | float noiseFloorOffset[MAX_NUM_NOISE_VALUES]; 25 | const float* smoothFilter; 26 | INVF_MODE diffThres; 27 | } 28 | SBR_NOISE_FLOOR_ESTIMATE; 29 | 30 | typedef SBR_NOISE_FLOOR_ESTIMATE *HANDLE_SBR_NOISE_FLOOR_ESTIMATE; 31 | 32 | /*************/ 33 | /* Functions */ 34 | /*************/ 35 | 36 | void 37 | sbrNoiseFloorEstimateQmf (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, 38 | const SBR_FRAME_INFO *frame_info, 39 | float *noiseLevels, 40 | float** quotaMatrixOrig, 41 | char* indexVector, 42 | int missingHarmonicsFlag, 43 | int startIndex, 44 | int numberOfEstiamtesPerFrame, 45 | int totalNumberOfEstimates, 46 | int transientFlag, 47 | INVF_MODE* pInvFiltLevels 48 | ); 49 | 50 | 51 | int 52 | CreateSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, 53 | int ana_max_level, 54 | const unsigned char *freqBandTable, 55 | int nSfb, 56 | int noiseBands, 57 | int noiseFloorOffset, 58 | unsigned int useSpeechConfig 59 | ); 60 | 61 | 62 | 63 | int 64 | resetSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, 65 | const unsigned char *freqBandTable, 66 | int nSfb); 67 | 68 | 69 | 70 | 71 | void deleteSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /libsbrenc/ps_bitenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Parametric stereo bitstream encoder 3 | */ 4 | #ifndef __PS_BITENC_H 5 | #define __PS_BITENC_H 6 | 7 | #include "FFR_bitbuffer.h" 8 | #include "sbr_main.h" 9 | 10 | #define CODE_BOOK_LAV_IID 14 11 | #define CODE_BOOK_LAV_ICC 7 12 | #define NO_IID_STEPS ( 7 ) 13 | #define NO_ICC_STEPS ( 8 ) 14 | 15 | 16 | struct PS_ENC; 17 | 18 | int WritePsData (struct PS_ENC* h_ps_e, 19 | int bHeaderActive); 20 | 21 | int AppendPsBS (struct PS_ENC* h_ps_e, 22 | HANDLE_BIT_BUF hBitstream, 23 | HANDLE_BIT_BUF hBitstreamPrev, 24 | int *sbrHdrBits); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libsbrenc/ps_enc.h: -------------------------------------------------------------------------------- 1 | /* 2 | parametric stereo encoding 3 | */ 4 | #ifndef __PS_ENC_H 5 | #define __PS_ENC_H 6 | 7 | #include "ps_bitenc.h" 8 | #include "hybrid.h" 9 | 10 | /*############################################################################*/ 11 | /* Constant definitions */ 12 | /*############################################################################*/ 13 | 14 | #define NO_BINS ( 20 ) 15 | #define NO_LOW_RES_BINS ( NO_IID_BINS / 2 ) 16 | 17 | #define NO_IID_BINS ( NO_BINS ) 18 | #define NO_ICC_BINS ( NO_BINS ) 19 | #define NO_IPD_BINS ( 11 ) 20 | #define NO_IPD_BINS_EST ( NO_BINS ) 21 | 22 | #define NO_LOW_RES_IID_BINS ( NO_LOW_RES_BINS ) 23 | #define NO_LOW_RES_ICC_BINS ( NO_LOW_RES_BINS ) 24 | 25 | #define NO_IPD_GROUPS ( NO_IPD_BINS_EST + 6 + 2 ) 26 | #define NEGATE_IPD_MASK ( 0x00001000 ) 27 | 28 | #define ENERGY_WINDOW_SLOPES ( 2 ) 29 | 30 | #define NO_SUBSAMPLES ( 32 ) 31 | #define NO_QMF_BANDS ( 64 ) 32 | #define SYSTEMLOOKAHEAD ( 1 ) 33 | 34 | /*############################################################################*/ 35 | /* Type definitions */ 36 | /*############################################################################*/ 37 | 38 | struct PS_ENC{ 39 | 40 | int bEnableHeader; 41 | 42 | int bHiFreqResIidIcc; 43 | int iidIccBins; 44 | 45 | unsigned int bPrevZeroIid; 46 | unsigned int bPrevZeroIcc; 47 | 48 | int psMode; 49 | 50 | struct BIT_BUF psBitBuf; 51 | 52 | int hdrBitsPrevFrame; 53 | 54 | float **aaaIIDDataBuffer; 55 | float **aaaICCDataBuffer; 56 | 57 | int aLastIidIndex[NO_IID_BINS]; 58 | int aLastIccIndex[NO_ICC_BINS]; 59 | 60 | float *mHybridRealLeft[NO_SUBSAMPLES]; 61 | float *mHybridImagLeft[NO_SUBSAMPLES]; 62 | float *mHybridRealRight[NO_SUBSAMPLES]; 63 | float *mHybridImagRight[NO_SUBSAMPLES]; 64 | 65 | HYBRID hybridLeft; 66 | HYBRID hybridRight; 67 | HANDLE_HYBRID hHybridLeft; 68 | HANDLE_HYBRID hHybridRight; 69 | 70 | float powerLeft [NO_BINS]; 71 | float powerRight [NO_BINS]; 72 | float powerCorrReal[NO_BINS]; 73 | float powerCorrImag[NO_BINS]; 74 | 75 | float **tempQmfLeftReal; 76 | float **tempQmfLeftImag; 77 | float **histQmfLeftReal; 78 | float **histQmfLeftImag; 79 | float **histQmfRightReal; 80 | float **histQmfRightImag; 81 | }; 82 | 83 | typedef struct PS_ENC *HANDLE_PS_ENC; 84 | 85 | /*############################################################################*/ 86 | /* Extern function prototypes */ 87 | /*############################################################################*/ 88 | int GetPsMode(int bitRate); 89 | 90 | int 91 | CreatePsEnc(HANDLE_PS_ENC h_ps_enc, 92 | int psMode); 93 | 94 | void 95 | DeletePsEnc(HANDLE_PS_ENC *h_ps_e); 96 | 97 | 98 | void 99 | EncodePsFrame(HANDLE_PS_ENC h_ps_e, 100 | float **iBufferLeft, 101 | float **rBufferLeft, 102 | float **iBufferRight, 103 | float **rBufferRight); 104 | #endif 105 | -------------------------------------------------------------------------------- /libsbrenc/qmf_enc.h: -------------------------------------------------------------------------------- 1 | /* 2 | QMF analysis structs and prototypes 3 | */ 4 | #ifndef __QMF_ENC_H 5 | #define __QMF_ENC_H 6 | 7 | typedef struct 8 | { 9 | const float *p_filter; 10 | 11 | const float *cos_twiddle; 12 | const float *sin_twiddle; 13 | const float *alt_sin_twiddle; 14 | 15 | float *timeBuffer; 16 | float *workBuffer; 17 | 18 | float *qmf_states_buffer; 19 | } 20 | SBR_QMF_FILTER_BANK; 21 | 22 | typedef SBR_QMF_FILTER_BANK *HANDLE_SBR_QMF_FILTER_BANK; 23 | 24 | 25 | void sbrAnalysisFiltering (const float *timeIn, 26 | int timeInStride, 27 | float **rAnalysis, 28 | float **iAnalysis, 29 | HANDLE_SBR_QMF_FILTER_BANK qmfBank); 30 | 31 | 32 | int createQmfBank (int chan,HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); 33 | 34 | 35 | void deleteQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); 36 | 37 | 38 | void 39 | getEnergyFromCplxQmfData (float **energyValues, 40 | float **realValues, 41 | float **imagValues 42 | 43 | ); 44 | 45 | void 46 | SynthesisQmfFiltering (float **sbrReal, 47 | float **sbrImag, 48 | float *timeOut, 49 | HANDLE_SBR_QMF_FILTER_BANK qmfBank); 50 | 51 | 52 | int 53 | CreateSynthesisQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); 54 | 55 | 56 | 57 | 58 | void DeleteSynthesisQmfBank (HANDLE_SBR_QMF_FILTER_BANK *h_sbrQmf); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libsbrenc/sbr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Main SBR structs definitions 3 | */ 4 | 5 | #ifndef __SBR_H 6 | #define __SBR_H 7 | 8 | #include "qmf_enc.h" 9 | #include "tran_det.h" 10 | #include "fram_gen.h" 11 | #include "nf_est.h" 12 | #include "mh_det.h" 13 | #include "invf_est.h" 14 | #include "env_est.h" 15 | #include "code_env.h" 16 | #include "sbr_main.h" 17 | #include "ton_corr.h" 18 | 19 | struct SBR_BITSTREAM_DATA 20 | { 21 | int TotalBits; 22 | int PayloadBits; 23 | int FillBits; 24 | int HeaderActive; 25 | int CRCActive; 26 | int NrSendHeaderData; 27 | int CountSendHeaderData; 28 | 29 | }; 30 | 31 | typedef struct SBR_BITSTREAM_DATA *HANDLE_SBR_BITSTREAM_DATA; 32 | 33 | struct SBR_HEADER_DATA 34 | { 35 | 36 | int protocol_version; 37 | AMP_RES sbr_amp_res; 38 | int sbr_start_frequency; 39 | int sbr_stop_frequency; 40 | int sbr_xover_band; 41 | int sbr_noise_bands; 42 | int sbr_data_extra; 43 | int header_extra_1; 44 | int header_extra_2; 45 | int sbr_limiter_bands; 46 | int sbr_limiter_gains; 47 | int sbr_interpol_freq; 48 | int sbr_smoothing_length; 49 | int alterScale; 50 | int freqScale; 51 | 52 | SR_MODE sampleRateMode; 53 | 54 | int coupling; 55 | int prev_coupling; 56 | 57 | }; 58 | 59 | typedef struct SBR_HEADER_DATA *HANDLE_SBR_HEADER_DATA; 60 | 61 | struct SBR_CONFIG_DATA 62 | { 63 | int nChannels; 64 | 65 | int nSfb[2]; 66 | int num_Master; 67 | int sampleFreq; 68 | 69 | int xOverFreq; 70 | 71 | unsigned char *freqBandTable[2]; 72 | unsigned char *v_k_master; 73 | 74 | 75 | SBR_STEREO_MODE stereoMode; 76 | 77 | int detectMissingHarmonics; 78 | int useParametricCoding; 79 | int xposCtrlSwitch; 80 | }; 81 | 82 | typedef struct SBR_CONFIG_DATA *HANDLE_SBR_CONFIG_DATA; 83 | 84 | struct SBR_ENV_DATA 85 | { 86 | 87 | int sbr_xpos_ctrl; 88 | FREQ_RES freq_res_fixfix; 89 | 90 | 91 | INVF_MODE sbr_invf_mode; 92 | INVF_MODE sbr_invf_mode_vec[MAX_NUM_NOISE_VALUES]; 93 | 94 | XPOS_MODE sbr_xpos_mode; 95 | 96 | int ienvelope[MAX_ENVELOPES][MAX_FREQ_COEFFS]; 97 | 98 | int codeBookScfLavBalance; 99 | int codeBookScfLav; 100 | const int *hufftableTimeC; 101 | const int *hufftableFreqC; 102 | const unsigned char *hufftableTimeL; 103 | const unsigned char *hufftableFreqL; 104 | 105 | const int *hufftableLevelTimeC; 106 | const int *hufftableBalanceTimeC; 107 | const int *hufftableLevelFreqC; 108 | const int *hufftableBalanceFreqC; 109 | const unsigned char *hufftableLevelTimeL; 110 | const unsigned char *hufftableBalanceTimeL; 111 | const unsigned char *hufftableLevelFreqL; 112 | const unsigned char *hufftableBalanceFreqL; 113 | 114 | 115 | const unsigned char *hufftableNoiseTimeL; 116 | const int *hufftableNoiseTimeC; 117 | const unsigned char *hufftableNoiseFreqL; 118 | const int *hufftableNoiseFreqC; 119 | 120 | const unsigned char *hufftableNoiseLevelTimeL; 121 | const int *hufftableNoiseLevelTimeC; 122 | const unsigned char *hufftableNoiseBalanceTimeL; 123 | const int *hufftableNoiseBalanceTimeC; 124 | const unsigned char *hufftableNoiseLevelFreqL; 125 | const int *hufftableNoiseLevelFreqC; 126 | const unsigned char *hufftableNoiseBalanceFreqL; 127 | const int *hufftableNoiseBalanceFreqC; 128 | 129 | HANDLE_SBR_GRID hSbrBSGrid; 130 | 131 | 132 | int syntheticCoding; 133 | int noHarmonics; 134 | int addHarmonicFlag; 135 | unsigned char addHarmonic[MAX_FREQ_COEFFS]; 136 | 137 | int si_sbr_start_env_bits_balance; 138 | int si_sbr_start_env_bits; 139 | int si_sbr_start_noise_bits_balance; 140 | int si_sbr_start_noise_bits; 141 | 142 | int noOfEnvelopes; 143 | int noScfBands[MAX_ENVELOPES]; 144 | int domain_vec[MAX_ENVELOPES]; 145 | int domain_vec_noise[MAX_ENVELOPES]; 146 | int sbr_noise_levels[MAX_NUM_NOISE_VALUES]; 147 | int noOfnoisebands; 148 | 149 | int balance; 150 | int init_sbr_amp_res; 151 | }; 152 | 153 | 154 | typedef struct SBR_ENV_DATA *HANDLE_SBR_ENV_DATA; 155 | 156 | struct ENV_CHANNEL 157 | { 158 | 159 | SBR_TRANSIENT_DETECTOR sbrTransientDetector; 160 | SBR_CODE_ENVELOPE sbrCodeEnvelope; 161 | SBR_CODE_ENVELOPE sbrCodeNoiseFloor; 162 | SBR_EXTRACT_ENVELOPE sbrExtractEnvelope; 163 | SBR_QMF_FILTER_BANK sbrQmf; 164 | SBR_ENVELOPE_FRAME SbrEnvFrame; 165 | SBR_TON_CORR_EST TonCorr; 166 | 167 | struct SBR_ENV_DATA encEnvData; 168 | }; 169 | 170 | typedef struct ENV_CHANNEL *HANDLE_ENV_CHANNEL; 171 | 172 | 173 | #endif /* __SBR_H */ 174 | -------------------------------------------------------------------------------- /libsbrenc/sbr_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | SBR main definitions 3 | */ 4 | #ifndef __SBR_DEF_H 5 | #define __SBR_DEF_H 6 | 7 | 8 | #define SWAP(a,b) tempr=a, a=b, b=tempr 9 | #define TRUE 1 10 | #define FALSE 0 11 | 12 | 13 | /* Constants */ 14 | #define PI 3.1415926535897932f 15 | #define EPS 1e-18 16 | #define LOG2 0.69314718056f 17 | #define ILOG2 1.442695041f 18 | #define RELAXATION 1e-6f 19 | 20 | /************ Definitions ***************/ 21 | #define SBR_COMP_MODE_DELTA 0 22 | #define SBR_COMP_MODE_CTS 1 23 | 24 | #define MAX_NUM_NOISE_VALUES 10 25 | #define MAX_NOISE_ENVELOPES 2 26 | #define MAX_NUM_NOISE_COEFFS 5 27 | #define MAX_ENVELOPES 5 28 | #define MAX_FREQ_COEFFS 27 29 | #define MAX_NUM_ENVELOPE_VALUES (MAX_FREQ_COEFFS*MAX_ENVELOPES) 30 | 31 | 32 | 33 | #define QMF_CHANNELS 64 34 | #define QMF_FILTER_LENGTH 640 35 | #define QMF_TIME_SLOTS 32 36 | #define NO_OF_ESTIMATES 4 37 | 38 | 39 | #define NOISE_FLOOR_OFFSET 6 40 | 41 | #define LOW_RES 0 42 | #define HIGH_RES 1 43 | 44 | #define LO 0 45 | #define HI 1 46 | 47 | #define LENGTH_SBR_FRAME_INFO 35 48 | 49 | #define SBR_NSFB_LOW_RES 9 50 | #define SBR_NSFB_HIGH_RES 18 51 | 52 | 53 | #define SI_SBR_PROTOCOL_VERSION_ID 0 54 | 55 | #define SBR_XPOS_CTRL_DEFAULT 2 56 | 57 | #define SBR_FREQ_SCALE_DEFAULT 2 58 | #define SBR_ALTER_SCALE_DEFAULT 1 59 | #define SBR_NOISE_BANDS_DEFAULT 2 60 | 61 | #define SBR_LIMITER_BANDS_DEFAULT 2 62 | #define SBR_LIMITER_GAINS_DEFAULT 2 63 | #define SBR_INTERPOL_FREQ_DEFAULT 1 64 | #define SBR_SMOOTHING_LENGTH_DEFAULT 0 65 | 66 | 67 | /* sbr_header */ 68 | #define SI_SBR_PROTOCOL_VERSION_BITS 2 69 | #define SI_SBR_AMP_RES_BITS 1 70 | #define SI_SBR_COUPLING_BITS 1 71 | #define SI_SBR_START_FREQ_BITS 4 72 | #define SI_SBR_STOP_FREQ_BITS 4 73 | #define SI_SBR_XOVER_BAND_BITS 3 74 | #define SI_SBR_RESERVED_BITS 2 75 | #define SI_SBR_DATA_EXTRA_BITS 1 76 | #define SI_SBR_HEADER_EXTRA_1_BITS 1 77 | #define SI_SBR_HEADER_EXTRA_2_BITS 1 78 | 79 | #define SI_SBR_LC_STEREO_MODE_BITS 2 80 | 81 | #define SI_SBR_FREQ_SCALE_BITS 2 82 | #define SI_SBR_ALTER_SCALE_BITS 1 83 | #define SI_SBR_NOISE_BANDS_BITS 2 84 | 85 | #define SI_SBR_LIMITER_BANDS_BITS 2 86 | #define SI_SBR_LIMITER_GAINS_BITS 2 87 | #define SI_SBR_INTERPOL_FREQ_BITS 1 88 | #define SI_SBR_SMOOTHING_LENGTH_BITS 1 89 | #define SI_SBR_RESERVED_HE2_BITS 1 90 | 91 | /* sbr_grid */ 92 | #define SBR_CLA_BITS 2 93 | #define SBR_ENV_BITS 2 94 | 95 | #define SBR_ABS_BITS 2 96 | 97 | #define SBR_NUM_BITS 2 98 | #define SBR_REL_BITS 2 99 | #define SBR_RES_BITS 1 100 | #define SBR_DIR_BITS 1 101 | 102 | 103 | /* sbr_data */ 104 | #define SI_SBR_SR_MODE_BITS 1 105 | #define SI_SBR_ENABLE_PSEUDOSTEREO_BITS 1 106 | 107 | #define SI_SBR_INVF_MODE_BITS 2 108 | #define SI_SBR_XPOS_MODE_BITS 2 109 | #define SI_SBR_XPOS_CTRL_BITS 3 110 | 111 | 112 | #define SI_SBR_START_ENV_BITS_AMP_RES_3_0 6 113 | #define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0 5 114 | #define SI_SBR_START_NOISE_BITS_AMP_RES_3_0 5 115 | #define SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0 5 116 | 117 | #define SI_SBR_START_ENV_BITS_AMP_RES_1_5 7 118 | #define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5 6 119 | 120 | 121 | #define SI_SBR_EXTENDED_DATA_BITS 1 122 | #define SI_SBR_EXTENSION_SIZE_BITS 4 123 | #define SI_SBR_EXTENSION_ESC_COUNT_BITS 8 124 | #define SI_SBR_EXTENSION_ID_BITS 2 125 | 126 | #define SBR_EXTENDED_DATA_MAX_CNT (15+255) 127 | 128 | #define EXTENSION_ID_PARAMETRIC_CODING 0 129 | #define EXTENSION_ID_PS_CODING 2 130 | 131 | /* Envelope coding constants */ 132 | #define FREQ 0 133 | #define TIME 1 134 | 135 | 136 | /* huffman tables */ 137 | #define CODE_BOOK_SCF_LAV00 60 138 | #define CODE_BOOK_SCF_LAV01 31 139 | #define CODE_BOOK_SCF_LAV10 60 140 | #define CODE_BOOK_SCF_LAV11 31 141 | #define CODE_BOOK_SCF_LAV_BALANCE11 12 142 | #define CODE_BOOK_SCF_LAV_BALANCE10 24 143 | 144 | typedef enum 145 | { 146 | SBR_AMP_RES_1_5=0, 147 | SBR_AMP_RES_3_0 148 | } 149 | AMP_RES; 150 | 151 | typedef enum 152 | { 153 | XPOS_MDCT, 154 | XPOS_MDCT_CROSS, 155 | XPOS_LC, 156 | XPOS_RESERVED, 157 | XPOS_SWITCHED 158 | } 159 | XPOS_MODE; 160 | 161 | typedef enum 162 | { 163 | INVF_OFF = 0, 164 | INVF_LOW_LEVEL, 165 | INVF_MID_LEVEL, 166 | INVF_HIGH_LEVEL, 167 | INVF_SWITCHED 168 | } 169 | INVF_MODE; 170 | 171 | typedef enum 172 | { 173 | SINGLE_RATE, 174 | DUAL_RATE 175 | } 176 | SR_MODE; 177 | 178 | typedef enum 179 | { 180 | FREQ_RES_LOW, 181 | FREQ_RES_HIGH 182 | } 183 | FREQ_RES; 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /libsbrenc/sbr_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | SBR encoder top level processing prototypes 3 | */ 4 | 5 | #ifndef __SBR_MAIN_H 6 | #define __SBR_MAIN_H 7 | 8 | #define MAX_TRANS_FAC 8 9 | #define MAX_CODEC_FRAME_RATIO 2 10 | #define MAX_PAYLOAD_SIZE 256 11 | 12 | typedef struct 13 | { 14 | int bitRate; 15 | int nChannels; 16 | int sampleFreq; 17 | int transFac; 18 | int standardBitrate; 19 | } CODEC_PARAM; 20 | 21 | typedef enum 22 | { 23 | SBR_MONO, 24 | SBR_LEFT_RIGHT, 25 | SBR_COUPLING, 26 | SBR_SWITCH_LRC 27 | } 28 | SBR_STEREO_MODE; 29 | 30 | typedef struct sbrConfiguration 31 | { 32 | CODEC_PARAM codecSettings; 33 | int SendHeaderDataTime; 34 | int crcSbr; 35 | int detectMissingHarmonics; 36 | int parametricCoding; 37 | 38 | 39 | int tran_thr; 40 | int noiseFloorOffset; 41 | unsigned int useSpeechConfig; 42 | 43 | 44 | int sbr_data_extra; 45 | int amp_res; 46 | int ana_max_level; 47 | int tran_fc; 48 | int tran_det_mode; 49 | int spread; 50 | int stat; 51 | int e; 52 | SBR_STEREO_MODE stereoMode; 53 | int deltaTAcrossFrames; 54 | float dF_edge_1stEnv; 55 | float dF_edge_incr; 56 | int sbr_invf_mode; 57 | int sbr_xpos_mode; 58 | int sbr_xpos_ctrl; 59 | int sbr_xpos_level; 60 | int startFreq; 61 | int stopFreq; 62 | 63 | int usePs; 64 | int psMode; 65 | 66 | int freqScale; 67 | int alterScale; 68 | int sbr_noise_bands; 69 | 70 | int sbr_limiter_bands; 71 | int sbr_limiter_gains; 72 | int sbr_interpol_freq; 73 | int sbr_smoothing_length; 74 | 75 | } sbrConfiguration, *sbrConfigurationPtr ; 76 | 77 | 78 | 79 | 80 | unsigned int 81 | IsSbrSettingAvail (unsigned int bitrate, 82 | unsigned int numOutputChannels, 83 | unsigned int sampleRateInput, 84 | unsigned int *sampleRateCore); 85 | 86 | unsigned int 87 | AdjustSbrSettings (const sbrConfigurationPtr config, 88 | unsigned int bitRate, 89 | unsigned int numChannels, 90 | unsigned int fsCore, 91 | unsigned int transFac, 92 | unsigned int standardBitrate); 93 | 94 | unsigned int 95 | InitializeSbrDefaults (sbrConfigurationPtr config 96 | 97 | ); 98 | 99 | 100 | typedef struct SBR_ENCODER *HANDLE_SBR_ENCODER; 101 | 102 | 103 | 104 | int 105 | EnvOpen (HANDLE_SBR_ENCODER* hEnvEncoder, 106 | float *pCoreBuffer, 107 | sbrConfigurationPtr params, 108 | int *coreBandWith 109 | ); 110 | 111 | void 112 | EnvClose (HANDLE_SBR_ENCODER hEnvEnc); 113 | 114 | int 115 | SbrGetXOverFreq(HANDLE_SBR_ENCODER hEnv, 116 | int xoverFreq ); 117 | 118 | int 119 | SbrGetStopFreqRaw(HANDLE_SBR_ENCODER hEnv); 120 | 121 | int 122 | EnvEncodeFrame (HANDLE_SBR_ENCODER hEnvEncoder, 123 | float *samples, 124 | float *pCoreBuffer, 125 | unsigned int timeInStride, 126 | unsigned int *numAncBytes, 127 | unsigned char *ancData); 128 | 129 | #endif /* ifndef __SBR_MAIN_H */ 130 | -------------------------------------------------------------------------------- /libsbrenc/sbr_misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sbr miscellaneous helper functions 3 | */ 4 | #include "sbr_misc.h" 5 | 6 | #include "counters.h" /* the 3GPP instrumenting tool */ 7 | 8 | 9 | /* Sorting routine */ 10 | void Shellsort_int (int *in, int n) 11 | { 12 | 13 | int i, j, v; 14 | int inc = 1; 15 | 16 | COUNT_sub_start("Shellsort_int"); 17 | 18 | MOVE(1); /* counting previous operation */ 19 | 20 | LOOP(1); 21 | do 22 | { 23 | MULT(1); ADD(1); 24 | inc = 3 * inc + 1; 25 | } 26 | while (inc <= n); 27 | 28 | LOOP(1); 29 | do { 30 | 31 | DIV(1); 32 | inc = inc / 3; 33 | 34 | PTR_INIT(1); /* pointers for in[] */ 35 | ADD(1); LOOP(1); 36 | for (i = inc + 1; i <= n; i++) { 37 | 38 | MOVE(2); 39 | v = in[i-1]; 40 | j = i; 41 | 42 | PTR_INIT(2); /* pointers for in[j-inc-1], 43 | in[j-1] 44 | */ 45 | LOOP(1); 46 | while (in[j-inc-1] > v) { 47 | 48 | MOVE(1); 49 | in[j-1] = in[j-inc-1]; 50 | 51 | ADD(1); 52 | j -= inc; 53 | 54 | ADD(1); BRANCH(1); 55 | if (j <= inc) 56 | break; 57 | } 58 | 59 | MOVE(1); 60 | in[j-1] = v; 61 | } 62 | } while (inc > 1); 63 | 64 | COUNT_sub_end(); 65 | } 66 | 67 | 68 | 69 | /******************************************************************************* 70 | Functionname: AddVecLeft 71 | ******************************************************************************* 72 | 73 | Arguments: int* dst, int* length_dst, int* src, int length_src 74 | Return: none 75 | *******************************************************************************/ 76 | void 77 | AddVecLeft (int *dst, int *length_dst, int *src, int length_src) 78 | { 79 | int i; 80 | 81 | COUNT_sub_start("AddVecLeft"); 82 | 83 | PTR_INIT(1); /* src[i] */ 84 | ADD(1); LOOP(1); 85 | for (i = length_src - 1; i >= 0; i--) 86 | { 87 | FUNC(3); 88 | AddLeft (dst, length_dst, src[i]); 89 | } 90 | 91 | COUNT_sub_end(); 92 | } 93 | 94 | 95 | /******************************************************************************* 96 | Functionname: AddLeft 97 | ******************************************************************************* 98 | 99 | Arguments: int* vector, int* length_vector, int value 100 | Return: none 101 | *******************************************************************************/ 102 | void 103 | AddLeft (int *vector, int *length_vector, int value) 104 | { 105 | int i; 106 | 107 | COUNT_sub_start("AddLeft"); 108 | 109 | PTR_INIT(1); /* vector[] */ 110 | LOOP(1); 111 | for (i = *length_vector; i > 0; i--) 112 | { 113 | MOVE(1); 114 | vector[i] = vector[i - 1]; 115 | } 116 | 117 | MOVE(1); 118 | vector[0] = value; 119 | 120 | ADD(1); 121 | (*length_vector)++; 122 | 123 | COUNT_sub_end(); 124 | } 125 | 126 | 127 | /******************************************************************************* 128 | Functionname: AddRight 129 | ******************************************************************************* 130 | 131 | Arguments: int* vector, int* length_vector, int value 132 | Return: none 133 | *******************************************************************************/ 134 | void 135 | AddRight (int *vector, int *length_vector, int value) 136 | { 137 | COUNT_sub_start("AddRight"); 138 | 139 | INDIRECT(1); MOVE(1); 140 | vector[*length_vector] = value; 141 | 142 | ADD(1); 143 | (*length_vector)++; 144 | 145 | COUNT_sub_end(); 146 | } 147 | 148 | 149 | 150 | /******************************************************************************* 151 | Functionname: AddVecRight 152 | ******************************************************************************* 153 | 154 | Arguments: int* dst, int* length_dst, int* src, int length_src) 155 | Return: none 156 | *******************************************************************************/ 157 | void 158 | AddVecRight (int *dst, int *length_dst, int *src, int length_src) 159 | { 160 | int i; 161 | 162 | COUNT_sub_start("AddVecRight"); 163 | 164 | PTR_INIT(1); /* src[] */ 165 | LOOP(1); 166 | for (i = 0; i < length_src; i++) 167 | { 168 | FUNC(3); 169 | AddRight (dst, length_dst, src[i]); 170 | } 171 | 172 | COUNT_sub_end(); 173 | } 174 | 175 | -------------------------------------------------------------------------------- /libsbrenc/sbr_misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sbr miscellaneous helper functions prototypes 3 | */ 4 | 5 | #ifndef _SBR_MISC_H 6 | #define _SBR_MISC_H 7 | 8 | /* Sorting routines */ 9 | void Shellsort_int (int *in, int n); 10 | 11 | void AddLeft (int *vector, int *length_vector, int value); 12 | void AddRight (int *vector, int *length_vector, int value); 13 | void AddVecLeft (int *dst, int *length_dst, int *src, int length_src); 14 | void AddVecRight (int *dst, int *length_vector_dst, int *src, int length_src); 15 | #endif 16 | -------------------------------------------------------------------------------- /libsbrenc/sbr_ram.c: -------------------------------------------------------------------------------- 1 | /* 2 | Memory layout 3 | This module declares all static and dynamic memory spaces 4 | */ 5 | #include 6 | #include 7 | #include "aacenc.h" 8 | #include "sbr_ram.h" 9 | #include "sbr_def.h" 10 | #include "sbr_main.h" 11 | #include "aac_ram.h" 12 | #include "hybrid.h" 13 | #include "FloatFR.h" 14 | 15 | #define PS_BUF4_SIZE (4*(QMF_TIME_SLOTS + QMF_BUFFER_MOVE) + 4*(NO_QMF_BANDS_IN_HYBRID + NO_QMF_BANDS_IN_HYBRID*QMF_BUFFER_MOVE)) 16 | #define PS_BUF5_SIZE (QMF_FILTER_LENGTH/2 + QMF_CHANNELS) 17 | 18 | /* Overlay with mdctDelayBuffer of 2nd channel since AAC only works in mono */ 19 | float *PsBuf2= &mdctDelayBuffer[BLOCK_SWITCHING_OFFSET]; 20 | 21 | /* Overlay PsBuf4 and PsBuf5 with sbr_toncorrBuff of 2nd channel, since SBR only works in mono */ 22 | float *PsBuf4 = &sbr_toncorrBuff[5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; 23 | float *PsBuf5 = &sbr_toncorrBuff[5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + PS_BUF4_SIZE]; 24 | 25 | float PsBuf3[MAX_CHANNELS*FRAME_LEN_LONG*sizeof(short)/sizeof(float)]; 26 | 27 | /*! 28 | \name StaticSbrData 29 | 30 | Static memory areas, must not be overwritten in other sections of the encoder 31 | */ 32 | 33 | /*! Filter states for QMF-analysis.
34 | Dimension: #MAXNRSBRCHANNELS * #SBR_QMF_FILTER_LENGTH */ 35 | float sbr_QmfStatesAnalysis[MAX_CHANNELS * QMF_FILTER_LENGTH]; 36 | 37 | /*! Energy buffer for envelope extraction
38 | Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_SLOTS*2 * #SBR_QMF_CHANNELS 39 | */ 40 | 41 | float sbr_envYBuffer[MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; 42 | 43 | /*! Matrix holding the quota values for all estimates, all channels 44 | Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_CHANNELS* #NO_OF_ESTIMATES 45 | */ 46 | 47 | float sbr_quotaMatrix[MAX_CHANNELS * NO_OF_ESTIMATES*QMF_CHANNELS]; 48 | 49 | 50 | /*! Thresholds for transient detection
51 | Dimension #MAXNRSBRCHANNELS * #SBR_QMF_CHANNELS 52 | */ 53 | float sbr_thresholds[MAX_CHANNELS *QMF_CHANNELS]; 54 | 55 | 56 | 57 | 58 | 59 | /*! Frequency band table (low res)
60 | Dimension #MAX_FREQ_COEFFS/2+1 61 | */ 62 | 63 | unsigned char sbr_freqBandTableLO[MAX_FREQ_COEFFS/2+1]; 64 | 65 | /*! Frequency band table (high res)
66 | Dimension #MAX_FREQ_COEFFS +1 67 | */ 68 | 69 | unsigned char sbr_freqBandTableHI[MAX_FREQ_COEFFS+1]; 70 | 71 | /*! vk matser table
72 | Dimension #MAX_FREQ_COEFFS +1 73 | */ 74 | 75 | 76 | unsigned char sbr_v_k_master[MAX_FREQ_COEFFS +1]; 77 | 78 | 79 | 80 | /* 81 | Missing harmonics detection 82 | */ 83 | 84 | /*! sbr_detectionVectors
85 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 86 | */ 87 | unsigned char sbr_detectionVectors[MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; 88 | 89 | /*! 90 | The following tonality correclation buffers are allocated in 91 | one non-reusable buffer 92 | sbr_tonalityDiff
93 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 94 | sbr_sfmOrig
95 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 96 | sbr_sfmSbr
97 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 98 | sbr_guideVectorDiff
99 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 100 | sbr_guideVectorOrig
101 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 102 | */ 103 | 104 | /* To overlay 2nd half of sbr_toncorrBuff with PS-Buffers, the 2nd half 105 | must not fall below a minium size */ 106 | float sbr_toncorrBuff[max( /* two channels or... */ 107 | (MAX_CHANNELS*5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS), 108 | ( 109 | /* 1st half */ 110 | (5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS)+ 111 | PS_BUF4_SIZE + PS_BUF5_SIZE 112 | ) 113 | )]; 114 | 115 | /*! sbr_prevCompVec[
116 | Dimension #MAX_CHANNELS*#MAX_FREQ_COEFFS] 117 | */ 118 | char sbr_prevEnvelopeCompensation[MAX_CHANNELS*MAX_FREQ_COEFFS]; 119 | /*! sbr_guideScfb[
120 | Dimension #MAX_CHANNELS*#MAX_FREQ_COEFFS] 121 | */ 122 | unsigned char sbr_guideScfb[MAX_CHANNELS*MAX_FREQ_COEFFS]; 123 | /*! sbr_guideVectorDiff
124 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 125 | */ 126 | /*! sbr_guideVectorDetected
127 | Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] 128 | */ 129 | unsigned char sbr_guideVectorDetected[MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; 130 | 131 | 132 | 133 | /*! 134 | \name DynamicSbrData 135 | 136 | Dynamic memory areas, might be reused in other algorithm sections, 137 | e.g. the core decoder 138 | */ 139 | 140 | 141 | /*! Real buffer for envelope extraction
142 | Dimension #SBR_QMF_SLOTS * #SBR_QMF_CHANNELS 143 | */ 144 | 145 | 146 | float sbr_envRBuffer [MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; 147 | 148 | /*! Imag buffer for envelope extraction
149 | Dimension #SBR_QMF_SLOTS * #SBR_QMF_CHANNELS 150 | */ 151 | 152 | float sbr_envIBuffer [MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; 153 | 154 | 155 | /*! Transients for transient detection
156 | Dimension MAX_CHANNELS*3* #QMF_TIME_SLOTS 157 | */ 158 | float sbr_transients[MAX_CHANNELS*3*QMF_TIME_SLOTS]; 159 | 160 | -------------------------------------------------------------------------------- /libsbrenc/sbr_ram.h: -------------------------------------------------------------------------------- 1 | /* 2 | Memory layout 3 | */ 4 | #ifndef __SBR_RAM_H 5 | #define __SBR_RAM_H 6 | 7 | 8 | extern float *PsBuf2; 9 | extern float PsBuf3[]; 10 | extern float *PsBuf4; 11 | extern float *PsBuf5; 12 | 13 | extern float sbr_envYBuffer[]; 14 | extern float sbr_QmfStatesAnalysis[]; 15 | extern float sbr_envRBuffer[]; 16 | extern float sbr_envIBuffer[]; 17 | extern float sbr_quotaMatrix[]; 18 | extern float sbr_thresholds[]; 19 | extern float sbr_transients[]; 20 | extern unsigned char sbr_freqBandTableLO[]; 21 | extern unsigned char sbr_freqBandTableHI[]; 22 | extern unsigned char sbr_v_k_master[]; 23 | 24 | extern unsigned char sbr_detectionVectors[]; 25 | extern char sbr_prevEnvelopeCompensation[]; 26 | extern unsigned char sbr_guideScfb[]; 27 | extern unsigned char sbr_guideVectorDetected[]; 28 | extern float sbr_toncorrBuff[]; 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /libsbrenc/sbr_rom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Declaration of constant tables 3 | */ 4 | #ifndef __SBR_ROM_H 5 | #define __SBR_ROM_H 6 | 7 | extern const int aHybridResolution[]; 8 | extern const int hiResBandBorders[]; 9 | extern const int groupBordersMix[]; 10 | extern const int bins2groupMap[]; 11 | extern const float panClass[]; 12 | extern const float saClass[]; 13 | extern const float p4_13[]; 14 | extern const float p8_13[]; 15 | extern const float sbr_cos_twiddle[]; 16 | extern const float sbr_sin_twiddle[]; 17 | extern const float sbr_alt_sin_twiddle[]; 18 | extern const float p_64_640_qmf[]; 19 | extern const int aBookPsIidTimeCode[]; 20 | extern const char aBookPsIidTimeLength[]; 21 | extern const int aBookPsIidFreqCode[]; 22 | extern const char aBookPsIidFreqLength[]; 23 | extern const short aBookPsIccTimeCode[]; 24 | extern const char aBookPsIccTimeLength[]; 25 | extern const short aBookPsIccFreqCode[]; 26 | extern const char aBookPsIccFreqLength[]; 27 | 28 | extern const float trigData_fct4_32[]; 29 | extern const float trigData_fct4_16[]; 30 | extern const float trigData_fct4_8[]; 31 | 32 | extern const float sbr_qmf_64_640[325]; 33 | 34 | extern const int v_Huff_envelopeLevelC10T[121]; 35 | extern const unsigned char v_Huff_envelopeLevelL10T[121]; 36 | extern const int v_Huff_envelopeLevelC10F[121]; 37 | extern const unsigned char v_Huff_envelopeLevelL10F[121]; 38 | extern const int bookSbrEnvBalanceC10T[49]; 39 | extern const unsigned char bookSbrEnvBalanceL10T[49]; 40 | extern const int bookSbrEnvBalanceC10F[49]; 41 | extern const unsigned char bookSbrEnvBalanceL10F[49]; 42 | extern const int v_Huff_envelopeLevelC11T[63]; 43 | extern const unsigned char v_Huff_envelopeLevelL11T[63]; 44 | extern const int v_Huff_envelopeLevelC11F[63]; 45 | extern const unsigned char v_Huff_envelopeLevelL11F[63]; 46 | extern const int bookSbrEnvBalanceC11T[25]; 47 | extern const unsigned char bookSbrEnvBalanceL11T[25]; 48 | extern const int bookSbrEnvBalanceC11F[25]; 49 | extern const unsigned char bookSbrEnvBalanceL11F[25]; 50 | extern const int v_Huff_NoiseLevelC11T[63]; 51 | extern const unsigned char v_Huff_NoiseLevelL11T[63]; 52 | extern const int bookSbrNoiseBalanceC11T[25]; 53 | extern const unsigned char bookSbrNoiseBalanceL11T[25]; 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /libsbrenc/ton_corr.h: -------------------------------------------------------------------------------- 1 | /* 2 | General tonality correction detector module. 3 | */ 4 | #ifndef _TON_CORR_EST_H 5 | #define _TON_CORR_EST_H 6 | 7 | #include "sbr.h" 8 | #include "sbr_main.h" 9 | #include "sbr_def.h" 10 | #include "mh_det.h" 11 | #include "invf_est.h" 12 | #include "nf_est.h" 13 | 14 | 15 | #define MAX_NUM_PATCHES 6 16 | 17 | /** parameter set for one single patch */ 18 | typedef struct { 19 | int sourceStartBand; 20 | int sourceStopBand; 21 | int guardStartBand; 22 | 23 | int targetStartBand; 24 | int targetBandOffs; 25 | int numBandsInPatch; 26 | } PATCH_PARAM; 27 | 28 | 29 | 30 | 31 | typedef struct 32 | { 33 | int switchInverseFilt; 34 | int noQmfChannels; 35 | int numberOfEstimates; 36 | int numberOfEstimatesPerFrame; 37 | int move; 38 | int frameStartIndex; 39 | int startIndexMatrix; 40 | int frameStartIndexInvfEst; 41 | 42 | int prevTransientFlag; 43 | int transientNextFrame; 44 | int transientPosOffset; 45 | 46 | float *quotaMatrix[NO_OF_ESTIMATES]; 47 | float nrgVector[NO_OF_ESTIMATES]; 48 | char indexVector[QMF_CHANNELS]; 49 | 50 | PATCH_PARAM patchParam[MAX_NUM_PATCHES]; 51 | int guard; 52 | int shiftStartSb; 53 | int noOfPatches; 54 | 55 | SBR_MISSING_HARMONICS_DETECTOR sbrMissingHarmonicsDetector; 56 | SBR_NOISE_FLOOR_ESTIMATE sbrNoiseFloorEstimate; 57 | SBR_INV_FILT_EST sbrInvFilt; 58 | } 59 | SBR_TON_CORR_EST; 60 | 61 | typedef SBR_TON_CORR_EST *HANDLE_SBR_TON_CORR_EST; 62 | 63 | 64 | /* Functions */ 65 | 66 | void 67 | TonCorrParamExtr(HANDLE_SBR_TON_CORR_EST hTonCorr, 68 | INVF_MODE* infVec, 69 | float* noiseLevels, 70 | int* missingHarmonicFlag, 71 | unsigned char* missingHarmonicsIndex, 72 | char* envelopeCompensation, 73 | const SBR_FRAME_INFO *frameInfo, 74 | int* transientInfo, 75 | unsigned char * freqBandTable, 76 | int nSfb, 77 | XPOS_MODE xposType 78 | ); 79 | 80 | 81 | 82 | int 83 | CreateTonCorrParamExtr (int chan, 84 | HANDLE_SBR_TON_CORR_EST hTonCorr, 85 | int fs, 86 | int usb, 87 | int noQmfChannels, 88 | int xposCtrl, 89 | int highBandStartSb, 90 | int channelOffset, 91 | unsigned char *v_k_master, 92 | int numMaster, 93 | int ana_max_level, 94 | unsigned char *freqBandTable[2], 95 | int* nSfb, 96 | int noiseBands, 97 | int noiseFloorOffset, 98 | unsigned int useSpeechConfig 99 | ); 100 | 101 | 102 | void 103 | DeleteTonCorrParamExtr(HANDLE_SBR_TON_CORR_EST hTonCorr); /*!< Handle to SBR_TON_CORR struct. */ 104 | 105 | 106 | void 107 | CalculateTonalityQuotas(HANDLE_SBR_TON_CORR_EST hTonCorr, 108 | float **sourceBufferReal, 109 | float **sourceBufferImag, 110 | int usb); 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /libsbrenc/tran_det.h: -------------------------------------------------------------------------------- 1 | /* 2 | Transient detector prototypes 3 | */ 4 | #ifndef __TRAN_DET_H 5 | #define __TRAN_DET_H 6 | 7 | typedef struct 8 | { 9 | float *transients; 10 | float *thresholds; 11 | 12 | float tran_thr; 13 | float split_thr; 14 | int tran_fc; 15 | int buffer_length; 16 | int no_cols; 17 | int no_rows; 18 | int mode; 19 | 20 | float prevLowBandEnergy; 21 | float totalHighBandEnergy; 22 | } 23 | SBR_TRANSIENT_DETECTOR; 24 | 25 | 26 | typedef SBR_TRANSIENT_DETECTOR *HANDLE_SBR_TRANSIENT_DETECTOR; 27 | 28 | /*************/ 29 | /* Functions */ 30 | /*************/ 31 | 32 | void transientDetect (float **Energies, 33 | HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, 34 | int *tran_vector, 35 | int timeStep 36 | ); 37 | 38 | int 39 | CreateSbrTransientDetector (int chan, 40 | HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, 41 | 42 | int sampleFreq, 43 | int totalBitrate, 44 | int codecBitrate, 45 | int tran_thr, 46 | int mode, 47 | int tran_fc 48 | 49 | 50 | ); 51 | 52 | void deleteSbrTransientDetector (HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector); 53 | 54 | void 55 | frameSplitter(float **Energies, 56 | HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, 57 | unsigned char * freqBandTable, 58 | int nSfb, 59 | int timeStep, 60 | int no_cols, 61 | int *tran_vector); 62 | 63 | #endif 64 | --------------------------------------------------------------------------------