├── AUTHORS ├── testdata └── test.wav ├── go.mod ├── aacenc ├── external │ └── aacenc │ │ ├── README │ │ ├── src │ │ ├── spreading.h │ │ ├── config.h │ │ ├── stat_bits.h │ │ ├── memalign.h │ │ ├── transform.h │ │ ├── channel_map.h │ │ ├── quantize.h │ │ ├── pre_echo_control.h │ │ ├── bitenc.h │ │ ├── grp_data.h │ │ ├── band_nrg.h │ │ ├── tns_param.h │ │ ├── sf_estim.h │ │ ├── ms_stereo.h │ │ ├── typedef.h │ │ ├── spreading.c │ │ ├── adj_thr.h │ │ ├── adj_thr_data.h │ │ ├── qc_main.h │ │ ├── cmnMemory.c │ │ ├── psy_const.h │ │ ├── oper_32b.h │ │ ├── psy_data.h │ │ ├── line_pe.h │ │ ├── dyn_bits.h │ │ ├── psy_main.h │ │ ├── tns_func.h │ │ ├── block_switch.h │ │ ├── memalign.c │ │ ├── bit_cnt.h │ │ ├── tns.h │ │ ├── bitbuffer.h │ │ ├── cmnMemory.h │ │ ├── psy_configuration.h │ │ ├── channel_map.c │ │ ├── band_nrg.c │ │ ├── pre_echo_control.c │ │ ├── interface.h │ │ ├── aac_rom.h │ │ ├── interface.c │ │ ├── qc_data.h │ │ ├── aacenc_core.h │ │ ├── bitbuffer.c │ │ ├── ms_stereo.c │ │ ├── line_pe.c │ │ ├── grp_data.c │ │ ├── typedefs.h │ │ ├── stat_bits.c │ │ └── aacenc_core.c │ │ └── include │ │ ├── voMem.h │ │ ├── voAAC.h │ │ ├── voIndex.h │ │ ├── voType.h │ │ └── voAudio.h ├── aacenc_cgo.go └── aacenc.go ├── examples ├── go.mod ├── basic │ └── basic.go ├── go.sum └── micgrab │ └── micgrab.go ├── .github └── workflows │ └── build.yml ├── encode_test.go ├── README.md ├── go.sum ├── encode.go └── COPYING /AUTHORS: -------------------------------------------------------------------------------- 1 | Milan Nikolic 2 | -------------------------------------------------------------------------------- /testdata/test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gen2brain/aac-go/HEAD/testdata/test.wav -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gen2brain/aac-go 2 | 3 | go 1.19 4 | 5 | require github.com/youpy/go-wav v0.3.2 6 | 7 | require ( 8 | github.com/youpy/go-riff v0.1.0 // indirect 9 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/README: -------------------------------------------------------------------------------- 1 | VisualOn AAC encoder library 2 | 3 | This library contains an encoder implementation of the Advanced Audio 4 | Coding (AAC) audio codec. The library is based on a codec implementation 5 | by VisualOn as part of the Stagefright framework from the Google 6 | Android project. 7 | 8 | -------------------------------------------------------------------------------- /examples/go.mod: -------------------------------------------------------------------------------- 1 | module examples 2 | 3 | go 1.19 4 | 5 | replace github.com/gen2brain/aac-go => ../ 6 | 7 | require ( 8 | github.com/gen2brain/aac-go v0.0.0-00010101000000-000000000000 9 | github.com/gen2brain/malgo v0.11.10 10 | github.com/youpy/go-wav v0.3.2 11 | ) 12 | 13 | require ( 14 | github.com/youpy/go-riff v0.1.0 // indirect 15 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | name: Build 3 | jobs: 4 | test: 5 | strategy: 6 | matrix: 7 | go-version: [1.19.x] 8 | os: [ubuntu-latest, macos-latest, windows-latest] 9 | runs-on: ${{ matrix.os }} 10 | steps: 11 | - name: Install Go 12 | uses: actions/setup-go@v2 13 | with: 14 | go-version: ${{ matrix.go-version }} 15 | - name: Checkout code 16 | uses: actions/checkout@v2 17 | - name: Build 18 | run: go build ./... 19 | -------------------------------------------------------------------------------- /examples/basic/basic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | 7 | "github.com/gen2brain/aac-go" 8 | "github.com/youpy/go-wav" 9 | ) 10 | 11 | func main() { 12 | file, err := os.Open("test.wav") 13 | if err != nil { 14 | panic(err) 15 | } 16 | 17 | wreader := wav.NewReader(file) 18 | f, err := wreader.Format() 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | buf := bytes.NewBuffer(make([]byte, 0)) 24 | 25 | opts := &aac.Options{} 26 | opts.SampleRate = int(f.SampleRate) 27 | opts.NumChannels = int(f.NumChannels) 28 | 29 | enc, err := aac.NewEncoder(buf, opts) 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | err = enc.Encode(wreader) 35 | if err != nil { 36 | panic(err) 37 | } 38 | 39 | err = enc.Close() 40 | if err != nil { 41 | panic(err) 42 | } 43 | 44 | err = os.WriteFile("test.aac", buf.Bytes(), 0644) 45 | if err != nil { 46 | panic(err) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /encode_test.go: -------------------------------------------------------------------------------- 1 | package aac_test 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "path/filepath" 7 | "testing" 8 | 9 | "github.com/gen2brain/aac-go" 10 | "github.com/youpy/go-wav" 11 | ) 12 | 13 | func TestEncode(t *testing.T) { 14 | file, err := os.Open(filepath.Join("testdata", "test.wav")) 15 | if err != nil { 16 | t.Fatal(err) 17 | } 18 | 19 | wr := wav.NewReader(file) 20 | f, err := wr.Format() 21 | if err != nil { 22 | t.Fatal(err) 23 | } 24 | 25 | buf := bytes.NewBuffer(make([]byte, 0)) 26 | 27 | opts := &aac.Options{} 28 | opts.SampleRate = int(f.SampleRate) 29 | opts.NumChannels = int(f.NumChannels) 30 | 31 | enc, err := aac.NewEncoder(buf, opts) 32 | if err != nil { 33 | t.Fatal(err) 34 | } 35 | 36 | err = enc.Encode(wr) 37 | if err != nil { 38 | t.Error(err) 39 | } 40 | 41 | err = enc.Close() 42 | if err != nil { 43 | t.Error(err) 44 | } 45 | 46 | err = os.WriteFile(filepath.Join(os.TempDir(), "test.aac"), buf.Bytes(), 0640) 47 | if err != nil { 48 | t.Error(err) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/spreading.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: spreading.h 18 | 19 | Content: Spreading of energy functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _SPREADING_H 24 | #define _SPREADING_H 25 | #include "typedefs.h" 26 | 27 | 28 | void SpreadingMax(const Word16 pbCnt, 29 | const Word16 *maskLowFactor, 30 | const Word16 *maskHighFactor, 31 | Word32 *pbSpreadedEnergy); 32 | 33 | #endif /* #ifndef _SPREADING_H */ 34 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: config.h 18 | 19 | Content: aac encoder parameter 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _AACENC_CONFIG_H_ 24 | #define _AACENC_CONFIG_H_ 25 | 26 | #define MAX_CHANNELS 2 27 | 28 | #define AACENC_BLOCKSIZE 1024 /*! encoder only takes BLOCKSIZE samples at a time */ 29 | #define AACENC_TRANS_FAC 8 /*! encoder short long ratio */ 30 | 31 | 32 | #define MAXBITS_COEF 6144 33 | #define MINBITS_COEF 744 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/stat_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: stat_bits.h 18 | 19 | Content: Static bit counter functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __STAT_BITS_H 24 | #define __STAT_BITS_H 25 | 26 | #include "psy_const.h" 27 | #include "interface.h" 28 | 29 | Word16 countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 30 | PSY_OUT_ELEMENT *psyOutElement, 31 | Word16 nChannels, 32 | Word16 adtsUsed); 33 | 34 | #endif /* __STAT_BITS_H */ 35 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/memalign.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: memalign.h 18 | 19 | Content: Memory alloc alignments functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __VO_AACENC_MEM_ALIGN_H__ 24 | #define __VO_AACENC_MEM_ALIGN_H__ 25 | 26 | #include "voMem.h" 27 | #include "typedef.h" 28 | 29 | extern void *mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID); 30 | extern void mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID); 31 | 32 | #endif /* __VO_MEM_ALIGN_H__ */ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: transform.h 18 | 19 | Content: MDCT Transform functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __TRANSFORM_H__ 24 | #define __TRANSFORM_H__ 25 | 26 | #include "typedef.h" 27 | 28 | void Transform_Real(Word16 *mdctDelayBuffer, 29 | Word16 *timeSignal, 30 | Word16 chIncrement, /*! channel increment */ 31 | Word32 *realOut, 32 | Word16 *mdctScale, 33 | Word16 windowSequence 34 | ); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/channel_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: channel_map.h 18 | 19 | Content: channel mapping functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _CHANNEL_MAP_H 24 | #define _CHANNEL_MAP_H 25 | 26 | #include "psy_const.h" 27 | #include "qc_data.h" 28 | 29 | Word16 InitElementInfo (Word16 nChannels, ELEMENT_INFO* elInfo); 30 | 31 | Word16 InitElementBits(ELEMENT_BITS *elementBits, 32 | ELEMENT_INFO elInfo, 33 | Word32 bitrateTot, 34 | Word16 averageBitsTot, 35 | Word16 staticBitsTot); 36 | 37 | #endif /* CHANNEL_MAP_H */ 38 | -------------------------------------------------------------------------------- /aacenc/aacenc_cgo.go: -------------------------------------------------------------------------------- 1 | package aacenc 2 | 3 | /* 4 | #include "external/aacenc/src/cmnMemory.c" 5 | #include "external/aacenc/src/basicop2.c" 6 | #include "external/aacenc/src/oper_32b.c" 7 | #include "external/aacenc/src/aac_rom.c" 8 | #include "external/aacenc/src/aacenc.c" 9 | #include "external/aacenc/src/aacenc_core.c" 10 | #include "external/aacenc/src/adj_thr.c" 11 | #include "external/aacenc/src/band_nrg.c" 12 | #include "external/aacenc/src/bit_cnt.c" 13 | #include "external/aacenc/src/bitbuffer.c" 14 | #include "external/aacenc/src/bitenc.c" 15 | #include "external/aacenc/src/block_switch.c" 16 | #include "external/aacenc/src/channel_map.c" 17 | #include "external/aacenc/src/dyn_bits.c" 18 | #include "external/aacenc/src/grp_data.c" 19 | #include "external/aacenc/src/interface.c" 20 | #include "external/aacenc/src/line_pe.c" 21 | #include "external/aacenc/src/memalign.c" 22 | #include "external/aacenc/src/ms_stereo.c" 23 | #include "external/aacenc/src/pre_echo_control.c" 24 | #include "external/aacenc/src/psy_configuration.c" 25 | #include "external/aacenc/src/psy_main.c" 26 | #include "external/aacenc/src/qc_main.c" 27 | #include "external/aacenc/src/quantize.c" 28 | #include "external/aacenc/src/sf_estim.c" 29 | #include "external/aacenc/src/spreading.c" 30 | #include "external/aacenc/src/stat_bits.c" 31 | #include "external/aacenc/src/tns.c" 32 | #include "external/aacenc/src/transform.c" 33 | 34 | #cgo CFLAGS: -std=gnu99 -Iexternal/aacenc/include -DUSE_DEFAULT_MEM 35 | */ 36 | import "C" 37 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/quantize.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: quantize.h 18 | 19 | Content: Quantization functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _QUANTIZE_H_ 24 | #define _QUANTIZE_H_ 25 | #include "typedefs.h" 26 | 27 | /* quantizing */ 28 | 29 | #define MAX_QUANT 8191 30 | 31 | void QuantizeSpectrum(Word16 sfbCnt, 32 | Word16 maxSfbPerGroup, 33 | Word16 sfbPerGroup, 34 | Word16 *sfbOffset, Word32 *mdctSpectrum, 35 | Word16 globalGain, Word16 *scalefactors, 36 | Word16 *quantizedSpectrum); 37 | 38 | Word32 calcSfbDist(const Word32 *spec, 39 | Word16 sfbWidth, 40 | Word16 gain); 41 | 42 | #endif /* _QUANTIZE_H_ */ 43 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/pre_echo_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: pre_echo_control.h 18 | 19 | Content: Pre echo control functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __PRE_ECHO_CONTROL_H 24 | #define __PRE_ECHO_CONTROL_H 25 | 26 | #include "typedefs.h" 27 | 28 | void InitPreEchoControl(Word32 *pbThresholdnm1, 29 | Word16 numPb, 30 | Word32 *pbThresholdQuiet); 31 | 32 | 33 | void PreEchoControl(Word32 *pbThresholdNm1, 34 | Word16 numPb, 35 | Word32 maxAllowedIncreaseFactor, 36 | Word16 minRemainingThresholdFactor, 37 | Word32 *pbThreshold, 38 | Word16 mdctScale, 39 | Word16 mdctScalenm1); 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/bitenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: bitenc.h 18 | 19 | Content: Bitstream encoder structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _BITENC_H 24 | #define _BITENC_H 25 | 26 | #include "qc_data.h" 27 | #include "tns.h" 28 | #include "channel_map.h" 29 | #include "interface.h" 30 | 31 | struct BITSTREAMENCODER_INIT 32 | { 33 | Word16 nChannels; 34 | Word32 bitrate; 35 | Word32 sampleRate; 36 | Word16 profile; 37 | }; 38 | 39 | 40 | 41 | Word16 WriteBitstream (HANDLE_BIT_BUF hBitstream, 42 | ELEMENT_INFO elInfo, 43 | QC_OUT *qcOut, 44 | PSY_OUT *psyOut, 45 | Word16 *globUsedBits, 46 | const UWord8 *ancBytes, 47 | Word16 samplerate 48 | ); 49 | 50 | #endif /* _BITENC_H */ 51 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/grp_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: grp_data.h 18 | 19 | Content: Short block grouping function 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __GRP_DATA_H__ 24 | #define __GRP_DATA_H__ 25 | #include "psy_data.h" 26 | #include "typedefs.h" 27 | 28 | void 29 | groupShortData(Word32 *mdctSpectrum, 30 | Word32 *tmpSpectrum, 31 | SFB_THRESHOLD *sfbThreshold, 32 | SFB_ENERGY *sfbEnergy, 33 | SFB_ENERGY *sfbEnergyMS, 34 | SFB_ENERGY *sfbSpreadedEnergy, 35 | const Word16 sfbCnt, 36 | const Word16 *sfbOffset, 37 | const Word16 *sfbMinSnr, 38 | Word16 *groupedSfbOffset, 39 | Word16 *maxSfbPerGroup, 40 | Word16 *groupedSfbMinSnr, 41 | const Word16 noOfGroups, 42 | const Word16 *groupLen); 43 | 44 | #endif /* _INTERFACE_H */ 45 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/band_nrg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: band_nrg.h 18 | 19 | Content: Band/Line energy calculations functions 20 | 21 | *******************************************************************************/ 22 | 23 | 24 | #ifndef _BAND_NRG_H 25 | #define _BAND_NRG_H 26 | 27 | #include "typedef.h" 28 | 29 | 30 | void CalcBandEnergy(const Word32 *mdctSpectrum, 31 | const Word16 *bandOffset, 32 | const Word16 numBands, 33 | Word32 *bandEnergy, 34 | Word32 *bandEnergySum); 35 | 36 | 37 | void CalcBandEnergyMS(const Word32 *mdctSpectrumLeft, 38 | const Word32 *mdctSpectrumRight, 39 | const Word16 *bandOffset, 40 | const Word16 numBands, 41 | Word32 *bandEnergyMid, 42 | Word32 *bandEnergyMidSum, 43 | Word32 *bandEnergySide, 44 | Word32 *bandEnergySideSum); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/tns_param.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: tns_param.h 18 | 19 | Content: TNS parameters 20 | 21 | *******************************************************************************/ 22 | 23 | /* 24 | TNS parameters 25 | */ 26 | #ifndef _TNS_PARAM_H 27 | #define _TNS_PARAM_H 28 | 29 | #include "tns.h" 30 | 31 | typedef struct{ 32 | Word32 samplingRate; 33 | Word16 maxBandLong; 34 | Word16 maxBandShort; 35 | }TNS_MAX_TAB_ENTRY; 36 | 37 | typedef struct{ 38 | Word32 bitRateFrom; 39 | Word32 bitRateTo; 40 | const TNS_CONFIG_TABULATED *paramMono_Long; /* contains TNS parameters */ 41 | const TNS_CONFIG_TABULATED *paramMono_Short; 42 | const TNS_CONFIG_TABULATED *paramStereo_Long; 43 | const TNS_CONFIG_TABULATED *paramStereo_Short; 44 | }TNS_INFO_TAB; 45 | 46 | 47 | void GetTnsParam(TNS_CONFIG_TABULATED *tnsConfigTab, 48 | Word32 bitRate, Word16 channels, Word16 blockType); 49 | 50 | void GetTnsMaxBands(Word32 samplingRate, Word16 blockType, Word16* tnsMaxSfb); 51 | 52 | #endif /* _TNS_PARAM_H */ 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## aac-go 2 | [![Build Status](https://github.com/gen2brain/aac-go/actions/workflows/build.yml/badge.svg)](https://github.com/gen2brain/aac-go/actions) 3 | [![GoDoc](https://godoc.org/github.com/gen2brain/aac-go?status.svg)](https://godoc.org/github.com/gen2brain/aac-go) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/gen2brain/aac-go?branch=master)](https://goreportcard.com/report/github.com/gen2brain/aac-go) 5 | 6 | `aac-go` provides AAC codec encoder based on [VisualOn AAC encoder](https://github.com/mstorsjo/vo-aacenc) library. 7 | 8 | ### Installation 9 | 10 | go get -u github.com/gen2brain/aac-go 11 | 12 | ### Examples 13 | 14 | See [micgrab](https://github.com/gen2brain/aac-go/blob/master/examples/micgrab/micgrab.go) example. 15 | 16 | ### Usage 17 | 18 | ```go 19 | package main 20 | 21 | import ( 22 | "bytes" 23 | "os" 24 | 25 | "github.com/gen2brain/aac-go" 26 | "github.com/youpy/go-wav" 27 | ) 28 | 29 | func main() { 30 | file, err := os.Open("test.wav") 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | wreader := wav.NewReader(file) 36 | f, err := wreader.Format() 37 | if err != nil { 38 | panic(err) 39 | } 40 | 41 | buf := bytes.NewBuffer(make([]byte, 0)) 42 | 43 | opts := &aac.Options{} 44 | opts.SampleRate = int(f.SampleRate) 45 | opts.NumChannels = int(f.NumChannels) 46 | 47 | enc, err := aac.NewEncoder(buf, opts) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | err = enc.Encode(wreader) 53 | if err != nil { 54 | panic(err) 55 | } 56 | 57 | err = enc.Close() 58 | if err != nil { 59 | panic(err) 60 | } 61 | 62 | err = os.WriteFile("test.aac", buf.Bytes(), 0644) 63 | if err != nil { 64 | panic(err) 65 | } 66 | } 67 | ``` 68 | 69 | ## More 70 | 71 | For H.264 encoder see [x264-go](https://github.com/gen2brain/x264-go). 72 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/sf_estim.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: sf_estim.h 18 | 19 | Content: Scale factor estimation functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __SF_ESTIM_H__ 24 | #define __SF_ESTIM_H__ 25 | /* 26 | Scale factor estimation 27 | */ 28 | #include "psy_const.h" 29 | #include "interface.h" 30 | #include "qc_data.h" 31 | 32 | void 33 | CalcFormFactor(Word16 logSfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB], 34 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], 35 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB], 36 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 37 | const Word16 nChannels); 38 | 39 | void 40 | EstimateScaleFactors(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 41 | QC_OUT_CHANNEL qcOutChannel[MAX_CHANNELS], 42 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB], 43 | Word16 logSfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB], 44 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], 45 | const Word16 nChannels); 46 | #endif 47 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/ms_stereo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: ms_stereo.h 18 | 19 | Content: Declaration MS stereo processing structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __MS_STEREO_H__ 24 | #define __MS_STEREO_H__ 25 | #include "typedef.h" 26 | 27 | void MsStereoProcessing(Word32 *sfbEnergyLeft, 28 | Word32 *sfbEnergyRight, 29 | const Word32 *sfbEnergyMid, 30 | const Word32 *sfbEnergySide, 31 | Word32 *mdctSpectrumLeft, 32 | Word32 *mdctSpectrumRight, 33 | Word32 *sfbThresholdLeft, 34 | Word32 *sfbThresholdRight, 35 | Word32 *sfbSpreadedEnLeft, 36 | Word32 *sfbSpreadedEnRight, 37 | Word16 *msDigest, 38 | Word16 *msMask, 39 | const Word16 sfbCnt, 40 | const Word16 sfbPerGroup, 41 | const Word16 maxSfbPerGroup, 42 | const Word16 *sfbOffset); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/typedef.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: typedef.h 18 | 19 | Content: type defined for defferent paltform 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef typedef_h 24 | #define typedef_h "$Id $" 25 | 26 | #undef ORIGINAL_TYPEDEF_H /* define to get "original" ETSI version 27 | of typedef.h */ 28 | 29 | #ifdef ORIGINAL_TYPEDEF_H 30 | /* 31 | * this is the original code from the ETSI file typedef.h 32 | */ 33 | 34 | #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__ZTC__) 35 | typedef signed char Word8; 36 | typedef short Word16; 37 | typedef long Word32; 38 | typedef int Flag; 39 | 40 | #elif defined(__sun) 41 | typedef signed char Word8; 42 | typedef short Word16; 43 | typedef long Word32; 44 | typedef int Flag; 45 | 46 | #elif defined(__unix__) || defined(__unix) 47 | typedef signed char Word8; 48 | typedef short Word16; 49 | typedef int Word32; 50 | typedef int Flag; 51 | 52 | #endif 53 | #else /* not original typedef.h */ 54 | 55 | /* 56 | * use (improved) type definition file typdefs.h and add a "Flag" type 57 | */ 58 | #include "typedefs.h" 59 | typedef int Flag; 60 | 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/spreading.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: spreading.c 18 | 19 | Content: Spreading of energy function 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "oper_32b.h" 25 | #include "spreading.h" 26 | 27 | /********************************************************************************* 28 | * 29 | * function name: SpreadingMax 30 | * description: spreading the energy 31 | * higher frequencies thr(n) = max(thr(n), sh(n)*thr(n-1)) 32 | * lower frequencies thr(n) = max(thr(n), sl(n)*thr(n+1)) 33 | * 34 | **********************************************************************************/ 35 | void SpreadingMax(const Word16 pbCnt, 36 | const Word16 *maskLowFactor, 37 | const Word16 *maskHighFactor, 38 | Word32 *pbSpreadedEnergy) 39 | { 40 | Word32 i; 41 | 42 | /* slope to higher frequencies */ 43 | for (i=1; i=0; i--) { 49 | pbSpreadedEnergy[i] = max(pbSpreadedEnergy[i], 50 | L_mpy_ls(pbSpreadedEnergy[i+1], maskLowFactor[i])); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 4 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 5 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 6 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 7 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 8 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 9 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 10 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 11 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 12 | github.com/youpy/go-riff v0.1.0 h1:vZO/37nI4tIET8tQI0Qn0Y79qQh99aEpponTPiPut7k= 13 | github.com/youpy/go-riff v0.1.0/go.mod h1:83nxdDV4Z9RzrTut9losK7ve4hUnxUR8ASSz4BsKXwQ= 14 | github.com/youpy/go-wav v0.3.2 h1:NLM8L/7yZ0Bntadw/0h95OyUsen+DQIVf9gay+SUsMU= 15 | github.com/youpy/go-wav v0.3.2/go.mod h1:0FCieAXAeSdcxFfwLpRuEo0PFmAoc+8NU34h7TUvk50= 16 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b h1:QqixIpc5WFIqTLxB3Hq8qs0qImAgBdq0p6rq2Qdl634= 17 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b/go.mod h1:T2h1zV50R/q0CVYnsQOQ6L7P4a2ZxH47ixWcMXFGyx8= 18 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 19 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 20 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 21 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 22 | gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= 23 | gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= 24 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/adj_thr.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: adj_thr.h 18 | 19 | Content: Threshold compensation function 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __ADJ_THR_H 24 | #define __ADJ_THR_H 25 | 26 | #include "adj_thr_data.h" 27 | #include "qc_data.h" 28 | #include "interface.h" 29 | 30 | Word16 bits2pe(const Word16 bits); 31 | 32 | Word32 AdjThrNew(ADJ_THR_STATE** phAdjThr, 33 | Word32 nElements); 34 | 35 | void AdjThrDelete(ADJ_THR_STATE *hAdjThr); 36 | 37 | void AdjThrInit(ADJ_THR_STATE *hAdjThr, 38 | const Word32 peMean, 39 | Word32 chBitrate); 40 | 41 | void AdjustThresholds(ADJ_THR_STATE *adjThrState, 42 | ATS_ELEMENT* AdjThrStateElement, 43 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 44 | PSY_OUT_ELEMENT *psyOutElement, 45 | Word16 *chBitDistribution, 46 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB], 47 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], 48 | QC_OUT_ELEMENT* qcOE, 49 | ELEMENT_BITS* elBits, 50 | const Word16 nChannels, 51 | const Word16 maxBitFac); 52 | 53 | void AdjThrUpdate(ATS_ELEMENT *AdjThrStateElement, 54 | const Word16 dynBitsUsed); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/include/voMem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voMem.h 18 | 19 | Content: memory functions & data structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __voMem_H__ 24 | #define __voMem_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voIndex.h" 31 | 32 | typedef struct 33 | { 34 | VO_S32 Size; /*!< Buffer stride */ 35 | VO_S32 Flag; 36 | VO_PTR VBuffer; /*!< user data pointer */ 37 | VO_PTR PBuffer; /*!< user data pointer */ 38 | } 39 | VO_MEM_INFO; 40 | 41 | typedef struct VO_MEM_OPERATOR 42 | { 43 | VO_U32 (VO_API * Alloc) (VO_S32 uID, VO_MEM_INFO * pMemInfo); 44 | VO_U32 (VO_API * Free) (VO_S32 uID, VO_PTR pBuff); 45 | VO_U32 (VO_API * Set) (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize); 46 | VO_U32 (VO_API * Copy) (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 47 | VO_U32 (VO_API * Check) (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize); 48 | VO_S32 (VO_API * Compare) (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize); 49 | VO_U32 (VO_API * Move) (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 50 | } VO_MEM_OPERATOR; 51 | 52 | #define voMemAlloc(pBuff, pMemOP, ID, nSize) \ 53 | { \ 54 | VO_MEM_INFO voMemInfo; \ 55 | voMemInfo.Size=nSize; \ 56 | pMemOP->Alloc(ID, &voMemInfo); \ 57 | pBuff=(VO_PBYTE)voMemInfo.VBuffer; \ 58 | } 59 | 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif /* __cplusplus */ 64 | 65 | #endif // __voMem_H__ 66 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/adj_thr_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: adj_thr_data.h 18 | 19 | Content: Threshold compensation parameter 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __ADJ_THR_DATA_H 24 | #define __ADJ_THR_DATA_H 25 | 26 | #include "typedef.h" 27 | #include "psy_const.h" 28 | #include "line_pe.h" 29 | 30 | typedef struct { 31 | Word16 clipSaveLow, clipSaveHigh; 32 | Word16 minBitSave, maxBitSave; 33 | Word16 clipSpendLow, clipSpendHigh; 34 | Word16 minBitSpend, maxBitSpend; 35 | } BRES_PARAM; 36 | 37 | typedef struct { 38 | UWord8 modifyMinSnr; 39 | Word16 startSfbL, startSfbS; 40 | } AH_PARAM; 41 | 42 | typedef struct { 43 | Word32 maxRed; 44 | Word32 startRatio, maxRatio; 45 | Word32 redRatioFac; 46 | Word32 redOffs; 47 | } MINSNR_ADAPT_PARAM; 48 | 49 | typedef struct { 50 | /* parameters for bitreservoir control */ 51 | Word16 peMin, peMax; 52 | /* constant offset to pe */ 53 | Word16 peOffset; 54 | /* avoid hole parameters */ 55 | AH_PARAM ahParam; 56 | /* paramters for adaptation of minSnr */ 57 | MINSNR_ADAPT_PARAM minSnrAdaptParam; 58 | /* values for correction of pe */ 59 | Word16 peLast; 60 | Word16 dynBitsLast; 61 | Word16 peCorrectionFactor; 62 | } ATS_ELEMENT; 63 | 64 | typedef struct { 65 | BRES_PARAM bresParamLong, bresParamShort; /* Word16 size: 2*8 */ 66 | ATS_ELEMENT adjThrStateElem; /* Word16 size: 19 */ 67 | } ADJ_THR_STATE; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /examples/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/gen2brain/malgo v0.11.10 h1:u41QchDBS7Z2rwEVPu7uycK6HA8IyzKoUOhLU7IvYW4= 4 | github.com/gen2brain/malgo v0.11.10/go.mod h1:f9TtuN7DVrXMiV/yIceMeWpvanyVzJQMlBecJFVMxww= 5 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 6 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 7 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 8 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 13 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | github.com/youpy/go-riff v0.1.0 h1:vZO/37nI4tIET8tQI0Qn0Y79qQh99aEpponTPiPut7k= 15 | github.com/youpy/go-riff v0.1.0/go.mod h1:83nxdDV4Z9RzrTut9losK7ve4hUnxUR8ASSz4BsKXwQ= 16 | github.com/youpy/go-wav v0.3.2 h1:NLM8L/7yZ0Bntadw/0h95OyUsen+DQIVf9gay+SUsMU= 17 | github.com/youpy/go-wav v0.3.2/go.mod h1:0FCieAXAeSdcxFfwLpRuEo0PFmAoc+8NU34h7TUvk50= 18 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b h1:QqixIpc5WFIqTLxB3Hq8qs0qImAgBdq0p6rq2Qdl634= 19 | github.com/zaf/g711 v0.0.0-20190814101024-76a4a538f52b/go.mod h1:T2h1zV50R/q0CVYnsQOQ6L7P4a2ZxH47ixWcMXFGyx8= 20 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 21 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 22 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 23 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 24 | gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= 25 | gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= 26 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/qc_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: qc_main.h 18 | 19 | Content: Quantizing & coding functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _QC_MAIN_H 24 | #define _QC_MAIN_H 25 | 26 | #include "qc_data.h" 27 | #include "interface.h" 28 | #include "memalign.h" 29 | 30 | /* Quantizing & coding stage */ 31 | 32 | Word16 QCOutNew(QC_OUT *hQC, Word16 nChannels, VO_MEM_OPERATOR *pMemOP); 33 | 34 | void QCOutDelete(QC_OUT *hQC, VO_MEM_OPERATOR *pMemOP); 35 | 36 | Word16 QCNew(QC_STATE *hQC, VO_MEM_OPERATOR *pMemOP); 37 | 38 | Word16 QCInit(QC_STATE *hQC, 39 | struct QC_INIT *init); 40 | 41 | void QCDelete(QC_STATE *hQC, VO_MEM_OPERATOR *pMemOP); 42 | 43 | 44 | Word16 QCMain(QC_STATE *hQC, 45 | ELEMENT_BITS* elBits, 46 | ATS_ELEMENT* adjThrStateElement, 47 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], /* may be modified in-place */ 48 | PSY_OUT_ELEMENT* psyOutElement, 49 | QC_OUT_CHANNEL qcOutChannel[MAX_CHANNELS], /* out */ 50 | QC_OUT_ELEMENT* qcOutElement, 51 | Word16 nChannels, 52 | Word16 ancillaryDataBytes); /* returns error code */ 53 | 54 | void updateBitres(QC_STATE* qcKernel, 55 | QC_OUT* qcOut); 56 | 57 | Word16 FinalizeBitConsumption(QC_STATE *hQC, 58 | QC_OUT* qcOut); 59 | 60 | Word16 AdjustBitrate(QC_STATE *hQC, 61 | Word32 bitRate, 62 | Word32 sampleRate); 63 | 64 | #endif /* _QC_MAIN_H */ 65 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/cmnMemory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: cmnMemory.c 18 | 19 | Content: sample code for memory operator implementation 20 | 21 | *******************************************************************************/ 22 | #include "cmnMemory.h" 23 | 24 | #include 25 | #include 26 | 27 | //VO_MEM_OPERATOR g_memOP; 28 | 29 | #define UNUSED(x) (void)(x) 30 | 31 | VO_U32 cmnMemAlloc (VO_S32 uID, VO_MEM_INFO * pMemInfo) 32 | { 33 | UNUSED(uID); 34 | 35 | if (!pMemInfo) 36 | return VO_ERR_INVALID_ARG; 37 | 38 | pMemInfo->VBuffer = malloc (pMemInfo->Size); 39 | return 0; 40 | } 41 | 42 | VO_U32 cmnMemFree (VO_S32 uID, VO_PTR pMem) 43 | { 44 | UNUSED(uID); 45 | 46 | free (pMem); 47 | return 0; 48 | } 49 | 50 | VO_U32 cmnMemSet (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize) 51 | { 52 | UNUSED(uID); 53 | 54 | memset (pBuff, uValue, uSize); 55 | return 0; 56 | } 57 | 58 | VO_U32 cmnMemCopy (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize) 59 | { 60 | UNUSED(uID); 61 | 62 | memcpy (pDest, pSource, uSize); 63 | return 0; 64 | } 65 | 66 | VO_U32 cmnMemCheck (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize) 67 | { 68 | UNUSED(uID); 69 | UNUSED(pBuffer); 70 | UNUSED(uSize); 71 | 72 | return 0; 73 | } 74 | 75 | VO_S32 cmnMemCompare (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize) 76 | { 77 | UNUSED(uID); 78 | 79 | return memcmp(pBuffer1, pBuffer2, uSize); 80 | } 81 | 82 | VO_U32 cmnMemMove (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize) 83 | { 84 | UNUSED(uID); 85 | 86 | memmove (pDest, pSource, uSize); 87 | return 0; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/psy_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: psy_const.h 18 | 19 | Content: Global psychoacoustic constants structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _PSYCONST_H 24 | #define _PSYCONST_H 25 | 26 | #include "config.h" 27 | 28 | #define TRUE 1 29 | #define FALSE 0 30 | 31 | #define FRAME_LEN_LONG AACENC_BLOCKSIZE 32 | #define TRANS_FAC 8 33 | #define FRAME_LEN_SHORT (FRAME_LEN_LONG/TRANS_FAC) 34 | 35 | 36 | 37 | /* Block types */ 38 | enum 39 | { 40 | LONG_WINDOW = 0, 41 | START_WINDOW, 42 | SHORT_WINDOW, 43 | STOP_WINDOW 44 | }; 45 | 46 | /* Window shapes */ 47 | enum 48 | { 49 | SINE_WINDOW = 0, 50 | KBD_WINDOW = 1 51 | }; 52 | 53 | /* 54 | MS stuff 55 | */ 56 | enum 57 | { 58 | SI_MS_MASK_NONE = 0, 59 | SI_MS_MASK_SOME = 1, 60 | SI_MS_MASK_ALL = 2 61 | }; 62 | 63 | #define MAX_NO_OF_GROUPS 4 64 | #define MAX_SFB_SHORT 15 /* 15 for a memory optimized implementation, maybe 16 for convenient debugging */ 65 | #define MAX_SFB_LONG 51 /* 51 for a memory optimized implementation, maybe 64 for convenient debugging */ 66 | #define MAX_SFB (MAX_SFB_SHORT > MAX_SFB_LONG ? MAX_SFB_SHORT : MAX_SFB_LONG) /* = MAX_SFB_LONG */ 67 | #define MAX_GROUPED_SFB (MAX_NO_OF_GROUPS*MAX_SFB_SHORT > MAX_SFB_LONG ? \ 68 | MAX_NO_OF_GROUPS*MAX_SFB_SHORT : MAX_SFB_LONG) 69 | 70 | #define BLOCK_SWITCHING_OFFSET (1*1024+3*128+64+128) 71 | #define BLOCK_SWITCHING_DATA_SIZE FRAME_LEN_LONG 72 | 73 | #define TRANSFORM_OFFSET_LONG 0 74 | #define TRANSFORM_OFFSET_SHORT 448 75 | 76 | #define LOG_NORM_PCM -15 77 | 78 | #define NUM_SAMPLE_RATES 12 79 | 80 | #endif /* _PSYCONST_H */ 81 | -------------------------------------------------------------------------------- /examples/micgrab/micgrab.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | 9 | "github.com/gen2brain/aac-go" 10 | "github.com/gen2brain/malgo" 11 | ) 12 | 13 | func main() { 14 | numChannels := 1 15 | sampleRate := 48000 16 | 17 | ctx, err := malgo.InitContext(nil, malgo.ContextConfig{}, func(message string) { 18 | fmt.Printf("LOG <%v>\n", message) 19 | }) 20 | if err != nil { 21 | fmt.Println(err) 22 | os.Exit(1) 23 | } 24 | defer func() { 25 | _ = ctx.Uninit() 26 | ctx.Free() 27 | }() 28 | 29 | deviceConfig := malgo.DefaultDeviceConfig(malgo.Capture) 30 | deviceConfig.Capture.Format = malgo.FormatS16 31 | deviceConfig.Capture.Channels = uint32(numChannels) 32 | 33 | var capturedSampleCount uint32 34 | pCapturedSamples := make([]byte, 0) 35 | 36 | sizeInBytes := uint32(malgo.SampleSizeInBytes(deviceConfig.Capture.Format)) 37 | onRecvFrames := func(pSample2, pSample []byte, framecount uint32) { 38 | sampleCount := framecount * deviceConfig.Capture.Channels * sizeInBytes 39 | newCapturedSampleCount := capturedSampleCount + sampleCount 40 | pCapturedSamples = append(pCapturedSamples, pSample...) 41 | capturedSampleCount = newCapturedSampleCount 42 | } 43 | 44 | fmt.Println("Recording...") 45 | captureCallbacks := malgo.DeviceCallbacks{ 46 | Data: onRecvFrames, 47 | } 48 | device, err := malgo.InitDevice(ctx.Context, deviceConfig, captureCallbacks) 49 | if err != nil { 50 | fmt.Println(err) 51 | os.Exit(1) 52 | } 53 | 54 | err = device.Start() 55 | if err != nil { 56 | fmt.Println(err) 57 | os.Exit(1) 58 | } 59 | 60 | fmt.Println("Press Enter to stop recording...") 61 | fmt.Scanln() 62 | 63 | device.Uninit() 64 | 65 | fmt.Println("Encoding...") 66 | buf := bytes.NewBuffer(make([]byte, 0)) 67 | 68 | opts := &aac.Options{} 69 | opts.SampleRate = sampleRate 70 | opts.NumChannels = numChannels 71 | 72 | enc, err := aac.NewEncoder(buf, opts) 73 | if err != nil { 74 | fmt.Println(err) 75 | os.Exit(1) 76 | } 77 | 78 | reader := bytes.NewReader(pCapturedSamples) 79 | 80 | err = enc.Encode(reader) 81 | if err != nil { 82 | fmt.Println(err) 83 | os.Exit(1) 84 | } 85 | 86 | err = enc.Close() 87 | if err != nil { 88 | fmt.Println(err) 89 | os.Exit(1) 90 | } 91 | 92 | err = ioutil.WriteFile("capture.aac", buf.Bytes(), 0644) 93 | if err != nil { 94 | fmt.Println(err) 95 | os.Exit(1) 96 | } 97 | 98 | os.Exit(0) 99 | } 100 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/oper_32b.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: oper_32b.h 18 | 19 | Content: Double precision operations 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __OPER_32b_H 24 | #define __OPER_32b_H 25 | 26 | #include "typedef.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define POW2_TABLE_BITS 8 33 | #define POW2_TABLE_SIZE (1<> 16); 52 | 53 | l_var_out = (long)swLow1 * (long)var1 >> 15; 54 | 55 | l_var_out += swHigh1 * var1 << 1; 56 | 57 | return(l_var_out); 58 | } 59 | 60 | __inline Word32 L_mpy_wx(Word32 L_var2, Word16 var1) 61 | { 62 | #if ARMV5TE_L_MPY_LS 63 | Word32 result; 64 | asm volatile( 65 | "SMULWB %[result], %[L_var2], %[var1] \n" 66 | :[result]"=r"(result) 67 | :[L_var2]"r"(L_var2), [var1]"r"(var1) 68 | ); 69 | return result; 70 | #else 71 | unsigned short swLow1; 72 | Word16 swHigh1; 73 | Word32 l_var_out; 74 | 75 | swLow1 = (unsigned short)(L_var2); 76 | swHigh1 = (Word16)(L_var2 >> 16); 77 | 78 | l_var_out = (long)swLow1 * (long)var1 >> 16; 79 | l_var_out += swHigh1 * var1; 80 | 81 | return(l_var_out); 82 | #endif 83 | } 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/psy_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: psy_data.h 18 | 19 | Content: Psychoacoustic data and structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _PSY_DATA_H 24 | #define _PSY_DATA_H 25 | 26 | #include "block_switch.h" 27 | #include "tns.h" 28 | 29 | /* 30 | the structs can be implemented as unions 31 | */ 32 | 33 | typedef struct{ 34 | Word32 sfbLong[MAX_GROUPED_SFB]; 35 | Word32 sfbShort[TRANS_FAC][MAX_SFB_SHORT]; 36 | }SFB_THRESHOLD; /* Word16 size: 260 */ 37 | 38 | typedef struct{ 39 | Word32 sfbLong[MAX_GROUPED_SFB]; 40 | Word32 sfbShort[TRANS_FAC][MAX_SFB_SHORT]; 41 | }SFB_ENERGY; /* Word16 size: 260 */ 42 | 43 | typedef struct{ 44 | Word32 sfbLong; 45 | Word32 sfbShort[TRANS_FAC]; 46 | }SFB_ENERGY_SUM; /* Word16 size: 18 */ 47 | 48 | 49 | typedef struct{ 50 | BLOCK_SWITCHING_CONTROL blockSwitchingControl; /* block switching */ 51 | Word16 *mdctDelayBuffer; /* mdct delay buffer [BLOCK_SWITCHING_OFFSET]*/ 52 | Word32 sfbThresholdnm1[MAX_SFB]; /* PreEchoControl */ 53 | Word16 mdctScalenm1; /* scale of last block's mdct (PreEchoControl) */ 54 | 55 | SFB_THRESHOLD sfbThreshold; /* adapt */ 56 | SFB_ENERGY sfbEnergy; /* sfb Energy */ 57 | SFB_ENERGY sfbEnergyMS; 58 | SFB_ENERGY_SUM sfbEnergySum; 59 | SFB_ENERGY_SUM sfbEnergySumMS; 60 | SFB_ENERGY sfbSpreadedEnergy; 61 | 62 | Word32 *mdctSpectrum; /* mdct spectrum [FRAME_LEN_LONG] */ 63 | Word16 mdctScale; /* scale of mdct */ 64 | }PSY_DATA; /* Word16 size: 4 + 87 + 102 + 360 + 360 + 360 + 18 + 18 + 360 = 1669 */ 65 | 66 | #endif /* _PSY_DATA_H */ 67 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/line_pe.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: line_pe.h 18 | 19 | Content: Perceptual entropie module structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __LINE_PE_H 24 | #define __LINE_PE_H 25 | 26 | 27 | #include "psy_const.h" 28 | #include "interface.h" 29 | 30 | 31 | typedef struct { 32 | Word16 sfbLdEnergy[MAX_GROUPED_SFB]; /* 4*log(sfbEnergy)/log(2) */ 33 | Word16 sfbNLines4[MAX_GROUPED_SFB]; /* 4*number of relevant lines in sfb */ 34 | Word16 sfbPe[MAX_GROUPED_SFB]; /* pe for each sfb */ 35 | Word16 sfbConstPart[MAX_GROUPED_SFB]; /* constant part for each sfb */ 36 | Word16 sfbNActiveLines[MAX_GROUPED_SFB]; /* number of active lines in sfb */ 37 | Word16 pe; /* sum of sfbPe */ 38 | Word16 constPart; /* sum of sfbConstPart */ 39 | Word16 nActiveLines; /* sum of sfbNActiveLines */ 40 | } PE_CHANNEL_DATA; /* size Word16: 303 */ 41 | 42 | 43 | typedef struct { 44 | PE_CHANNEL_DATA peChannelData[MAX_CHANNELS]; 45 | Word16 pe; 46 | Word16 constPart; 47 | Word16 nActiveLines; 48 | Word16 offset; 49 | Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB]; 50 | Word32 thrExp[MAX_CHANNELS][MAX_GROUPED_SFB]; 51 | Word32 sfbPeFactors[MAX_CHANNELS][MAX_GROUPED_SFB]; 52 | } PE_DATA; /* size Word16: 303 + 4 + 120 + 240 = 667 */ 53 | 54 | 55 | 56 | 57 | void prepareSfbPe(PE_DATA *peData, 58 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 59 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB], 60 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], 61 | const Word16 nChannels, 62 | const Word16 peOffset); 63 | 64 | 65 | 66 | 67 | 68 | void calcSfbPe(PE_DATA *peData, 69 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 70 | const Word16 nChannels); 71 | 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/dyn_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: dyn_bits.h 18 | 19 | Content: Noiseless coder module structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __DYN_BITS_H 24 | #define __DYN_BITS_H 25 | 26 | #include "psy_const.h" 27 | #include "tns.h" 28 | #include "bit_cnt.h" 29 | 30 | 31 | 32 | #define MAX_SECTIONS MAX_GROUPED_SFB 33 | #define SECT_ESC_VAL_LONG 31 34 | #define SECT_ESC_VAL_SHORT 7 35 | #define CODE_BOOK_BITS 4 36 | #define SECT_BITS_LONG 5 37 | #define SECT_BITS_SHORT 3 38 | 39 | typedef struct 40 | { 41 | Word16 codeBook; 42 | Word16 sfbStart; 43 | Word16 sfbCnt; 44 | Word16 sectionBits; 45 | } 46 | SECTION_INFO; 47 | 48 | 49 | 50 | 51 | typedef struct 52 | { 53 | Word16 blockType; 54 | Word16 noOfGroups; 55 | Word16 sfbCnt; 56 | Word16 maxSfbPerGroup; 57 | Word16 sfbPerGroup; 58 | Word16 noOfSections; 59 | SECTION_INFO sectionInfo[MAX_SECTIONS]; 60 | Word16 sideInfoBits; /* sectioning bits */ 61 | Word16 huffmanBits; /* huffman coded bits */ 62 | Word16 scalefacBits; /* scalefac coded bits */ 63 | Word16 firstScf; /* first scf to be coded */ 64 | Word16 bitLookUp[MAX_SFB_LONG*(CODE_BOOK_ESC_NDX+1)]; 65 | Word16 mergeGainLookUp[MAX_SFB_LONG]; 66 | } 67 | SECTION_DATA; /* Word16 size: 10 + 60(MAX_SECTIONS)*4(SECTION_INFO) + 51(MAX_SFB_LONG)*12(CODE_BOOK_ESC_NDX+1) + 51(MAX_SFB_LONG) = 913 */ 68 | 69 | 70 | Word16 BCInit(void); 71 | 72 | Word16 dynBitCount(const Word16 *quantSpectrum, 73 | const UWord16 *maxValueInSfb, 74 | const Word16 *scalefac, 75 | const Word16 blockType, 76 | const Word16 sfbCnt, 77 | const Word16 maxSfbPerGroup, 78 | const Word16 sfbPerGroup, 79 | const Word16 *sfbOffset, 80 | SECTION_DATA *sectionData); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/psy_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: psy_main.h 18 | 19 | Content: Psychoacoustic major function block 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _PSYMAIN_H 24 | #define _PSYMAIN_H 25 | 26 | #include "psy_configuration.h" 27 | #include "qc_data.h" 28 | #include "memalign.h" 29 | 30 | /* 31 | psy kernel 32 | */ 33 | typedef struct { 34 | PSY_CONFIGURATION_LONG psyConfLong; /* Word16 size: 515 */ 35 | PSY_CONFIGURATION_SHORT psyConfShort; /* Word16 size: 167 */ 36 | PSY_DATA psyData[MAX_CHANNELS]; /* Word16 size: MAX_CHANNELS*1669*/ 37 | TNS_DATA tnsData[MAX_CHANNELS]; /* Word16 size: MAX_CHANNELS*235 */ 38 | Word32* pScratchTns; 39 | Word16 sampleRateIdx; 40 | }PSY_KERNEL; /* Word16 size: 2587 / 4491 */ 41 | 42 | 43 | Word16 PsyNew( PSY_KERNEL *hPsy, Word32 nChan, VO_MEM_OPERATOR *pMemOP); 44 | Word16 PsyDelete( PSY_KERNEL *hPsy, VO_MEM_OPERATOR *pMemOP); 45 | 46 | Word16 PsyOutNew( PSY_OUT *hPsyOut, VO_MEM_OPERATOR *pMemOP); 47 | Word16 PsyOutDelete( PSY_OUT *hPsyOut, VO_MEM_OPERATOR *pMemOP); 48 | 49 | Word16 psyMainInit( PSY_KERNEL *hPsy, 50 | Word32 sampleRate, 51 | Word32 bitRate, 52 | Word16 channels, 53 | Word16 tnsMask, 54 | Word16 bandwidth); 55 | 56 | 57 | Word16 psyMain(Word16 nChannels, /*!< total number of channels */ 58 | ELEMENT_INFO *elemInfo, 59 | Word16 *timeSignal, /*!< interleaved time signal */ 60 | PSY_DATA psyData[MAX_CHANNELS], 61 | TNS_DATA tnsData[MAX_CHANNELS], 62 | PSY_CONFIGURATION_LONG* psyConfLong, 63 | PSY_CONFIGURATION_SHORT* psyConfShort, 64 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 65 | PSY_OUT_ELEMENT *psyOutElement, 66 | Word32 *pScratchTns, 67 | Word32 sampleRate); 68 | 69 | #endif /* _PSYMAIN_H */ 70 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/tns_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: tns_func.h 18 | 19 | Content: TNS functions 20 | 21 | *******************************************************************************/ 22 | 23 | /* 24 | Temporal noise shaping 25 | */ 26 | #ifndef _TNS_FUNC_H 27 | #define _TNS_FUNC_H 28 | #include "typedef.h" 29 | #include "psy_configuration.h" 30 | 31 | Word16 InitTnsConfigurationLong(Word32 bitrate, 32 | Word32 samplerate, 33 | Word16 channels, 34 | TNS_CONFIG *tnsConfig, 35 | PSY_CONFIGURATION_LONG *psyConfig, 36 | Word16 active); 37 | 38 | Word16 InitTnsConfigurationShort(Word32 bitrate, 39 | Word32 samplerate, 40 | Word16 channels, 41 | TNS_CONFIG *tnsConfig, 42 | PSY_CONFIGURATION_SHORT *psyConfig, 43 | Word16 active); 44 | 45 | Word32 TnsDetect(TNS_DATA* tnsData, 46 | TNS_CONFIG tC, 47 | Word32* pScratchTns, 48 | const Word16 sfbOffset[], 49 | Word32* spectrum, 50 | Word16 subBlockNumber, 51 | Word16 blockType, 52 | Word32 * sfbEnergy); 53 | 54 | void TnsSync(TNS_DATA *tnsDataDest, 55 | const TNS_DATA *tnsDataSrc, 56 | const TNS_CONFIG tC, 57 | const Word16 subBlockNumber, 58 | const Word16 blockType); 59 | 60 | Word16 TnsEncode(TNS_INFO* tnsInfo, 61 | TNS_DATA* tnsData, 62 | Word16 numOfSfb, 63 | TNS_CONFIG tC, 64 | Word16 lowPassLine, 65 | Word32* spectrum, 66 | Word16 subBlockNumber, 67 | Word16 blockType); 68 | 69 | void ApplyTnsMultTableToRatios(Word16 startCb, 70 | Word16 stopCb, 71 | TNS_SUBBLOCK_INFO subInfo, 72 | Word32 *thresholds); 73 | 74 | 75 | #endif /* _TNS_FUNC_H */ 76 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/block_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: block_switch.h 18 | 19 | Content: Block switching structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _BLOCK_SWITCH_H 24 | #define _BLOCK_SWITCH_H 25 | 26 | #include "typedef.h" 27 | 28 | 29 | /****************** Defines ******************************/ 30 | #define BLOCK_SWITCHING_IIR_LEN 2 /* Length of HighPass-FIR-Filter for Attack-Detection */ 31 | #define BLOCK_SWITCH_WINDOWS TRANS_FAC /* number of windows for energy calculation */ 32 | #define BLOCK_SWITCH_WINDOW_LEN FRAME_LEN_SHORT /* minimal granularity of energy calculation */ 33 | 34 | 35 | 36 | /****************** Structures ***************************/ 37 | typedef struct{ 38 | Word32 invAttackRatio; 39 | Word16 windowSequence; 40 | Word16 nextwindowSequence; 41 | Flag attack; 42 | Flag lastattack; 43 | Word16 attackIndex; 44 | Word16 lastAttackIndex; 45 | Word16 noOfGroups; 46 | Word16 groupLen[TRANS_FAC]; 47 | Word32 windowNrg[2][BLOCK_SWITCH_WINDOWS]; /* time signal energy in Subwindows (last and current) */ 48 | Word32 windowNrgF[2][BLOCK_SWITCH_WINDOWS]; /* filtered time signal energy in segments (last and current) */ 49 | Word32 iirStates[BLOCK_SWITCHING_IIR_LEN]; /* filter delay-line */ 50 | Word32 maxWindowNrg; /* max energy in subwindows */ 51 | Word32 accWindowNrg; /* recursively accumulated windowNrgF */ 52 | }BLOCK_SWITCHING_CONTROL; 53 | 54 | 55 | 56 | 57 | 58 | Word16 InitBlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControl, 59 | const Word32 bitRate, const Word16 nChannels); 60 | 61 | Word16 BlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControl, 62 | Word16 *timeSignal, 63 | Word32 sampleRate, 64 | Word16 chIncrement); 65 | 66 | Word16 SyncBlockSwitching(BLOCK_SWITCHING_CONTROL *blockSwitchingControlLeft, 67 | BLOCK_SWITCHING_CONTROL *blockSwitchingControlRight, 68 | const Word16 noOfChannels); 69 | 70 | 71 | 72 | #endif /* #ifndef _BLOCK_SWITCH_H */ 73 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/include/voAAC.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voAAC.h 18 | 19 | Content: AAC codec APIs & data types 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __voAAC_H__ 24 | #define __voAAC_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voAudio.h" 31 | 32 | /*! 33 | * the frame type that the decoder supports 34 | */ 35 | typedef enum { 36 | VOAAC_RAWDATA = 0, /*! 28 | #else 29 | #include 30 | #endif 31 | 32 | /***************************************************************************** 33 | * 34 | * function name: mem_malloc 35 | * description: malloc the alignments memory 36 | * returns: the point of the memory 37 | * 38 | **********************************************************************************/ 39 | void * 40 | mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID) 41 | { 42 | int ret; 43 | unsigned char *mem_ptr; 44 | VO_MEM_INFO MemInfo; 45 | 46 | if (!alignment) { 47 | 48 | MemInfo.Flag = 0; 49 | MemInfo.Size = size + 1; 50 | ret = pMemop->Alloc(CodecID, &MemInfo); 51 | if(ret != 0) 52 | return 0; 53 | mem_ptr = (unsigned char *)MemInfo.VBuffer; 54 | 55 | pMemop->Set(CodecID, mem_ptr, 0, size + 1); 56 | 57 | *mem_ptr = (unsigned char)1; 58 | 59 | return ((void *)(mem_ptr+1)); 60 | } else { 61 | unsigned char *tmp; 62 | 63 | MemInfo.Flag = 0; 64 | MemInfo.Size = size + alignment; 65 | ret = pMemop->Alloc(CodecID, &MemInfo); 66 | if(ret != 0) 67 | return 0; 68 | 69 | tmp = (unsigned char *)MemInfo.VBuffer; 70 | 71 | pMemop->Set(CodecID, tmp, 0, size + alignment); 72 | 73 | mem_ptr = 74 | (unsigned char *) ((intptr_t) (tmp + alignment - 1) & 75 | (~((intptr_t) (alignment - 1)))); 76 | 77 | if (mem_ptr == tmp) 78 | mem_ptr += alignment; 79 | 80 | *(mem_ptr - 1) = (unsigned char) (mem_ptr - tmp); 81 | 82 | return ((void *)mem_ptr); 83 | } 84 | 85 | return(0); 86 | } 87 | 88 | 89 | /***************************************************************************** 90 | * 91 | * function name: mem_free 92 | * description: free the memory 93 | * 94 | *******************************************************************************/ 95 | void 96 | mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID) 97 | { 98 | 99 | unsigned char *ptr; 100 | 101 | if (mem_ptr == 0) 102 | return; 103 | 104 | ptr = mem_ptr; 105 | 106 | ptr -= *(ptr - 1); 107 | 108 | pMemop->Free(CodecID, ptr); 109 | } 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/bit_cnt.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: bit_cnt.h 18 | 19 | Content: Huffman Bitcounter & coder structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __BITCOUNT_H 24 | #define __BITCOUNT_H 25 | 26 | #include "bitbuffer.h" 27 | #include "basic_op.h" 28 | #define INVALID_BITCOUNT (MAX_16/4) 29 | 30 | /* 31 | code book number table 32 | */ 33 | 34 | enum codeBookNo{ 35 | CODE_BOOK_ZERO_NO= 0, 36 | CODE_BOOK_1_NO= 1, 37 | CODE_BOOK_2_NO= 2, 38 | CODE_BOOK_3_NO= 3, 39 | CODE_BOOK_4_NO= 4, 40 | CODE_BOOK_5_NO= 5, 41 | CODE_BOOK_6_NO= 6, 42 | CODE_BOOK_7_NO= 7, 43 | CODE_BOOK_8_NO= 8, 44 | CODE_BOOK_9_NO= 9, 45 | CODE_BOOK_10_NO= 10, 46 | CODE_BOOK_ESC_NO= 11, 47 | CODE_BOOK_RES_NO= 12, 48 | CODE_BOOK_PNS_NO= 13 49 | }; 50 | 51 | /* 52 | code book index table 53 | */ 54 | 55 | enum codeBookNdx{ 56 | CODE_BOOK_ZERO_NDX=0, 57 | CODE_BOOK_1_NDX, 58 | CODE_BOOK_2_NDX, 59 | CODE_BOOK_3_NDX, 60 | CODE_BOOK_4_NDX, 61 | CODE_BOOK_5_NDX, 62 | CODE_BOOK_6_NDX, 63 | CODE_BOOK_7_NDX, 64 | CODE_BOOK_8_NDX, 65 | CODE_BOOK_9_NDX, 66 | CODE_BOOK_10_NDX, 67 | CODE_BOOK_ESC_NDX, 68 | CODE_BOOK_RES_NDX, 69 | CODE_BOOK_PNS_NDX, 70 | NUMBER_OF_CODE_BOOKS 71 | }; 72 | 73 | /* 74 | code book lav table 75 | */ 76 | 77 | enum codeBookLav{ 78 | CODE_BOOK_ZERO_LAV=0, 79 | CODE_BOOK_1_LAV=1, 80 | CODE_BOOK_2_LAV=1, 81 | CODE_BOOK_3_LAV=2, 82 | CODE_BOOK_4_LAV=2, 83 | CODE_BOOK_5_LAV=4, 84 | CODE_BOOK_6_LAV=4, 85 | CODE_BOOK_7_LAV=7, 86 | CODE_BOOK_8_LAV=7, 87 | CODE_BOOK_9_LAV=12, 88 | CODE_BOOK_10_LAV=12, 89 | CODE_BOOK_ESC_LAV=16, 90 | CODE_BOOK_SCF_LAV=60, 91 | CODE_BOOK_PNS_LAV=60 92 | }; 93 | 94 | Word16 bitCount(const Word16 *aQuantSpectrum, 95 | const Word16 noOfSpecLines, 96 | Word16 maxVal, 97 | Word16 *bitCountLut); 98 | 99 | Word16 codeValues(Word16 *values, Word16 width, Word16 codeBook, HANDLE_BIT_BUF hBitstream); 100 | 101 | Word16 bitCountScalefactorDelta(Word16 delta); 102 | Word16 codeScalefactorDelta(Word16 scalefactor, HANDLE_BIT_BUF hBitstream); 103 | 104 | 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/tns.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: tns.h 18 | 19 | Content: TNS structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _TNS_H 24 | #define _TNS_H 25 | 26 | #include "typedef.h" 27 | #include "psy_const.h" 28 | 29 | 30 | 31 | #define TNS_MAX_ORDER 12 32 | #define TNS_MAX_ORDER_SHORT 5 33 | 34 | #define FILTER_DIRECTION 0 35 | 36 | typedef struct{ /*stuff that is tabulated dependent on bitrate etc. */ 37 | Word16 threshOn; /* min. prediction gain for using tns TABUL * 100*/ 38 | Word32 lpcStartFreq; /* lowest freq for lpc TABUL*/ 39 | Word32 lpcStopFreq; /* TABUL */ 40 | Word32 tnsTimeResolution; 41 | }TNS_CONFIG_TABULATED; 42 | 43 | 44 | typedef struct { /*assigned at InitTime*/ 45 | Word16 tnsActive; 46 | Word16 tnsMaxSfb; 47 | 48 | Word16 maxOrder; /* max. order of tns filter */ 49 | Word16 tnsStartFreq; /* lowest freq. for tns filtering */ 50 | Word16 coefRes; 51 | 52 | TNS_CONFIG_TABULATED confTab; 53 | 54 | Word32 acfWindow[TNS_MAX_ORDER+1]; 55 | 56 | Word16 tnsStartBand; 57 | Word16 tnsStartLine; 58 | 59 | Word16 tnsStopBand; 60 | Word16 tnsStopLine; 61 | 62 | Word16 lpcStartBand; 63 | Word16 lpcStartLine; 64 | 65 | Word16 lpcStopBand; 66 | Word16 lpcStopLine; 67 | 68 | Word16 tnsRatioPatchLowestCb; 69 | Word16 tnsModifyBeginCb; 70 | 71 | Word16 threshold; /* min. prediction gain for using tns TABUL * 100 */ 72 | 73 | }TNS_CONFIG; 74 | 75 | 76 | typedef struct { 77 | Word16 tnsActive; 78 | Word32 parcor[TNS_MAX_ORDER]; 79 | Word16 predictionGain; 80 | } TNS_SUBBLOCK_INFO; /* Word16 size: 26 */ 81 | 82 | typedef struct{ 83 | TNS_SUBBLOCK_INFO subBlockInfo[TRANS_FAC]; 84 | } TNS_DATA_SHORT; 85 | 86 | typedef struct{ 87 | TNS_SUBBLOCK_INFO subBlockInfo; 88 | } TNS_DATA_LONG; 89 | 90 | typedef struct{ 91 | TNS_DATA_LONG tnsLong; 92 | TNS_DATA_SHORT tnsShort; 93 | }TNS_DATA_RAW; 94 | 95 | typedef struct{ 96 | Word16 numOfSubblocks; 97 | TNS_DATA_RAW dataRaw; 98 | }TNS_DATA; /* Word16 size: 1 + 8*26 + 26 = 235 */ 99 | 100 | typedef struct{ 101 | Word16 tnsActive[TRANS_FAC]; 102 | Word16 coefRes[TRANS_FAC]; 103 | Word16 length[TRANS_FAC]; 104 | Word16 order[TRANS_FAC]; 105 | Word16 coef[TRANS_FAC*TNS_MAX_ORDER_SHORT]; 106 | }TNS_INFO; /* Word16 size: 72 */ 107 | 108 | #endif /* _TNS_H */ 109 | -------------------------------------------------------------------------------- /encode.go: -------------------------------------------------------------------------------- 1 | // Package aac provides AAC codec encoder based on VisualOn AAC encoder library. 2 | package aac 3 | 4 | //#include 5 | import "C" 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | "io" 11 | "unsafe" 12 | 13 | "github.com/gen2brain/aac-go/aacenc" 14 | ) 15 | 16 | // Options represent encoding options. 17 | type Options struct { 18 | // Audio file sample rate 19 | SampleRate int 20 | // Encoder bit rate in bits/sec 21 | BitRate int 22 | // Number of channels on input (1,2) 23 | NumChannels int 24 | } 25 | 26 | // Encoder type. 27 | type Encoder struct { 28 | w io.Writer 29 | 30 | insize int 31 | inbuf []byte 32 | outbuf []byte 33 | } 34 | 35 | // NewEncoder returns new AAC encoder. 36 | func NewEncoder(w io.Writer, opts *Options) (*Encoder, error) { 37 | e := &Encoder{} 38 | e.w = w 39 | 40 | if opts.BitRate == 0 { 41 | opts.BitRate = 64000 42 | } 43 | 44 | ret := aacenc.Init(aacenc.VoAudioCodingAac) 45 | err := aacenc.ErrorFromResult(ret) 46 | if err != nil { 47 | return nil, fmt.Errorf("aac: %w", err) 48 | } 49 | 50 | var params aacenc.Param 51 | params.SampleRate = int32(opts.SampleRate) 52 | params.BitRate = int32(opts.BitRate) 53 | params.NChannels = int16(opts.NumChannels) 54 | params.AdtsUsed = 1 55 | 56 | ret = aacenc.SetParam(aacenc.VoPidAacEncparam, unsafe.Pointer(¶ms)) 57 | err = aacenc.ErrorFromResult(ret) 58 | if err != nil { 59 | return nil, fmt.Errorf("aac: %w", err) 60 | } 61 | 62 | e.insize = opts.NumChannels * 2 * 1024 63 | 64 | e.inbuf = make([]byte, e.insize) 65 | e.outbuf = make([]byte, 20480) 66 | 67 | return e, nil 68 | } 69 | 70 | // Encode encodes data from reader. 71 | func (e *Encoder) Encode(r io.Reader) error { 72 | inputEmpty := false 73 | for !inputEmpty { 74 | n, err := r.Read(e.inbuf) 75 | if err != nil { 76 | if !errors.Is(err, io.EOF) { 77 | return fmt.Errorf("aac: %w", err) 78 | } 79 | inputEmpty = true 80 | } 81 | 82 | if n < e.insize { 83 | inputEmpty = true 84 | } 85 | 86 | var outinfo aacenc.VoAudioOutputinfo 87 | var input, output aacenc.VoCodecBuffer 88 | 89 | input.Buffer = C.CBytes(e.inbuf) 90 | input.Length = uint64(n) 91 | 92 | ret := aacenc.SetInputData(&input) 93 | err = aacenc.ErrorFromResult(ret) 94 | if err != nil { 95 | return fmt.Errorf("aac: %w", err) 96 | } 97 | 98 | outputEmpty := false 99 | for !outputEmpty { 100 | output.Buffer = C.CBytes(e.outbuf) 101 | output.Length = uint64(len(e.outbuf)) 102 | 103 | ret = aacenc.GetOutputData(&output, &outinfo) 104 | err = aacenc.ErrorFromResult(ret) 105 | if err != nil { 106 | if !errors.Is(err, aacenc.ErrInputBufferSmall) { 107 | return fmt.Errorf("aac: %w", err) 108 | } 109 | outputEmpty = true 110 | } 111 | 112 | _, err = e.w.Write(C.GoBytes(output.Buffer, C.int(output.Length))) 113 | if err != nil { 114 | return fmt.Errorf("aac: %w", err) 115 | } 116 | C.free(output.Buffer) 117 | } 118 | 119 | C.free(input.Buffer) 120 | } 121 | 122 | return nil 123 | } 124 | 125 | // Close closes encoder. 126 | func (e *Encoder) Close() error { 127 | ret := aacenc.Uninit() 128 | return aacenc.ErrorFromResult(ret) 129 | } 130 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/bitbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: bitbuffer.h 18 | 19 | Content: Bit Buffer Management structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef BITBUFFER_H 24 | #define BITBUFFER_H 25 | 26 | #include "typedef.h" 27 | 28 | 29 | enum direction 30 | { 31 | forwardDirection, 32 | backwardDirection 33 | }; 34 | 35 | 36 | /*! 37 | The pointer 'pReadNext' points to the next available word, where bits can be read from. The pointer 38 | 'pWriteNext' points to the next available word, where bits can be written to. The pointer pBitBufBase 39 | points to the start of the bitstream buffer and the pointer pBitBufEnd points to the end of the bitstream 40 | buffer. The two pointers are used as lower-bound respectively upper-bound address for the modulo addressing 41 | mode. 42 | 43 | The element cntBits contains the currently available bits in the bit buffer. It will be incremented when 44 | bits are written to the bitstream buffer and decremented when bits are read from the bitstream buffer. 45 | */ 46 | struct BIT_BUF 47 | { 48 | UWord8 *pBitBufBase; /*!< pointer points to first position in bitstream buffer */ 49 | UWord8 *pBitBufEnd; /*!< pointer points to last position in bitstream buffer */ 50 | 51 | UWord8 *pWriteNext; /*!< pointer points to next available word in bitstream buffer to write */ 52 | 53 | UWord32 cache; 54 | 55 | Word16 wBitPos; /*!< 31<=wBitPos<=0*/ 56 | Word16 cntBits; /*!< number of available bits in the bitstream buffer 57 | write bits to bitstream buffer => increment cntBits 58 | read bits from bitstream buffer => decrement cntBits */ 59 | Word16 size; /*!< size of bitbuffer in bits */ 60 | Word16 isValid; /*!< indicates whether the instance has been initialized */ 61 | }; /* size Word16: 8 */ 62 | 63 | /*! Define pointer to bit buffer structure */ 64 | typedef struct BIT_BUF *HANDLE_BIT_BUF; 65 | 66 | 67 | HANDLE_BIT_BUF CreateBitBuffer(HANDLE_BIT_BUF hBitBuf, 68 | UWord8 *pBitBufBase, 69 | Word16 bitBufSize); 70 | 71 | 72 | void DeleteBitBuffer(HANDLE_BIT_BUF *hBitBuf); 73 | 74 | 75 | Word16 GetBitsAvail(HANDLE_BIT_BUF hBitBuf); 76 | 77 | 78 | Word16 WriteBits(HANDLE_BIT_BUF hBitBuf, 79 | UWord32 writeValue, 80 | Word16 noBitsToWrite); 81 | 82 | void ResetBitBuf(HANDLE_BIT_BUF hBitBuf, 83 | UWord8 *pBitBufBase, 84 | Word16 bitBufSize); 85 | 86 | #define GetNrBitsAvailable(hBitBuf) ( (hBitBuf)->cntBits) 87 | #define GetNrBitsRead(hBitBuf) ((hBitBuf)->size-(hBitBuf)->cntBits) 88 | 89 | #endif /* BITBUFFER_H */ 90 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/cmnMemory.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: cmnMemory.h 18 | 19 | Content: memory operator implementation header file 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __cmnMemory_H__ 24 | #define __cmnMemory_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voMem.h" 31 | 32 | //extern VO_MEM_OPERATOR g_memOP; 33 | 34 | /** 35 | * Allocate memory 36 | * \param uID [in] module ID 37 | * \param uSize [in] size of memory 38 | * \return value is the allocated memory address. NULL is failed. 39 | */ 40 | VO_U32 cmnMemAlloc (VO_S32 uID, VO_MEM_INFO * pMemInfo); 41 | 42 | /** 43 | * Free up memory 44 | * \param uID [in] module ID 45 | * \param pMem [in] address of memory 46 | * \return value 0, if succeeded. 47 | */ 48 | VO_U32 cmnMemFree (VO_S32 uID, VO_PTR pBuffer); 49 | 50 | /** 51 | * memory set function 52 | * \param uID [in] module ID 53 | * \param pBuff [in/out] address of memory 54 | * \param uValue [in] the value to be set 55 | * \param uSize [in] the size to be set 56 | * \return value 0, if succeeded. 57 | */ 58 | VO_U32 cmnMemSet (VO_S32 uID, VO_PTR pBuff, VO_U8 uValue, VO_U32 uSize); 59 | 60 | /** 61 | * memory copy function 62 | * \param uID [in] module ID 63 | * \param pDest [in/out] address of destination memory 64 | * \param pSource [in] address of source memory 65 | * \param uSize [in] the size to be copied 66 | * \return value 0, if succeeded. 67 | */ 68 | VO_U32 cmnMemCopy (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 69 | 70 | /** 71 | * memory check function 72 | * \param uID [in] module ID 73 | * \param pBuff [in] address of buffer to be checked 74 | * \param uSize [in] the size to be checked 75 | * \return value 0, if succeeded. 76 | */ 77 | VO_U32 cmnMemCheck (VO_S32 uID, VO_PTR pBuffer, VO_U32 uSize); 78 | 79 | /** 80 | * memory compare function 81 | * \param uID [in] module ID 82 | * \param pBuffer1 [in] address of buffer 1 to be compared 83 | * \param pBuffer2 [in] address of buffer 2 to be compared 84 | * \param uSize [in] the size to be compared 85 | * \return value: same as standard C run-time memcmp() function. 86 | */ 87 | VO_S32 cmnMemCompare (VO_S32 uID, VO_PTR pBuffer1, VO_PTR pBuffer2, VO_U32 uSize); 88 | 89 | /** 90 | * memory move function 91 | * \param uID [in] module ID 92 | * \param pDest [in/out] address of destination memory 93 | * \param pSource [in] address of source memory 94 | * \param uSize [in] the size to be moved 95 | * \return value 0, if succeeded. 96 | */ 97 | VO_U32 cmnMemMove (VO_S32 uID, VO_PTR pDest, VO_PTR pSource, VO_U32 uSize); 98 | 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif /* __cplusplus */ 103 | 104 | #endif // __cmnMemory_H__ 105 | 106 | 107 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/psy_configuration.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: psy_configuration.h 18 | 19 | Content: Psychoaccoustic configuration structure and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _PSY_CONFIGURATION_H 24 | #define _PSY_CONFIGURATION_H 25 | 26 | #include "typedefs.h" 27 | #include "psy_const.h" 28 | #include "tns.h" 29 | 30 | typedef struct{ 31 | 32 | Word16 sfbCnt; 33 | Word16 sfbActive; /* number of sf bands containing energy after lowpass */ 34 | const Word16 *sfbOffset; 35 | 36 | Word32 sfbThresholdQuiet[MAX_SFB_LONG]; 37 | 38 | Word16 maxAllowedIncreaseFactor; /* preecho control */ 39 | Word16 minRemainingThresholdFactor; 40 | 41 | Word16 lowpassLine; 42 | Word16 sampRateIdx; 43 | Word32 clipEnergy; /* for level dependend tmn */ 44 | 45 | Word16 ratio; 46 | Word16 sfbMaskLowFactor[MAX_SFB_LONG]; 47 | Word16 sfbMaskHighFactor[MAX_SFB_LONG]; 48 | 49 | Word16 sfbMaskLowFactorSprEn[MAX_SFB_LONG]; 50 | Word16 sfbMaskHighFactorSprEn[MAX_SFB_LONG]; 51 | 52 | 53 | Word16 sfbMinSnr[MAX_SFB_LONG]; /* minimum snr (formerly known as bmax) */ 54 | 55 | TNS_CONFIG tnsConf; 56 | 57 | }PSY_CONFIGURATION_LONG; /*Word16 size: 8 + 52 + 102 + 51 + 51 + 51 + 51 + 47 = 515 */ 58 | 59 | 60 | typedef struct{ 61 | 62 | Word16 sfbCnt; 63 | Word16 sfbActive; /* number of sf bands containing energy after lowpass */ 64 | const Word16 *sfbOffset; 65 | 66 | Word32 sfbThresholdQuiet[MAX_SFB_SHORT]; 67 | 68 | Word16 maxAllowedIncreaseFactor; /* preecho control */ 69 | Word16 minRemainingThresholdFactor; 70 | 71 | Word16 lowpassLine; 72 | Word16 sampRateIdx; 73 | Word32 clipEnergy; /* for level dependend tmn */ 74 | 75 | Word16 ratio; 76 | Word16 sfbMaskLowFactor[MAX_SFB_SHORT]; 77 | Word16 sfbMaskHighFactor[MAX_SFB_SHORT]; 78 | 79 | Word16 sfbMaskLowFactorSprEn[MAX_SFB_SHORT]; 80 | Word16 sfbMaskHighFactorSprEn[MAX_SFB_SHORT]; 81 | 82 | 83 | Word16 sfbMinSnr[MAX_SFB_SHORT]; /* minimum snr (formerly known as bmax) */ 84 | 85 | TNS_CONFIG tnsConf; 86 | 87 | }PSY_CONFIGURATION_SHORT; /*Word16 size: 8 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 47 = 167 */ 88 | 89 | 90 | /* Returns the sample rate index */ 91 | Word32 GetSRIndex(Word32 sampleRate); 92 | 93 | 94 | Word16 InitPsyConfigurationLong(Word32 bitrate, 95 | Word32 samplerate, 96 | Word16 bandwidth, 97 | PSY_CONFIGURATION_LONG *psyConf); 98 | 99 | Word16 InitPsyConfigurationShort(Word32 bitrate, 100 | Word32 samplerate, 101 | Word16 bandwidth, 102 | PSY_CONFIGURATION_SHORT *psyConf); 103 | 104 | #endif /* _PSY_CONFIGURATION_H */ 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/channel_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: channel_map.c 18 | 19 | Content: channel mapping functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "channel_map.h" 24 | #include "bitenc.h" 25 | #include "psy_const.h" 26 | #include "qc_data.h" 27 | 28 | static const Word16 maxChannelBits = MAXBITS_COEF; 29 | 30 | static Word16 initElement(ELEMENT_INFO* elInfo, ELEMENT_TYPE elType) 31 | { 32 | Word16 error=0; 33 | 34 | elInfo->elType=elType; 35 | 36 | switch(elInfo->elType) { 37 | 38 | case ID_SCE: 39 | elInfo->nChannelsInEl=1; 40 | 41 | elInfo->ChannelIndex[0]=0; 42 | 43 | elInfo->instanceTag=0; 44 | break; 45 | 46 | case ID_CPE: 47 | 48 | elInfo->nChannelsInEl=2; 49 | 50 | elInfo->ChannelIndex[0]=0; 51 | elInfo->ChannelIndex[1]=1; 52 | 53 | elInfo->instanceTag=0; 54 | break; 55 | 56 | default: 57 | error=1; 58 | } 59 | 60 | return error; 61 | } 62 | 63 | 64 | Word16 InitElementInfo (Word16 nChannels, ELEMENT_INFO* elInfo) 65 | { 66 | Word16 error; 67 | error = 0; 68 | 69 | switch(nChannels) { 70 | 71 | case 1: 72 | initElement(elInfo, ID_SCE); 73 | break; 74 | 75 | case 2: 76 | initElement(elInfo, ID_CPE); 77 | break; 78 | 79 | default: 80 | error=4; 81 | } 82 | 83 | return error; 84 | } 85 | 86 | 87 | Word16 InitElementBits(ELEMENT_BITS *elementBits, 88 | ELEMENT_INFO elInfo, 89 | Word32 bitrateTot, 90 | Word16 averageBitsTot, 91 | Word16 staticBitsTot) 92 | { 93 | Word16 error; 94 | error = 0; 95 | 96 | switch(elInfo.nChannelsInEl) { 97 | case 1: 98 | elementBits->chBitrate = bitrateTot; 99 | elementBits->averageBits = averageBitsTot - staticBitsTot; 100 | elementBits->maxBits = maxChannelBits; 101 | 102 | elementBits->maxBitResBits = maxChannelBits - averageBitsTot; 103 | elementBits->maxBitResBits = elementBits->maxBitResBits - (elementBits->maxBitResBits & 7); 104 | elementBits->bitResLevel = elementBits->maxBitResBits; 105 | elementBits->relativeBits = 0x4000; /* 1.0f/2 */ 106 | break; 107 | 108 | case 2: 109 | elementBits->chBitrate = bitrateTot >> 1; 110 | elementBits->averageBits = averageBitsTot - staticBitsTot; 111 | elementBits->maxBits = maxChannelBits << 1; 112 | 113 | elementBits->maxBitResBits = (maxChannelBits << 1) - averageBitsTot; 114 | elementBits->maxBitResBits = elementBits->maxBitResBits - (elementBits->maxBitResBits & 7); 115 | elementBits->bitResLevel = elementBits->maxBitResBits; 116 | elementBits->relativeBits = 0x4000; /* 1.0f/2 */ 117 | break; 118 | 119 | default: 120 | error = 1; 121 | } 122 | return error; 123 | } 124 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/band_nrg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: band_nrg.c 18 | 19 | Content: Band/Line energy calculations functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "band_nrg.h" 25 | 26 | #ifndef ARMV5E 27 | /******************************************************************************** 28 | * 29 | * function name: CalcBandEnergy 30 | * description: Calc sfb-bandwise mdct-energies for left and right channel 31 | * 32 | **********************************************************************************/ 33 | void CalcBandEnergy(const Word32 *mdctSpectrum, 34 | const Word16 *bandOffset, 35 | const Word16 numBands, 36 | Word32 *bandEnergy, 37 | Word32 *bandEnergySum) 38 | { 39 | Word32 i, j; 40 | Word32 accuSum = 0; 41 | 42 | for (i=0; i> 1; 83 | r = mdctSpectrumRight[j] >> 1; 84 | specm = l + r; 85 | specs = l - r; 86 | accuMid = L_add(accuMid, MULHIGH(specm, specm)); 87 | accuSide = L_add(accuSide, MULHIGH(specs, specs)); 88 | } 89 | 90 | accuMid = L_add(accuMid, accuMid); 91 | accuSide = L_add(accuSide, accuSide); 92 | bandEnergyMid[i] = accuMid; 93 | accuMidSum = L_add(accuMidSum, accuMid); 94 | bandEnergySide[i] = accuSide; 95 | accuSideSum = L_add(accuSideSum, accuSide); 96 | 97 | } 98 | *bandEnergyMidSum = accuMidSum; 99 | *bandEnergySideSum = accuSideSum; 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/pre_echo_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: pre_echo_control.c 18 | 19 | Content: Pre echo control functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "oper_32b.h" 25 | 26 | #include "oper_32b.h" 27 | #include "pre_echo_control.h" 28 | 29 | 30 | /***************************************************************************** 31 | * 32 | * function name:InitPreEchoControl 33 | * description: init pre echo control parameter 34 | * 35 | *****************************************************************************/ 36 | void InitPreEchoControl(Word32 *pbThresholdNm1, 37 | Word16 numPb, 38 | Word32 *pbThresholdQuiet) 39 | { 40 | Word16 pb; 41 | 42 | for(pb=0; pb 0 ) { 73 | for(i = 0; i < numPb; i++) { 74 | tmpThreshold1 = pbThresholdNm1[i] >> (scaling-1); 75 | tmpThreshold2 = L_mpy_ls(pbThreshold[i], minRemainingThresholdFactor); 76 | 77 | /* copy thresholds to internal memory */ 78 | pbThresholdNm1[i] = pbThreshold[i]; 79 | 80 | 81 | if(pbThreshold[i] > tmpThreshold1) { 82 | pbThreshold[i] = tmpThreshold1; 83 | } 84 | 85 | if(tmpThreshold2 > pbThreshold[i]) { 86 | pbThreshold[i] = tmpThreshold2; 87 | } 88 | 89 | } 90 | } 91 | else { 92 | scaling = -scaling; 93 | for(i = 0; i < numPb; i++) { 94 | 95 | tmpThreshold1 = pbThresholdNm1[i] << 1; 96 | tmpThreshold2 = L_mpy_ls(pbThreshold[i], minRemainingThresholdFactor); 97 | 98 | /* copy thresholds to internal memory */ 99 | pbThresholdNm1[i] = pbThreshold[i]; 100 | 101 | 102 | if(((pbThreshold[i] >> scaling) > tmpThreshold1)) { 103 | pbThreshold[i] = tmpThreshold1 << scaling; 104 | } 105 | 106 | if(tmpThreshold2 > pbThreshold[i]) { 107 | pbThreshold[i] = tmpThreshold2; 108 | } 109 | 110 | } 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: interface.h 18 | 19 | Content: psychoaccoustic/quantizer structures and interface 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _INTERFACE_H 24 | #define _INTERFACE_H 25 | 26 | #include "config.h" 27 | #include "psy_const.h" 28 | #include "psy_data.h" 29 | #include "typedefs.h" 30 | 31 | 32 | enum 33 | { 34 | MS_NONE = 0, 35 | MS_SOME = 1, 36 | MS_ALL = 2 37 | }; 38 | 39 | enum 40 | { 41 | MS_ON = 1 42 | }; 43 | 44 | struct TOOLSINFO { 45 | Word16 msDigest; 46 | Word16 msMask[MAX_GROUPED_SFB]; 47 | }; 48 | 49 | 50 | typedef struct { 51 | Word16 sfbCnt; 52 | Word16 sfbPerGroup; 53 | Word16 maxSfbPerGroup; 54 | Word16 windowSequence; 55 | Word16 windowShape; 56 | Word16 groupingMask; 57 | Word16 sfbOffsets[MAX_GROUPED_SFB+1]; 58 | Word16 mdctScale; 59 | Word32 *sfbEnergy; 60 | Word32 *sfbSpreadedEnergy; 61 | Word32 *sfbThreshold; 62 | Word32 *mdctSpectrum; 63 | Word32 sfbEnSumLR; 64 | Word32 sfbEnSumMS; 65 | Word32 sfbDist[MAX_GROUPED_SFB]; 66 | Word32 sfbDistNew[MAX_GROUPED_SFB]; 67 | Word16 sfbMinSnr[MAX_GROUPED_SFB]; 68 | Word16 minSfMaxQuant[MAX_GROUPED_SFB]; 69 | Word16 minScfCalculated[MAX_GROUPED_SFB]; 70 | Word16 prevScfLast[MAX_GROUPED_SFB]; 71 | Word16 prevScfNext[MAX_GROUPED_SFB]; 72 | Word16 deltaPeLast[MAX_GROUPED_SFB]; 73 | TNS_INFO tnsInfo; 74 | } PSY_OUT_CHANNEL; /* Word16 size: 14 + 60(MAX_GROUPED_SFB) + 112(TNS_INFO) = 186 */ 75 | 76 | typedef struct { 77 | struct TOOLSINFO toolsInfo; 78 | Word16 groupedSfbOffset[MAX_CHANNELS][MAX_GROUPED_SFB+1]; /* plus one for last dummy offset ! */ 79 | Word16 groupedSfbMinSnr[MAX_CHANNELS][MAX_GROUPED_SFB]; 80 | } PSY_OUT_ELEMENT; 81 | 82 | typedef struct { 83 | /* information shared by both channels */ 84 | PSY_OUT_ELEMENT psyOutElement; 85 | /* information specific to each channel */ 86 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS]; 87 | }PSY_OUT; 88 | 89 | void BuildInterface(Word32 *mdctSpectrum, 90 | const Word16 mdctScale, 91 | SFB_THRESHOLD *sfbThreshold, 92 | SFB_ENERGY *sfbEnergy, 93 | SFB_ENERGY *sfbSpreadedEnergy, 94 | const SFB_ENERGY_SUM sfbEnergySumLR, 95 | const SFB_ENERGY_SUM sfbEnergySumMS, 96 | const Word16 windowSequence, 97 | const Word16 windowShape, 98 | const Word16 sfbCnt, 99 | const Word16 *sfbOffset, 100 | const Word16 maxSfbPerGroup, 101 | const Word16 *groupedSfbMinSnr, 102 | const Word16 noOfGroups, 103 | const Word16 *groupLen, 104 | PSY_OUT_CHANNEL *psyOutCh); 105 | 106 | #endif /* _INTERFACE_H */ 107 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/aac_rom.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: aac_rom.h 18 | 19 | Content: constant tables 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef ROM_H 24 | #define ROM_H 25 | 26 | #include "config.h" 27 | #include "psy_const.h" 28 | #include "tns_param.h" 29 | 30 | /* 31 | mdct 32 | */ 33 | extern const int ShortWindowSine[FRAME_LEN_SHORT/2]; 34 | extern const int LongWindowKBD[FRAME_LEN_LONG/2]; 35 | 36 | extern const unsigned char bitrevTab[17 + 129]; 37 | extern const int cossintab[128 + 1024]; 38 | 39 | #if defined (ARMV5E) && !defined (ARMV7Neon) 40 | extern const int twidTab64[(4*6 + 16*6)/2]; 41 | extern const int twidTab512[(8*6 + 32*6 + 128*6)/2]; 42 | #else 43 | extern const int twidTab64[4*6 + 16*6]; 44 | extern const int twidTab512[8*6 + 32*6 + 128*6]; 45 | #endif 46 | 47 | /* 48 | form factor 49 | */ 50 | extern const Word32 formfac_sqrttable[96]; 51 | 52 | /* 53 | quantizer 54 | */ 55 | extern const Word32 mTab_3_4[512]; 56 | extern const Word32 mTab_4_3[512]; 57 | /*! $2^{-\frac{n}{16}}$ table */ 58 | extern const Word16 pow2tominusNover16[17] ; 59 | 60 | extern const Word32 specExpMantTableComb_enc[4][14]; 61 | extern const UWord8 specExpTableComb_enc[4][14]; 62 | 63 | extern const Word16 quantBorders[4][4]; 64 | //extern const Word16 quantRecon[3][4]; 65 | extern const Word16 quantRecon[4][3]; 66 | 67 | /* 68 | huffman 69 | */ 70 | extern const UWord16 huff_ltab1_2[3][3][3][3]; 71 | extern const UWord16 huff_ltab3_4[3][3][3][3]; 72 | extern const UWord16 huff_ltab5_6[9][9]; 73 | extern const UWord16 huff_ltab7_8[8][8]; 74 | extern const UWord16 huff_ltab9_10[13][13]; 75 | extern const UWord16 huff_ltab11[17][17]; 76 | extern const UWord16 huff_ltabscf[121]; 77 | extern const UWord16 huff_ctab1[3][3][3][3]; 78 | extern const UWord16 huff_ctab2[3][3][3][3]; 79 | extern const UWord16 huff_ctab3[3][3][3][3]; 80 | extern const UWord16 huff_ctab4[3][3][3][3]; 81 | extern const UWord16 huff_ctab5[9][9]; 82 | extern const UWord16 huff_ctab6[9][9]; 83 | extern const UWord16 huff_ctab7[8][8]; 84 | extern const UWord16 huff_ctab8[8][8]; 85 | extern const UWord16 huff_ctab9[13][13]; 86 | extern const UWord16 huff_ctab10[13][13]; 87 | extern const UWord16 huff_ctab11[17][17]; 88 | extern const UWord32 huff_ctabscf[121]; 89 | 90 | 91 | 92 | /* 93 | misc 94 | */ 95 | extern const int sampRateTab[NUM_SAMPLE_RATES]; 96 | extern const int BandwithCoefTab[8][NUM_SAMPLE_RATES]; 97 | extern const int rates[8]; 98 | extern const UWord8 sfBandTotalShort[NUM_SAMPLE_RATES]; 99 | extern const UWord8 sfBandTotalLong[NUM_SAMPLE_RATES]; 100 | extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES]; 101 | extern const short sfBandTabShort[76]; 102 | extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES]; 103 | extern const short sfBandTabLong[325]; 104 | 105 | extern const Word32 m_log2_table[INT_BITS]; 106 | 107 | /* 108 | TNS 109 | */ 110 | extern const Word32 tnsCoeff3[8]; 111 | extern const Word32 tnsCoeff3Borders[8]; 112 | extern const Word32 tnsCoeff4[16]; 113 | extern const Word32 tnsCoeff4Borders[16]; 114 | extern const Word32 invSBF[24]; 115 | extern const Word16 sideInfoTabLong[MAX_SFB_LONG + 1]; 116 | extern const Word16 sideInfoTabShort[MAX_SFB_SHORT + 1]; 117 | #endif 118 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: interface.c 18 | 19 | Content: Interface psychoaccoustic/quantizer functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "oper_32b.h" 25 | #include "psy_const.h" 26 | #include "interface.h" 27 | 28 | /***************************************************************************** 29 | * 30 | * function name: BuildInterface 31 | * description: update output parameter 32 | * 33 | **********************************************************************************/ 34 | void BuildInterface(Word32 *groupedMdctSpectrum, 35 | const Word16 mdctScale, 36 | SFB_THRESHOLD *groupedSfbThreshold, 37 | SFB_ENERGY *groupedSfbEnergy, 38 | SFB_ENERGY *groupedSfbSpreadedEnergy, 39 | const SFB_ENERGY_SUM sfbEnergySumLR, 40 | const SFB_ENERGY_SUM sfbEnergySumMS, 41 | const Word16 windowSequence, 42 | const Word16 windowShape, 43 | const Word16 groupedSfbCnt, 44 | const Word16 *groupedSfbOffset, 45 | const Word16 maxSfbPerGroup, 46 | const Word16 *groupedSfbMinSnr, 47 | const Word16 noOfGroups, 48 | const Word16 *groupLen, 49 | PSY_OUT_CHANNEL *psyOutCh) 50 | { 51 | Word32 j; 52 | Word32 grp; 53 | Word32 mask; 54 | Word16 *tmpV; 55 | 56 | /* 57 | copy values to psyOut 58 | */ 59 | psyOutCh->maxSfbPerGroup = maxSfbPerGroup; 60 | psyOutCh->sfbCnt = groupedSfbCnt; 61 | if(noOfGroups) 62 | psyOutCh->sfbPerGroup = groupedSfbCnt/ noOfGroups; 63 | else 64 | psyOutCh->sfbPerGroup = 0x7fff; 65 | psyOutCh->windowSequence = windowSequence; 66 | psyOutCh->windowShape = windowShape; 67 | psyOutCh->mdctScale = mdctScale; 68 | psyOutCh->mdctSpectrum = groupedMdctSpectrum; 69 | psyOutCh->sfbEnergy = groupedSfbEnergy->sfbLong; 70 | psyOutCh->sfbThreshold = groupedSfbThreshold->sfbLong; 71 | psyOutCh->sfbSpreadedEnergy = groupedSfbSpreadedEnergy->sfbLong; 72 | 73 | tmpV = psyOutCh->sfbOffsets; 74 | for(j=0; jsfbMinSnr; 79 | for(j=0;jgroupingMask = mask; 93 | 94 | if (windowSequence != SHORT_WINDOW) { 95 | psyOutCh->sfbEnSumLR = sfbEnergySumLR.sfbLong; 96 | psyOutCh->sfbEnSumMS = sfbEnergySumMS.sfbLong; 97 | } 98 | else { 99 | Word32 i; 100 | Word32 accuSumMS=0; 101 | Word32 accuSumLR=0; 102 | const Word32 *pSumMS = sfbEnergySumMS.sfbShort; 103 | const Word32 *pSumLR = sfbEnergySumLR.sfbShort; 104 | 105 | for (i=TRANS_FAC; i; i--) { 106 | accuSumLR = L_add(accuSumLR, *pSumLR); pSumLR++; 107 | accuSumMS = L_add(accuSumMS, *pSumMS); pSumMS++; 108 | } 109 | psyOutCh->sfbEnSumMS = accuSumMS; 110 | psyOutCh->sfbEnSumLR = accuSumLR; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/qc_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: qc_data.h 18 | 19 | Content: Quantizing & coding structures 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _QC_DATA_H 24 | #define _QC_DATA_H 25 | 26 | #include "psy_const.h" 27 | #include "dyn_bits.h" 28 | #include "adj_thr_data.h" 29 | 30 | 31 | #define MAX_MODES 10 32 | 33 | typedef enum { 34 | MODE_INVALID = 0, 35 | MODE_1, /* mono */ 36 | MODE_1_1, /* dual mono */ 37 | MODE_2 /* stereo */ 38 | } ENCODER_MODE; 39 | 40 | typedef enum { 41 | ID_SCE=0, /* Single Channel Element */ 42 | ID_CPE=1, /* Channel Pair Element */ 43 | ID_CCE=2, /* Coupling Channel Element */ 44 | ID_LFE=3, /* LFE Channel Element */ 45 | ID_DSE=4, /* current one DSE element for ancillary is supported */ 46 | ID_PCE=5, 47 | ID_FIL=6, 48 | ID_END=7 49 | }ELEMENT_TYPE; 50 | 51 | typedef struct { 52 | ELEMENT_TYPE elType; 53 | Word16 instanceTag; 54 | Word16 nChannelsInEl; 55 | Word16 ChannelIndex[MAX_CHANNELS]; 56 | } ELEMENT_INFO; 57 | 58 | typedef struct { 59 | Word32 paddingRest; 60 | } PADDING; 61 | 62 | 63 | /* Quantizing & coding stage */ 64 | 65 | struct QC_INIT{ 66 | ELEMENT_INFO *elInfo; 67 | Word16 maxBits; /* maximum number of bits in reservoir */ 68 | Word16 averageBits; /* average number of bits we should use */ 69 | Word16 bitRes; 70 | Word16 meanPe; 71 | Word32 chBitrate; 72 | Word16 maxBitFac; 73 | Word32 bitrate; 74 | 75 | PADDING padding; 76 | }; 77 | 78 | typedef struct 79 | { 80 | Word16 *quantSpec; /* [FRAME_LEN_LONG]; */ 81 | UWord16 *maxValueInSfb; /* [MAX_GROUPED_SFB]; */ 82 | Word16 *scf; /* [MAX_GROUPED_SFB]; */ 83 | Word16 globalGain; 84 | Word16 mdctScale; 85 | Word16 groupingMask; 86 | SECTION_DATA sectionData; 87 | Word16 windowShape; 88 | } QC_OUT_CHANNEL; 89 | 90 | typedef struct 91 | { 92 | Word16 adtsUsed; 93 | Word16 staticBitsUsed; /* for verification purposes */ 94 | Word16 dynBitsUsed; /* for verification purposes */ 95 | Word16 pe; 96 | Word16 ancBitsUsed; 97 | Word16 fillBits; 98 | } QC_OUT_ELEMENT; 99 | 100 | typedef struct 101 | { 102 | QC_OUT_CHANNEL qcChannel[MAX_CHANNELS]; 103 | QC_OUT_ELEMENT qcElement; 104 | Word16 totStaticBitsUsed; /* for verification purposes */ 105 | Word16 totDynBitsUsed; /* for verification purposes */ 106 | Word16 totAncBitsUsed; /* for verification purposes */ 107 | Word16 totFillBits; 108 | Word16 alignBits; 109 | Word16 bitResTot; 110 | Word16 averageBitsTot; 111 | } QC_OUT; 112 | 113 | typedef struct { 114 | Word32 chBitrate; 115 | Word16 averageBits; /* brutto -> look ancillary.h */ 116 | Word16 maxBits; 117 | Word16 bitResLevel; 118 | Word16 maxBitResBits; 119 | Word16 relativeBits; /* Bits relative to total Bits scaled down by 2 */ 120 | } ELEMENT_BITS; 121 | 122 | typedef struct 123 | { 124 | /* this is basically struct QC_INIT */ 125 | Word16 averageBitsTot; 126 | Word16 maxBitsTot; 127 | Word16 globStatBits; 128 | Word16 nChannels; 129 | Word16 bitResTot; 130 | 131 | Word16 maxBitFac; 132 | 133 | PADDING padding; 134 | 135 | ELEMENT_BITS elementBits; 136 | ADJ_THR_STATE adjThr; 137 | 138 | Word16 logSfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB]; 139 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB]; 140 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB]; 141 | } QC_STATE; 142 | 143 | #endif /* _QC_DATA_H */ 144 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/aacenc_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: aacenc_core.h 18 | 19 | Content: aac encoder interface functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef _aacenc_core_h_ 24 | #define _aacenc_core_h_ 25 | 26 | 27 | #include "typedef.h" 28 | #include "config.h" 29 | #include "bitenc.h" 30 | 31 | #include "psy_configuration.h" 32 | #include "psy_main.h" 33 | #include "qc_main.h" 34 | #include "psy_main.h" 35 | /*-------------------------- defines --------------------------------------*/ 36 | 37 | 38 | /*-------------------- structure definitions ------------------------------*/ 39 | typedef struct { 40 | Word32 sampleRate; /* audio file sample rate */ 41 | Word32 bitRate; /* encoder bit rate in bits/sec */ 42 | Word16 nChannelsIn; /* number of channels on input (1,2) */ 43 | Word16 nChannelsOut; /* number of channels on output (1,2) */ 44 | Word16 bandWidth; /* targeted audio bandwidth in Hz */ 45 | Word16 adtsUsed; /* whether write adts header */ 46 | } AACENC_CONFIG; 47 | 48 | 49 | typedef struct { 50 | 51 | AACENC_CONFIG config; /* Word16 size: 8 */ 52 | 53 | ELEMENT_INFO elInfo; /* Word16 size: 4 */ 54 | 55 | QC_STATE qcKernel; /* Word16 size: 6 + 5(PADDING) + 7(ELEMENT_BITS) + 54(ADJ_THR_STATE) = 72 */ 56 | QC_OUT qcOut; /* Word16 size: MAX_CHANNELS*920(QC_OUT_CHANNEL) + 5(QC_OUT_ELEMENT) + 7 = 932 / 1852 */ 57 | 58 | PSY_OUT psyOut; /* Word16 size: MAX_CHANNELS*186 + 2 = 188 / 374 */ 59 | PSY_KERNEL psyKernel; /* Word16 size: 2587 / 4491 */ 60 | 61 | struct BITSTREAMENCODER_INIT bseInit; /* Word16 size: 6 */ 62 | struct BIT_BUF bitStream; /* Word16 size: 8 */ 63 | HANDLE_BIT_BUF hBitStream; 64 | int initOK; 65 | 66 | short *intbuf; 67 | short *encbuf; 68 | short *inbuf; 69 | int enclen; 70 | int inlen; 71 | int intlen; 72 | int uselength; 73 | 74 | void *hCheck; 75 | VO_MEM_OPERATOR *voMemop; 76 | VO_MEM_OPERATOR voMemoprator; 77 | 78 | }AAC_ENCODER; /* Word16 size: 3809 / 6851 */ 79 | 80 | /*----------------------------------------------------------------------------- 81 | 82 | functionname: AacInitDefaultConfig 83 | description: gives reasonable default configuration 84 | returns: --- 85 | 86 | ------------------------------------------------------------------------------*/ 87 | void AacInitDefaultConfig(AACENC_CONFIG *config); 88 | 89 | /*--------------------------------------------------------------------------- 90 | 91 | functionname:AacEncOpen 92 | description: allocate and initialize a new encoder instance 93 | returns: AACENC_OK if success 94 | 95 | ---------------------------------------------------------------------------*/ 96 | 97 | Word16 AacEncOpen (AAC_ENCODER *hAacEnc, /* pointer to an encoder handle, initialized on return */ 98 | const AACENC_CONFIG config); /* pre-initialized config struct */ 99 | 100 | Word16 AacEncEncode(AAC_ENCODER *hAacEnc, 101 | Word16 *timeSignal, 102 | const UWord8 *ancBytes, /*!< pointer to ancillary data bytes */ 103 | Word16 *numAncBytes, /*!< number of ancillary Data Bytes, send as fill element */ 104 | UWord8 *outBytes, /*!< pointer to output buffer */ 105 | VO_U32 *numOutBytes /*!< number of bytes in output buffer */ 106 | ); 107 | 108 | /*--------------------------------------------------------------------------- 109 | 110 | functionname:AacEncClose 111 | description: deallocate an encoder instance 112 | 113 | ---------------------------------------------------------------------------*/ 114 | 115 | void AacEncClose (AAC_ENCODER* hAacEnc, VO_MEM_OPERATOR *pMemOP); /* an encoder handle */ 116 | 117 | #endif /* _aacenc_h_ */ 118 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/bitbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: bitbuffer.c 18 | 19 | Content: Bit Buffer Management functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "bitbuffer.h" 24 | 25 | /***************************************************************************** 26 | * 27 | * function name: CreateBitBuffer 28 | * description: create and init Bit Buffer Management 29 | * 30 | *****************************************************************************/ 31 | HANDLE_BIT_BUF CreateBitBuffer(HANDLE_BIT_BUF hBitBuf, 32 | UWord8 *pBitBufBase, 33 | Word16 bitBufSize) 34 | { 35 | assert(bitBufSize*8 <= 32768); 36 | 37 | hBitBuf->pBitBufBase = pBitBufBase; 38 | hBitBuf->pBitBufEnd = pBitBufBase + bitBufSize - 1; 39 | 40 | hBitBuf->pWriteNext = pBitBufBase; 41 | 42 | hBitBuf->cache = 0; 43 | 44 | hBitBuf->wBitPos = 0; 45 | hBitBuf->cntBits = 0; 46 | 47 | hBitBuf->size = (bitBufSize << 3); 48 | hBitBuf->isValid = 1; 49 | 50 | return hBitBuf; 51 | } 52 | 53 | /***************************************************************************** 54 | * 55 | * function name: DeleteBitBuffer 56 | * description: uninit Bit Buffer Management 57 | * 58 | *****************************************************************************/ 59 | void DeleteBitBuffer(HANDLE_BIT_BUF *hBitBuf) 60 | { 61 | if(*hBitBuf) 62 | (*hBitBuf)->isValid = 0; 63 | *hBitBuf = NULL; 64 | } 65 | 66 | /***************************************************************************** 67 | * 68 | * function name: ResetBitBuf 69 | * description: reset Bit Buffer Management 70 | * 71 | *****************************************************************************/ 72 | void ResetBitBuf(HANDLE_BIT_BUF hBitBuf, 73 | UWord8 *pBitBufBase, 74 | Word16 bitBufSize) 75 | { 76 | hBitBuf->pBitBufBase = pBitBufBase; 77 | hBitBuf->pBitBufEnd = pBitBufBase + bitBufSize - 1; 78 | 79 | 80 | hBitBuf->pWriteNext = pBitBufBase; 81 | 82 | hBitBuf->wBitPos = 0; 83 | hBitBuf->cntBits = 0; 84 | 85 | hBitBuf->cache = 0; 86 | } 87 | 88 | /***************************************************************************** 89 | * 90 | * function name: CopyBitBuf 91 | * description: copy Bit Buffer Management 92 | * 93 | *****************************************************************************/ 94 | void CopyBitBuf(HANDLE_BIT_BUF hBitBufSrc, 95 | HANDLE_BIT_BUF hBitBufDst) 96 | { 97 | *hBitBufDst = *hBitBufSrc; 98 | } 99 | 100 | /***************************************************************************** 101 | * 102 | * function name: GetBitsAvail 103 | * description: get available bits 104 | * 105 | *****************************************************************************/ 106 | Word16 GetBitsAvail(HANDLE_BIT_BUF hBitBuf) 107 | { 108 | return hBitBuf->cntBits; 109 | } 110 | 111 | /***************************************************************************** 112 | * 113 | * function name: WriteBits 114 | * description: write bits to the buffer 115 | * 116 | *****************************************************************************/ 117 | Word16 WriteBits(HANDLE_BIT_BUF hBitBuf, 118 | UWord32 writeValue, 119 | Word16 noBitsToWrite) 120 | { 121 | Word16 wBitPos; 122 | 123 | assert(noBitsToWrite <= (Word16)sizeof(Word32)*8); 124 | 125 | if(noBitsToWrite == 0) 126 | return noBitsToWrite; 127 | 128 | hBitBuf->cntBits += noBitsToWrite; 129 | 130 | wBitPos = hBitBuf->wBitPos; 131 | wBitPos += noBitsToWrite; 132 | writeValue &= ~(0xffffffff << noBitsToWrite); // Mask out everything except the lowest noBitsToWrite bits 133 | writeValue <<= 32 - wBitPos; 134 | writeValue |= hBitBuf->cache; 135 | 136 | while (wBitPos >= 8) 137 | { 138 | UWord8 tmp; 139 | tmp = (UWord8)((writeValue >> 24) & 0xFF); 140 | 141 | *hBitBuf->pWriteNext++ = tmp; 142 | writeValue <<= 8; 143 | wBitPos -= 8; 144 | } 145 | 146 | hBitBuf->wBitPos = wBitPos; 147 | hBitBuf->cache = writeValue; 148 | 149 | return noBitsToWrite; 150 | } 151 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/ms_stereo.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: ms_stereo.c 18 | 19 | Content: MS stereo processing function 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "oper_32b.h" 25 | #include "psy_const.h" 26 | #include "ms_stereo.h" 27 | 28 | 29 | /******************************************************************************** 30 | * 31 | * function name: MsStereoProcessing 32 | * description: detect use ms stereo or not 33 | * if ((min(thrLn, thrRn)*min(thrLn, thrRn))/(enMn*enSn)) 34 | * >= ((thrLn *thrRn)/(enLn*enRn)) then ms stereo 35 | * 36 | **********************************************************************************/ 37 | void MsStereoProcessing(Word32 *sfbEnergyLeft, 38 | Word32 *sfbEnergyRight, 39 | const Word32 *sfbEnergyMid, 40 | const Word32 *sfbEnergySide, 41 | Word32 *mdctSpectrumLeft, 42 | Word32 *mdctSpectrumRight, 43 | Word32 *sfbThresholdLeft, 44 | Word32 *sfbThresholdRight, 45 | Word32 *sfbSpreadedEnLeft, 46 | Word32 *sfbSpreadedEnRight, 47 | Word16 *msDigest, 48 | Word16 *msMask, 49 | const Word16 sfbCnt, 50 | const Word16 sfbPerGroup, 51 | const Word16 maxSfbPerGroup, 52 | const Word16 *sfbOffset) { 53 | Word32 sfb,sfboffs, j; 54 | Word32 msMaskTrueSomewhere = 0; 55 | Word32 msMaskFalseSomewhere = 0; 56 | 57 | for (sfb=0; sfb> 8) + 1); 98 | 99 | temp = pnms - pnlr; 100 | if( temp > 0 ){ 101 | 102 | msMask[idx] = 1; 103 | msMaskTrueSomewhere = 1; 104 | 105 | for (j=sfbOffset[idx]; j> 1); 108 | right = (mdctSpectrumRight[j] >> 1); 109 | mdctSpectrumLeft[j] = left + right; 110 | mdctSpectrumRight[j] = left - right; 111 | } 112 | 113 | sfbThresholdLeft[idx] = minThreshold; 114 | sfbThresholdRight[idx] = minThreshold; 115 | sfbEnergyLeft[idx] = sfbEnergyMid[idx]; 116 | sfbEnergyRight[idx] = sfbEnergySide[idx]; 117 | 118 | sfbSpreadedEnRight[idx] = min(sfbSpreadedEnLeft[idx],sfbSpreadedEnRight[idx]) >> 1; 119 | sfbSpreadedEnLeft[idx] = sfbSpreadedEnRight[idx]; 120 | 121 | } 122 | else { 123 | msMask[idx] = 0; 124 | msMaskFalseSomewhere = 1; 125 | } 126 | } 127 | if ( msMaskTrueSomewhere ) { 128 | if(msMaskFalseSomewhere ) { 129 | *msDigest = SI_MS_MASK_SOME; 130 | } else { 131 | *msDigest = SI_MS_MASK_ALL; 132 | } 133 | } else { 134 | *msDigest = SI_MS_MASK_NONE; 135 | } 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/line_pe.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: line_pe.c 18 | 19 | Content: Perceptual entropie module functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "oper_32b.h" 25 | #include "typedef.h" 26 | #include "line_pe.h" 27 | 28 | 29 | static const Word16 C1_I = 12; /* log(8.0)/log(2) *4 */ 30 | static const Word32 C2_I = 10830; /* log(2.5)/log(2) * 1024 * 4 * 2 */ 31 | static const Word16 C3_I = 573; /* (1-C2/C1) *1024 */ 32 | 33 | 34 | /***************************************************************************** 35 | * 36 | * function name: prepareSfbPe 37 | * description: constants that do not change during successive pe calculations 38 | * 39 | **********************************************************************************/ 40 | void prepareSfbPe(PE_DATA *peData, 41 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 42 | Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB], 43 | Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], 44 | const Word16 nChannels, 45 | const Word16 peOffset) 46 | { 47 | Word32 sfbGrp, sfb; 48 | Word32 ch; 49 | 50 | for(ch=0; chpeChannelData[ch]; 53 | for(sfbGrp=0;sfbGrpsfbCnt; sfbGrp+=psyOutChan->sfbPerGroup){ 54 | for (sfb=0; sfbmaxSfbPerGroup; sfb++) { 55 | peChanData->sfbNLines4[sfbGrp+sfb] = sfbNRelevantLines[ch][sfbGrp+sfb]; 56 | sfbNRelevantLines[ch][sfbGrp+sfb] = sfbNRelevantLines[ch][sfbGrp+sfb] >> 2; 57 | peChanData->sfbLdEnergy[sfbGrp+sfb] = logSfbEnergy[ch][sfbGrp+sfb]; 58 | } 59 | } 60 | } 61 | peData->offset = peOffset; 62 | } 63 | 64 | 65 | /***************************************************************************** 66 | * 67 | * function name: calcSfbPe 68 | * description: constPart is sfbPe without the threshold part n*ld(thr) or n*C3*ld(thr) 69 | * 70 | **********************************************************************************/ 71 | void calcSfbPe(PE_DATA *peData, 72 | PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 73 | const Word16 nChannels) 74 | { 75 | Word32 ch; 76 | Word32 sfbGrp, sfb; 77 | Word32 nLines4; 78 | Word32 ldThr, ldRatio; 79 | Word32 pe, constPart, nActiveLines; 80 | 81 | peData->pe = peData->offset; 82 | peData->constPart = 0; 83 | peData->nActiveLines = 0; 84 | for(ch=0; chpeChannelData[ch]; 87 | const Word32 *sfbEnergy = psyOutChan->sfbEnergy; 88 | const Word32 *sfbThreshold = psyOutChan->sfbThreshold; 89 | 90 | pe = 0; 91 | constPart = 0; 92 | nActiveLines = 0; 93 | 94 | for(sfbGrp=0; sfbGrpsfbCnt; sfbGrp+=psyOutChan->sfbPerGroup) { 95 | for (sfb=0; sfbmaxSfbPerGroup; sfb++) { 96 | Word32 nrg = sfbEnergy[sfbGrp+sfb]; 97 | Word32 thres = sfbThreshold[sfbGrp+sfb]; 98 | Word32 sfbLDEn = peChanData->sfbLdEnergy[sfbGrp+sfb]; 99 | 100 | if (nrg > thres) { 101 | ldThr = iLog4(thres); 102 | 103 | ldRatio = sfbLDEn - ldThr; 104 | 105 | nLines4 = peChanData->sfbNLines4[sfbGrp+sfb]; 106 | 107 | /* sfbPe = nl*log2(en/thr)*/ 108 | if (ldRatio >= C1_I) { 109 | peChanData->sfbPe[sfbGrp+sfb] = (nLines4*ldRatio + 8) >> 4; 110 | peChanData->sfbConstPart[sfbGrp+sfb] = ((nLines4*sfbLDEn)) >> 4; 111 | } 112 | else { 113 | /* sfbPe = nl*(c2 + c3*log2(en/thr))*/ 114 | peChanData->sfbPe[sfbGrp+sfb] = extract_l((L_mpy_wx( 115 | (C2_I + C3_I * ldRatio * 2) << 4, nLines4) + 4) >> 3); 116 | peChanData->sfbConstPart[sfbGrp+sfb] = extract_l(( L_mpy_wx( 117 | (C2_I + C3_I * sfbLDEn * 2) << 4, nLines4) + 4) >> 3); 118 | nLines4 = (nLines4 * C3_I + (1024<<1)) >> 10; 119 | } 120 | peChanData->sfbNActiveLines[sfbGrp+sfb] = nLines4 >> 2; 121 | } 122 | else { 123 | peChanData->sfbPe[sfbGrp+sfb] = 0; 124 | peChanData->sfbConstPart[sfbGrp+sfb] = 0; 125 | peChanData->sfbNActiveLines[sfbGrp+sfb] = 0; 126 | } 127 | pe = pe + peChanData->sfbPe[sfbGrp+sfb]; 128 | constPart = constPart + peChanData->sfbConstPart[sfbGrp+sfb]; 129 | nActiveLines = nActiveLines + peChanData->sfbNActiveLines[sfbGrp+sfb]; 130 | } 131 | } 132 | 133 | peChanData->pe = saturate(pe); 134 | peChanData->constPart = saturate(constPart); 135 | peChanData->nActiveLines = saturate(nActiveLines); 136 | 137 | 138 | pe += peData->pe; 139 | peData->pe = saturate(pe); 140 | constPart += peData->constPart; 141 | peData->constPart = saturate(constPart); 142 | nActiveLines += peData->nActiveLines; 143 | peData->nActiveLines = saturate(nActiveLines); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/grp_data.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: grp_data.c 18 | 19 | Content: Short block grouping function 20 | 21 | *******************************************************************************/ 22 | 23 | #include "basic_op.h" 24 | #include "psy_const.h" 25 | #include "interface.h" 26 | #include "grp_data.h" 27 | 28 | /***************************************************************************** 29 | * 30 | * function name: groupShortData 31 | * description: group short data for next quantization and coding 32 | * 33 | **********************************************************************************/ 34 | void 35 | groupShortData(Word32 *mdctSpectrum, 36 | Word32 *tmpSpectrum, 37 | SFB_THRESHOLD *sfbThreshold, 38 | SFB_ENERGY *sfbEnergy, 39 | SFB_ENERGY *sfbEnergyMS, 40 | SFB_ENERGY *sfbSpreadedEnergy, 41 | const Word16 sfbCnt, 42 | const Word16 *sfbOffset, 43 | const Word16 *sfbMinSnr, 44 | Word16 *groupedSfbOffset, 45 | Word16 *maxSfbPerGroup, 46 | Word16 *groupedSfbMinSnr, 47 | const Word16 noOfGroups, 48 | const Word16 *groupLen) 49 | { 50 | Word32 i, j; 51 | Word32 line; 52 | Word32 sfb; 53 | Word32 grp; 54 | Word32 wnd; 55 | Word32 offset; 56 | Word32 highestSfb; 57 | 58 | /* for short: regroup and */ 59 | /* cumulate energies und thresholds group-wise . */ 60 | 61 | /* calculate sfbCnt */ 62 | highestSfb = 0; 63 | for (wnd=0; wnd=highestSfb; sfb--) { 65 | for (line=(sfbOffset[sfb + 1] - 1); line>=sfbOffset[sfb]; line--) { 66 | 67 | if (mdctSpectrum[wnd*FRAME_LEN_SHORT+line] != 0) break; 68 | } 69 | 70 | if (line >= sfbOffset[sfb]) break; 71 | } 72 | highestSfb = max(highestSfb, sfb); 73 | } 74 | 75 | if (highestSfb < 0) { 76 | highestSfb = 0; 77 | } 78 | *maxSfbPerGroup = highestSfb + 1; 79 | 80 | /* calculate sfbOffset */ 81 | i = 0; 82 | offset = 0; 83 | for (grp = 0; grp < noOfGroups; grp++) { 84 | for (sfb = 0; sfb < sfbCnt; sfb++) { 85 | groupedSfbOffset[i] = offset + sfbOffset[sfb] * groupLen[grp]; 86 | i += 1; 87 | } 88 | offset += groupLen[grp] * FRAME_LEN_SHORT; 89 | } 90 | groupedSfbOffset[i] = FRAME_LEN_LONG; 91 | i += 1; 92 | 93 | /* calculate minSnr */ 94 | i = 0; 95 | offset = 0; 96 | for (grp = 0; grp < noOfGroups; grp++) { 97 | for (sfb = 0; sfb < sfbCnt; sfb++) { 98 | groupedSfbMinSnr[i] = sfbMinSnr[sfb]; 99 | i += 1; 100 | } 101 | offset += groupLen[grp] * FRAME_LEN_SHORT; 102 | } 103 | 104 | 105 | /* sum up sfbThresholds */ 106 | wnd = 0; 107 | i = 0; 108 | for (grp = 0; grp < noOfGroups; grp++) { 109 | for (sfb = 0; sfb < sfbCnt; sfb++) { 110 | Word32 thresh = sfbThreshold->sfbShort[wnd][sfb]; 111 | for (j=1; jsfbShort[wnd+j][sfb]); 113 | } 114 | sfbThreshold->sfbLong[i] = thresh; 115 | i += 1; 116 | } 117 | wnd += groupLen[grp]; 118 | } 119 | 120 | /* sum up sfbEnergies left/right */ 121 | wnd = 0; 122 | i = 0; 123 | for (grp = 0; grp < noOfGroups; grp++) { 124 | for (sfb = 0; sfb < sfbCnt; sfb++) { 125 | Word32 energy = sfbEnergy->sfbShort[wnd][sfb]; 126 | for (j=1; jsfbShort[wnd+j][sfb]); 128 | } 129 | sfbEnergy->sfbLong[i] = energy; 130 | i += 1; 131 | } 132 | wnd += groupLen[grp]; 133 | } 134 | 135 | /* sum up sfbEnergies mid/side */ 136 | wnd = 0; 137 | i = 0; 138 | for (grp = 0; grp < noOfGroups; grp++) { 139 | for (sfb = 0; sfb < sfbCnt; sfb++) { 140 | Word32 energy = sfbEnergyMS->sfbShort[wnd][sfb]; 141 | for (j=1; jsfbShort[wnd+j][sfb]); 143 | } 144 | sfbEnergyMS->sfbLong[i] = energy; 145 | i += 1; 146 | } 147 | wnd += groupLen[grp]; 148 | } 149 | 150 | /* sum up sfbSpreadedEnergies */ 151 | wnd = 0; 152 | i = 0; 153 | for (grp = 0; grp < noOfGroups; grp++) { 154 | for (sfb = 0; sfb < sfbCnt; sfb++) { 155 | Word32 energy = sfbSpreadedEnergy->sfbShort[wnd][sfb]; 156 | for (j=1; jsfbShort[wnd+j][sfb]); 158 | } 159 | sfbSpreadedEnergy->sfbLong[i] = energy; 160 | i += 1; 161 | } 162 | wnd += groupLen[grp]; 163 | } 164 | 165 | /* re-group spectrum */ 166 | wnd = 0; 167 | i = 0; 168 | for (grp = 0; grp < noOfGroups; grp++) { 169 | for (sfb = 0; sfb < sfbCnt; sfb++) { 170 | for (j = 0; j < groupLen[grp]; j++) { 171 | Word16 lineOffset = FRAME_LEN_SHORT * (wnd + j); 172 | for (line = lineOffset + sfbOffset[sfb]; line < lineOffset + sfbOffset[sfb+1]; line++) { 173 | tmpSpectrum[i] = mdctSpectrum[line]; 174 | i = i + 1; 175 | } 176 | } 177 | } 178 | wnd += groupLen[grp]; 179 | } 180 | 181 | for(i=0;i b ? a : b) 97 | #endif 98 | 99 | #ifdef ARM_INASM 100 | #ifdef ARMV5_INASM 101 | #define ARMV5E_INASM 1 102 | #endif 103 | #define ARMV4_INASM 1 104 | #endif 105 | 106 | #if ARMV4_INASM 107 | #define ARMV5TE_SAT 1 108 | #define ARMV5TE_ADD 1 109 | #define ARMV5TE_SUB 1 110 | #define ARMV5TE_SHL 1 111 | #define ARMV5TE_SHR 1 112 | #define ARMV5TE_L_SHL 1 113 | #define ARMV5TE_L_SHR 1 114 | #endif//ARMV4 115 | #if ARMV5E_INASM 116 | #define ARMV5TE_L_ADD 1 117 | #define ARMV5TE_L_SUB 1 118 | #define ARMV5TE_L_MULT 1 119 | #define ARMV5TE_L_MAC 1 120 | #define ARMV5TE_L_MSU 1 121 | 122 | 123 | #define ARMV5TE_DIV_S 1 124 | #define ARMV5TE_ROUND 1 125 | #define ARMV5TE_MULT 1 126 | 127 | #define ARMV5TE_NORM_S 1 128 | #define ARMV5TE_NORM_L 1 129 | #define ARMV5TE_L_MPY_LS 1 130 | #endif 131 | #if ARMV6_INASM 132 | #undef ARMV5TE_ADD 133 | #define ARMV5TE_ADD 0 134 | #undef ARMV5TE_SUB 135 | #define ARMV5TE_SUB 0 136 | #define ARMV6_SAT 1 137 | #endif 138 | 139 | //basic operation functions optimization flags 140 | #define SATRUATE_IS_INLINE 1 //define saturate as inline function 141 | #define SHL_IS_INLINE 1 //define shl as inline function 142 | #define SHR_IS_INLINE 1 //define shr as inline function 143 | #define L_MULT_IS_INLINE 1 //define L_mult as inline function 144 | #define L_MSU_IS_INLINE 1 //define L_msu as inline function 145 | #define L_SUB_IS_INLINE 1 //define L_sub as inline function 146 | #define L_SHL_IS_INLINE 1 //define L_shl as inline function 147 | #define L_SHR_IS_INLINE 1 //define L_shr as inline function 148 | #define ADD_IS_INLINE 1 //define add as inline function //add, inline is the best 149 | #define SUB_IS_INLINE 1 //define sub as inline function //sub, inline is the best 150 | #define DIV_S_IS_INLINE 1 //define div_s as inline function 151 | #define MULT_IS_INLINE 1 //define mult as inline function 152 | #define NORM_S_IS_INLINE 1 //define norm_s as inline function 153 | #define NORM_L_IS_INLINE 1 //define norm_l as inline function 154 | #define ROUND_IS_INLINE 1 //define round as inline function 155 | #define L_MAC_IS_INLINE 1 //define L_mac as inline function 156 | #define L_ADD_IS_INLINE 1 //define L_add as inline function 157 | #define EXTRACT_H_IS_INLINE 1 //define extract_h as inline function 158 | #define EXTRACT_L_IS_INLINE 1 //define extract_l as inline function //??? 159 | #define MULT_R_IS_INLINE 1 //define mult_r as inline function 160 | #define SHR_R_IS_INLINE 1 //define shr_r as inline function 161 | #define MAC_R_IS_INLINE 1 //define mac_r as inline function 162 | #define MSU_R_IS_INLINE 1 //define msu_r as inline function 163 | #define L_SHR_R_IS_INLINE 1 //define L_shr_r as inline function 164 | 165 | #define PREFIX voAACEnc 166 | #define LINK0(x, y, z) LINK1(x,y,z) 167 | #define LINK1(x,y,z) x##y##z 168 | #define ADD_PREFIX(func) LINK0(PREFIX, _, func) 169 | 170 | #define L_Extract ADD_PREFIX(L_Extract) 171 | #define L_Comp ADD_PREFIX(L_Comp) 172 | #define Mpy_32 ADD_PREFIX(Mpy_32) 173 | #define Mpy_32_16 ADD_PREFIX(Mpy_32_16) 174 | #define Div_32 ADD_PREFIX(Div_32) 175 | #define iLog4 ADD_PREFIX(iLog4) 176 | #define rsqrt ADD_PREFIX(rsqrt) 177 | #define pow2_xy ADD_PREFIX(pow2_xy) 178 | #define L_mpy_ls ADD_PREFIX(L_mpy_ls) 179 | #define L_mpy_wx ADD_PREFIX(L_mpy_wx) 180 | #define TnsEncode ADD_PREFIX(TnsEncode) 181 | #define GetSRIndex ADD_PREFIX(GetSRIndex) 182 | #define WriteBitstream ADD_PREFIX(WriteBitstream) 183 | 184 | #define mem_malloc ADD_PREFIX(mem_malloc) 185 | #define mem_free ADD_PREFIX(mem_free) 186 | 187 | #endif 188 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/include/voType.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voType.h 18 | 19 | Content: data type definition 20 | 21 | *******************************************************************************/ 22 | #ifndef __voType_H__ 23 | #define __voType_H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /* __cplusplus */ 28 | 29 | #ifdef _WIN32 30 | # define VO_API __cdecl 31 | # define VO_CBI __stdcall 32 | #else 33 | # define VO_API 34 | # define VO_CBI 35 | #endif //_WIN32 36 | 37 | /** VO_IN is used to identify inputs to an VO function. This designation 38 | will also be used in the case of a pointer that points to a parameter 39 | that is used as an output. */ 40 | #ifndef VO_IN 41 | #define VO_IN 42 | #endif 43 | 44 | /** VO_OUT is used to identify outputs from an VO function. This 45 | designation will also be used in the case of a pointer that points 46 | to a parameter that is used as an input. */ 47 | #ifndef VO_OUT 48 | #define VO_OUT 49 | #endif 50 | 51 | /** VO_INOUT is used to identify parameters that may be either inputs or 52 | outputs from an VO function at the same time. This designation will 53 | also be used in the case of a pointer that points to a parameter that 54 | is used both as an input and an output. */ 55 | #ifndef VO_INOUT 56 | #define VO_INOUT 57 | #endif 58 | 59 | #define VO_MAX_ENUM_VALUE 0X7FFFFFFF 60 | 61 | /** VO_VOID */ 62 | typedef void VO_VOID; 63 | 64 | /** VO_U8 is an 8 bit unsigned quantity that is byte aligned */ 65 | typedef unsigned char VO_U8; 66 | 67 | /** VO_BYTE is an 8 bit unsigned quantity that is byte aligned */ 68 | typedef unsigned char VO_BYTE; 69 | 70 | /** VO_S8 is an 8 bit signed quantity that is byte aligned */ 71 | typedef signed char VO_S8; 72 | 73 | /** VO_CHAR is an 8 bit signed quantity that is byte aligned */ 74 | typedef char VO_CHAR; 75 | 76 | /** VO_U16 is a 16 bit unsigned quantity that is 16 bit word aligned */ 77 | typedef unsigned short VO_U16; 78 | 79 | /** VO_S16 is a 16 bit signed quantity that is 16 bit word aligned */ 80 | typedef signed short VO_S16; 81 | 82 | /** VO_U32 is a 32 bit unsigned quantity that is 32 bit word aligned */ 83 | typedef unsigned long VO_U32; 84 | 85 | /** VO_S32 is a 32 bit signed quantity that is 32 bit word aligned */ 86 | typedef signed long VO_S32; 87 | 88 | /* Users with compilers that cannot accept the "long long" designation should 89 | define the VO_SKIP64BIT macro. It should be noted that this may cause 90 | some components to fail to compile if the component was written to require 91 | 64 bit integral types. However, these components would NOT compile anyway 92 | since the compiler does not support the way the component was written. 93 | */ 94 | #ifndef VO_SKIP64BIT 95 | #ifdef _MSC_VER 96 | /** VO_U64 is a 64 bit unsigned quantity that is 64 bit word aligned */ 97 | typedef unsigned __int64 VO_U64; 98 | /** VO_S64 is a 64 bit signed quantity that is 64 bit word aligned */ 99 | typedef signed __int64 VO_S64; 100 | #else // WIN32 101 | /** VO_U64 is a 64 bit unsigned quantity that is 64 bit word aligned */ 102 | typedef unsigned long long VO_U64; 103 | /** VO_S64 is a 64 bit signed quantity that is 64 bit word aligned */ 104 | typedef signed long long VO_S64; 105 | #endif // WIN32 106 | #endif // VO_SKIP64BIT 107 | 108 | /** The VO_BOOL type is intended to be used to represent a true or a false 109 | value when passing parameters to and from the VO core and components. The 110 | VO_BOOL is a 32 bit quantity and is aligned on a 32 bit word boundary. 111 | */ 112 | typedef enum VO_BOOL { 113 | VO_FALSE = 0, 114 | VO_TRUE = !VO_FALSE, 115 | VO_BOOL_MAX = VO_MAX_ENUM_VALUE 116 | } VO_BOOL; 117 | 118 | /** The VO_PTR type is intended to be used to pass pointers between the VO 119 | applications and the VO Core and components. This is a 32 bit pointer and 120 | is aligned on a 32 bit boundary. 121 | */ 122 | typedef void* VO_PTR; 123 | 124 | /** The VO_HANDLE type is intended to be used to pass pointers between the VO 125 | applications and the VO Core and components. This is a 32 bit pointer and 126 | is aligned on a 32 bit boundary. 127 | */ 128 | typedef void* VO_HANDLE; 129 | 130 | /** The VO_STRING type is intended to be used to pass "C" type strings between 131 | the application and the core and component. The VO_STRING type is a 32 132 | bit pointer to a zero terminated string. The pointer is word aligned and 133 | the string is byte aligned. 134 | */ 135 | typedef char* VO_PCHAR; 136 | 137 | /** The VO_PBYTE type is intended to be used to pass arrays of bytes such as 138 | buffers between the application and the component and core. The VO_PBYTE 139 | type is a 32 bit pointer to a zero terminated string. The pointer is word 140 | aligned and the string is byte aligned. 141 | */ 142 | typedef unsigned char* VO_PBYTE; 143 | 144 | #ifndef NULL 145 | #ifdef __cplusplus 146 | #define NULL 0 147 | #else 148 | #define NULL ((void *)0) 149 | #endif 150 | #endif 151 | 152 | /** 153 | * Input stream format, Frame or Stream.. 154 | */ 155 | typedef enum { 156 | VO_INPUT_FRAME = 1, /*!< Input contains completely frame(s) data. */ 157 | VO_INPUT_STREAM, /*!< Input is stream data. */ 158 | VO_INPUT_STREAM_MAX = VO_MAX_ENUM_VALUE 159 | } VO_INPUT_TYPE; 160 | 161 | 162 | /** 163 | * General data buffer, used as input or output. 164 | */ 165 | typedef struct { 166 | VO_PBYTE Buffer; /*!< Buffer pointer */ 167 | VO_U32 Length; /*!< Buffer size in byte */ 168 | VO_S64 Time; /*!< The time of the buffer */ 169 | } VO_CODECBUFFER; 170 | 171 | 172 | /** 173 | * The init memdata flag. 174 | */ 175 | typedef enum{ 176 | VO_IMF_USERMEMOPERATOR =0, /*!< memData is the pointer of memoperator function*/ 177 | VO_IMF_PREALLOCATEDBUFFER =1, /*!< memData is preallocated memory*/ 178 | VO_IMF_MAX = VO_MAX_ENUM_VALUE 179 | }VO_INIT_MEM_FlAG; 180 | 181 | 182 | /** 183 | * The init memory structure.. 184 | */ 185 | typedef struct{ 186 | VO_INIT_MEM_FlAG memflag; /*!msDigest) { 59 | case MS_NONE: 60 | case MS_ALL: 61 | break; 62 | 63 | case MS_SOME: 64 | for(sfbOff=0; sfbOfftnsActive[i]!=0) { 99 | tnsPresent = 1; 100 | } 101 | } 102 | 103 | if (tnsPresent) { 104 | /* there is data to be written*/ 105 | /*count += 1; */ 106 | for (i=0; itnsActive[i]) { 114 | count += 1; 115 | 116 | if (blockType == 2) { 117 | count += 4; 118 | count += 3; 119 | } 120 | else { 121 | count += 6; 122 | count += 5; 123 | } 124 | 125 | if (tnsInfo->order[i]) { 126 | count += 1; /*direction*/ 127 | count += 1; /*coef_compression */ 128 | 129 | if (tnsInfo->coefRes[i] == 4) { 130 | ptcoef = tnsInfo->coef + i*TNS_MAX_ORDER_SHORT; 131 | coefBits = 3; 132 | for(k=0; korder[i]; k++) { 133 | 134 | if ((ptcoef[k] > 3) || (ptcoef[k] < -4)) { 135 | coefBits = 4; 136 | break; 137 | } 138 | } 139 | } 140 | else { 141 | coefBits = 2; 142 | ptcoef = tnsInfo->coef + i*TNS_MAX_ORDER_SHORT; 143 | for(k=0; korder[i]; k++) { 144 | 145 | if ((ptcoef[k] > 1) || (ptcoef[k] < -2)) { 146 | coefBits = 3; 147 | break; 148 | } 149 | } 150 | } 151 | for (k=0; korder[i]; k++ ) { 152 | count += coefBits; 153 | } 154 | } 155 | } 156 | } 157 | } 158 | 159 | return count; 160 | } 161 | 162 | /********************************************************************************** 163 | * 164 | * function name: countTnsBits 165 | * description: count tns bit demand 166 | * 167 | **********************************************************************************/ 168 | static Word16 countTnsBits(TNS_INFO *tnsInfo,Word16 blockType) 169 | { 170 | return(tnsCount(tnsInfo, blockType)); 171 | } 172 | 173 | /********************************************************************************* 174 | * 175 | * function name: countStaticBitdemand 176 | * description: count static bit demand include tns 177 | * 178 | **********************************************************************************/ 179 | Word16 countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], 180 | PSY_OUT_ELEMENT *psyOutElement, 181 | Word16 channels, 182 | Word16 adtsUsed) 183 | { 184 | Word32 statBits; 185 | Word32 ch; 186 | 187 | statBits = 0; 188 | 189 | /* if adts used, add 56 bits */ 190 | if(adtsUsed) statBits += 56; 191 | 192 | 193 | switch (channels) { 194 | case 1: 195 | statBits += SI_ID_BITS+SI_SCE_BITS+SI_ICS_BITS; 196 | statBits += countTnsBits(&(psyOutChannel[0].tnsInfo), 197 | psyOutChannel[0].windowSequence); 198 | 199 | switch(psyOutChannel[0].windowSequence){ 200 | case LONG_WINDOW: 201 | case START_WINDOW: 202 | case STOP_WINDOW: 203 | statBits += SI_ICS_INFO_BITS_LONG; 204 | break; 205 | case SHORT_WINDOW: 206 | statBits += SI_ICS_INFO_BITS_SHORT; 207 | break; 208 | } 209 | break; 210 | case 2: 211 | statBits += SI_ID_BITS+SI_CPE_BITS+2*SI_ICS_BITS; 212 | 213 | statBits += SI_CPE_MS_MASK_BITS; 214 | statBits += countMsMaskBits(psyOutChannel[0].sfbCnt, 215 | psyOutChannel[0].sfbPerGroup, 216 | psyOutChannel[0].maxSfbPerGroup, 217 | &psyOutElement->toolsInfo); 218 | 219 | switch (psyOutChannel[0].windowSequence) { 220 | case LONG_WINDOW: 221 | case START_WINDOW: 222 | case STOP_WINDOW: 223 | statBits += SI_ICS_INFO_BITS_LONG; 224 | break; 225 | case SHORT_WINDOW: 226 | statBits += SI_ICS_INFO_BITS_SHORT; 227 | break; 228 | } 229 | for(ch=0; ch<2; ch++) 230 | statBits += countTnsBits(&(psyOutChannel[ch].tnsInfo), 231 | psyOutChannel[ch].windowSequence); 232 | break; 233 | } 234 | 235 | return statBits; 236 | } 237 | 238 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/include/voAudio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: voAudio.h 18 | 19 | Content: Audio types and functions 20 | 21 | *******************************************************************************/ 22 | 23 | #ifndef __voAudio_H__ 24 | #define __voAudio_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | #include "voIndex.h" 31 | #include "voMem.h" 32 | 33 | #define VO_PID_AUDIO_BASE 0x42000000 /*!< The base param ID for AUDIO codec */ 34 | #define VO_PID_AUDIO_FORMAT (VO_PID_AUDIO_BASE | 0X0001) /*!< The format data of audio in track */ 35 | #define VO_PID_AUDIO_SAMPLEREATE (VO_PID_AUDIO_BASE | 0X0002) /*!< The sample rate of audio */ 36 | #define VO_PID_AUDIO_CHANNELS (VO_PID_AUDIO_BASE | 0X0003) /*!< The channel of audio */ 37 | #define VO_PID_AUDIO_BITRATE (VO_PID_AUDIO_BASE | 0X0004) /*!< The bit rate of audio */ 38 | #define VO_PID_AUDIO_CHANNELMODE (VO_PID_AUDIO_BASE | 0X0005) /*!< The channel mode of audio */ 39 | 40 | #define VO_ERR_AUDIO_BASE 0x82000000 41 | #define VO_ERR_AUDIO_UNSCHANNEL VO_ERR_AUDIO_BASE | 0x0001 42 | #define VO_ERR_AUDIO_UNSSAMPLERATE VO_ERR_AUDIO_BASE | 0x0002 43 | #define VO_ERR_AUDIO_UNSFEATURE VO_ERR_AUDIO_BASE | 0x0003 44 | 45 | 46 | /** 47 | *Enumeration used to define the possible audio coding formats. 48 | */ 49 | typedef enum VO_AUDIO_CODINGTYPE { 50 | VO_AUDIO_CodingUnused = 0, /**< Placeholder value when coding is N/A */ 51 | VO_AUDIO_CodingPCM, /**< Any variant of PCM coding */ 52 | VO_AUDIO_CodingADPCM, /**< Any variant of ADPCM encoded data */ 53 | VO_AUDIO_CodingAMRNB, /**< Any variant of AMR encoded data */ 54 | VO_AUDIO_CodingAMRWB, /**< Any variant of AMR encoded data */ 55 | VO_AUDIO_CodingAMRWBP, /**< Any variant of AMR encoded data */ 56 | VO_AUDIO_CodingQCELP13, /**< Any variant of QCELP 13kbps encoded data */ 57 | VO_AUDIO_CodingEVRC, /**< Any variant of EVRC encoded data */ 58 | VO_AUDIO_CodingAAC, /**< Any variant of AAC encoded data, 0xA106 - ISO/MPEG-4 AAC, 0xFF - AAC */ 59 | VO_AUDIO_CodingAC3, /**< Any variant of AC3 encoded data */ 60 | VO_AUDIO_CodingFLAC, /**< Any variant of FLAC encoded data */ 61 | VO_AUDIO_CodingMP1, /**< Any variant of MP1 encoded data */ 62 | VO_AUDIO_CodingMP3, /**< Any variant of MP3 encoded data */ 63 | VO_AUDIO_CodingOGG, /**< Any variant of OGG encoded data */ 64 | VO_AUDIO_CodingWMA, /**< Any variant of WMA encoded data */ 65 | VO_AUDIO_CodingRA, /**< Any variant of RA encoded data */ 66 | VO_AUDIO_CodingMIDI, /**< Any variant of MIDI encoded data */ 67 | VO_AUDIO_CodingDRA, /**< Any variant of dra encoded data */ 68 | VO_AUDIO_CodingG729, /**< Any variant of dra encoded data */ 69 | VO_AUDIO_Coding_MAX = VO_MAX_ENUM_VALUE 70 | } VO_AUDIO_CODINGTYPE; 71 | 72 | /*! 73 | * the channel type value 74 | */ 75 | typedef enum { 76 | VO_CHANNEL_CENTER = 1, /*!
InputUsed is total used input data size in byte. 137 | * \retval VO_ERR_NONE Succeeded. 138 | * VO_ERR_INPUT_BUFFER_SMALL. The input was finished or the input data was not enought. Continue to input 139 | * data before next call. 140 | */ 141 | VO_U32 (VO_API * GetOutputData) (VO_HANDLE hCodec, VO_CODECBUFFER * pOutBuffer, VO_AUDIO_OUTPUTINFO * pOutInfo); 142 | 143 | /** 144 | * Set the parameter for the specified param ID. 145 | * \param hCodec [IN]] The codec handle which was created by Init function. 146 | * \param uParamID [IN] The param ID. 147 | * \param pData [IN] The param value. 148 | * \retval VO_ERR_NONE Succeeded. 149 | */ 150 | VO_U32 (VO_API * SetParam) (VO_HANDLE hCodec, VO_S32 uParamID, VO_PTR pData); 151 | 152 | /** 153 | * Get the parameter for the specified param ID. 154 | * \param hCodec [IN]] The codec handle which was created by Init function. 155 | * \param uParamID [IN] The param ID. 156 | * \param pData [IN] The param value. 157 | * \retval VO_ERR_NONE Succeeded. 158 | */ 159 | VO_U32 (VO_API * GetParam) (VO_HANDLE hCodec, VO_S32 uParamID, VO_PTR pData); 160 | 161 | /** 162 | * Uninit the Codec. 163 | * \param hCodec [IN]] The codec handle which was created by Init function. 164 | * \retval VO_ERR_NONE Succeeded. 165 | */ 166 | VO_U32 (VO_API * Uninit) (VO_HANDLE hCodec); 167 | } VO_AUDIO_CODECAPI; 168 | 169 | #ifdef __cplusplus 170 | } 171 | #endif /* __cplusplus */ 172 | 173 | #endif // __voAudio_H__ 174 | -------------------------------------------------------------------------------- /aacenc/external/aacenc/src/aacenc_core.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2003-2010, VisualOn, Inc. 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | /******************************************************************************* 17 | File: aacenc_core.c 18 | 19 | Content: aac encoder core functions 20 | 21 | *******************************************************************************/ 22 | 23 | #include "typedef.h" 24 | #include "aacenc_core.h" 25 | #include "bitenc.h" 26 | 27 | #include "psy_configuration.h" 28 | #include "psy_main.h" 29 | #include "qc_main.h" 30 | #include "psy_main.h" 31 | #include "channel_map.h" 32 | #include "aac_rom.h" 33 | 34 | /******************************************************************************** 35 | * 36 | * function name: AacInitDefaultConfig 37 | * description: gives reasonable default configuration 38 | * 39 | **********************************************************************************/ 40 | void AacInitDefaultConfig(AACENC_CONFIG *config) 41 | { 42 | /* default configurations */ 43 | config->adtsUsed = 1; 44 | config->nChannelsIn = 2; 45 | config->nChannelsOut = 2; 46 | config->bitRate = 128000; 47 | config->bandWidth = 0; 48 | } 49 | 50 | /******************************************************************************** 51 | * 52 | * function name: AacEncOpen 53 | * description: allocate and initialize a new encoder instance 54 | * returns: 0 if success 55 | * 56 | **********************************************************************************/ 57 | Word16 AacEncOpen( AAC_ENCODER* hAacEnc, /* pointer to an encoder handle, initialized on return */ 58 | const AACENC_CONFIG config /* pre-initialized config struct */ 59 | ) 60 | { 61 | Word32 error = 0; 62 | Word16 profile = 1; 63 | 64 | ELEMENT_INFO *elInfo = NULL; 65 | 66 | if (hAacEnc==0) { 67 | error=1; 68 | } 69 | 70 | if (!error) { 71 | hAacEnc->config = config; 72 | } 73 | 74 | if (!error) { 75 | error = InitElementInfo (config.nChannelsOut, 76 | &hAacEnc->elInfo); 77 | } 78 | 79 | if (!error) { 80 | elInfo = &hAacEnc->elInfo; 81 | } 82 | 83 | if (!error) { 84 | /* use or not tns tool for long and short block */ 85 | Word16 tnsMask=3; 86 | 87 | /* init encoder psychoacoustic */ 88 | error = psyMainInit(&hAacEnc->psyKernel, 89 | config.sampleRate, 90 | config.bitRate, 91 | elInfo->nChannelsInEl, 92 | tnsMask, 93 | hAacEnc->config.bandWidth); 94 | } 95 | 96 | /* use or not adts header */ 97 | if(!error) { 98 | hAacEnc->qcOut.qcElement.adtsUsed = config.adtsUsed; 99 | } 100 | 101 | /* init encoder quantization */ 102 | if (!error) { 103 | struct QC_INIT qcInit; 104 | 105 | /*qcInit.channelMapping = &hAacEnc->channelMapping;*/ 106 | qcInit.elInfo = &hAacEnc->elInfo; 107 | 108 | qcInit.maxBits = (Word16) (MAXBITS_COEF*elInfo->nChannelsInEl); 109 | qcInit.bitRes = qcInit.maxBits; 110 | qcInit.averageBits = (Word16) ((config.bitRate * FRAME_LEN_LONG) / config.sampleRate); 111 | 112 | qcInit.padding.paddingRest = config.sampleRate; 113 | 114 | qcInit.meanPe = (Word16) ((10 * FRAME_LEN_LONG * hAacEnc->config.bandWidth) / 115 | (config.sampleRate>>1)); 116 | 117 | qcInit.maxBitFac = (Word16) ((100 * (MAXBITS_COEF-MINBITS_COEF)* elInfo->nChannelsInEl)/ 118 | (qcInit.averageBits?qcInit.averageBits:1)); 119 | 120 | qcInit.bitrate = config.bitRate; 121 | 122 | error = QCInit(&hAacEnc->qcKernel, &qcInit); 123 | } 124 | 125 | /* init bitstream encoder */ 126 | if (!error) { 127 | hAacEnc->bseInit.nChannels = elInfo->nChannelsInEl; 128 | hAacEnc->bseInit.bitrate = config.bitRate; 129 | hAacEnc->bseInit.sampleRate = config.sampleRate; 130 | hAacEnc->bseInit.profile = profile; 131 | } 132 | 133 | return error; 134 | } 135 | 136 | /******************************************************************************** 137 | * 138 | * function name: AacEncEncode 139 | * description: encode pcm to aac data core function 140 | * returns: 0 if success 141 | * 142 | **********************************************************************************/ 143 | Word16 AacEncEncode(AAC_ENCODER *aacEnc, /*!< an encoder handle */ 144 | Word16 *timeSignal, /*!< BLOCKSIZE*nChannels audio samples, interleaved */ 145 | const UWord8 *ancBytes, /*!< pointer to ancillary data bytes */ 146 | Word16 *numAncBytes, /*!< number of ancillary Data Bytes */ 147 | UWord8 *outBytes, /*!< pointer to output buffer (must be large MINBITS_COEF/8*MAX_CHANNELS bytes) */ 148 | VO_U32 *numOutBytes /*!< number of bytes in output buffer after processing */ 149 | ) 150 | { 151 | ELEMENT_INFO *elInfo = &aacEnc->elInfo; 152 | Word16 globUsedBits; 153 | Word16 ancDataBytes, ancDataBytesLeft; 154 | 155 | ancDataBytes = ancDataBytesLeft = *numAncBytes; 156 | 157 | /* init output aac data buffer and length */ 158 | aacEnc->hBitStream = CreateBitBuffer(&aacEnc->bitStream, outBytes, *numOutBytes); 159 | 160 | /* psychoacoustic process */ 161 | psyMain(aacEnc->config.nChannelsOut, 162 | elInfo, 163 | timeSignal, 164 | &aacEnc->psyKernel.psyData[elInfo->ChannelIndex[0]], 165 | &aacEnc->psyKernel.tnsData[elInfo->ChannelIndex[0]], 166 | &aacEnc->psyKernel.psyConfLong, 167 | &aacEnc->psyKernel.psyConfShort, 168 | &aacEnc->psyOut.psyOutChannel[elInfo->ChannelIndex[0]], 169 | &aacEnc->psyOut.psyOutElement, 170 | aacEnc->psyKernel.pScratchTns, 171 | aacEnc->config.sampleRate); 172 | 173 | /* adjust bitrate and frame length */ 174 | AdjustBitrate(&aacEnc->qcKernel, 175 | aacEnc->config.bitRate, 176 | aacEnc->config.sampleRate); 177 | 178 | /* quantization and coding process */ 179 | QCMain(&aacEnc->qcKernel, 180 | &aacEnc->qcKernel.elementBits, 181 | &aacEnc->qcKernel.adjThr.adjThrStateElem, 182 | &aacEnc->psyOut.psyOutChannel[elInfo->ChannelIndex[0]], 183 | &aacEnc->psyOut.psyOutElement, 184 | &aacEnc->qcOut.qcChannel[elInfo->ChannelIndex[0]], 185 | &aacEnc->qcOut.qcElement, 186 | elInfo->nChannelsInEl, 187 | min(ancDataBytesLeft,ancDataBytes)); 188 | 189 | ancDataBytesLeft = ancDataBytesLeft - ancDataBytes; 190 | 191 | globUsedBits = FinalizeBitConsumption(&aacEnc->qcKernel, 192 | &aacEnc->qcOut); 193 | 194 | /* write bitstream process */ 195 | WriteBitstream(aacEnc->hBitStream, 196 | *elInfo, 197 | &aacEnc->qcOut, 198 | &aacEnc->psyOut, 199 | &globUsedBits, 200 | ancBytes, 201 | aacEnc->psyKernel.sampleRateIdx); 202 | 203 | updateBitres(&aacEnc->qcKernel, 204 | &aacEnc->qcOut); 205 | 206 | /* write out the bitstream */ 207 | *numOutBytes = GetBitsAvail(aacEnc->hBitStream) >> 3; 208 | 209 | return 0; 210 | } 211 | 212 | 213 | /******************************************************************************** 214 | * 215 | * function name:AacEncClose 216 | * description: deallocate an encoder instance 217 | * 218 | **********************************************************************************/ 219 | void AacEncClose (AAC_ENCODER* hAacEnc, VO_MEM_OPERATOR *pMemOP) 220 | { 221 | if (hAacEnc) { 222 | QCDelete(&hAacEnc->qcKernel, pMemOP); 223 | 224 | QCOutDelete(&hAacEnc->qcOut, pMemOP); 225 | 226 | PsyDelete(&hAacEnc->psyKernel, pMemOP); 227 | 228 | PsyOutDelete(&hAacEnc->psyOut, pMemOP); 229 | 230 | DeleteBitBuffer(&hAacEnc->hBitStream); 231 | 232 | if(hAacEnc->intbuf) 233 | { 234 | mem_free(pMemOP, hAacEnc->intbuf, VO_INDEX_ENC_AAC); 235 | hAacEnc->intbuf = NULL; 236 | } 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /aacenc/aacenc.go: -------------------------------------------------------------------------------- 1 | // Package aacenc implements cgo bindings for VisualOn AAC encoder library. 2 | package aacenc 3 | 4 | //#include "voAAC.h" 5 | import "C" 6 | 7 | import ( 8 | "errors" 9 | "unsafe" 10 | ) 11 | 12 | // Constants. 13 | const ( 14 | // VoPidAacModule - AAC Param ID 15 | VoPidAacModule = 0x42211000 16 | VoPidAacEncparam = VoPidAacModule | 0x0040 17 | 18 | // VoErrAacModule - AAC decoder error ID 19 | VoErrAacModule = 0x82210000 20 | VoErrAacUnsfileformat = VoErrAacModule | 0xF001 21 | VoErrAacUnsprofile = VoErrAacModule | 0xF002 22 | 23 | // VoPidAudioBase - The base param ID for AUDIO codec 24 | VoPidAudioBase = 0x42000000 25 | // VoPidAudioFormat - The format data of audio in track 26 | VoPidAudioFormat = VoPidAudioBase | 0x0001 27 | // VoPidAudioSampleRate - The sample rate of audio 28 | VoPidAudioSampleRate = VoPidAudioBase | 0x0002 29 | // VoPidAudioChannels - The channel of audio 30 | VoPidAudioChannels = VoPidAudioBase | 0x0003 31 | // VoPidAudioBitrate - The bit rate of audio 32 | VoPidAudioBitrate = VoPidAudioBase | 0x0004 33 | // VoPidAudioChannelmode - The channel mode of audio 34 | VoPidAudioChannelmode = VoPidAudioBase | 0x0005 35 | 36 | // VoPidCommonBase - The base of common param ID 37 | VoPidCommonBase = 0x40000000 38 | // VoPidCommonQueryMem - Query the memory needed; Reserved 39 | VoPidCommonQueryMem = VoPidCommonBase 40 | // VoPidCommonInputType - Set or get the input buffer type 41 | VoPidCommonInputType = VoPidCommonBase 42 | // VoPidCommonHasResource - Query it has resource to be used 43 | VoPidCommonHasResource = VoPidCommonBase 44 | // VoPidCommonHeadData - Decoder track header data 45 | VoPidCommonHeadData = VoPidCommonBase 46 | // VoPidCommonFlush . 47 | VoPidCommonFlush = VoPidCommonBase 48 | ) 49 | 50 | // Error codes. 51 | const ( 52 | VoErrNone = 0x00000000 53 | VoErrFinish = 0x00000001 54 | VoErrFailed = 0x80000001 55 | VoErrOutofMemory = 0x80000002 56 | VoErrNotImplement = 0x80000003 57 | VoErrInvalidArg = 0x80000004 58 | VoErrInputBufferSmall = 0x80000005 59 | VoErrOutputBufferSmall = 0x80000006 60 | VoErrWrongStatus = 0x80000007 61 | VoErrWrongParamID = 0x80000008 62 | VoErrLicenseError = 0x80000009 63 | 64 | VoErrAudioBase = 0x82000000 65 | VoErrAudioUnsChannel = VoErrAudioBase | 0x0001 66 | VoErrAudioUnsSampleRate = VoErrAudioBase | 0x0002 67 | VoErrAudioUnsFeature = VoErrAudioBase | 0x0003 68 | ) 69 | 70 | // Enumeration used to define the possible audio coding formats. 71 | const ( 72 | // Placeholder value when coding is N/A 73 | VoAudioCodingUnused int32 = iota 74 | // Any variant of PCM coding 75 | VoAudioCodingPcm 76 | // Any variant of ADPCM encoded data 77 | VoAudioCodingAdpcm 78 | // Any variant of AMR encoded data 79 | VoAudioCodingAmrnb 80 | // Any variant of AMR encoded data 81 | VoAudioCodingAmrwb 82 | // Any variant of AMR encoded data 83 | VoAudioCodingAmrwbp 84 | // Any variant of QCELP 13kbps encoded data 85 | VoAudioCodingQcelp13 86 | // Any variant of EVRC encoded data 87 | VoAudioCodingEvrc 88 | // Any variant of AAC encoded data, 0xA106 - ISO/MPEG-4 AAC, 0xFF - AAC 89 | VoAudioCodingAac 90 | // Any variant of AC3 encoded data 91 | VoAudioCodingAc3 92 | // Any variant of FLAC encoded data 93 | VoAudioCodingFlac 94 | // Any variant of MP1 encoded data 95 | VoAudioCodingMp1 96 | // Any variant of MP3 encoded data 97 | VoAudioCodingMp3 98 | // Any variant of OGG encoded data 99 | VoAudioCodingOgg 100 | // Any variant of WMA encoded data 101 | VoAudioCodingWma 102 | // Any variant of RA encoded data 103 | VoAudioCodingRa 104 | // Any variant of MIDI encoded data 105 | VoAudioCodingMidi 106 | // Any variant of dra encoded data 107 | VoAudioCodingDra 108 | // Any variant of dra encoded data 109 | VoAudioCodingG729 110 | ) 111 | 112 | // The frame type that the decoder supports. 113 | const ( 114 | // Contains only raw aac data in a frame 115 | VoAacRawdata int32 = iota 116 | // Contains ADTS header + raw AAC data in a frame 117 | VoAacAdts 118 | ) 119 | 120 | // The channel type value. 121 | const ( 122 | // Center channel 123 | VoChannelCenter int32 = 1 124 | // Front left channel 125 | VoChannelFrontLeft = 1 << 1 126 | // Front right channel 127 | VoChannelFrontRight = 1 << 2 128 | // Side left channel 129 | VoChannelSideLeft = 1 << 3 130 | // Side right channel 131 | VoChannelSideRight = 1 << 4 132 | // Back left channel 133 | VoChannelBackLeft = 1 << 5 134 | // Back right channel 135 | VoChannelBackRight = 1 << 6 136 | // Back center channel 137 | VoChannelBackCenter = 1 << 7 138 | // Low-frequency effects bass channel 139 | VoChannelLfeBass = 1 << 8 140 | // Include all channels (default) 141 | VoChannelAll = 0xffff 142 | ) 143 | 144 | // Input stream format, Frame or Stream. 145 | const ( 146 | // Input contains completely frame(s) data 147 | VoInputFrame int32 = iota + 1 148 | // Input is stream data. 149 | VoInputStream 150 | ) 151 | 152 | // VoAudioFormat - general audio format info. 153 | type VoAudioFormat struct { 154 | // Sample rate 155 | SampleRate int 156 | // Channel count 157 | Channels int 158 | // Bits per sample 159 | SampleBits int 160 | } 161 | 162 | // cptr return C pointer. 163 | func (v *VoAudioFormat) cptr() *C.VO_AUDIO_FORMAT { 164 | return (*C.VO_AUDIO_FORMAT)(unsafe.Pointer(v)) 165 | } 166 | 167 | // VoAudioOutputinfo - general audio output info. 168 | type VoAudioOutputinfo struct { 169 | // Sample rate 170 | Format VoAudioFormat 171 | // Channel count 172 | InputUsed uint 173 | // Reserved 174 | Reserve uint 175 | } 176 | 177 | // cptr return C pointer. 178 | func (v *VoAudioOutputinfo) cptr() *C.VO_AUDIO_OUTPUTINFO { 179 | return (*C.VO_AUDIO_OUTPUTINFO)(unsafe.Pointer(v)) 180 | } 181 | 182 | // VoCodecBuffer - general data buffer, used as input or output. 183 | type VoCodecBuffer struct { 184 | // Buffer pointer 185 | Buffer unsafe.Pointer 186 | // Buffer size in byte 187 | Length uint64 188 | // The time of the buffer 189 | Time int64 190 | } 191 | 192 | // cptr return C pointer. 193 | func (v *VoCodecBuffer) cptr() *C.VO_CODECBUFFER { 194 | return (*C.VO_CODECBUFFER)(unsafe.Pointer(v)) 195 | } 196 | 197 | // Param - the structure for AAC encoder input parameter. 198 | type Param struct { 199 | // Audio file sample rate 200 | SampleRate int32 201 | // Encoder bit rate in bits/sec 202 | BitRate int32 203 | // Number of channels on input (1,2) 204 | NChannels int16 205 | // Whether write adts header 206 | AdtsUsed int16 207 | } 208 | 209 | var handle C.VO_HANDLE 210 | 211 | // Errors. 212 | var ( 213 | ErrFinish = errors.New("error finish") 214 | ErrFailed = errors.New("process data failed") 215 | ErrOutOfMemory = errors.New("out of memory") 216 | ErrNotImplement = errors.New("feature not implemented") 217 | ErrInvalidArg = errors.New("invalid argument") 218 | ErrInputBufferSmall = errors.New("input buffer data too small") 219 | ErrOutputBufferSmall = errors.New("output buffer size too small") 220 | ErrWrongStatus = errors.New("wrong encoder run-time status") 221 | ErrWrongParamID = errors.New("wrong parameter id") 222 | ErrLicenseError = errors.New("license error") 223 | ErrAudioBase = errors.New("error audio base") 224 | ErrAudioUnsChannel = errors.New("unsupported number of channel") 225 | ErrAudioUnsSampleRate = errors.New("unsupported sample rate") 226 | ErrAudioUnsFeature = errors.New("unsupported feature") 227 | ) 228 | 229 | // ErrorFromResult returns error for result code 230 | func ErrorFromResult(r uint) error { 231 | switch r { 232 | case VoErrNone: 233 | return nil 234 | case VoErrFinish: 235 | return ErrFinish 236 | case VoErrFailed: 237 | return ErrFailed 238 | case VoErrOutofMemory: 239 | return ErrOutOfMemory 240 | case VoErrNotImplement: 241 | return ErrNotImplement 242 | case VoErrInvalidArg: 243 | return ErrInvalidArg 244 | case VoErrInputBufferSmall: 245 | return ErrInputBufferSmall 246 | case VoErrOutputBufferSmall: 247 | return ErrOutputBufferSmall 248 | case VoErrWrongStatus: 249 | return ErrWrongStatus 250 | case VoErrWrongParamID: 251 | return ErrWrongParamID 252 | case VoErrLicenseError: 253 | return ErrLicenseError 254 | case VoErrAudioBase: 255 | return ErrAudioBase 256 | case VoErrAudioUnsChannel: 257 | return ErrAudioUnsChannel 258 | case VoErrAudioUnsSampleRate: 259 | return ErrAudioUnsSampleRate 260 | case VoErrAudioUnsFeature: 261 | return ErrAudioUnsFeature 262 | default: 263 | return nil 264 | } 265 | } 266 | 267 | // Init - init the audio codec module and return codec handle. 268 | func Init(vtype int32) uint { 269 | cvtype := (C.VO_AUDIO_CODINGTYPE)(vtype) 270 | ret := C.voAACEncInit(&handle, cvtype, nil) 271 | v := (uint)(ret) 272 | 273 | return v 274 | } 275 | 276 | // SetInputData - set input audio data. 277 | func SetInputData(pinput *VoCodecBuffer) uint { 278 | cpinput := pinput.cptr() 279 | ret := C.voAACEncSetInputData(handle, cpinput) 280 | v := (uint)(ret) 281 | 282 | return v 283 | } 284 | 285 | // GetOutputData - get the outut audio data. 286 | func GetOutputData(poutbuffer *VoCodecBuffer, poutinfo *VoAudioOutputinfo) uint { 287 | cpoutbuffer := poutbuffer.cptr() 288 | cpoutinfo := poutinfo.cptr() 289 | ret := C.voAACEncGetOutputData(handle, cpoutbuffer, cpoutinfo) 290 | v := (uint)(ret) 291 | 292 | return v 293 | } 294 | 295 | // SetParam - set the parameter for the specified param ID. 296 | func SetParam(uparamid int, pdata unsafe.Pointer) uint { 297 | cuparamid := (C.VO_S32)(uparamid) 298 | cpdata := (C.VO_PTR)(pdata) 299 | ret := C.voAACEncSetParam(handle, cuparamid, cpdata) 300 | v := (uint)(ret) 301 | 302 | return v 303 | } 304 | 305 | // GetParam - get the parameter for the specified param ID. 306 | func GetParam(uparamid int, pdata unsafe.Pointer) uint { 307 | cuparamid := (C.VO_S32)(uparamid) 308 | cpdata := (C.VO_PTR)(pdata) 309 | ret := C.voAACEncGetParam(handle, cuparamid, cpdata) 310 | v := (uint)(ret) 311 | 312 | return v 313 | } 314 | 315 | // Uninit - uninit the Codec. 316 | func Uninit() uint { 317 | ret := C.voAACEncUninit(handle) 318 | v := (uint)(ret) 319 | 320 | return v 321 | } 322 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the 13 | copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other 16 | entities that control, are controlled by, or are under common control with 17 | that entity. For the purposes of this definition, "control" means (i) the 18 | power, direct or indirect, to cause the direction or management of such 19 | entity, whether by contract or otherwise, or (ii) ownership of fifty 20 | percent (50%) or more of the outstanding shares, or (iii) beneficial 21 | ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity exercising 24 | permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation source, 28 | and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical transformation 31 | or translation of a Source form, including but not limited to compiled 32 | object code, generated documentation, and conversions to other media types. 33 | 34 | "Work" shall mean the work of authorship, whether in Source or Object form, 35 | made available under the License, as indicated by a copyright notice that 36 | is included in or attached to the work (an example is provided in the 37 | Appendix below). 38 | 39 | "Derivative Works" shall mean any work, whether in Source or Object form, 40 | that is based on (or derived from) the Work and for which the editorial 41 | revisions, annotations, elaborations, or other modifications represent, as 42 | a whole, an original work of authorship. For the purposes of this License, 43 | Derivative Works shall not include works that remain separable from, or 44 | merely link (or bind by name) to the interfaces of, the Work and Derivative 45 | Works thereof. 46 | 47 | "Contribution" shall mean any work of authorship, including the original 48 | version of the Work and any modifications or additions to that Work or 49 | Derivative Works thereof, that is intentionally submitted to Licensor for 50 | inclusion in the Work by the copyright owner or by an individual or Legal 51 | Entity authorized to submit on behalf of the copyright owner. For the 52 | purposes of this definition, "submitted" means any form of electronic, 53 | verbal, or written communication sent to the Licensor or its 54 | representatives, including but not limited to communication on electronic 55 | mailing lists, source code control systems, and issue tracking systems that 56 | are managed by, or on behalf of, the Licensor for the purpose of discussing 57 | and improving the Work, but excluding communication that is conspicuously 58 | marked or otherwise designated in writing by the copyright owner as "Not a 59 | Contribution." 60 | 61 | "Contributor" shall mean Licensor and any individual or Legal Entity on 62 | behalf of whom a Contribution has been received by Licensor and 63 | subsequently incorporated within the Work. 64 | 65 | 2. Grant of Copyright License. Subject to the terms and conditions of this 66 | License, each Contributor hereby grants to You a perpetual, worldwide, 67 | non-exclusive, no-charge, royalty-free, irrevocable copyright license to 68 | reproduce, prepare Derivative Works of, publicly display, publicly perform, 69 | sublicense, and distribute the Work and such Derivative Works in Source or 70 | Object form. 71 | 72 | 3. Grant of Patent License. Subject to the terms and conditions of this 73 | License, each Contributor hereby grants to You a perpetual, worldwide, 74 | non-exclusive, no-charge, royalty-free, irrevocable (except as stated in 75 | this section) patent license to make, have made, use, offer to sell, sell, 76 | import, and otherwise transfer the Work, where such license applies only to 77 | those patent claims licensable by such Contributor that are necessarily 78 | infringed by their Contribution(s) alone or by combination of their 79 | Contribution(s) with the Work to which such Contribution(s) was submitted. 80 | If You institute patent litigation against any entity (including a 81 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 82 | Contribution incorporated within the Work constitutes direct or 83 | contributory patent infringement, then any patent licenses granted to You 84 | under this License for that Work shall terminate as of the date such 85 | litigation is filed. 86 | 87 | 4. Redistribution. You may reproduce and distribute copies of the Work or 88 | Derivative Works thereof in any medium, with or without modifications, and 89 | in Source or Object form, provided that You meet the following conditions: 90 | 91 | 1. You must give any other recipients of the Work or Derivative Works a 92 | copy of this License; and 93 | 94 | 2. You must cause any modified files to carry prominent notices stating 95 | that You changed the files; and 96 | 97 | 3. You must retain, in the Source form of any Derivative Works that You 98 | distribute, all copyright, patent, trademark, and attribution notices from 99 | the Source form of the Work, excluding those notices that do not pertain to 100 | any part of the Derivative Works; and 101 | 102 | 4. If the Work includes a "NOTICE" text file as part of its 103 | distribution, then any Derivative Works that You distribute must include a 104 | readable copy of the attribution notices contained within such NOTICE file, 105 | excluding those notices that do not pertain to any part of the Derivative 106 | Works, in at least one of the following places: within a NOTICE text file 107 | distributed as part of the Derivative Works; within the Source form or 108 | documentation, if provided along with the Derivative Works; or, within a 109 | display generated by the Derivative Works, if and wherever such third-party 110 | notices normally appear. The contents of the NOTICE file are for 111 | informational purposes only and do not modify the License. You may add Your 112 | own attribution notices within Derivative Works that You distribute, 113 | alongside or as an addendum to the NOTICE text from the Work, provided that 114 | such additional attribution notices cannot be construed as modifying the 115 | License. 116 | 117 | You may add Your own copyright statement to Your modifications and may 118 | provide additional or different license terms and conditions for use, 119 | reproduction, or distribution of Your modifications, or for any such 120 | Derivative Works as a whole, provided Your use, reproduction, and 121 | distribution of the Work otherwise complies with the conditions stated in 122 | this License. 123 | 124 | 5. Submission of Contributions. Unless You explicitly state otherwise, any 125 | Contribution intentionally submitted for inclusion in the Work by You to 126 | the Licensor shall be under the terms and conditions of this License, 127 | without any additional terms or conditions. Notwithstanding the above, 128 | nothing herein shall supersede or modify the terms of any separate license 129 | agreement you may have executed with Licensor regarding such Contributions. 130 | 131 | 6. Trademarks. This License does not grant permission to use the trade 132 | names, trademarks, service marks, or product names of the Licensor, except 133 | as required for reasonable and customary use in describing the origin of 134 | the Work and reproducing the content of the NOTICE file. 135 | 136 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to 137 | in writing, Licensor provides the Work (and each Contributor provides its 138 | Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 139 | KIND, either express or implied, including, without limitation, any 140 | warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or 141 | FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for 142 | determining the appropriateness of using or redistributing the Work and 143 | assume any risks associated with Your exercise of permissions under this 144 | License. 145 | 146 | 8. Limitation of Liability. In no event and under no legal theory, whether 147 | in tort (including negligence), contract, or otherwise, unless required by 148 | applicable law (such as deliberate and grossly negligent acts) or agreed to 149 | in writing, shall any Contributor be liable to You for damages, including 150 | any direct, indirect, special, incidental, or consequential damages of any 151 | character arising as a result of this License or out of the use or 152 | inability to use the Work (including but not limited to damages for loss of 153 | goodwill, work stoppage, computer failure or malfunction, or any and all 154 | other commercial damages or losses), even if such Contributor has been 155 | advised of the possibility of such damages. 156 | 157 | 9. Accepting Warranty or Additional Liability. While redistributing the 158 | Work or Derivative Works thereof, You may choose to offer, and charge a fee 159 | for, acceptance of support, warranty, indemnity, or other liability 160 | obligations and/or rights consistent with this License. However, in 161 | accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if 163 | You agree to indemnify, defend, and hold each Contributor harmless for any 164 | liability incurred by, or claims asserted against, such Contributor by 165 | reason of your accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included 176 | on the same "printed page" as the copyright notice for easier 177 | identification within third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); you may 182 | not use this file except in compliance with the License. You may obtain a 183 | copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable 188 | law or agreed to in writing, software distributed under the License is 189 | distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 190 | KIND, either express or implied. See the License for the specific language 191 | governing permissions and limitations under the License. 192 | --------------------------------------------------------------------------------