├── Types ├── ByteOrder.cs ├── MimeType.cs ├── GroovyCodecs.Types.csproj ├── AudioFormat.cs └── Version.cs ├── Mp3 ├── IMp3Decoder.cs ├── Mp3 │ ├── GenreListHandler.cs │ ├── Enc.cs │ ├── VbrMode.cs │ ├── III_psy_ratio.cs │ ├── MeanBits.cs │ ├── Inf.cs │ ├── IIterationLoop.cs │ ├── MPEGMode.cs │ ├── CalcNoiseData.cs │ ├── FrameDataNode.cs │ ├── III_psy_xmin.cs │ ├── IIISideInfo.cs │ ├── ShortBlock.cs │ ├── NsPsy.cs │ ├── PSY.cs │ ├── ID3TagSpec.cs │ ├── CalcNoiseResult.cs │ ├── HuffCodeTab.cs │ ├── ScaleFac.cs │ ├── VBRSeekInfo.cs │ ├── L3Side.cs │ ├── Util.cs │ ├── MP3Data.cs │ ├── ABRPresets.cs │ ├── VBRTagData.cs │ ├── VBRPresets.cs │ ├── ReplayGain.cs │ ├── ATH.cs │ ├── ShortBlockConstrain.cs │ ├── GrInfo.cs │ ├── CBRNewIterationLoop.cs │ ├── VBRNewIterationLoop.cs │ ├── ABRIterationLoop.cs │ ├── VBROldIterationLoop.cs │ ├── PlottingData.cs │ └── LongBlockConstrain.cs ├── GroovyCodecs.Mp3.csproj ├── IMp3Encoder.cs ├── Mpg │ ├── Frame.cs │ └── MPG123.cs ├── Common │ └── Arrays.cs └── Mp3Decoder.cs ├── WavFile ├── GroovyCodecs.WavFile.csproj └── WavReader.cs ├── Coder ├── GroovyCodecs.Coder.csproj └── Program.cs ├── G729 ├── GroovyCodecs.G729.csproj ├── Codec │ ├── IntReference.cs │ ├── FloatReference.cs │ ├── PParity.cs │ ├── DeAcelp.cs │ ├── PostPro.cs │ ├── PredLt3.cs │ ├── PreProc.cs │ ├── CorFunc.cs │ ├── DecLag3.cs │ ├── Taming.cs │ ├── DecGain.cs │ ├── Gainpred.cs │ ├── Filter.cs │ ├── Pwf.cs │ ├── Lspdec.cs │ ├── Bits.cs │ ├── Util.cs │ └── Lpcfunc.cs ├── Conversion.txt └── G729Encoder.cs ├── G711 ├── GroovyCodecs.G711.csproj ├── uLaw │ └── ULawDecoder.cs └── aLaw │ └── ALawDecoder.cs ├── README.md ├── GroovyCodecs.sln ├── .gitignore └── LICENSE /Types/ByteOrder.cs: -------------------------------------------------------------------------------- 1 | namespace GroovyCodecs.Types 2 | { 3 | public enum ByteOrder 4 | { 5 | BIG_ENDIAN, 6 | LITTLE_ENDIAN 7 | } 8 | } -------------------------------------------------------------------------------- /Types/MimeType.cs: -------------------------------------------------------------------------------- 1 | namespace GroovyCodecs.Types 2 | { 3 | public enum MimeType 4 | { 5 | MIMETYPE_NONE = 0, 6 | MIMETYPE_JPEG, 7 | MIMETYPE_PNG, 8 | MIMETYPE_GIF 9 | } 10 | } -------------------------------------------------------------------------------- /Mp3/IMp3Decoder.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace GroovyCodecs.Mp3 4 | { 5 | public interface IMp3Decoder 6 | { 7 | void close(); 8 | 9 | void decode(MemoryStream sampleBuffer, bool playOriginal); 10 | } 11 | } -------------------------------------------------------------------------------- /Types/GroovyCodecs.Types.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /WavFile/GroovyCodecs.WavFile.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Coder/GroovyCodecs.Coder.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Mp3/Mp3/GenreListHandler.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal interface GenreListHandler 10 | { 11 | void genre_list_handler(int num, string name); 12 | } 13 | } -------------------------------------------------------------------------------- /Mp3/Mp3/Enc.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class Enc 10 | { 11 | internal int enc_delay = -1; 12 | 13 | internal int enc_padding = -1; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VbrMode.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal enum VbrMode 10 | { 11 | vbr_off, 12 | vbr_mt, 13 | vbr_rh, 14 | vbr_abr, 15 | vbr_mtrh, 16 | vbr_default 17 | } 18 | } -------------------------------------------------------------------------------- /Mp3/Mp3/III_psy_ratio.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal sealed class III_psy_ratio 10 | { 11 | 12 | internal III_psy_xmin en = new III_psy_xmin(); 13 | 14 | internal III_psy_xmin thm = new III_psy_xmin(); 15 | } 16 | } -------------------------------------------------------------------------------- /Mp3/Mp3/MeanBits.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class MeanBits 10 | { 11 | 12 | internal int bits; 13 | 14 | internal MeanBits(int meanBits) 15 | { 16 | bits = meanBits; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Mp3/Mp3/Inf.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal sealed class Inf 10 | { 11 | 12 | internal int dim; 13 | 14 | /// 15 | /// 0:Latin-1, 1:UCS-2, 2:RAW 16 | /// 17 | internal int enc; 18 | 19 | internal string l; 20 | } 21 | } -------------------------------------------------------------------------------- /Mp3/Mp3/IIterationLoop.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /// 10 | /// Global Type Definitions 11 | /// @author Ken 12 | /// 13 | internal interface IIterationLoop 14 | { 15 | 16 | void iteration_loop(LameGlobalFlags gfp, float[][] pe, float[] ms_ratio, III_psy_ratio[][] ratio); 17 | } 18 | } -------------------------------------------------------------------------------- /Mp3/Mp3/MPEGMode.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /* MPEG modes */ 10 | internal enum MPEGMode 11 | { 12 | STEREO, 13 | 14 | JOINT_STEREO, 15 | 16 | /// 17 | /// LAME doesn't supports this! 18 | /// 19 | DUAL_CHANNEL, 20 | 21 | MONO, 22 | 23 | NOT_SET 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /G729/GroovyCodecs.G729.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 0.1.2 7 | Jon Gooch 8 | https://github.com/jongoochgithub/GroovyCodecs 9 | A C# native implementation of a G729 encoder / decoder, based on libjitsi/Atlassian code 10 | GroovyG729 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /G711/GroovyCodecs.G711.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 0.1.2 7 | Jon Gooch 8 | https://github.com/jongoochgithub/GroovyCodecs 9 | A C# native implementation of a G711 encoder / decoder, based on RedHat/JBoss/Mobius code 10 | GroovyG711 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /G729/Codec/IntReference.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | /** 18 | * @author Lubomir Marinov 19 | */ 20 | namespace GroovyCodecs.G729.Codec 21 | { 22 | internal class IntReference 23 | { 24 | public int value; 25 | } 26 | } -------------------------------------------------------------------------------- /Mp3/Mp3/CalcNoiseData.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /// 10 | /// allows re-use of previously computed noise values 11 | /// 12 | internal class CalcNoiseData 13 | { 14 | internal int global_gain; 15 | 16 | internal float[] noise = new float[39]; 17 | 18 | internal float[] noise_log = new float[39]; 19 | 20 | internal int sfb_count1; 21 | 22 | internal int[] step = new int[39]; 23 | } 24 | } -------------------------------------------------------------------------------- /G729/Codec/FloatReference.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | /** 18 | * @author Lubomir Marinov 19 | */ 20 | namespace GroovyCodecs.G729.Codec 21 | { 22 | internal class FloatReference 23 | { 24 | public float value; 25 | } 26 | } -------------------------------------------------------------------------------- /Mp3/Mp3/FrameDataNode.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal sealed class FrameDataNode 10 | { 11 | 12 | internal Inf dsc = new Inf(), txt = new Inf(); 13 | 14 | /// 15 | /// Frame Identifier 16 | /// 17 | internal int fid; 18 | 19 | /// 20 | /// 3-character language descriptor 21 | /// 22 | internal string lng; 23 | 24 | internal FrameDataNode nxt; 25 | } 26 | } -------------------------------------------------------------------------------- /Types/AudioFormat.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace GroovyCodecs.Types 4 | { 5 | public class AudioFormat 6 | { 7 | /// for buffer estimation 8 | public int AverageBytesPerSecond { get; set; } 9 | 10 | public bool BigEndian { get; set; } 11 | 12 | /// number of bits per sample of mono data 13 | public short BitsPerSample { get; set; } 14 | 15 | /// block size of data 16 | public short BlockAlign { get; set; } 17 | 18 | /// number of channels 19 | public short Channels { get; set; } 20 | 21 | public Dictionary Properties { get; set; } 22 | 23 | /// sample rate 24 | public int SampleRate { get; set; } 25 | 26 | public bool IsFloatingPoint { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /Mp3/GroovyCodecs.Mp3.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | true 6 | 0.1.2 7 | Jon Gooch 8 | https://github.com/jongoochgithub/GroovyCodecs 9 | A C# native implementation of an MP3 encoder / decoder, based on LAME and Jump3r. 10 | GroovyMp3 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Mp3/Mp3/III_psy_xmin.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using GroovyCodecs.Mp3.Common; 9 | 10 | namespace GroovyCodecs.Mp3.Mp3 11 | { 12 | internal sealed class III_psy_xmin 13 | { 14 | internal float[] l = new float[Encoder.SBMAX_l]; 15 | 16 | internal float[][] s = Arrays.ReturnRectangularArray(Encoder.SBMAX_s, 3); 17 | 18 | internal void assign(III_psy_xmin iii_psy_xmin) 19 | { 20 | Array.Copy(iii_psy_xmin.l, 0, l, 0, Encoder.SBMAX_l); 21 | for (var i = 0; i < Encoder.SBMAX_s; i++) 22 | for (var j = 0; j < 3; j++) 23 | s[i][j] = iii_psy_xmin.s[i][j]; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GroovyCodecs 2 | A set of C# native implementations of various audio codecs: 3 | - An MP3 encoder / decoder, based on LAME and Jump3r. 4 | - A G.729 encoder / decoder based on libjitsi/Atlassian code. 5 | - A G.711 encoder / decoder 6 | 7 | Released under the LGPL v3.0. 8 | 9 | Compiles to a .NET Standard 2.0 DLL and will run on .NET Framework >= 4.6 and .NET Core >= 2.0. 10 | 11 | Fully managed code, no external OS dependencies, cross platform. 12 | 13 | Not the most polished or optimised code; if you want efficiency you should be using LAME via NAudio or something like that. 14 | 15 | Some of the Jump3r java code was converted to C# using the Free Edition of the Java to C# Converter 16 | produced by Tangible Software Solutions - https://www.tangiblesoftwaresolutions.com 17 | 18 | V0.1.0 (alpha) 19 | - Functional MP3 encoding 20 | - A minimal console test app that will convert a wav file to an mp3 file 21 | 22 | NOTE: this is still alpha code, and the GroovyMp3.dll interface is likely to change 23 | 24 | V0.1.1 (alpha) 25 | - Added G.711 and G.729 codecs 26 | -------------------------------------------------------------------------------- /Mp3/Mp3/IIISideInfo.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using GroovyCodecs.Mp3.Common; 8 | 9 | namespace GroovyCodecs.Mp3.Mp3 10 | { 11 | internal class IIISideInfo 12 | { 13 | 14 | internal int main_data_begin; 15 | 16 | internal int private_bits; 17 | 18 | internal int resvDrain_post; 19 | 20 | internal int resvDrain_pre; 21 | 22 | internal int[][] scfsi = Arrays.ReturnRectangularArray(2, 4); 23 | 24 | internal GrInfo[][] tt = Arrays.ReturnRectangularArray(2, 2); 25 | 26 | internal IIISideInfo() 27 | { 28 | for (var gr = 0; gr < 2; gr++) 29 | for (var ch = 0; ch < 2; ch++) 30 | tt[gr][ch] = new GrInfo(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ShortBlock.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal enum ShortBlock 10 | { 11 | /// 12 | /// LAME may use them, even different block types for L/R. 13 | /// 14 | short_block_allowed, 15 | 16 | /// 17 | /// LAME may use them, but always same block types in L/R. 18 | /// 19 | short_block_coupled, 20 | 21 | /// 22 | /// LAME will not use short blocks, long blocks only. 23 | /// 24 | short_block_dispensed, 25 | 26 | /// 27 | /// LAME will not use long blocks, short blocks only. 28 | /// 29 | short_block_forced 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Mp3/IMp3Encoder.cs: -------------------------------------------------------------------------------- 1 | using GroovyCodecs.Types; 2 | 3 | namespace GroovyCodecs.Mp3 4 | { 5 | public interface IMp3Encoder 6 | { 7 | int EffectiveBitRate { get; } 8 | 9 | int EffectiveChannelMode { get; } 10 | 11 | AudioFormat EffectiveFormat { get; } 12 | 13 | int EffectiveQuality { get; } 14 | 15 | int EffectiveSampleRate { get; } 16 | 17 | bool EffectiveVBR { get; } 18 | 19 | string EncoderVersion { get; } 20 | 21 | int InputBufferSize { get; } 22 | 23 | int MP3BufferSize { get; } 24 | 25 | int OutputBufferSize { get; } 26 | 27 | int PCMBufferSize { get; } 28 | 29 | AudioFormat SourceFormat { get; set; } 30 | 31 | AudioFormat TargetFormat { get; set; } 32 | 33 | void Close(); 34 | 35 | float ConvertByteArrayToFloat(byte[] bytes, int offset, ByteOrder byteOrder); 36 | 37 | int EncodeBuffer(byte[] pcm, int offset, int length, byte[] encoded); 38 | 39 | int EncodeFinish(byte[] encoded); 40 | 41 | void SetFormat(AudioFormat sourceFormat, AudioFormat targetFormat); 42 | } 43 | } -------------------------------------------------------------------------------- /Mp3/Mp3/NsPsy.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using GroovyCodecs.Mp3.Common; 8 | 9 | namespace GroovyCodecs.Mp3.Mp3 10 | { 11 | /// 12 | /// Variables used for --nspsytune 13 | /// @author Ken 14 | /// 15 | internal class NsPsy 16 | { 17 | 18 | /// 19 | /// short block tuning 20 | /// 21 | internal float attackthre; 22 | 23 | internal float attackthre_s; 24 | 25 | internal float[][] last_en_subshort = Arrays.ReturnRectangularArray(4, 9); 26 | 27 | internal int[] lastAttacks = new int[4]; 28 | 29 | internal float[] longfact = new float[Encoder.SBMAX_l]; 30 | 31 | internal float[] pefirbuf = new float[19]; 32 | 33 | internal float[] shortfact = new float[Encoder.SBMAX_s]; 34 | } 35 | } -------------------------------------------------------------------------------- /Mp3/Mp3/PSY.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /// 10 | /// PSY Model related stuff 11 | /// 12 | internal class PSY 13 | { 14 | 15 | /* at transition from one scalefactor band to next */ 16 | /// 17 | /// Band weight long scalefactor bands. 18 | /// 19 | internal float[] bo_l_weight = new float[Encoder.SBMAX_l]; 20 | 21 | /// 22 | /// Band weight short scalefactor bands. 23 | /// 24 | internal float[] bo_s_weight = new float[Encoder.SBMAX_s]; 25 | 26 | /// 27 | /// The dbQ stuff. 28 | /// 29 | internal float mask_adjust; 30 | 31 | /// 32 | /// The dbQ stuff. 33 | /// 34 | internal float mask_adjust_short; 35 | } 36 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ID3TagSpec.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System.Collections.Generic; 8 | using GroovyCodecs.Types; 9 | 10 | namespace GroovyCodecs.Mp3.Mp3 11 | { 12 | 13 | internal sealed class ID3TagSpec 14 | { 15 | 16 | internal string album; 17 | 18 | internal sbyte[] albumart; 19 | 20 | internal MimeType albumart_mimetype; 21 | 22 | internal int albumart_size; 23 | 24 | internal string artist; 25 | 26 | internal string comment; 27 | 28 | internal int flags; 29 | 30 | internal int genre_id3v1; 31 | 32 | internal int num_values; 33 | 34 | internal int padding_size; 35 | 36 | internal string title; 37 | 38 | internal int track_id3v1; 39 | 40 | internal FrameDataNode v2_head, v2_tail; 41 | 42 | internal List values = new List(); 43 | 44 | internal int year; 45 | } 46 | } -------------------------------------------------------------------------------- /Mp3/Mp3/CalcNoiseResult.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class CalcNoiseResult 10 | { 11 | 12 | internal int bits; 13 | 14 | /// 15 | /// max quantization noise 16 | /// 17 | internal float max_noise; 18 | 19 | /// 20 | /// number of quantization noise > masking 21 | /// 22 | internal int over_count; 23 | 24 | /// 25 | /// sum of quantization noise > masking 26 | /// 27 | internal float over_noise; 28 | 29 | /// 30 | /// SSD-like cost of distorted bands 31 | /// 32 | internal int over_SSD; 33 | 34 | /// 35 | /// sum of all quantization noise 36 | /// 37 | internal float tot_noise; 38 | } 39 | } -------------------------------------------------------------------------------- /Mp3/Mp3/HuffCodeTab.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class HuffCodeTab 10 | { 11 | 12 | /// 13 | /// pointer to array[xlen][ylen] 14 | /// 15 | internal readonly int[] hlen; 16 | 17 | /// 18 | /// max number to be stored in linbits 19 | /// 20 | internal readonly int linmax; 21 | 22 | /// 23 | /// pointer to array[xlen][ylen] 24 | /// 25 | internal readonly int[] table; 26 | 27 | /// 28 | /// max. x-index+ 29 | /// 30 | internal readonly int xlen; 31 | 32 | internal HuffCodeTab(int len, int max, int[] tab, int[] hl) 33 | { 34 | xlen = len; 35 | linmax = max; 36 | table = tab; 37 | hlen = hl; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Coder/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using GroovyCodecs.Mp3; 4 | using GroovyCodecs.WavFile; 5 | 6 | namespace GroovyCodecs.Coder 7 | { 8 | class Program 9 | { 10 | private static IMp3Encoder _lameEnc; 11 | 12 | static void Main(string[] args) 13 | { 14 | var files =Directory.GetFiles("../testfiles/", "*.wav", SearchOption.AllDirectories); 15 | 16 | foreach(var file in files) 17 | { 18 | _lameEnc = new Mp3Encoder(); 19 | 20 | var audioFile = new WavReader(); 21 | audioFile.OpenFile(file); 22 | 23 | var srcFormat = audioFile.GetFormat(); 24 | 25 | _lameEnc.SetFormat(srcFormat, srcFormat); 26 | 27 | var inBuffer = audioFile.readWav(); 28 | 29 | var outBuffer = new byte[inBuffer.Length]; 30 | 31 | var timer = new System.Diagnostics.Stopwatch(); 32 | timer.Start(); 33 | var len = _lameEnc.EncodeBuffer(inBuffer, 0, inBuffer.Length, outBuffer); 34 | timer.Stop(); 35 | 36 | _lameEnc.Close(); 37 | 38 | // _lameDec = new LameDecoder(); 39 | 40 | var outFile = File.Create(file + ".mp3"); 41 | outFile.Write(outBuffer, 0, len); 42 | outFile.Close(); 43 | 44 | Console.WriteLine($"Converted {file} to MP3 in {timer.ElapsedMilliseconds / 1000}s"); 45 | } 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Mp3/Mp3/ScaleFac.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | 9 | namespace GroovyCodecs.Mp3.Mp3 10 | { 11 | /// 12 | /// Layer III side information. 13 | /// @author Ken 14 | /// 15 | internal sealed class ScaleFac 16 | { 17 | 18 | internal int[] l = new int[1 + Encoder.SBMAX_l]; 19 | 20 | internal int[] psfb12 = new int[1 + Encoder.PSFB12]; 21 | 22 | internal int[] psfb21 = new int[1 + Encoder.PSFB21]; 23 | 24 | internal int[] s = new int[1 + Encoder.SBMAX_s]; 25 | 26 | internal ScaleFac() 27 | { 28 | } 29 | 30 | internal ScaleFac(int[] arrL, int[] arrS, int[] arr21, int[] arr12) 31 | { 32 | Array.Copy(arrL, 0, l, 0, Math.Min(arrL.Length, l.Length)); 33 | Array.Copy(arrS, 0, s, 0, Math.Min(arrS.Length, s.Length)); 34 | Array.Copy(arr21, 0, psfb21, 0, Math.Min(arr21.Length, psfb21.Length)); 35 | Array.Copy(arr12, 0, psfb12, 0, Math.Min(arr12.Length, psfb12.Length)); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VBRSeekInfo.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class VBRSeekInfo 10 | { 11 | 12 | /// 13 | /// Pointer to our bag. 14 | /// 15 | internal int[] bag; 16 | 17 | internal int nBytesWritten; 18 | 19 | internal int nVbrNumFrames; 20 | 21 | /// 22 | /// Actual position in our bag. 23 | /// 24 | internal int pos; 25 | 26 | /// 27 | /// How many frames we have seen in this chunk. 28 | /// 29 | internal int seen; 30 | 31 | /// 32 | /// Size of our bag. 33 | /// 34 | internal int size; 35 | 36 | /// 37 | /// What we have seen so far. 38 | /// 39 | internal int sum; 40 | 41 | /* VBR tag data */ 42 | internal int TotalFrameSize; 43 | 44 | /// 45 | /// How many frames we want to collect into one chunk. 46 | /// 47 | internal int want; 48 | } 49 | } -------------------------------------------------------------------------------- /Mp3/Mp3/L3Side.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | /* 8 | * Layer 3 side include file 9 | * 10 | * Copyright (c) 1999 Mark Taylor 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Library General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the 24 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 25 | * Boston, MA 02111-1307, USA. 26 | */ 27 | namespace GroovyCodecs.Mp3.Mp3 28 | { 29 | internal class L3Side 30 | { 31 | 32 | /// 33 | /// max scalefactor band, max(SBMAX_l, SBMAX_s*3, (SBMAX_s-3)*3+8) 34 | /// 35 | internal static readonly int SFBMAX = Encoder.SBMAX_s * 3; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Mp3/Mpg/Frame.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mpg 8 | { 9 | 10 | internal class Frame 11 | { 12 | 13 | internal L2Tables.al_table2[] alloc; 14 | 15 | internal int bitrate_index; 16 | 17 | internal int copyright; 18 | 19 | internal int down_sample; 20 | 21 | internal int down_sample_sblimit; 22 | 23 | internal int emphasis; 24 | 25 | internal bool error_protection; // 1 = CRC-16 code following header 26 | 27 | internal int extension; 28 | 29 | internal int framesize; // computed framesize 30 | 31 | /* AF: ADDED FOR LAYER1/LAYER2 */ 32 | internal int II_sblimit; 33 | 34 | internal int jsbound; 35 | 36 | internal int lay; // Layer 37 | 38 | internal int lsf; // 0 = MPEG-1, 1 = MPEG-2/2.5 39 | 40 | internal int mode; 41 | 42 | internal int mode_ext; 43 | 44 | internal bool mpeg25; // 1 = MPEG-2.5, 0 = MPEG-1/2 45 | 46 | internal int original; 47 | 48 | internal int padding; 49 | 50 | internal int sampling_frequency; // sample rate of decompressed audio in Hz 51 | 52 | internal int single; // single channel (monophonic) 53 | 54 | internal int stereo; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /Mp3/Mp3/Util.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | 9 | /* 10 | * lame utility library include file 11 | * 12 | * Copyright (c) 1999 Albert L Faber 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License as published by the Free Software Foundation; either 17 | * version 2 of the License, or (at your option) any later version. 18 | * 19 | * This library is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * Library General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU Lesser General Public 25 | * License along with this library; if not, write to the 26 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 27 | * Boston, MA 02111-1307, USA. 28 | */ 29 | 30 | /* $Id: Util.java,v 1.16 2011/05/24 21:27:00 kenchis Exp $ */ 31 | 32 | namespace GroovyCodecs.Mp3.Mp3 33 | { 34 | 35 | internal class Util 36 | { 37 | 38 | internal const float SQRT2 = 1.41421356237309504880f; 39 | 40 | internal static float FAST_LOG10(float x) 41 | { 42 | return (float)Math.Log10(x); 43 | } 44 | 45 | internal static float FAST_LOG10_X(float x, float y) 46 | { 47 | return (float)Math.Log10(x) * y; 48 | } 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /Mp3/Mp3/MP3Data.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class MP3Data 10 | { 11 | 12 | /// 13 | /// bitrate 14 | /// 15 | internal int bitrate; 16 | 17 | /* this data is not currently computed by the mpglib routines */ 18 | 19 | /// 20 | /// frames decoded counter 21 | /// 22 | internal int framenum; 23 | 24 | /// 25 | /// number of samples per mp3 frame 26 | /// 27 | internal int framesize; 28 | 29 | /// 30 | /// true if header was parsed and following data was computed 31 | /// 32 | internal bool header_parsed; 33 | 34 | /// 35 | /// mp3 frame type 36 | /// 37 | internal int mode; 38 | 39 | /// 40 | /// mp3 frame type 41 | /// 42 | internal int mode_ext; 43 | 44 | /* this data is only computed if mpglib detects a Xing VBR header */ 45 | 46 | /// 47 | /// number of samples in mp3 file. 48 | /// 49 | internal int nsamp; 50 | 51 | /// 52 | /// sample rate 53 | /// 54 | internal int samplerate; 55 | 56 | /// 57 | /// number of channels 58 | /// 59 | internal int stereo; 60 | 61 | /// 62 | /// total number of frames in mp3 file 63 | /// 64 | internal int totalframes; 65 | } 66 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ABRPresets.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class ABRPresets 10 | { 11 | 12 | internal float ath_curve; 13 | 14 | internal float ath_lower; 15 | 16 | internal float interch; 17 | 18 | internal float masking_adj; 19 | 20 | internal float nsbass; 21 | 22 | internal float nsmsfix; 23 | 24 | internal int quant_comp; 25 | 26 | internal int quant_comp_s; 27 | 28 | internal int safejoint; 29 | 30 | internal float scale; 31 | 32 | internal int sfscale; 33 | 34 | /// 35 | /// short threshold 36 | /// 37 | internal float st_lrm; 38 | 39 | internal float st_s; 40 | 41 | internal ABRPresets( 42 | int kbps, 43 | int comp, 44 | int compS, 45 | int joint, 46 | float fix, 47 | float shThreshold, 48 | float shThresholdS, 49 | float bass, 50 | float sc, 51 | float mask, 52 | float lower, 53 | float curve, 54 | float interCh, 55 | int sfScale) 56 | { 57 | quant_comp = comp; 58 | quant_comp_s = compS; 59 | safejoint = joint; 60 | nsmsfix = fix; 61 | st_lrm = shThreshold; 62 | st_s = shThresholdS; 63 | nsbass = bass; 64 | scale = sc; 65 | masking_adj = mask; 66 | ath_lower = lower; 67 | ath_curve = curve; 68 | interch = interCh; 69 | sfscale = sfScale; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VBRTagData.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /// 10 | /// Structure to receive extracted header (toc may be null). 11 | /// @author Ken 12 | /// 13 | internal class VBRTagData 14 | { 15 | 16 | /// 17 | /// Total bit stream bytes from Vbr header data. 18 | /// 19 | protected internal int bytes; 20 | 21 | /// 22 | /// Encoder delay. 23 | /// 24 | internal int encDelay; 25 | 26 | /// 27 | /// Encoder padding added at end of stream. 28 | /// 29 | internal int encPadding; 30 | 31 | /// 32 | /// From Vbr header data. 33 | /// 34 | protected internal int flags; 35 | 36 | /// 37 | /// Total bit stream frames from Vbr header data. 38 | /// 39 | internal int frames; 40 | 41 | /// 42 | /// Size of VBR header, in bytes. 43 | /// 44 | internal int headersize; 45 | 46 | /// 47 | /// From MPEG header 0=MPEG2, 1=MPEG1. 48 | /// 49 | protected internal int hId; 50 | 51 | /// 52 | /// Sample rate determined from MPEG header. 53 | /// 54 | protected internal int samprate; 55 | 56 | /// 57 | /// May be null if toc not desired. 58 | /// 59 | protected internal byte[] toc = new byte[VBRTag.NUMTOCENTRIES]; 60 | 61 | /// 62 | /// Encoded vbr scale from Vbr header data. 63 | /// 64 | protected internal int vbrScale; 65 | } 66 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VBRPresets.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal class VBRPresets 10 | { 11 | 12 | internal float ath_curve; 13 | 14 | internal float ath_lower; 15 | 16 | internal float ath_sensitivity; 17 | 18 | internal int expY; 19 | 20 | internal float interch; 21 | 22 | internal float masking_adj; 23 | 24 | internal float masking_adj_short; 25 | 26 | internal float msfix; 27 | 28 | internal int quant_comp; 29 | 30 | internal int quant_comp_s; 31 | 32 | internal int safejoint; 33 | 34 | internal int sfb21mod; 35 | 36 | /// 37 | /// short threshold 38 | /// 39 | internal float st_lrm; 40 | 41 | internal float st_s; 42 | 43 | internal int vbr_q; 44 | 45 | internal VBRPresets( 46 | int qual, 47 | int comp, 48 | int compS, 49 | int y, 50 | float shThreshold, 51 | float shThresholdS, 52 | float adj, 53 | float adjShort, 54 | float lower, 55 | float curve, 56 | float sens, 57 | float inter, 58 | int joint, 59 | int mod, 60 | float fix) 61 | { 62 | vbr_q = qual; 63 | quant_comp = comp; 64 | quant_comp_s = compS; 65 | expY = y; 66 | st_lrm = shThreshold; 67 | st_s = shThresholdS; 68 | masking_adj = adj; 69 | masking_adj_short = adjShort; 70 | ath_lower = lower; 71 | ath_curve = curve; 72 | ath_sensitivity = sens; 73 | interch = inter; 74 | safejoint = joint; 75 | sfb21mod = mod; 76 | msfix = fix; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Mp3/Common/Arrays.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace GroovyCodecs.Mp3.Common 4 | { 5 | public static class Arrays 6 | { 7 | public static void Fill(T[] array, int start, int end, T value) 8 | { 9 | for (var i = start; i < end; i++) 10 | array[i] = value; 11 | } 12 | 13 | public static void Fill(T[] array, T value) 14 | { 15 | Fill(array, 0, array.Length, value); 16 | } 17 | 18 | public static void Sort(T[] array, int start, int end) 19 | { 20 | var sortedPart = array.Skip(start).Take(array.Length - end).OrderBy(x => x).ToList(); 21 | for (var i = start; i < end; i++) 22 | { 23 | array[i] = sortedPart[i - start]; 24 | } 25 | } 26 | 27 | internal static T[][] ReturnRectangularArray(int size1, int size2) 28 | { 29 | var newArray = new T[size1][]; 30 | for (var array1 = 0; array1 < size1; array1++) 31 | newArray[array1] = new T[size2]; 32 | 33 | return newArray; 34 | } 35 | 36 | internal static T[][][] ReturnRectangularArray(int size1, int size2, int size3) 37 | { 38 | var newArray = new T[size1][][]; 39 | for (var array1 = 0; array1 < size1; array1++) 40 | { 41 | newArray[array1] = new T[size2][]; 42 | if (size3 > 0) 43 | for (var array2 = 0; array2 < size2; array2++) 44 | newArray[array1][array2] = new T[size3]; 45 | } 46 | 47 | return newArray; 48 | } 49 | 50 | internal static T[][][][] ReturnRectangularArray(int size1, int size2, int size3, int size4) 51 | { 52 | var newArray = new T[size1][][][]; 53 | for (var array1 = 0; array1 < size1; array1++) 54 | { 55 | newArray[array1] = new T[size2][][]; 56 | for (var array2 = 0; array2 < size2; array2++) 57 | { 58 | newArray[array1][array2] = new T[size3][]; 59 | for (var array3 = 0; array3 < size3; array3++) 60 | newArray[array1][array2][array3] = new T[size4]; 61 | } 62 | } 63 | 64 | return newArray; 65 | } 66 | 67 | } 68 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ReplayGain.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | internal sealed class ReplayGain 10 | { 11 | 12 | internal int[] A = new int[(int)(GainAnalysis.STEPS_per_dB * GainAnalysis.MAX_dB)]; 13 | 14 | internal int[] B = new int[(int)(GainAnalysis.STEPS_per_dB * GainAnalysis.MAX_dB)]; 15 | 16 | internal int first; 17 | 18 | internal int freqindex; 19 | 20 | /// 21 | /// left input samples, with pre-buffer 22 | /// 23 | internal int linpre; 24 | 25 | internal float[] linprebuf = new float[GainAnalysis.MAX_ORDER * 2]; 26 | 27 | /// 28 | /// left "out" (i.e. post second filter) samples 29 | /// 30 | internal int lout; 31 | 32 | internal float[] loutbuf = new float[GainAnalysis.MAX_SAMPLES_PER_WINDOW + GainAnalysis.MAX_ORDER]; 33 | 34 | /// 35 | /// left "first step" (i.e. post first filter) samples 36 | /// 37 | internal int lstep; 38 | 39 | internal float[] lstepbuf = new float[GainAnalysis.MAX_SAMPLES_PER_WINDOW + GainAnalysis.MAX_ORDER]; 40 | 41 | internal double lsum; 42 | 43 | /// 44 | /// right input samples ... 45 | /// 46 | internal int rinpre; 47 | 48 | internal float[] rinprebuf = new float[GainAnalysis.MAX_ORDER * 2]; 49 | 50 | internal int rout; 51 | 52 | internal float[] routbuf = new float[GainAnalysis.MAX_SAMPLES_PER_WINDOW + GainAnalysis.MAX_ORDER]; 53 | 54 | internal int rstep; 55 | 56 | internal float[] rstepbuf = new float[GainAnalysis.MAX_SAMPLES_PER_WINDOW + GainAnalysis.MAX_ORDER]; 57 | 58 | internal double rsum; 59 | 60 | /// 61 | /// number of samples required to reach number of milliseconds required 62 | /// for RMS window 63 | /// 64 | internal int sampleWindow; 65 | 66 | internal int totsamp; 67 | } 68 | } -------------------------------------------------------------------------------- /WavFile/WavReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using GroovyCodecs.Types; 4 | 5 | namespace GroovyCodecs.WavFile 6 | { 7 | public class WavReader 8 | { 9 | FileStream _fs; 10 | BinaryReader _reader; 11 | private int chunkID; 12 | private int fileSize; 13 | private int riffType; 14 | private int fmtID; 15 | private int fmtSize; 16 | private short fmtCode; 17 | private short channels; 18 | private int sampleRate; 19 | private int byteRate; 20 | private short fmtBlockAlign; 21 | private short bitDepth; 22 | private short fmtExtraSize; 23 | private int dataID; 24 | private int bytes; 25 | 26 | public bool OpenFile(string filename) 27 | { 28 | if (!File.Exists(filename)) 29 | { 30 | return false; 31 | } 32 | 33 | try 34 | { 35 | _fs = File.Open(filename, FileMode.Open); 36 | _reader = new BinaryReader(_fs); 37 | 38 | // chunk 0 39 | chunkID = _reader.ReadInt32(); 40 | fileSize = _reader.ReadInt32(); 41 | riffType = _reader.ReadInt32(); 42 | 43 | 44 | // chunk 1 45 | fmtID = _reader.ReadInt32(); 46 | fmtSize = _reader.ReadInt32(); // bytes for this chunk 47 | fmtCode = _reader.ReadInt16(); 48 | channels = _reader.ReadInt16(); 49 | sampleRate = _reader.ReadInt32(); 50 | byteRate = _reader.ReadInt32(); 51 | fmtBlockAlign = _reader.ReadInt16(); 52 | bitDepth = _reader.ReadInt16(); 53 | 54 | if (fmtSize == 18) 55 | { 56 | // Read any extra values 57 | fmtExtraSize = _reader.ReadInt16(); 58 | _reader.ReadBytes(fmtExtraSize); 59 | } 60 | 61 | // chunk 2 62 | dataID = _reader.ReadInt32(); 63 | bytes = _reader.ReadInt32(); 64 | 65 | while (dataID != 0x61746164) 66 | { 67 | byte[] byteArray = _reader.ReadBytes(bytes); 68 | dataID = _reader.ReadInt32(); 69 | bytes = _reader.ReadInt32(); 70 | } 71 | } 72 | catch (Exception ex) 73 | { 74 | return false; 75 | } 76 | 77 | return true; 78 | } 79 | 80 | public AudioFormat GetFormat() 81 | { 82 | return new AudioFormat 83 | { 84 | BitsPerSample = bitDepth, 85 | 86 | BlockAlign = fmtBlockAlign, 87 | 88 | Channels = channels, 89 | 90 | SampleRate = sampleRate, 91 | 92 | IsFloatingPoint = fmtCode == 3, 93 | }; 94 | } 95 | 96 | 97 | public byte[] readWav() 98 | { 99 | byte[] byteArray = _reader.ReadBytes(bytes); 100 | _reader.Close(); 101 | _fs.Dispose(); 102 | 103 | return byteArray; 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /G729/Conversion.txt: -------------------------------------------------------------------------------- 1 | /* See: https://github.com/jitsi/libjitsi 2 | * 3 | * Converted to C# from Java (from C) 4 | * The following transformations have been used... 5 | * 6 | // Replace "extends" with ":" in class declaration 7 | // Remove all "throws" declarations 8 | // Remove all "package" lines 9 | // Remove all "import" lines 10 | // Remove all "@Override" qualifiers 11 | // Remove all "final" qualifiers in declarations 12 | // Change "0." shorthand to "0.0" for float assignments 13 | // In method signatures, move the array "[]" declarations from the variable to the type 14 | // Fix all scope issues (lots default to private and need changing to public) 15 | // Import System.Math where prompted, and rename the library function called (just capitalize the first letter!) 16 | // Remove all "@SuppressWarnings("resource")" lines 17 | // ".length" to ".Length" for arrays 18 | // "System.out.printf" to "Console.Write" 19 | // Replace "System.exit" with "Environment.Exit" 20 | // Can't do a labelled break in C# :( replace with a "goto"!! 21 | // "InputStream" and "OutputStream" to "Stream" in method declarations 22 | // "new FileInputStream(args[0])" to "new FileStream(args[0], FileMode.Open)" 23 | // "new FileOutputStream(args[1])" to "new FileStream(args[1], FileMode.Create)" 24 | // ".close" to ".Close" for FileStreams 25 | // Can't do "new float[Ld8k.MA_NP][Ld8k.M];", need "new float[Ld8k.MA_NP][];" instead, then add an initialize in the constructor as: 26 | // public Lspdec() 27 | // { 28 | // // need this to initialize freq_prev 29 | // for (var i = 0; i < freq_prev.Length; i++ ) 30 | // freq_prev[i] = new float[M]; 31 | // } 32 | // Variable named 'in' renamed to 'in_' as 'in' is a reserved word in C# 33 | // Variable named 'out' renamed to 'out_' as 'out' is a reserved word in C# 34 | // Replace Map<,> with Dictionary<,>, Map.get with Dictionary.TryGetValue 35 | // Integer.parse becomes Int32.Parse 36 | // System.arraycopy to Array.Copy 37 | // Arrays.fill - new static method to implement: 38 | // public static void Fill(T[] array, int start, int end, T value) 39 | // { 40 | // for (int i = start; i < end; i++) 41 | // { 42 | // array[i] = value; 43 | // } 44 | // } 45 | // The java shift right operator with zero fill is not available in c#; replace with: 46 | // private static int ZFRS(int i, int j) 47 | // { 48 | // bool maskIt = (i < 0); 49 | // i = i >> j; 50 | // if (maskIt) 51 | // i &= 0x7FFFFFFF; 52 | // return i; 53 | // } 54 | // Multi-dimensional static array declarations need lots of extra "new float[] { }" things adding 55 | */ 56 | -------------------------------------------------------------------------------- /Mp3/Mp3/ATH.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mp3 8 | { 9 | /// 10 | /// ATH related stuff, if something new ATH related has to be added, please plug 11 | /// it here into the ATH. 12 | /// 13 | internal class ATH 14 | { 15 | 16 | /// 17 | /// factor for tuning the (sample power) point below which adaptive threshold 18 | /// of hearing adjustment occurs 19 | /// 20 | internal float aaSensitivityP; 21 | 22 | /// 23 | /// Lowering based on peak volume, 1 = no lowering. 24 | /// 25 | internal float adjust; 26 | 27 | /// 28 | /// Limit for dynamic ATH adjust. 29 | /// 30 | internal float adjustLimit; 31 | 32 | /// 33 | /// ATH for long block convolution bands. 34 | /// 35 | internal float[] cb_l = new float[Encoder.CBANDS]; 36 | 37 | /// 38 | /// ATH for short block convolution bands. 39 | /// 40 | internal float[] cb_s = new float[Encoder.CBANDS]; 41 | 42 | /// 43 | /// Determined to lower x dB each second. 44 | /// 45 | internal float decay; 46 | 47 | /// 48 | /// Equal loudness weights (based on ATH). 49 | /// 50 | internal float[] eql_w = new float[Encoder.BLKSIZE / 2]; 51 | 52 | /// 53 | /// Lowest ATH value. 54 | /// 55 | internal float floor; 56 | 57 | /// 58 | /// ATH for sfbs in long blocks. 59 | /// 60 | internal float[] l = new float[Encoder.SBMAX_l]; 61 | 62 | /// 63 | /// ATH for partitioned sfb12 in short blocks. 64 | /// 65 | internal float[] psfb12 = new float[Encoder.PSFB12]; 66 | 67 | /// 68 | /// ATH for partitioned sfb21 in long blocks. 69 | /// 70 | internal float[] psfb21 = new float[Encoder.PSFB21]; 71 | 72 | /// 73 | /// ATH for sfbs in short blocks. 74 | /// 75 | internal float[] s = new float[Encoder.SBMAX_s]; 76 | 77 | /// 78 | /// Method for the auto adjustment. 79 | /// 80 | internal int useAdjust; 81 | } 82 | } -------------------------------------------------------------------------------- /Mp3/Mpg/MPG123.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Mp3.Mpg 8 | { 9 | internal class MPG123 10 | { 11 | 12 | internal class gr_info_s 13 | { 14 | 15 | internal int big_values; 16 | 17 | internal int block_type; 18 | 19 | internal int count1table_select; 20 | 21 | internal float[][] full_gain = new float[3][]; 22 | 23 | internal int[] full_gainPos = new int[3]; 24 | 25 | internal int maxb; 26 | 27 | internal int[] maxband = new int[3]; 28 | 29 | internal int maxbandl; 30 | 31 | internal int mixed_block_flag; 32 | 33 | internal int part2_3_length; 34 | 35 | internal float[] pow2gain; 36 | 37 | internal int pow2gainPos; 38 | 39 | internal int preflag; 40 | 41 | internal int region1start; 42 | 43 | internal int region2start; 44 | 45 | internal int scalefac_compress; 46 | 47 | internal int scalefac_scale; 48 | 49 | internal int scfsi; 50 | 51 | internal int[] subblock_gain = new int[3]; 52 | 53 | internal int[] table_select = new int[3]; 54 | } 55 | 56 | internal class grT 57 | { 58 | 59 | internal gr_info_s[] gr = new gr_info_s[2]; 60 | 61 | internal grT() 62 | { 63 | gr[0] = new gr_info_s(); 64 | gr[1] = new gr_info_s(); 65 | } 66 | } 67 | 68 | internal class III_sideinfo 69 | { 70 | 71 | internal grT[] ch = new grT[2]; 72 | 73 | internal int main_data_begin; 74 | 75 | internal int private_bits; 76 | 77 | internal III_sideinfo() 78 | { 79 | ch[0] = new grT(); 80 | ch[1] = new grT(); 81 | } 82 | } 83 | 84 | internal const double M_PI = 3.14159265358979323846; 85 | 86 | internal const double M_SQRT2 = 1.41421356237309504880; 87 | 88 | internal const int MAXFRAMESIZE = 2880; 89 | 90 | internal const int MPG_MD_DUAL_CHANNEL = 2; 91 | 92 | internal const int MPG_MD_JOINT_STEREO = 1; 93 | 94 | internal const int MPG_MD_MONO = 3; 95 | 96 | internal const int MPG_MD_STEREO = 0; 97 | 98 | internal const int SBLIMIT = 32; 99 | 100 | /* AF: ADDED FOR LAYER1/LAYER2 */ 101 | internal const int SCALE_BLOCK = 12; 102 | 103 | internal const int SSLIMIT = 18; 104 | } 105 | 106 | } -------------------------------------------------------------------------------- /Types/Version.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | namespace GroovyCodecs.Types 8 | { 9 | public class Mp3Version 10 | { 11 | 12 | /// 13 | /// Major version number. 14 | /// 15 | private const int LAME_MAJOR_VERSION = 3; 16 | 17 | /// 18 | /// Minor version number. 19 | /// 20 | private const int LAME_MINOR_VERSION = 98; 21 | 22 | /// 23 | /// Patch level. 24 | /// 25 | private const int LAME_PATCH_VERSION = 4; 26 | 27 | /// 28 | /// URL for the LAME website. 29 | /// 30 | private const string LAME_URL = "http://www.mp3dev.org/"; 31 | 32 | /// 33 | /// Major version number. 34 | /// 35 | private const int PSY_MAJOR_VERSION = 0; 36 | 37 | /// 38 | /// Minor version number. 39 | /// 40 | private const int PSY_MINOR_VERSION = 93; 41 | 42 | /// 43 | /// A string which describes the version of LAME. 44 | /// 45 | /// string which describes the version of LAME 46 | public string LameVersion => LAME_MAJOR_VERSION + "." + LAME_MINOR_VERSION + "." + LAME_PATCH_VERSION; 47 | 48 | /// 49 | /// The short version of the LAME version string. 50 | /// 51 | /// short version of the LAME version string 52 | public string LameShortVersion => LAME_MAJOR_VERSION + "." + LAME_MINOR_VERSION + "." + LAME_PATCH_VERSION; 53 | 54 | /// 55 | /// The shortest version of the LAME version string. 56 | /// 57 | /// shortest version of the LAME version string 58 | public string LameVeryShortVersion => "LAME" + LAME_MAJOR_VERSION + "." + LAME_MINOR_VERSION + "r"; 59 | 60 | /// 61 | /// String which describes the version of GPSYCHO 62 | /// 63 | /// string which describes the version of GPSYCHO 64 | public string PsyVersion => PSY_MAJOR_VERSION + "." + PSY_MINOR_VERSION; 65 | 66 | /// 67 | /// String which is a URL for the LAME website. 68 | /// 69 | /// string which is a URL for the LAME website 70 | public string LameUrl => LAME_URL; 71 | 72 | /// 73 | /// Quite useless for a java version, however we are compatible ;-) 74 | /// 75 | /// "32bits" 76 | public string LameOsBitness => "32bits"; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /G729/Codec/PParity.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | namespace GroovyCodecs.G729.Codec 26 | { 27 | internal class PParity 28 | { 29 | 30 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 31 | /* 32 | ITU-T G.729 Annex C - Reference C code for floating point 33 | implementation of G.729 34 | Version 1.01 of 15.September.98 35 | */ 36 | 37 | /* 38 | ---------------------------------------------------------------------- 39 | COPYRIGHT NOTICE 40 | ---------------------------------------------------------------------- 41 | ITU-T G.729 Annex C ANSI C source code 42 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 43 | Sherbrooke. All rights reserved. 44 | 45 | ---------------------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | File : P_PARITY.C 50 | Used for the floating point version of both 51 | G.729 main body and G.729A 52 | */ 53 | 54 | /** 55 | * Compute parity bit for first 6 MSBs 56 | * 57 | * @param pitch_index input : index for which parity is computed 58 | * @return parity bit (XOR of 6 MSB bits) 59 | */ 60 | 61 | public static int parity_pitch( 62 | int pitch_index 63 | ) 64 | { 65 | int temp, sum, i, bit; 66 | 67 | temp = pitch_index >> 1; 68 | 69 | sum = 1; 70 | for (i = 0; i <= 5; i++) 71 | { 72 | temp >>= 1; 73 | bit = temp & 1; 74 | sum = sum + bit; 75 | } 76 | 77 | sum = sum & 1; 78 | return sum; 79 | } 80 | 81 | /** 82 | * Check parity of index with transmitted parity 83 | * 84 | * @param pitch_index input : index of parameter 85 | * @param parity input : parity bit 86 | * @return 0 = no error, 1= error 87 | */ 88 | 89 | public static int check_parity_pitch( 90 | int pitch_index, 91 | int parity 92 | ) 93 | { 94 | int temp, sum, i, bit; 95 | temp = pitch_index >> 1; 96 | 97 | sum = 1; 98 | for (i = 0; i <= 5; i++) 99 | { 100 | temp >>= 1; 101 | bit = temp & 1; 102 | sum = sum + bit; 103 | } 104 | 105 | sum += parity; 106 | sum = sum & 1; 107 | return sum; 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /G729/Codec/DeAcelp.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | namespace GroovyCodecs.G729.Codec 26 | { 27 | internal class DeAcelp 28 | { 29 | 30 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 31 | /* 32 | ITU-T G.729 Annex C - Reference C code for floating point 33 | implementation of G.729 34 | Version 1.01 of 15.September.98 35 | */ 36 | 37 | /* 38 | ---------------------------------------------------------------------- 39 | COPYRIGHT NOTICE 40 | ---------------------------------------------------------------------- 41 | ITU-T G.729 Annex C ANSI C source code 42 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 43 | Sherbrooke. All rights reserved. 44 | 45 | ---------------------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | File : DE_ACELP.C 50 | Used for the floating point version of both 51 | G.729 main body and G.729A 52 | */ 53 | 54 | /** 55 | * Algebraic codebook decoder. 56 | * 57 | * @param sign input : signs of 4 pulses 58 | * @param index input : positions of 4 pulses 59 | * @param cod output: innovative codevector 60 | */ 61 | 62 | public static void decod_ACELP( 63 | int sign, 64 | int index, 65 | float[] cod 66 | ) 67 | { 68 | var L_SUBFR = Ld8k.L_SUBFR; 69 | 70 | var pos = new int[4]; 71 | int i, j; 72 | 73 | /* decode the positions of 4 pulses */ 74 | 75 | i = index & 7; 76 | pos[0] = i * 5; 77 | 78 | index >>= 3; 79 | i = index & 7; 80 | pos[1] = i * 5 + 1; 81 | 82 | index >>= 3; 83 | i = index & 7; 84 | pos[2] = i * 5 + 2; 85 | 86 | index >>= 3; 87 | j = index & 1; 88 | index >>= 1; 89 | i = index & 7; 90 | pos[3] = i * 5 + 3 + j; 91 | 92 | /* find the algebraic codeword */ 93 | 94 | for (i = 0; i < L_SUBFR; i++) cod[i] = 0; 95 | 96 | /* decode the signs of 4 pulses */ 97 | 98 | for (j = 0; j < 4; j++) 99 | { 100 | 101 | i = sign & 1; 102 | sign >>= 1; 103 | 104 | if (i != 0) 105 | cod[pos[j]] = 1.0f; 106 | else 107 | cod[pos[j]] = -1.0f; 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ShortBlockConstrain.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using System.Diagnostics; 9 | 10 | namespace GroovyCodecs.Mp3.Mp3 11 | { 12 | internal sealed class ShortBlockConstrain : VBRQuantize.alloc_sf_f 13 | { 14 | /// 15 | private readonly VBRQuantize vbrQuantize; 16 | 17 | /// 18 | internal ShortBlockConstrain(VBRQuantize vbrQuantize) 19 | { 20 | this.vbrQuantize = vbrQuantize; 21 | } 22 | 23 | /// 24 | /// **************************************************************** 25 | /// short block scalefacs 26 | /// ***************************************************************** 27 | /// 28 | public void alloc(VBRQuantize.algo_t that, int[] vbrsf, int[] vbrsfmin, int vbrmax) 29 | { 30 | 31 | var cod_info = that.cod_info; 32 | 33 | var gfc = that.gfc; 34 | 35 | var maxminsfb = that.mingain_l; 36 | int mover, maxover0 = 0, maxover1 = 0, delta = 0; 37 | int v, v0, v1; 38 | int sfb; 39 | 40 | var psymax = cod_info.psymax; 41 | 42 | for (sfb = 0; sfb < psymax; ++sfb) 43 | { 44 | Debug.Assert(vbrsf[sfb] >= vbrsfmin[sfb]); 45 | v = vbrmax - vbrsf[sfb]; 46 | if (delta < v) 47 | delta = v; 48 | 49 | v0 = v - (4 * 14 + 2 * VBRQuantize.max_range_short[sfb]); 50 | v1 = v - (4 * 14 + 4 * VBRQuantize.max_range_short[sfb]); 51 | if (maxover0 < v0) 52 | maxover0 = v0; 53 | 54 | if (maxover1 < v1) 55 | maxover1 = v1; 56 | } 57 | 58 | if (gfc.noise_shaping == 2) 59 | mover = Math.Min(maxover0, maxover1); 60 | else 61 | mover = maxover0; 62 | 63 | if (delta > mover) 64 | delta = mover; 65 | 66 | vbrmax -= delta; 67 | maxover0 -= mover; 68 | maxover1 -= mover; 69 | 70 | if (maxover0 == 0) 71 | cod_info.scalefac_scale = 0; 72 | else if (maxover1 == 0) 73 | cod_info.scalefac_scale = 1; 74 | 75 | if (vbrmax < maxminsfb) 76 | vbrmax = maxminsfb; 77 | 78 | cod_info.global_gain = vbrmax; 79 | 80 | if (cod_info.global_gain < 0) 81 | cod_info.global_gain = 0; 82 | else if (cod_info.global_gain > 255) 83 | cod_info.global_gain = 255; 84 | 85 | { 86 | var sf_temp = new int[L3Side.SFBMAX]; 87 | for (sfb = 0; sfb < L3Side.SFBMAX; ++sfb) 88 | sf_temp[sfb] = vbrsf[sfb] - vbrmax; 89 | 90 | vbrQuantize.set_subblock_gain(cod_info, that.mingain_s, sf_temp); 91 | vbrQuantize.set_scalefacs(cod_info, vbrsfmin, sf_temp, VBRQuantize.max_range_short); 92 | } 93 | Debug.Assert(vbrQuantize.checkScalefactor(cod_info, vbrsfmin)); 94 | 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /G729/Codec/PostPro.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Post-processing of output speech. 24 | * 2nd order high pass filter with cut off frequency at 100 Hz. 25 | * Designed with SPPACK efi command -40 dB att, 0.25 ri. 26 | * 27 | * Algorithm: 28 | *
 29 |  *  y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]
 30 |  *                   + a[1]*y[i-1] + a[2]*y[i-2];
 31 |  *
 32 |  *     b[3] = {0.93980581E+00, -0.18795834E+01,  0.93980581E+00};
 33 |  *     a[3] = {0.10000000E+01, +0.19330735E+01, -0.93589199E+00};
 34 |  * 
35 | * 36 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 37 | */ 38 | namespace GroovyCodecs.G729.Codec 39 | { 40 | internal class PostPro 41 | { 42 | 43 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 44 | /* 45 | ITU-T G.729 Annex C - Reference C code for floating point 46 | implementation of G.729 47 | Version 1.01 of 15.September.98 48 | */ 49 | 50 | /* 51 | ---------------------------------------------------------------------- 52 | COPYRIGHT NOTICE 53 | ---------------------------------------------------------------------- 54 | ITU-T G.729 Annex C ANSI C source code 55 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 56 | Sherbrooke. All rights reserved. 57 | 58 | ---------------------------------------------------------------------- 59 | */ 60 | 61 | /* 62 | File : POST_PRO.C 63 | Used for the floating point version of both 64 | G.729 main body and G.729A 65 | */ 66 | 67 | /** 68 | * High-pass fir memory 69 | */ 70 | private float x0, x1; 71 | 72 | /** 73 | * High-pass iir memory 74 | */ 75 | private float y1, y2; 76 | 77 | /** 78 | * Init Post Process. 79 | */ 80 | 81 | public void init_post_process() 82 | { 83 | x0 = x1 = 0.0f; 84 | y2 = y1 = 0.0f; 85 | } 86 | 87 | /** 88 | * Post Process 89 | * 90 | * @param signal (i/o) : signal 91 | * @param lg (i) : lenght of signal 92 | */ 93 | 94 | public void post_process( 95 | float[] signal, 96 | int lg 97 | ) 98 | { 99 | var a100 = TabLd8k.a100; 100 | var b100 = TabLd8k.b100; 101 | 102 | int i; 103 | float x2; 104 | float y0; 105 | 106 | for (i = 0; i < lg; i++) 107 | { 108 | x2 = x1; 109 | x1 = x0; 110 | x0 = signal[i]; 111 | 112 | y0 = y1 * a100[1] + y2 * a100[2] + x0 * b100[0] + x1 * b100[1] + x2 * b100[2]; 113 | 114 | signal[i] = y0; 115 | y2 = y1; 116 | y1 = y0; 117 | } 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /G729/Codec/PredLt3.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | namespace GroovyCodecs.G729.Codec 26 | { 27 | internal class PredLt3 28 | { 29 | 30 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 31 | /* 32 | ITU-T G.729 Annex C - Reference C code for floating point 33 | implementation of G.729 34 | Version 1.01 of 15.September.98 35 | */ 36 | 37 | /* 38 | ---------------------------------------------------------------------- 39 | COPYRIGHT NOTICE 40 | ---------------------------------------------------------------------- 41 | ITU-T G.729 Annex C ANSI C source code 42 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 43 | Sherbrooke. All rights reserved. 44 | 45 | ---------------------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | File : PRED_LT3.C 50 | Used for the floating point version of both 51 | G.729 main body and G.729A 52 | */ 53 | 54 | /** 55 | * Compute the result of long term prediction with fractional 56 | * interpolation of resolution 1/3. 57 | * 58 | * On return exc[0..L_subfr-1] contains the interpolated signal 59 | * (adaptive codebook excitation) 60 | * 61 | * @param exc in/out: excitation vector, exc[0:l_sub-1] = out 62 | * @param exc_offset input: excitation vector offset 63 | * @param t0 input : pitch lag 64 | * @param frac input : Fraction of pitch lag (-1, 0, 1) / 3 65 | * @param l_subfr input : length of subframe. 66 | */ 67 | 68 | public static void pred_lt_3( 69 | float[] exc, 70 | int exc_offset, 71 | int t0, 72 | int frac, 73 | int l_subfr 74 | ) 75 | { 76 | var L_INTER10 = Ld8k.L_INTER10; 77 | var UP_SAMP = Ld8k.UP_SAMP; 78 | var inter_3l = TabLd8k.inter_3l; 79 | 80 | int i, j, k; 81 | float s; 82 | int x0, x1, x2, c1, c2; 83 | 84 | x0 = exc_offset - t0; 85 | 86 | frac = -frac; 87 | if (frac < 0) 88 | { 89 | frac += UP_SAMP; 90 | x0--; 91 | } 92 | 93 | for (j = 0; j < l_subfr; j++) 94 | { 95 | x1 = x0; 96 | x0++; 97 | x2 = x0; 98 | c1 = frac; 99 | c2 = UP_SAMP - frac; 100 | 101 | s = 0.0f; 102 | for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP) 103 | s += exc[x1 - i] * inter_3l[c1 + k] + exc[x2 + i] * inter_3l[c2 + k]; 104 | 105 | exc[exc_offset + j] = s; 106 | } 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /G729/Codec/PreProc.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Preprocessing of input speech. 24 | * - 2nd order high pass filter with cut off frequency at 140 Hz. 25 | * 26 | * 2nd order high pass filter with cut off frequency at 140 Hz. 27 | * Designed with SPPACK efi command -40 dB att, 0.25 ri. 28 | * 29 | * Algorithm: 30 | *
 31 |  *  y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]
 32 |  *                   + a[1]*y[i-1] + a[2]*y[i-2];
 33 |  *
 34 |  *     b[3] = {0.92727435E+00, -0.18544941E+01, 0.92727435E+00};
 35 |  *     a[3] = {0.10000000E+01, 0.19059465E+01, -0.91140240E+00};
 36 |  * 
37 | * 38 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 39 | */ 40 | namespace GroovyCodecs.G729.Codec 41 | { 42 | internal class PreProc 43 | { 44 | 45 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 46 | /* 47 | ITU-T G.729 Annex C - Reference C code for floating point 48 | implementation of G.729 49 | Version 1.01 of 15.September.98 50 | */ 51 | 52 | /* 53 | ---------------------------------------------------------------------- 54 | COPYRIGHT NOTICE 55 | ---------------------------------------------------------------------- 56 | ITU-T G.729 Annex C ANSI C source code 57 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 58 | Sherbrooke. All rights reserved. 59 | 60 | ---------------------------------------------------------------------- 61 | */ 62 | 63 | /* 64 | File : PRE_PROC.C 65 | Used for the floating point version of both 66 | G.729 main body and G.729A 67 | */ 68 | 69 | /** 70 | * High-pass fir memory 71 | */ 72 | private float x0, x1; 73 | 74 | /** 75 | * High-pass iir memory 76 | */ 77 | private float y1, y2; 78 | 79 | /** 80 | * Init Pre Process 81 | */ 82 | 83 | public void init_pre_process() 84 | { 85 | x0 = x1 = 0.0f; 86 | y2 = y1 = 0.0f; 87 | } 88 | 89 | /** 90 | * Pre Process 91 | * 92 | * @param signal (i/o) : signal 93 | * @param signal_offset (input) : signal offset 94 | * @param lg (i) : length of signal 95 | */ 96 | 97 | public void pre_process( 98 | float[] signal, 99 | int signal_offset, 100 | int lg 101 | ) 102 | { 103 | var a140 = TabLd8k.a140; 104 | var b140 = TabLd8k.b140; 105 | 106 | float x2; 107 | float y0; 108 | 109 | for (int i = signal_offset, toIndex = lg + signal_offset; i < toIndex; i++) 110 | { 111 | x2 = x1; 112 | x1 = x0; 113 | x0 = signal[i]; 114 | 115 | y0 = y1 * a140[1] + y2 * a140[2] + x0 * b140[0] + x1 * b140[1] + x2 * b140[2]; 116 | 117 | signal[i] = y0; 118 | y2 = y1; 119 | y1 = y0; 120 | } 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /G729/Codec/CorFunc.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Functions corr_xy2() and cor_h_x(). 24 | * 25 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 26 | */ 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class CorFunc 30 | { 31 | 32 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 33 | /* 34 | ITU-T G.729 Annex C - Reference C code for floating point 35 | implementation of G.729 36 | Version 1.01 of 15.September.98 37 | */ 38 | 39 | /* 40 | ---------------------------------------------------------------------- 41 | COPYRIGHT NOTICE 42 | ---------------------------------------------------------------------- 43 | ITU-T G.729 Annex C ANSI C source code 44 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 45 | Sherbrooke. All rights reserved. 46 | 47 | ---------------------------------------------------------------------- 48 | */ 49 | 50 | /* 51 | File : COR_FUNC.C 52 | Used for the floating point version of both 53 | G.729 main body and G.729A 54 | */ 55 | 56 | /** 57 | * Compute the correlation products needed for gain computation. 58 | * 59 | * @param xn input : target vector x[0:l_subfr] 60 | * @param y1 input : filtered adaptive codebook vector 61 | * @param y2 input : filtered 1st codebook innovation 62 | * @param g_coeff output: , -2 , and 2 63 | */ 64 | 65 | public static void corr_xy2( 66 | float[] xn, 67 | float[] y1, 68 | float[] y2, 69 | float[] g_coeff 70 | ) 71 | { 72 | var L_SUBFR = Ld8k.L_SUBFR; 73 | 74 | float y2y2, xny2, y1y2; 75 | int i; 76 | 77 | y2y2 = 0.01f; 78 | for (i = 0; i < L_SUBFR; i++) y2y2 += y2[i] * y2[i]; 79 | g_coeff[2] = y2y2; 80 | 81 | xny2 = 0.01f; 82 | for (i = 0; i < L_SUBFR; i++) xny2 += xn[i] * y2[i]; 83 | g_coeff[3] = -2.0f * xny2; 84 | 85 | y1y2 = 0.01f; 86 | for (i = 0; i < L_SUBFR; i++) y1y2 += y1[i] * y2[i]; 87 | g_coeff[4] = 2.0f * y1y2; 88 | } 89 | 90 | /** 91 | * Compute correlations of input response h[] with the target vector X[]. 92 | * 93 | * @param h (i) :Impulse response of filters 94 | * @param x (i) :Target vector 95 | * @param d (o) :Correlations between h[] and x[] 96 | */ 97 | 98 | public static void cor_h_x( 99 | float[] h, 100 | float[] x, 101 | float[] d 102 | ) 103 | { 104 | var L_SUBFR = Ld8k.L_SUBFR; 105 | 106 | int i, j; 107 | float s; 108 | 109 | for (i = 0; i < L_SUBFR; i++) 110 | { 111 | s = 0.0f; 112 | for (j = i; j < L_SUBFR; j++) 113 | s += x[j] * h[j - i]; 114 | d[i] = s; 115 | } 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /G711/uLaw/ULawDecoder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2011, Red Hat, Inc. and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * This is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this software; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | */ 22 | 23 | /* 24 | * 15/07/13 - Change notice: 25 | * This file has been modified by Mobius Software Ltd. 26 | * For more information please visit http://www.mobius.ua 27 | */ 28 | /** 29 | * 30 | * @author Oleg Kulikov 31 | */ 32 | /* 33 | * Converted to C# for GroovyG7xx, see https://github.com/jongoochgithub/GroovyCodecs 34 | */ 35 | 36 | namespace GroovyCodecs.G711.uLaw 37 | { 38 | 39 | public class ULawDecoder 40 | { 41 | private static short[] _uLawDecompressTable = { 42 | -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956, 43 | -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764, 44 | -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412, 45 | -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316, 46 | -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140, 47 | -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092, 48 | -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004, 49 | -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980, 50 | -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436, 51 | -1372, -1308, -1244, -1180, -1116, -1052, -988, -924, 52 | -876, -844, -812, -780, -748, -716, -684, -652, 53 | -620, -588, -556, -524, -492, -460, -428, -396, 54 | -372, -356, -340, -324, -308, -292, -276, -260, 55 | -244, -228, -212, -196, -180, -164, -148, -132, 56 | -120, -112, -104, -96, -88, -80, -72, -64, 57 | -56, -48, -40, -32, -24, -16, -8, 0, 58 | 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, 59 | 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, 60 | 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, 61 | 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, 62 | 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, 63 | 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, 64 | 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, 65 | 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, 66 | 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, 67 | 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, 68 | 876, 844, 812, 780, 748, 716, 684, 652, 69 | 620, 588, 556, 524, 492, 460, 428, 396, 70 | 372, 356, 340, 324, 308, 292, 276, 260, 71 | 244, 228, 212, 196, 180, 164, 148, 132, 72 | 120, 112, 104, 96, 88, 80, 72, 64, 73 | 56, 48, 40, 32, 24, 16, 8, 0 74 | }; 75 | 76 | public short[] Process(byte[] frame) 77 | { 78 | var sourceLen = frame.Length; 79 | var res = new short[sourceLen]; 80 | 81 | for (var i = 0; i < sourceLen; i++) 82 | res[i] = _uLawDecompressTable[frame[i] & 0xff]; 83 | 84 | return res; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /G729/Codec/DecLag3.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | namespace GroovyCodecs.G729.Codec 26 | { 27 | internal class DecLag3 28 | { 29 | 30 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 31 | /* 32 | ITU-T G.729 Annex C - Reference C code for floating point 33 | implementation of G.729 34 | Version 1.01 of 15.September.98 35 | */ 36 | 37 | /* 38 | ---------------------------------------------------------------------- 39 | COPYRIGHT NOTICE 40 | ---------------------------------------------------------------------- 41 | ITU-T G.729 Annex C ANSI C source code 42 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 43 | Sherbrooke. All rights reserved. 44 | 45 | ---------------------------------------------------------------------- 46 | */ 47 | 48 | /* 49 | File : DEC_LAG3.C 50 | Used for the floating point version of both 51 | G.729 main body and G.729A 52 | */ 53 | 54 | /** 55 | * Decoding of fractional pitch lag with 1/3 resolution. 56 | * See the source for more details about the encoding procedure. 57 | * 58 | * @param index input : received pitch index 59 | * @param pit_min input : minimum pitch lag 60 | * @param pit_max input : maximum pitch lag 61 | * @param i_subfr input : subframe flag 62 | * @param T0 output: integer part of pitch lag 63 | * @param T0_frac output: fractional part of pitch lag 64 | */ 65 | 66 | public static void dec_lag3( 67 | int index, 68 | int pit_min, 69 | int pit_max, 70 | int i_subfr, 71 | IntReference T0, 72 | IntReference T0_frac 73 | ) 74 | { 75 | int i; 76 | int _T0 = T0.value, _T0_frac = T0_frac.value; 77 | int T0_min, T0_max; 78 | 79 | if (i_subfr == 0) /* if 1st subframe */ 80 | { 81 | if (index < 197) 82 | { 83 | _T0 = (index + 2) / 3 + 19; 84 | _T0_frac = index - _T0 * 3 + 58; 85 | } 86 | else 87 | { 88 | _T0 = index - 112; 89 | _T0_frac = 0; 90 | } 91 | } 92 | 93 | else /* second subframe */ 94 | { 95 | /* find T0_min and T0_max for 2nd subframe */ 96 | 97 | T0_min = _T0 - 5; 98 | if (T0_min < pit_min) 99 | T0_min = pit_min; 100 | 101 | T0_max = T0_min + 9; 102 | if (T0_max > pit_max) 103 | { 104 | T0_max = pit_max; 105 | T0_min = T0_max - 9; 106 | } 107 | 108 | i = (index + 2) / 3 - 1; 109 | _T0 = i + T0_min; 110 | _T0_frac = index - 2 - i * 3; 111 | } 112 | 113 | T0.value = _T0; 114 | T0_frac.value = _T0_frac; 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /GroovyCodecs.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 15 3 | VisualStudioVersion = 15.0.27428.2015 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.Mp3", "Mp3\GroovyCodecs.Mp3.csproj", "{DDDBBE09-C897-406D-A19B-42FDD6AEDB74}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.WavFile", "WavFile\GroovyCodecs.WavFile.csproj", "{EB20FBF3-FFC5-4B58-AC9D-EC9791E4B25B}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.Types", "Types\GroovyCodecs.Types.csproj", "{410E57F3-E35F-48FC-9426-30C8CA328A5A}" 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.G729", "G729\GroovyCodecs.G729.csproj", "{4908B1D8-21C4-4E1B-A911-0CC23AB514DA}" 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.G711", "G711\GroovyCodecs.G711.csproj", "{5EFA30A5-00F9-42DB-B3A0-803C2496446F}" 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GroovyCodecs.Coder", "Coder\GroovyCodecs.Coder.csproj", "{3FB219E7-EBD3-43DF-A950-14072A92A423}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {DDDBBE09-C897-406D-A19B-42FDD6AEDB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {DDDBBE09-C897-406D-A19B-42FDD6AEDB74}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {DDDBBE09-C897-406D-A19B-42FDD6AEDB74}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {DDDBBE09-C897-406D-A19B-42FDD6AEDB74}.Release|Any CPU.Build.0 = Release|Any CPU 27 | {EB20FBF3-FFC5-4B58-AC9D-EC9791E4B25B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {EB20FBF3-FFC5-4B58-AC9D-EC9791E4B25B}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {EB20FBF3-FFC5-4B58-AC9D-EC9791E4B25B}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {EB20FBF3-FFC5-4B58-AC9D-EC9791E4B25B}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {410E57F3-E35F-48FC-9426-30C8CA328A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {410E57F3-E35F-48FC-9426-30C8CA328A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {410E57F3-E35F-48FC-9426-30C8CA328A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {410E57F3-E35F-48FC-9426-30C8CA328A5A}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {4908B1D8-21C4-4E1B-A911-0CC23AB514DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {4908B1D8-21C4-4E1B-A911-0CC23AB514DA}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {4908B1D8-21C4-4E1B-A911-0CC23AB514DA}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {4908B1D8-21C4-4E1B-A911-0CC23AB514DA}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {5EFA30A5-00F9-42DB-B3A0-803C2496446F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {5EFA30A5-00F9-42DB-B3A0-803C2496446F}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {5EFA30A5-00F9-42DB-B3A0-803C2496446F}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {5EFA30A5-00F9-42DB-B3A0-803C2496446F}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {3FB219E7-EBD3-43DF-A950-14072A92A423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {3FB219E7-EBD3-43DF-A950-14072A92A423}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {3FB219E7-EBD3-43DF-A950-14072A92A423}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {3FB219E7-EBD3-43DF-A950-14072A92A423}.Release|Any CPU.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | GlobalSection(SolutionProperties) = preSolution 49 | HideSolutionNode = FALSE 50 | EndGlobalSection 51 | GlobalSection(ExtensibilityGlobals) = postSolution 52 | SolutionGuid = {5E9C0FC5-35BA-4A4E-B850-C2471BF50CE1} 53 | EndGlobalSection 54 | GlobalSection(MonoDevelopProperties) = preSolution 55 | Policies = $0 56 | $0.DotNetNamingPolicy = $1 57 | $1.DirectoryNamespaceAssociation = PrefixedHierarchical 58 | $0.TextStylePolicy = $2 59 | $2.FileWidth = 80 60 | $2.TabsToSpaces = True 61 | $2.scope = text/plain 62 | $0.VersionControlPolicy = $3 63 | EndGlobalSection 64 | EndGlobal 65 | -------------------------------------------------------------------------------- /G711/aLaw/ALawDecoder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2011, Red Hat, Inc. and individual contributors 4 | * by the @authors tag. See the copyright.txt in the distribution for a 5 | * full listing of individual contributors. 6 | * 7 | * This is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this software; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | */ 22 | 23 | /* 24 | * 15/07/13 - Change notice: 25 | * This file has been modified by Mobius Software Ltd. 26 | * For more information please visit http://www.mobius.ua 27 | */ 28 | /** 29 | * Implements G.711 A-Law decompressor. 30 | * 31 | * @author Yulian Oifa 32 | */ 33 | /* 34 | * Converted to C# for GroovyG7xx, see https://github.com/jongoochgithub/GroovyCodecs 35 | */ 36 | 37 | namespace GroovyCodecs.G711.aLaw 38 | { 39 | public class ALawDecoder 40 | { 41 | /** decompress table constants **/ 42 | private static short[] _aLawDecompressTable = { 43 | -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, 44 | -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, 45 | -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368, 46 | -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, 47 | -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944, 48 | -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, 49 | -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472, 50 | -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568, 51 | -344, -328, -376, -360, -280, -264, -312, -296, 52 | -472, -456, -504, -488, -408, -392, -440, -424, 53 | -88, -72, -120, -104, -24, -8, -56, -40, 54 | -216, -200, -248, -232, -152, -136, -184, -168, 55 | -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184, 56 | -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, 57 | -688, -656, -752, -720, -560, -528, -624, -592, 58 | -944, -912, -1008, -976, -816, -784, -880, -848, 59 | 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736, 60 | 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, 61 | 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368, 62 | 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, 63 | 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, 64 | 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, 65 | 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472, 66 | 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, 67 | 344, 328, 376, 360, 280, 264, 312, 296, 68 | 472, 456, 504, 488, 408, 392, 440, 424, 69 | 88, 72, 120, 104, 24, 8, 56, 40, 70 | 216, 200, 248, 232, 152, 136, 184, 168, 71 | 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184, 72 | 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, 73 | 688, 656, 752, 720, 560, 528, 624, 592, 74 | 944, 912, 1008, 976, 816, 784, 880, 848 75 | }; 76 | 77 | public short[] Process(byte[] frame) 78 | { 79 | var sourceLen = frame.Length; 80 | var res = new short[sourceLen]; 81 | 82 | for (var i = 0; i < sourceLen; i++) 83 | res[i] = _aLawDecompressTable[frame[i] & 0xff]; 84 | 85 | return res; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Mp3/Mp3/GrInfo.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | 9 | namespace GroovyCodecs.Mp3.Mp3 10 | { 11 | internal sealed class GrInfo 12 | { 13 | 14 | internal int big_values; 15 | 16 | internal int block_type; 17 | 18 | internal int count1; 19 | 20 | internal int count1bits; 21 | 22 | internal int count1table_select; 23 | 24 | internal int global_gain; 25 | 26 | internal int[] l3_enc = new int[576]; 27 | 28 | internal int max_nonzero_coeff; 29 | 30 | internal int mixed_block_flag; 31 | 32 | internal int part2_3_length; 33 | 34 | internal int part2_length; 35 | 36 | internal int preflag; 37 | 38 | internal int psy_lmax; 39 | 40 | internal int psymax; 41 | 42 | internal int region0_count; 43 | 44 | internal int region1_count; 45 | 46 | internal int[] scalefac = new int[L3Side.SFBMAX]; 47 | 48 | internal int scalefac_compress; 49 | 50 | internal int scalefac_scale; 51 | 52 | internal int sfb_lmax; 53 | 54 | /// 55 | /// added for LSF 56 | /// 57 | internal int[] sfb_partition_table; 58 | 59 | internal int sfb_smin; 60 | 61 | internal int sfbdivide; 62 | 63 | internal int sfbmax; 64 | 65 | internal int[] slen = new int[4]; 66 | 67 | internal int[] subblock_gain = new int[3 + 1]; 68 | 69 | internal int[] table_select = new int[3]; 70 | 71 | internal int[] width = new int[L3Side.SFBMAX]; 72 | 73 | internal int[] window = new int[L3Side.SFBMAX]; 74 | 75 | internal float[] xr = new float[576]; 76 | 77 | internal float xrpow_max; 78 | 79 | internal void assign(GrInfo other) 80 | { 81 | Array.Copy(other.xr, xr, other.xr.Length); 82 | Array.Copy(other.l3_enc, l3_enc, other.l3_enc.Length); 83 | Array.Copy(other.scalefac, scalefac, other.scalefac.Length); 84 | xrpow_max = other.xrpow_max; 85 | 86 | part2_3_length = other.part2_3_length; 87 | big_values = other.big_values; 88 | count1 = other.count1; 89 | global_gain = other.global_gain; 90 | scalefac_compress = other.scalefac_compress; 91 | block_type = other.block_type; 92 | mixed_block_flag = other.mixed_block_flag; 93 | Array.Copy(other.table_select, table_select, other.table_select.Length); 94 | Array.Copy(other.subblock_gain, subblock_gain, other.subblock_gain.Length); 95 | region0_count = other.region0_count; 96 | region1_count = other.region1_count; 97 | preflag = other.preflag; 98 | scalefac_scale = other.scalefac_scale; 99 | count1table_select = other.count1table_select; 100 | 101 | part2_length = other.part2_length; 102 | sfb_lmax = other.sfb_lmax; 103 | sfb_smin = other.sfb_smin; 104 | psy_lmax = other.psy_lmax; 105 | sfbmax = other.sfbmax; 106 | psymax = other.psymax; 107 | sfbdivide = other.sfbdivide; 108 | Array.Copy(other.width, width, other.width.Length); 109 | Array.Copy(other.window, window, other.window.Length); 110 | count1bits = other.count1bits; 111 | 112 | sfb_partition_table = new int[other.sfb_partition_table.Length]; 113 | Array.Copy(other.sfb_partition_table, sfb_partition_table, other.sfb_partition_table.Length); 114 | Array.Copy(other.slen, slen, other.slen.Length); 115 | max_nonzero_coeff = other.max_nonzero_coeff; 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /Mp3/Mp3/CBRNewIterationLoop.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using System.Diagnostics; 9 | 10 | namespace GroovyCodecs.Mp3.Mp3 11 | { 12 | /// 13 | /// author/date?? 14 | /// encodes one frame of MP3 data with constant bitrate 15 | /// @author Ken 16 | /// 17 | internal sealed class CBRNewIterationLoop : IIterationLoop 18 | { 19 | /// 20 | private readonly Quantize quantize; 21 | 22 | /// 23 | internal CBRNewIterationLoop(Quantize quantize) 24 | { 25 | this.quantize = quantize; 26 | } 27 | 28 | public void iteration_loop(LameGlobalFlags gfp, float[][] pe, float[] ms_ener_ratio, III_psy_ratio[][] ratio) 29 | { 30 | 31 | var gfc = gfp.internal_flags; 32 | var l3_xmin = new float[L3Side.SFBMAX]; 33 | var xrpow = new float[576]; 34 | var targ_bits = new int[2]; 35 | int mean_bits = 0, max_bits; 36 | 37 | var l3_side = gfc.l3_side; 38 | 39 | var mb = new MeanBits(mean_bits); 40 | quantize.rv.ResvFrameBegin(gfp, mb); 41 | mean_bits = mb.bits; 42 | 43 | /* quantize! */ 44 | for (var gr = 0; gr < gfc.mode_gr; gr++) 45 | { 46 | 47 | /* 48 | * calculate needed bits 49 | */ 50 | max_bits = quantize.qupvt.on_pe(gfp, pe, targ_bits, mean_bits, gr, gr); 51 | 52 | if (gfc.mode_ext == Encoder.MPG_MD_MS_LR) 53 | { 54 | quantize.ms_convert(gfc.l3_side, gr); 55 | quantize.qupvt.reduce_side(targ_bits, ms_ener_ratio[gr], mean_bits, max_bits); 56 | } 57 | 58 | for (var ch = 0; ch < gfc.channels_out; ch++) 59 | { 60 | float adjust, masking_lower_db; 61 | var cod_info = l3_side.tt[gr][ch]; 62 | 63 | if (cod_info.block_type != Encoder.SHORT_TYPE) 64 | { 65 | // NORM, START or STOP type 66 | adjust = 0; 67 | masking_lower_db = gfc.PSY.mask_adjust - adjust; 68 | } 69 | else 70 | { 71 | adjust = 0; 72 | masking_lower_db = gfc.PSY.mask_adjust_short - adjust; 73 | } 74 | 75 | gfc.masking_lower = (float)Math.Pow(10.0, masking_lower_db * 0.1); 76 | 77 | /* 78 | * init_outer_loop sets up cod_info, scalefac and xrpow 79 | */ 80 | quantize.init_outer_loop(gfc, cod_info); 81 | if (quantize.init_xrpow(gfc, cod_info, xrpow)) 82 | { 83 | /* 84 | * xr contains energy we will have to encode calculate the 85 | * masking abilities find some good quantization in 86 | * outer_loop 87 | */ 88 | quantize.qupvt.calc_xmin(gfp, ratio[gr][ch], cod_info, l3_xmin); 89 | quantize.outer_loop(gfp, cod_info, l3_xmin, xrpow, ch, targ_bits[ch]); 90 | } 91 | 92 | quantize.iteration_finish_one(gfc, gr, ch); 93 | Debug.Assert(cod_info.part2_3_length <= LameInternalFlags.MAX_BITS_PER_CHANNEL); 94 | Debug.Assert(cod_info.part2_3_length <= targ_bits[ch]); 95 | } // for ch 96 | } // for gr 97 | 98 | quantize.rv.ResvFrameEnd(gfc, mean_bits); 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VBRNewIterationLoop.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using GroovyCodecs.Mp3.Common; 10 | 11 | namespace GroovyCodecs.Mp3.Mp3 12 | { 13 | internal sealed class VBRNewIterationLoop : IIterationLoop 14 | { 15 | 16 | /// 17 | private readonly Quantize quantize; 18 | 19 | /// 20 | internal VBRNewIterationLoop(Quantize quantize) 21 | { 22 | this.quantize = quantize; 23 | } 24 | 25 | public void iteration_loop(LameGlobalFlags gfp, float[][] pe, float[] ms_ener_ratio, III_psy_ratio[][] ratio) 26 | { 27 | var gfc = gfp.internal_flags; 28 | 29 | var l3_xmin = Arrays.ReturnRectangularArray(2, 2, L3Side.SFBMAX); 30 | 31 | var xrpow = Arrays.ReturnRectangularArray(2, 2, 576); 32 | var frameBits = new int[15]; 33 | 34 | var max_bits = Arrays.ReturnRectangularArray(2, 2); 35 | 36 | var l3_side = gfc.l3_side; 37 | 38 | var analog_silence = quantize.VBR_new_prepare(gfp, pe, ratio, l3_xmin, frameBits, max_bits); 39 | 40 | for (var gr = 0; gr < gfc.mode_gr; gr++) 41 | for (var ch = 0; ch < gfc.channels_out; ch++) 42 | { 43 | 44 | var cod_info = l3_side.tt[gr][ch]; 45 | 46 | /* 47 | * init_outer_loop sets up cod_info, scalefac and xrpow 48 | */ 49 | if (!quantize.init_xrpow(gfc, cod_info, xrpow[gr][ch])) 50 | max_bits[gr][ch] = 0; 51 | } // for ch 52 | 53 | /* 54 | * quantize granules with lowest possible number of bits 55 | */ 56 | 57 | var used_bits = quantize.vbr.VBR_encode_frame(gfc, xrpow, l3_xmin, max_bits); 58 | 59 | if (!gfp.free_format) 60 | { 61 | /* 62 | * find lowest bitrate able to hold used bits 63 | */ 64 | if (analog_silence != 0 && 0 == gfp.VBR_hard_min) 65 | gfc.bitrate_index = 1; 66 | else 67 | gfc.bitrate_index = gfc.VBR_min_bitrate; 68 | 69 | for (; gfc.bitrate_index < gfc.VBR_max_bitrate; gfc.bitrate_index++) 70 | if (used_bits <= frameBits[gfc.bitrate_index]) 71 | break; 72 | 73 | if (gfc.bitrate_index > gfc.VBR_max_bitrate) 74 | gfc.bitrate_index = gfc.VBR_max_bitrate; 75 | } 76 | else 77 | { 78 | gfc.bitrate_index = 0; 79 | } 80 | 81 | if (used_bits <= frameBits[gfc.bitrate_index]) 82 | { 83 | /* update Reservoire status */ 84 | int mean_bits = 0, fullframebits; 85 | var mb = new MeanBits(mean_bits); 86 | fullframebits = quantize.rv.ResvFrameBegin(gfp, mb); 87 | mean_bits = mb.bits; 88 | Debug.Assert(used_bits <= fullframebits); 89 | for (var gr = 0; gr < gfc.mode_gr; gr++) 90 | for (var ch = 0; ch < gfc.channels_out; ch++) 91 | { 92 | 93 | var cod_info = l3_side.tt[gr][ch]; 94 | quantize.rv.ResvAdjust(gfc, cod_info); 95 | } 96 | 97 | quantize.rv.ResvFrameEnd(gfc, mean_bits); 98 | } 99 | else 100 | { 101 | /* 102 | * SHOULD NOT HAPPEN INTERNAL ERROR 103 | */ 104 | throw new Exception("INTERNAL ERROR IN VBR NEW CODE, please send bug report"); 105 | } 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /Mp3/Mp3/ABRIterationLoop.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using GroovyCodecs.Mp3.Common; 10 | 11 | namespace GroovyCodecs.Mp3.Mp3 12 | { 13 | /// 14 | /// encode a frame with a desired average bitrate 15 | /// mt 2000/05/31 16 | /// @author Ken 17 | /// 18 | internal sealed class ABRIterationLoop : IIterationLoop 19 | { 20 | 21 | /// 22 | private readonly Quantize quantize; 23 | 24 | /// 25 | internal ABRIterationLoop(Quantize quantize) 26 | { 27 | this.quantize = quantize; 28 | } 29 | 30 | public void iteration_loop(LameGlobalFlags gfp, float[][] pe, float[] ms_ener_ratio, III_psy_ratio[][] ratio) 31 | { 32 | 33 | var gfc = gfp.internal_flags; 34 | var l3_xmin = new float[L3Side.SFBMAX]; 35 | var xrpow = new float[576]; 36 | 37 | var targ_bits = Arrays.ReturnRectangularArray(2, 2); 38 | var max_frame_bits = new int[1]; 39 | var analog_silence_bits = new int[1]; 40 | 41 | var l3_side = gfc.l3_side; 42 | 43 | var mean_bits = 0; 44 | 45 | quantize.calc_target_bits(gfp, pe, ms_ener_ratio, targ_bits, analog_silence_bits, max_frame_bits); 46 | 47 | /* 48 | * encode granules 49 | */ 50 | for (var gr = 0; gr < gfc.mode_gr; gr++) 51 | { 52 | 53 | if (gfc.mode_ext == Encoder.MPG_MD_MS_LR) 54 | quantize.ms_convert(gfc.l3_side, gr); 55 | 56 | for (var ch = 0; ch < gfc.channels_out; ch++) 57 | { 58 | float adjust, masking_lower_db; 59 | var cod_info = l3_side.tt[gr][ch]; 60 | 61 | if (cod_info.block_type != Encoder.SHORT_TYPE) 62 | { 63 | // NORM, START or STOP type 64 | adjust = 0; 65 | masking_lower_db = gfc.PSY.mask_adjust - adjust; 66 | } 67 | else 68 | { 69 | adjust = 0; 70 | masking_lower_db = gfc.PSY.mask_adjust_short - adjust; 71 | } 72 | 73 | gfc.masking_lower = (float)Math.Pow(10.0, masking_lower_db * 0.1); 74 | 75 | /* 76 | * cod_info, scalefac and xrpow get initialized in 77 | * init_outer_loop 78 | */ 79 | quantize.init_outer_loop(gfc, cod_info); 80 | if (quantize.init_xrpow(gfc, cod_info, xrpow)) 81 | { 82 | /* 83 | * xr contains energy we will have to encode calculate the 84 | * masking abilities find some good quantization in 85 | * outer_loop 86 | */ 87 | var ath_over = quantize.qupvt.calc_xmin(gfp, ratio[gr][ch], cod_info, l3_xmin); 88 | if (0 == ath_over) // analog silence 89 | targ_bits[gr][ch] = analog_silence_bits[0]; 90 | 91 | quantize.outer_loop(gfp, cod_info, l3_xmin, xrpow, ch, targ_bits[gr][ch]); 92 | } 93 | 94 | quantize.iteration_finish_one(gfc, gr, ch); 95 | } // ch 96 | } // gr 97 | 98 | /* 99 | * find a bitrate which can refill the resevoir to positive size. 100 | */ 101 | for (gfc.bitrate_index = gfc.VBR_min_bitrate; gfc.bitrate_index <= gfc.VBR_max_bitrate; gfc.bitrate_index++) 102 | { 103 | 104 | var mb = new MeanBits(mean_bits); 105 | var rc = quantize.rv.ResvFrameBegin(gfp, mb); 106 | mean_bits = mb.bits; 107 | if (rc >= 0) 108 | break; 109 | } 110 | 111 | Debug.Assert(gfc.bitrate_index <= gfc.VBR_max_bitrate); 112 | 113 | quantize.rv.ResvFrameEnd(gfc, mean_bits); 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | 26 | # Visual Studio 2015 cache/options directory 27 | .vs/ 28 | # Uncomment if you have tasks that create the project's static files in wwwroot 29 | wwwroot/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | # DNX 45 | project.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | 144 | # TODO: Un-comment the next line if you do not want to checkin 145 | # your web deploy settings because they may include unencrypted 146 | # passwords 147 | #*.pubxml 148 | *.publishproj 149 | 150 | # NuGet Packages 151 | *.nupkg 152 | # The packages folder can be ignored because of Package Restore 153 | **/packages/* 154 | # except build/, which is used as an MSBuild target. 155 | !**/packages/build/ 156 | # Uncomment if necessary however generally it will be regenerated when needed 157 | #!**/packages/repositories.config 158 | # NuGet v3's project.json files produces more ignoreable files 159 | *.nuget.props 160 | *.nuget.targets 161 | 162 | # Microsoft Azure Build Output 163 | csx/ 164 | *.build.csdef 165 | 166 | # Microsoft Azure Emulator 167 | ecf/ 168 | rcf/ 169 | 170 | # Windows Store app package directory 171 | AppPackages/ 172 | BundleArtifacts/ 173 | 174 | # Visual Studio cache files 175 | # files ending in .cache can be ignored 176 | *.[Cc]ache 177 | # but keep track of directories ending in .cache 178 | !*.[Cc]ache/ 179 | 180 | # Others 181 | ClientBin/ 182 | [Ss]tyle[Cc]op.* 183 | ~$* 184 | *~ 185 | *.dbmdl 186 | *.dbproj.schemaview 187 | *.pfx 188 | *.publishsettings 189 | node_modules/ 190 | orleans.codegen.cs 191 | 192 | # RIA/Silverlight projects 193 | Generated_Code/ 194 | 195 | # Backup & report files from converting an old project file 196 | # to a newer Visual Studio version. Backup files are not needed, 197 | # because we have git ;-) 198 | _UpgradeReport_Files/ 199 | Backup*/ 200 | UpgradeLog*.XML 201 | UpgradeLog*.htm 202 | 203 | # SQL Server files 204 | *.mdf 205 | *.ldf 206 | 207 | # Business Intelligence projects 208 | *.rdl.data 209 | *.bim.layout 210 | *.bim_*.settings 211 | 212 | # Microsoft Fakes 213 | FakesAssemblies/ 214 | 215 | # GhostDoc plugin setting file 216 | *.GhostDoc.xml 217 | 218 | # Node.js Tools for Visual Studio 219 | .ntvs_analysis.dat 220 | 221 | # Visual Studio 6 build log 222 | *.plg 223 | 224 | # Visual Studio 6 workspace options file 225 | *.opt 226 | 227 | # Visual Studio LightSwitch build output 228 | **/*.HTMLClient/GeneratedArtifacts 229 | **/*.DesktopClient/GeneratedArtifacts 230 | **/*.DesktopClient/ModelManifest.xml 231 | **/*.Server/GeneratedArtifacts 232 | **/*.Server/ModelManifest.xml 233 | _Pvt_Extensions 234 | 235 | # LightSwitch generated files 236 | GeneratedArtifacts/ 237 | ModelManifest.xml 238 | 239 | # Paket dependency manager 240 | .paket/paket.exe 241 | 242 | # FAKE - F# Make 243 | .fake/ 244 | -------------------------------------------------------------------------------- /G729/Codec/Taming.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Taming functions. 24 | * 25 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 26 | */ 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Taming 30 | { 31 | 32 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 33 | /* 34 | ITU-T G.729 Annex C - Reference C code for floating point 35 | implementation of G.729 36 | Version 1.01 of 15.September.98 37 | */ 38 | 39 | /* 40 | ---------------------------------------------------------------------- 41 | COPYRIGHT NOTICE 42 | ---------------------------------------------------------------------- 43 | ITU-T G.729 Annex C ANSI C source code 44 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 45 | Sherbrooke. All rights reserved. 46 | 47 | ---------------------------------------------------------------------- 48 | */ 49 | 50 | /* 51 | File : TAMING.C 52 | Used for the floating point version of both 53 | G.729 main body and G.729A 54 | */ 55 | 56 | private readonly float[] exc_err = new float[4]; 57 | 58 | public void init_exc_err() 59 | { 60 | int i; 61 | for (i = 0; i < 4; i++) exc_err[i] = 1.0f; 62 | } 63 | 64 | /** 65 | * Computes the accumulated potential error in the 66 | * adaptive codebook contribution 67 | * 68 | * @param t0 (i) integer part of pitch delay 69 | * @param t0_frac (i) fractional part of pitch delay 70 | * @return flag set to 1 if taming is necessary 71 | */ 72 | 73 | public int test_err( 74 | int t0, 75 | int t0_frac 76 | ) 77 | { 78 | var INV_L_SUBFR = Ld8k.INV_L_SUBFR; 79 | var L_INTER10 = Ld8k.L_INTER10; 80 | var L_SUBFR = Ld8k.L_SUBFR; 81 | var THRESH_ERR = Ld8k.THRESH_ERR; 82 | 83 | int i, t1, zone1, zone2, flag; 84 | float maxloc; 85 | 86 | t1 = t0_frac > 0 ? t0 + 1 : t0; 87 | 88 | i = t1 - L_SUBFR - L_INTER10; 89 | if (i < 0) i = 0; 90 | zone1 = (int)(i * INV_L_SUBFR); 91 | 92 | i = t1 + L_INTER10 - 2; 93 | zone2 = (int)(i * INV_L_SUBFR); 94 | 95 | maxloc = -1.0f; 96 | flag = 0; 97 | for (i = zone2; i >= zone1; i--) 98 | if (exc_err[i] > maxloc) 99 | maxloc = exc_err[i]; 100 | if (maxloc > THRESH_ERR) 101 | flag = 1; 102 | return flag; 103 | } 104 | 105 | /** 106 | * Maintains the memory used to compute the error 107 | * function due to an adaptive codebook mismatch between encoder and 108 | * decoder 109 | * 110 | * @param gain_pit (i) pitch gain 111 | * @param t0 (i) integer part of pitch delay 112 | */ 113 | 114 | public void update_exc_err( 115 | float gain_pit, 116 | int t0 117 | ) 118 | { 119 | var INV_L_SUBFR = Ld8k.INV_L_SUBFR; 120 | var L_SUBFR = Ld8k.L_SUBFR; 121 | 122 | int i, zone1, zone2, n; 123 | float worst, temp; 124 | 125 | worst = (float)-1.0; 126 | 127 | n = t0 - L_SUBFR; 128 | if (n < 0) 129 | { 130 | temp = 1.0f + gain_pit * exc_err[0]; 131 | if (temp > worst) worst = temp; 132 | temp = 1.0f + gain_pit * temp; 133 | if (temp > worst) worst = temp; 134 | } 135 | 136 | else 137 | { 138 | zone1 = (int)(n * INV_L_SUBFR); 139 | 140 | i = t0 - 1; 141 | zone2 = (int)(i * INV_L_SUBFR); 142 | 143 | for (i = zone1; i <= zone2; i++) 144 | { 145 | temp = 1.0f + gain_pit * exc_err[i]; 146 | if (temp > worst) worst = temp; 147 | } 148 | } 149 | 150 | for (i = 3; i >= 1; i--) exc_err[i] = exc_err[i - 1]; 151 | exc_err[0] = worst; 152 | } 153 | } 154 | } -------------------------------------------------------------------------------- /G729/Codec/DecGain.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | namespace GroovyCodecs.G729.Codec 26 | { 27 | internal class DecGain 28 | { 29 | 30 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 31 | /* 32 | ITU-T G.729 Annex C - Reference C code for floating point 33 | implementation of G.729 34 | Version 1.01 of 15.September.98 35 | */ 36 | 37 | /* 38 | ---------------------------------------------------------------------- 39 | COPYRIGHT NOTICE 40 | ---------------------------------------------------------------------- 41 | ITU-T G.729 Annex C ANSI C source code 42 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 43 | Sherbrooke. All rights reserved. 44 | 45 | ---------------------------------------------------------------------- 46 | */ 47 | /* 48 | File : DEC_GAIN.C 49 | Used for the floating point version of both 50 | G.729 main body and G.729A 51 | */ 52 | private readonly float[ /* 4 */] past_qua_en = 53 | { 54 | -14.0f, 55 | -14.0f, 56 | -14.0f, 57 | -14.0f 58 | }; 59 | 60 | /** 61 | * Decode the adaptive and fixed codebook gains. 62 | * 63 | * @param index input : quantizer index 64 | * @param code input : fixed code book vector 65 | * @param l_subfr input : subframe size 66 | * @param bfi input : bad frame indicator good = 0 67 | * @param gain_pit output: quantized acb gain 68 | * @param gain_code output: quantized fcb gain 69 | */ 70 | 71 | public void dec_gain( 72 | int index, 73 | float[] code, 74 | int l_subfr, 75 | int bfi, 76 | FloatReference gain_pit, 77 | FloatReference gain_code 78 | ) 79 | { 80 | var NCODE2 = Ld8k.NCODE2; 81 | var gbk1 = TabLd8k.gbk1; 82 | var gbk2 = TabLd8k.gbk2; 83 | var imap1 = TabLd8k.imap1; 84 | var imap2 = TabLd8k.imap2; 85 | 86 | int index1, index2; 87 | float gcode0, g_code; 88 | 89 | /*----------------- Test erasure ---------------*/ 90 | if (bfi != 0) 91 | { 92 | gain_pit.value *= 0.9f; 93 | if (gain_pit.value > 0.9f) gain_pit.value = 0.9f; 94 | gain_code.value *= 0.98f; 95 | 96 | /*----------------------------------------------* 97 | * update table of past quantized energies * 98 | * (frame erasure) * 99 | *----------------------------------------------*/ 100 | Gainpred.gain_update_erasure(past_qua_en); 101 | 102 | return; 103 | } 104 | 105 | /*-------------- Decode pitch gain ---------------*/ 106 | 107 | index1 = imap1[index / NCODE2]; 108 | index2 = imap2[index % NCODE2]; 109 | gain_pit.value = gbk1[index1][0] + gbk2[index2][0]; 110 | 111 | /*-------------- Decode codebook gain ---------------*/ 112 | 113 | /*---------------------------------------------------* 114 | *- energy due to innovation -* 115 | *- predicted energy -* 116 | *- predicted codebook gain => gcode0[exp_gcode0] -* 117 | *---------------------------------------------------*/ 118 | 119 | gcode0 = Gainpred.gain_predict(past_qua_en, code, l_subfr); 120 | 121 | /*-----------------------------------------------------------------* 122 | * *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0; * 123 | *-----------------------------------------------------------------*/ 124 | 125 | g_code = gbk1[index1][1] + gbk2[index2][1]; 126 | gain_code.value = g_code * gcode0; 127 | 128 | /*----------------------------------------------* 129 | * update table of past quantized energies * 130 | *----------------------------------------------*/ 131 | 132 | Gainpred.gain_update(past_qua_en, g_code); 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /G729/Codec/Gainpred.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | using System; 26 | 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Gainpred 30 | { 31 | 32 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 33 | /* 34 | ITU-T G.729 Annex C - Reference C code for floating point 35 | implementation of G.729 36 | Version 1.01 of 15.September.98 37 | */ 38 | 39 | /* 40 | ---------------------------------------------------------------------- 41 | COPYRIGHT NOTICE 42 | ---------------------------------------------------------------------- 43 | ITU-T G.729 Annex C ANSI C source code 44 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 45 | Sherbrooke. All rights reserved. 46 | 47 | ---------------------------------------------------------------------- 48 | */ 49 | 50 | /* 51 | File : GAINPRED.C 52 | Used for the floating point version of both 53 | G.729 main body and G.729A 54 | */ 55 | 56 | /** 57 | * MA prediction is performed on the innovation energy (in dB with mean 58 | * removed). 59 | * 60 | * @param past_qua_en (i) :Past quantized energies 61 | * @param code (i) :Innovative vector. 62 | * @param l_subfr (i) :Subframe length. 63 | * @return Predicted codebook gain 64 | */ 65 | 66 | public static float gain_predict( 67 | float[] past_qua_en, 68 | float[] code, 69 | int l_subfr 70 | ) 71 | { 72 | var MEAN_ENER = Ld8k.MEAN_ENER; 73 | var pred = TabLd8k.pred; 74 | 75 | float ener_code, pred_code; 76 | int i; 77 | float gcode0; /* (o) :Predicted codebook gain */ 78 | 79 | pred_code = MEAN_ENER; 80 | 81 | /* innovation energy */ 82 | ener_code = 0.01f; 83 | for (i = 0; i < l_subfr; i++) 84 | ener_code += code[i] * code[i]; 85 | ener_code = 10.0f * (float)Math.Log10(ener_code / l_subfr); 86 | 87 | pred_code -= ener_code; 88 | 89 | /* predicted energy */ 90 | for (i = 0; i < 4; i++) pred_code += pred[i] * past_qua_en[i]; 91 | 92 | /* predicted codebook gain */ 93 | gcode0 = pred_code; 94 | gcode0 = (float)Math.Pow(10.0, gcode0 / 20.0); /* predicted gain */ 95 | 96 | return gcode0; 97 | } 98 | 99 | /** 100 | * Update table of past quantized energies. 101 | * 102 | * @param past_qua_en input/output :Past quantized energies 103 | * @param g_code input: gbk1[indice1][1]+gbk2[indice2][1] 104 | */ 105 | 106 | public static void gain_update( 107 | float[] past_qua_en, 108 | float g_code 109 | ) 110 | { 111 | int i; 112 | 113 | /* update table of past quantized energies */ 114 | for (i = 3; i > 0; i--) 115 | past_qua_en[i] = past_qua_en[i - 1]; 116 | past_qua_en[0] = 20.0f * (float)Math.Log10(g_code); 117 | } 118 | 119 | /** 120 | * Update table of past quantized energies (frame erasure). 121 | *
122 |  *     av_pred_en = 0.0;
123 |  *     for (i = 0; i < 4; i++)
124 |  *        av_pred_en += past_qua_en[i];
125 |  *     av_pred_en = av_pred_en*0.25 - 4.0;
126 |  *     if (av_pred_en < -14.0) av_pred_en = -14.0;
127 |  * 
128 | * 129 | * @param past_qua_en input/output:Past quantized energies 130 | */ 131 | 132 | public static void gain_update_erasure( 133 | float[] past_qua_en 134 | ) 135 | { 136 | int i; 137 | float av_pred_en; 138 | 139 | av_pred_en = 0.0f; 140 | for (i = 0; i < 4; i++) 141 | av_pred_en += past_qua_en[i]; 142 | av_pred_en = av_pred_en * 0.25f - 4.0f; 143 | if (av_pred_en < -14.0f) av_pred_en = -14.0f; 144 | 145 | for (i = 3; i > 0; i--) 146 | past_qua_en[i] = past_qua_en[i - 1]; 147 | past_qua_en[0] = av_pred_en; 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /Mp3/Mp3/VBROldIterationLoop.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using GroovyCodecs.Mp3.Common; 8 | 9 | namespace GroovyCodecs.Mp3.Mp3 10 | { 11 | /// 12 | /// tries to find out how many bits are needed for each granule and channel 13 | /// to get an acceptable quantization. An appropriate bitrate will then be 14 | /// chosen for quantization. rh 8/99 15 | /// Robert Hegemann 2000-09-06 rewrite 16 | /// @author Ken 17 | /// 18 | internal sealed class VBROldIterationLoop : IIterationLoop 19 | { 20 | 21 | /// 22 | private readonly Quantize quantize; 23 | 24 | /// 25 | internal VBROldIterationLoop(Quantize quantize) 26 | { 27 | this.quantize = quantize; 28 | } 29 | 30 | public void iteration_loop(LameGlobalFlags gfp, float[][] pe, float[] ms_ener_ratio, III_psy_ratio[][] ratio) 31 | { 32 | 33 | var gfc = gfp.internal_flags; 34 | 35 | var l3_xmin = Arrays.ReturnRectangularArray(2, 2, L3Side.SFBMAX); 36 | 37 | var xrpow = new float[576]; 38 | 39 | var bands = Arrays.ReturnRectangularArray(2, 2); 40 | var frameBits = new int[15]; 41 | 42 | var min_bits = Arrays.ReturnRectangularArray(2, 2); 43 | var max_bits = Arrays.ReturnRectangularArray(2, 2); 44 | var mean_bits = 0; 45 | 46 | var l3_side = gfc.l3_side; 47 | 48 | var analog_silence = quantize.VBR_old_prepare( 49 | gfp, 50 | pe, 51 | ms_ener_ratio, 52 | ratio, 53 | l3_xmin, 54 | frameBits, 55 | min_bits, 56 | max_bits, 57 | bands); 58 | 59 | /*---------------------------------*/ 60 | for (;;) 61 | { 62 | /* 63 | * quantize granules with lowest possible number of bits 64 | */ 65 | var used_bits = 0; 66 | 67 | for (var gr = 0; gr < gfc.mode_gr; gr++) 68 | for (var ch = 0; ch < gfc.channels_out; ch++) 69 | { 70 | 71 | var cod_info = l3_side.tt[gr][ch]; 72 | 73 | /* 74 | * init_outer_loop sets up cod_info, scalefac and xrpow 75 | */ 76 | var ret = quantize.init_xrpow(gfc, cod_info, xrpow); 77 | if (!ret || max_bits[gr][ch] == 0) 78 | continue; // with next channel 79 | 80 | quantize.VBR_encode_granule( 81 | gfp, 82 | cod_info, 83 | l3_xmin[gr][ch], 84 | xrpow, 85 | ch, 86 | min_bits[gr][ch], 87 | max_bits[gr][ch]); 88 | 89 | /* 90 | * do the 'substep shaping' 91 | */ 92 | if ((gfc.substep_shaping & 1) != 0) 93 | quantize.trancate_smallspectrums(gfc, l3_side.tt[gr][ch], l3_xmin[gr][ch], xrpow); 94 | 95 | var usedB = cod_info.part2_3_length + cod_info.part2_length; 96 | used_bits += usedB; 97 | } // for ch 98 | 99 | /* 100 | * find lowest bitrate able to hold used bits 101 | */ 102 | if (analog_silence != 0 && 0 == gfp.VBR_hard_min) 103 | gfc.bitrate_index = 1; 104 | else 105 | gfc.bitrate_index = gfc.VBR_min_bitrate; 106 | 107 | for (; gfc.bitrate_index < gfc.VBR_max_bitrate; gfc.bitrate_index++) 108 | if (used_bits <= frameBits[gfc.bitrate_index]) 109 | break; 110 | 111 | var mb = new MeanBits(mean_bits); 112 | var bits = quantize.rv.ResvFrameBegin(gfp, mb); 113 | mean_bits = mb.bits; 114 | 115 | if (used_bits <= bits) 116 | break; 117 | 118 | quantize.bitpressure_strategy(gfc, l3_xmin, min_bits, max_bits); 119 | 120 | } 121 | /* breaks adjusted */ 122 | /*--------------------------------------*/ 123 | 124 | for (var gr = 0; gr < gfc.mode_gr; gr++) 125 | for (var ch = 0; ch < gfc.channels_out; ch++) 126 | quantize.iteration_finish_one(gfc, gr, ch); 127 | 128 | quantize.rv.ResvFrameEnd(gfc, mean_bits); 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /Mp3/Mp3/PlottingData.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | /* 8 | * GTK plotting routines source file 9 | * 10 | * Copyright (c) 1999 Mark Taylor 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2 of the License, or (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Library General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the 24 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 25 | * Boston, MA 02111-1307, USA. 26 | */ 27 | using GroovyCodecs.Mp3.Common; 28 | 29 | namespace GroovyCodecs.Mp3.Mp3 30 | { 31 | /// 32 | /// used by the frame analyzer 33 | /// 34 | internal class PlottingData 35 | { 36 | 37 | internal int[][] big_values = Arrays.ReturnRectangularArray(2, 2); 38 | 39 | internal int[][] blocktype = Arrays.ReturnRectangularArray(2, 2); 40 | 41 | internal int crc, padding; 42 | 43 | internal double[][][] en = Arrays.ReturnRectangularArray(2, 4, Encoder.SBMAX_l); 44 | 45 | internal double[][][] en_s = Arrays.ReturnRectangularArray(2, 4, 3 * Encoder.SBMAX_s); 46 | 47 | internal double[][][] energy = Arrays.ReturnRectangularArray(2, 4, Encoder.BLKSIZE); 48 | 49 | /* L,R, M and S values */ 50 | 51 | /// 52 | /// psymodel is one ahead 53 | /// 54 | internal double[][] energy_save = Arrays.ReturnRectangularArray(4, Encoder.BLKSIZE); 55 | 56 | internal double[][] ers = Arrays.ReturnRectangularArray(2, 4); 57 | 58 | /// 59 | /// psymodel is one ahead 60 | /// 61 | internal double[] ers_save = new double[4]; 62 | 63 | internal int framesize, stereo, js, ms_stereo, i_stereo, emph, bitrate, sampfreq, maindata; 64 | 65 | internal int[][] LAMEmainbits = Arrays.ReturnRectangularArray(2, 2); 66 | 67 | internal int[][] LAMEqss = Arrays.ReturnRectangularArray(2, 2); 68 | 69 | internal double[][][] LAMEsfb = Arrays.ReturnRectangularArray(2, 2, Encoder.SBMAX_l); 70 | 71 | internal double[][][] LAMEsfb_s = Arrays.ReturnRectangularArray(2, 2, 3 * Encoder.SBMAX_s); 72 | 73 | internal int[][] LAMEsfbits = Arrays.ReturnRectangularArray(2, 2); 74 | 75 | internal int[][] mainbits = Arrays.ReturnRectangularArray(2, 2); 76 | 77 | internal double[][] max_noise = Arrays.ReturnRectangularArray(2, 2); 78 | 79 | internal int mean_bits; 80 | 81 | internal int[][] mixed = Arrays.ReturnRectangularArray(2, 2); 82 | 83 | internal int[][] mpg123blocktype = Arrays.ReturnRectangularArray(2, 2); 84 | 85 | internal double[][][] mpg123xr = Arrays.ReturnRectangularArray(2, 2, 576); 86 | 87 | internal double[] ms_ener_ratio = new double[2]; 88 | 89 | internal double[] ms_ratio = new double[2]; 90 | 91 | internal int[][] over = Arrays.ReturnRectangularArray(2, 2); 92 | 93 | internal double[][] over_noise = Arrays.ReturnRectangularArray(2, 2); 94 | 95 | internal int[][] over_SSD = Arrays.ReturnRectangularArray(2, 2); 96 | 97 | internal double[][] pcmdata = Arrays.ReturnRectangularArray(2, 1600); 98 | 99 | internal double[][] pcmdata2 = 100 | Arrays.ReturnRectangularArray(2, 1152 + 1152 - Encoder.DECDELAY); 101 | 102 | internal double[][] pe = Arrays.ReturnRectangularArray(2, 4); 103 | 104 | internal int[][] preflag = Arrays.ReturnRectangularArray(2, 2); 105 | 106 | internal int[][] qss = Arrays.ReturnRectangularArray(2, 2); 107 | 108 | internal int resvsize; 109 | 110 | internal int[][] scalefac_scale = Arrays.ReturnRectangularArray(2, 2); 111 | 112 | internal int[] scfsi = new int[2]; 113 | 114 | internal double[][][] sfb = Arrays.ReturnRectangularArray(2, 2, Encoder.SBMAX_l); 115 | 116 | internal double[][][] sfb_s = Arrays.ReturnRectangularArray(2, 2, 3 * Encoder.SBMAX_s); 117 | 118 | internal int[][] sfbits = Arrays.ReturnRectangularArray(2, 2); 119 | 120 | internal int[][][] sub_gain = Arrays.ReturnRectangularArray(2, 2, 3); 121 | 122 | internal double[][][] thr = Arrays.ReturnRectangularArray(2, 4, Encoder.SBMAX_l); 123 | 124 | internal double[][][] thr_s = Arrays.ReturnRectangularArray(2, 4, 3 * Encoder.SBMAX_s); 125 | 126 | internal double[][] tot_noise = Arrays.ReturnRectangularArray(2, 2); 127 | 128 | internal int totbits; 129 | 130 | internal double[][][] xfsf = Arrays.ReturnRectangularArray(2, 2, Encoder.SBMAX_l); 131 | 132 | internal double[][][] xfsf_s = Arrays.ReturnRectangularArray(2, 2, 3 * Encoder.SBMAX_s); 133 | 134 | internal double[][][] xr = Arrays.ReturnRectangularArray(2, 2, 576); 135 | } 136 | } -------------------------------------------------------------------------------- /G729/Codec/Filter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * General filter routines. 24 | * 25 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 26 | */ 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Filter 30 | { 31 | 32 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 33 | /* 34 | ITU-T G.729 Annex C - Reference C code for floating point 35 | implementation of G.729 36 | Version 1.01 of 15.September.98 37 | */ 38 | 39 | /* 40 | ---------------------------------------------------------------------- 41 | COPYRIGHT NOTICE 42 | ---------------------------------------------------------------------- 43 | ITU-T G.729 Annex C ANSI C source code 44 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 45 | Sherbrooke. All rights reserved. 46 | 47 | ---------------------------------------------------------------------- 48 | */ 49 | 50 | /* 51 | File : FILTER.C 52 | Used for the floating point version of both 53 | G.729 main body and G.729A 54 | */ 55 | 56 | /** 57 | * Convolve vectors x and h and put result in y. 58 | * 59 | * @param x input : input vector x[0:l] 60 | * @param x_offset input : input vector offset 61 | * @param h input : impulse response or second input h[0:l] 62 | * @param y output: x convolved with h , y[0:l] 63 | * @param l input : dimension of all vectors 64 | */ 65 | 66 | public static void convolve( 67 | float[] x, 68 | int x_offset, 69 | float[] h, 70 | float[] y, 71 | int l 72 | ) 73 | { 74 | float temp; 75 | int i, n; 76 | 77 | for (n = 0; n < l; n++) 78 | { 79 | temp = 0.0f; 80 | for (i = 0; i <= n; i++) 81 | temp += x[x_offset + i] * h[n - i]; 82 | y[n] = temp; 83 | } 84 | } 85 | 86 | /** 87 | * Filter with synthesis filter 1/A(z). 88 | * 89 | * @param a input : predictor coefficients a[0:m] 90 | * @param a_offset input : predictor coefficients a offset 91 | * @param x input : excitation signal 92 | * @param x_offset input : excitation signal offset 93 | * @param y output: filtered output signal 94 | * @param y_offset output: filtered output signal offset 95 | * @param l input : vector dimension 96 | * @param mem in/out: filter memory 97 | * @param mem_offset input : filter memory ofset 98 | * @param update input : 0 = no memory update, 1 = update 99 | */ 100 | 101 | public static void syn_filt( 102 | float[] a, 103 | int a_offset, 104 | float[] x, 105 | int x_offset, 106 | float[] y, 107 | int y_offset, 108 | int l, 109 | float[] mem, 110 | int mem_offset, 111 | int update 112 | ) 113 | { 114 | var L_SUBFR = Ld8k.L_SUBFR; 115 | var M = Ld8k.M; 116 | 117 | int i, j; 118 | 119 | /* This is usually done by memory allocation (l+m) */ 120 | var yy_b = new float[L_SUBFR + M]; 121 | float s; 122 | int yy, py, pa; 123 | /* Copy mem[] to yy[] */ 124 | yy = 0; //index instead of pointer 125 | for (i = 0; i < M; i++) yy_b[yy++] = mem[mem_offset++]; 126 | 127 | /* Filtering */ 128 | 129 | for (i = 0; i < l; i++) 130 | { 131 | py = yy; 132 | pa = 0; //index instead of pointer 133 | s = x[x_offset++]; 134 | for (j = 0; j < M; j++) s -= a[a_offset + ++pa] * yy_b[--py]; 135 | yy_b[yy++] = s; 136 | y[y_offset++] = s; 137 | } 138 | 139 | /* Update memory if required */ 140 | 141 | if (update != 0) 142 | for (i = 0; i < M; i++) 143 | mem[--mem_offset] = yy_b[--yy]; 144 | } 145 | 146 | /** 147 | * Filter input vector with all-zero filter A(Z). 148 | * 149 | * @param a input : prediction coefficients a[0:m+1], a[0]=1. 150 | * @param a_offset input : prediction coefficients a offset 151 | * @param x input : input signal x[0:l-1], x[-1:m] are needed 152 | * @param x_offset input : input signal x offset 153 | * @param y output: output signal y[0:l-1]. 154 | * NOTE: x[] and y[] cannot point to same array 155 | * @param y_offset input : output signal y offset 156 | * @param l input : dimension of x and y 157 | */ 158 | 159 | public static void residu( 160 | float[] a, 161 | int a_offset, 162 | float[] x, 163 | int x_offset, 164 | float[] y, 165 | int y_offset, 166 | int l 167 | ) 168 | { 169 | var M = Ld8k.M; 170 | 171 | float s; 172 | int i, j; 173 | 174 | for (i = 0; i < l; i++) 175 | { 176 | s = x[x_offset + i]; 177 | for (j = 1; j <= M; j++) s += a[a_offset + j] * x[x_offset + i - j]; 178 | y[y_offset + i] = s; 179 | } 180 | } 181 | } 182 | } -------------------------------------------------------------------------------- /Mp3/Mp3/LongBlockConstrain.cs: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // This conversion was produced by the Free Edition of 3 | // Java to C# Converter courtesy of Tangible Software Solutions. 4 | // Order the Premium Edition at https://www.tangiblesoftwaresolutions.com 5 | //======================================================================== 6 | 7 | using System; 8 | using System.Diagnostics; 9 | 10 | namespace GroovyCodecs.Mp3.Mp3 11 | { 12 | 13 | internal sealed class LongBlockConstrain : VBRQuantize.alloc_sf_f 14 | { 15 | /// 16 | private readonly VBRQuantize vbrQuantize; 17 | 18 | /// 19 | internal LongBlockConstrain(VBRQuantize vbrQuantize) 20 | { 21 | this.vbrQuantize = vbrQuantize; 22 | } 23 | 24 | /// 25 | /// **************************************************************** 26 | /// long block scalefacs 27 | /// ***************************************************************** 28 | /// 29 | public void alloc(VBRQuantize.algo_t that, int[] vbrsf, int[] vbrsfmin, int vbrmax) 30 | { 31 | 32 | var cod_info = that.cod_info; 33 | 34 | var gfc = that.gfc; 35 | int[] max_rangep; 36 | 37 | var maxminsfb = that.mingain_l; 38 | int sfb; 39 | int maxover0, maxover1, maxover0p, maxover1p, mover, delta = 0; 40 | int v, v0, v1, v0p, v1p, vm0p = 1, vm1p = 1; 41 | 42 | var psymax = cod_info.psymax; 43 | 44 | max_rangep = gfc.mode_gr == 2 ? VBRQuantize.max_range_long : VBRQuantize.max_range_long_lsf_pretab; 45 | 46 | maxover0 = 0; 47 | maxover1 = 0; 48 | maxover0p = 0; // pretab 49 | maxover1p = 0; // pretab 50 | 51 | for (sfb = 0; sfb < psymax; ++sfb) 52 | { 53 | Debug.Assert(vbrsf[sfb] >= vbrsfmin[sfb]); 54 | v = vbrmax - vbrsf[sfb]; 55 | if (delta < v) 56 | delta = v; 57 | 58 | v0 = v - 2 * VBRQuantize.max_range_long[sfb]; 59 | v1 = v - 4 * VBRQuantize.max_range_long[sfb]; 60 | v0p = v - 2 * (max_rangep[sfb] + vbrQuantize.qupvt.pretab[sfb]); 61 | v1p = v - 4 * (max_rangep[sfb] + vbrQuantize.qupvt.pretab[sfb]); 62 | if (maxover0 < v0) 63 | maxover0 = v0; 64 | 65 | if (maxover1 < v1) 66 | maxover1 = v1; 67 | 68 | if (maxover0p < v0p) 69 | maxover0p = v0p; 70 | 71 | if (maxover1p < v1p) 72 | maxover1p = v1p; 73 | } 74 | 75 | if (vm0p == 1) 76 | { 77 | var gain = vbrmax - maxover0p; 78 | if (gain < maxminsfb) 79 | gain = maxminsfb; 80 | 81 | for (sfb = 0; sfb < psymax; ++sfb) 82 | { 83 | 84 | var a = gain - vbrsfmin[sfb] - 2 * vbrQuantize.qupvt.pretab[sfb]; 85 | if (a <= 0) 86 | { 87 | vm0p = 0; 88 | vm1p = 0; 89 | break; 90 | } 91 | } 92 | } 93 | 94 | if (vm1p == 1) 95 | { 96 | var gain = vbrmax - maxover1p; 97 | if (gain < maxminsfb) 98 | gain = maxminsfb; 99 | 100 | for (sfb = 0; sfb < psymax; ++sfb) 101 | { 102 | 103 | var b = gain - vbrsfmin[sfb] - 4 * vbrQuantize.qupvt.pretab[sfb]; 104 | if (b <= 0) 105 | { 106 | vm1p = 0; 107 | break; 108 | } 109 | } 110 | } 111 | 112 | if (vm0p == 0) 113 | maxover0p = maxover0; 114 | 115 | if (vm1p == 0) 116 | maxover1p = maxover1; 117 | 118 | if (gfc.noise_shaping != 2) 119 | { 120 | maxover1 = maxover0; 121 | maxover1p = maxover0p; 122 | } 123 | 124 | mover = Math.Min(maxover0, maxover0p); 125 | mover = Math.Min(mover, maxover1); 126 | mover = Math.Min(mover, maxover1p); 127 | 128 | if (delta > mover) 129 | delta = mover; 130 | 131 | vbrmax -= delta; 132 | if (vbrmax < maxminsfb) 133 | vbrmax = maxminsfb; 134 | 135 | maxover0 -= mover; 136 | maxover0p -= mover; 137 | maxover1 -= mover; 138 | maxover1p -= mover; 139 | 140 | if (maxover0 == 0) 141 | { 142 | cod_info.scalefac_scale = 0; 143 | cod_info.preflag = 0; 144 | max_rangep = VBRQuantize.max_range_long; 145 | } 146 | else if (maxover0p == 0) 147 | { 148 | cod_info.scalefac_scale = 0; 149 | cod_info.preflag = 1; 150 | } 151 | else if (maxover1 == 0) 152 | { 153 | cod_info.scalefac_scale = 1; 154 | cod_info.preflag = 0; 155 | max_rangep = VBRQuantize.max_range_long; 156 | } 157 | else if (maxover1p == 0) 158 | { 159 | cod_info.scalefac_scale = 1; 160 | cod_info.preflag = 1; 161 | } 162 | else 163 | { 164 | Debug.Assert(false); // this should not happen 165 | } 166 | 167 | cod_info.global_gain = vbrmax; 168 | if (cod_info.global_gain < 0) 169 | cod_info.global_gain = 0; 170 | else if (cod_info.global_gain > 255) 171 | cod_info.global_gain = 255; 172 | 173 | { 174 | var sf_temp = new int[L3Side.SFBMAX]; 175 | for (sfb = 0; sfb < L3Side.SFBMAX; ++sfb) 176 | sf_temp[sfb] = vbrsf[sfb] - vbrmax; 177 | 178 | vbrQuantize.set_scalefacs(cod_info, vbrsfmin, sf_temp, max_rangep); 179 | } 180 | Debug.Assert(vbrQuantize.checkScalefactor(cod_info, vbrsfmin)); 181 | 182 | } 183 | } 184 | } -------------------------------------------------------------------------------- /G729/Codec/Pwf.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | using System; 26 | 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Pwf 30 | { 31 | private readonly float[ /* 2 */] lar_old = 32 | { 33 | 0.0f, 34 | 0.0f 35 | }; 36 | 37 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 38 | /* 39 | ITU-T G.729 Annex C - Reference C code for floating point 40 | implementation of G.729 41 | Version 1.01 of 15.September.98 42 | */ 43 | 44 | /* 45 | ---------------------------------------------------------------------- 46 | COPYRIGHT NOTICE 47 | ---------------------------------------------------------------------- 48 | ITU-T G.729 Annex C ANSI C source code 49 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 50 | Sherbrooke. All rights reserved. 51 | 52 | ---------------------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | File : PWF.C 57 | Used for the floating point version of G.729 main body 58 | (not for G.729A) 59 | */ 60 | 61 | private int smooth = 1; 62 | 63 | /** 64 | * Adaptive bandwidth expansion for perceptual weighting filter 65 | * 66 | * @param gamma1 output: gamma1 value 67 | * @param gamma2 output: gamma2 value 68 | * @param lsfint input : Interpolated lsf vector : 1st subframe 69 | * @param lsfnew input : lsf vector : 2nd subframe 70 | * @param r_c input : Reflection coefficients 71 | */ 72 | 73 | public void perc_var( 74 | float[] gamma1, 75 | float[] gamma2, 76 | float[] lsfint, 77 | float[] lsfnew, 78 | float[] r_c 79 | ) 80 | { 81 | var ALPHA = Ld8k.ALPHA; 82 | var BETA = Ld8k.BETA; 83 | var GAMMA1_0 = Ld8k.GAMMA1_0; 84 | var GAMMA1_1 = Ld8k.GAMMA1_1; 85 | var GAMMA2_0_H = Ld8k.GAMMA2_0_H; 86 | var GAMMA2_0_L = Ld8k.GAMMA2_0_L; 87 | var GAMMA2_1 = Ld8k.GAMMA2_1; 88 | var M = Ld8k.M; 89 | var THRESH_H1 = Ld8k.THRESH_H1; 90 | var THRESH_H2 = Ld8k.THRESH_H2; 91 | var THRESH_L1 = Ld8k.THRESH_L1; 92 | var THRESH_L2 = Ld8k.THRESH_L2; 93 | 94 | var lar = new float[4]; 95 | float[] lsf; 96 | float critlar0, critlar1; 97 | float d_min, temp; 98 | int i, k; 99 | 100 | var lar_new = lar; 101 | var lar_new_offset = 2; 102 | 103 | /* reflection coefficients --> lar */ 104 | for (i = 0; i < 2; i++) 105 | lar_new[lar_new_offset + i] = (float)Math.Log10((1.0f + r_c[i]) / (1.0f - r_c[i])); 106 | 107 | /* Interpolation of lar for the 1st subframe */ 108 | for (i = 0; i < 2; i++) 109 | { 110 | lar[i] = 0.5f * (lar_new[lar_new_offset + i] + lar_old[i]); 111 | lar_old[i] = lar_new[lar_new_offset + i]; 112 | } 113 | 114 | for (k = 0; k < 2; k++) 115 | { 116 | /* LOOP : gamma2 for 1st to 2nd subframes */ 117 | 118 | /* ----------------------------------------------------- */ 119 | /* First criterion based on the first two lars */ 120 | /* */ 121 | /* smooth == 1 ==> gamma2 is set to 0.6 */ 122 | /* gamma1 is set to 0.94 */ 123 | /* */ 124 | /* smooth == 0 ==> gamma2 can vary from 0.4 to 0.7 */ 125 | /* (gamma2 = -6.0 dmin + 1.0) */ 126 | /* gamma1 is set to 0.98 */ 127 | /* ----------------------------------------------------- */ 128 | critlar0 = lar[2 * k]; 129 | critlar1 = lar[2 * k + 1]; 130 | 131 | if (smooth != 0) 132 | { 133 | if (critlar0 < THRESH_L1 && critlar1 > THRESH_H1) smooth = 0; 134 | } 135 | else 136 | { 137 | if (critlar0 > THRESH_L2 || critlar1 < THRESH_H2) smooth = 1; 138 | } 139 | 140 | if (smooth == 0) 141 | { 142 | /* ------------------------------------------------------ */ 143 | /* Second criterion based on the minimum distance between */ 144 | /* two successives lsfs */ 145 | /* ------------------------------------------------------ */ 146 | gamma1[k] = GAMMA1_0; 147 | if (k == 0) lsf = lsfint; 148 | else lsf = lsfnew; 149 | d_min = lsf[1] - lsf[0]; 150 | for (i = 1; i < M - 1; i++) 151 | { 152 | temp = lsf[i + 1] - lsf[i]; 153 | if (temp < d_min) d_min = temp; 154 | } 155 | 156 | gamma2[k] = ALPHA * d_min + BETA; 157 | 158 | if (gamma2[k] > GAMMA2_0_H) gamma2[k] = GAMMA2_0_H; 159 | if (gamma2[k] < GAMMA2_0_L) gamma2[k] = GAMMA2_0_L; 160 | } 161 | else 162 | { 163 | gamma1[k] = GAMMA1_1; 164 | gamma2[k] = GAMMA2_1; 165 | ; 166 | } 167 | } 168 | } 169 | } 170 | } -------------------------------------------------------------------------------- /Mp3/Mp3Decoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Text; 5 | using GroovyCodecs.Mp3.Common; 6 | using GroovyCodecs.Mp3.Mp3; 7 | using GroovyCodecs.Mp3.Mpg; 8 | using GroovyCodecs.Types; 9 | 10 | namespace GroovyCodecs.Mp3 11 | { 12 | 13 | public class Mp3Decoder : IMp3Decoder 14 | { 15 | 16 | private readonly BitStream bs; 17 | 18 | private readonly short[][] buffer = Arrays.ReturnRectangularArray(2, 1152); 19 | 20 | private readonly Mpg.Common common; 21 | 22 | private readonly GainAnalysis ga; 23 | 24 | private readonly GetAudio gaud; 25 | 26 | // private DataOutput outf; 27 | private readonly LameGlobalFlags gfp; 28 | 29 | private readonly ID3Tag id3; 30 | 31 | private readonly Interface intf; 32 | 33 | private readonly Lame lame; 34 | 35 | private readonly MPGLib mpg; 36 | 37 | private readonly Presets p; 38 | 39 | private readonly Parse parse; 40 | 41 | private readonly Quantize qu; 42 | 43 | private readonly QuantizePVT qupvt; 44 | 45 | private readonly Reservoir rv; 46 | 47 | private readonly Takehiro tak; 48 | 49 | private readonly VBRTag vbr; 50 | 51 | private readonly Mp3Version ver; 52 | 53 | private int wavsize; 54 | 55 | public Mp3Decoder(string mp3File) 56 | { 57 | // encoder modules 58 | lame = new Lame(); 59 | gaud = new GetAudio(); 60 | ga = new GainAnalysis(); 61 | bs = new BitStream(); 62 | p = new Presets(); 63 | qupvt = new QuantizePVT(); 64 | qu = new Quantize(); 65 | vbr = new VBRTag(); 66 | ver = new Mp3Version(); 67 | id3 = new ID3Tag(); 68 | rv = new Reservoir(); 69 | tak = new Takehiro(); 70 | parse = new Parse(); 71 | 72 | mpg = new MPGLib(); 73 | intf = new Interface(); 74 | common = new Mpg.Common(); 75 | 76 | lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg); 77 | bs.setModules(ga, mpg, ver, vbr); 78 | id3.setModules(bs, ver); 79 | p.Modules = lame; 80 | qu.setModules(bs, rv, qupvt, tak); 81 | qupvt.setModules(tak, rv, lame.enc.psy); 82 | rv.Modules = bs; 83 | tak.Modules = qupvt; 84 | vbr.setModules(lame, bs, ver); 85 | gaud.setModules(parse, mpg); 86 | parse.setModules(ver, id3, p); 87 | 88 | // decoder modules 89 | mpg.setModules(intf, common); 90 | intf.setModules(vbr, common); 91 | 92 | gfp = lame.lame_init(); 93 | 94 | /* 95 | * turn off automatic writing of ID3 tag data into mp3 stream we have to 96 | * call it before 'lame_init_params', because that function would spit 97 | * out ID3v2 tag data. 98 | */ 99 | gfp.write_id3tag_automatic = false; 100 | 101 | /* 102 | * Now that all the options are set, lame needs to analyze them and set 103 | * some more internal options and check for problems 104 | */ 105 | lame.lame_init_params(gfp); 106 | 107 | parse.input_format = GetAudio.sound_file_format.sf_mp3; 108 | 109 | var inPath = new StringBuilder(mp3File); 110 | var enc = new Enc(); 111 | 112 | gaud.init_infile(gfp, inPath.ToString(), enc); 113 | 114 | var skip_start = 0; 115 | var skip_end = 0; 116 | 117 | if (parse.silent < 10) 118 | Console.Write( 119 | "\rinput: {0}{1}({2:g} kHz, {3:D} channel{4}, ", 120 | inPath, 121 | inPath.Length > 26 ? "\n\t" : " ", 122 | gfp.in_samplerate / 1000, 123 | gfp.num_channels, 124 | gfp.num_channels != 1 ? "s" : ""); 125 | 126 | if (enc.enc_delay > -1 || enc.enc_padding > -1) 127 | { 128 | if (enc.enc_delay > -1) 129 | skip_start = enc.enc_delay + 528 + 1; 130 | 131 | if (enc.enc_padding > -1) 132 | skip_end = enc.enc_padding - (528 + 1); 133 | } 134 | else 135 | { 136 | skip_start = gfp.encoder_delay + 528 + 1; 137 | } 138 | 139 | Console.Write("MPEG-{0:D}{1} Layer {2}", 2 - gfp.version, gfp.out_samplerate < 16000 ? ".5" : "", "III"); 140 | 141 | Console.Write(")\noutput: (16 bit, Microsoft WAVE)\n"); 142 | 143 | if (skip_start > 0) 144 | Console.Write("skipping initial {0:D} samples (encoder+decoder delay)\n", skip_start); 145 | 146 | if (skip_end > 0) 147 | Console.Write("skipping final {0:D} samples (encoder padding-decoder delay)\n", skip_end); 148 | 149 | wavsize = -(skip_start + skip_end); 150 | parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize; 151 | 152 | Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2); 153 | } 154 | 155 | public virtual void decode(MemoryStream sampleBuffer, bool playOriginal) 156 | { 157 | var iread = gaud.get_audio16(gfp, buffer); 158 | if (iread >= 0) 159 | { 160 | parse.mp3input_data.framenum += iread / parse.mp3input_data.framesize; 161 | wavsize += iread; 162 | 163 | for (var i = 0; i < iread; i++) 164 | { 165 | if (playOriginal) 166 | { 167 | // We put mp3 data into the sample buffer here! 168 | sampleBuffer.WriteByte(unchecked((byte)(buffer[0][i] & 0xff))); 169 | sampleBuffer.WriteByte(unchecked((byte)(((buffer[0][i] & 0xffff) >> 8) & 0xff))); 170 | } 171 | 172 | if (gfp.num_channels == 2) 173 | { 174 | // gaud.write16BitsLowHigh(outf, buffer[1][i] & 0xffff); 175 | // TODO two channels? 176 | } 177 | } 178 | } 179 | 180 | } 181 | 182 | public virtual void close() 183 | { 184 | lame.lame_close(gfp); 185 | } 186 | } 187 | } -------------------------------------------------------------------------------- /G729/Codec/Lspdec.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | using System; 26 | 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Lspdec 30 | { 31 | 32 | /** 33 | * Previous LSP vector(init) 34 | */ 35 | private static readonly float[ /* M */] FREQ_PREV_RESET = 36 | { 37 | 0.285599f, 38 | 0.571199f, 39 | 0.856798f, 40 | 1.142397f, 41 | 1.427997f, 42 | 1.713596f, 43 | 1.999195f, 44 | 2.284795f, 45 | 2.570394f, 46 | 2.855993f 47 | }; /* PI*(float)(j+1)/(float)(M+1) */ 48 | 49 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 50 | /* 51 | ITU-T G.729 Annex C - Reference C code for floating point 52 | implementation of G.729 53 | Version 1.01 of 15.September.98 54 | */ 55 | 56 | /* 57 | ---------------------------------------------------------------------- 58 | COPYRIGHT NOTICE 59 | ---------------------------------------------------------------------- 60 | ITU-T G.729 Annex C ANSI C source code 61 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 62 | Sherbrooke. All rights reserved. 63 | 64 | ---------------------------------------------------------------------- 65 | */ 66 | 67 | /* 68 | File : LSPDEC.C 69 | Used for the floating point version of both 70 | G.729 main body and G.729A 71 | */ 72 | 73 | private static readonly int M = Ld8k.M; 74 | 75 | private static readonly int MA_NP = Ld8k.MA_NP; 76 | 77 | /* static memory */ 78 | /** 79 | * Previous LSP vector 80 | */ 81 | private readonly float[][] freq_prev = new float[MA_NP][ /* M */]; 82 | 83 | /** 84 | * Previous LSP vector 85 | */ 86 | private readonly float[] prev_lsp = new float[M]; 87 | 88 | /* static memory for frame erase operation */ 89 | /** 90 | * Previous MA prediction coef 91 | */ 92 | private int prev_ma; 93 | 94 | public Lspdec() 95 | { 96 | // need this to initialize freq_prev 97 | for (var i = 0; i < freq_prev.Length; i++) 98 | freq_prev[i] = new float[M]; 99 | } 100 | 101 | /** 102 | * Set the previous LSP vectors. 103 | */ 104 | 105 | public void lsp_decw_reset() 106 | { 107 | int i; 108 | 109 | for (i = 0; i < MA_NP; i++) 110 | Util.copy(FREQ_PREV_RESET, freq_prev[i], M); 111 | 112 | prev_ma = 0; 113 | 114 | Util.copy(FREQ_PREV_RESET, prev_lsp, M); 115 | } 116 | 117 | private static int ZFRS(int i, int j) 118 | { 119 | var maskIt = i < 0; 120 | i = i >> j; 121 | if (maskIt) 122 | i &= 0x7FFFFFFF; 123 | return i; 124 | } 125 | 126 | /** 127 | * LSP main quantization routine 128 | * 129 | * @param prm input : codes of the selected LSP 130 | * @param prm_offset input : codes offset 131 | * @param lsp_q output: Quantized LSP parameters 132 | * @param erase input : frame erase information 133 | */ 134 | private void lsp_iqua_cs( 135 | int[] prm, 136 | int prm_offset, 137 | float[] lsp_q, 138 | int erase 139 | ) 140 | { 141 | var NC0 = Ld8k.NC0; 142 | var NC0_B = Ld8k.NC0_B; 143 | var NC1 = Ld8k.NC1; 144 | var NC1_B = Ld8k.NC1_B; 145 | var fg = TabLd8k.fg; 146 | var fg_sum = TabLd8k.fg_sum; 147 | var fg_sum_inv = TabLd8k.fg_sum_inv; 148 | var lspcb1 = TabLd8k.lspcb1; 149 | var lspcb2 = TabLd8k.lspcb2; 150 | 151 | int mode_index; 152 | int code0; 153 | int code1; 154 | int code2; 155 | var buf = new float[M]; 156 | 157 | if (erase == 0) /* Not frame erasure */ 158 | { 159 | mode_index = ZFRS(prm[prm_offset + 0], NC0_B) & 1; 160 | code0 = prm[prm_offset + 0] & (short)(NC0 - 1); 161 | code1 = ZFRS(prm[prm_offset + 1], NC1_B) & (short)(NC1 - 1); 162 | code2 = prm[prm_offset + 1] & (short)(NC1 - 1); 163 | 164 | Lspgetq.lsp_get_quant( 165 | lspcb1, 166 | lspcb2, 167 | code0, 168 | code1, 169 | code2, 170 | fg[mode_index], 171 | freq_prev, 172 | lsp_q, 173 | fg_sum[mode_index]); 174 | 175 | Util.copy(lsp_q, prev_lsp, M); 176 | prev_ma = mode_index; 177 | } 178 | else /* Frame erased */ 179 | { 180 | Util.copy(prev_lsp, lsp_q, M); 181 | 182 | /* update freq_prev */ 183 | Lspgetq.lsp_prev_extract( 184 | prev_lsp, 185 | buf, 186 | fg[prev_ma], 187 | freq_prev, 188 | fg_sum_inv[prev_ma]); 189 | Lspgetq.lsp_prev_update(buf, freq_prev); 190 | } 191 | } 192 | 193 | /** 194 | * Decode lsp parameters 195 | * 196 | * @param index input : indexes 197 | * @param index_offset input : indexes offset 198 | * @param lsp_q output: decoded lsp 199 | * @param bfi input : frame erase information 200 | */ 201 | 202 | public void d_lsp( 203 | int[] index, 204 | int index_offset, 205 | float[] lsp_q, 206 | int bfi 207 | ) 208 | { 209 | int i; 210 | 211 | lsp_iqua_cs(index, index_offset, lsp_q, bfi); /* decode quantized information */ 212 | 213 | /* Convert LSFs to LSPs */ 214 | 215 | for (i = 0; i < M; i++) 216 | lsp_q[i] = (float)Math.Cos(lsp_q[i]); 217 | } 218 | } 219 | } -------------------------------------------------------------------------------- /G729/Codec/Bits.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Bit stream manipulation routines. 24 | *

prm2bits_ld8k -converts encoder parameter vector into vector of serial bits

25 | *

bits2prm_ld8k - converts serial received bits to encoder parameter vector

26 | *
 27 |  * The transmitted parameters for 8000 bits/sec are:
 28 |  *
 29 |  *     LPC:     1st codebook           7+1 bit
 30 |  *              2nd codebook           5+5 bit
 31 |  *
 32 |  *     1st subframe:
 33 |  *          pitch period                 8 bit
 34 |  *          parity check on 1st period   1 bit
 35 |  *          codebook index1 (positions) 13 bit
 36 |  *          codebook index2 (signs)      4 bit
 37 |  *          pitch and codebook gains   4+3 bit
 38 |  *
 39 |  *     2nd subframe:
 40 |  *          pitch period (relative)      5 bit
 41 |  *          codebook index1 (positions) 13 bit
 42 |  *          codebook index2 (signs)      4 bit
 43 |  *          pitch and codebook gains   4+3 bit
 44 |  * 
45 | * 46 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 47 | */ 48 | namespace GroovyCodecs.G729.Codec 49 | { 50 | internal class Bits 51 | { 52 | 53 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 54 | /* 55 | ITU-T G.729 Annex C - Reference C code for floating point 56 | implementation of G.729 57 | Version 1.01 of 15.September.98 58 | */ 59 | 60 | /* 61 | ---------------------------------------------------------------------- 62 | COPYRIGHT NOTICE 63 | ---------------------------------------------------------------------- 64 | ITU-T G.729 Annex C ANSI C source code 65 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 66 | Sherbrooke. All rights reserved. 67 | 68 | ---------------------------------------------------------------------- 69 | */ 70 | 71 | /* 72 | File : BITS.C 73 | Used for the floating point version of both 74 | G.729 main body and G.729A 75 | */ 76 | 77 | /** 78 | * Converts encoder parameter vector into vector of serial bits. 79 | * 80 | * @param prm input : encoded parameters 81 | * @param bits output: serial bits 82 | */ 83 | 84 | public static void prm2bits_ld8k( 85 | int[] prm, 86 | short[] bits 87 | ) 88 | { 89 | var PRM_SIZE = Ld8k.PRM_SIZE; 90 | var SIZE_WORD = Ld8k.SIZE_WORD; 91 | var SYNC_WORD = Ld8k.SYNC_WORD; 92 | var bitsno = TabLd8k.bitsno; 93 | 94 | int j = 0, i; 95 | bits[j] = SYNC_WORD; /* At receiver this bit indicates BFI */ 96 | j++; 97 | bits[j] = SIZE_WORD; /* Number of bits in this frame */ 98 | j++; 99 | 100 | for (i = 0; i < PRM_SIZE; i++) 101 | { 102 | int2bin(prm[i], bitsno[i], bits, j); 103 | j += bitsno[i]; 104 | } 105 | } 106 | 107 | /** 108 | * Convert integer to binary and write the bits bitstream array. 109 | * 110 | * @param value input : decimal value 111 | * @param no_of_bits input : number of bits to use 112 | * @param bitstream output: bitstream 113 | * @param bitstream_offset input: bitstream offset 114 | */ 115 | private static void int2bin( 116 | int value, 117 | int no_of_bits, 118 | short[] bitstream, 119 | int bitstream_offset 120 | ) 121 | { 122 | var BIT_0 = Ld8k.BIT_0; 123 | var BIT_1 = Ld8k.BIT_1; 124 | 125 | int pt_bitstream; 126 | int i, bit; 127 | 128 | pt_bitstream = bitstream_offset + no_of_bits; 129 | 130 | for (i = 0; i < no_of_bits; i++) 131 | { 132 | bit = value & 0x0001; /* get lsb */ 133 | if (bit == 0) 134 | bitstream[--pt_bitstream] = BIT_0; 135 | else 136 | bitstream[--pt_bitstream] = BIT_1; 137 | value >>= 1; 138 | } 139 | } 140 | 141 | /** 142 | * Converts serial received bits to encoder parameter vector. 143 | * 144 | * @param bits input : serial bits 145 | * @param prm output: decoded parameters 146 | */ 147 | private static void bits2prm_ld8k(short[] bits, int[] prm) 148 | { 149 | bits2prm_ld8k(bits, 0, prm, 0); 150 | } 151 | 152 | /** 153 | * Converts serial received bits to encoder parameter vector. 154 | * 155 | * @param bits input : serial bits 156 | * @param bits_offset input : serial bits offset 157 | * @param prm output: decoded parameters 158 | * @param prm_offset input: decoded parameters offset 159 | */ 160 | public static void bits2prm_ld8k( 161 | short[] bits, 162 | int bits_offset, 163 | int[] prm, 164 | int prm_offset 165 | ) 166 | { 167 | var PRM_SIZE = Ld8k.PRM_SIZE; 168 | var bitsno = TabLd8k.bitsno; 169 | 170 | int i; 171 | for (i = 0; i < PRM_SIZE; i++) 172 | { 173 | prm[i + prm_offset] = bin2int(bitsno[i], bits, bits_offset); 174 | bits_offset += bitsno[i]; 175 | } 176 | } 177 | 178 | /** 179 | * Read specified bits from bit array and convert to integer value. 180 | * 181 | * @param no_of_bits input : number of bits to read 182 | * @param bitstream input : array containing bits 183 | * @param bitstream_offset input : array offset 184 | * @return decimal value of bit pattern 185 | */ 186 | private static int bin2int( 187 | int no_of_bits, 188 | short[] bitstream, 189 | int bitstream_offset 190 | ) 191 | { 192 | var BIT_1 = Ld8k.BIT_1; 193 | 194 | int value, i; 195 | int bit; 196 | 197 | value = 0; 198 | for (i = 0; i < no_of_bits; i++) 199 | { 200 | value <<= 1; 201 | bit = bitstream[bitstream_offset++]; 202 | if (bit == BIT_1) value += 1; 203 | } 204 | 205 | return value; 206 | } 207 | } 208 | } -------------------------------------------------------------------------------- /G729/Codec/Util.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * Auxiliary functions. 24 | * 25 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 26 | */ 27 | using System.IO; 28 | 29 | namespace GroovyCodecs.G729.Codec 30 | { 31 | public class Util 32 | { 33 | 34 | /* Random generator */ 35 | private static short seed = 21845; 36 | 37 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 38 | /* 39 | ITU-T G.729 Annex C - Reference C code for floating point 40 | implementation of G.729 41 | Version 1.01 of 15.September.98 42 | */ 43 | 44 | /* 45 | ---------------------------------------------------------------------- 46 | COPYRIGHT NOTICE 47 | ---------------------------------------------------------------------- 48 | ITU-T G.729 Annex C ANSI C source code 49 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 50 | Sherbrooke. All rights reserved. 51 | 52 | ---------------------------------------------------------------------- 53 | */ 54 | 55 | /* 56 | File : UTIL.C 57 | Used for the floating point version of both 58 | G.729 main body and G.729A 59 | */ 60 | 61 | /** 62 | * Assigns the value zero to element of the specified array of floats. 63 | * The number of components set to zero equal to the length argument. 64 | * 65 | * @param x (o) : vector to clear 66 | * @param L (i) : length of vector 67 | */ 68 | public static void set_zero( 69 | float[] x, 70 | int L 71 | ) 72 | { 73 | set_zero(x, 0, L); 74 | } 75 | 76 | /** 77 | * Assigns the value zero to element of the specified array of floats. 78 | * The number of components set to zero equal to the length argument. 79 | * The components at positions offset through offset+length-1 in the 80 | * array are set to zero. 81 | * 82 | * @param x (o) : vector to clear 83 | * @param offset (i) : offset of vector 84 | * @param length (i) : length of vector 85 | */ 86 | public static void set_zero(float[] x, int offset, int length) 87 | { 88 | for (int i = offset, toIndex = offset + length; i < toIndex; i++) 89 | x[i] = 0.0f; 90 | } 91 | 92 | /** 93 | * Copies an array from the specified x array, to the specified y array. 94 | * The number of components copied is equal to the length argument. 95 | * 96 | * @param x (i) : input vector 97 | * @param y (o) : output vector 98 | * @param L (i) : vector length 99 | */ 100 | public static void copy( 101 | float[] x, 102 | float[] y, 103 | int L 104 | ) 105 | { 106 | copy(x, 0, y, L); 107 | } 108 | 109 | /** 110 | * Copies an array from the specified source array, 111 | * beginning at the specified destination array. 112 | * A subsequence of array components are copied from the source array referenced 113 | * by x to the destination array referenced by y. 114 | * The number of components copied is equal to the length argument. 115 | * The components at positions x_offset through x_offset+length-1 in the source 116 | * array are copied into positions 0 through length-1, 117 | * respectively, of the destination array. 118 | * 119 | * @param x (i) : input vector 120 | * @param x_offset (i) : input vector offset 121 | * @param y (o) : output vector 122 | * @param L (i) : vector length 123 | */ 124 | public static void copy(float[] x, int x_offset, float[] y, int L) 125 | { 126 | copy(x, x_offset, y, 0, L); 127 | } 128 | 129 | /** 130 | * Copies an array from the specified source array, 131 | * beginning at the specified position, 132 | * to the specified position of the destination array. 133 | * A subsequence of array components are copied from the source array referenced 134 | * by x to the destination array referenced by y. 135 | * The number of components copied is equal to the length argument. 136 | * The components at positions x_offset through x_offset+length-1 in the source 137 | * array are copied into positions y_offset through y_offset+length-1, 138 | * respectively, of the destination array. 139 | * 140 | * @param x (i) : input vector 141 | * @param x_offset (i) : input vector offset 142 | * @param y (o) : output vector 143 | * @param y_offset (i) : output vector offset 144 | * @param L (i) : vector length 145 | */ 146 | public static void copy(float[] x, int x_offset, float[] y, int y_offset, int L) 147 | { 148 | int i; 149 | 150 | for (i = 0; i < L; i++) 151 | y[y_offset + i] = x[x_offset + i]; 152 | } 153 | 154 | /** 155 | * Return random short. 156 | * 157 | * @return random short 158 | */ 159 | public static short random_g729() 160 | { 161 | seed = (short)(seed * 31821L + 13849L); 162 | 163 | return seed; 164 | } 165 | 166 | /** 167 | * Write data in fp 168 | * 169 | * @param data 170 | * @param length 171 | * @param fp 172 | * @throws java.io.IOException 173 | */ 174 | public static void fwrite(short[] data, int length, Stream fp) 175 | 176 | { 177 | var bytes = new byte[2]; 178 | 179 | for (var i = 0; i < length; i++) 180 | { 181 | int value = data[i]; 182 | bytes[0] = (byte)(value & 0xFF); 183 | bytes[1] = (byte)(value >> 8); 184 | fp.Write(bytes, 0, bytes.Length); 185 | } 186 | } 187 | 188 | /** 189 | * Read data from fp. 190 | * 191 | * @param data 192 | * @param length 193 | * @param fp 194 | * @return length of resulting data array 195 | * @throws java.io.IOException 196 | */ 197 | public static int fread(short[] data, int length, Stream fp) 198 | 199 | { 200 | var bytes = new byte[2]; 201 | var readLength = 0; 202 | 203 | for (var i = 0; i < length; i++) 204 | { 205 | if (fp.Read(bytes, 0, bytes.Length) != 2) 206 | break; 207 | data[i] = (short)((bytes[1] << 8) | (bytes[0] & 0x00FF)); 208 | readLength++; 209 | } 210 | 211 | return readLength; 212 | } 213 | } 214 | } -------------------------------------------------------------------------------- /G729/Codec/Lpcfunc.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * WARNING: The use of G.729 may require a license fee and/or royalty fee in 18 | * some countries and is licensed by 19 | * SIPRO Lab Telecom. 20 | */ 21 | 22 | /** 23 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 24 | */ 25 | using System; 26 | 27 | namespace GroovyCodecs.G729.Codec 28 | { 29 | internal class Lpcfunc 30 | { 31 | 32 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 33 | /* 34 | ITU-T G.729 Annex C - Reference C code for floating point 35 | implementation of G.729 36 | Version 1.01 of 15.September.98 37 | */ 38 | 39 | /* 40 | ---------------------------------------------------------------------- 41 | COPYRIGHT NOTICE 42 | ---------------------------------------------------------------------- 43 | ITU-T G.729 Annex C ANSI C source code 44 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 45 | Sherbrooke. All rights reserved. 46 | 47 | ---------------------------------------------------------------------- 48 | */ 49 | 50 | /* 51 | File : LPCFUNC.C 52 | Used for the floating point version of G.729 main body 53 | (not for G.729A) 54 | */ 55 | 56 | /** 57 | * Convert LSPs to predictor coefficients a[] 58 | * 59 | * @param lsp input : lsp[0:M-1] 60 | * @param a output: predictor coeffs a[0:M], a[0] = 1. 61 | * @param a_offset input: predictor coeffs a offset. 62 | */ 63 | private static void lsp_az( 64 | float[] lsp, 65 | float[] a, 66 | int a_offset 67 | ) 68 | { 69 | var M = Ld8k.M; 70 | var NC = Ld8k.NC; 71 | 72 | float[] f1 = new float[NC + 1], f2 = new float[NC + 1]; 73 | int i, j; 74 | 75 | get_lsp_pol(lsp, 0, f1); 76 | get_lsp_pol(lsp, 1, f2); 77 | 78 | for (i = NC; i > 0; i--) 79 | { 80 | f1[i] += f1[i - 1]; 81 | f2[i] -= f2[i - 1]; 82 | } 83 | 84 | a[a_offset + 0] = 1.0f; 85 | for (i = 1, j = M; i <= NC; i++, j--) 86 | { 87 | a[a_offset + i] = 0.5f * (f1[i] + f2[i]); 88 | a[a_offset + j] = 0.5f * (f1[i] - f2[i]); 89 | } 90 | } 91 | 92 | /** 93 | * Find the polynomial F1(z) or F2(z) from the LSFs 94 | * 95 | * @param lsp input : line spectral freq. (cosine domain) 96 | * @param lsp_offset input : line spectral freq offset 97 | * @param f output: the coefficients of F1 or F2 98 | */ 99 | private static void get_lsp_pol( 100 | float[] lsp, 101 | int lsp_offset, 102 | float[] f 103 | ) 104 | { 105 | var NC = Ld8k.NC; 106 | 107 | float b; 108 | int i, j; 109 | 110 | f[0] = 1.0f; 111 | b = -2.0f * lsp[lsp_offset + 0]; 112 | f[1] = b; 113 | for (i = 2; i <= NC; i++) 114 | { 115 | b = -2.0f * lsp[lsp_offset + 2 * i - 2]; 116 | f[i] = b * f[i - 1] + 2.0f * f[i - 2]; 117 | for (j = i - 1; j > 1; j--) 118 | f[j] += b * f[j - 1] + f[j - 2]; 119 | f[1] += b; 120 | } 121 | } 122 | 123 | /** 124 | * Convert from lsf[0..M-1 to lsp[0..M-1] 125 | * 126 | * @param lsf input : lsf 127 | * @param lsp output: lsp 128 | * @param m input : length 129 | */ 130 | private static void lsf_lsp( 131 | float[] lsf, 132 | float[] lsp, 133 | int m 134 | ) 135 | { 136 | int i; 137 | for (i = 0; i < m; i++) 138 | lsp[i] = (float)Math.Cos(lsf[i]); 139 | } 140 | 141 | /** 142 | * Convert from lsp[0..M-1 to lsf[0..M-1] 143 | * 144 | * @param lsp input : lsp coefficients 145 | * @param lsf output: lsf (normalized frequencies 146 | * @param m input: length 147 | */ 148 | private static void lsp_lsf( 149 | float[] lsp, 150 | float[] lsf, 151 | int m 152 | ) 153 | { 154 | int i; 155 | 156 | for (i = 0; i < m; i++) 157 | lsf[i] = (float)Math.Acos(lsp[i]); 158 | } 159 | 160 | /** 161 | * Weighting of LPC coefficients ap[i] = a[i] * (gamma ** i) 162 | * 163 | * @param a input : lpc coefficients a[0:m] 164 | * @param a_offset input : lpc coefficients offset 165 | * @param gamma input : weighting factor 166 | * @param m input : filter order 167 | * @param ap output: weighted coefficients ap[0:m] 168 | */ 169 | 170 | public static void weight_az( 171 | float[] a, 172 | int a_offset, 173 | float gamma, 174 | int m, 175 | float[] ap 176 | ) 177 | { 178 | float fac; 179 | int i; 180 | 181 | ap[0] = a[a_offset + 0]; 182 | fac = gamma; 183 | for (i = 1; i < m; i++) 184 | { 185 | ap[i] = fac * a[a_offset + i]; 186 | fac *= gamma; 187 | } 188 | 189 | ap[m] = fac * a[a_offset + m]; 190 | } 191 | 192 | /** 193 | * Interpolated M LSP parameters and convert to M+1 LPC coeffs 194 | * 195 | * @param lsp_old input : LSPs for past frame (0:M-1) 196 | * @param lsp_new input : LSPs for present frame (0:M-1) 197 | * @param az output: filter parameters in 2 subfr (dim 2(m+1)) 198 | */ 199 | 200 | public static void int_qlpc( 201 | float[] lsp_old, 202 | float[] lsp_new, 203 | float[] az 204 | ) 205 | { 206 | var M = Ld8k.M; 207 | 208 | int i; 209 | var lsp = new float[M]; 210 | 211 | for (i = 0; i < M; i++) 212 | lsp[i] = lsp_old[i] * 0.5f + lsp_new[i] * 0.5f; 213 | 214 | lsp_az(lsp, az, 0); 215 | lsp_az(lsp_new, az, M + 1); 216 | } 217 | /** 218 | * Interpolated M LSP parameters and convert to M+1 LPC coeffs 219 | * 220 | * @param lsp_old input : LSPs for past frame (0:M-1) 221 | * @param lsp_new input : LSPs for present frame (0:M-1) 222 | * @param lsf_int output: interpolated lsf coefficients 223 | * @param lsf_new input : LSFs for present frame (0:M-1) 224 | * @param az output: filter parameters in 2 subfr (dim 2(m+1)) 225 | */ 226 | 227 | public static void int_lpc( 228 | float[] lsp_old, 229 | float[] lsp_new, 230 | float[] lsf_int, 231 | float[] lsf_new, 232 | float[] az 233 | ) 234 | { 235 | var M = Ld8k.M; 236 | 237 | int i; 238 | var lsp = new float[M]; 239 | 240 | for (i = 0; i < M; i++) 241 | lsp[i] = lsp_old[i] * 0.5f + lsp_new[i] * 0.5f; 242 | 243 | lsp_az(lsp, az, 0); 244 | 245 | lsp_lsf(lsp, lsf_int, M); 246 | lsp_lsf(lsp_new, lsf_new, M); 247 | } 248 | } 249 | } -------------------------------------------------------------------------------- /G729/G729Encoder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright @ 2015 Atlassian Pty Ltd 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 | * G.729 is now patent free. See: 18 | * SIPRO Lab Telecom. 19 | */ 20 | /* ITU-T G.729 Software Package Release 2 (November 2006) */ 21 | /* 22 | * ITU-T G.729 Annex C - Reference C code for floating point 23 | * implementation of G.729 24 | * Version 1.01 of 15.September.98 25 | */ 26 | /* 27 | ---------------------------------------------------------------------- 28 | COPYRIGHT NOTICE 29 | ---------------------------------------------------------------------- 30 | ITU-T G.729 Annex C ANSI C source code 31 | Copyright (C) 1998, AT&T, France Telecom, NTT, University of 32 | Sherbrooke. All rights reserved. 33 | 34 | ---------------------------------------------------------------------- 35 | */ 36 | /** 37 | * Main program of the ITU-T G.729 8 kbit/s encoder. 38 | * 39 | * @author Lubomir Marinov (translation of ITU-T C source code to Java) 40 | */ 41 | /* 42 | * Converted to C# for GroovyG7xx, see https://github.com/jongoochgithub/GroovyCodecs 43 | */ 44 | 45 | using System; 46 | using System.IO; 47 | using GroovyCodecs.G729.Codec; 48 | 49 | namespace GroovyCodecs.G729 50 | { 51 | public class G729Encoder : Ld8k 52 | { 53 | 54 | /** 55 | * Initialization of the coder. 56 | */ 57 | 58 | private byte[] _leftover = new byte[0]; 59 | 60 | /** 61 | * Init the Ld8k Coder 62 | */ 63 | private readonly CodLd8k codLd8k = new CodLd8k(); 64 | 65 | /** 66 | * Init the PreProc 67 | */ 68 | private readonly PreProc preProc = new PreProc(); 69 | 70 | /** 71 | * Transmitted parameters 72 | */ 73 | private readonly int[] prm = new int[PRM_SIZE]; 74 | 75 | public G729Encoder() 76 | { 77 | preProc.init_pre_process(); 78 | codLd8k.init_coder_ld8k(); /* Initialize the coder */ 79 | } 80 | 81 | private static void Fill(T[] array, int start, int end, T value) 82 | { 83 | for (var i = start; i < end; i++) 84 | array[i] = value; 85 | } 86 | 87 | private void packetize(short[] serial, byte[] outFrame, int outFrameOffset) 88 | { 89 | Fill(outFrame, outFrameOffset, outFrameOffset + L_FRAME / 8, (byte)0); 90 | 91 | for (var s = 0; s < L_FRAME; s++) 92 | if (BIT_1 == serial[2 + s]) 93 | { 94 | var o = outFrameOffset + s / 8; 95 | int out_ = outFrame[o]; 96 | 97 | out_ |= 1 << (7 - s % 8); 98 | outFrame[o] = (byte)(out_ & 0xFF); 99 | } 100 | } 101 | 102 | /** 103 | * Process L_FRAME short of speech. 104 | * 105 | * @param sp16 input : speach short array 106 | * @param serial output : serial array encoded in bits_ld8k 107 | */ 108 | private void ProcessPacket(short[] sp16, short[] serial) 109 | { 110 | var new_speech = codLd8k.new_speech; /* Pointer to new speech data */ 111 | var new_speech_offset = codLd8k.new_speech_offset; 112 | 113 | for (var i = 0; i < L_FRAME; i++) 114 | new_speech[new_speech_offset + i] = sp16[i]; 115 | 116 | preProc.pre_process(new_speech, new_speech_offset, L_FRAME); 117 | 118 | codLd8k.coder_ld8k(prm); 119 | 120 | Bits.prm2bits_ld8k(prm, serial); 121 | 122 | } 123 | 124 | /** 125 | * Usage : coder speech_file bitstream_file 126 | * 127 | * Format for speech_file: 128 | * Speech is read form a binary file of 16 bits data. 129 | * 130 | * Format for bitstream_file: 131 | * One word (2-bytes) to indicate erasure. 132 | * One word (2 bytes) to indicate bit rate 133 | * 80 words (2-bytes) containing 80 bits. 134 | * 135 | * @param args speech_file bitstream_file 136 | * @throws java.io.IOException 137 | */ 138 | public byte[] Process(byte[] speech) 139 | { 140 | var sp16 = new short[L_FRAME]; /* Buffer to read 16 bits speech */ 141 | var serial = new short[SERIAL_SIZE]; /* Output bit stream buffer */ 142 | var packet = new byte[L_FRAME / 8]; 143 | var output = new MemoryStream(); 144 | var buffer = new MemoryStream(); 145 | 146 | buffer.Write(_leftover, 0, _leftover.Length); 147 | buffer.Write(speech, 0, speech.Length); 148 | var input = buffer.ToArray(); 149 | 150 | /*-------------------------------------------------------------------------* 151 | * Loop for every analysis/transmission frame. * 152 | * -New L_FRAME data are read. (L_FRAME = number of speech data per frame) * 153 | * -Conversion of the speech data from 16 bit integer to real * 154 | * -Call cod_ld8k to encode the speech. * 155 | * -The compressed serial output stream is written to a file. * 156 | * -The synthesis speech is written to a file * 157 | *-------------------------------------------------------------------------* 158 | */ 159 | 160 | var frame = 0; 161 | try 162 | { 163 | // Iterate over each frame 164 | int i; 165 | for (i = 0; i <= input.Length - L_FRAME * 2 /* must have a complete frame left */; i += L_FRAME * 2) 166 | { 167 | frame++; 168 | Buffer.BlockCopy(input, i, sp16, 0, L_FRAME * 2); 169 | ProcessPacket(sp16, serial); 170 | packetize(serial, packet, 0); 171 | output.Write(packet, 0, packet.Length); 172 | } 173 | 174 | _leftover = new byte[input.Length - i]; 175 | Array.Copy(input, i, _leftover, 0, _leftover.Length); 176 | } 177 | catch (Exception) 178 | { 179 | // No logging as we could get huge log files if any issues arises decoding 180 | } 181 | 182 | return output.ToArray(); 183 | } 184 | 185 | // TODO: pad out _leftover with silence, and return one last frame 186 | public byte[] Flush() 187 | { 188 | var output = new MemoryStream(); 189 | if (_leftover.Length > 0) 190 | { 191 | var sp16 = new short[L_FRAME]; /* Buffer to read 16 bits speech */ 192 | var serial = new short[SERIAL_SIZE]; /* Output bit stream buffer */ 193 | var packet = new byte[L_FRAME / 8]; 194 | 195 | Buffer.BlockCopy(_leftover, 0, sp16, 0, _leftover.Length); 196 | Fill(sp16, _leftover.Length / 2, sp16.Length, (short)0); 197 | ProcessPacket(sp16, serial); 198 | packetize(serial, packet, 0); 199 | output.Write(packet, 0, packet.Length); 200 | } 201 | 202 | return output.ToArray(); 203 | } 204 | } 205 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | --------------------------------------------------------------------------------