You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openmeetings.apache.org by co...@google.com on 2013/02/21 18:25:22 UTC
[red5phone] r98 committed - Code is auto-formatted
Revision: 98
Author: solomax666@gmail.com
Date: Thu Feb 21 09:21:48 2013
Log: Code is auto-formatted
http://code.google.com/p/red5phone/source/detail?r=98
Modified:
/branches/red5sip/src/java/org/openmeetings/utils/IOUtils.java
/branches/red5sip/src/java/org/openmeetings/utils/PropertiesUtils.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodec.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecAttributes.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecFactory.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecG729.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMA.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMU.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodecUtils.java
/branches/red5sip/src/java/org/red5/codecs/SIPCodeciLBC.java
/branches/red5sip/src/java/org/red5/codecs/asao/ByteStream.java
/branches/red5sip/src/java/org/red5/codecs/asao/Codec.java
/branches/red5sip/src/java/org/red5/codecs/asao/CodecImpl.java
/branches/red5sip/src/java/org/red5/codecs/asao/Decoder.java
/branches/red5sip/src/java/org/red5/codecs/asao/DecoderMap.java
/branches/red5sip/src/java/org/red5/codecs/asao/Encoder.java
/branches/red5sip/src/java/org/red5/codecs/asao/EncoderMap.java
/branches/red5sip/src/java/org/red5/codecs/asao/NellyDecoderMap.java
/branches/red5sip/src/java/org/red5/codecs/asao/NellyEncoderMap.java
/branches/red5sip/src/java/org/red5/codecs/asao/SetupTable.java
/branches/red5sip/src/java/org/red5/codecs/asao/StateTable.java
/branches/red5sip/src/java/org/red5/codecs/asao/Utility.java
/branches/red5sip/src/java/org/red5/codecs/g729/ArrayUtils.java
/branches/red5sip/src/java/org/red5/codecs/g729/Bits.java
/branches/red5sip/src/java/org/red5/codecs/g729/CelpCo.java
/branches/red5sip/src/java/org/red5/codecs/g729/CircularBuffer.java
/branches/red5sip/src/java/org/red5/codecs/g729/CodLD8K.java
/branches/red5sip/src/java/org/red5/codecs/g729/CorFunc.java
/branches/red5sip/src/java/org/red5/codecs/g729/DecAcelp.java
/branches/red5sip/src/java/org/red5/codecs/g729/DecGain.java
/branches/red5sip/src/java/org/red5/codecs/g729/DecLD8K.java
/branches/red5sip/src/java/org/red5/codecs/g729/DecLag.java
/branches/red5sip/src/java/org/red5/codecs/g729/Decoder.java
/branches/red5sip/src/java/org/red5/codecs/g729/Encoder.java
/branches/red5sip/src/java/org/red5/codecs/g729/Filter.java
/branches/red5sip/src/java/org/red5/codecs/g729/FloatPointer.java
/branches/red5sip/src/java/org/red5/codecs/g729/GainPred.java
/branches/red5sip/src/java/org/red5/codecs/g729/GenericPointer.java
/branches/red5sip/src/java/org/red5/codecs/g729/IntegerPointer.java
/branches/red5sip/src/java/org/red5/codecs/g729/LD8KConstants.java
/branches/red5sip/src/java/org/red5/codecs/g729/Lpc.java
/branches/red5sip/src/java/org/red5/codecs/g729/LpcFunc.java
/branches/red5sip/src/java/org/red5/codecs/g729/LspDec.java
/branches/red5sip/src/java/org/red5/codecs/g729/LspGetq.java
/branches/red5sip/src/java/org/red5/codecs/g729/PParity.java
/branches/red5sip/src/java/org/red5/codecs/g729/Pitch.java
/branches/red5sip/src/java/org/red5/codecs/g729/PostFil.java
/branches/red5sip/src/java/org/red5/codecs/g729/PostPro.java
/branches/red5sip/src/java/org/red5/codecs/g729/PreProc.java
/branches/red5sip/src/java/org/red5/codecs/g729/PredLt.java
/branches/red5sip/src/java/org/red5/codecs/g729/Pwf.java
/branches/red5sip/src/java/org/red5/codecs/g729/QuaGain.java
/branches/red5sip/src/java/org/red5/codecs/g729/QuaLsp.java
/branches/red5sip/src/java/org/red5/codecs/g729/TabLD8k.java
/branches/red5sip/src/java/org/red5/codecs/g729/Taming.java
/branches/red5sip/src/java/org/red5/codecs/g729/Util.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/bitpack.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/bitstream.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/ilbc_common.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/ilbc_constants.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/ilbc_decoder.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/ilbc_encoder.java
/branches/red5sip/src/java/org/red5/codecs/ilbc/ilbc_ulp.java
/branches/red5sip/src/java/org/red5/sip/app/Application.java
/branches/red5sip/src/java/org/red5/sip/app/BufferUtils.java
/branches/red5sip/src/java/org/red5/sip/app/BytesBuffer.java
/branches/red5sip/src/java/org/red5/sip/app/IMediaReceiver.java
/branches/red5sip/src/java/org/red5/sip/app/IMediaSender.java
/branches/red5sip/src/java/org/red5/sip/app/IMediaStream.java
/branches/red5sip/src/java/org/red5/sip/app/ISipNumberListener.java
/branches/red5sip/src/java/org/red5/sip/app/PlayNetStream.java
/branches/red5sip/src/java/org/red5/sip/app/RTMPControlClient.java
/branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java
/branches/red5sip/src/java/org/red5/sip/app/RTPStream.java
/branches/red5sip/src/java/org/red5/sip/app/RTPStreamForMultiplex.java
/branches/red5sip/src/java/org/red5/sip/app/RTPStreamMultiplexingSender.java
/branches/red5sip/src/java/org/red5/sip/app/RTPStreamReceiver.java
/branches/red5sip/src/java/org/red5/sip/app/RTPStreamSender.java
/branches/red5sip/src/java/org/red5/sip/app/ResampleUtils.java
/branches/red5sip/src/java/org/red5/sip/app/SIPAudioLauncher.java
/branches/red5sip/src/java/org/red5/sip/app/SIPRegisterAgent.java
/branches/red5sip/src/java/org/red5/sip/app/SIPRegisterAgentListener.java
/branches/red5sip/src/java/org/red5/sip/app/SIPTransport.java
/branches/red5sip/src/java/org/red5/sip/app/SIPUserAgent.java
/branches/red5sip/src/java/org/red5/sip/app/SIPUserAgentListener.java
/branches/red5sip/src/java/org/red5/sip/app/SIPUserAgentProfile.java
/branches/red5sip/src/java/org/red5/sip/app/SdpUtils.java
=======================================
--- /branches/red5sip/src/java/org/openmeetings/utils/IOUtils.java Thu Feb
14 08:34:08 2013
+++ /branches/red5sip/src/java/org/openmeetings/utils/IOUtils.java Thu Feb
21 09:21:48 2013
@@ -12,53 +12,51 @@
*/
public class IOUtils {
- public static void close(Logger l, Closeable io) {
- try {
- io.close();
- } catch (Exception e) {
- l.error("Unexpected error while closing:" + io, e);
- }
- }
+ public static void close(Logger l, Closeable io) {
+ try {
+ io.close();
+ } catch (Exception e) {
+ l.error("Unexpected error while closing:" + io, e);
+ }
+ }
- public static String readFileToString(File file) {
- String result;
- try {
- result = FileUtils.readFileToString(file);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return result;
- }
+ public static String readFileToString(File file) {
+ String result;
+ try {
+ result = FileUtils.readFileToString(file);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return result;
+ }
- public static void writeStringToFile(File file, String text) {
- try {
- FileUtils.writeStringToFile(file, text);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ public static void writeStringToFile(File file, String text) {
+ try {
+ FileUtils.writeStringToFile(file, text);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- public static void touch(File file) {
- try {
- FileUtils.touch(file);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ public static void touch(File file) {
+ try {
+ FileUtils.touch(file);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- public static boolean deleteDirectory(File path) {
- if (path.exists()) {
- File[] files = path.listFiles();
- for (File file : files) {
- if (file.isDirectory()) {
- deleteDirectory(file);
- } else {
- file.delete();
- }
- }
- }
- return (path.delete());
- }
+ public static boolean deleteDirectory(File path) {
+ if (path.exists()) {
+ File[] files = path.listFiles();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ deleteDirectory(file);
+ } else {
+ file.delete();
+ }
+ }
+ }
+ return (path.delete());
+ }
}
-
-
=======================================
--- /branches/red5sip/src/java/org/openmeetings/utils/PropertiesUtils.java
Thu Feb 14 08:34:08 2013
+++ /branches/red5sip/src/java/org/openmeetings/utils/PropertiesUtils.java
Thu Feb 21 09:21:48 2013
@@ -19,200 +19,195 @@
/**
* A wrapper for java.util.Properties class
- *
+ *
* @threadsafety yes
*/
public final class PropertiesUtils {
- public static final Logger log =
LoggerFactory.getLogger(PropertiesUtils.class);
+ public static final Logger log =
LoggerFactory.getLogger(PropertiesUtils.class);
- private PropertiesUtils() {
- }
+ private PropertiesUtils() {
+ }
+ public static String getRequiredProperty(Properties p, String pp, String
name) {
+ String eName = getEffectiveName(p, pp, name);
+ return getRequiredProperty(p, eName);
+ }
- public static String getRequiredProperty(Properties p, String pp,
String name) {
- String eName = getEffectiveName(p, pp, name);
- return getRequiredProperty(p, eName);
- }
+ public static String getRequiredProperty(Properties p, String name) {
+ String value = p.getProperty(name);
+ if (value == null) {
+ throw new RuntimeException("Property is not set '" + name + "'");
+ }
+ return value;
+ }
- public static String getRequiredProperty(Properties p, String name) {
- String value = p.getProperty(name);
- if (value == null) {
- throw new RuntimeException("Property is not set '" + name
+ "'");
- }
- return value;
- }
+ public static String getEffectiveName(Properties p, String prefix, String
name) {
+ String fullName = prefix + name;
+ if (p.getProperty(fullName) != null) {
+ return fullName;
+ }
+ if (p.getProperty(name) != null) {
+ return name;
+ }
+ return fullName;
+ }
+ public static boolean getBoolean(Properties p, String pp, String name,
boolean defaultValue) {
+ String eName = getEffectiveName(p, pp, name);
+ return getBoolean(p, eName, defaultValue);
+ }
- public static String getEffectiveName(Properties p, String prefix,
String name) {
- String fullName = prefix + name;
- if (p.getProperty(fullName) != null) {
- return fullName;
- }
- if (p.getProperty(name) != null) {
- return name;
- }
- return fullName;
- }
+ public static boolean getBoolean(Properties p, String name, boolean
defaultValue) {
+ return p.getProperty(name, "" + defaultValue).equals("true");
+ }
- public static boolean getBoolean(Properties p, String pp, String name,
boolean defaultValue) {
- String eName = getEffectiveName(p, pp, name);
- return getBoolean(p, eName, defaultValue);
- }
+ public static int getRequiredInteger(Properties p, String name) {
+ return Integer.parseInt(getRequiredProperty(p, name));
+ }
- public static boolean getBoolean(Properties p, String name, boolean
defaultValue) {
- return p.getProperty(name, "" + defaultValue).equals("true");
- }
+ public static int getInteger(Properties p, String pp, String name, int
defaultValue) {
+ String eName = getEffectiveName(p, pp, name);
+ return getInteger(p, eName, defaultValue);
+ }
- public static int getRequiredInteger(Properties p, String name) {
- return Integer.parseInt(getRequiredProperty(p, name));
- }
+ public static int getInteger(Properties p, String name, int defaultValue)
{
+ return Integer.parseInt(p.getProperty(name, "" + defaultValue));
+ }
- public static int getInteger(Properties p, String pp, String name, int
defaultValue) {
- String eName = getEffectiveName(p, pp, name);
- return getInteger(p, eName, defaultValue);
- }
+ public static long getLong(Properties p, String pp, String name, long
defaultValue) {
+ String eName = getEffectiveName(p, pp, name);
+ return getLong(p, eName, defaultValue);
+ }
- public static int getInteger(Properties p, String name, int
defaultValue) {
- return Integer.parseInt(p.getProperty(name, "" + defaultValue));
- }
+ public static long getLong(Properties p, String name, long defaultValue) {
+ return Long.parseLong(p.getProperty(name, "" + defaultValue));
+ }
- public static long getLong(Properties p, String pp, String name, long
defaultValue) {
- String eName = getEffectiveName(p, pp, name);
- return getLong(p, eName, defaultValue);
- }
+ public static Locale getLocale(Properties p, String name, Locale
defaultValue) {
+ String country = p.getProperty(name, "NOT_EXIST_PROP");
+ for (Locale locale : Locale.getAvailableLocales()) {
+ if (locale.getCountry().equals(country)) {
+ return locale;
+ }
+ }
+ return defaultValue;
+ }
- public static long getLong(Properties p, String name, long
defaultValue) {
- return Long.parseLong(p.getProperty(name, "" + defaultValue));
- }
+ public static Properties load(File path) {
+ Properties p;
+ try {
+ InputStream is = new FileInputStream(path);
+ try {
+ Properties tmp = new Properties();
+ tmp.load(is);
+ p = patchProperties(tmp);
+ } finally {
+ close(log, is);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading property file: " + path, e);
+ }
+ return p;
+ }
- public static Locale getLocale(Properties p, String name, Locale
defaultValue) {
- String country = p.getProperty(name, "NOT_EXIST_PROP");
- for (Locale locale : Locale.getAvailableLocales()) {
- if (locale.getCountry().equals(country)) {
- return locale;
- }
- }
- return defaultValue;
- }
+ private static Properties patchProperties(Properties p) {
+ Properties res = new Properties();
+ for (Map.Entry<Object, Object> e : p.entrySet()) {
+ int idx = -1;
+ String val = e.getValue().toString();
+ while ((idx = val.indexOf("${", idx + 1)) != -1) {
+ int end = val.indexOf("}", idx + 2);
+ if (end != -1) {
+ String varName = val.substring(idx + 2, end);
+ String jvmProp = System.getProperty(varName);
+ if (jvmProp == null) {
+ // log.warn("JVM property " + varName + " is not set");
+ continue;
+ }
+ val = val.replace(val.substring(idx, end + 1), jvmProp);
+ }
+ }
+ res.put(e.getKey().toString(), val);
+ }
+ return res;
+ }
- public static Properties load(File path) {
- Properties p;
- try {
- InputStream is = new FileInputStream(path);
- try {
- Properties tmp = new Properties();
- tmp.load(is);
- p = patchProperties(tmp);
- } finally {
- close(log, is);
- }
- } catch (IOException e) {
- throw new RuntimeException("Error reading property file: " +
path, e);
- }
- return p;
- }
-
- private static Properties patchProperties(Properties p) {
- Properties res = new Properties();
- for(Map.Entry<Object,Object> e: p.entrySet()) {
- int idx = -1;
- String val = e.getValue().toString();
- while((idx = val.indexOf("${", idx+1)) != -1) {
- int end = val.indexOf("}", idx+2);
- if(end != -1) {
- String varName = val.substring(idx+2, end);
- String jvmProp = System.getProperty(varName);
- if(jvmProp == null) {
- //log.warn("JVM property " + varName + " is not
set");
- continue;
- }
- val = val.replace(val.substring(idx, end + 1),
jvmProp);
- }
- }
- res.put(e.getKey().toString(), val);
- }
- return res;
- }
-
- public static Properties load(Class<?> cls, String path) {
- Properties p;
- try {
- InputStream is = cls.getResourceAsStream(path);
- try {
- Properties tmp = new Properties();
- tmp.load(is);
- p = patchProperties(tmp);
- } finally {
- close(log, is);
- }
- } catch (IOException e) {
- throw new RuntimeException("Error reading property file: " +
path, e);
- }
- return p;
- }
-
-
- public static String loadTextResource(Class<?> cls, String path) {
- StringBuilder result = new StringBuilder();
- try {
- InputStream stream = cls.getResourceAsStream(path);
- if (stream == null) {
- throw new RuntimeException("Resource not found:" + path);
- }
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream));
- try {
+ public static Properties load(Class<?> cls, String path) {
+ Properties p;
+ try {
+ InputStream is = cls.getResourceAsStream(path);
+ try {
+ Properties tmp = new Properties();
+ tmp.load(is);
+ p = patchProperties(tmp);
+ } finally {
+ close(log, is);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading property file: " + path, e);
+ }
+ return p;
+ }
- do {
- String line = reader.readLine();
- if (line == null) {
- break;
- }
- if (result.length() != 0) {
- result.append('\n');
- }
- result.append(line);
- } while (true);
- } finally {
- close(log, reader);
- }
- } catch (IOException e) {
- throw new RuntimeException("Error reading property file: " +
path, e);
- }
- return result.toString();
- }
+ public static String loadTextResource(Class<?> cls, String path) {
+ StringBuilder result = new StringBuilder();
+ try {
+ InputStream stream = cls.getResourceAsStream(path);
+ if (stream == null) {
+ throw new RuntimeException("Resource not found:" + path);
+ }
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(stream));
+ try {
+ do {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ }
+ if (result.length() != 0) {
+ result.append('\n');
+ }
+ result.append(line);
+ } while (true);
+ } finally {
+ close(log, reader);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading property file: " + path, e);
+ }
+ return result.toString();
+ }
- public static void store(File file, Properties p) {
- File dir = file.getParentFile();
- if (!dir.exists()) {
- boolean ok = dir.mkdirs();
- if (!ok) {
- throw new RuntimeException("Failed to create directory: "
+ dir.getAbsolutePath());
- }
- }
- try {
- BufferedWriter w = new BufferedWriter(new FileWriter(file));
- try {
- p.store(w, null);
- } finally {
- close(log, w);
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ public static void store(File file, Properties p) {
+ File dir = file.getParentFile();
+ if (!dir.exists()) {
+ boolean ok = dir.mkdirs();
+ if (!ok) {
+ throw new RuntimeException("Failed to create directory: " +
dir.getAbsolutePath());
+ }
+ }
+ try {
+ BufferedWriter w = new BufferedWriter(new FileWriter(file));
+ try {
+ p.store(w, null);
+ } finally {
+ close(log, w);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- public static Properties getAllWithPrefix(String prefix, Properties
properties) {
- Properties result = new Properties();
- for (String name : properties.stringPropertyNames()) {
- if (name.startsWith(prefix)) {
- String value = properties.getProperty(name);
- result.setProperty(name, value);
- }
- }
- return result;
+ public static Properties getAllWithPrefix(String prefix, Properties
properties) {
+ Properties result = new Properties();
+ for (String name : properties.stringPropertyNames()) {
+ if (name.startsWith(prefix)) {
+ String value = properties.getProperty(name);
+ result.setProperty(name, value);
+ }
+ }
+ return result;
- }
+ }
}
-
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodec.java Thu Feb 21
09:13:01 2013
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodec.java Thu Feb 21
09:21:48 2013
@@ -1,65 +1,64 @@
package org.red5.codecs;
-
/**
* Interface for audio codecs
* */
public interface SIPCodec {
- // Codec constants
- public static String MEDIA_TYPE_AUDIO = "audio";
-
- public static String MEDIA_TYPE_VIDEO = "video";
-
- public static String ATTRIBUTE_PTIME = "ptime";
-
- public static String ATTRIBUTE_RTPMAP = "rtpmap";
-
- public static String ATTRIBUTE_FMTP = "fmtp";
-
- public static String ATTRIBUTE_AS = "AS";
-
- public static int DEFAULT_PACKETIZATION = 20;
-
- // Codec members
- public void encodeInit( int defaultEncodePacketization );
+ // Codec constants
+ public static String MEDIA_TYPE_AUDIO = "audio";
- public void decodeInit( int defaultDecodePacketization );
+ public static String MEDIA_TYPE_VIDEO = "video";
+
+ public static String ATTRIBUTE_PTIME = "ptime";
+
+ public static String ATTRIBUTE_RTPMAP = "rtpmap";
+
+ public static String ATTRIBUTE_FMTP = "fmtp";
+
+ public static String ATTRIBUTE_AS = "AS";
+
+ public static int DEFAULT_PACKETIZATION = 20;
+
+ // Codec members
+ public void encodeInit(int defaultEncodePacketization);
+
+ public void decodeInit(int defaultDecodePacketization);
+
+ public String codecNegotiateAttribute(String attributeName, String
localAttributeValue, String remoteAttributeValue);
+
+ public int getCodecBlankPacket(byte[] buffer, int offset);
+
+ public int pcmToCodec(float[] bufferIn, byte[] bufferOut);
+
+ public int codecToPcm(byte[] bufferIn, float[] bufferOut);
+
+ public int getIncomingEncodedFrameSize();
- public String codecNegotiateAttribute( String attributeName, String
localAttributeValue, String remoteAttributeValue );
+ public int getIncomingDecodedFrameSize();
- public int getCodecBlankPacket( byte[] buffer, int offset );
+ public int getOutgoingEncodedFrameSize();
- public int pcmToCodec( float[] bufferIn, byte[] bufferOut );
+ public int getOutgoingDecodedFrameSize();
- public int codecToPcm( byte[] bufferIn, float[] bufferOut );
+ public int getSampleRate();
- public int getIncomingEncodedFrameSize();
+ public String getCodecName();
- public int getIncomingDecodedFrameSize();
+ public int getCodecId();
- public int getOutgoingEncodedFrameSize();
+ public int getIncomingPacketization();
- public int getOutgoingDecodedFrameSize();
+ public int getOutgoingPacketization();
- public int getSampleRate();
+ public void setLocalPtime(int localPtime);
- public String getCodecName();
+ public void setRemotePtime(int remotePtime);
- public int getCodecId();
-
- public int getIncomingPacketization();
-
- public int getOutgoingPacketization();
-
- public void setLocalPtime( int localPtime );
-
- public void setRemotePtime( int remotePtime );
-
- /**
- * Get codec media attributes used for SDP negotiation
- * Example: iLBC codec will return "fmtp:111 mode=30"
- * @return String array containing codec attribute
- */
- public String[] getCodecMediaAttributes();
+ /**
+ * Get codec media attributes used for SDP negotiation Example: iLBC
codec will return "fmtp:111 mode=30"
+ *
+ * @return String array containing codec attribute
+ */
+ public String[] getCodecMediaAttributes();
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecAttributes.java Thu
Feb 14 08:34:08 2013
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecAttributes.java Thu
Feb 21 09:21:48 2013
@@ -7,121 +7,120 @@
* A class to store codecs attributes, used to configure them
*/
public class SIPCodecAttributes {
- private Hashtable< String, String > codecEncodeAttributes;
- private Hashtable< String, String > codecDecodeAttributes;
-
-
- public SIPCodecAttributes( String[] encodeAttributes, String[]
decodeAttributes ) {
-
- codecEncodeAttributes = new Hashtable< String, String >();
-
- for (int i = 0; i < encodeAttributes.length; i++) {
- codecEncodeAttributes.put( encodeAttributes[i], "" );
- }
-
- codecDecodeAttributes = new Hashtable< String, String >();
-
- for (int i = 0; i < decodeAttributes.length; i++) {
- codecDecodeAttributes.put( decodeAttributes[i], "" );
- }
- }
-
- public void setEncodeAttribute( String attributeName, String
attributeValue ) {
-
- codecEncodeAttributes.put( attributeName, attributeValue );
- }
-
- public String getEncodeAttribute( String attributeName ) {
-
- return codecEncodeAttributes.get( attributeName );
- }
-
- public void setDecodeAttribute( String attributeName, String
attributeValue ) {
-
- codecDecodeAttributes.put( attributeName, attributeValue );
- }
-
- public String getDecodeAttribute( String attributeName ) {
-
- return codecDecodeAttributes.get( attributeName );
- }
-
- public boolean hasEncodeAttribute( String attributeName ) {
-
- return codecEncodeAttributes.containsKey( attributeName );
- }
-
- public boolean hasDecodeAttribute( String attributeName ) {
-
- return codecDecodeAttributes.containsKey( attributeName );
- }
-
- public boolean hasEncodeAttributeValue( String attributeName ) {
-
- boolean hasAttribute = false;
-
- if ( codecEncodeAttributes.containsKey( attributeName ) ) {
-
- String attributeValue = codecEncodeAttributes.get(
attributeName );
-
- if ( ( attributeValue != null ) && ( !attributeValue.isEmpty()
) ) {
-
- hasAttribute = true;
- }
- }
-
- return hasAttribute;
- }
-
- public boolean hasDecodeAttributeValue( String attributeName ) {
-
- boolean hasAttribute = false;
-
- if ( codecDecodeAttributes.containsKey( attributeName ) ) {
-
- String attributeValue = codecEncodeAttributes.get(
attributeName );
-
- if ( ( attributeValue != null ) && ( !attributeValue.isEmpty()
) ) {
-
- hasAttribute = true;
- }
- }
-
- return hasAttribute;
- }
-
- @Override
- public String toString() {
-
- String toStringRet = "";
-
- if ( codecEncodeAttributes.size() > 0 ) {
-
- toStringRet += "Encode attributes:\n";
- }
-
- for ( Enumeration<String> keysEnum = codecEncodeAttributes.keys();
keysEnum.hasMoreElements(); ) {
-
- String attributeName = (String) keysEnum.nextElement();
- toStringRet += "\t" + attributeName + "=" +
codecEncodeAttributes.get( attributeName );
- }
-
- if ( codecDecodeAttributes.size() > 0 ) {
-
- if ( codecEncodeAttributes.size() > 0 ) {
-
- toStringRet += "\n";
- }
-
- toStringRet += "Decode attributes:\n";
- }
-
- for ( Enumeration<String> keysEnum = codecDecodeAttributes.keys();
keysEnum.hasMoreElements(); ) {
-
- String attributeName = (String) keysEnum.nextElement();
- toStringRet += "\t" + attributeName + "=" +
codecDecodeAttributes.get( attributeName );
- }
-
- return toStringRet;
- }
+ private Hashtable<String, String> codecEncodeAttributes;
+ private Hashtable<String, String> codecDecodeAttributes;
+
+ public SIPCodecAttributes(String[] encodeAttributes, String[]
decodeAttributes) {
+
+ codecEncodeAttributes = new Hashtable<String, String>();
+
+ for (int i = 0; i < encodeAttributes.length; i++) {
+ codecEncodeAttributes.put(encodeAttributes[i], "");
+ }
+
+ codecDecodeAttributes = new Hashtable<String, String>();
+
+ for (int i = 0; i < decodeAttributes.length; i++) {
+ codecDecodeAttributes.put(decodeAttributes[i], "");
+ }
+ }
+
+ public void setEncodeAttribute(String attributeName, String
attributeValue) {
+
+ codecEncodeAttributes.put(attributeName, attributeValue);
+ }
+
+ public String getEncodeAttribute(String attributeName) {
+
+ return codecEncodeAttributes.get(attributeName);
+ }
+
+ public void setDecodeAttribute(String attributeName, String
attributeValue) {
+
+ codecDecodeAttributes.put(attributeName, attributeValue);
+ }
+
+ public String getDecodeAttribute(String attributeName) {
+
+ return codecDecodeAttributes.get(attributeName);
+ }
+
+ public boolean hasEncodeAttribute(String attributeName) {
+
+ return codecEncodeAttributes.containsKey(attributeName);
+ }
+
+ public boolean hasDecodeAttribute(String attributeName) {
+
+ return codecDecodeAttributes.containsKey(attributeName);
+ }
+
+ public boolean hasEncodeAttributeValue(String attributeName) {
+
+ boolean hasAttribute = false;
+
+ if (codecEncodeAttributes.containsKey(attributeName)) {
+
+ String attributeValue = codecEncodeAttributes.get(attributeName);
+
+ if ((attributeValue != null) && (!attributeValue.isEmpty())) {
+
+ hasAttribute = true;
+ }
+ }
+
+ return hasAttribute;
+ }
+
+ public boolean hasDecodeAttributeValue(String attributeName) {
+
+ boolean hasAttribute = false;
+
+ if (codecDecodeAttributes.containsKey(attributeName)) {
+
+ String attributeValue = codecEncodeAttributes.get(attributeName);
+
+ if ((attributeValue != null) && (!attributeValue.isEmpty())) {
+
+ hasAttribute = true;
+ }
+ }
+
+ return hasAttribute;
+ }
+
+ @Override
+ public String toString() {
+
+ String toStringRet = "";
+
+ if (codecEncodeAttributes.size() > 0) {
+
+ toStringRet += "Encode attributes:\n";
+ }
+
+ for (Enumeration<String> keysEnum = codecEncodeAttributes.keys();
keysEnum.hasMoreElements();) {
+
+ String attributeName = (String) keysEnum.nextElement();
+ toStringRet += "\t" + attributeName + "=" +
codecEncodeAttributes.get(attributeName);
+ }
+
+ if (codecDecodeAttributes.size() > 0) {
+
+ if (codecEncodeAttributes.size() > 0) {
+
+ toStringRet += "\n";
+ }
+
+ toStringRet += "Decode attributes:\n";
+ }
+
+ for (Enumeration<String> keysEnum = codecDecodeAttributes.keys();
keysEnum.hasMoreElements();) {
+
+ String attributeName = (String) keysEnum.nextElement();
+ toStringRet += "\t" + attributeName + "=" +
codecDecodeAttributes.get(attributeName);
+ }
+
+ return toStringRet;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecFactory.java Thu Feb
21 09:13:01 2013
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecFactory.java Thu Feb
21 09:21:48 2013
@@ -3,212 +3,202 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* SIPCodec Factory
* */
public class SIPCodecFactory {
-
- protected static Logger log = LoggerFactory.getLogger(
SIPCodecFactory.class );
-
- // ----------------
- // Available audio codecs
- private static final int audioCodecPCMU = 0;
-
- private static final int audioCodecPCMA = 8;
-
- private static final int audioCodecG729 = 18;
-
- private static final int audioCodeciLBC = 111;
-
- private int[] availableAudioCodecsId = { audioCodecPCMU,
audioCodecPCMA, audioCodecG729, audioCodeciLBC };
- // ----------------
- // Available video codecs
-
- private int[] availableVideoCodecsId = {};
-
-
- private static SIPCodecFactory singletonSIPCodecFactory = new
SIPCodecFactory();
-
- private static String[] codecCommonAudioMediaAttributes = { "ptime:20"
};
-
-
- public static SIPCodecFactory getInstance() {
+ protected static Logger log =
LoggerFactory.getLogger(SIPCodecFactory.class);
- return singletonSIPCodecFactory;
- }
-
- /**
- * Create a new instance of SIPCodec by codec id.
- * @return The codec associated with "codecId".
- * */
- public SIPCodec getSIPAudioCodec( int codecId ) {
-
- SIPCodec sipCodec;
-
- printLog( "getSIPAudioCodec", "Init..." );
-
- printLog( "getSIPAudioCodec", "codecId = [" + codecId + "]." );
+ // ----------------
+ // Available audio codecs
+ private static final int audioCodecPCMU = 0;
- switch ( codecId ) {
- case audioCodecPCMU:
- sipCodec = new SIPCodecPCMU();
- break;
- case audioCodecPCMA:
- sipCodec = new SIPCodecPCMA();
- break;
- case audioCodecG729:
- sipCodec = new SIPCodecG729();
- break;
- case audioCodeciLBC:
- sipCodec = new SIPCodeciLBC();
- break;
- default:
- sipCodec = null;
- }
-
- if ( sipCodec != null ) {
-
- printLog( "getSIPAudioCodec",
- "codecId = [" + sipCodec.getCodecId() +
- "], codecName = [" + sipCodec.getCodecName() + "]." );
- }
-
- return sipCodec;
- }
-
- /**
- * Get all available audio codecs
- * @return SIPCodec array containing all audio codecs instances
- */
- public SIPCodec[] getAvailableAudioCodecs() {
-
- printLog( "getAvailableAudioCodecs", "Init..." );
-
- SIPCodec[] availableCodecs = new
SIPCodec[availableAudioCodecsId.length];
-
- for ( int i = 0; i < availableAudioCodecsId.length; i++ ) {
- int codecId = availableAudioCodecsId[ i ];
- SIPCodec codec = getSIPAudioCodec( codecId );
- availableCodecs[i] = codec;
- }
-
- return availableCodecs;
-
- }
-
- /**
- * Get all available video codecs
- * @return SIPCodec array containing all video codecs instances
- */
- public SIPCodec[] getAvailableVideoCodecs() {
-
- printLog( "getAvailableVideoCodecs", "Init..." );
-
- SIPCodec[] availableCodecs = new
SIPCodec[availableVideoCodecsId.length];
-
- for ( int i = 0; i < availableVideoCodecsId.length; i++ ) {
- int codecId = availableVideoCodecsId[ i ];
- SIPCodec codec = getSIPAudioCodec( codecId );
- availableCodecs[i] = codec;
- }
-
- return availableCodecs;
-
- }
-
- /**
- * Get all available codecs
- * @param codecsPrecedence semicolon separated ids from the codecs
- * @return SIPCodec array containing all codecs instances
- */
- public SIPCodec[] getAvailableAudioCodecsWithPrecedence( String
codecsPrecedence ) {
-
- int initIndex = 0;
- int finalIndex = codecsPrecedence.indexOf( ";" );
- String codecId;
- SIPCodec[] availableCodecs = new
SIPCodec[availableAudioCodecsId.length];
- int codecsIndex = 0;
-
- printLog( "getAvailableAudioCodecsWithPrecedence",
- "codecsPrecedence = [" + codecsPrecedence +
- "], initIndex = [" + initIndex +
- "], finalIndex = [" + finalIndex + "]." );
-
- while ( initIndex < finalIndex ) {
-
- codecId = codecsPrecedence.substring( initIndex, finalIndex );
-
- printLog( "getAvailableAudioCodecsWithPrecedence",
- "codecId = [" + codecId + "]." );
-
- SIPCodec sipCodec = getSIPAudioCodec(
- Integer.valueOf( codecId ).intValue() );
-
- if ( sipCodec != null ) {
-
- printLog( "getAvailableAudioCodecsWithPrecedence",
- "codecId = [" + sipCodec.getCodecId() +
- "], codecName = [" + sipCodec.getCodecName()
+ "]." );
-
- availableCodecs[codecsIndex] = sipCodec;
- codecsIndex++;
-
- initIndex = finalIndex+1;
- finalIndex = codecsPrecedence.indexOf( ";", initIndex );
-
- if ( (finalIndex == -1 ) &&
- ( initIndex <= codecsPrecedence.length() ) ) {
+ private static final int audioCodecPCMA = 8;
- finalIndex = codecsPrecedence.length();
- }
-
- printLog( "getAvailableAudioCodecsWithPrecedence",
- "codecsIndex = [" + codecsIndex +
- "], initIndex = [" + initIndex +
- "], finalIndex = [" + finalIndex + "]." );
- }
- else {
-
- printLog( "getAvailableAudioCodecsWithPrecedence",
- "Problem with value [" + codecId +
- "] retrieved from [" + codecsPrecedence + "].");
- }
- }
-
- return availableCodecs;
-
- }
-
- /**
- * @return Count of available audio codecs
- */
- public int getAvailableAudioCodecsCount() {
-
- return availableAudioCodecsId.length;
- }
-
- /**
- * @return Count of available video codecs
- */
- public int getAvailableVideoCodecsCount() {
-
- return availableVideoCodecsId.length;
- }
-
- public String[] getCommonAudioMediaAttributes() {
-
- return codecCommonAudioMediaAttributes;
- }
-
- public String[] getCommonVideoMediaAttributes() {
-
- return null;
- }
+ private static final int audioCodecG729 = 18;
+
+ private static final int audioCodeciLBC = 111;
+
+ private int[] availableAudioCodecsId = { audioCodecPCMU, audioCodecPCMA,
audioCodecG729, audioCodeciLBC };
+
+ // ----------------
+ // Available video codecs
+
+ private int[] availableVideoCodecsId = {};
+
+ private static SIPCodecFactory singletonSIPCodecFactory = new
SIPCodecFactory();
+
+ private static String[] codecCommonAudioMediaAttributes = { "ptime:20" };
+
+ public static SIPCodecFactory getInstance() {
+
+ return singletonSIPCodecFactory;
+ }
+
+ /**
+ * Create a new instance of SIPCodec by codec id.
+ *
+ * @return The codec associated with "codecId".
+ * */
+ public SIPCodec getSIPAudioCodec(int codecId) {
+
+ SIPCodec sipCodec;
+
+ printLog("getSIPAudioCodec", "Init...");
+
+ printLog("getSIPAudioCodec", "codecId = [" + codecId + "].");
+
+ switch (codecId) {
+ case audioCodecPCMU:
+ sipCodec = new SIPCodecPCMU();
+ break;
+ case audioCodecPCMA:
+ sipCodec = new SIPCodecPCMA();
+ break;
+ case audioCodecG729:
+ sipCodec = new SIPCodecG729();
+ break;
+ case audioCodeciLBC:
+ sipCodec = new SIPCodeciLBC();
+ break;
+ default:
+ sipCodec = null;
+ }
+
+ if (sipCodec != null) {
+
+ printLog("getSIPAudioCodec",
+ "codecId = [" + sipCodec.getCodecId() + "], codecName = [" +
sipCodec.getCodecName() + "].");
+ }
+
+ return sipCodec;
+ }
+
+ /**
+ * Get all available audio codecs
+ *
+ * @return SIPCodec array containing all audio codecs instances
+ */
+ public SIPCodec[] getAvailableAudioCodecs() {
+
+ printLog("getAvailableAudioCodecs", "Init...");
+
+ SIPCodec[] availableCodecs = new SIPCodec[availableAudioCodecsId.length];
+
+ for (int i = 0; i < availableAudioCodecsId.length; i++) {
+ int codecId = availableAudioCodecsId[i];
+ SIPCodec codec = getSIPAudioCodec(codecId);
+ availableCodecs[i] = codec;
+ }
+
+ return availableCodecs;
+
+ }
+
+ /**
+ * Get all available video codecs
+ *
+ * @return SIPCodec array containing all video codecs instances
+ */
+ public SIPCodec[] getAvailableVideoCodecs() {
+
+ printLog("getAvailableVideoCodecs", "Init...");
+
+ SIPCodec[] availableCodecs = new SIPCodec[availableVideoCodecsId.length];
+
+ for (int i = 0; i < availableVideoCodecsId.length; i++) {
+ int codecId = availableVideoCodecsId[i];
+ SIPCodec codec = getSIPAudioCodec(codecId);
+ availableCodecs[i] = codec;
+ }
+
+ return availableCodecs;
+
+ }
+
+ /**
+ * Get all available codecs
+ *
+ * @param codecsPrecedence
+ * semicolon separated ids from the codecs
+ * @return SIPCodec array containing all codecs instances
+ */
+ public SIPCodec[] getAvailableAudioCodecsWithPrecedence(String
codecsPrecedence) {
+
+ int initIndex = 0;
+ int finalIndex = codecsPrecedence.indexOf(";");
+ String codecId;
+ SIPCodec[] availableCodecs = new SIPCodec[availableAudioCodecsId.length];
+ int codecsIndex = 0;
+
+ printLog("getAvailableAudioCodecsWithPrecedence", "codecsPrecedence = ["
+ codecsPrecedence
+ + "], initIndex = [" + initIndex + "], finalIndex = [" + finalIndex
+ "].");
+
+ while (initIndex < finalIndex) {
+
+ codecId = codecsPrecedence.substring(initIndex, finalIndex);
+
+ printLog("getAvailableAudioCodecsWithPrecedence", "codecId = [" +
codecId + "].");
+
+ SIPCodec sipCodec =
getSIPAudioCodec(Integer.valueOf(codecId).intValue());
+
+ if (sipCodec != null) {
+
+ printLog("getAvailableAudioCodecsWithPrecedence", "codecId = [" +
sipCodec.getCodecId()
+ + "], codecName = [" + sipCodec.getCodecName() + "].");
+
+ availableCodecs[codecsIndex] = sipCodec;
+ codecsIndex++;
+
+ initIndex = finalIndex + 1;
+ finalIndex = codecsPrecedence.indexOf(";", initIndex);
+
+ if ((finalIndex == -1) && (initIndex <= codecsPrecedence.length())) {
+
+ finalIndex = codecsPrecedence.length();
+ }
+
+ printLog("getAvailableAudioCodecsWithPrecedence", "codecsIndex = [" +
codecsIndex + "], initIndex = ["
+ + initIndex + "], finalIndex = [" + finalIndex + "].");
+ } else {
+
+ printLog("getAvailableAudioCodecsWithPrecedence", "Problem with value
[" + codecId
+ + "] retrieved from [" + codecsPrecedence + "].");
+ }
+ }
+
+ return availableCodecs;
+
+ }
+
+ /**
+ * @return Count of available audio codecs
+ */
+ public int getAvailableAudioCodecsCount() {
+
+ return availableAudioCodecsId.length;
+ }
+
+ /**
+ * @return Count of available video codecs
+ */
+ public int getAvailableVideoCodecsCount() {
+
+ return availableVideoCodecsId.length;
+ }
+
+ public String[] getCommonAudioMediaAttributes() {
+
+ return codecCommonAudioMediaAttributes;
+ }
+
+ public String[] getCommonVideoMediaAttributes() {
+ return null;
+ }
- private static void printLog( String method, String message ) {
- log.debug( "SIPCodecFactory - " + method + " -> " + message );
- }
+ private static void printLog(String method, String message) {
+ log.debug("SIPCodecFactory - " + method + " -> " + message);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecG729.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecG729.java Thu Feb 21
09:21:48 2013
@@ -1,181 +1,160 @@
package org.red5.codecs;
-
import org.red5.codecs.g729.Decoder;
import org.red5.codecs.g729.Encoder;
-
public class SIPCodecG729 implements SIPCodec {
- // Codec information
- private static final String codecName = "G729";
+ // Codec information
+ private static final String codecName = "G729";
- private static String[] codecMediaAttributes = { "fmtp:18 annexb=no" };
+ private static String[] codecMediaAttributes = { "fmtp:18 annexb=no" };
- private static final int codecId = 18;
+ private static final int codecId = 18;
- private static int defaultEncodedFrameSize = 20;
+ private static int defaultEncodedFrameSize = 20;
- private static int defaultDecodedFrameSize = 160;
+ private static int defaultDecodedFrameSize = 160;
- private static int defaultSampleRate = 8000;
+ private static int defaultSampleRate = 8000;
- private int outgoingPacketization = 0;
+ private int outgoingPacketization = 0;
- private int incomingPacketization = 0;
+ private int incomingPacketization = 0;
- private Encoder encoder = new Encoder();
-
- private Decoder decoder = new Decoder();
+ private Encoder encoder = new Encoder();
+ private Decoder decoder = new Decoder();
- public SIPCodecG729() {
+ public SIPCodecG729() {
- }
+ }
+ @Override
+ public void encodeInit(int defaultEncodePacketization) {
- @Override
- public void encodeInit( int defaultEncodePacketization ) {
-
- if ( this.outgoingPacketization == 0 ) {
-
- this.outgoingPacketization = defaultEncodePacketization;
- }
- }
+ if (this.outgoingPacketization == 0) {
+ this.outgoingPacketization = defaultEncodePacketization;
+ }
+ }
- @Override
- public void decodeInit( int defaultDecodePacketization ) {
-
- if ( this.incomingPacketization == 0 ) {
-
- this.incomingPacketization = defaultDecodePacketization;
- }
- }
+ @Override
+ public void decodeInit(int defaultDecodePacketization) {
+ if (this.incomingPacketization == 0) {
- @Override
- public String codecNegotiateAttribute( String attributeName, String
localAttributeValue, String remoteAttributeValue ) {
+ this.incomingPacketization = defaultDecodePacketization;
+ }
+ }
- // Not applicable for this codec type
- return null;
- }
+ @Override
+ public String codecNegotiateAttribute(String attributeName, String
localAttributeValue, String remoteAttributeValue) {
+ // Not applicable for this codec type
+ return null;
+ }
- @Override
- public int getCodecBlankPacket( byte[] buffer, int offset ) {
+ @Override
+ public int getCodecBlankPacket(byte[] buffer, int offset) {
- // TODO Auto-generated method stub
- return 0;
- }
+ // TODO Auto-generated method stub
+ return 0;
+ }
+ @Override
+ public int codecToPcm(byte[] bufferIn, float[] bufferOut) {
- @Override
- public int codecToPcm( byte[] bufferIn, float[] bufferOut ) {
+ decoder.decode(bufferIn, bufferOut);
- decoder.decode( bufferIn, bufferOut );
+ return bufferOut.length;
+ }
- return bufferOut.length;
- }
+ @Override
+ public int pcmToCodec(float[] bufferIn, byte[] bufferOut) {
+ encoder.encode(bufferIn, bufferOut);
- @Override
- public int pcmToCodec( float[] bufferIn, byte[] bufferOut ) {
+ return bufferOut.length;
+ }
- encoder.encode( bufferIn, bufferOut );
+ @Override
+ public int getIncomingEncodedFrameSize() {
- return bufferOut.length;
- }
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
+ @Override
+ public int getIncomingDecodedFrameSize() {
- @Override
- public int getIncomingEncodedFrameSize() {
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
-
-
- @Override
- public int getIncomingDecodedFrameSize() {
-
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
-
-
- @Override
- public int getOutgoingEncodedFrameSize() {
-
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
-
-
- @Override
- public int getOutgoingDecodedFrameSize() {
-
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
-
+ @Override
+ public int getOutgoingEncodedFrameSize() {
- @Override
- public int getIncomingPacketization() {
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- return incomingPacketization;
- }
+ @Override
+ public int getOutgoingDecodedFrameSize() {
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- @Override
- public int getOutgoingPacketization() {
+ @Override
+ public int getIncomingPacketization() {
- return outgoingPacketization;
- }
+ return incomingPacketization;
+ }
+ @Override
+ public int getOutgoingPacketization() {
- @Override
- public void setLocalPtime( int localPtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.incomingPacketization == 0 ) {
-
- incomingPacketization = localPtime;
- }
- }
+ return outgoingPacketization;
+ }
+ @Override
+ public void setLocalPtime(int localPtime) {
- @Override
- public void setRemotePtime( int remotePtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.outgoingPacketization == 0 ) {
-
- outgoingPacketization = remotePtime;
- }
- }
+ // Test for prior update during attributes negotiation.
+ if (this.incomingPacketization == 0) {
+ incomingPacketization = localPtime;
+ }
+ }
- @Override
- public int getSampleRate() {
+ @Override
+ public void setRemotePtime(int remotePtime) {
- return defaultSampleRate;
- }
+ // Test for prior update during attributes negotiation.
+ if (this.outgoingPacketization == 0) {
+ outgoingPacketization = remotePtime;
+ }
+ }
- @Override
- public String getCodecName() {
+ @Override
+ public int getSampleRate() {
- return codecName;
- }
+ return defaultSampleRate;
+ }
+ @Override
+ public String getCodecName() {
- @Override
- public int getCodecId() {
+ return codecName;
+ }
- return codecId;
- }
+ @Override
+ public int getCodecId() {
+ return codecId;
+ }
- @Override
- public String[] getCodecMediaAttributes() {
+ @Override
+ public String[] getCodecMediaAttributes() {
- return codecMediaAttributes;
- }
+ return codecMediaAttributes;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMA.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMA.java Thu Feb 21
09:21:48 2013
@@ -4,188 +4,166 @@
import local.media.G711;
-
public class SIPCodecPCMA implements SIPCodec {
- // Codec information
- private static final String codecName = "PCMA";
-
- private static final int codecId = 8;
+ // Codec information
+ private static final String codecName = "PCMA";
- private static int defaultEncodedFrameSize = 160;
+ private static final int codecId = 8;
- private static int defaultDecodedFrameSize = 160;
-
- private static int defaultSampleRate = 8000;
+ private static int defaultEncodedFrameSize = 160;
- private int outgoingPacketization = 0;
+ private static int defaultDecodedFrameSize = 160;
- private int incomingPacketization = 0;
+ private static int defaultSampleRate = 8000;
+ private int outgoingPacketization = 0;
- public SIPCodecPCMA() {
+ private int incomingPacketization = 0;
- }
+ public SIPCodecPCMA() {
+ }
- @Override
- public void encodeInit( int defaultEncodePacketization ) {
-
- if ( this.outgoingPacketization == 0 ) {
-
- this.outgoingPacketization = defaultEncodePacketization;
- }
- }
+ @Override
+ public void encodeInit(int defaultEncodePacketization) {
+ if (this.outgoingPacketization == 0) {
- @Override
- public void decodeInit( int defaultDecodePacketization ) {
-
- if ( this.incomingPacketization == 0 ) {
-
- this.incomingPacketization = defaultDecodePacketization;
- }
- }
+ this.outgoingPacketization = defaultEncodePacketization;
+ }
+ }
+ @Override
+ public void decodeInit(int defaultDecodePacketization) {
- @Override
- public String codecNegotiateAttribute( String attributeName, String
localAttributeValue, String remoteAttributeValue ) {
+ if (this.incomingPacketization == 0) {
- // Not applicable for this codec type
- return null;
- }
+ this.incomingPacketization = defaultDecodePacketization;
+ }
+ }
+ @Override
+ public String codecNegotiateAttribute(String attributeName, String
localAttributeValue, String remoteAttributeValue) {
- @Override
- public int getCodecBlankPacket( byte[] buffer, int offset ) {
+ // Not applicable for this codec type
+ return null;
+ }
- Arrays.fill( buffer, offset, offset +
getOutgoingEncodedFrameSize(), (byte)G711.linear2alaw(0));
-
- return getOutgoingEncodedFrameSize();
- }
+ @Override
+ public int getCodecBlankPacket(byte[] buffer, int offset) {
+ Arrays.fill(buffer, offset, offset + getOutgoingEncodedFrameSize(),
(byte) G711.linear2alaw(0));
- @Override
- public int codecToPcm( byte[] bufferIn, float[] bufferOut ) {
+ return getOutgoingEncodedFrameSize();
+ }
- if ( bufferIn.length > 0 ) {
- for ( int i = 0; i < bufferIn.length; i++ ) {
- bufferOut[ i ] = (float) G711.alaw2linear( (int) bufferIn[
i ] );
- }
-
- return bufferOut.length;
- }
- else {
- return 0;
- }
- }
+ @Override
+ public int codecToPcm(byte[] bufferIn, float[] bufferOut) {
+ if (bufferIn.length > 0) {
+ for (int i = 0; i < bufferIn.length; i++) {
+ bufferOut[i] = (float) G711.alaw2linear((int) bufferIn[i]);
+ }
- @Override
- public int pcmToCodec( float[] bufferIn, byte[] bufferOut ) {
-
- if ( bufferIn.length > 0 ) {
- for ( int i = 0; i < bufferIn.length; i++ ) {
- bufferOut[ i ] = (byte) G711.linear2alaw( (int) bufferIn[
i ] );
- }
-
- return bufferOut.length;
- }
- else {
- return 0;
- }
- }
-
-
- @Override
- public int getIncomingEncodedFrameSize() {
-
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
-
-
- @Override
- public int getIncomingDecodedFrameSize() {
+ return bufferOut.length;
+ } else {
+ return 0;
+ }
+ }
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
+ @Override
+ public int pcmToCodec(float[] bufferIn, byte[] bufferOut) {
+ if (bufferIn.length > 0) {
+ for (int i = 0; i < bufferIn.length; i++) {
+ bufferOut[i] = (byte) G711.linear2alaw((int) bufferIn[i]);
+ }
- @Override
- public int getOutgoingEncodedFrameSize() {
+ return bufferOut.length;
+ } else {
+ return 0;
+ }
+ }
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
+ @Override
+ public int getIncomingEncodedFrameSize() {
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
- @Override
- public int getOutgoingDecodedFrameSize() {
+ @Override
+ public int getIncomingDecodedFrameSize() {
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
+ @Override
+ public int getOutgoingEncodedFrameSize() {
- @Override
- public int getIncomingPacketization() {
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- return incomingPacketization;
- }
+ @Override
+ public int getOutgoingDecodedFrameSize() {
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- @Override
- public int getOutgoingPacketization() {
+ @Override
+ public int getIncomingPacketization() {
- return outgoingPacketization;
- }
+ return incomingPacketization;
+ }
+ @Override
+ public int getOutgoingPacketization() {
- @Override
- public void setLocalPtime( int localPtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.incomingPacketization == 0 ) {
-
- incomingPacketization = localPtime;
- }
- }
+ return outgoingPacketization;
+ }
+ @Override
+ public void setLocalPtime(int localPtime) {
- @Override
- public void setRemotePtime( int remotePtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.outgoingPacketization == 0 ) {
-
- outgoingPacketization = remotePtime;
- }
- }
+ // Test for prior update during attributes negotiation.
+ if (this.incomingPacketization == 0) {
+ incomingPacketization = localPtime;
+ }
+ }
- @Override
- public int getSampleRate() {
+ @Override
+ public void setRemotePtime(int remotePtime) {
- return defaultSampleRate;
- }
+ // Test for prior update during attributes negotiation.
+ if (this.outgoingPacketization == 0) {
+ outgoingPacketization = remotePtime;
+ }
+ }
- @Override
- public String getCodecName() {
+ @Override
+ public int getSampleRate() {
- return codecName;
- }
+ return defaultSampleRate;
+ }
+ @Override
+ public String getCodecName() {
- @Override
- public int getCodecId() {
+ return codecName;
+ }
- return codecId;
- }
+ @Override
+ public int getCodecId() {
+ return codecId;
+ }
- @Override
- public String[] getCodecMediaAttributes() {
+ @Override
+ public String[] getCodecMediaAttributes() {
- // TODO Auto-generated method stub
- return null;
- }
+ // TODO Auto-generated method stub
+ return null;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMU.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecPCMU.java Thu Feb 21
09:21:48 2013
@@ -4,188 +4,166 @@
import local.media.G711;
-
public class SIPCodecPCMU implements SIPCodec {
- // Codec information
- private static final String codecName = "PCMU";
-
- private static final int codecId = 0;
+ // Codec information
+ private static final String codecName = "PCMU";
- private static int defaultEncodedFrameSize = 160;
+ private static final int codecId = 0;
- private static int defaultDecodedFrameSize = 160;
-
- private static int defaultSampleRate = 8000;
+ private static int defaultEncodedFrameSize = 160;
- private int outgoingPacketization = 0;
+ private static int defaultDecodedFrameSize = 160;
- private int incomingPacketization = 0;
+ private static int defaultSampleRate = 8000;
+ private int outgoingPacketization = 0;
- public SIPCodecPCMU() {
+ private int incomingPacketization = 0;
- }
+ public SIPCodecPCMU() {
+ }
- @Override
- public void encodeInit( int defaultEncodePacketization ) {
-
- if ( this.outgoingPacketization == 0 ) {
-
- this.outgoingPacketization = defaultEncodePacketization;
- }
- }
+ @Override
+ public void encodeInit(int defaultEncodePacketization) {
+ if (this.outgoingPacketization == 0) {
- @Override
- public void decodeInit( int defaultDecodePacketization ) {
-
- if ( this.incomingPacketization == 0 ) {
-
- this.incomingPacketization = defaultDecodePacketization;
- }
- }
+ this.outgoingPacketization = defaultEncodePacketization;
+ }
+ }
+ @Override
+ public void decodeInit(int defaultDecodePacketization) {
- @Override
- public String codecNegotiateAttribute( String attributeName, String
localAttributeValue, String remoteAttributeValue ) {
+ if (this.incomingPacketization == 0) {
- // Not applicable for this codec type
- return null;
- }
+ this.incomingPacketization = defaultDecodePacketization;
+ }
+ }
+ @Override
+ public String codecNegotiateAttribute(String attributeName, String
localAttributeValue, String remoteAttributeValue) {
- @Override
- public int getCodecBlankPacket( byte[] buffer, int offset ) {
+ // Not applicable for this codec type
+ return null;
+ }
- Arrays.fill( buffer, offset, offset +
getOutgoingEncodedFrameSize(), (byte)G711.linear2ulaw(0));
-
- return getOutgoingEncodedFrameSize();
- }
+ @Override
+ public int getCodecBlankPacket(byte[] buffer, int offset) {
+ Arrays.fill(buffer, offset, offset + getOutgoingEncodedFrameSize(),
(byte) G711.linear2ulaw(0));
- @Override
- public int codecToPcm( byte[] bufferIn, float[] bufferOut ) {
+ return getOutgoingEncodedFrameSize();
+ }
- if ( bufferIn.length > 0 ) {
- for ( int i = 0; i < bufferIn.length; i++ ) {
- bufferOut[ i ] = (float) G711.ulaw2linear( (int) bufferIn[
i ] );
- }
-
- return bufferOut.length;
- }
- else {
- return 0;
- }
- }
+ @Override
+ public int codecToPcm(byte[] bufferIn, float[] bufferOut) {
+ if (bufferIn.length > 0) {
+ for (int i = 0; i < bufferIn.length; i++) {
+ bufferOut[i] = (float) G711.ulaw2linear((int) bufferIn[i]);
+ }
- @Override
- public int pcmToCodec( float[] bufferIn, byte[] bufferOut ) {
-
- if ( bufferIn.length > 0 ) {
- for ( int i = 0; i < bufferIn.length; i++ ) {
- bufferOut[ i ] = (byte) G711.linear2ulaw( (int) bufferIn[
i ] );
- }
-
- return bufferOut.length;
- }
- else {
- return 0;
- }
- }
-
-
- @Override
- public int getIncomingEncodedFrameSize() {
-
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
-
-
- @Override
- public int getIncomingDecodedFrameSize() {
+ return bufferOut.length;
+ } else {
+ return 0;
+ }
+ }
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * incomingPacketization;
- }
+ @Override
+ public int pcmToCodec(float[] bufferIn, byte[] bufferOut) {
+ if (bufferIn.length > 0) {
+ for (int i = 0; i < bufferIn.length; i++) {
+ bufferOut[i] = (byte) G711.linear2ulaw((int) bufferIn[i]);
+ }
- @Override
- public int getOutgoingEncodedFrameSize() {
+ return bufferOut.length;
+ } else {
+ return 0;
+ }
+ }
- return ( defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
+ @Override
+ public int getIncomingEncodedFrameSize() {
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
- @Override
- public int getOutgoingDecodedFrameSize() {
+ @Override
+ public int getIncomingDecodedFrameSize() {
- return ( defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION
) * outgoingPacketization;
- }
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
incomingPacketization;
+ }
+ @Override
+ public int getOutgoingEncodedFrameSize() {
- @Override
- public int getIncomingPacketization() {
+ return (defaultEncodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- return incomingPacketization;
- }
+ @Override
+ public int getOutgoingDecodedFrameSize() {
+ return (defaultDecodedFrameSize / SIPCodec.DEFAULT_PACKETIZATION) *
outgoingPacketization;
+ }
- @Override
- public int getOutgoingPacketization() {
+ @Override
+ public int getIncomingPacketization() {
- return outgoingPacketization;
- }
+ return incomingPacketization;
+ }
+ @Override
+ public int getOutgoingPacketization() {
- @Override
- public void setLocalPtime( int localPtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.incomingPacketization == 0 ) {
-
- incomingPacketization = localPtime;
- }
- }
+ return outgoingPacketization;
+ }
+ @Override
+ public void setLocalPtime(int localPtime) {
- @Override
- public void setRemotePtime( int remotePtime ) {
-
- // Test for prior update during attributes negotiation.
- if ( this.outgoingPacketization == 0 ) {
-
- outgoingPacketization = remotePtime;
- }
- }
+ // Test for prior update during attributes negotiation.
+ if (this.incomingPacketization == 0) {
+ incomingPacketization = localPtime;
+ }
+ }
- @Override
- public int getSampleRate() {
+ @Override
+ public void setRemotePtime(int remotePtime) {
- return defaultSampleRate;
- }
+ // Test for prior update during attributes negotiation.
+ if (this.outgoingPacketization == 0) {
+ outgoingPacketization = remotePtime;
+ }
+ }
- @Override
- public String getCodecName() {
+ @Override
+ public int getSampleRate() {
- return codecName;
- }
+ return defaultSampleRate;
+ }
+ @Override
+ public String getCodecName() {
- @Override
- public int getCodecId() {
+ return codecName;
+ }
- return codecId;
- }
+ @Override
+ public int getCodecId() {
+ return codecId;
+ }
- @Override
- public String[] getCodecMediaAttributes() {
+ @Override
+ public String[] getCodecMediaAttributes() {
- // TODO Auto-generated method stub
- return null;
- }
+ // TODO Auto-generated method stub
+ return null;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodecUtils.java Sun Feb
17 19:49:41 2013
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodecUtils.java Thu Feb
21 09:21:48 2013
@@ -5,162 +5,139 @@
import org.zoolu.sdp.AttributeField;
import org.zoolu.sdp.SessionDescriptor;
-
/**
- * A utility class for determine, instantiate and configure SIP codec,
- * based on payload, local and remote SDP packets
+ * A utility class for determine, instantiate and configure SIP codec,
based on payload, local and remote SDP packets
*/
public class SIPCodecUtils {
- protected static Logger log = LoggerFactory.getLogger(
SIPCodecUtils.class );
-
-
- public static SIPCodec initSipAudioCodec( SIPCodec audioCodec, int
defaultEncodePacketization,
- int defaultDecodePacketization, SessionDescriptor localSDP,
SessionDescriptor remoteSDP ) {
-
- AttributeField remotePtimeAttribute =
- remoteSDP.getMediaDescriptor( SIPCodec.MEDIA_TYPE_AUDIO ).
- getAttribute( SIPCodec.ATTRIBUTE_PTIME );
-
- if ( remotePtimeAttribute != null ) {
-
- audioCodec.setRemotePtime(
- Integer.valueOf(
remotePtimeAttribute.getAttributeValue() ) );
- }
-
- AttributeField localPtimeAttribute =
- localSDP.getMediaDescriptor( SIPCodec.MEDIA_TYPE_AUDIO ).
- getAttribute( SIPCodec.ATTRIBUTE_PTIME );
-
- if ( localPtimeAttribute != null ) {
-
- audioCodec.setLocalPtime(
- Integer.valueOf(
localPtimeAttribute.getAttributeValue() ) );
- }
-
- printLog( "initSipAudioCodec",
- "Codec id = [" + audioCodec.getCodecId() +
- "], codec name = [" + audioCodec.getCodecName() +
- "], sampleRate = [" + audioCodec.getSampleRate() +
- "], incomingEndodedFrameSize = [" +
audioCodec.getIncomingEncodedFrameSize() +
- "], incomingDedodedFrameSize = [" +
audioCodec.getIncomingDecodedFrameSize() +
- "], incomingPacketization = [" +
audioCodec.getIncomingPacketization() +
- "], outgoingEndodedFrameSize = [" +
audioCodec.getOutgoingEncodedFrameSize() +
- "], outgoingDedodedFrameSize = [" +
audioCodec.getOutgoingDecodedFrameSize() +
- "], outgoingPacketization = [" +
audioCodec.getOutgoingPacketization() + "]." );
-
- // Initialize encode and decode codec.
- audioCodec.encodeInit( defaultEncodePacketization );
- audioCodec.decodeInit( defaultDecodePacketization );
-
- return audioCodec;
- }
-
- /**
- * Converts a byte array into a short array. Since a byte is 8-bits,
- * and a short is 16-bits, the returned short array will be half in
- * length than the byte array. If the length of the byte array is odd,
- * the length of the short array will be
- * <code>(byteArray.length - 1)/2</code>, i.e., the last byte is
- * discarded.
- *
- * @param byteArray a byte array
- * @param offset which byte to start from
- * @param length how many bytes to convert
- * @param little specifies whether the result should be using little
endian
- * order or not.
- *
- * @return a short array, or <code>null</code> if byteArray is of zero
- * length
- *
- * @throws java.lang.ArrayIndexOutOfBoundsException
- * @author Damian Minkov
- */
- public static short[] byteToShortArray
- (byte[] byteArray, int offset, int length, boolean little)
- throws ArrayIndexOutOfBoundsException
- {
+ protected static Logger log =
LoggerFactory.getLogger(SIPCodecUtils.class);
- if (0 < length && (offset + length) <= byteArray.length)
- {
- int shortLength = length / 2;
- short[] shortArray = new short[shortLength];
- int temp;
- for (int i = offset, j = 0; j < shortLength;
- j++, temp = 0x00000000)
- {
- if(little)
- {
- temp = byteArray[i++] & 0x000000FF;
- temp |= 0x0000FF00 & (byteArray[i++] << 8);
- }
- else
- {
- temp = byteArray[i++] << 8;
- temp |= 0x000000FF & byteArray[i++];
- }
+ public static SIPCodec initSipAudioCodec(SIPCodec audioCodec, int
defaultEncodePacketization,
+ int defaultDecodePacketization, SessionDescriptor localSDP,
SessionDescriptor remoteSDP) {
+
+ AttributeField remotePtimeAttribute =
remoteSDP.getMediaDescriptor(SIPCodec.MEDIA_TYPE_AUDIO).getAttribute(
+ SIPCodec.ATTRIBUTE_PTIME);
+
+ if (remotePtimeAttribute != null) {
+
+
audioCodec.setRemotePtime(Integer.valueOf(remotePtimeAttribute.getAttributeValue()));
+ }
+
+ AttributeField localPtimeAttribute =
localSDP.getMediaDescriptor(SIPCodec.MEDIA_TYPE_AUDIO).getAttribute(
+ SIPCodec.ATTRIBUTE_PTIME);
+
+ if (localPtimeAttribute != null) {
+
+
audioCodec.setLocalPtime(Integer.valueOf(localPtimeAttribute.getAttributeValue()));
+ }
+
+ printLog(
+ "initSipAudioCodec",
+ "Codec id = [" + audioCodec.getCodecId() + "], codec name = [" +
audioCodec.getCodecName()
+ + "], sampleRate = [" + audioCodec.getSampleRate() + "],
incomingEndodedFrameSize = ["
+ + audioCodec.getIncomingEncodedFrameSize() + "],
incomingDedodedFrameSize = ["
+ + audioCodec.getIncomingDecodedFrameSize() + "],
incomingPacketization = ["
+ + audioCodec.getIncomingPacketization() + "],
outgoingEndodedFrameSize = ["
+ + audioCodec.getOutgoingEncodedFrameSize() + "],
outgoingDedodedFrameSize = ["
+ + audioCodec.getOutgoingDecodedFrameSize() + "],
outgoingPacketization = ["
+ + audioCodec.getOutgoingPacketization() + "].");
+
+ // Initialize encode and decode codec.
+ audioCodec.encodeInit(defaultEncodePacketization);
+ audioCodec.decodeInit(defaultDecodePacketization);
+
+ return audioCodec;
+ }
+
+ /**
+ * Converts a byte array into a short array. Since a byte is 8-bits, and
a short is 16-bits, the returned short
+ * array will be half in length than the byte array. If the length of the
byte array is odd, the length of the short
+ * array will be <code>(byteArray.length - 1)/2</code>, i.e., the last
byte is discarded.
+ *
+ * @param byteArray
+ * a byte array
+ * @param offset
+ * which byte to start from
+ * @param length
+ * how many bytes to convert
+ * @param little
+ * specifies whether the result should be using little endian
order or not.
+ *
+ * @return a short array, or <code>null</code> if byteArray is of zero
length
+ *
+ * @throws java.lang.ArrayIndexOutOfBoundsException
+ * @author Damian Minkov
+ */
+ public static short[] byteToShortArray(byte[] byteArray, int offset, int
length, boolean little)
+ throws ArrayIndexOutOfBoundsException {
- shortArray[j] = (short) temp;
- }
- return shortArray;
- }
- else
- {
- throw new ArrayIndexOutOfBoundsException
- ("offset: " + offset + ", length: " + length
- + ", array length: " + byteArray.length);
- }
- }
+ if (0 < length && (offset + length) <= byteArray.length) {
+ int shortLength = length / 2;
+ short[] shortArray = new short[shortLength];
+ int temp;
+ for (int i = offset, j = 0; j < shortLength; j++, temp = 0x00000000) {
+ if (little) {
+ temp = byteArray[i++] & 0x000000FF;
+ temp |= 0x0000FF00 & (byteArray[i++] << 8);
+ } else {
+ temp = byteArray[i++] << 8;
+ temp |= 0x000000FF & byteArray[i++];
+ }
- /**
- * The result array must be twice as the input one. Since a byte is
8-bits,
- * and a short is 16-bits.
- * @param in the short[] array that we'll be transforming.
- * @param res the byte[] arrays where we'll be setting the converted
short
- * values.
- * @param little specifies whether the result should be using little
endian
- * order or not.
- * @author Damian Minkov
- */
- public static void shortArrToByteArr(short[] in, byte[] res, boolean
little)
- {
- int resIx = 0;
+ shortArray[j] = (short) temp;
+ }
+ return shortArray;
+ } else {
+ throw new ArrayIndexOutOfBoundsException("offset: " + offset + ",
length: " + length + ", array length: "
+ + byteArray.length);
+ }
+ }
- byte[] tmp = null;
- for (int i = 0; i < in.length; i++)
- {
- tmp = shortToBytes(in[i], little);
- res[resIx++] = tmp[0];
- res[resIx++] = tmp[1];
- }
- }
+ /**
+ * The result array must be twice as the input one. Since a byte is
8-bits, and a short is 16-bits.
+ *
+ * @param in
+ * the short[] array that we'll be transforming.
+ * @param res
+ * the byte[] arrays where we'll be setting the converted
short values.
+ * @param little
+ * specifies whether the result should be using little endian
order or not.
+ * @author Damian Minkov
+ */
+ public static void shortArrToByteArr(short[] in, byte[] res, boolean
little) {
+ int resIx = 0;
- /**
- * Get a pair of bytes representing a short value.
- * @param v the short value to convert.
- * @param little specifies whether the result should be using little
endian
- * order or no.
- * @return a byte[] array containing the result.
- * @author Damian Minkov
- */
- public static byte[] shortToBytes(short v, boolean little)
- {
- byte[] rtn = new byte[2];
- if (little)
- {
- rtn[0] = (byte) (v & 0xff);
- rtn[1] = (byte) ( (v >>> 8) & 0xff);
- }
- else
- {
- rtn[0] = (byte) ( (v >>> 8) & 0xff);
- rtn[1] = (byte) (v & 0xff);
- }
- return rtn;
- }
+ byte[] tmp = null;
+ for (int i = 0; i < in.length; i++) {
+ tmp = shortToBytes(in[i], little);
+ res[resIx++] = tmp[0];
+ res[resIx++] = tmp[1];
+ }
+ }
+ /**
+ * Get a pair of bytes representing a short value.
+ *
+ * @param v
+ * the short value to convert.
+ * @param little
+ * specifies whether the result should be using little endian
order or no.
+ * @return a byte[] array containing the result.
+ * @author Damian Minkov
+ */
+ public static byte[] shortToBytes(short v, boolean little) {
+ byte[] rtn = new byte[2];
+ if (little) {
+ rtn[0] = (byte) (v & 0xff);
+ rtn[1] = (byte) ((v >>> 8) & 0xff);
+ } else {
+ rtn[0] = (byte) ((v >>> 8) & 0xff);
+ rtn[1] = (byte) (v & 0xff);
+ }
+ return rtn;
+ }
- private static void printLog( String method, String message ) {
- log.debug( "SIPCodecUtils - " + method + " -> " + message );
- }
+ private static void printLog(String method, String message) {
+ log.debug("SIPCodecUtils - " + method + " -> " + message);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/SIPCodeciLBC.java Sun Feb 17
19:49:41 2013
+++ /branches/red5sip/src/java/org/red5/codecs/SIPCodeciLBC.java Thu Feb 21
09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs;
-
import org.red5.codecs.ilbc.bitstream;
import org.red5.codecs.ilbc.ilbc_constants;
import org.red5.codecs.ilbc.ilbc_decoder;
@@ -8,279 +7,246 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class SIPCodeciLBC implements SIPCodec {
- protected static Logger log = LoggerFactory.getLogger(
SIPCodeciLBC.class );
-
-
- // Codec information
- private static final String codecName = "ILBC";
-
- private static String[] codecMediaAttributes = { "fmtp:111 mode=30" };
+ protected static Logger log = LoggerFactory.getLogger(SIPCodeciLBC.class);
- private static final int codecId = 111;
+ // Codec information
+ private static final String codecName = "ILBC";
- private static int sampleFrame20ms = 20;
+ private static String[] codecMediaAttributes = { "fmtp:111 mode=30" };
- private static int sampleFrame30ms = 30;
+ private static final int codecId = 111;
- private static int defaultEncodedFrameSize20ms =
ilbc_constants.NO_OF_BYTES_20MS;
+ private static int sampleFrame20ms = 20;
- private static int defaultEncodedFrameSize30ms =
ilbc_constants.NO_OF_BYTES_30MS;
+ private static int sampleFrame30ms = 30;
- private static int defaultDecodedFrameSize20ms =
ilbc_constants.BLOCKL_20MS;
+ private static int defaultEncodedFrameSize20ms =
ilbc_constants.NO_OF_BYTES_20MS;
- private static int defaultDecodedFrameSize30ms =
ilbc_constants.BLOCKL_30MS;
+ private static int defaultEncodedFrameSize30ms =
ilbc_constants.NO_OF_BYTES_30MS;
- private static int defaultSampleRate = 8000;
+ private static int defaultDecodedFrameSize20ms =
ilbc_constants.BLOCKL_20MS;
- // For iLBC we must init this with default "mode" packetization.
- private int outgoingPacketization = 30;
+ private static int defaultDecodedFrameSize30ms =
ilbc_constants.BLOCKL_30MS;
- // For iLBC we must init this with default "mode" packetization.
- private int incomingPacketization = 30;
+ private static int defaultSampleRate = 8000;
- private ilbc_encoder ilbcEncoder;
+ // For iLBC we must init this with default "mode" packetization.
+ private int outgoingPacketization = 30;
- private ilbc_decoder ilbcDecoder;
+ // For iLBC we must init this with default "mode" packetization.
+ private int incomingPacketization = 30;
+ private ilbc_encoder ilbcEncoder;
- public SIPCodeciLBC() {
+ private ilbc_decoder ilbcDecoder;
- }
+ public SIPCodeciLBC() {
+ }
- @Override
- public void encodeInit( int defaultEncodePacketization ) {
+ @Override
+ public void encodeInit(int defaultEncodePacketization) {
- ilbcEncoder = new ilbc_encoder( outgoingPacketization );
- }
+ ilbcEncoder = new ilbc_encoder(outgoingPacketization);
+ }
+ @Override
+ public void decodeInit(int defaultDecodePacketization) {
- @Override
- public void decodeInit( int defaultDecodePacketization ) {
+ ilbcDecoder = new ilbc_decoder(incomingPacketization, 1);
+ }
- ilbcDecoder = new ilbc_decoder( incomingPacketization, 1 );
- }
+ @Override
+ public String codecNegotiateAttribute(String attributeName, String
localAttributeValue, String remoteAttributeValue) {
+ Integer localMode = SIPCodec.DEFAULT_PACKETIZATION;
+ Integer remoteMode = 0;
+ String finalAttributeValue = "";
- @Override
- public String codecNegotiateAttribute( String attributeName, String
localAttributeValue, String remoteAttributeValue ) {
+ printLog("codecNegotiateAttribute ", "attributeName = [" + attributeName
+ "localAttributeValue = ["
+ + localAttributeValue + "] remoteAttributeValue = [" +
remoteAttributeValue + "].");
- Integer localMode = SIPCodec.DEFAULT_PACKETIZATION;
- Integer remoteMode = 0;
- String finalAttributeValue = "";
+ if (0 == attributeName.compareTo(SIPCodec.ATTRIBUTE_FMTP)) {
- printLog( "codecNegotiateAttribute ",
- "attributeName = [" + attributeName +
- "localAttributeValue = [" + localAttributeValue +
- "] remoteAttributeValue = [" + remoteAttributeValue + "]."
);
-
- if ( 0 == attributeName.compareTo( SIPCodec.ATTRIBUTE_FMTP ) ) {
-
- if ( ( null == remoteAttributeValue ) || (
remoteAttributeValue.isEmpty() ) ) {
-
- finalAttributeValue = "";
- }
- else {
- remoteMode = extractModeFromFmtpValue(
remoteAttributeValue );
-
- if ( ( null != localAttributeValue ) &&
( !localAttributeValue.isEmpty() ) ) {
-
- localMode = extractModeFromFmtpValue(
localAttributeValue );
- }
-
- if ( remoteMode > localMode ) {
-
- finalAttributeValue = remoteAttributeValue;
-
- outgoingPacketization = remoteMode;
- incomingPacketization = remoteMode;
- }
- else if ( null == localAttributeValue ) {
-
- finalAttributeValue = remoteAttributeValue.substring(
- 0, remoteAttributeValue.indexOf( " mode=" ) +
6 );
- finalAttributeValue.concat( localMode.toString() );
- }
- }
- }
-
- printLog( "codecNegotiateAttribute ",
- "finalAttributeValue = [" + finalAttributeValue + "]." );
-
- return finalAttributeValue;
- }
-
-
- protected int extractModeFromFmtpValue( String fmtpValue ) {
-
- int modePos = fmtpValue.indexOf( " mode=" ) + 6;
- return Integer.parseInt( fmtpValue.substring( modePos ) );
- }
+ if ((null == remoteAttributeValue) || (remoteAttributeValue.isEmpty()))
{
+ finalAttributeValue = "";
+ } else {
+ remoteMode = extractModeFromFmtpValue(remoteAttributeValue);
- @Override
- public int getCodecBlankPacket( byte[] buffer, int offset ) {
+ if ((null != localAttributeValue) && (!localAttributeValue.isEmpty()))
{
- // TODO Auto-generated method stub
- return 0;
- }
+ localMode = extractModeFromFmtpValue(localAttributeValue);
+ }
+ if (remoteMode > localMode) {
- @Override
- public int codecToPcm( byte[] bufferIn, float[] bufferOut ) {
+ finalAttributeValue = remoteAttributeValue;
- short[] encodedData = SIPCodecUtils.byteToShortArray(bufferIn, 0,
bufferIn.length, false);
+ outgoingPacketization = remoteMode;
+ incomingPacketization = remoteMode;
+ } else if (null == localAttributeValue) {
- bitstream encodedBitStream = new bitstream(
getOutgoingDecodedFrameSize() * 2 );
-
- for (int i = 0; i < encodedData.length; i++) {
- encodedBitStream.buffer[2*i+1] = (char) (encodedData[i] &
0xff);
- encodedBitStream.buffer[2*i] = (char) ((encodedData[i] >> 8) &
0xff);
- }
-
- ilbcDecoder.iLBC_decode(bufferOut, encodedBitStream, 1);
+ finalAttributeValue = remoteAttributeValue.substring(0,
remoteAttributeValue.indexOf(" mode=") + 6);
+ finalAttributeValue.concat(localMode.toString());
+ }
+ }
+ }
- return getOutgoingDecodedFrameSize();
- }
+ printLog("codecNegotiateAttribute ", "finalAttributeValue = [" +
finalAttributeValue + "].");
+ return finalAttributeValue;
+ }
- @Override
- public int pcmToCodec( float[] bufferIn, byte[] bufferOut ) {
+ protected int extractModeFromFmtpValue(String fmtpValue) {
- short[] encodedData = new short[ getIncomingEncodedFrameSize() / 2
];
+ int modePos = fmtpValue.indexOf(" mode=") + 6;
+ return Integer.parseInt(fmtpValue.substring(modePos));
+ }
- bitstream encodedBitStream = new bitstream(
getIncomingEncodedFrameSize() * 2 );
+ @Override
+ public int getCodecBlankPacket(byte[] buffer, int offset) {
- ilbcEncoder.iLBC_encode( encodedBitStream, bufferIn );
+ // TODO Auto-generated method stub
+ return 0;
+ }
- for ( int i = 0; i < encodedData.length; i++ ) {
- encodedData[ i ] = (short) ( ( ( encodedBitStream.buffer[ 2 *
i ] << 8 ) & 0xff00 ) | ( ( (short) encodedBitStream.buffer[ 2 * i + 1 ] )
& 0x00ff ) );
- }
-
- SIPCodecUtils.shortArrToByteArr( encodedData, bufferOut, false );
+ @Override
+ public int codecToPcm(byte[] bufferIn, float[] bufferOut) {
- return getIncomingEncodedFrameSize();
- }
+ short[] encodedData = SIPCodecUtils.byteToShortArray(bufferIn, 0,
bufferIn.length, false);
+ bitstream encodedBitStream = new bitstream(getOutgoingDecodedFrameSize()
* 2);
- @Override
- public int getIncomingEncodedFrameSize() {
+ for (int i = 0; i < encodedData.length; i++) {
+ encodedBitStream.buffer[2 * i + 1] = (char) (encodedData[i] & 0xff);
+ encodedBitStream.buffer[2 * i] = (char) ((encodedData[i] >> 8) & 0xff);
+ }
- if ( incomingPacketization == sampleFrame20ms ) {
- return defaultEncodedFrameSize20ms;
- }
- else if ( incomingPacketization == sampleFrame30ms ) {
- return defaultEncodedFrameSize30ms;
- }
+ ilbcDecoder.iLBC_decode(bufferOut, encodedBitStream, 1);
- return defaultEncodedFrameSize20ms;
- }
+ return getOutgoingDecodedFrameSize();
+ }
+ @Override
+ public int pcmToCodec(float[] bufferIn, byte[] bufferOut) {
- @Override
- public int getIncomingDecodedFrameSize() {
+ short[] encodedData = new short[getIncomingEncodedFrameSize() / 2];
- if ( incomingPacketization == sampleFrame20ms ) {
- return defaultDecodedFrameSize20ms;
- }
- else if ( incomingPacketization == sampleFrame30ms ) {
- return defaultDecodedFrameSize30ms;
- }
+ bitstream encodedBitStream = new bitstream(getIncomingEncodedFrameSize()
* 2);
- return defaultDecodedFrameSize20ms;
- }
+ ilbcEncoder.iLBC_encode(encodedBitStream, bufferIn);
+ for (int i = 0; i < encodedData.length; i++) {
+ encodedData[i] = (short) (((encodedBitStream.buffer[2 * i] << 8) &
0xff00) | (((short) encodedBitStream.buffer[2 * i + 1]) & 0x00ff));
+ }
- @Override
- public int getOutgoingEncodedFrameSize() {
+ SIPCodecUtils.shortArrToByteArr(encodedData, bufferOut, false);
- if ( outgoingPacketization == sampleFrame20ms ) {
- return defaultEncodedFrameSize20ms;
- }
- else if ( outgoingPacketization == sampleFrame30ms ) {
- return defaultEncodedFrameSize30ms;
- }
+ return getIncomingEncodedFrameSize();
+ }
- return defaultEncodedFrameSize20ms;
- }
+ @Override
+ public int getIncomingEncodedFrameSize() {
+ if (incomingPacketization == sampleFrame20ms) {
+ return defaultEncodedFrameSize20ms;
+ } else if (incomingPacketization == sampleFrame30ms) {
+ return defaultEncodedFrameSize30ms;
+ }
- @Override
- public int getOutgoingDecodedFrameSize() {
+ return defaultEncodedFrameSize20ms;
+ }
- if ( outgoingPacketization == sampleFrame20ms ) {
- return defaultDecodedFrameSize20ms;
- }
- else if ( outgoingPacketization == sampleFrame30ms ) {
- return defaultDecodedFrameSize30ms;
- }
+ @Override
+ public int getIncomingDecodedFrameSize() {
- return defaultDecodedFrameSize20ms;
- }
+ if (incomingPacketization == sampleFrame20ms) {
+ return defaultDecodedFrameSize20ms;
+ } else if (incomingPacketization == sampleFrame30ms) {
+ return defaultDecodedFrameSize30ms;
+ }
+ return defaultDecodedFrameSize20ms;
+ }
- @Override
- public int getIncomingPacketization() {
+ @Override
+ public int getOutgoingEncodedFrameSize() {
- return incomingPacketization;
- }
+ if (outgoingPacketization == sampleFrame20ms) {
+ return defaultEncodedFrameSize20ms;
+ } else if (outgoingPacketization == sampleFrame30ms) {
+ return defaultEncodedFrameSize30ms;
+ }
+ return defaultEncodedFrameSize20ms;
+ }
- @Override
- public int getOutgoingPacketization() {
+ @Override
+ public int getOutgoingDecodedFrameSize() {
- return outgoingPacketization;
- }
+ if (outgoingPacketization == sampleFrame20ms) {
+ return defaultDecodedFrameSize20ms;
+ } else if (outgoingPacketization == sampleFrame30ms) {
+ return defaultDecodedFrameSize30ms;
+ }
+ return defaultDecodedFrameSize20ms;
+ }
- @Override
- public void setLocalPtime( int localPtime ) {
-
- // For iLBC we have a "mode" paramater setted and it
- // overcomes any ptime configuration.
- }
+ @Override
+ public int getIncomingPacketization() {
+ return incomingPacketization;
+ }
- @Override
- public void setRemotePtime( int remotePtime ) {
-
- // For iLBC we have a "mode" paramater setted and it
- // overcomes any ptime configuration.
- }
+ @Override
+ public int getOutgoingPacketization() {
+ return outgoingPacketization;
+ }
- @Override
- public int getSampleRate() {
+ @Override
+ public void setLocalPtime(int localPtime) {
- return defaultSampleRate;
- }
+ // For iLBC we have a "mode" paramater setted and it
+ // overcomes any ptime configuration.
+ }
+ @Override
+ public void setRemotePtime(int remotePtime) {
- @Override
- public String getCodecName() {
+ // For iLBC we have a "mode" paramater setted and it
+ // overcomes any ptime configuration.
+ }
- return codecName;
- }
+ @Override
+ public int getSampleRate() {
+ return defaultSampleRate;
+ }
- @Override
- public int getCodecId() {
+ @Override
+ public String getCodecName() {
- return codecId;
- }
+ return codecName;
+ }
+ @Override
+ public int getCodecId() {
- @Override
- public String[] getCodecMediaAttributes() {
+ return codecId;
+ }
- return codecMediaAttributes;
- }
+ @Override
+ public String[] getCodecMediaAttributes() {
+ return codecMediaAttributes;
+ }
- private static void printLog( String method, String message ) {
- log.debug( "SIPCodecUtils - " + method + " -> " + message );
- }
+ private static void printLog(String method, String message) {
+ log.debug("SIPCodecUtils - " + method + " -> " + message);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/ByteStream.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/ByteStream.java Thu Feb
21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,35 +32,31 @@
//------------------------------------------------------------------------
public final class ByteStream {
- public final byte[] bytes;
+ public final byte[] bytes;
- public final int offset;
+ public final int offset;
- public final int length;
+ public final int length;
+ public ByteStream(int i) {
- public ByteStream( int i ) {
+ this(new byte[i]);
+ }
- this( new byte[ i ] );
- }
+ public ByteStream(byte[] abyte0) {
+ this(abyte0, 0, abyte0.length);
+ }
- public ByteStream( byte[] abyte0 ) {
+ public ByteStream(byte[] abyte0, int i) {
- this( abyte0, 0, abyte0.length );
- }
-
-
- public ByteStream( byte[] abyte0, int i ) {
-
- this( abyte0, i, abyte0.length );
- }
-
+ this(abyte0, i, abyte0.length);
+ }
- public ByteStream( byte[] abyte0, int i, int j ) {
+ public ByteStream(byte[] abyte0, int i, int j) {
- bytes = abyte0;
- offset = i;
- length = Math.min( j, abyte0.length - i );
- }
+ bytes = abyte0;
+ offset = i;
+ length = Math.min(j, abyte0.length - i);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/Codec.java Thu Feb 14
08:34:08 2013
+++ /branches/red5sip/src/java/org/red5/codecs/asao/Codec.java Thu Feb 21
09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,751 +32,693 @@
//------------------------------------------------------------------------
public final class Codec {
- public Codec() {
+ public Codec() {
- }
+ }
- private static final float[] i_nelly_init_table = { 3134F, 5342F,
6870F, 7792F, 8569F, 9185F, 9744F, 10191F,
- 10631F, 11061F, 11434F, 11770F, 12116F, 12513F, 12925F, 13300F,
13674F, 14027F, 14352F, 14716F, 15117F, 15477F,
- 15824F, 16157F, 16513F, 16804F, 17090F, 17401F, 17679F, 17948F,
18238F, 18520F, 18764F, 19078F, 19381F, 19640F,
- 19921F, 20205F, 20500F, 20813F, 21162F, 21465F, 21794F, 22137F,
22453F, 22756F, 23067F, 23350F, 23636F, 23926F,
- 24227F, 24521F, 24819F, 25107F, 25414F, 25730F, 26120F, 26497F,
26895F, 27344F, 27877F, 28463F, 29426F, 31355F };
+ private static final float[] i_nelly_init_table = { 3134F, 5342F, 6870F,
7792F, 8569F, 9185F, 9744F, 10191F,
+ 10631F, 11061F, 11434F, 11770F, 12116F, 12513F, 12925F, 13300F, 13674F,
14027F, 14352F, 14716F, 15117F,
+ 15477F, 15824F, 16157F, 16513F, 16804F, 17090F, 17401F, 17679F, 17948F,
18238F, 18520F, 18764F, 19078F,
+ 19381F, 19640F, 19921F, 20205F, 20500F, 20813F, 21162F, 21465F, 21794F,
22137F, 22453F, 22756F, 23067F,
+ 23350F, 23636F, 23926F, 24227F, 24521F, 24819F, 25107F, 25414F, 25730F,
26120F, 26497F, 26895F, 27344F,
+ 27877F, 28463F, 29426F, 31355F };
- private static final float[] j_nelly_delta_table = { -11725F, -9420F,
-7910F, -6801F, -5948F, -5233F, -4599F,
- -4039F, -3507F, -3030F, -2596F, -2170F, -1774F, -1383F, -1016F,
-660F, -329F, -1F, 337F, 696F, 1085F, 1512F,
- 1962F, 2433F, 2968F, 3569F, 4314F, 5279F, 6622F, 8154F, 10076F,
12975F };
+ private static final float[] j_nelly_delta_table = { -11725F, -9420F,
-7910F, -6801F, -5948F, -5233F, -4599F,
+ -4039F, -3507F, -3030F, -2596F, -2170F, -1774F, -1383F, -1016F, -660F,
-329F, -1F, 337F, 696F, 1085F,
+ 1512F, 1962F, 2433F, 2968F, 3569F, 4314F, 5279F, 6622F, 8154F, 10076F,
12975F };
- private static final double[] k__nelly_dequantization_table = {
0.0000000000,
+ private static final double[] k__nelly_dequantization_table = {
0.0000000000,
- -0.8472560048, 0.7224709988,
+ -0.8472560048, 0.7224709988,
- -1.5247479677, -0.4531480074, 0.3753609955, 1.4717899561,
+ -1.5247479677, -0.4531480074, 0.3753609955, 1.4717899561,
- -1.9822579622, -1.1929379702, -0.5829370022, -0.0693780035,
0.3909569979, 0.9069200158, 1.4862740040, 2.2215409279,
+ -1.9822579622, -1.1929379702, -0.5829370022, -0.0693780035, 0.3909569979,
0.9069200158, 1.4862740040, 2.2215409279,
- -2.3887870312, -1.8067539930, -1.4105420113, -1.0773609877,
-0.7995010018, -0.5558109879, -0.3334020078,
- -0.1324490011, 0.0568020009, 0.2548770010, 0.4773550034,
0.7386850119, 1.0443060398, 1.3954459429,
- 1.8098750114, 2.3918759823,
+ -2.3887870312, -1.8067539930, -1.4105420113, -1.0773609877,
-0.7995010018, -0.5558109879, -0.3334020078,
+ -0.1324490011, 0.0568020009, 0.2548770010, 0.4773550034, 0.7386850119,
1.0443060398, 1.3954459429,
+ 1.8098750114, 2.3918759823,
- -2.3893830776, -1.9884680510, -1.7514040470, -1.5643119812,
-1.3922129869, -1.2164649963, -1.0469499826,
- -0.8905100226, -0.7645580173, -0.6454579830, -0.5259280205,
-0.4059549868, -0.3029719889, -0.2096900046,
- -0.1239869967, -0.0479229987, 0.0257730000, 0.1001340002,
0.1737180054, 0.2585540116, 0.3522900045,
- 0.4569880068, 0.5767750144, 0.7003160119, 0.8425520062,
1.0093879700, 1.1821349859, 1.3534560204, 1.5320819616,
- 1.7332619429, 1.9722349644, 2.3978140354,
+ -2.3893830776, -1.9884680510, -1.7514040470, -1.5643119812,
-1.3922129869, -1.2164649963, -1.0469499826,
+ -0.8905100226, -0.7645580173, -0.6454579830, -0.5259280205,
-0.4059549868, -0.3029719889, -0.2096900046,
+ -0.1239869967, -0.0479229987, 0.0257730000, 0.1001340002, 0.1737180054,
0.2585540116, 0.3522900045,
+ 0.4569880068, 0.5767750144, 0.7003160119, 0.8425520062, 1.0093879700,
1.1821349859, 1.3534560204,
+ 1.5320819616, 1.7332619429, 1.9722349644, 2.3978140354,
- -2.5756309032, -2.0573320389, -1.8984919786, -1.7727810144,
-1.6662600040, -1.5742180347, -1.4993319511,
- -1.4316639900, -1.3652280569, -1.3000990152, -1.2280930281,
-1.1588579416, -1.0921250582, -1.0135740042,
- -0.9202849865, -0.8287050128, -0.7374889851, -0.6447759867,
-0.5590940118, -0.4857139885, -0.4110319912,
- -0.3459700048, -0.2851159871, -0.2341620028, -0.1870580018,
-0.1442500055, -0.1107169986, -0.0739680007,
- -0.0365610011, -0.0073290002, 0.0203610007, 0.0479039997,
0.0751969963, 0.0980999991, 0.1220389977,
- 0.1458999962, 0.1694349945, 0.1970459968, 0.2252430022,
0.2556869984, 0.2870100141, 0.3197099864, 0.3525829911,
- 0.3889069855, 0.4334920049, 0.4769459963, 0.5204820037,
0.5644530058, 0.6122040153, 0.6685929894, 0.7341650128,
- 0.8032159805, 0.8784040213, 0.9566209912, 1.0397069454,
1.1293770075, 1.2211159468, 1.3080279827, 1.4024800062,
- 1.5056819916, 1.6227730513, 1.7724959850, 1.9430880547,
2.2903931141, 0.0F };
+ -2.5756309032, -2.0573320389, -1.8984919786, -1.7727810144,
-1.6662600040, -1.5742180347, -1.4993319511,
+ -1.4316639900, -1.3652280569, -1.3000990152, -1.2280930281,
-1.1588579416, -1.0921250582, -1.0135740042,
+ -0.9202849865, -0.8287050128, -0.7374889851, -0.6447759867,
-0.5590940118, -0.4857139885, -0.4110319912,
+ -0.3459700048, -0.2851159871, -0.2341620028, -0.1870580018,
-0.1442500055, -0.1107169986, -0.0739680007,
+ -0.0365610011, -0.0073290002, 0.0203610007, 0.0479039997, 0.0751969963,
0.0980999991, 0.1220389977,
+ 0.1458999962, 0.1694349945, 0.1970459968, 0.2252430022, 0.2556869984,
0.2870100141, 0.3197099864,
+ 0.3525829911, 0.3889069855, 0.4334920049, 0.4769459963, 0.5204820037,
0.5644530058, 0.6122040153,
+ 0.6685929894, 0.7341650128, 0.8032159805, 0.8784040213, 0.9566209912,
1.0397069454, 1.1293770075,
+ 1.2211159468, 1.3080279827, 1.4024800062, 1.5056819916, 1.6227730513,
1.7724959850, 1.9430880547,
+ 2.2903931141, 0.0F };
- private static final int[] f = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18,
21, 24, 28, 32, 37, 43, 49, 56, 64, 73, 83, 95,
- 109, 124 };
+ private static final int[] f = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21,
24, 28, 32, 37, 43, 49, 56, 64, 73, 83, 95,
+ 109, 124 };
- private static final short[] g = { 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
- 0, 0, 0, 0, 0 };
+ private static final short[] g = { 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
- private static final int[] h = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 8,
8, 10, 12, 12, 14, 16, 18, 20, 24, 28, 30, 0 };
+ private static final int[] h = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 8, 8,
10, 12, 12, 14, 16, 18, 20, 24, 28, 30, 0 };
- public static final float[] a = makeTableA();
+ public static final float[] a = makeTableA();
- public static final float[] b = makeTableB();
+ public static final float[] b = makeTableB();
- public static final float[] c = makeTableC();
+ public static final float[] c = makeTableC();
- public static final float[] d = makeTableD();
+ public static final float[] d = makeTableD();
- private static final short[] l = { 32767, 30840, 29127, 27594, 26214,
24966, 23831, 22795, 21845, 20972, 20165,
- 19418, 18725, 18079, 17476, 16913, 16384, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0 };
+ private static final short[] l = { 32767, 30840, 29127, 27594, 26214,
24966, 23831, 22795, 21845, 20972, 20165,
+ 19418, 18725, 18079, 17476, 16913, 16384, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0 };
- public static final float[] e = makeTableE();
+ public static final float[] e = makeTableE();
+ public static void process(float[] af, float[] af1, int i1, byte[]
abyte0, int j1, float[] af2, float[] af3,
+ float[] af4, float[] af5, float[] af6, int[] ai) {
- public static void process(
- float[] af,
- float[] af1,
- int i1,
- byte[] abyte0,
- int j1,
- float[] af2,
- float[] af3,
- float[] af4,
- float[] af5,
- float[] af6,
- int[] ai ) {
+ StateTable j2 = new StateTable(abyte0, j1);
+ process(af, af1, i1, af2, 0, 7);
+ process(af, af1, i1 + 128, af2, 128, 7);
+ for (int k1 = 0; k1 < 23; k1++) {
+ double d1 = 0.0D;
+ int j4 = f[k1];
+ for (int j5 = f[k1 + 1]; j4 < j5; j4++) {
+ double d2 = af2[j4];
+ double d3 = af2[j4 + 128];
+ d1 += d2 * d2 + d3 * d3;
+ }
- StateTable j2 = new StateTable( abyte0, j1 );
- process( af, af1, i1, af2, 0, 7 );
- process( af, af1, i1 + 128, af2, 128, 7 );
- for ( int k1 = 0; k1 < 23; k1++ ) {
- double d1 = 0.0D;
- int j4 = f[ k1 ];
- for ( int j5 = f[ k1 + 1 ]; j4 < j5; j4++ ) {
- double d2 = af2[ j4 ];
- double d3 = af2[ j4 + 128 ];
- d1 += d2 * d2 + d3 * d3;
- }
+ af3[k1] = Math.round(Math.log(Math.max(1.0D, d1 / (double) h[k1])) *
1477.3197004799999D);
+ }
- af3[ k1 ] = Math.round( Math.log( Math.max( 1.0D, d1 /
(double) h[ k1 ] ) ) * 1477.3197004799999D );
- }
+ int l1 = process(af3[0], i_nelly_init_table, 0, 64);
+ af4[0] = i_nelly_init_table[l1];
+ j2.state(l1, g[0]);
+ for (int l2 = 1; l2 < 23; l2++) {
+ int i2 = process(af3[l2] - af4[l2 - 1], j_nelly_delta_table, 0, 32);
+ af4[l2] = af4[l2 - 1] + j_nelly_delta_table[i2];
+ j2.state(i2, g[l2]);
+ }
- int l1 = process( af3[ 0 ], i_nelly_init_table, 0, 64 );
- af4[ 0 ] = i_nelly_init_table[ l1 ];
- j2.state( l1, g[ 0 ] );
- for ( int l2 = 1; l2 < 23; l2++ ) {
- int i2 = process( af3[ l2 ] - af4[ l2 - 1 ],
j_nelly_delta_table, 0, 32 );
- af4[ l2 ] = af4[ l2 - 1 ] + j_nelly_delta_table[ i2 ];
- j2.state( i2, g[ l2 ] );
- }
+ for (int i3 = 0; i3 < 23; i3++) {
+ af3[i3] = (float) (1.0D / Math.pow(2D, (double) af4[i3] *
0.00048828125D));
+ }
- for ( int i3 = 0; i3 < 23; i3++ ) {
- af3[ i3 ] = (float) ( 1.0D / Math.pow( 2D, (double) af4[ i3 ]
* 0.00048828125D ) );
- }
+ for (int j3 = 0; j3 < 23; j3++) {
+ int l3 = f[j3];
+ for (int k4 = f[j3 + 1]; l3 < k4; l3++) {
+ af5[l3] = af4[j3];
+ af6[l3] = af3[j3];
+ }
- for ( int j3 = 0; j3 < 23; j3++ ) {
- int l3 = f[ j3 ];
- for ( int k4 = f[ j3 + 1 ]; l3 < k4; l3++ ) {
- af5[ l3 ] = af4[ j3 ];
- af6[ l3 ] = af3[ j3 ];
- }
+ }
- }
+ int k3 = process(af5, 124, 198, ai);
- int k3 = process( af5, 124, 198, ai );
+ for (int i4 = 0; i4 < 256; /* FIXME DEAD CODE i4 += 128 */) {
+ for (int l4 = 0; l4 < 124; l4++) {
+ int k5 = ai[l4];
+ if (k5 > 0) {
+ int l5 = 1 << k5;
+ int k2 = processIt(af6[l4] * af2[i4 + l4],
k__nelly_dequantization_table, l5 - 1, (l5 << 1) - 1);
+ j2.state(k2, k5);
+ }
+ }
- for ( int i4 = 0; i4 < 256; /* FIXME DEAD CODE i4 += 128 */ ) {
- for ( int l4 = 0; l4 < 124; l4++ ) {
- int k5 = ai[ l4 ];
- if ( k5 > 0 ) {
- int l5 = 1 << k5;
- int k2 = processIt(
- af6[ l4 ] * af2[ i4 + l4 ],
- k__nelly_dequantization_table,
- l5 - 1,
- ( l5 << 1 ) - 1 );
- j2.state( k2, k5 );
- }
- }
+ int i5 = k3;
+ do {
+ if (i5 <= 0) {
+ continue;
+ }
+ if (i5 > 8) {
+ j2.state(0, 8);
+ } else {
+ j2.state(0, i5);
+ continue;
+ }
+ i5 -= 8;
+ } while (true);
+ }
- int i5 = k3;
- do {
- if ( i5 <= 0 ) {
- continue;
- }
- if ( i5 > 8 ) {
- j2.state( 0, 8 );
- }
- else {
- j2.state( 0, i5 );
- continue;
- }
- i5 -= 8;
- }
- while ( true );
- }
+ }
- }
+ public static void process(float[] af, byte[] abyte0, int i1, float[]
af1, int j1, float[] af2, float[] af3,
+ float[] af4, byte[] abyte1, int[] ai) {
+ StateTable j2 = new StateTable(abyte0, i1);
+ int k1 = j2.state(g[0]);
+ abyte1[0] = (byte) k1;
+ af2[0] = i_nelly_init_table[k1];
+ for (int k2 = 1; k2 < 23; k2++) {
+ int l1 = j2.state(g[k2]);
+ abyte1[k2] = (byte) l1;
+ af2[k2] = af2[k2 - 1] + j_nelly_delta_table[l1];
+ }
- public static void process(
- float[] af,
- byte[] abyte0,
- int i1,
- float[] af1,
- int j1,
- float[] af2,
- float[] af3,
- float[] af4,
- byte[] abyte1,
- int[] ai ) {
+ for (int l2 = 0; l2 < 23; l2++) {
+ float f1 = (float) Math.pow(2D, (double) af2[l2] * 0.00048828125D);
+ int k3 = f[l2];
+ for (int k4 = f[l2 + 1]; k3 < k4; k3++) {
+ af4[k3] = af2[l2];
+ af3[k3] = f1;
+ }
- StateTable j2 = new StateTable( abyte0, i1 );
- int k1 = j2.state( g[ 0 ] );
- abyte1[ 0 ] = (byte) k1;
- af2[ 0 ] = i_nelly_init_table[ k1 ];
- for ( int k2 = 1; k2 < 23; k2++ ) {
- int l1 = j2.state( g[ k2 ] );
- abyte1[ k2 ] = (byte) l1;
- af2[ k2 ] = af2[ k2 - 1 ] + j_nelly_delta_table[ l1 ];
- }
+ }
- for ( int l2 = 0; l2 < 23; l2++ ) {
- float f1 = (float) Math.pow( 2D, (double) af2[ l2 ] *
0.00048828125D );
- int k3 = f[ l2 ];
- for ( int k4 = f[ l2 + 1 ]; k3 < k4; k3++ ) {
- af4[ k3 ] = af2[ l2 ];
- af3[ k3 ] = f1;
- }
+ int i3 = process(af4, 124, 198, ai);
+ for (int j3 = 0; j3 < 256; j3 += 128) {
+ for (int l3 = 0; l3 < 124; l3++) {
+ int l4 = ai[l3];
+ float f2 = af3[l3];
+ if (l4 > 0) {
+ int i5 = 1 << l4;
+ int i2 = j2.state(l4);
+ abyte1[l3] = (byte) i2;
+ f2 *= k__nelly_dequantization_table[(i5 - 1) + i2];
+ } else {
+ double d1 = Math.random() * 4294967296D;
+ if (d1 < 1073758208D) {
+ f2 = (float) ((double) f2 * -0.70709997400000002D);
+ } else {
+ f2 = (float) ((double) f2 * 0.70709997400000002D);
+ }
+ }
+ af2[l3] = f2;
+ }
- }
+ for (int i4 = 124; i4 < 128; i4++) {
+ af2[i4] = 0.0F;
+ }
- int i3 = process( af4, 124, 198, ai );
- for ( int j3 = 0; j3 < 256; j3 += 128 ) {
- for ( int l3 = 0; l3 < 124; l3++ ) {
- int l4 = ai[ l3 ];
- float f2 = af3[ l3 ];
- if ( l4 > 0 ) {
- int i5 = 1 << l4;
- int i2 = j2.state( l4 );
- abyte1[ l3 ] = (byte) i2;
- f2 *= k__nelly_dequantization_table[ ( i5 - 1 ) + i2 ];
- }
- else {
- double d1 = Math.random() * 4294967296D;
- if ( d1 < 1073758208D ) {
- f2 = (float) ( (double) f2 * -0.70709997400000002D
);
- }
- else {
- f2 = (float) ( (double) f2 * 0.70709997400000002D
);
- }
- }
- af2[ l3 ] = f2;
- }
+ int j4 = i3;
+ do {
+ if (j4 <= 0) {
+ break;
+ }
+ if (j4 > 8) {
+ j2.state(8);
+ } else {
+ j2.state(j4);
+ break;
+ }
+ j4 -= 8;
+ } while (true);
+ process(af, af2, af1, j3, 7);
+ }
- for ( int i4 = 124; i4 < 128; i4++ ) {
- af2[ i4 ] = 0.0F;
- }
+ }
- int j4 = i3;
- do {
- if ( j4 <= 0 ) {
- break;
- }
- if ( j4 > 8 ) {
- j2.state( 8 );
- }
- else {
- j2.state( j4 );
- break;
- }
- j4 -= 8;
- }
- while ( true );
- process( af, af2, af1, j3, 7 );
- }
+ private static void process(float[] af, float[] af1, float[] af2, int i1,
int j1) {
- }
+ int k1 = 1 << j1;
+ int l1 = k1 >> 2;
+ int i2 = k1 - 1;
+ int j2 = k1 >> 1;
+ int k2 = j2 - 1;
+ int l2 = 0;
+ process(af1, 0, af2, i1, j1);
+ while (l2 < l1) {
+ double d1 = af[l2];
+ double d2 = af[k2];
+ double d3 = af2[i1 + j2];
+ double d4 = af2[i1 + i2];
+ af[l2] = -af2[i1 + k2];
+ af[k2] = -af2[i1 + l2];
+ af2[i1 + l2] = (float) (d1 * (double) d[i2] + d3 * (double) d[l2]);
+ af2[i1 + k2] = (float) (d2 * (double) d[j2] + d4 * (double) d[k2]);
+ af2[i1 + j2] = (float) ((double) d[j2] * -d4 + (double) d[k2] * d2);
+ af2[i1 + i2] = (float) ((double) d[i2] * -d3 + (double) d[l2] * d1);
+ l2++;
+ k2--;
+ j2++;
+ i2--;
+ }
+ }
+ private static void process(float[] af, float[] af1, int i1, float[] af2,
int j1, int k1) {
- private static void process( float[] af, float[] af1, float[] af2, int
i1, int j1 ) {
+ int l1 = 1 << k1;
+ int i2 = l1 >> 2;
+ int j2 = l1 - 1;
+ int k2 = l1 >> 1;
+ int l2 = k2 - 1;
+ for (int i3 = 0; i3 < i2;) {
+ af2[j1 + k2] = af[i3];
+ af2[j1 + j2] = af[l2];
+ af2[j1 + i3] = -af1[i1 + l2] * d[k2] - af1[i1 + k2] * d[l2];
+ af2[j1 + l2] = -af1[i1 + j2] * d[i3] - af1[i1 + i3] * d[j2];
+ af[i3] = af1[i1 + i3] * d[i3] - af1[i1 + j2] * d[j2];
+ af[l2] = af1[i1 + l2] * d[l2] - af1[i1 + k2] * d[k2];
+ i3++;
+ k2++;
+ j2--;
+ l2--;
+ }
- int k1 = 1 << j1;
- int l1 = k1 >> 2;
- int i2 = k1 - 1;
- int j2 = k1 >> 1;
- int k2 = j2 - 1;
- int l2 = 0;
- process( af1, 0, af2, i1, j1 );
- while ( l2 < l1 ) {
- double d1 = af[ l2 ];
- double d2 = af[ k2 ];
- double d3 = af2[ i1 + j2 ];
- double d4 = af2[ i1 + i2 ];
- af[ l2 ] = -af2[ i1 + k2 ];
- af[ k2 ] = -af2[ i1 + l2 ];
- af2[ i1 + l2 ] = (float) ( d1 * (double) d[ i2 ] + d3 *
(double) d[ l2 ] );
- af2[ i1 + k2 ] = (float) ( d2 * (double) d[ j2 ] + d4 *
(double) d[ k2 ] );
- af2[ i1 + j2 ] = (float) ( (double) d[ j2 ] * -d4 + (double)
d[ k2 ] * d2 );
- af2[ i1 + i2 ] = (float) ( (double) d[ i2 ] * -d3 + (double)
d[ l2 ] * d1 );
- l2++;
- k2--;
- j2++;
- i2--;
- }
- }
+ process(af2, j1, af2, j1, k1);
+ }
+ private static void process(float[] af, int i1, float[] af1, int j1, int
k1) {
- private static void process( float[] af, float[] af1, int i1, float[]
af2, int j1, int k1 ) {
+ int l1 = 1 << k1;
+ int i2 = (l1 >> 1) - 1;
+ int j2 = l1 >> 2;
+ for (int k2 = 0; k2 < j2; k2++) {
+ int l2 = k2 << 1;
+ int i3 = l1 - 1 - l2;
+ int k3 = i3 - 1;
+ double d1 = af[i1 + l2];
+ double d2 = af[i1 + l2 + 1];
+ double d4 = af[i1 + i3];
+ double d6 = af[i1 + k3];
+ af1[j1 + l2] = (float) ((double) a[k2] * d1 - (double) c[k2] * d4);
+ af1[j1 + l2 + 1] = (float) (d4 * (double) a[k2] + d1 * (double) c[k2]);
+ af1[j1 + k3] = (float) ((double) a[i2 - k2] * d6 - (double) c[i2 - k2]
* d2);
+ af1[j1 + i3] = (float) (d2 * (double) a[i2 - k2] + d6 * (double) c[i2 -
k2]);
+ }
- int l1 = 1 << k1;
- int i2 = l1 >> 2;
- int j2 = l1 - 1;
- int k2 = l1 >> 1;
- int l2 = k2 - 1;
- for ( int i3 = 0; i3 < i2; ) {
- af2[ j1 + k2 ] = af[ i3 ];
- af2[ j1 + j2 ] = af[ l2 ];
- af2[ j1 + i3 ] = -af1[ i1 + l2 ] * d[ k2 ] - af1[ i1 + k2 ] *
d[ l2 ];
- af2[ j1 + l2 ] = -af1[ i1 + j2 ] * d[ i3 ] - af1[ i1 + i3 ] *
d[ j2 ];
- af[ i3 ] = af1[ i1 + i3 ] * d[ i3 ] - af1[ i1 + j2 ] * d[ j2 ];
- af[ l2 ] = af1[ i1 + l2 ] * d[ l2 ] - af1[ i1 + k2 ] * d[ k2 ];
- i3++;
- k2++;
- j2--;
- l2--;
- }
+ process(af1, j1, k1 - 1);
+ float f1 = af1[(j1 + l1) - 1];
+ float f2 = af1[(j1 + l1) - 2];
+ af1[j1] = b[0] * af1[j1];
+ af1[(j1 + l1) - 1] = af1[j1 + 1] * -b[0];
+ af1[(j1 + l1) - 2] = b[i2] * af1[(j1 + l1) - 2] + b[1] * f1;
+ af1[j1 + 1] = f2 * b[1] - f1 * b[i2];
+ int j3 = 1;
+ int l3 = l1 - 3;
+ int i4 = i2;
- process( af2, j1, af2, j1, k1 );
- }
+ for (int j4 = 3; j3 < j2; j4 += 2) {
+ double d3 = af1[j1 + l3];
+ double d5 = af1[(j1 + l3) - 1];
+ double d7 = af1[j1 + j4];
+ double d8 = af1[(j1 + j4) - 1];
+ af1[(j1 + j4) - 1] = (float) ((double) b[i4] * d7 + (double) b[j4 - 1
>> 1] * d8);
+ af1[j1 + j4] = (float) (d5 * (double) b[j4 + 1 >> 1] - d3 * (double)
b[i4 - 1]);
+ af1[j1 + l3] = (float) (d8 * (double) b[i4] - d7 * (double) b[j4 - 1 >>
1]);
+ af1[(j1 + l3) - 1] = (float) ((double) b[j4 + 1 >> 1] * d3 + (double)
b[i4 - 1] * d5);
+ j3++;
+ i4--;
+ l3 -= 2;
+ }
+ }
- private static void process( float[] af, int i1, float[] af1, int j1,
int k1 ) {
+ private static void process(float[] af, int i1, int j1) {
- int l1 = 1 << k1;
- int i2 = ( l1 >> 1 ) - 1;
- int j2 = l1 >> 2;
- for ( int k2 = 0; k2 < j2; k2++ ) {
- int l2 = k2 << 1;
- int i3 = l1 - 1 - l2;
- int k3 = i3 - 1;
- double d1 = af[ i1 + l2 ];
- double d2 = af[ i1 + l2 + 1 ];
- double d4 = af[ i1 + i3 ];
- double d6 = af[ i1 + k3 ];
- af1[ j1 + l2 ] = (float) ( (double) a[ k2 ] * d1 - (double) c[
k2 ] * d4 );
- af1[ j1 + l2 + 1 ] = (float) ( d4 * (double) a[ k2 ] + d1 *
(double) c[ k2 ] );
- af1[ j1 + k3 ] = (float) ( (double) a[ i2 - k2 ] * d6 -
(double) c[ i2 - k2 ] * d2 );
- af1[ j1 + i3 ] = (float) ( d2 * (double) a[ i2 - k2 ] + d6 *
(double) c[ i2 - k2 ] );
- }
+ int k1 = 1 << j1;
+ processIt(af, i1, k1);
+ int l1 = 0;
+ for (int j2 = k1 >> 1; j2 > 0;) {
+ float f1 = af[i1 + l1];
+ float f3 = af[i1 + l1 + 1];
+ float f5 = af[i1 + l1 + 2];
+ float f7 = af[i1 + l1 + 3];
+ af[i1 + l1] = f1 + f5;
+ af[i1 + l1 + 1] = f3 + f7;
+ af[i1 + l1 + 2] = f1 - f5;
+ af[i1 + l1 + 3] = f3 - f7;
+ j2--;
+ l1 += 4;
+ }
- process( af1, j1, k1 - 1 );
- float f1 = af1[ ( j1 + l1 ) - 1 ];
- float f2 = af1[ ( j1 + l1 ) - 2 ];
- af1[ j1 ] = b[ 0 ] * af1[ j1 ];
- af1[ ( j1 + l1 ) - 1 ] = af1[ j1 + 1 ] * -b[ 0 ];
- af1[ ( j1 + l1 ) - 2 ] = b[ i2 ] * af1[ ( j1 + l1 ) - 2 ] + b[ 1 ]
* f1;
- af1[ j1 + 1 ] = f2 * b[ 1 ] - f1 * b[ i2 ];
- int j3 = 1;
- int l3 = l1 - 3;
- int i4 = i2;
+ l1 = 0;
+ for (int k2 = k1 >> 2; k2 > 0;) {
+ float f2 = af[i1 + l1];
+ float f4 = af[i1 + l1 + 1];
+ float f6 = af[i1 + l1 + 2];
+ float f8 = af[i1 + l1 + 3];
+ float f9 = af[i1 + l1 + 4];
+ float f10 = af[i1 + l1 + 5];
+ float f11 = af[i1 + l1 + 6];
+ float f12 = af[i1 + l1 + 7];
+ af[i1 + l1] = f2 + f9;
+ af[i1 + l1 + 1] = f4 + f10;
+ af[i1 + l1 + 2] = f6 + f12;
+ af[i1 + l1 + 3] = f8 - f11;
+ af[i1 + l1 + 4] = f2 - f9;
+ af[i1 + l1 + 5] = f4 - f10;
+ af[i1 + l1 + 6] = f6 - f12;
+ af[i1 + l1 + 7] = f8 + f11;
+ k2--;
+ l1 += 8;
+ }
- for ( int j4 = 3; j3 < j2; j4 += 2 ) {
- double d3 = af1[ j1 + l3 ];
- double d5 = af1[ ( j1 + l3 ) - 1 ];
- double d7 = af1[ j1 + j4 ];
- double d8 = af1[ ( j1 + j4 ) - 1 ];
- af1[ ( j1 + j4 ) - 1 ] = (float) ( (double) b[ i4 ] * d7 +
(double) b[ j4 - 1 >> 1 ] * d8 );
- af1[ j1 + j4 ] = (float) ( d5 * (double) b[ j4 + 1 >> 1 ] - d3
* (double) b[ i4 - 1 ] );
- af1[ j1 + l3 ] = (float) ( d8 * (double) b[ i4 ] - d7 *
(double) b[ j4 - 1 >> 1 ] );
- af1[ ( j1 + l3 ) - 1 ] = (float) ( (double) b[ j4 + 1 >> 1 ] *
d3 + (double) b[ i4 - 1 ] * d5 );
- j3++;
- i4--;
- l3 -= 2;
- }
+ int l2 = 0;
+ int i3 = k1 >> 3;
+ int j3 = 64;
+ int k3 = 4;
+ for (int l3 = j1 - 2; l3 > 0;) {
+ int i2 = 0;
+ for (int i4 = i3; i4 != 0;) {
+ for (int j4 = k3 >> 1; j4 > 0;) {
+ int l4 = i2 + (k3 << 1);
+ double d1 = af[i1 + i2];
+ double d3 = af[i1 + i2 + 1];
+ double d5 = af[i1 + l4];
+ double d7 = af[i1 + l4 + 1];
+ af[i1 + l4] = (float) (d1 - (d5 * (double) e[128 - l2] + d7 *
(double) e[l2]));
+ af[i1 + i2] = (float) (d1 + (d5 * (double) e[128 - l2] + d7 *
(double) e[l2]));
+ af[i1 + l4 + 1] = (float) (d3 + (d5 * (double) e[l2] - d7 * (double)
e[128 - l2]));
+ af[i1 + i2 + 1] = (float) (d3 - (d5 * (double) e[l2] - d7 * (double)
e[128 - l2]));
+ j4--;
+ i2 += 2;
+ l2 += j3;
+ }
- }
+ for (int k4 = k3 >> 1; k4 > 0;) {
+ int i5 = i2 + (k3 << 1);
+ double d2 = af[i1 + i2];
+ double d4 = af[i1 + i2 + 1];
+ double d6 = af[i1 + i5];
+ double d8 = af[i1 + i5 + 1];
+ af[i1 + i5] = (float) (d2 + (d6 * (double) e[128 - l2] - d8 *
(double) e[l2]));
+ af[i1 + i2] = (float) (d2 - (d6 * (double) e[128 - l2] - d8 *
(double) e[l2]));
+ af[i1 + i5 + 1] = (float) (d4 + (d8 * (double) e[128 - l2] + d6 *
(double) e[l2]));
+ af[i1 + i2 + 1] = (float) (d4 - (d8 * (double) e[128 - l2] + d6 *
(double) e[l2]));
+ k4--;
+ i2 += 2;
+ l2 -= j3;
+ }
+ i4--;
+ i2 += k3 << 1;
+ }
- private static void process( float[] af, int i1, int j1 ) {
+ l3--;
+ k3 <<= 1;
+ j3 >>= 1;
+ i3 >>= 1;
+ }
- int k1 = 1 << j1;
- processIt( af, i1, k1 );
- int l1 = 0;
- for ( int j2 = k1 >> 1; j2 > 0; ) {
- float f1 = af[ i1 + l1 ];
- float f3 = af[ i1 + l1 + 1 ];
- float f5 = af[ i1 + l1 + 2 ];
- float f7 = af[ i1 + l1 + 3 ];
- af[ i1 + l1 ] = f1 + f5;
- af[ i1 + l1 + 1 ] = f3 + f7;
- af[ i1 + l1 + 2 ] = f1 - f5;
- af[ i1 + l1 + 3 ] = f3 - f7;
- j2--;
- l1 += 4;
- }
+ }
- l1 = 0;
- for ( int k2 = k1 >> 2; k2 > 0; ) {
- float f2 = af[ i1 + l1 ];
- float f4 = af[ i1 + l1 + 1 ];
- float f6 = af[ i1 + l1 + 2 ];
- float f8 = af[ i1 + l1 + 3 ];
- float f9 = af[ i1 + l1 + 4 ];
- float f10 = af[ i1 + l1 + 5 ];
- float f11 = af[ i1 + l1 + 6 ];
- float f12 = af[ i1 + l1 + 7 ];
- af[ i1 + l1 ] = f2 + f9;
- af[ i1 + l1 + 1 ] = f4 + f10;
- af[ i1 + l1 + 2 ] = f6 + f12;
- af[ i1 + l1 + 3 ] = f8 - f11;
- af[ i1 + l1 + 4 ] = f2 - f9;
- af[ i1 + l1 + 5 ] = f4 - f10;
- af[ i1 + l1 + 6 ] = f6 - f12;
- af[ i1 + l1 + 7 ] = f8 + f11;
- k2--;
- l1 += 8;
- }
+ public static int process(int i1) {
- int l2 = 0;
- int i3 = k1 >> 3;
- int j3 = 64;
- int k3 = 4;
- for ( int l3 = j1 - 2; l3 > 0; ) {
- int i2 = 0;
- for ( int i4 = i3; i4 != 0; ) {
- for ( int j4 = k3 >> 1; j4 > 0; ) {
- int l4 = i2 + ( k3 << 1 );
- double d1 = af[ i1 + i2 ];
- double d3 = af[ i1 + i2 + 1 ];
- double d5 = af[ i1 + l4 ];
- double d7 = af[ i1 + l4 + 1 ];
- af[ i1 + l4 ] = (float) ( d1 - ( d5 * (double) e[ 128
- l2 ] + d7 * (double) e[ l2 ] ) );
- af[ i1 + i2 ] = (float) ( d1 + ( d5 * (double) e[ 128
- l2 ] + d7 * (double) e[ l2 ] ) );
- af[ i1 + l4 + 1 ] = (float) ( d3 + ( d5 * (double) e[
l2 ] - d7 * (double) e[ 128 - l2 ] ) );
- af[ i1 + i2 + 1 ] = (float) ( d3 - ( d5 * (double) e[
l2 ] - d7 * (double) e[ 128 - l2 ] ) );
- j4--;
- i2 += 2;
- l2 += j3;
- }
+ return 30 - processIt(Math.abs(i1));
+ }
- for ( int k4 = k3 >> 1; k4 > 0; ) {
- int i5 = i2 + ( k3 << 1 );
- double d2 = af[ i1 + i2 ];
- double d4 = af[ i1 + i2 + 1 ];
- double d6 = af[ i1 + i5 ];
- double d8 = af[ i1 + i5 + 1 ];
- af[ i1 + i5 ] = (float) ( d2 + ( d6 * (double) e[ 128
- l2 ] - d8 * (double) e[ l2 ] ) );
- af[ i1 + i2 ] = (float) ( d2 - ( d6 * (double) e[ 128
- l2 ] - d8 * (double) e[ l2 ] ) );
- af[ i1 + i5 + 1 ] = (float) ( d4 + ( d8 * (double) e[
128 - l2 ] + d6 * (double) e[ l2 ] ) );
- af[ i1 + i2 + 1 ] = (float) ( d4 - ( d8 * (double) e[
128 - l2 ] + d6 * (double) e[ l2 ] ) );
- k4--;
- i2 += 2;
- l2 -= j3;
- }
+ public static int processIt(int i1) {
- i4--;
- i2 += k3 << 1;
- }
+ if (i1 == 0) {
+ return -1;
+ }
+ int j1 = 0;
+ if ((i1 & 0xffff0000) != 0) {
+ j1 = 16;
+ i1 >>= 16;
+ }
+ if ((i1 & 0xff00) != 0) {
+ j1 += 8;
+ i1 >>= 8;
+ }
+ if ((i1 & 0xf0) != 0) {
+ j1 += 4;
+ i1 >>= 4;
+ }
+ if ((i1 & 0xc) != 0) {
+ j1 += 2;
+ i1 >>= 2;
+ }
+ if ((i1 & 2) != 0) {
+ j1++;
+ }
+ return j1;
+ }
- l3--;
- k3 <<= 1;
- j3 >>= 1;
- i3 >>= 1;
- }
+ public static int process(float f1, float[] af, int i1, int j1) {
- }
+ int k1 = 0;
+ float f2 = Math.abs(f1 - af[i1]);
+ for (int l1 = i1; l1 < j1; l1++) {
+ float f3 = Math.abs(f1 - af[l1]);
+ if (f3 < f2) {
+ k1 = l1 - i1;
+ f2 = f3;
+ }
+ }
+ return k1;
+ }
- public static int process( int i1 ) {
+ private static void processIt(float[] af, int i1, int j1) {
- return 30 - processIt( Math.abs( i1 ) );
- }
+ int k1 = 1;
+ int l1 = 1;
+ for (int i2 = j1 << 1; l1 < i2; l1 += 2) {
+ if (l1 < k1) {
+ float f1 = af[i1 + l1];
+ af[i1 + l1] = af[i1 + k1];
+ af[i1 + k1] = f1;
+ float f2 = af[(i1 + l1) - 1];
+ af[(i1 + l1) - 1] = af[(i1 + k1) - 1];
+ af[(i1 + k1) - 1] = f2;
+ }
+ int j2;
+ for (j2 = j1; j2 > 1 && j2 < k1; j2 >>= 1) {
+ k1 -= j2;
+ }
+ k1 += j2;
+ }
- public static int processIt( int i1 ) {
+ }
- if ( i1 == 0 ) {
- return -1;
- }
- int j1 = 0;
- if ( ( i1 & 0xffff0000 ) != 0 ) {
- j1 = 16;
- i1 >>= 16;
- }
- if ( ( i1 & 0xff00 ) != 0 ) {
- j1 += 8;
- i1 >>= 8;
- }
- if ( ( i1 & 0xf0 ) != 0 ) {
- j1 += 4;
- i1 >>= 4;
- }
- if ( ( i1 & 0xc ) != 0 ) {
- j1 += 2;
- i1 >>= 2;
- }
- if ( ( i1 & 2 ) != 0 ) {
- j1++;
- }
- return j1;
- }
+ private static int processIt(float f1, double[] af, int i1, int j1) {
+ int k1 = i1;
+ int l1 = j1;
+ do {
+ int i2 = k1 + l1 >> 1;
+ if (f1 > af[i2]) {
+ k1 = i2;
+ } else {
+ l1 = i2;
+ }
+ } while (l1 - k1 > 1);
+ if (l1 != j1 && f1 - af[k1] > af[l1] - f1) {
+ k1 = l1;
+ }
+ return k1 - i1;
+ }
- public static int process( float f1, float[] af, int i1, int j1 ) {
+ static int process(float[] af, int i1, int j1, int[] ai) {
- int k1 = 0;
- float f2 = Math.abs( f1 - af[ i1 ] );
- for ( int l1 = i1; l1 < j1; l1++ ) {
- float f3 = Math.abs( f1 - af[ l1 ] );
- if ( f3 < f2 ) {
- k1 = l1 - i1;
- f2 = f3;
- }
- }
+ float f1 = 0.0F;
+ for (int k1 = 0; k1 < i1; k1++) {
+ if (af[k1] > f1) {
+ f1 = af[k1];
+ }
+ }
- return k1;
- }
+ int l1 = process((int) f1) - 16;
+ short[] aword0 = new short[124];
+ if (l1 < 0) {
+ for (int i2 = 0; i2 < i1; i2++) {
+ aword0[i2] = (short) ((int) af[i2] >> -l1);
+ }
+ } else {
+ for (int j2 = 0; j2 < i1; j2++) {
+ aword0[j2] = (short) ((int) af[j2] << l1);
+ }
- private static void processIt( float[] af, int i1, int j1 ) {
+ }
- int k1 = 1;
- int l1 = 1;
- for ( int i2 = j1 << 1; l1 < i2; l1 += 2 ) {
- if ( l1 < k1 ) {
- float f1 = af[ i1 + l1 ];
- af[ i1 + l1 ] = af[ i1 + k1 ];
- af[ i1 + k1 ] = f1;
- float f2 = af[ ( i1 + l1 ) - 1 ];
- af[ ( i1 + l1 ) - 1 ] = af[ ( i1 + k1 ) - 1 ];
- af[ ( i1 + k1 ) - 1 ] = f2;
- }
- int j2;
- for ( j2 = j1; j2 > 1 && j2 < k1; j2 >>= 1 ) {
- k1 -= j2;
- }
+ SetupTable setupTable = new SetupTable(i1);
- k1 += j2;
- }
+ for (int k2 = 0; k2 < i1; k2++) {
+ aword0[k2] = (short) (aword0[k2] * 3 >> 2);
+ }
- }
+ int l2 = 0;
+ for (int i3 = 0; i3 < i1; i3++) {
+ l2 += aword0[i3];
+ }
+ l1 += 11;
+ l2 -= j1 << l1;
+ int j3 = 0;
+ int k3 = l2 - (j1 << l1);
+ j3 = (k3 >> 16) * setupTable.parameterA >> 15;
+ int l3 = 31 - setupTable.parameterB - process(k3);
+ if (l3 >= 0) {
+ j3 <<= l3;
+ } else {
+ j3 >>= -l3;
+ }
+ k3 = process(aword0, l1, i1, 6, j3);
+ if (k3 != j1) {
+ int i4 = k3 - j1;
+ int l4 = 0;
+ if (i4 <= 0) {
+ for (; i4 >= -16384; i4 <<= 1) {
+ l4++;
+ }
+ } else {
+ for (; i4 < 16384; i4 <<= 1) {
+ l4++;
+ }
+ }
- private static int processIt( float f1, double[] af, int i1, int j1 ) {
+ int k5 = i4 * setupTable.parameterA >> 15;
+ l4 = l1 - ((setupTable.parameterB + l4) - 15);
+ if (l4 >= 0) {
+ k5 <<= l4;
+ } else {
+ k5 >>= -l4;
+ }
+ int l5 = 1;
+ int i6;
+ int j6;
+ do {
+ i6 = k3;
+ j6 = j3;
+ j3 += k5;
+ k3 = process(aword0, l1, i1, 6, j3);
+ } while (++l5 <= 19 && (k3 - j1) * (i6 - j1) > 0);
+ if (k3 != j1) {
+ int k6;
+ int l6;
+ int i7;
+ if (k3 > j1) {
+ k6 = j3;
+ j3 = j6;
+ l6 = k3;
+ i7 = i6;
+ } else {
+ k6 = j6;
+ l6 = i6;
+ i7 = k3;
+ }
+ while (k3 != j1 && l5 < 20) {
+ int j7 = j3 + k6 >> 1;
+ k3 = process(aword0, l1, i1, 6, j7);
+ l5++;
+ if (k3 > j1) {
+ k6 = j7;
+ l6 = k3;
+ } else {
+ j3 = j7;
***The diff for this file has been truncated for email.***
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/CodecImpl.java Thu Feb
14 09:33:19 2013
+++ /branches/red5sip/src/java/org/red5/codecs/asao/CodecImpl.java Thu Feb
21 09:21:48 2013
@@ -22,993 +22,871 @@
public class CodecImpl {
- private static class BitStream {
+ private static class BitStream {
- private int byteOffset = 0;
- private int bitOffset = 0;
+ private int byteOffset = 0;
+ private int bitOffset = 0;
- public void push(int val, int len, byte[] buf) {
+ public void push(int val, int len, byte[] buf) {
- if (bitOffset == 0) {
- buf[byteOffset] = (byte)val;
- } else {
- buf[byteOffset] |= (byte)(val << bitOffset);
- }
- bitOffset += len;
- if (bitOffset >= 8) {
- ++byteOffset;
- bitOffset -= 8;
- if (bitOffset > 0) {
- buf[byteOffset] = (byte)(val >> (len - bitOffset));
- }
- }
- }
+ if (bitOffset == 0) {
+ buf[byteOffset] = (byte) val;
+ } else {
+ buf[byteOffset] |= (byte) (val << bitOffset);
+ }
+ bitOffset += len;
+ if (bitOffset >= 8) {
+ ++byteOffset;
+ bitOffset -= 8;
+ if (bitOffset > 0) {
+ buf[byteOffset] = (byte) (val >> (len - bitOffset));
+ }
+ }
+ }
- public int pop(int len, byte[] buf) {
+ public int pop(int len, byte[] buf) {
- int val = ((int)buf[byteOffset] & 0xff) >> bitOffset;
- final int bits_read = 8 - bitOffset;
+ int val = ((int) buf[byteOffset] & 0xff) >> bitOffset;
+ final int bits_read = 8 - bitOffset;
- if (len >= bits_read) {
- ++byteOffset;
- if (len > bits_read) {
- val |= buf[byteOffset] << bits_read;
- }
- }
+ if (len >= bits_read) {
+ ++byteOffset;
+ if (len > bits_read) {
+ val |= buf[byteOffset] << bits_read;
+ }
+ }
- bitOffset = (bitOffset + len) & 7;
- return val & ((1 << len) - 1);
- }
- }
+ bitOffset = (bitOffset + len) & 7;
+ return val & ((1 << len) - 1);
+ }
+ }
- private static class NormalizedInt32 {
- public final int scale;
+ private static class NormalizedInt32 {
+ public final int scale;
- public NormalizedInt32(final int val) {
- if (val == 0) {
- scale = 31;
- return;
- } else if (val >= (1 << 30)) {
- scale = 0;
- return;
- }
+ public NormalizedInt32(final int val) {
+ if (val == 0) {
+ scale = 31;
+ return;
+ } else if (val >= (1 << 30)) {
+ scale = 0;
+ return;
+ }
- int v = val;
- int s = 0;
+ int v = val;
+ int s = 0;
- if (v > 0) {
- do {
- v <<= 1;
- ++s;
- } while (v < (1 << 30));
- } else {
- final int floor = 1 << 31; // lowest possible 32bit value
- do {
- v <<= 1;
- ++s;
- } while (v > floor + (1 << 30));
- }
+ if (v > 0) {
+ do {
+ v <<= 1;
+ ++s;
+ } while (v < (1 << 30));
+ } else {
+ final int floor = 1 << 31; // lowest possible 32bit value
+ do {
+ v <<= 1;
+ ++s;
+ } while (v > floor + (1 << 30));
+ }
- scale = s;
- }
- }
+ scale = s;
+ }
+ }
- private static class Factor {
+ private static class Factor {
- public final int value;
- public final int shift;
+ public final int value;
+ public final int shift;
- public Factor(final int val) {
- if (val == 124) {
- // Common case optimization.
- value = 4228;
- shift = 19;
- return;
- } else if (val == 0) {
- value = 0;
- shift = 0;
- return;
- }
+ public Factor(final int val) {
+ if (val == 124) {
+ // Common case optimization.
+ value = 4228;
+ shift = 19;
+ return;
+ } else if (val == 0) {
+ value = 0;
+ shift = 0;
+ return;
+ }
- final int sign = ((~val >>> 31) << 1) - 1;
+ final int sign = ((~val >>> 31) << 1) - 1;
- int abs = val * sign;
+ int abs = val * sign;
- int scale = -1;
- while ((abs & (1 << 15)) == 0) {
- abs <<= 1;
- ++scale;
- }
- abs >>= 1;
+ int scale = -1;
+ while ((abs & (1 << 15)) == 0) {
+ abs <<= 1;
+ ++scale;
+ }
+ abs >>= 1;
- shift = 27 - scale;
+ shift = 27 - scale;
- final int table_val = table9[(abs - 0x3e00) >> 10];
- int tmp = abs * table_val;
- tmp = (1 << 30) - tmp;
- tmp += (1 << 14);
- tmp >>= 15;
- tmp *= table_val;
- tmp += (1 << 14);
- tmp >>= 15;
- final int tmp2 = tmp;
- tmp *= abs;
- tmp = (1 << 29) - tmp;
- tmp += (1 << 14);
- tmp >>= 15;
- tmp *= tmp2;
- tmp += (1 << 13);
- tmp >>= 14;
- tmp *= sign;
+ final int table_val = table9[(abs - 0x3e00) >> 10];
+ int tmp = abs * table_val;
+ tmp = (1 << 30) - tmp;
+ tmp += (1 << 14);
+ tmp >>= 15;
+ tmp *= table_val;
+ tmp += (1 << 14);
+ tmp >>= 15;
+ final int tmp2 = tmp;
+ tmp *= abs;
+ tmp = (1 << 29) - tmp;
+ tmp += (1 << 14);
+ tmp >>= 15;
+ tmp *= tmp2;
+ tmp += (1 << 13);
+ tmp >>= 14;
+ tmp *= sign;
- if (tmp > 32767 && sign == 1) {
- tmp = 32767;
- } else if (tmp < -32768 && sign == -1) {
- tmp = -32768;
- }
+ if (tmp > 32767 && sign == 1) {
+ tmp = 32767;
+ } else if (tmp < -32768 && sign == -1) {
+ tmp = -32768;
+ }
- value = tmp;
- }
- }
+ value = tmp;
+ }
+ }
- public static float[] encode(float[] state, float[] in, byte[] out) {
+ public static float[] encode(float[] state, float[] in, byte[] out) {
- float var_8d8[] = new float[256];
- float var_2e8[] = new float[23];
- float var_268[] = new float[23];
- float var_4d8[] = new float[124];
- float var_208[] = new float[124];
+ float var_8d8[] = new float[256];
+ float var_2e8[] = new float[23];
+ float var_268[] = new float[23];
+ float var_4d8[] = new float[124];
+ float var_208[] = new float[124];
- final BitStream bs = new BitStream();
+ final BitStream bs = new BitStream();
- fTransfm(state, in, 0, 7, var_8d8, 0);
- fTransfm(state, in, 128, 7, var_8d8, 128);
+ fTransfm(state, in, 0, 7, var_8d8, 0);
+ fTransfm(state, in, 128, 7, var_8d8, 128);
- for (int i = 0; i < 23; ++i) {
- int bound = bandBound[i];
- final int next_bound = bandBound[i + 1];
- double acc = 0.0;
- for (; bound < next_bound; ++bound) {
- final double a = var_8d8[bound];
- final double b = var_8d8[bound + 128];
- acc += a*a + b*b;
- }
- final double tmp = Math.max(1.0, acc / (table0[i] << 1));
- var_2e8[i] = Math.round(Math.log(tmp) * (1.44269502 * 1024.0));
- };
+ for (int i = 0; i < 23; ++i) {
+ int bound = bandBound[i];
+ final int next_bound = bandBound[i + 1];
+ double acc = 0.0;
+ for (; bound < next_bound; ++bound) {
+ final double a = var_8d8[bound];
+ final double b = var_8d8[bound + 128];
+ acc += a * a + b * b;
+ }
+ final double tmp = Math.max(1.0, acc / (table0[i] << 1));
+ var_2e8[i] = Math.round(Math.log(tmp) * (1.44269502 * 1024.0));
+ }
+ ;
- int idx = findClosest(var_2e8[0], table1, 0, 64);
- var_268[0] = table1[idx];
- bs.push(idx, gainBit[0], out);
- for (int i = 1; i < 23; ++i) {
- idx = findClosest(var_2e8[i] - var_268[i - 1], table2, 0, 32);
- var_268[i] = var_268[i - 1] + table2[idx];
- bs.push(idx, gainBit[i], out);
- }
+ int idx = findClosest(var_2e8[0], table1, 0, 64);
+ var_268[0] = table1[idx];
+ bs.push(idx, gainBit[0], out);
+ for (int i = 1; i < 23; ++i) {
+ idx = findClosest(var_2e8[i] - var_268[i - 1], table2, 0, 32);
+ var_268[i] = var_268[i - 1] + table2[idx];
+ bs.push(idx, gainBit[i], out);
+ }
- for (int i = 0; i < 23; ++i) {
- var_2e8[i] = (float)(1.0 / Math.pow(2.0, var_268[i] * (0.5 *
0.0009765625)));
- }
+ for (int i = 0; i < 23; ++i) {
+ var_2e8[i] = (float) (1.0 / Math.pow(2.0, var_268[i] * (0.5 *
0.0009765625)));
+ }
- for (int i = 0; i < 23; ++i) {
- int bound = bandBound[i];
- final int next_bound = bandBound[i + 1];
- for (; bound < next_bound; ++bound) {
- var_4d8[bound] = var_268[i];
- var_208[bound] = var_2e8[i];
- }
- }
+ for (int i = 0; i < 23; ++i) {
+ int bound = bandBound[i];
+ final int next_bound = bandBound[i + 1];
+ for (; bound < next_bound; ++bound) {
+ var_4d8[bound] = var_268[i];
+ var_208[bound] = var_2e8[i];
+ }
+ }
- int packed_byte_sizes[] = new int[124];
- final int leftover = wc(var_4d8, 124, 198, packed_byte_sizes);
- for (int off = 0; off < 256; off += 128) {
- for (int i = 0; i < 124; ++i) {
- final int packedSize = packed_byte_sizes[i];
- if (packedSize > 0) {
- final int pow2 = 1 << packedSize;
- idx = findClosestOrdered(
- var_208[i] * var_8d8[off + i],
- table3, pow2 - 1, (pow2 << 1) - 1
- );
- bs.push(idx, packedSize, out);
- }
- }
- for (int i = leftover; i > 0; i -= 8) {
- if (i > 8) {
- bs.push(0, 8, out);
- } else {
- bs.push(0, i, out);
- break;
- }
- }
- }
+ int packed_byte_sizes[] = new int[124];
+ final int leftover = wc(var_4d8, 124, 198, packed_byte_sizes);
+ for (int off = 0; off < 256; off += 128) {
+ for (int i = 0; i < 124; ++i) {
+ final int packedSize = packed_byte_sizes[i];
+ if (packedSize > 0) {
+ final int pow2 = 1 << packedSize;
+ idx = findClosestOrdered(var_208[i] * var_8d8[off + i], table3, pow2
- 1, (pow2 << 1) - 1);
+ bs.push(idx, packedSize, out);
+ }
+ }
+ for (int i = leftover; i > 0; i -= 8) {
+ if (i > 8) {
+ bs.push(0, 8, out);
+ } else {
+ bs.push(0, i, out);
+ break;
+ }
+ }
+ }
- return state;
- }
+ return state;
+ }
- public static float[] decode(float[] state, byte[] in, float[] out) {
+ public static float[] decode(float[] state, byte[] in, float[] out) {
- byte[] unpacked_input = new byte[124];
- float[] var_808 = new float[128];
- float[] var_608 = new float[124];
- float[] var_418 = new float[124];
+ byte[] unpacked_input = new byte[124];
+ float[] var_808 = new float[128];
+ float[] var_608 = new float[124];
+ float[] var_418 = new float[124];
- BitStream bs = new BitStream();
+ BitStream bs = new BitStream();
- int unpacked_byte = bs.pop(gainBit[0], in);
- unpacked_input[0] = (byte)unpacked_byte;
- var_808[0] = table1[unpacked_byte];
+ int unpacked_byte = bs.pop(gainBit[0], in);
+ unpacked_input[0] = (byte) unpacked_byte;
+ var_808[0] = table1[unpacked_byte];
- for (int i = 1; i < 23; ++i) {
- unpacked_byte = bs.pop(gainBit[i], in);
- unpacked_input[i] = (byte)unpacked_byte;
- var_808[i] = var_808[i - 1] + table2[unpacked_byte];
- };
+ for (int i = 1; i < 23; ++i) {
+ unpacked_byte = bs.pop(gainBit[i], in);
+ unpacked_input[i] = (byte) unpacked_byte;
+ var_808[i] = var_808[i - 1] + table2[unpacked_byte];
+ }
+ ;
- for (int i = 0; i < 23; ++i) {
- final float pow = (float)Math.pow(
- 2.0, var_808[i] * (0.5 * 0.0009765625)
- );
+ for (int i = 0; i < 23; ++i) {
+ final float pow = (float) Math.pow(2.0, var_808[i] * (0.5 *
0.0009765625));
- int bound = bandBound[i];
- final int next_bound = bandBound[i + 1];
- for (; bound < next_bound; ++bound) {
- var_418[bound] = var_808[i];
- var_608[bound] = pow;
- }
- }
+ int bound = bandBound[i];
+ final int next_bound = bandBound[i + 1];
+ for (; bound < next_bound; ++bound) {
+ var_418[bound] = var_808[i];
+ var_608[bound] = pow;
+ }
+ }
- int packed_byte_sizes[] = new int[124];
- final int leftover = wc(var_418, 124, 198, packed_byte_sizes);
+ int packed_byte_sizes[] = new int[124];
+ final int leftover = wc(var_418, 124, 198, packed_byte_sizes);
- for (int out_off = 0; out_off < 256; out_off += 128) {
- for (int i = 0; i < 124; ++i) {
- final int packed_size = packed_byte_sizes[i];
- float val = var_608[i];
- if (packed_size > 0) {
- final int pow2 = 1 << packed_size;
- unpacked_byte = bs.pop(packed_size, in);
- unpacked_input[i] = (byte)unpacked_byte;
- val *= table3[pow2 - 1 + unpacked_byte];
- } else {
- final double rnd_u32 = Math.random() * 4294967296.0;
- if (rnd_u32 < (1<<30) + (1<<14)) {
- val *= -0.707099974;
- } else {
- val *= 0.707099974;
- }
- }
- var_808[i] = val;
- }
+ for (int out_off = 0; out_off < 256; out_off += 128) {
+ for (int i = 0; i < 124; ++i) {
+ final int packed_size = packed_byte_sizes[i];
+ float val = var_608[i];
+ if (packed_size > 0) {
+ final int pow2 = 1 << packed_size;
+ unpacked_byte = bs.pop(packed_size, in);
+ unpacked_input[i] = (byte) unpacked_byte;
+ val *= table3[pow2 - 1 + unpacked_byte];
+ } else {
+ final double rnd_u32 = Math.random() * 4294967296.0;
+ if (rnd_u32 < (1 << 30) + (1 << 14)) {
+ val *= -0.707099974;
+ } else {
+ val *= 0.707099974;
+ }
+ }
+ var_808[i] = val;
+ }
- for (int i = 124; i < 128; ++i) {
- var_808[i] = 0;
- }
+ for (int i = 124; i < 128; ++i) {
+ var_808[i] = 0;
+ }
- for (int i = leftover; i > 0; i -= 8) {
- if (i > 8) {
- bs.pop(8, in);
- } else {
- bs.pop(i, in);
- break;
- }
- }
+ for (int i = leftover; i > 0; i -= 8) {
+ if (i > 8) {
+ bs.pop(8, in);
+ } else {
+ bs.pop(i, in);
+ break;
+ }
+ }
- iTransfm(state, var_808, 7, out, out_off);
- }
+ iTransfm(state, var_808, 7, out, out_off);
+ }
- return state;
- }
+ return state;
+ }
- private static void iTransfm(float[] state, float[] in,
- int len_log2, float[] out, int out_off) {
+ private static void iTransfm(float[] state, float[] in, int len_log2,
float[] out, int out_off) {
- final int len = 1 << len_log2;
- final int quarter_len = len >> 2;
- int y = len - 1;
- int x = len >> 1;
- int j = x - 1;
- int i = 0;
+ final int len = 1 << len_log2;
+ final int quarter_len = len >> 2;
+ int y = len - 1;
+ int x = len >> 1;
+ int j = x - 1;
+ int i = 0;
- /*
- i--> <--j
- ----------------------------
- x--> <--y
+ /*
+ * i--> <--j ---------------------------- x--> <--y
+ *
+ * i, j, x, y are indexes into table7. table7 is defined as follows: for
(int i = 0; i < 128; ++i) { table7[i] =
+ * Math.sin((i + 0.5) / 128 * (Math.PI / 2)); }
+ */
- i, j, x, y are indexes into table7.
- table7 is defined as follows:
- for (int i = 0; i < 128; ++i) {
- table7[i] = Math.sin((i + 0.5) / 128 * (Math.PI / 2));
- }
- */
+ auxceps(in, 0, len_log2, out, out_off);
- auxceps(in, 0, len_log2, out, out_off);
+ for (; i < quarter_len; ++i, --j, ++x, --y) {
+ final double state_i = state[i];
+ final double state_j = state[j];
+ final double out_x = out[out_off + x];
+ final double out_y = out[out_off + y];
- for (; i < quarter_len; ++i, --j, ++x, --y) {
- final double state_i = state[i];
- final double state_j = state[j];
- final double out_x = out[out_off + x];
- final double out_y = out[out_off + y];
+ state[i] = -out[out_off + j];
+ state[j] = -out[out_off + i];
- state[i] = -out[out_off + j];
- state[j] = -out[out_off + i];
+ out[out_off + i] = (float) (state_i * table7[y] + out_x * table7[i]);
+ out[out_off + j] = (float) (state_j * table7[x] + out_y * table7[j]);
- out[out_off + i] = (float)(state_i * table7[y] + out_x *
table7[i]);
- out[out_off + j] = (float)(state_j * table7[x] + out_y *
table7[j]);
+ out[out_off + x] = (float) (table7[x] * -out_y + table7[j] * state_j);
+ out[out_off + y] = (float) (table7[y] * -out_x + table7[i] * state_i);
+ }
+ }
- out[out_off + x] = (float)(table7[x] * -out_y + table7[j] *
state_j);
- out[out_off + y] = (float)(table7[y] * -out_x + table7[i] *
state_i);
- }
- }
+ private static void fTransfm(float[] state, float[] in, int in_off, int
len_log2, float[] out, int out_off) {
- private static void fTransfm(float[] state, float[] in, int in_off,
- int len_log2, float[] out, int out_off) {
+ final int len = 1 << len_log2;
+ final int quarter_len = len >> 2;
+ int y = len - 1;
+ int x = len >> 1;
+ int j = x - 1;
+ int i = 0;
- final int len = 1 << len_log2;
- final int quarter_len = len >> 2;
- int y = len - 1;
- int x = len >> 1;
- int j = x - 1;
- int i = 0;
+ /*
+ * i--> <--j ---------------------------- x--> <--y
+ *
+ * i, j, x, y are indexes into table7. table7 is defined as follows: for
(int i = 0; i < 128; ++i) { table7[i] =
+ * Math.sin((i + 0.5) / 128 * (Math.PI / 2)); }
+ */
- /*
- i--> <--j
- ----------------------------
- x--> <--y
+ for (; i < quarter_len; ++i, ++x, --y, --j) {
+ out[out_off + x] = state[i];
+ out[out_off + y] = state[j];
- i, j, x, y are indexes into table7.
- table7 is defined as follows:
- for (int i = 0; i < 128; ++i) {
- table7[i] = Math.sin((i + 0.5) / 128 * (Math.PI / 2));
- }
- */
+ out[out_off + i] = -in[in_off + j] * table7[x] - in[in_off + x] *
table7[j];
+ out[out_off + j] = -in[in_off + y] * table7[i] - in[in_off + i] *
table7[y];
- for (; i < quarter_len; ++i, ++x, --y, --j) {
- out[out_off + x] = state[i];
- out[out_off + y] = state[j];
+ state[i] = in[in_off + i] * table7[i] - in[in_off + y] * table7[y];
+ state[j] = in[in_off + j] * table7[j] - in[in_off + x] * table7[x];
+ }
- out[out_off + i] = -in[in_off + j] * table7[x] - in[in_off +
x] * table7[j];
- out[out_off + j] = -in[in_off + y] * table7[i] - in[in_off +
i] * table7[y];
+ auxceps(out, out_off, len_log2, out, out_off);
+ }
- state[i] = in[in_off + i] * table7[i] - in[in_off + y] *
table7[y];
- state[j] = in[in_off + j] * table7[j] - in[in_off + x] *
table7[x];
- }
+ private static void auxceps(float[] in, final int in_off, int len_log2,
float[] out, final int out_off) {
- auxceps(out, out_off, len_log2, out, out_off);
- }
+ final int len = 1 << len_log2;
+ final int half_len_m1 = (len >> 1) - 1;
+ final int quarter_len = len >> 2;
- private static void auxceps(
- float[] in, final int in_off, int len_log2, float[] out, final
int out_off) {
+ for (int i = 0; i < quarter_len; ++i) {
+ final int i2 = i << 1;
+ final int j = len - 1 - i2;
+ final int k = j - 1;
- final int len = 1 << len_log2;
- final int half_len_m1 = (len >> 1) - 1;
- final int quarter_len = len >> 2;
+ final double in_i2 = in[in_off + i2];
+ final double in_i2_1 = in[in_off + i2 + 1];
+ final double in_j = in[in_off + j];
+ final double in_k = in[in_off + k];
- for (int i = 0; i < quarter_len; ++i) {
- final int i2 = i << 1;
- final int j = len - 1 - i2;
- final int k = j - 1;
+ out[out_off + i2] = (float) (table4[i] * in_i2 - table6[i] * in_j);
+ out[out_off + i2 + 1] = (float) (in_j * table4[i] + in_i2 * table6[i]);
- final double in_i2 = in[in_off + i2];
- final double in_i2_1 = in[in_off + i2 + 1];
- final double in_j = in[in_off + j];
- final double in_k = in[in_off + k];
+ out[out_off + k] = (float) (table4[half_len_m1 - i] * in_k -
table6[half_len_m1 - i] * in_i2_1);
+ out[out_off + j] = (float) (in_i2_1 * table4[half_len_m1 - i] + in_k *
table6[half_len_m1 - i]);
+ }
- out[out_off + i2] = (float)(table4[i] * in_i2 - table6[i] *
in_j);
- out[out_off + i2 + 1] = (float)(in_j * table4[i] + in_i2 *
table6[i]);
+ HarXfm(out, out_off, len_log2 - 1);
- out[out_off + k] = (float)(table4[half_len_m1 - i] * in_k -
table6[half_len_m1 - i] * in_i2_1);
- out[out_off + j] = (float)(in_i2_1 * table4[half_len_m1 - i] +
in_k * table6[half_len_m1 - i]);
- }
+ final float last_out = out[out_off + len - 1];
+ final float pre_last_out = out[out_off + len - 2];
- HarXfm(out, out_off, len_log2 - 1);
+ out[out_off] = table5[0] * out[out_off];
+ out[out_off + len - 1] = out[out_off + 1] * -table5[0];
- final float last_out = out[out_off + len - 1];
- final float pre_last_out = out[out_off + len - 2];
+ out[out_off + len - 2] = table5[half_len_m1] * out[out_off + len - 2] +
table5[1] * last_out;
+ out[out_off + 1] = pre_last_out * table5[1] - last_out *
table5[half_len_m1];
- out[out_off] = table5[0] * out[out_off];
- out[out_off + len - 1] = out[out_off + 1] * -table5[0];
+ int i_out = len - 3;
+ int i_tbl = half_len_m1;
+ int j = 3;
+ for (int i = 1; i < quarter_len; ++i, --i_tbl, i_out -= 2, j += 2) {
+ final double old_out_a = out[out_off + i_out];
+ final double old_out_b = out[out_off + i_out - 1];
+ final double old_out_c = out[out_off + j];
+ final double old_out_d = out[out_off + j - 1];
- out[out_off + len - 2] = table5[half_len_m1] * out[out_off + len -
2] + table5[1] * last_out;
- out[out_off + 1] = pre_last_out * table5[1] - last_out *
table5[half_len_m1];
+ out[out_off + j - 1] = (float) (table5[i_tbl] * old_out_c + table5[(j -
1) >> 1] * old_out_d);
+ out[out_off + j] = (float) (old_out_b * table5[(j + 1) >> 1] -
old_out_a * table5[i_tbl - 1]);
+ out[out_off + i_out] = (float) (old_out_d * table5[i_tbl] - old_out_c *
table5[(j - 1) >> 1]);
+ out[out_off + i_out - 1] = (float) (table5[(j + 1) >> 1] * old_out_a +
table5[i_tbl - 1] * old_out_b);
+ }
+ }
- int i_out = len - 3;
- int i_tbl = half_len_m1;
- int j = 3;
- for (int i = 1; i < quarter_len; ++i, --i_tbl, i_out -= 2, j += 2)
{
- final double old_out_a = out[out_off + i_out];
- final double old_out_b = out[out_off + i_out - 1];
- final double old_out_c = out[out_off + j];
- final double old_out_d = out[out_off + j - 1];
+ private static void HarXfm(float[] data, int data_off, int half_len_log2)
{
- out[out_off + j - 1] = (float)(table5[i_tbl] * old_out_c +
table5[(j - 1) >> 1] * old_out_d);
- out[out_off + j] = (float)(old_out_b * table5[(j + 1) >> 1] -
old_out_a * table5[i_tbl - 1]);
- out[out_off + i_out] = (float)(old_out_d * table5[i_tbl] -
old_out_c * table5[(j - 1) >> 1]);
- out[out_off + i_out - 1] = (float)(table5[(j + 1) >> 1] *
old_out_a + table5[i_tbl - 1] * old_out_b);
- }
- }
+ final int half_len = 1 << half_len_log2;
- private static void HarXfm(float[] data, int data_off, int
half_len_log2) {
+ HarXfmHelper(data, data_off, half_len);
- final int half_len = 1 << half_len_log2;
+ int j = 0;
+ for (int i = half_len >> 1; i > 0; --i, j += 4) {
+ final float j0 = data[data_off + j];
+ final float j1 = data[data_off + j + 1];
+ final float j2 = data[data_off + j + 2];
+ final float j3 = data[data_off + j + 3];
+ data[data_off + j] = j0 + j2;
+ data[data_off + j + 1] = j1 + j3;
+ data[data_off + j + 2] = j0 - j2;
+ data[data_off + j + 3] = j1 - j3;
+ }
- HarXfmHelper(data, data_off, half_len);
+ j = 0;
+ for (int i = half_len >> 2; i > 0; --i, j += 8) {
+ final float j0 = data[data_off + j];
+ final float j1 = data[data_off + j + 1];
+ final float j2 = data[data_off + j + 2];
+ final float j3 = data[data_off + j + 3];
+ final float j4 = data[data_off + j + 4];
+ final float j5 = data[data_off + j + 5];
+ final float j6 = data[data_off + j + 6];
+ final float j7 = data[data_off + j + 7];
+ data[data_off + j] = j0 + j4;
+ data[data_off + j + 1] = j1 + j5;
+ data[data_off + j + 2] = j2 + j7;
+ data[data_off + j + 3] = j3 - j6;
+ data[data_off + j + 4] = j0 - j4;
+ data[data_off + j + 5] = j1 - j5;
+ data[data_off + j + 6] = j2 - j7;
+ data[data_off + j + 7] = j3 + j6;
+ }
- int j = 0;
- for (int i = half_len >> 1; i > 0; --i, j += 4) {
- final float j0 = data[data_off + j];
- final float j1 = data[data_off + j + 1];
- final float j2 = data[data_off + j + 2];
- final float j3 = data[data_off + j + 3];
- data[data_off + j] = j0 + j2;
- data[data_off + j + 1] = j1 + j3;
- data[data_off + j + 2] = j0 - j2;
- data[data_off + j + 3] = j1 - j3;
- }
+ int i = 0;
+ int x = half_len >> 3;
+ int y = 64;
+ int z = 4;
+ for (int idx1 = half_len_log2 - 2; idx1 > 0; --idx1, z <<= 1, y >>= 1, x
>>= 1) {
+ j = 0;
+ for (int idx2 = x; idx2 != 0; --idx2, j += z << 1) {
+ for (int idx3 = z >> 1; idx3 > 0; --idx3, j += 2, i += y) {
+ final int k = j + (z << 1);
- j = 0;
- for (int i = half_len >> 2; i > 0; --i, j += 8) {
- final float j0 = data[data_off + j];
- final float j1 = data[data_off + j + 1];
- final float j2 = data[data_off + j + 2];
- final float j3 = data[data_off + j + 3];
- final float j4 = data[data_off + j + 4];
- final float j5 = data[data_off + j + 5];
- final float j6 = data[data_off + j + 6];
- final float j7 = data[data_off + j + 7];
- data[data_off + j] = j0 + j4;
- data[data_off + j + 1] = j1 + j5;
- data[data_off + j + 2] = j2 + j7;
- data[data_off + j + 3] = j3 - j6;
- data[data_off + j + 4] = j0 - j4;
- data[data_off + j + 5] = j1 - j5;
- data[data_off + j + 6] = j2 - j7;
- data[data_off + j + 7] = j3 + j6;
- }
+ final double j0 = data[data_off + j];
+ final double j1 = data[data_off + j + 1];
+ final double k0 = data[data_off + k];
+ final double k1 = data[data_off + k + 1];
- int i = 0;
- int x = half_len >> 3;
- int y = 64;
- int z = 4;
- for (int idx1 = half_len_log2 - 2; idx1 > 0; --idx1, z <<= 1, y
>>= 1, x >>= 1) {
- j = 0;
- for (int idx2 = x; idx2 != 0; --idx2, j += z << 1) {
- for (int idx3 = z >> 1; idx3 > 0; --idx3, j += 2, i += y) {
- final int k = j + (z << 1);
+ data[data_off + k] = (float) (j0 - (k0 * table10[128 - i] + k1 *
table10[i]));
+ data[data_off + j] = (float) (j0 + (k0 * table10[128 - i] + k1 *
table10[i]));
+ data[data_off + k + 1] = (float) (j1 + (k0 * table10[i] - k1 *
table10[128 - i]));
+ data[data_off + j + 1] = (float) (j1 - (k0 * table10[i] - k1 *
table10[128 - i]));
+ }
+ for (int idx4 = z >> 1; idx4 > 0; --idx4, j += 2, i -= y) {
+ final int k = j + (z << 1);
- final double j0 = data[data_off + j];
- final double j1 = data[data_off + j + 1];
- final double k0 = data[data_off + k];
- final double k1 = data[data_off + k + 1];
+ final double j0 = data[data_off + j];
+ final double j1 = data[data_off + j + 1];
+ final double k0 = data[data_off + k];
+ final double k1 = data[data_off + k + 1];
- data[data_off + k] = (float)(j0 - (k0 * table10[128 -
i] + k1 * table10[i]));
- data[data_off + j] = (float)(j0 + (k0 * table10[128 -
i] + k1 * table10[i]));
- data[data_off + k + 1] = (float)(j1 + (k0 * table10[i]
- k1 * table10[128 - i]));
- data[data_off + j + 1] = (float)(j1 - (k0 * table10[i]
- k1 * table10[128 - i]));
- }
- for (int idx4 = z >> 1; idx4 > 0; --idx4, j += 2, i -= y) {
- final int k = j + (z << 1);
+ data[data_off + k] = (float) (j0 + (k0 * table10[128 - i] - k1 *
table10[i]));
+ data[data_off + j] = (float) (j0 - (k0 * table10[128 - i] - k1 *
table10[i]));
+ data[data_off + k + 1] = (float) (j1 + (k1 * table10[128 - i] + k0 *
table10[i]));
+ data[data_off + j + 1] = (float) (j1 - (k1 * table10[128 - i] + k0 *
table10[i]));
+ }
+ }
+ }
+ }
- final double j0 = data[data_off + j];
- final double j1 = data[data_off + j + 1];
- final double k0 = data[data_off + k];
- final double k1 = data[data_off + k + 1];
+ private static void HarXfmHelper(float[] data, int data_off, int
half_len) {
- data[data_off + k] = (float)(j0 + (k0 * table10[128 -
i] - k1 * table10[i]));
- data[data_off + j] = (float)(j0 - (k0 * table10[128 -
i] - k1 * table10[i]));
- data[data_off + k + 1] = (float)(j1 + (k1 *
table10[128 - i] + k0 * table10[i]));
- data[data_off + j + 1] = (float)(j1 - (k1 *
table10[128 - i] + k0 * table10[i]));
- }
- }
- }
- }
+ final int len = half_len << 1;
- private static void HarXfmHelper(float[] data, int data_off, int
half_len) {
+ int j = 1;
+ for (int i = 1; i < len; i += 2) {
+ if (i < j) {
+ final float tmp1 = data[data_off + i];
+ data[data_off + i] = data[data_off + j];
+ data[data_off + j] = tmp1;
- final int len = half_len << 1;
+ final float tmp2 = data[data_off + i - 1];
+ data[data_off + i - 1] = data[data_off + j - 1];
+ data[data_off + j - 1] = tmp2;
+ }
- int j = 1;
- for (int i = 1; i < len; i += 2) {
- if (i < j) {
- final float tmp1 = data[data_off + i];
- data[data_off + i] = data[data_off + j];
- data[data_off + j] = tmp1;
+ int x = half_len;
+ while (x > 1 && x < j) {
+ j -= x;
+ x >>= 1;
+ }
+ j += x;
+ }
+ }
- final float tmp2 = data[data_off + i - 1];
- data[data_off + i - 1] = data[data_off + j - 1];
- data[data_off + j - 1] = tmp2;
- }
+ private static int findClosest(float target, float[] values, int from,
int to) {
- int x = half_len;
- while (x > 1 && x < j) {
- j -= x;
- x >>= 1;
- }
- j += x;
- }
- }
+ int min_idx = 0;
+ float min_distance = Math.abs(target - values[from]);
- private static int findClosest(float target, float[] values, int from,
int to) {
+ for (int i = from; i < to; ++i) {
+ final float distance = Math.abs(target - values[i]);
+ if (distance < min_distance) {
+ min_distance = distance;
+ min_idx = i - from;
+ }
+ }
- int min_idx = 0;
- float min_distance = Math.abs(target - values[from]);
+ return min_idx;
+ }
- for (int i = from; i < to; ++i) {
- final float distance = Math.abs(target - values[i]);
- if (distance < min_distance) {
- min_distance = distance;
- min_idx = i - from;
- }
- }
+ private static int findClosestOrdered(float target, float[] values, int
from, int to) {
- return min_idx;
- }
+ int begin = from;
+ int end = to;
+ do {
+ final int middle = (begin + end) >> 1;
+ if (target > values[middle]) {
+ begin = middle;
+ } else {
+ end = middle;
+ }
+ } while (end - begin > 1);
- private static int findClosestOrdered(float target, float[] values,
int from, int to) {
+ if (end != to) {
+ if (target - values[begin] > values[end] - target) {
+ begin = end;
+ }
+ }
+ return begin - from;
+ }
- int begin = from;
- int end = to;
- do {
- final int middle = (begin + end) >> 1;
- if (target > values[middle]) {
- begin = middle;
- } else {
- end = middle;
- }
- } while (end - begin > 1);
+ static int wc(float[] in, int len, int total_bits, int[] packed_sizes) {
- if (end != to) {
- if (target - values[begin] > values[end] - target) {
- begin = end;
- }
- }
- return begin - from;
- }
+ float max_input = 0;
+ for (int i = 0; i < len; ++i) {
+ if (in[i] > max_input) {
+ max_input = in[i];
+ }
+ }
- static int wc(float[] in, int len, int total_bits, int[] packed_sizes)
{
+ int max_input_scale = 0;
+ {
+ NormalizedInt32 normalized = new NormalizedInt32((int) max_input);
+ max_input_scale = normalized.scale - 16;
+ }
- float max_input = 0;
- for (int i = 0; i < len; ++i) {
- if (in[i] > max_input) {
- max_input = in[i];
- }
- }
***The diff for this file has been truncated for email.***
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/Decoder.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/Decoder.java Thu Feb 21
09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,45 +32,34 @@
//------------------------------------------------------------------------
public final class Decoder {
- public Decoder() {
+ public Decoder() {
- }
+ }
+ public DecoderMap decode(DecoderMap d1, byte[] abyte0, int i, float[] af,
int j) {
- public DecoderMap decode( DecoderMap d1, byte[] abyte0, int i, float[]
af, int j ) {
+ if (d1 == null) {
+ d1 = new NellyDecoderMap(this);
+ }
- if ( d1 == null ) {
- d1 = new NellyDecoderMap( this );
- }
-
- NellyDecoderMap nellyDecoderMap = (NellyDecoderMap) d1;
-
- Codec.process(
- nellyDecoderMap.a,
- abyte0,
- i,
- af,
- j,
- nellyDecoderMap.c,
- nellyDecoderMap.d,
- nellyDecoderMap.e,
- nellyDecoderMap.f,
- nellyDecoderMap.g );
+ NellyDecoderMap nellyDecoderMap = (NellyDecoderMap) d1;
- return d1;
- }
+ Codec.process(nellyDecoderMap.a, abyte0, i, af, j, nellyDecoderMap.c,
nellyDecoderMap.d, nellyDecoderMap.e,
+ nellyDecoderMap.f, nellyDecoderMap.g);
+ return d1;
+ }
- public DecoderMap decode( DecoderMap d1, byte[] abyte0, int i, byte[]
abyte1, int j, boolean flag ) {
+ public DecoderMap decode(DecoderMap d1, byte[] abyte0, int i, byte[]
abyte1, int j, boolean flag) {
- if ( d1 == null ) {
- d1 = new NellyDecoderMap( this );
- }
+ if (d1 == null) {
+ d1 = new NellyDecoderMap(this);
+ }
- d1 = decode( d1, abyte0, i, ( (NellyDecoderMap) d1 ).b, 0 );
+ d1 = decode(d1, abyte0, i, ((NellyDecoderMap) d1).b, 0);
- Utility.float2byte( ( (NellyDecoderMap) d1 ).b, 0, 256, abyte1, j,
flag );
+ Utility.float2byte(((NellyDecoderMap) d1).b, 0, 256, abyte1, j, flag);
- return d1;
- }
+ return d1;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/DecoderMap.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/DecoderMap.java Thu Feb
21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/Encoder.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/Encoder.java Thu Feb 21
09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,43 +32,31 @@
//------------------------------------------------------------------------
public final class Encoder {
- public Encoder() {
+ public Encoder() {
- }
+ }
+ public EncoderMap encode(EncoderMap e1, float[] af, int j, byte[] abyte0,
int k) {
- public EncoderMap encode( EncoderMap e1, float[] af, int j, byte[]
abyte0, int k ) {
+ if (e1 == null) {
+ e1 = new NellyEncoderMap(this);
+ }
- if ( e1 == null ) {
- e1 = new NellyEncoderMap( this );
- }
+ NellyEncoderMap nellyEncoderMap = (NellyEncoderMap) e1;
+ Codec.process(nellyEncoderMap.a, af, j, abyte0, k, nellyEncoderMap.c,
nellyEncoderMap.d, nellyEncoderMap.e,
+ nellyEncoderMap.f, nellyEncoderMap.g, nellyEncoderMap.h);
- NellyEncoderMap nellyEncoderMap = (NellyEncoderMap) e1;
- Codec.process(
- nellyEncoderMap.a,
- af,
- j,
- abyte0,
- k,
- nellyEncoderMap.c,
- nellyEncoderMap.d,
- nellyEncoderMap.e,
- nellyEncoderMap.f,
- nellyEncoderMap.g,
- nellyEncoderMap.h );
-
- return e1;
- }
-
+ return e1;
+ }
- public EncoderMap encode( EncoderMap e1, byte[] abyte0, int j, boolean
flag, byte[] abyte1, int k ) {
+ public EncoderMap encode(EncoderMap e1, byte[] abyte0, int j, boolean
flag, byte[] abyte1, int k) {
- if ( e1 == null ) {
- e1 = new NellyEncoderMap( this );
- }
+ if (e1 == null) {
+ e1 = new NellyEncoderMap(this);
+ }
- Utility.byte2float( abyte0, j, 512, ( (NellyEncoderMap) e1 ).b, 0,
flag );
+ Utility.byte2float(abyte0, j, 512, ((NellyEncoderMap) e1).b, 0, flag);
- return encode( e1, ( (NellyEncoderMap) e1 ).b, 0, abyte1, k );
- }
+ return encode(e1, ((NellyEncoderMap) e1).b, 0, abyte1, k);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/EncoderMap.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/EncoderMap.java Thu Feb
21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/NellyDecoderMap.java
Fri Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/NellyDecoderMap.java
Thu Feb 21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,27 +32,26 @@
//------------------------------------------------------------------------
final class NellyDecoderMap implements DecoderMap {
- public final float[] a = new float[ 64 ];
+ public final float[] a = new float[64];
- public final float[] b = new float[ 256 ];
+ public final float[] b = new float[256];
- public final float[] c = new float[ 128 ];
+ public final float[] c = new float[128];
- public final float[] d = new float[ 124 ];
+ public final float[] d = new float[124];
- public final float[] e = new float[ 124 ];
+ public final float[] e = new float[124];
- public final byte[] f = new byte[ 124 ];
-
- public final int[] g = new int[ 124 ];
+ public final byte[] f = new byte[124];
- final Decoder decoder;
+ public final int[] g = new int[124];
+ final Decoder decoder;
- public NellyDecoderMap( Decoder decoder ) {
+ public NellyDecoderMap(Decoder decoder) {
- super();
- this.decoder = decoder;
- }
+ super();
+ this.decoder = decoder;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/NellyEncoderMap.java
Fri Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/NellyEncoderMap.java
Thu Feb 21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,29 +32,28 @@
//------------------------------------------------------------------------
final class NellyEncoderMap implements EncoderMap {
- public final float[] a = new float[ 64 ];
+ public final float[] a = new float[64];
- public final float[] b = new float[ 256 ];
+ public final float[] b = new float[256];
- public final float[] c = new float[ 256 ];
+ public final float[] c = new float[256];
- public final float[] d = new float[ 23 ];
+ public final float[] d = new float[23];
- public final float[] e = new float[ 23 ];
+ public final float[] e = new float[23];
- public final float[] f = new float[ 124 ];
-
- public final float[] g = new float[ 124 ];
+ public final float[] f = new float[124];
- public final int[] h = new int[ 124 ];
+ public final float[] g = new float[124];
- final Encoder encoder;
+ public final int[] h = new int[124];
+ final Encoder encoder;
- public NellyEncoderMap( Encoder encoder ) {
+ public NellyEncoderMap(Encoder encoder) {
- super();
- this.encoder = encoder;
- }
+ super();
+ this.encoder = encoder;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/SetupTable.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/SetupTable.java Thu Feb
21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,54 +32,52 @@
//------------------------------------------------------------------------
class SetupTable {
- public final int parameterA;
+ public final int parameterA;
- public final int parameterB;
+ public final int parameterB;
+ public SetupTable(int i) {
- public SetupTable( int i ) {
+ if (i == 124) {
+ parameterA = 4228;
+ parameterB = 19;
+ return;
+ }
- if ( i == 124 ) {
- parameterA = 4228;
- parameterB = 19;
- return;
- }
+ if (i == 0) {
+ parameterA = 0;
+ parameterB = 0;
+ return;
+ }
+ int j = ((~i >>> 31) << 1) - 1;
+ int k = i * j;
+ int l;
- if ( i == 0 ) {
- parameterA = 0;
- parameterB = 0;
- return;
- }
- int j = ( ( ~i >>> 31 ) << 1 ) - 1;
- int k = i * j;
- int l;
+ for (l = -1; (k & 0x8000) == 0; l++) {
+ k <<= 1;
+ }
- for ( l = -1; ( k & 0x8000 ) == 0; l++ ) {
- k <<= 1;
- }
-
- k >>= 1;
- parameterB = 27 - l;
- short word0 = Codec.f()[ k - 15872 >> 10 ];
- int i1 = k * word0;
- i1 = 0x40000000 - i1;
- i1 = ( i1 += 16384 ) >> 15;
- i1 *= word0;
- i1 = ( i1 += 16384 ) >> 15;
- int j1 = i1;
- i1 *= k;
- i1 = 0x20000000 - i1;
- i1 = ( i1 += 16384 ) >> 15;
- i1 *= j1;
- i1 = ( i1 += 8192 ) >> 14;
- i1 *= j;
+ k >>= 1;
+ parameterB = 27 - l;
+ short word0 = Codec.f()[k - 15872 >> 10];
+ int i1 = k * word0;
+ i1 = 0x40000000 - i1;
+ i1 = (i1 += 16384) >> 15;
+ i1 *= word0;
+ i1 = (i1 += 16384) >> 15;
+ int j1 = i1;
+ i1 *= k;
+ i1 = 0x20000000 - i1;
+ i1 = (i1 += 16384) >> 15;
+ i1 *= j1;
+ i1 = (i1 += 8192) >> 14;
+ i1 *= j;
- if ( i1 > 32767 && j == 1 ) {
- i1 = 32767;
- }
- else if ( i1 < -32768 && j == -1 ) {
- i1 = -32768;
- }
- parameterA = i1;
- }
+ if (i1 > 32767 && j == 1) {
+ i1 = 32767;
+ } else if (i1 < -32768 && j == -1) {
+ i1 = -32768;
+ }
+ parameterA = i1;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/StateTable.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/StateTable.java Thu Feb
21 09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,56 +32,52 @@
//------------------------------------------------------------------------
final class StateTable {
- private final byte[] a;
+ private final byte[] a;
- private final int b;
+ private final int b;
- private int c;
+ private int c;
- private int d;
+ private int d;
+ public StateTable(byte[] abyte0, int i) {
- public StateTable( byte[] abyte0, int i ) {
+ c = 0;
+ d = 0;
+ a = abyte0;
+ b = i;
+ }
- c = 0;
- d = 0;
- a = abyte0;
- b = i;
- }
+ public int state(int i) {
+ int k = 8 - d;
+ int l = (a[b + c] & 0xff) >> d;
+ if (i >= k) {
+ c++;
+ if (i > k) {
+ l |= a[b + c] << k;
+ }
+ }
+ d = d + i & 7;
+ return l & (1 << i) - 1;
+ }
- public int state( int i ) {
+ public void state(int i, int k) {
- int k = 8 - d;
- int l = ( a[ b + c ] & 0xff ) >> d;
- if ( i >= k ) {
- c++;
- if ( i > k ) {
- l |= a[ b + c ] << k;
- }
- }
- d = d + i & 7;
- return l & ( 1 << i ) - 1;
- }
-
-
- public void state( int i, int k ) {
-
- if ( d == 0 ) {
- a[ b + c ] = (byte) i;
- }
- else {
- a[ b + c ] |= (byte) ( i << d );
- }
- d += k;
- if ( d < 8 ) {
- return;
- }
- c++;
- d -= 8;
- if ( d > 0 ) {
- a[ b + c ] = (byte) ( i >> k - d );
- }
- }
+ if (d == 0) {
+ a[b + c] = (byte) i;
+ } else {
+ a[b + c] |= (byte) (i << d);
+ }
+ d += k;
+ if (d < 8) {
+ return;
+ }
+ c++;
+ d -= 8;
+ if (d > 0) {
+ a[b + c] = (byte) (i >> k - d);
+ }
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/asao/Utility.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/asao/Utility.java Thu Feb 21
09:21:48 2013
@@ -1,6 +1,5 @@
package org.red5.codecs.asao;
-
/*
* Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5,
* 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and
@@ -33,44 +32,41 @@
//------------------------------------------------------------------------
public final class Utility {
- public static final void byte2float( byte[] abyte0, int i, int j,
float[] af, int k, boolean flag ) {
+ public static final void byte2float(byte[] abyte0, int i, int j, float[]
af, int k, boolean flag) {
- if ( flag ) {
- int l = 0;
- for ( int j1 = j >> 1; l < j1; l++ ) {
- af[ k + l ] = ( abyte0[ i + l * 2 + 0 ] << 8 ) + ( abyte0[
i + l * 2 + 1 ] << 0 );
- }
+ if (flag) {
+ int l = 0;
+ for (int j1 = j >> 1; l < j1; l++) {
+ af[k + l] = (abyte0[i + l * 2 + 0] << 8) + (abyte0[i + l * 2 + 1] <<
0);
+ }
- }
- else {
- int i1 = 0;
- for ( int k1 = j >> 1; i1 < k1; i1++ ) {
- af[ k + i1 ] = ( abyte0[ i + i1 * 2 + 0 ] << 0 ) + (
abyte0[ i + i1 * 2 + 1 ] << 8 );
- }
+ } else {
+ int i1 = 0;
+ for (int k1 = j >> 1; i1 < k1; i1++) {
+ af[k + i1] = (abyte0[i + i1 * 2 + 0] << 0) + (abyte0[i + i1 * 2 + 1]
<< 8);
+ }
- }
- }
+ }
+ }
+ public static final void float2byte(float[] af, int i, int j, byte[]
abyte0, int k, boolean flag) {
- public static final void float2byte( float[] af, int i, int j, byte[]
abyte0, int k, boolean flag ) {
-
- if ( flag ) {
- int l = 0;
- for ( int j1 = j; l < j1; l++ ) {
- int l1 = (int) af[ i + l ];
- abyte0[ k + 2 * l ] = (byte) ( l1 >> 8 & 0xff );
- abyte0[ k + 2 * l + 1 ] = (byte) ( l1 >> 0 & 0xff );
- }
+ if (flag) {
+ int l = 0;
+ for (int j1 = j; l < j1; l++) {
+ int l1 = (int) af[i + l];
+ abyte0[k + 2 * l] = (byte) (l1 >> 8 & 0xff);
+ abyte0[k + 2 * l + 1] = (byte) (l1 >> 0 & 0xff);
+ }
- }
- else {
- int i1 = 0;
- for ( int k1 = j; i1 < k1; i1++ ) {
- int i2 = (int) af[ i + i1 ];
- abyte0[ k + 2 * i1 ] = (byte) ( i2 >> 0 & 0xff );
- abyte0[ k + 2 * i1 + 1 ] = (byte) ( i2 >> 8 & 0xff );
- }
+ } else {
+ int i1 = 0;
+ for (int k1 = j; i1 < k1; i1++) {
+ int i2 = (int) af[i + i1];
+ abyte0[k + 2 * i1] = (byte) (i2 >> 0 & 0xff);
+ abyte0[k + 2 * i1 + 1] = (byte) (i2 >> 8 & 0xff);
+ }
- }
- }
+ }
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/ArrayUtils.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/ArrayUtils.java Thu Feb
21 09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class ArrayUtils {
@@ -6,16 +7,16 @@
public static float[] subArray(float[] array, int start) {
int nl = array.length - start;
float[] ret = new float[nl];
- for(int q=start; q<array.length; q++) {
- ret[q-start] = array[q];
+ for (int q = start; q < array.length; q++) {
+ ret[q - start] = array[q];
}
return ret;
}
public static void replace(float[] array, int start, float[] tmp) {
-
- for(int q=start; q<array.length; q++) {
- array[q] = tmp[q-start];
+
+ for (int q = start; q < array.length; q++) {
+ array[q] = tmp[q - start];
}
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Bits.java Sun Feb 17
20:04:17 2013
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Bits.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class Bits {
@@ -26,70 +27,75 @@
* pitch and codebook gains 4+3 bit
*----------------------------------------------------------------------------
*/
-
- public static void prm2bits_ld8k_b(
- int anau[], /* input : encoded parameters (PRM_SIZE
parameters) */
- byte dst[] /* output: serial bits (SERIAL_SIZE ) bits[0] =
bfi
- bits[1] = 80 */
- )
- {
- dst[0] = (byte)(anau[0] & 255);
- dst[1] = (byte)((anau[1] & 0x3ff) >> 2);
- dst[2] = (byte)(((anau[1] & 3) << 6) | ((anau[2]>>2)&0x3f));
- dst[3] = (byte)(((anau[2] & 3) << 6) | ((anau[3] & 1) << 5) |
((anau[4] & 8191) >> 8));
- dst[4] = (byte)(anau[4] & 255);
- dst[5] = (byte)(((anau[5] & 15)<<4) | ((anau[6] & 127) >> 3));
- dst[6] = (byte)(((anau[6] & 7)<< 5) | (anau[7] & 31));
- dst[7] = (byte)((anau[8] & 8191) >> 5);
- dst[8] = (byte)(((anau[8] & 31) << 3) | ((anau[9] & 15) >> 1));
- dst[9] = (byte)(((anau[9] & 1) << 7) | (anau[10] & 127));
- return;
- }
-
- public static void prm2bits_ld8k(
- int prm[], /* input : encoded parameters (PRM_SIZE
parameters) */
- short bits[] /* output: serial bits (SERIAL_SIZE ) bits[0] =
bfi
- bits[1] = 80 */
- )
- {
+ public static void prm2bits_ld8k_b(int anau[], /*
+ * input : encoded parameters (PRM_SIZE parameters)
+ */
+ byte dst[] /*
+ * output: serial bits (SERIAL_SIZE ) bits[0] = bfi bits[1] = 80
+ */
+ ) {
+ dst[0] = (byte) (anau[0] & 255);
+ dst[1] = (byte) ((anau[1] & 0x3ff) >> 2);
+ dst[2] = (byte) (((anau[1] & 3) << 6) | ((anau[2] >> 2) & 0x3f));
+ dst[3] = (byte) (((anau[2] & 3) << 6) | ((anau[3] & 1) << 5) | ((anau[4]
& 8191) >> 8));
+ dst[4] = (byte) (anau[4] & 255);
+ dst[5] = (byte) (((anau[5] & 15) << 4) | ((anau[6] & 127) >> 3));
+ dst[6] = (byte) (((anau[6] & 7) << 5) | (anau[7] & 31));
+ dst[7] = (byte) ((anau[8] & 8191) >> 5);
+ dst[8] = (byte) (((anau[8] & 31) << 3) | ((anau[9] & 15) >> 1));
+ dst[9] = (byte) (((anau[9] & 1) << 7) | (anau[10] & 127));
+
+ return;
+ }
+
+ public static void prm2bits_ld8k(int prm[], /*
+ * input : encoded parameters (PRM_SIZE parameters)
+ */
+ short bits[] /*
+ * output: serial bits (SERIAL_SIZE ) bits[0] = bfi bits[1] = 80
+ */
+ ) {
int bitsp = 0;
- short i;
- bits[bitsp++] = LD8KConstants.SYNC_WORD; /* bit[0], at receiver
this bits indicates BFI */
- bits[bitsp++] = LD8KConstants.SIZE_WORD; /* bit[1], to be
compatible with hardware */
+ short i;
+ bits[bitsp++] = LD8KConstants.SYNC_WORD; /*
+ * bit[0], at receiver this bits indicates BFI
+ */
+ bits[bitsp++] = LD8KConstants.SIZE_WORD; /*
+ * bit[1], to be compatible with hardware
+ */
- for (i = 0; i < LD8KConstants.PRM_SIZE; i++)
- {
- int2bin(prm[i], TabLD8k.bitsno[i], bits, bitsp);
- bitsp += TabLD8k.bitsno[i];
- }
+ for (i = 0; i < LD8KConstants.PRM_SIZE; i++) {
+ int2bin(prm[i], TabLD8k.bitsno[i], bits, bitsp);
+ bitsp += TabLD8k.bitsno[i];
+ }
- return;
+ return;
}
-
- public static byte[] toRealBits(short[] fakebits){
+
+ public static byte[] toRealBits(short[] fakebits) {
byte[] real = new byte[10];
- for(int q=0; q<80; q++) {
- if(fakebits[q+2] == LD8KConstants.BIT_1) {
- int tmp = real[q/8];
- int onebit = 1<<(7-(q%8));
- tmp|=onebit;
- real[q/8] = (byte)(0xFF&tmp);
+ for (int q = 0; q < 80; q++) {
+ if (fakebits[q + 2] == LD8KConstants.BIT_1) {
+ int tmp = real[q / 8];
+ int onebit = 1 << (7 - (q % 8));
+ tmp |= onebit;
+ real[q / 8] = (byte) (0xFF & tmp);
}
-
+
}
return real;
}
-
- public static short[] fromRealBits(byte[] real){
+
+ public static short[] fromRealBits(byte[] real) {
short[] fake = new short[82];
fake[0] = LD8KConstants.SYNC_WORD;
fake[1] = LD8KConstants.SIZE_WORD;
- for(int q=0; q<80; q++) {
- if((real[q/8]&(1<<(7-(q%8)))) != 0)
- fake[q+2] = LD8KConstants.BIT_1;
+ for (int q = 0; q < 80; q++) {
+ if ((real[q / 8] & (1 << (7 - (q % 8)))) != 0)
+ fake[q + 2] = LD8KConstants.BIT_1;
else
- fake[q+2] = LD8KConstants.BIT_0;
+ fake[q + 2] = LD8KConstants.BIT_0;
}
return fake;
}
@@ -98,43 +104,39 @@
* int2bin convert integer to binary and write the bits bitstream array
*----------------------------------------------------------------------------
*/
- static void int2bin(
- int value, /* input : decimal value */
- int no_of_bits, /* input : number of bits to use */
- short[] bitstream, int bitstreams /* output: bitstream */
- )
- {
- int pt_bitstream;
- short i, bit;
+ static void int2bin(int value, /* input : decimal value */
+ int no_of_bits, /* input : number of bits to use */
+ short[] bitstream, int bitstreams /* output: bitstream */
+ ) {
+ int pt_bitstream;
+ short i, bit;
- pt_bitstream = bitstreams + no_of_bits;
+ pt_bitstream = bitstreams + no_of_bits;
- for (i = 0; i < no_of_bits; i++)
- {
- bit = (short)(value & 0x0001); /* get lsb */
- if (bit == 0)
- bitstream[--pt_bitstream] = LD8KConstants.BIT_0;
- else
- bitstream[--pt_bitstream] = LD8KConstants.BIT_1;
- value >>= 1;
- }
+ for (i = 0; i < no_of_bits; i++) {
+ bit = (short) (value & 0x0001); /* get lsb */
+ if (bit == 0)
+ bitstream[--pt_bitstream] = LD8KConstants.BIT_0;
+ else
+ bitstream[--pt_bitstream] = LD8KConstants.BIT_1;
+ value >>= 1;
+ }
}
/*----------------------------------------------------------------------------
* bits2prm_ld8k - converts serial received bits to encoder parameter
vector
*----------------------------------------------------------------------------
*/
- public static void bits2prm_ld8k(
- short bits[], int bitss, /* input : serial bits
(80) */
- int prm[], int ps /* output: decoded parameters (11
parameters) */
- )
- {
- short i;
- for (i = 0; i < LD8KConstants.PRM_SIZE; i++)
- {
- prm[i+ps] = bin2int(TabLD8k.bitsno[i], bits,bitss);
- bitss += TabLD8k.bitsno[i];
- }
+ public static void bits2prm_ld8k(short bits[], int bitss, /*
+ * input : serial bits (80)
+ */
+ int prm[], int ps /* output: decoded parameters (11 parameters) */
+ ) {
+ short i;
+ for (i = 0; i < LD8KConstants.PRM_SIZE; i++) {
+ prm[i + ps] = bin2int(TabLD8k.bitsno[i], bits, bitss);
+ bitss += TabLD8k.bitsno[i];
+ }
}
@@ -142,22 +144,21 @@
* bin2int - read specified bits from bit array and convert to integer
value
*----------------------------------------------------------------------------
*/
- static short bin2int( /* output: decimal value of bit pattern
*/
- int no_of_bits, /* input : number of bits to read */
- short []bitstream, int bitstreams /* input : array containing bits
*/
- )
- {
- short value, i;
- short bit;
+ static short bin2int( /* output: decimal value of bit pattern */
+ int no_of_bits, /* input : number of bits to read */
+ short[] bitstream, int bitstreams /* input : array containing bits */
+ ) {
+ short value, i;
+ short bit;
- value = 0;
- for (i = 0; i < no_of_bits; i++)
- {
- value <<= 1;
- bit = bitstream[bitstreams++];
- if (bit == LD8KConstants.BIT_1) value += 1;
- }
- return(value);
+ value = 0;
+ for (i = 0; i < no_of_bits; i++) {
+ value <<= 1;
+ bit = bitstream[bitstreams++];
+ if (bit == LD8KConstants.BIT_1)
+ value += 1;
+ }
+ return (value);
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/CelpCo.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/CelpCo.java Thu Feb 21
09:21:48 2013
@@ -1,57 +1,56 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class CelpCo {
- int ACELP_codebook( /* (o) :index of pulses positions */
- float x[], /* (i) :Target vector */
- float h[], /* (i) :Impulse response of filters */
- int t0, /* (i) :Pitch lag */
- float pitch_sharp, /* (i) :Last quantized pitch gain */
- int i_subfr, /* (i) :Indicator of 1st subframe, */
- float code[], /* (o) :Innovative codebook */
- float y[], /* (o) :Filtered innovative codebook */
- IntegerPointer sign /* (o) :Signs of 4
pulses */
- )
- {
- int i, index;
- float dn[] = new float[LD8KConstants.L_SUBFR];
- float rr[] = new float[LD8KConstants.DIM_RR];
+ int ACELP_codebook( /* (o) :index of pulses positions */
+ float x[], /* (i) :Target vector */
+ float h[], /* (i) :Impulse response of filters */
+ int t0, /* (i) :Pitch lag */
+ float pitch_sharp, /* (i) :Last quantized pitch gain */
+ int i_subfr, /* (i) :Indicator of 1st subframe, */
+ float code[], /* (o) :Innovative codebook */
+ float y[], /* (o) :Filtered innovative codebook */
+ IntegerPointer sign /* (o) :Signs of 4 pulses */
+ ) {
+ int i, index;
+ float dn[] = new float[LD8KConstants.L_SUBFR];
+ float rr[] = new float[LD8KConstants.DIM_RR];
- /*----------------------------------------------------------------*
- * Include fixed-gain pitch contribution into impulse resp. h[] *
- * Find correlations of h[] needed for the codebook search. *
- *-----------------------------------------------------------------*/
+ /*----------------------------------------------------------------*
+ * Include fixed-gain pitch contribution into impulse resp. h[] *
+ * Find correlations of h[] needed for the codebook search. *
+ *-----------------------------------------------------------------*/
- if(t0 < LD8KConstants.L_SUBFR)
- for (i = t0; i < LD8KConstants.L_SUBFR; i++)
- h[i] += pitch_sharp * h[i-t0];
+ if (t0 < LD8KConstants.L_SUBFR)
+ for (i = t0; i < LD8KConstants.L_SUBFR; i++)
+ h[i] += pitch_sharp * h[i - t0];
- cor_h(h, rr);
+ cor_h(h, rr);
- /*----------------------------------------------------------------*
- * Compute correlation of target vector with impulse response. *
- *-----------------------------------------------------------------*/
+ /*----------------------------------------------------------------*
+ * Compute correlation of target vector with impulse response. *
+ *-----------------------------------------------------------------*/
- CorFunc.cor_h_x(h, x, dn); /* backward filtered target vector dn
*/
+ CorFunc.cor_h_x(h, x, dn); /* backward filtered target vector dn */
- /*----------------------------------------------------------------*
- * Find innovative codebook. *
- *-----------------------------------------------------------------*/
+ /*----------------------------------------------------------------*
+ * Find innovative codebook. *
+ *-----------------------------------------------------------------*/
- index = d4i40_17(dn, rr, h, code, y, sign, i_subfr);
+ index = d4i40_17(dn, rr, h, code, y, sign, i_subfr);
- /*------------------------------------------------------*
- * - Add the fixed-gain pitch contribution to code[]. *
- *-------------------------------------------------------*/
+ /*------------------------------------------------------*
+ * - Add the fixed-gain pitch contribution to code[]. *
+ *-------------------------------------------------------*/
- if(t0 < LD8KConstants.L_SUBFR)
- for (i = t0; i < LD8KConstants.L_SUBFR; i++)
- code[i] += pitch_sharp * code[i-t0];
+ if (t0 < LD8KConstants.L_SUBFR)
+ for (i = t0; i < LD8KConstants.L_SUBFR; i++)
+ code[i] += pitch_sharp * code[i - t0];
- return index;
+ return index;
}
-
/*--------------------------------------------------------------------------*
* Function
cor_h() *
@@ -59,279 +58,343 @@
* Compute correlations of h[] needed for the codebook
search. *
*--------------------------------------------------------------------------*/
- static void cor_h(
- float []h, /* (i) :Impulse response of filters */
- float []rr /* (o) :Correlations of H[] */
- )
- {
- int rri0i0, rri1i1, rri2i2, rri3i3, rri4i4;
- int rri0i1, rri0i2, rri0i3, rri0i4;
- int rri1i2, rri1i3, rri1i4;
- int rri2i3, rri2i4;
+ static void cor_h(float[] h, /* (i) :Impulse response of filters */
+ float[] rr /* (o) :Correlations of H[] */
+ ) {
+ int rri0i0, rri1i1, rri2i2, rri3i3, rri4i4;
+ int rri0i1, rri0i2, rri0i3, rri0i4;
+ int rri1i2, rri1i3, rri1i4;
+ int rri2i3, rri2i4;
- int p0, p1, p2, p3, p4;
+ int p0, p1, p2, p3, p4;
- int ptr_hd,ptr_hf, ptr_h1, ptr_h2;
- float cor;
- int i, k, ldec, l_fin_sup, l_fin_inf;
+ int ptr_hd, ptr_hf, ptr_h1, ptr_h2;
+ float cor;
+ int i, k, ldec, l_fin_sup, l_fin_inf;
- /* Init pointers */
- rri0i0 = 0;//rr;
- rri1i1 = rri0i0 + LD8KConstants.NB_POS;
- rri2i2 = rri1i1 + LD8KConstants.NB_POS;
- rri3i3 = rri2i2 + LD8KConstants.NB_POS;
- rri4i4 = rri3i3 + LD8KConstants.NB_POS;
- rri0i1 = rri4i4 + LD8KConstants.NB_POS;
- rri0i2 = rri0i1 + LD8KConstants.MSIZE;
- rri0i3 = rri0i2 + LD8KConstants.MSIZE;
- rri0i4 = rri0i3 + LD8KConstants.MSIZE;
- rri1i2 = rri0i4 + LD8KConstants.MSIZE;
- rri1i3 = rri1i2 + LD8KConstants.MSIZE;
- rri1i4 = rri1i3 + LD8KConstants.MSIZE;
- rri2i3 = rri1i4 + LD8KConstants.MSIZE;
- rri2i4 = rri2i3 + LD8KConstants.MSIZE;
+ /* Init pointers */
+ rri0i0 = 0;// rr;
+ rri1i1 = rri0i0 + LD8KConstants.NB_POS;
+ rri2i2 = rri1i1 + LD8KConstants.NB_POS;
+ rri3i3 = rri2i2 + LD8KConstants.NB_POS;
+ rri4i4 = rri3i3 + LD8KConstants.NB_POS;
+ rri0i1 = rri4i4 + LD8KConstants.NB_POS;
+ rri0i2 = rri0i1 + LD8KConstants.MSIZE;
+ rri0i3 = rri0i2 + LD8KConstants.MSIZE;
+ rri0i4 = rri0i3 + LD8KConstants.MSIZE;
+ rri1i2 = rri0i4 + LD8KConstants.MSIZE;
+ rri1i3 = rri1i2 + LD8KConstants.MSIZE;
+ rri1i4 = rri1i3 + LD8KConstants.MSIZE;
+ rri2i3 = rri1i4 + LD8KConstants.MSIZE;
+ rri2i4 = rri2i3 + LD8KConstants.MSIZE;
- /*------------------------------------------------------------*
- * Compute rri0i0[], rri1i1[], rri2i2[], rri3i3 and rri4i4[] *
- *------------------------------------------------------------*/
+ /*------------------------------------------------------------*
+ * Compute rri0i0[], rri1i1[], rri2i2[], rri3i3 and rri4i4[] *
+ *------------------------------------------------------------*/
- p0 = rri0i0 + LD8KConstants.NB_POS-1; /* Init pointers to last
position of rrixix[] */
- p1 = rri1i1 + LD8KConstants.NB_POS-1;
- p2 = rri2i2 + LD8KConstants.NB_POS-1;
- p3 = rri3i3 + LD8KConstants.NB_POS-1;
- p4 = rri4i4 + LD8KConstants.NB_POS-1;
+ p0 = rri0i0 + LD8KConstants.NB_POS - 1; /*
+ * Init pointers to last position of rrixix[]
+ */
+ p1 = rri1i1 + LD8KConstants.NB_POS - 1;
+ p2 = rri2i2 + LD8KConstants.NB_POS - 1;
+ p3 = rri3i3 + LD8KConstants.NB_POS - 1;
+ p4 = rri4i4 + LD8KConstants.NB_POS - 1;
- ptr_h1 = 0;//h;
- cor = (float)0.0;
- for(i=0; i<LD8KConstants.NB_POS; i++)
- {
- cor += h[ptr_h1] * h[ptr_h1]; ptr_h1++;
- rr[p4--] = cor;
+ ptr_h1 = 0;// h;
+ cor = (float) 0.0;
+ for (i = 0; i < LD8KConstants.NB_POS; i++) {
+ cor += h[ptr_h1] * h[ptr_h1];
+ ptr_h1++;
+ rr[p4--] = cor;
- cor += h[ptr_h1] * h[ptr_h1]; ptr_h1++;
- rr[p3--] = cor;
+ cor += h[ptr_h1] * h[ptr_h1];
+ ptr_h1++;
+ rr[p3--] = cor;
- cor += h[ptr_h1] * h[ptr_h1]; ptr_h1++;
- rr[p2--] = cor;
+ cor += h[ptr_h1] * h[ptr_h1];
+ ptr_h1++;
+ rr[p2--] = cor;
- cor += h[ptr_h1] * h[ptr_h1]; ptr_h1++;
- rr[p1--] = cor;
+ cor += h[ptr_h1] * h[ptr_h1];
+ ptr_h1++;
+ rr[p1--] = cor;
- cor += h[ptr_h1] * h[ptr_h1]; ptr_h1++;
- rr[p0--] = cor;
- }
+ cor += h[ptr_h1] * h[ptr_h1];
+ ptr_h1++;
+ rr[p0--] = cor;
+ }
- /*-----------------------------------------------------------------*
- * Compute elements of: rri2i3[], rri1i2[], rri0i1[] and rri0i4[] *
- *-----------------------------------------------------------------*/
+ /*-----------------------------------------------------------------*
+ * Compute elements of: rri2i3[], rri1i2[], rri0i1[] and rri0i4[] *
+ *-----------------------------------------------------------------*/
- l_fin_sup = LD8KConstants.MSIZE-1;
- l_fin_inf = l_fin_sup-1;
- ldec = LD8KConstants.NB_POS+1;
+ l_fin_sup = LD8KConstants.MSIZE - 1;
+ l_fin_inf = l_fin_sup - 1;
+ ldec = LD8KConstants.NB_POS + 1;
- ptr_hd = 0;//h;
- ptr_hf = ptr_hd + 1;
+ ptr_hd = 0;// h;
+ ptr_hf = ptr_hd + 1;
- for(k=0; k<LD8KConstants.NB_POS; k++) {
+ for (k = 0; k < LD8KConstants.NB_POS; k++) {
- p3 = rri2i3 + l_fin_sup;
- p2 = rri1i2 + l_fin_sup;
- p1 = rri0i1 + l_fin_sup;
- p0 = rri0i4 + l_fin_inf;
- cor = (float)0.0;
- ptr_h1 = ptr_hd;
- ptr_h2 = ptr_hf;
+ p3 = rri2i3 + l_fin_sup;
+ p2 = rri1i2 + l_fin_sup;
+ p1 = rri0i1 + l_fin_sup;
+ p0 = rri0i4 + l_fin_inf;
+ cor = (float) 0.0;
+ ptr_h1 = ptr_hd;
+ ptr_h2 = ptr_hf;
- for(i=k+1; i<LD8KConstants.NB_POS; i++ ) {
+ for (i = k + 1; i < LD8KConstants.NB_POS; i++) {
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p1] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p1] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p0] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p0] = cor;
- p3 -= ldec;
- p2 -= ldec;
- p1 -= ldec;
- p0 -= ldec;
- }
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ p3 -= ldec;
+ p2 -= ldec;
+ p1 -= ldec;
+ p0 -= ldec;
+ }
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] *h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p1] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p1] = cor;
- l_fin_sup -= LD8KConstants.NB_POS;
- l_fin_inf--;
- ptr_hf += LD8KConstants.STEP;
- }
+ l_fin_sup -= LD8KConstants.NB_POS;
+ l_fin_inf--;
+ ptr_hf += LD8KConstants.STEP;
+ }
- /*---------------------------------------------------------------------*
- * Compute elements of: rri2i4[], rri1i3[], rri0i2[], rri1i4[], rri0i3 *
- *---------------------------------------------------------------------*/
+ /*---------------------------------------------------------------------*
+ * Compute elements of: rri2i4[], rri1i3[], rri0i2[], rri1i4[], rri0i3 *
+ *---------------------------------------------------------------------*/
- ptr_hd = 0;//h;
- ptr_hf = ptr_hd + 2;
- l_fin_sup = LD8KConstants.MSIZE-1;
- l_fin_inf = l_fin_sup-1;
- for(k=0; k<LD8KConstants.NB_POS; k++) {
+ ptr_hd = 0;// h;
+ ptr_hf = ptr_hd + 2;
+ l_fin_sup = LD8KConstants.MSIZE - 1;
+ l_fin_inf = l_fin_sup - 1;
+ for (k = 0; k < LD8KConstants.NB_POS; k++) {
- p4 = rri2i4 + l_fin_sup;
- p3 = rri1i3 + l_fin_sup;
- p2 = rri0i2 + l_fin_sup;
- p1 = rri1i4 + l_fin_inf;
- p0 = rri0i3 + l_fin_inf;
+ p4 = rri2i4 + l_fin_sup;
+ p3 = rri1i3 + l_fin_sup;
+ p2 = rri0i2 + l_fin_sup;
+ p1 = rri1i4 + l_fin_inf;
+ p0 = rri0i3 + l_fin_inf;
- cor = (float)0.0;
- ptr_h1 = ptr_hd;
- ptr_h2 = ptr_hf;
- for(i=k+1; i<LD8KConstants.NB_POS; i++ ) {
+ cor = (float) 0.0;
+ ptr_h1 = ptr_hd;
+ ptr_h2 = ptr_hf;
+ for (i = k + 1; i < LD8KConstants.NB_POS; i++) {
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p4] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p4] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p1] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p1] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p0] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p0] = cor;
- p4 -= ldec;
- p3 -= ldec;
- p2 -= ldec;
- p1 -= ldec;
- p0 -= ldec;
- }
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p4] = cor;
+ p4 -= ldec;
+ p3 -= ldec;
+ p2 -= ldec;
+ p1 -= ldec;
+ p0 -= ldec;
+ }
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p4] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- l_fin_sup -= LD8KConstants.NB_POS;
- l_fin_inf--;
- ptr_hf += LD8KConstants.STEP;
- }
+ l_fin_sup -= LD8KConstants.NB_POS;
+ l_fin_inf--;
+ ptr_hf += LD8KConstants.STEP;
+ }
- /*----------------------------------------------------------------------*
- * Compute elements of: rri1i4[], rri0i3[], rri2i4[], rri1i3[], rri0i2 *
-
*----------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------*
+ * Compute elements of: rri1i4[], rri0i3[], rri2i4[], rri1i3[], rri0i2 *
+
*----------------------------------------------------------------------*/
- ptr_hd = 0;//h;
- ptr_hf = ptr_hd + 3;
- l_fin_sup = LD8KConstants.MSIZE-1;
- l_fin_inf = l_fin_sup-1;
- for(k=0; k<LD8KConstants.NB_POS; k++) {
+ ptr_hd = 0;// h;
+ ptr_hf = ptr_hd + 3;
+ l_fin_sup = LD8KConstants.MSIZE - 1;
+ l_fin_inf = l_fin_sup - 1;
+ for (k = 0; k < LD8KConstants.NB_POS; k++) {
- p4 = rri1i4 + l_fin_sup;
- p3 = rri0i3 + l_fin_sup;
- p2 = rri2i4 + l_fin_inf;
- p1 = rri1i3 + l_fin_inf;
- p0 = rri0i2 + l_fin_inf;
+ p4 = rri1i4 + l_fin_sup;
+ p3 = rri0i3 + l_fin_sup;
+ p2 = rri2i4 + l_fin_inf;
+ p1 = rri1i3 + l_fin_inf;
+ p0 = rri0i2 + l_fin_inf;
- ptr_h1 = ptr_hd;
- ptr_h2 = ptr_hf;
- cor = (float)0.0;
- for(i=k+1; i<LD8KConstants.NB_POS; i++ ) {
+ ptr_h1 = ptr_hd;
+ ptr_h2 = ptr_hf;
+ cor = (float) 0.0;
+ for (i = k + 1; i < LD8KConstants.NB_POS; i++) {
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p4] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p4] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p1] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p1] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p0] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p0] = cor;
- p4 -= ldec;
- p3 -= ldec;
- p2 -= ldec;
- p1 -= ldec;
- p0 -= ldec;
- }
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p4] = cor;
+ p4 -= ldec;
+ p3 -= ldec;
+ p2 -= ldec;
+ p1 -= ldec;
+ p0 -= ldec;
+ }
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p4] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- l_fin_sup -= LD8KConstants.NB_POS;
- l_fin_inf--;
- ptr_hf += LD8KConstants.STEP;
- }
+ l_fin_sup -= LD8KConstants.NB_POS;
+ l_fin_inf--;
+ ptr_hf += LD8KConstants.STEP;
+ }
- /*----------------------------------------------------------------------*
- * Compute elements of: rri0i4[], rri2i3[], rri1i2[], rri0i1[] *
-
*----------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------*
+ * Compute elements of: rri0i4[], rri2i3[], rri1i2[], rri0i1[] *
+
*----------------------------------------------------------------------*/
- ptr_hd = 0;//h;
- ptr_hf = ptr_hd + 4;
- l_fin_sup = LD8KConstants.MSIZE-1;
- l_fin_inf = l_fin_sup-1;
- for(k=0; k<LD8KConstants.NB_POS; k++) {
+ ptr_hd = 0;// h;
+ ptr_hf = ptr_hd + 4;
+ l_fin_sup = LD8KConstants.MSIZE - 1;
+ l_fin_inf = l_fin_sup - 1;
+ for (k = 0; k < LD8KConstants.NB_POS; k++) {
- p3 = rri0i4 + l_fin_sup;
- p2 = rri2i3 + l_fin_inf;
- p1 = rri1i2 + l_fin_inf;
- p0 = rri0i1 + l_fin_inf;
+ p3 = rri0i4 + l_fin_sup;
+ p2 = rri2i3 + l_fin_inf;
+ p1 = rri1i2 + l_fin_inf;
+ p0 = rri0i1 + l_fin_inf;
- ptr_h1 = ptr_hd;
- ptr_h2 = ptr_hf;
- cor = (float)0.;
- for(i=k+1; i<LD8KConstants.NB_POS; i++ ) {
+ ptr_h1 = ptr_hd;
+ ptr_h2 = ptr_hf;
+ cor = (float) 0.;
+ for (i = k + 1; i < LD8KConstants.NB_POS; i++) {
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p2] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p2] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p1] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p1] = cor;
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p0] = cor;
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p0] = cor;
- p3 -= ldec;
- p2 -= ldec;
- p1 -= ldec;
- p0 -= ldec;
- }
- cor += h[ptr_h1] * h[ptr_h2]; ptr_h1++; ptr_h2++;
- rr[p3] = cor;
+ p3 -= ldec;
+ p2 -= ldec;
+ p1 -= ldec;
+ p0 -= ldec;
+ }
+ cor += h[ptr_h1] * h[ptr_h2];
+ ptr_h1++;
+ ptr_h2++;
+ rr[p3] = cor;
- l_fin_sup -= LD8KConstants.NB_POS;
- l_fin_inf--;
- ptr_hf += LD8KConstants.STEP;
- }
- return;
+ l_fin_sup -= LD8KConstants.NB_POS;
+ l_fin_inf--;
+ ptr_hf += LD8KConstants.STEP;
+ }
+ return;
}
int extra;
@@ -340,333 +403,338 @@
* d4i40_17 - algebraic codebook search 17 bits; 4 pulses 40 sampleframe
*----------------------------------------------------------------------------
*/
- int d4i40_17( /* output: pulse positions */
- float dn[], /* input : backward filtered target
vector */
- float rr[], /* input : autocorrelations of impulse response
h[] */
- float h[], /* input : impulse response of
filters */
- float cod[], /* output: selected algebraic
codeword */
- float y[], /* output: filtered algebraic
codeword */
- IntegerPointer signs, /* output: signs of 4
pulses */
- int i_subfr /* input : subframe
flag */
- )
- {
- /*
- * The code length is 40, containing 4 nonzero pulses i0, i1, i2, i3.
- * with pulse spacings of step = 5
- * Each pulses can have 8 possible positions (positive or negative):
- *
- * i0 (+-1) : 0, 5, 10, 15, 20, 25, 30, 35
- * i1 (+-1) : 1, 6, 11, 16, 21, 26, 31, 36
- * i2 (+-1) : 2, 7, 12, 17, 22, 27, 32, 37
- * i3 (+-1) : 3, 8, 13, 18, 23, 28, 33, 38
- * 4, 9, 14, 19, 24, 29, 34, 39
-
*---------------------------------------------------------------------------
- */
- int i0, i1, i2, i3, ip0, ip1, ip2, ip3;
- int i, j, time;
- float ps0, ps1, ps2, ps3, alp0, alp1, alp2, alp3;
- float ps3c, psc, alpha;
- float average, max0, max1, max2, thres;
- float p_sign[] = new float[LD8KConstants.L_SUBFR];
+ int d4i40_17( /* output: pulse positions */
+ float dn[], /* input : backward filtered target vector */
+ float rr[], /* input : autocorrelations of impulse response h[] */
+ float h[], /* input : impulse response of filters */
+ float cod[], /* output: selected algebraic codeword */
+ float y[], /* output: filtered algebraic codeword */
+ IntegerPointer signs, /* output: signs of 4 pulses */
+ int i_subfr /* input : subframe flag */
+ ) {
+ /*
+ * The code length is 40, containing 4 nonzero pulses i0, i1, i2, i3.
with pulse spacings of step = 5 Each
+ * pulses can have 8 possible positions (positive or negative):
+ *
+ * i0 (+-1) : 0, 5, 10, 15, 20, 25, 30, 35 i1 (+-1) : 1, 6, 11, 16, 21,
26, 31, 36 i2 (+-1) : 2, 7, 12, 17, 22,
+ * 27, 32, 37 i3 (+-1) : 3, 8, 13, 18, 23, 28, 33, 38 4, 9, 14, 19, 24,
29, 34, 39 --------------------
+ * -------------------------------------------------------
+ */
+ int i0, i1, i2, i3, ip0, ip1, ip2, ip3;
+ int i, j, time;
+ float ps0, ps1, ps2, ps3, alp0, alp1, alp2, alp3;
+ float ps3c, psc, alpha;
+ float average, max0, max1, max2, thres;
+ float p_sign[] = new float[LD8KConstants.L_SUBFR];
- int rri0i0, rri1i1, rri2i2, rri3i3, rri4i4;
- int rri0i1, rri0i2, rri0i3, rri0i4;
- int rri1i2, rri1i3, rri1i4;
- int rri2i3, rri2i4;
+ int rri0i0, rri1i1, rri2i2, rri3i3, rri4i4;
+ int rri0i1, rri0i2, rri0i3, rri0i4;
+ int rri1i2, rri1i3, rri1i4;
+ int rri2i3, rri2i4;
- int ptr_ri0i0, ptr_ri1i1, ptr_ri2i2, ptr_ri3i3, ptr_ri4i4;
- int ptr_ri0i1, ptr_ri0i2, ptr_ri0i3, ptr_ri0i4;
- int ptr_ri1i2, ptr_ri1i3, ptr_ri1i4;
- int ptr_ri2i3, ptr_ri2i4;
+ int ptr_ri0i0, ptr_ri1i1, ptr_ri2i2, ptr_ri3i3, ptr_ri4i4;
+ int ptr_ri0i1, ptr_ri0i2, ptr_ri0i3, ptr_ri0i4;
+ int ptr_ri1i2, ptr_ri1i3, ptr_ri1i4;
+ int ptr_ri2i3, ptr_ri2i4;
- /* Init pointers */
+ /* Init pointers */
- rri0i0 = 0;//rr;
- rri1i1 = rri0i0 + LD8KConstants.NB_POS;
- rri2i2 = rri1i1 + LD8KConstants.NB_POS;
- rri3i3 = rri2i2 + LD8KConstants.NB_POS;
- rri4i4 = rri3i3 + LD8KConstants.NB_POS;
+ rri0i0 = 0;// rr;
+ rri1i1 = rri0i0 + LD8KConstants.NB_POS;
+ rri2i2 = rri1i1 + LD8KConstants.NB_POS;
+ rri3i3 = rri2i2 + LD8KConstants.NB_POS;
+ rri4i4 = rri3i3 + LD8KConstants.NB_POS;
- rri0i1 = rri4i4 + LD8KConstants.NB_POS;
- rri0i2 = rri0i1 + LD8KConstants.MSIZE;
- rri0i3 = rri0i2 + LD8KConstants.MSIZE;
- rri0i4 = rri0i3 + LD8KConstants.MSIZE;
- rri1i2 = rri0i4 + LD8KConstants.MSIZE;
- rri1i3 = rri1i2 + LD8KConstants.MSIZE;
- rri1i4 = rri1i3 + LD8KConstants.MSIZE;
- rri2i3 = rri1i4 + LD8KConstants.MSIZE;
- rri2i4 = rri2i3 + LD8KConstants.MSIZE;
+ rri0i1 = rri4i4 + LD8KConstants.NB_POS;
+ rri0i2 = rri0i1 + LD8KConstants.MSIZE;
+ rri0i3 = rri0i2 + LD8KConstants.MSIZE;
+ rri0i4 = rri0i3 + LD8KConstants.MSIZE;
+ rri1i2 = rri0i4 + LD8KConstants.MSIZE;
+ rri1i3 = rri1i2 + LD8KConstants.MSIZE;
+ rri1i4 = rri1i3 + LD8KConstants.MSIZE;
+ rri2i3 = rri1i4 + LD8KConstants.MSIZE;
+ rri2i4 = rri2i3 + LD8KConstants.MSIZE;
-
/*-----------------------------------------------------------------------*
- * Reset max_time for 1st
subframe. *
-
*-----------------------------------------------------------------------*
- */
- if (i_subfr == 0) extra = 30;
+
/*-----------------------------------------------------------------------*
+ * Reset max_time for 1st subframe.
*
+
*-----------------------------------------------------------------------*
+ */
+ if (i_subfr == 0)
+ extra = 30;
-
/*----------------------------------------------------------------------*
- * Chose the signs of the
impulses. *
-
*-----------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------*
+ * Chose the signs of the impulses.
*
+
*-----------------------------------------------------------------------*/
- for (i=0; i<LD8KConstants.L_SUBFR; i++)
- {
- if( dn[i] >= (float)0.0)
- {
- p_sign[i] = (float)1.0;
- }
- else {
- p_sign[i] = (float)-1.0;
- dn[i] = -dn[i];
- }
- }
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ if (dn[i] >= (float) 0.0) {
+ p_sign[i] = (float) 1.0;
+ } else {
+ p_sign[i] = (float) -1.0;
+ dn[i] = -dn[i];
+ }
+ }
- /*-------------------------------------------------------------------*
- * - Compute the search threshold after three pulses *
-
*-------------------------------------------------------------------*/
+ /*-------------------------------------------------------------------*
+ * - Compute the search threshold after three pulses *
+ *-------------------------------------------------------------------*/
+ average = dn[0] + dn[1] + dn[2];
+ max0 = dn[0];
+ max1 = dn[1];
+ max2 = dn[2];
+ for (i = 5; i < LD8KConstants.L_SUBFR; i += LD8KConstants.STEP) {
+ average += dn[i] + dn[i + 1] + dn[i + 2];
+ if (dn[i] > max0)
+ max0 = dn[i];
+ if (dn[i + 1] > max1)
+ max1 = dn[i + 1];
+ if (dn[i + 2] > max2)
+ max2 = dn[i + 2];
+ }
+ max0 += max1 + max2;
+ average *= (float) 0.125; /* 1/8 */
+ thres = average + (max0 - average) * LD8KConstants.THRESHFCB;
- average = dn[0] + dn[1] + dn[2];
- max0 = dn[0];
- max1 = dn[1];
- max2 = dn[2];
- for (i = 5; i < LD8KConstants.L_SUBFR; i+=LD8KConstants.STEP)
- {
- average += dn[i] + dn[i+1]+ dn[i+2];
- if (dn[i] > max0) max0 = dn[i];
- if (dn[i+1] > max1) max1 = dn[i+1];
- if (dn[i+2] > max2) max2 = dn[i+2];
- }
- max0 += max1+max2;
- average *= (float)0.125; /* 1/8 */
- thres = average + (max0-average)*LD8KConstants.THRESHFCB;
+ /*-------------------------------------------------------------------*
+ * Modification of rrixiy to take into account signs. *
+ *-------------------------------------------------------------------*/
+ ptr_ri0i1 = rri0i1;
+ ptr_ri0i2 = rri0i2;
+ ptr_ri0i3 = rri0i3;
+ ptr_ri0i4 = rri0i4;
- /*-------------------------------------------------------------------*
- * Modification of rrixiy to take into account signs. *
- *-------------------------------------------------------------------*/
- ptr_ri0i1 = rri0i1;
- ptr_ri0i2 = rri0i2;
- ptr_ri0i3 = rri0i3;
- ptr_ri0i4 = rri0i4;
+ for (i0 = 0; i0 < LD8KConstants.L_SUBFR; i0 += LD8KConstants.STEP) {
+ for (i1 = 1; i1 < LD8KConstants.L_SUBFR; i1 += LD8KConstants.STEP) {
+ rr[ptr_ri0i1] *= (p_sign[i0] * p_sign[i1]);
+ ptr_ri0i1++;
+ rr[ptr_ri0i2] *= (p_sign[i0] * p_sign[i1 + 1]);
+ ptr_ri0i2++;
+ rr[ptr_ri0i3] *= (p_sign[i0] * p_sign[i1 + 2]);
+ ptr_ri0i3++;
+ rr[ptr_ri0i4] *= (p_sign[i0] * p_sign[i1 + 3]);
+ ptr_ri0i4++;
+ }
+ }
- for(i0=0; i0<LD8KConstants.L_SUBFR; i0+=LD8KConstants.STEP)
- {
- for(i1=1; i1<LD8KConstants.L_SUBFR; i1+=LD8KConstants.STEP) {
- rr[ptr_ri0i1] *= (p_sign[i0] * p_sign[i1]);
- ptr_ri0i1++;
- rr[ptr_ri0i2] *= (p_sign[i0] * p_sign[i1+1]);
- ptr_ri0i2++;
- rr[ptr_ri0i3] *= (p_sign[i0] * p_sign[i1+2]);
- ptr_ri0i3++;
- rr[ptr_ri0i4] *= (p_sign[i0] * p_sign[i1+3]);
- ptr_ri0i4++;
- }
- }
+ ptr_ri1i2 = rri1i2;
+ ptr_ri1i3 = rri1i3;
+ ptr_ri1i4 = rri1i4;
- ptr_ri1i2 = rri1i2;
- ptr_ri1i3 = rri1i3;
- ptr_ri1i4 = rri1i4;
+ for (i1 = 1; i1 < LD8KConstants.L_SUBFR; i1 += LD8KConstants.STEP) {
+ for (i2 = 2; i2 < LD8KConstants.L_SUBFR; i2 += LD8KConstants.STEP) {
+ rr[ptr_ri1i2] *= (p_sign[i1] * p_sign[i2]);
+ ptr_ri1i2++;
+ rr[ptr_ri1i3] *= (p_sign[i1] * p_sign[i2 + 1]);
+ ptr_ri1i3++;
+ rr[ptr_ri1i4] *= (p_sign[i1] * p_sign[i2 + 2]);
+ ptr_ri1i4++;
+ }
+ }
- for(i1=1; i1<LD8KConstants.L_SUBFR; i1+=LD8KConstants.STEP)
- {
- for(i2=2; i2<LD8KConstants.L_SUBFR; i2+=LD8KConstants.STEP)
- {
- rr[ptr_ri1i2] *= (p_sign[i1] * p_sign[i2]);
- ptr_ri1i2++;
- rr[ptr_ri1i3] *= (p_sign[i1] * p_sign[i2+1]);
- ptr_ri1i3++;
- rr[ptr_ri1i4] *= (p_sign[i1] * p_sign[i2+2]);
- ptr_ri1i4++;
- }
- }
+ ptr_ri2i3 = rri2i3;
+ ptr_ri2i4 = rri2i4;
- ptr_ri2i3 = rri2i3;
- ptr_ri2i4 = rri2i4;
+ for (i2 = 2; i2 < LD8KConstants.L_SUBFR; i2 += LD8KConstants.STEP) {
+ for (i3 = 3; i3 < LD8KConstants.L_SUBFR; i3 += LD8KConstants.STEP) {
+ rr[ptr_ri2i3] *= (p_sign[i2] * p_sign[i3]);
+ ptr_ri2i3++;
+ rr[ptr_ri2i4] *= (p_sign[i2] * p_sign[i3 + 1]);
+ ptr_ri2i4++;
+ }
+ }
- for(i2=2; i2<LD8KConstants.L_SUBFR; i2+=LD8KConstants.STEP)
- {
- for(i3=3; i3<LD8KConstants.L_SUBFR; i3+=LD8KConstants.STEP)
- {
- rr[ptr_ri2i3] *= (p_sign[i2] * p_sign[i3]);
- ptr_ri2i3++;
- rr[ptr_ri2i4] *= (p_sign[i2] * p_sign[i3+1]);
- ptr_ri2i4++;
- }
- }
-
- /*-------------------------------------------------------------------*
- * Search the optimum positions of the four pulses which maximize *
- * square(correlation) / energy *
- * The search is performed in four nested loops. At each loop, one *
- * pulse contribution is added to the correlation and energy. *
- * *
- * The fourth loop is entered only if the correlation due to the *
- * contribution of the first three pulses exceeds the preset *
- * threshold. *
- *-------------------------------------------------------------------*/
+ /*-------------------------------------------------------------------*
+ * Search the optimum positions of the four pulses which maximize *
+ * square(correlation) / energy *
+ * The search is performed in four nested loops. At each loop, one *
+ * pulse contribution is added to the correlation and energy. *
+ * *
+ * The fourth loop is entered only if the correlation due to the *
+ * contribution of the first three pulses exceeds the preset *
+ * threshold. *
+ *-------------------------------------------------------------------*/
- /* Default values */
+ /* Default values */
- ip0 = 0;
- ip1 = 1;
- ip2 = 2;
- ip3 = 3;
- psc = (float)0.0;
- alpha = (float)1000000.0;
- time = LD8KConstants.MAX_TIME + extra;
+ ip0 = 0;
+ ip1 = 1;
+ ip2 = 2;
+ ip3 = 3;
+ psc = (float) 0.0;
+ alpha = (float) 1000000.0;
+ time = LD8KConstants.MAX_TIME + extra;
- /* Four loops to search innovation code. */
- ptr_ri0i0 = rri0i0; /* Init. pointers that depend on first loop */
- ptr_ri0i1 = rri0i1;
- ptr_ri0i2 = rri0i2;
- ptr_ri0i3 = rri0i3;
- ptr_ri0i4 = rri0i4;
-
- end_search:
- for (i0 = 0; i0 < LD8KConstants.L_SUBFR; i0 +=
LD8KConstants.STEP) /* first pulse loop */
- {
- ps0 = dn[i0];
- alp0 = rr[ptr_ri0i0++];
+ /* Four loops to search innovation code. */
+ ptr_ri0i0 = rri0i0; /* Init. pointers that depend on first loop */
+ ptr_ri0i1 = rri0i1;
+ ptr_ri0i2 = rri0i2;
+ ptr_ri0i3 = rri0i3;
+ ptr_ri0i4 = rri0i4;
- ptr_ri1i1 = rri1i1; /* Init. pointers that depend on second
loop */
- ptr_ri1i2 = rri1i2;
- ptr_ri1i3 = rri1i3;
- ptr_ri1i4 = rri1i4;
+ end_search: for (i0 = 0; i0 < LD8KConstants.L_SUBFR; i0 +=
LD8KConstants.STEP) /*
+ * first pulse loop
+ */
+ {
***The diff for this file has been truncated for email.***
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/CircularBuffer.java Fri
Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/CircularBuffer.java Thu
Feb 21 09:21:48 2013
@@ -1,43 +1,46 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
/**
- * This is just a buffer that stores temporary info. FIFO/old info get's
overwritten.
- * Used to compensate irregularly delivered RTP packets.
+ * This is just a buffer that stores temporary info. FIFO/old info get's
overwritten. Used to compensate irregularly
+ * delivered RTP packets.
*
* @author vralev
- *
+ *
*/
public class CircularBuffer {
-
+
private byte[] buffer;
private int cursor = 0;
private int availableData = 0;
-
+
public CircularBuffer(int size) {
buffer = new byte[size];
}
-
+
synchronized public void addData(byte[] data) {
boolean zeros = false;
- //for(int q=0; q<data.length; q++) if(data[q]!=0) zeros = false;
- if(!zeros) {
- for(int q=0; q<data.length; q++) {
- buffer[(cursor+q)%buffer.length] = data[q];
+ // for(int q=0; q<data.length; q++) if(data[q]!=0) zeros = false;
+ if (!zeros) {
+ for (int q = 0; q < data.length; q++) {
+ buffer[(cursor + q) % buffer.length] = data[q];
}
availableData += data.length;
- if(availableData > buffer.length) availableData = buffer.length;
+ if (availableData > buffer.length)
+ availableData = buffer.length;
}
}
-
+
synchronized public byte[] getData(int size) {
- if(availableData<size) return null;
-
+ if (availableData < size)
+ return null;
+
byte[] data = new byte[size];
- for(int q=0; q<data.length; q++) {
- data[q] = buffer[(cursor+q)%buffer.length];
+ for (int q = 0; q < data.length; q++) {
+ data[q] = buffer[(cursor + q) % buffer.length];
}
- cursor = (cursor + data.length)%buffer.length;
+ cursor = (cursor + data.length) % buffer.length;
availableData -= size;
return data;
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/CodLD8K.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/CodLD8K.java Thu Feb 21
09:21:48 2013
@@ -1,67 +1,65 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
-
public class CodLD8K {
-
/*-----------------------------------------------------------------------*
- * Initialize pointers to speech
vector. *
-
* *
-
* *
- * |--------------------|-------------|-------------|
------------| *
- * previous speech sf1 sf2
L_NEXT *
-
* *
- * <---------------- Total speech vector (L_TOTAL)
-----------> *
- * | <------------ LPC analysis window (L_WINDOW)
-----------> *
- * | | <-- present frame (L_FRAME)
--> *
- * old_speech | <-- new speech (L_FRAME)
--> *
- * p_wind |
| *
- * speech
| *
- *
new_speech *
-
*-----------------------------------------------------------------------*/
+ /*-----------------------------------------------------------------------*
+ * Initialize pointers to speech vector. *
+ * *
+ * *
+ * |--------------------|-------------|-------------|------------| *
+ * previous speech sf1 sf2 L_NEXT *
+ * *
+ * <---------------- Total speech vector (L_TOTAL) -----------> *
+ * | <------------ LPC analysis window (L_WINDOW) -----------> *
+ * | | <-- present frame (L_FRAME) --> *
+ * old_speech | <-- new speech (L_FRAME) --> *
+ * p_wind | | *
+ * speech | *
+ * new_speech *
+
*-----------------------------------------------------------------------*/
- /* Speech vector */
+ /* Speech vector */
float[] old_speech_array = new float[LD8KConstants.L_TOTAL];
int old_speech;
int speech;
int p_window;
int new_speech;
-
- /* Weighted speech vector */
- float[] old_wsp_array = new
float[LD8KConstants.L_FRAME+LD8KConstants.PIT_MAX];
+ /* Weighted speech vector */
+
+ float[] old_wsp_array = new float[LD8KConstants.L_FRAME +
LD8KConstants.PIT_MAX];
int old_wsp;
int wsp;
- /* Excitation vector */
+ /* Excitation vector */
- float[] old_exc_array = new
float[LD8KConstants.L_FRAME+LD8KConstants.PIT_MAX+LD8KConstants.L_INTERPOL];
+ float[] old_exc_array = new float[LD8KConstants.L_FRAME +
LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL];
int old_exc;
int exc;
- /* Zero vector */
+ /* Zero vector */
- float[] ai_zero_array = new
float[LD8KConstants.L_SUBFR+LD8KConstants.MP1];
+ float[] ai_zero_array = new float[LD8KConstants.L_SUBFR +
LD8KConstants.MP1];
int ai_zero;
int zero;
-
- /* Lsp (Line spectral pairs) */
- float[] lsp_old =
- { (float)0.9595, (float)0.8413, (float)0.6549, (float)0.4154,
(float)0.1423,
- (float)-0.1423, (float)-0.4154, (float)-0.6549, (float)-0.8413,
(float)-0.9595};
+ /* Lsp (Line spectral pairs) */
+ float[] lsp_old = { (float) 0.9595, (float) 0.8413, (float) 0.6549,
(float) 0.4154, (float) 0.1423,
+ (float) -0.1423, (float) -0.4154, (float) -0.6549, (float) -0.8413,
(float) -0.9595 };
float[] lsp_old_q = new float[LD8KConstants.M];
- /* Filter's memory */
+ /* Filter's memory */
float[] mem_syn = new float[LD8KConstants.M];
float[] mem_w0 = new float[LD8KConstants.M];
float[] mem_w = new float[LD8KConstants.M];
- float[] mem_err_array = new float[LD8KConstants.M+LD8KConstants.L_SUBFR];
+ float[] mem_err_array = new float[LD8KConstants.M +
LD8KConstants.L_SUBFR];
int mem_err;
int error;
float sharp;
-
+
Lpc lpc = new Lpc();
QuaLsp quaLsp = new QuaLsp();
Pwf pwf = new Pwf();
@@ -73,60 +71,57 @@
* init_coder_ld8k - initialization of variables for the encoder
*----------------------------------------------------------------------------
*/
- public void init_coder_ld8k()
- {
-
/*-----------------------------------------------------------------------*
- * Initialize pointers to speech
vector. *
-
* *
-
* *
- * |--------------------|-------------|-------------|
------------| *
- * previous speech sf1 sf2
L_NEXT *
-
* *
- * <---------------- Total speech vector (L_TOTAL)
-----------> *
- * | <------------ LPC analysis window (L_WINDOW)
-----------> *
- * | | <-- present frame (L_FRAME)
--> *
- * old_speech | <-- new speech (L_FRAME)
--> *
- * p_wind |
| *
- * speech
| *
- *
new_speech *
-
*-----------------------------------------------------------------------*/
+ public void init_coder_ld8k() {
+
/*-----------------------------------------------------------------------*
+ * Initialize pointers to speech vector.
*
+ *
*
+ *
*
+ * |--------------------|-------------|-------------|------------|
*
+ * previous speech sf1 sf2 L_NEXT
*
+ *
*
+ * <---------------- Total speech vector (L_TOTAL) ----------->
*
+ * | <------------ LPC analysis window (L_WINDOW) ----------->
*
+ * | | <-- present frame (L_FRAME) -->
*
+ * old_speech | <-- new speech (L_FRAME) -->
*
+ * p_wind | |
*
+ * speech |
*
+ * new_speech
*
+
*-----------------------------------------------------------------------*/
- new_speech = old_speech + LD8KConstants.L_TOTAL -
LD8KConstants.L_FRAME; /* New speech */
- speech = new_speech - LD8KConstants.L_NEXT; /*
Present frame */
- p_window = old_speech + LD8KConstants.L_TOTAL -
LD8KConstants.L_WINDOW; /* For LPC window */
+ new_speech = old_speech + LD8KConstants.L_TOTAL - LD8KConstants.L_FRAME;
/*
+ * New speech
+ */
+ speech = new_speech - LD8KConstants.L_NEXT; /* Present frame */
+ p_window = old_speech + LD8KConstants.L_TOTAL - LD8KConstants.L_WINDOW;
/*
+ * For LPC window
+ */
- /* Initialize static pointers */
+ /* Initialize static pointers */
- wsp = old_wsp + LD8KConstants.PIT_MAX;
- exc = old_exc + LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL;
- zero = ai_zero + LD8KConstants.MP1;
- error = mem_err + LD8KConstants.M;
+ wsp = old_wsp + LD8KConstants.PIT_MAX;
+ exc = old_exc + LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL;
+ zero = ai_zero + LD8KConstants.MP1;
+ error = mem_err + LD8KConstants.M;
- /* Static vectors to zero */
-/*
- set_zero(old_speech, LD8KConstants.L_TOTAL);
- set_zero(old_exc, PIT_MAX+L_INTERPOL);
- set_zero(old_wsp, PIT_MAX);
- set_zero(mem_syn, M);
- set_zero(mem_w, M);
- set_zero(mem_w0, M);
- set_zero(mem_err, M);
- set_zero(zero, L_SUBFR);
- sharp = SHARPMIN;
-*/
- sharp = LD8KConstants.SHARPMIN;
- /* Initialize lsp_old_q[] */
- System.arraycopy(lsp_old, 0, lsp_old_q, 0, LD8KConstants.M);
+ /* Static vectors to zero */
+ /*
+ * set_zero(old_speech, LD8KConstants.L_TOTAL); set_zero(old_exc,
PIT_MAX+L_INTERPOL); set_zero(old_wsp,
+ * PIT_MAX); set_zero(mem_syn, M); set_zero(mem_w, M); set_zero(mem_w0,
M); set_zero(mem_err, M); set_zero(zero,
+ * L_SUBFR); sharp = SHARPMIN;
+ */
+ sharp = LD8KConstants.SHARPMIN;
+ /* Initialize lsp_old_q[] */
+ System.arraycopy(lsp_old, 0, lsp_old_q, 0, LD8KConstants.M);
- quaLsp.lsp_encw_reset();
- tamingFunc.init_exc_err();
+ quaLsp.lsp_encw_reset();
+ tamingFunc.init_exc_err();
- return;
+ return;
}
-
+
public void loadSpeech(float[] newSpeech) {
- int i=239;
- for(int q=79; q>=0; q--) {
+ int i = 239;
+ for (int q = 79; q >= 0; q--) {
old_speech_array[i--] = newSpeech[q];
}
}
@@ -135,322 +130,351 @@
* coder_ld8k - encoder routine ( speech data should be in new_speech )
*----------------------------------------------------------------------------
*/
- public void coder_ld8k(
- int[] ana_array, int ana /* output: analysis parameters */
- )
- {
-
- /* LPC coefficients */
- float[] r = new float[LD8KConstants.MP1]; /*
Autocorrelations low and hi */
- float[] A_t = new float[(LD8KConstants.MP1)*2]; /* A(z)
unquantized for the 2 subframes */
- float[] Aq_t = new float[(LD8KConstants.MP1)*2]; /* A(z)
quantized for the 2 subframes */
- float[] Ap1 = new float[LD8KConstants.MP1]; /* A(z) with
spectral expansion */
- float[] Ap2 = new float[LD8KConstants.MP1]; /* A(z) with
spectral expansion */
- int A, Aq; /* Pointer on A_t and Aq_t */
+ public void coder_ld8k(int[] ana_array, int ana /*
+ * output: analysis parameters
+ */
+ ) {
- /* LSP coefficients */
- float[] lsp_new = new float[LD8KConstants.M];
- float[] lsp_new_q = new float[LD8KConstants.M]; /* LSPs at 2th
subframe */
- float[] lsf_int = new float[LD8KConstants.M]; /*
Interpolated LSF 1st subframe. */
- float[] lsf_new = new float[LD8KConstants.M];
+ /* LPC coefficients */
+ float[] r = new float[LD8KConstants.MP1]; /* Autocorrelations low and hi
*/
+ float[] A_t = new float[(LD8KConstants.MP1) * 2]; /*
+ * A(z) unquantized for the 2 subframes
+ */
+ float[] Aq_t = new float[(LD8KConstants.MP1) * 2]; /*
+ * A(z) quantized for the 2 subframes
+ */
+ float[] Ap1 = new float[LD8KConstants.MP1]; /*
+ * A(z) with spectral expansion
+ */
+ float[] Ap2 = new float[LD8KConstants.MP1]; /*
+ * A(z) with spectral expansion
+ */
+ int A, Aq; /* Pointer on A_t and Aq_t */
- /* Variable added for adaptive gamma1 and gamma2 of the PWF */
+ /* LSP coefficients */
+ float[] lsp_new = new float[LD8KConstants.M];
+ float[] lsp_new_q = new float[LD8KConstants.M]; /* LSPs at 2th subframe
*/
+ float[] lsf_int = new float[LD8KConstants.M]; /*
+ * Interpolated LSF 1st subframe.
+ */
+ float[] lsf_new = new float[LD8KConstants.M];
- float[] rc = new float[LD8KConstants.M]; /*
Reflection coefficients */
- float[] gamma1 = new float[2]; /* Gamma1 for 1st and 2nd
subframes */
- float[] gamma2 = new float[2]; /* Gamma2 for 1st and 2nd
subframes */
+ /* Variable added for adaptive gamma1 and gamma2 of the PWF */
- /* Other vectors */
- float[] synth = new float[LD8KConstants.L_FRAME]; /* Buffer for
synthesis speech */
- float[] h1 = new float[LD8KConstants.L_SUBFR]; /* Impulse
response h1[] */
- float[] xn = new float[LD8KConstants.L_SUBFR]; /* Target
vector for pitch search */
- float[] xn2 = new float[LD8KConstants.L_SUBFR]; /* Target
vector for codebook search */
- float[] code = new float[LD8KConstants.L_SUBFR]; /* Fixed
codebook excitation */
- float[] y1 = new float[LD8KConstants.L_SUBFR]; /* Filtered
adaptive excitation */
- float[] y2 = new float[LD8KConstants.L_SUBFR]; /* Filtered
fixed codebook excitation */
- float[] g_coeff = new float[5]; /* Correlations between xn,
y1, & y2:
- <y1,y1>, <xn,y1>, <y2,y2>,
<xn,y2>,<y1,y2>*/
+ float[] rc = new float[LD8KConstants.M]; /* Reflection coefficients */
+ float[] gamma1 = new float[2]; /* Gamma1 for 1st and 2nd subframes */
+ float[] gamma2 = new float[2]; /* Gamma2 for 1st and 2nd subframes */
- /* Scalars */
+ /* Other vectors */
+ float[] synth = new float[LD8KConstants.L_FRAME]; /*
+ * Buffer for synthesis speech
+ */
+ float[] h1 = new float[LD8KConstants.L_SUBFR]; /* Impulse response h1[]
*/
+ float[] xn = new float[LD8KConstants.L_SUBFR]; /*
+ * Target vector for pitch search
+ */
+ float[] xn2 = new float[LD8KConstants.L_SUBFR]; /*
+ * Target vector for codebook search
+ */
+ float[] code = new float[LD8KConstants.L_SUBFR]; /*
+ * Fixed codebook excitation
+ */
+ float[] y1 = new float[LD8KConstants.L_SUBFR]; /*
+ * Filtered adaptive excitation
+ */
+ float[] y2 = new float[LD8KConstants.L_SUBFR]; /*
+ * Filtered fixed codebook excitation
+ */
+ float[] g_coeff = new float[5]; /*
+ * Correlations between xn, y1, & y2: <y1,y1>, <xn,y1>, <y2,y2>,
<xn,y2>,<y1,y2>
+ */
- int i, j, i_gamma, i_subfr;
- int T_op, t0;
- IntegerPointer t0_frac = new IntegerPointer();
- IntegerPointer t0_min = new IntegerPointer();
- IntegerPointer t0_max = new IntegerPointer();
- int index, taming;
- float gain_pit, gain_code=0;
+ /* Scalars */
-
/*------------------------------------------------------------------------*
- * - Perform LPC analysis:
*
- * * autocorrelation + lag windowing
*
- * * Levinson-durbin algorithm to find a[]
*
- * * convert a[] to lsp[]
*
- * * quantize and code the LSPs
*
- * * find the interpolated LSPs and convert to a[] for the 2
*
- * subframes (both quantized and unquantized)
*
-
*------------------------------------------------------------------------*/
+ int i, j, i_gamma, i_subfr;
+ int T_op, t0;
+ IntegerPointer t0_frac = new IntegerPointer();
+ IntegerPointer t0_min = new IntegerPointer();
+ IntegerPointer t0_max = new IntegerPointer();
+ int index, taming;
+ float gain_pit, gain_code = 0;
- /* LP analysis */
+
/*------------------------------------------------------------------------*
+ * - Perform LPC
analysis: *
+ * * autocorrelation + lag
windowing *
+ * * Levinson-durbin algorithm to find
a[] *
+ * * convert a[] to
lsp[] *
+ * * quantize and code the
LSPs *
+ * * find the interpolated LSPs and convert to a[] for the
2 *
+ * subframes (both quantized and
unquantized) *
+
*------------------------------------------------------------------------*/
- lpc.autocorr(ArrayUtils.subArray(old_speech_array, p_window),
LD8KConstants.M, r); /* Autocorrelations */
- lpc.lag_window(LD8KConstants.M, r); /* Lag
windowing */
-
- float[] tmp = ArrayUtils.subArray(A_t, LD8KConstants.MP1);
- lpc.levinson(r, tmp, rc); /* Levinson Durbin */
- ArrayUtils.replace(A_t, LD8KConstants.MP1, tmp);
-
- lpc.az_lsp(tmp, lsp_new, lsp_old); /* From A(z) to lsp */
- ArrayUtils.replace(A_t, LD8KConstants.MP1, tmp);
- /* LSP quantization */
+ /* LP analysis */
- quaLsp.qua_lsp(lsp_new, lsp_new_q, ana_array);
- ana += 2; /* Advance analysis parameters
pointer */
+ lpc.autocorr(ArrayUtils.subArray(old_speech_array, p_window),
LD8KConstants.M, r); /* Autocorrelations */
+ lpc.lag_window(LD8KConstants.M, r); /* Lag windowing */
- /*--------------------------------------------------------------------*
- * Find interpolated LPC parameters in all subframes (both quantized *
- * and unquantized). *
- * The interpolated parameters are in array A_t[] of size (M+1)*4 *
- * and the quantized interpolated parameters are in array Aq_t[] *
- *--------------------------------------------------------------------*/
+ float[] tmp = ArrayUtils.subArray(A_t, LD8KConstants.MP1);
+ lpc.levinson(r, tmp, rc); /* Levinson Durbin */
+ ArrayUtils.replace(A_t, LD8KConstants.MP1, tmp);
- LpcFunc.int_lpc(lsp_old, lsp_new, lsf_int, lsf_new, A_t);
- LpcFunc.int_qlpc(lsp_old_q, lsp_new_q, Aq_t);
+ lpc.az_lsp(tmp, lsp_new, lsp_old); /* From A(z) to lsp */
+ ArrayUtils.replace(A_t, LD8KConstants.MP1, tmp);
+ /* LSP quantization */
- /* update the LSPs for the next frame */
+ quaLsp.qua_lsp(lsp_new, lsp_new_q, ana_array);
+ ana += 2; /* Advance analysis parameters pointer */
- for(i=0; i<LD8KConstants.M; i++)
- {
- lsp_old[i] = lsp_new[i];
- lsp_old_q[i] = lsp_new_q[i];
- }
+ /*--------------------------------------------------------------------*
+ * Find interpolated LPC parameters in all subframes (both quantized *
+ * and unquantized). *
+ * The interpolated parameters are in array A_t[] of size (M+1)*4 *
+ * and the quantized interpolated parameters are in array Aq_t[] *
+ *--------------------------------------------------------------------*/
- /*----------------------------------------------------------------------*
- * - Find the weighting factors *
-
*----------------------------------------------------------------------*/
+ LpcFunc.int_lpc(lsp_old, lsp_new, lsf_int, lsf_new, A_t);
+ LpcFunc.int_qlpc(lsp_old_q, lsp_new_q, Aq_t);
- pwf.perc_var(gamma1, gamma2, lsf_int, lsf_new, rc);
+ /* update the LSPs for the next frame */
+ for (i = 0; i < LD8KConstants.M; i++) {
+ lsp_old[i] = lsp_new[i];
+ lsp_old_q[i] = lsp_new_q[i];
+ }
- /*----------------------------------------------------------------------*
- * - Find the weighted input speech w_sp[] for the whole speech frame *
- * - Find the open-loop pitch delay for the whole speech frame *
- * - Set the range for searching closed-loop pitch in 1st subframe *
-
*----------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------*
+ * - Find the weighting factors *
+
*----------------------------------------------------------------------*/
- LpcFunc.weight_az(A_t, 0, gamma1[0], LD8KConstants.M, Ap1, 0);
- LpcFunc.weight_az(A_t, 0, gamma2[0], LD8KConstants.M, Ap2, 0);
-
- Filter.residu(Ap1, 0, old_speech_array, speech, old_wsp_array, wsp,
LD8KConstants.L_SUBFR);
- Filter.syn_filt(Ap2, 0, old_wsp_array, wsp, old_wsp_array, wsp,
LD8KConstants.L_SUBFR, mem_w, 0, 1);
-
- LpcFunc.weight_az(A_t, LD8KConstants.MP1, gamma1[1], LD8KConstants.M,
Ap1, 0);
- LpcFunc.weight_az(A_t, LD8KConstants.MP1, gamma2[1], LD8KConstants.M,
Ap2, 0);
- Filter.residu(Ap1, 0, old_speech_array, speech + LD8KConstants.L_SUBFR,
old_wsp_array, wsp + LD8KConstants.L_SUBFR, LD8KConstants.L_SUBFR);
- Filter.syn_filt(Ap2, 0, old_wsp_array, wsp + LD8KConstants.L_SUBFR,
old_wsp_array, wsp + LD8KConstants.L_SUBFR, LD8KConstants.L_SUBFR, mem_w,
0, 1);
-
- /* Find open loop pitch lag for whole speech frame */
+ pwf.perc_var(gamma1, gamma2, lsf_int, lsf_new, rc);
+
+ /*----------------------------------------------------------------------*
+ * - Find the weighted input speech w_sp[] for the whole speech frame *
+ * - Find the open-loop pitch delay for the whole speech frame *
+ * - Set the range for searching closed-loop pitch in 1st subframe *
+
*----------------------------------------------------------------------*/
- T_op = Pitch.pitch_ol(old_wsp_array, wsp, LD8KConstants.PIT_MIN,
LD8KConstants.PIT_MAX, LD8KConstants.L_FRAME);
+ LpcFunc.weight_az(A_t, 0, gamma1[0], LD8KConstants.M, Ap1, 0);
+ LpcFunc.weight_az(A_t, 0, gamma2[0], LD8KConstants.M, Ap2, 0);
- /* range for closed loop pitch search in 1st subframe */
+ Filter.residu(Ap1, 0, old_speech_array, speech, old_wsp_array, wsp,
LD8KConstants.L_SUBFR);
+ Filter.syn_filt(Ap2, 0, old_wsp_array, wsp, old_wsp_array, wsp,
LD8KConstants.L_SUBFR, mem_w, 0, 1);
- t0_min.value = T_op - 3;
- if (t0_min.value < LD8KConstants.PIT_MIN) t0_min.value =
(int)LD8KConstants.PIT_MIN;
- t0_max.value = t0_min.value + 6;
- if (t0_max.value > LD8KConstants.PIT_MAX)
- {
- t0_max.value = (int)LD8KConstants.PIT_MAX;
- t0_min.value = t0_max.value - 6;
- }
+ LpcFunc.weight_az(A_t, LD8KConstants.MP1, gamma1[1], LD8KConstants.M,
Ap1, 0);
+ LpcFunc.weight_az(A_t, LD8KConstants.MP1, gamma2[1], LD8KConstants.M,
Ap2, 0);
+ Filter.residu(Ap1, 0, old_speech_array, speech + LD8KConstants.L_SUBFR,
old_wsp_array, wsp
+ + LD8KConstants.L_SUBFR, LD8KConstants.L_SUBFR);
+ Filter.syn_filt(Ap2, 0, old_wsp_array, wsp + LD8KConstants.L_SUBFR,
old_wsp_array, wsp + LD8KConstants.L_SUBFR,
+ LD8KConstants.L_SUBFR, mem_w, 0, 1);
-
/*------------------------------------------------------------------------*
- * Loop for every subframe in the analysis
frame *
-
*------------------------------------------------------------------------*
- * To find the pitch and innovation parameters. The subframe size
is *
- * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR
times. *
- * - find the weighted LPC
coefficients *
- * - find the LPC residual
signal *
- * - compute the target signal for pitch
search *
- * - compute impulse response of weighted synthesis filter
(h1[]) *
- * - find the closed-loop pitch
parameters *
- * - encode the pitch
delay *
- * - update the impulse response h1[] by including fixed-gain
pitch *
- * - find target vector for codebook
search *
- * - codebook
search *
- * - encode codebook
address *
- * - VQ of pitch and codebook
gains *
- * - find synthesis
speech *
- * - update states of weighting
filter *
-
*------------------------------------------------------------------------*/
+ /* Find open loop pitch lag for whole speech frame */
- A = 0;//A_t; /* pointer to interpolated LPC parameters */
- Aq = 0;//Aq_t; /* pointer to interpolated quantized LPC parameters */
+ T_op = Pitch.pitch_ol(old_wsp_array, wsp, LD8KConstants.PIT_MIN,
LD8KConstants.PIT_MAX, LD8KConstants.L_FRAME);
- i_gamma = 0;
+ /* range for closed loop pitch search in 1st subframe */
- for (i_subfr = 0; i_subfr < LD8KConstants.L_FRAME; i_subfr +=
LD8KConstants.L_SUBFR)
- {
- /*---------------------------------------------------------------*
- * Find the weighted LPC coefficients for the weighting filter. *
- *---------------------------------------------------------------*/
+ t0_min.value = T_op - 3;
+ if (t0_min.value < LD8KConstants.PIT_MIN)
+ t0_min.value = (int) LD8KConstants.PIT_MIN;
+ t0_max.value = t0_min.value + 6;
+ if (t0_max.value > LD8KConstants.PIT_MAX) {
+ t0_max.value = (int) LD8KConstants.PIT_MAX;
+ t0_min.value = t0_max.value - 6;
+ }
- LpcFunc.weight_az(A_t, A, gamma1[i_gamma], LD8KConstants.M, Ap1, 0);
- LpcFunc.weight_az(A_t, A, gamma2[i_gamma], LD8KConstants.M, Ap2, 0);
- i_gamma++;
+
/*------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis
frame *
+
*------------------------------------------------------------------------*
+ * To find the pitch and innovation parameters. The subframe size
is *
+ * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR
times. *
+ * - find the weighted LPC
coefficients *
+ * - find the LPC residual
signal *
+ * - compute the target signal for pitch
search *
+ * - compute impulse response of weighted synthesis filter
(h1[]) *
+ * - find the closed-loop pitch
parameters *
+ * - encode the pitch
delay *
+ * - update the impulse response h1[] by including fixed-gain
pitch *
+ * - find target vector for codebook
search *
+ * - codebook
search *
+ * - encode codebook
address *
+ * - VQ of pitch and codebook
gains *
+ * - find synthesis
speech *
+ * - update states of weighting
filter *
+
*------------------------------------------------------------------------*/
- /*---------------------------------------------------------------*
- * Compute impulse response, h1[], of weighted synthesis filter *
- *---------------------------------------------------------------*/
+ A = 0;// A_t; /* pointer to interpolated LPC parameters */
+ Aq = 0;// Aq_t; /* pointer to interpolated quantized LPC parameters */
- for (i = 0; i <= LD8KConstants.M; i++) ai_zero_array[ai_zero+i] =
Ap1[i];
- Filter.syn_filt(Aq_t, Aq, ai_zero_array, ai_zero, h1, 0,
LD8KConstants.L_SUBFR, ai_zero_array, zero, 0);
- Filter.syn_filt(Ap2, 0, h1, 0, h1, 0, LD8KConstants.L_SUBFR,
ai_zero_array, zero, 0);
+ i_gamma = 0;
-
/*------------------------------------------------------------------------*
-
* *
- * Find the target vector for pitch
search: *
- *
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
-
* *
- * |------|
res[n] *
- * speech[n]---| A(z) |
-------- *
- * |------| | |--------| error[n] |
------| *
- * zero -- (-)--| 1/A(z) |-----------| W(z) |--
target *
- * exc |--------| |
------| *
-
* *
- * Instead of subtracting the zero-input response of filters
from *
- * the weighted input speech, the above configuration is used
to *
- * compute the target vector. This configuration gives better
performance *
- * with fixed-point implementation. The memory of 1/A(z) is updated
by *
- * filtering (res[n]-exc[n]) through 1/A(z), or simply by
subtracting *
- * the synthesis speech from the input
speech: *
- * error[n] = speech[n] -
syn[n]. *
- * The memory of W(z) is updated by filtering error[n] through
W(z), *
- * or more simply by subtracting the filtered adaptive and
fixed *
- * codebook excitations from the
target: *
- * target[n] - gain_pit*y1[n] -
gain_code*y2[n] *
- * as these signals are already
available. *
-
* *
-
*------------------------------------------------------------------------*/
+ for (i_subfr = 0; i_subfr < LD8KConstants.L_FRAME; i_subfr +=
LD8KConstants.L_SUBFR) {
+ /*---------------------------------------------------------------*
+ * Find the weighted LPC coefficients for the weighting filter. *
+ *---------------------------------------------------------------*/
+ LpcFunc.weight_az(A_t, A, gamma1[i_gamma], LD8KConstants.M, Ap1, 0);
+ LpcFunc.weight_az(A_t, A, gamma2[i_gamma], LD8KConstants.M, Ap2, 0);
+ i_gamma++;
- Filter.residu(Aq_t, Aq, old_speech_array, speech + i_subfr,
old_exc_array, exc + i_subfr, LD8KConstants.L_SUBFR); /* LPC residual */
+ /*---------------------------------------------------------------*
+ * Compute impulse response, h1[], of weighted synthesis filter *
+ *---------------------------------------------------------------*/
- Filter.syn_filt(Aq_t, Aq, old_exc_array, exc+i_subfr, mem_err_array,
error, LD8KConstants.L_SUBFR, mem_err_array, mem_err, 0);
+ for (i = 0; i <= LD8KConstants.M; i++)
+ ai_zero_array[ai_zero + i] = Ap1[i];
+ Filter.syn_filt(Aq_t, Aq, ai_zero_array, ai_zero, h1, 0,
LD8KConstants.L_SUBFR, ai_zero_array, zero, 0);
+ Filter.syn_filt(Ap2, 0, h1, 0, h1, 0, LD8KConstants.L_SUBFR,
ai_zero_array, zero, 0);
- Filter.residu(Ap1, 0, mem_err_array, error, xn, 0,
LD8KConstants.L_SUBFR);
+
/*------------------------------------------------------------------------*
+
* *
+ * Find the target vector for pitch
search: *
+ *
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
+
* *
+ * |------|
res[n] *
+ * speech[n]---| A(z) |
-------- *
+ * |------| | |--------| error[n] |
------| *
+ * zero -- (-)--| 1/A(z) |-----------| W(z) |--
target *
+ * exc |--------| |
------| *
+
* *
+ * Instead of subtracting the zero-input response of filters
from *
+ * the weighted input speech, the above configuration is used
to *
+ * compute the target vector. This configuration gives better
performance *
+ * with fixed-point implementation. The memory of 1/A(z) is updated
by *
+ * filtering (res[n]-exc[n]) through 1/A(z), or simply by
subtracting *
+ * the synthesis speech from the input
speech: *
+ * error[n] = speech[n] -
syn[n]. *
+ * The memory of W(z) is updated by filtering error[n] through
W(z), *
+ * or more simply by subtracting the filtered adaptive and
fixed *
+ * codebook excitations from the
target: *
+ * target[n] - gain_pit*y1[n] -
gain_code*y2[n] *
+ * as these signals are already
available. *
+
* *
+
*------------------------------------------------------------------------*/
- Filter.syn_filt(Ap2, 0, xn, 0, xn, 0, LD8KConstants.L_SUBFR, mem_w0,
0, 0); /* target signal xn[]*/
+ Filter.residu(Aq_t, Aq, old_speech_array, speech + i_subfr,
old_exc_array, exc + i_subfr,
+ LD8KConstants.L_SUBFR); /*
+ * LPC residual
+ */
-
/*----------------------------------------------------------------------*
- * Closed-loop fractional pitch
search *
-
*----------------------------------------------------------------------*/
+ Filter.syn_filt(Aq_t, Aq, old_exc_array, exc + i_subfr, mem_err_array,
error, LD8KConstants.L_SUBFR,
+ mem_err_array, mem_err, 0);
- t0 = Pitch.pitch_fr3(old_exc_array,exc+i_subfr, xn, 0, h1, 0,
LD8KConstants.L_SUBFR, t0_min.value, t0_max.value,
- i_subfr, t0_frac);
+ Filter.residu(Ap1, 0, mem_err_array, error, xn, 0,
LD8KConstants.L_SUBFR);
+ Filter.syn_filt(Ap2, 0, xn, 0, xn, 0, LD8KConstants.L_SUBFR, mem_w0, 0,
0); /* target signal xn[] */
- index = Pitch.enc_lag3(t0, t0_frac.value, t0_min,
t0_max,LD8KConstants.PIT_MIN,LD8KConstants.PIT_MAX,i_subfr);
+
/*----------------------------------------------------------------------*
+ * Closed-loop fractional pitch search
*
+
*----------------------------------------------------------------------*/
- ana_array[ana++] = index;
- if (i_subfr == 0)
- ana_array[ana++] = PParity.parity_pitch(index);
+ t0 = Pitch.pitch_fr3(old_exc_array, exc + i_subfr, xn, 0, h1, 0,
LD8KConstants.L_SUBFR, t0_min.value,
+ t0_max.value, i_subfr, t0_frac);
+ index = Pitch.enc_lag3(t0, t0_frac.value, t0_min, t0_max,
LD8KConstants.PIT_MIN, LD8KConstants.PIT_MAX,
+ i_subfr);
- /*-----------------------------------------------------------------*
- * - find unity gain pitch excitation (adaptive codebook entry) *
- * with fractional interpolation. *
- * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) *
- * - compute pitch gain and limit between 0 and 1.2 *
- * - update target vector for codebook search *
- * - find LTP residual. *
- *-----------------------------------------------------------------*/
+ ana_array[ana++] = index;
+ if (i_subfr == 0)
+ ana_array[ana++] = PParity.parity_pitch(index);
- PredLt.pred_lt_3(old_exc_array,exc + i_subfr, t0, t0_frac.value,
LD8KConstants.L_SUBFR);
+ /*-----------------------------------------------------------------*
+ * - find unity gain pitch excitation (adaptive codebook entry) *
+ * with fractional interpolation. *
+ * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) *
+ * - compute pitch gain and limit between 0 and 1.2 *
+ * - update target vector for codebook search *
+ * - find LTP residual. *
+ *-----------------------------------------------------------------*/
- Filter.convolve(old_exc_array,exc+i_subfr, h1, 0, y1, 0,
LD8KConstants.L_SUBFR);
+ PredLt.pred_lt_3(old_exc_array, exc + i_subfr, t0, t0_frac.value,
LD8KConstants.L_SUBFR);
- gain_pit = Pitch.g_pitch(xn, 0, y1, 0, g_coeff, 0,
LD8KConstants.L_SUBFR);
+ Filter.convolve(old_exc_array, exc + i_subfr, h1, 0, y1, 0,
LD8KConstants.L_SUBFR);
- /* clip pitch gain if taming is necessary */
- taming = tamingFunc.test_err(t0, t0_frac.value);
+ gain_pit = Pitch.g_pitch(xn, 0, y1, 0, g_coeff, 0,
LD8KConstants.L_SUBFR);
- if( taming == 1){
- if ( gain_pit> LD8KConstants.GPCLIP) {
- gain_pit = LD8KConstants.GPCLIP;
- }
- }
+ /* clip pitch gain if taming is necessary */
+ taming = tamingFunc.test_err(t0, t0_frac.value);
- for (i = 0; i < LD8KConstants.L_SUBFR; i++)
- xn2[i] = xn[i] - y1[i]*gain_pit;
+ if (taming == 1) {
+ if (gain_pit > LD8KConstants.GPCLIP) {
+ gain_pit = LD8KConstants.GPCLIP;
+ }
+ }
- /*-----------------------------------------------------*
- * - Innovative codebook search. *
- *-----------------------------------------------------*/
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ xn2[i] = xn[i] - y1[i] * gain_pit;
- IntegerPointer tmpi = new IntegerPointer(i);
- index = acelp.ACELP_codebook(xn2, h1, t0, sharp, i_subfr, code, y2,
tmpi);
- i = tmpi.value;
- ana_array[ana++] = index; /* Positions index */
- ana_array[ana++] = i; /* Signs index */
+ /*-----------------------------------------------------*
+ * - Innovative codebook search. *
+ *-----------------------------------------------------*/
+ IntegerPointer tmpi = new IntegerPointer(i);
+ index = acelp.ACELP_codebook(xn2, h1, t0, sharp, i_subfr, code, y2,
tmpi);
+ i = tmpi.value;
+ ana_array[ana++] = index; /* Positions index */
+ ana_array[ana++] = i; /* Signs index */
- /*-----------------------------------------------------*
- * - Quantization of gains. *
- *-----------------------------------------------------*/
- CorFunc.corr_xy2(xn, y1, y2, g_coeff);
+ /*-----------------------------------------------------*
+ * - Quantization of gains. *
+ *-----------------------------------------------------*/
+ CorFunc.corr_xy2(xn, y1, y2, g_coeff);
- FloatPointer tmpgain_pit = new FloatPointer(gain_pit), tmpgain_code =
new FloatPointer(gain_code);
- ana_array[ana++] = quaGain.qua_gain(code, g_coeff,
LD8KConstants.L_SUBFR, tmpgain_pit, tmpgain_code, taming );
- gain_pit = tmpgain_pit.value; gain_code = tmpgain_code.value;
-
- /*------------------------------------------------------------*
- * - Update pitch sharpening "sharp" with quantized gain_pit *
- *------------------------------------------------------------*/
+ FloatPointer tmpgain_pit = new FloatPointer(gain_pit), tmpgain_code =
new FloatPointer(gain_code);
+ ana_array[ana++] = quaGain
+ .qua_gain(code, g_coeff, LD8KConstants.L_SUBFR, tmpgain_pit,
tmpgain_code, taming);
+ gain_pit = tmpgain_pit.value;
+ gain_code = tmpgain_code.value;
- sharp = gain_pit;
- if (sharp > LD8KConstants.SHARPMAX) sharp = LD8KConstants.SHARPMAX;
- if (sharp < LD8KConstants.SHARPMIN) sharp = LD8KConstants.SHARPMIN;
- /*------------------------------------------------------*
- * - Find the total excitation *
- * - find synthesis speech corresponding to exc[] *
- * - update filters' memories for finding the target *
- * vector in the next subframe *
- * (update error[-m..-1] and mem_w0[]) *
- * update error function for taming process *
- *------------------------------------------------------*/
+ /*------------------------------------------------------------*
+ * - Update pitch sharpening "sharp" with quantized gain_pit *
+ *------------------------------------------------------------*/
- for (i = 0; i < LD8KConstants.L_SUBFR; i++)
- old_exc_array[exc+i+i_subfr] =
gain_pit*old_exc_array[exc+i+i_subfr] + gain_code*code[i];
+ sharp = gain_pit;
+ if (sharp > LD8KConstants.SHARPMAX)
+ sharp = LD8KConstants.SHARPMAX;
+ if (sharp < LD8KConstants.SHARPMIN)
+ sharp = LD8KConstants.SHARPMIN;
+ /*------------------------------------------------------*
+ * - Find the total excitation *
+ * - find synthesis speech corresponding to exc[] *
+ * - update filters' memories for finding the target *
+ * vector in the next subframe *
+ * (update error[-m..-1] and mem_w0[]) *
+ * update error function for taming process *
+ *------------------------------------------------------*/
- tamingFunc.update_exc_err(gain_pit, t0);
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ old_exc_array[exc + i + i_subfr] = gain_pit * old_exc_array[exc + i +
i_subfr] + gain_code * code[i];
- Filter.syn_filt(Aq_t, Aq, old_exc_array, exc+i_subfr, synth, i_subfr,
LD8KConstants.L_SUBFR, mem_syn, 0, 1);
+ tamingFunc.update_exc_err(gain_pit, t0);
- for (i = LD8KConstants.L_SUBFR-LD8KConstants.M, j = 0; i <
LD8KConstants.L_SUBFR; i++, j++)
- {
- mem_err_array[mem_err+j] = old_speech_array[speech+i_subfr+i] -
synth[i_subfr+i];
- mem_w0[j] = xn[i] - gain_pit*y1[i] - gain_code*y2[i];
- }
- A += LD8KConstants.MP1; /* interpolated LPC parameters for next
subframe */
- Aq += LD8KConstants.MP1;
+ Filter.syn_filt(Aq_t, Aq, old_exc_array, exc + i_subfr, synth, i_subfr,
LD8KConstants.L_SUBFR, mem_syn, 0,
+ 1);
- }
+ for (i = LD8KConstants.L_SUBFR - LD8KConstants.M, j = 0; i <
LD8KConstants.L_SUBFR; i++, j++) {
+ mem_err_array[mem_err + j] = old_speech_array[speech + i_subfr + i] -
synth[i_subfr + i];
+ mem_w0[j] = xn[i] - gain_pit * y1[i] - gain_code * y2[i];
+ }
+ A += LD8KConstants.MP1; /*
+ * interpolated LPC parameters for next subframe
+ */
+ Aq += LD8KConstants.MP1;
- /*--------------------------------------------------*
- * Update signal for next frame. *
- * -> shift to the left by L_FRAME: *
- * speech[], wsp[] and exc[] *
- *--------------------------------------------------*/
+ }
- Util.copy(old_speech_array,old_speech+LD8KConstants.L_FRAME,
old_speech_array, old_speech, LD8KConstants.L_TOTAL-LD8KConstants.L_FRAME);
- Util.copy(old_wsp_array, old_wsp+LD8KConstants.L_FRAME, old_wsp_array,
old_wsp, LD8KConstants.PIT_MAX);
- Util.copy(old_exc_array, old_exc+LD8KConstants.L_FRAME, old_exc_array,
old_exc, LD8KConstants.PIT_MAX+LD8KConstants.L_INTERPOL);
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> shift to the left by L_FRAME: *
+ * speech[], wsp[] and exc[] *
+ *--------------------------------------------------*/
+ Util.copy(old_speech_array, old_speech + LD8KConstants.L_FRAME,
old_speech_array, old_speech,
+ LD8KConstants.L_TOTAL - LD8KConstants.L_FRAME);
+ Util.copy(old_wsp_array, old_wsp + LD8KConstants.L_FRAME, old_wsp_array,
old_wsp, LD8KConstants.PIT_MAX);
+ Util.copy(old_exc_array, old_exc + LD8KConstants.L_FRAME, old_exc_array,
old_exc, LD8KConstants.PIT_MAX
+ + LD8KConstants.L_INTERPOL);
- return;
+ return;
}
-
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/CorFunc.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/CorFunc.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class CorFunc {
@@ -7,29 +8,32 @@
* corr_xy2 - compute the correlation products needed for gain computation
*----------------------------------------------------------------------------
*/
- public static void corr_xy2(
- float xn[], /* input : target vector x[0:l_subfr] */
- float y1[], /* input : filtered adaptive codebook vector */
- float y2[], /* input : filtered 1st codebook innovation */
- float g_coeff[] /* output: <y2,y2> , -2<xn,y2> , and 2<y1,y2>*/
- )
- {
- float y2y2, xny2, y1y2;
- int i;
+ public static void corr_xy2(float xn[], /*
+ * input : target vector x[0:l_subfr]
+ */
+ float y1[], /* input : filtered adaptive codebook vector */
+ float y2[], /* input : filtered 1st codebook innovation */
+ float g_coeff[] /* output: <y2,y2> , -2<xn,y2> , and 2<y1,y2> */
+ ) {
+ float y2y2, xny2, y1y2;
+ int i;
- y2y2= (float)0.01;
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) y2y2 += y2[i]*y2[i];
- g_coeff[2] = y2y2 ;
+ y2y2 = (float) 0.01;
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ y2y2 += y2[i] * y2[i];
+ g_coeff[2] = y2y2;
- xny2 = (float)0.01;
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) xny2+= xn[i]*y2[i];
- g_coeff[3] = (float)-2.0* xny2;
+ xny2 = (float) 0.01;
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ xny2 += xn[i] * y2[i];
+ g_coeff[3] = (float) -2.0 * xny2;
- y1y2 = (float)0.01;
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) y1y2 += y1[i]*y2[i];
- g_coeff[4] = (float)2.0* y1y2 ;
+ y1y2 = (float) 0.01;
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ y1y2 += y1[i] * y2[i];
+ g_coeff[4] = (float) 2.0 * y1y2;
- return;
+ return;
}
@@ -39,25 +43,21 @@
* Compute correlations of input response h[] with the target vector
X[]. *
*--------------------------------------------------------------------------*/
- public static void cor_h_x(
- float h[], /* (i) :Impulse response of filters */
- float x[], /* (i) :Target vector */
- float d[] /* (o) :Correlations between h[] and x[] */
- )
- {
- int i, j;
- float s;
+ public static void cor_h_x(float h[], /* (i) :Impulse response of filters
*/
+ float x[], /* (i) :Target vector */
+ float d[] /* (o) :Correlations between h[] and x[] */
+ ) {
+ int i, j;
+ float s;
- for (i = 0; i < LD8KConstants.L_SUBFR; i++)
- {
- s = (float)0.0;
- for (j = i; j < LD8KConstants.L_SUBFR; j++)
- s += x[j] * h[j-i];
- d[i] = s;
- }
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ s = (float) 0.0;
+ for (j = i; j < LD8KConstants.L_SUBFR; j++)
+ s += x[j] * h[j - i];
+ d[i] = s;
+ }
- return;
+ return;
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/DecAcelp.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/DecAcelp.java Thu Feb
21 09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class DecAcelp {
@@ -9,55 +10,52 @@
* Algebraic codebook decoder. *
*----------------------------------------------------------*/
- public static void decod_ACELP(
- int sign, /* input : signs of 4 pulses */
- int index, /* input : positions of 4 pulses */
- float cod[] /* output: innovative codevector */
- )
- {
- int pos[] = new int[4];
- int i, j;
+ public static void decod_ACELP(int sign, /* input : signs of 4 pulses */
+ int index, /* input : positions of 4 pulses */
+ float cod[] /* output: innovative codevector */
+ ) {
+ int pos[] = new int[4];
+ int i, j;
- /* decode the positions of 4 pulses */
+ /* decode the positions of 4 pulses */
- i = index & 7;
- pos[0] = i*5;
+ i = index & 7;
+ pos[0] = i * 5;
- index >>= 3;
- i = index & 7;
- pos[1] = i*5 + 1;
+ index >>= 3;
+ i = index & 7;
+ pos[1] = i * 5 + 1;
- index >>= 3;
- i = index & 7;
- pos[2] = i*5 + 2;
+ index >>= 3;
+ i = index & 7;
+ pos[2] = i * 5 + 2;
- index >>= 3;
- j = index & 1;
- index >>= 1;
- i = index & 7;
- pos[3] = i*5 + 3 + j;
+ index >>= 3;
+ j = index & 1;
+ index >>= 1;
+ i = index & 7;
+ pos[3] = i * 5 + 3 + j;
- /* find the algebraic codeword */
+ /* find the algebraic codeword */
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) cod[i] = 0;
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++)
+ cod[i] = 0;
- /* decode the signs of 4 pulses */
+ /* decode the signs of 4 pulses */
- for (j=0; j<4; j++)
- {
+ for (j = 0; j < 4; j++) {
- i = sign & 1;
- sign >>= 1;
+ i = sign & 1;
+ sign >>= 1;
- if (i != 0) {
- cod[pos[j]] = (float)1.0;
- }
- else {
- cod[pos[j]] = (float)-1.0;
- }
- }
+ if (i != 0) {
+ cod[pos[j]] = (float) 1.0;
+ } else {
+ cod[pos[j]] = (float) -1.0;
+ }
+ }
- return;
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/DecGain.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/DecGain.java Thu Feb 21
09:21:48 2013
@@ -1,69 +1,68 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class DecGain {
- float past_qua_en[]=new
float[]{(float)-14.0,(float)-14.0,(float)-14.0,(float)-14.0};
- public void dec_gain(
- int index, /* input : quantizer index */
- float code[], /* input : fixed code book vector */
- int l_subfr, /* input : subframe size */
- int bfi, /* input : bad frame indicator good = 0 */
- FloatPointer gain_pit, /* output: quantized acb gain */
- FloatPointer gain_code /* output: quantized fcb gain */
- )
- {
-
+ float past_qua_en[] = new float[] { (float) -14.0, (float) -14.0, (float)
-14.0, (float) -14.0 };
- int index1,index2;
- float g_code;
- FloatPointer gcode0 = new FloatPointer();
+ public void dec_gain(int index, /* input : quantizer index */
+ float code[], /* input : fixed code book vector */
+ int l_subfr, /* input : subframe size */
+ int bfi, /* input : bad frame indicator good = 0 */
+ FloatPointer gain_pit, /* output: quantized acb gain */
+ FloatPointer gain_code /* output: quantized fcb gain */
+ ) {
- /*----------------- Test erasure ---------------*/
- if (bfi != 0)
- {
- gain_pit.value *= (float)0.9;
- if(gain_pit.value > (float)0.9) gain_pit.value=(float)0.9;
- gain_code.value *= (float)0.98;
+ int index1, index2;
+ float g_code;
+ FloatPointer gcode0 = new FloatPointer();
- /*----------------------------------------------*
- * update table of past quantized energies *
- * (frame erasure) *
- *----------------------------------------------*/
- GainPred.gain_update_erasure(past_qua_en);
+ /*----------------- Test erasure ---------------*/
+ if (bfi != 0) {
+ gain_pit.value *= (float) 0.9;
+ if (gain_pit.value > (float) 0.9)
+ gain_pit.value = (float) 0.9;
+ gain_code.value *= (float) 0.98;
+
+ /*----------------------------------------------*
+ * update table of past quantized energies *
+ * (frame erasure) *
+ *----------------------------------------------*/
+ GainPred.gain_update_erasure(past_qua_en);
- return;
- }
+ return;
+ }
- /*-------------- Decode pitch gain ---------------*/
+ /*-------------- Decode pitch gain ---------------*/
- index1 = TabLD8k.imap1[index/LD8KConstants.NCODE2] ;
- index2 = TabLD8k.imap2[index%LD8KConstants.NCODE2] ;
- gain_pit.value = TabLD8k.gbk1[index1][0]+TabLD8k.gbk2[index2][0] ;
+ index1 = TabLD8k.imap1[index / LD8KConstants.NCODE2];
+ index2 = TabLD8k.imap2[index % LD8KConstants.NCODE2];
+ gain_pit.value = TabLD8k.gbk1[index1][0] + TabLD8k.gbk2[index2][0];
- /*-------------- Decode codebook gain ---------------*/
+ /*-------------- Decode codebook gain ---------------*/
- /*---------------------------------------------------*
- *- energy due to innovation -*
- *- predicted energy -*
- *- predicted codebook gain => gcode0[exp_gcode0] -*
- *---------------------------------------------------*/
+ /*---------------------------------------------------*
+ *- energy due to innovation -*
+ *- predicted energy -*
+ *- predicted codebook gain => gcode0[exp_gcode0] -*
+ *---------------------------------------------------*/
- GainPred.gain_predict( past_qua_en, code, l_subfr, gcode0);
+ GainPred.gain_predict(past_qua_en, code, l_subfr, gcode0);
- /*-----------------------------------------------------------------*
- * *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0; *
- *-----------------------------------------------------------------*/
+ /*-----------------------------------------------------------------*
+ * *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0; *
+ *-----------------------------------------------------------------*/
- g_code = TabLD8k.gbk1[index1][1]+TabLD8k.gbk2[index2][1];
- gain_code.value = g_code * gcode0.value;
+ g_code = TabLD8k.gbk1[index1][1] + TabLD8k.gbk2[index2][1];
+ gain_code.value = g_code * gcode0.value;
- /*----------------------------------------------*
- * update table of past quantized energies *
- *----------------------------------------------*/
+ /*----------------------------------------------*
+ * update table of past quantized energies *
+ *----------------------------------------------*/
- GainPred.gain_update( past_qua_en, g_code);
+ GainPred.gain_update(past_qua_en, g_code);
- return;
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/DecLD8K.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/DecLD8K.java Thu Feb 21
09:21:48 2013
@@ -1,9 +1,9 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class DecLD8K {
-
/*---------------------------------------------------------------*
* Decoder constant parameters (defined in "ld8k.h") *
*---------------------------------------------------------------*
@@ -21,24 +21,23 @@
* Static memory allocation. *
*--------------------------------------------------------*/
- /* Excitation vector */
+ /* Excitation vector */
- float old_exc_array[] = new
float[LD8KConstants.L_FRAME+LD8KConstants.PIT_MAX+LD8KConstants.L_INTERPOL];
+ float old_exc_array[] = new float[LD8KConstants.L_FRAME +
LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL];
int exc;
- /* Lsp (Line spectral pairs) */
+ /* Lsp (Line spectral pairs) */
- float lsp_old[]= new float[]{
- (float)0.9595, (float)0.8413, (float)0.6549, (float)0.4154,
(float)0.1423,
- (float)-0.1423, (float)-0.4154, (float)-0.6549, (float)-0.8413,
(float)-0.9595};
+ float lsp_old[] = new float[] { (float) 0.9595, (float) 0.8413, (float)
0.6549, (float) 0.4154, (float) 0.1423,
+ (float) -0.1423, (float) -0.4154, (float) -0.6549, (float) -0.8413,
(float) -0.9595 };
- /* Filter's memory */
- float mem_syn[] = new float[LD8KConstants.M]; /* Filter's memory */
+ /* Filter's memory */
+ float mem_syn[] = new float[LD8KConstants.M]; /* Filter's memory */
- float sharp ; /* pitch sharpening of previous fr */
- int old_t0; /* integer delay of previous frame */
- FloatPointer gain_code = new FloatPointer(); /* fixed codebook
gain */
- FloatPointer gain_pitch = new FloatPointer(); /* adaptive codebook
gain */
+ float sharp; /* pitch sharpening of previous fr */
+ int old_t0; /* integer delay of previous frame */
+ FloatPointer gain_code = new FloatPointer(); /* fixed codebook gain */
+ FloatPointer gain_pitch = new FloatPointer(); /* adaptive codebook gain */
LspDec lspDec = new LspDec();
DecGain decGain = new DecGain();
@@ -46,192 +45,196 @@
* init_decod_ld8k - Initialization of variables for the decoder section.
*--------------------------------------------------------------------------
*/
- public void init_decod_ld8k()
- {
- /* Initialize static pointer */
- exc = 0 + LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL;
+ public void init_decod_ld8k() {
+ /* Initialize static pointer */
+ exc = 0 + LD8KConstants.PIT_MAX + LD8KConstants.L_INTERPOL;
- /* Static vectors to zero */
- Util.set_zero(old_exc_array,LD8KConstants.PIT_MAX +
LD8KConstants.L_INTERPOL);
- Util.set_zero(mem_syn, LD8KConstants.M);
+ /* Static vectors to zero */
+ Util.set_zero(old_exc_array, LD8KConstants.PIT_MAX +
LD8KConstants.L_INTERPOL);
+ Util.set_zero(mem_syn, LD8KConstants.M);
- sharp = LD8KConstants.SHARPMIN;
- old_t0 = 60;
- gain_code.value = (float)0.;
- gain_pitch.value = (float)0.;
+ sharp = LD8KConstants.SHARPMIN;
+ old_t0 = 60;
+ gain_code.value = (float) 0.;
+ gain_pitch.value = (float) 0.;
- lspDec.lsp_decw_reset();
+ lspDec.lsp_decw_reset();
- return;
+ return;
}
/*--------------------------------------------------------------------------
* decod_ld8k - decoder
*--------------------------------------------------------------------------
*/
- public void decod_ld8k(
- int parm[], int parms, /* input : synthesis parameters
(parm[0] = bfi) */
- int voicing, /* input : voicing decision from previous
frame */
- float synth[],int ss, /* output: synthesized
speech */
- float A_t[], /* output: two sets of A(z) coefficients
length=2*MP1 */
- IntegerPointer t0_first /* output: integer delay of first
subframe */
- )
- {
- int Az; /* Pointer to A_t (LPC coefficients) */
- float lsp_new[] = new float[LD8KConstants.M]; /*
LSPs */
- float code[] = new float[LD8KConstants.L_SUBFR]; /* algebraic
codevector */
+ public void decod_ld8k(int parm[], int parms, /*
+ * input : synthesis parameters (parm[0] = bfi)
+ */
+ int voicing, /* input : voicing decision from previous frame */
+ float synth[], int ss, /* output: synthesized speech */
+ float A_t[], /* output: two sets of A(z) coefficients length=2*MP1 */
+ IntegerPointer t0_first /* output: integer delay of first subframe */
+ ) {
+ int Az; /* Pointer to A_t (LPC coefficients) */
+ float lsp_new[] = new float[LD8KConstants.M]; /* LSPs */
+ float code[] = new float[LD8KConstants.L_SUBFR]; /* algebraic codevector
*/
- /* Scalars */
- int i, i_subfr;
- int index;
+ /* Scalars */
+ int i, i_subfr;
+ int index;
- IntegerPointer t0 = new IntegerPointer(), t0_frac = new
IntegerPointer();
- int bfi;
- int bad_pitch;
+ IntegerPointer t0 = new IntegerPointer(), t0_frac = new IntegerPointer();
+ int bfi;
+ int bad_pitch;
- /* Test bad frame indicator (bfi) */
+ /* Test bad frame indicator (bfi) */
- bfi = parm[parms++];
+ bfi = parm[parms++];
- /* Decode the LSPs */
+ /* Decode the LSPs */
- lspDec.d_lsp(parm, parms, lsp_new, bfi);
- parms += 2; /* Advance synthesis parameters pointer */
+ lspDec.d_lsp(parm, parms, lsp_new, bfi);
+ parms += 2; /* Advance synthesis parameters pointer */
- /* Interpolation of LPC for the 2 subframes */
+ /* Interpolation of LPC for the 2 subframes */
- LpcFunc.int_qlpc(lsp_old, lsp_new, A_t);
+ LpcFunc.int_qlpc(lsp_old, lsp_new, A_t);
- /* update the LSFs for the next frame */
+ /* update the LSFs for the next frame */
- Util.copy(lsp_new, lsp_old, LD8KConstants.M);
+ Util.copy(lsp_new, lsp_old, LD8KConstants.M);
-
/*------------------------------------------------------------------------*
- * Loop for every subframe in the analysis frame
*
-
*------------------------------------------------------------------------*
- * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR
*
- * times
*
- * - decode the pitch delay
*
- * - decode algebraic code
*
- * - decode pitch and codebook gains
*
- * - find the excitation and compute synthesis speech
*
-
*------------------------------------------------------------------------*/
+
/*------------------------------------------------------------------------*
+ * Loop for every subframe in the analysis
frame *
+
*------------------------------------------------------------------------*
+ * The subframe size is L_SUBFR and the loop is repeated
L_FRAME/L_SUBFR *
+ *
times *
+ * - decode the pitch
delay *
+ * - decode algebraic
code *
+ * - decode pitch and codebook
gains *
+ * - find the excitation and compute synthesis
speech *
+
*------------------------------------------------------------------------*/
- Az = 0;//A_t; /* pointer to interpolated LPC parameters */
+ Az = 0;// A_t; /* pointer to interpolated LPC parameters */
- for (i_subfr = 0; i_subfr < LD8KConstants.L_FRAME; i_subfr +=
LD8KConstants.L_SUBFR) {
+ for (i_subfr = 0; i_subfr < LD8KConstants.L_FRAME; i_subfr +=
LD8KConstants.L_SUBFR) {
- index = parm[parms++]; /* pitch index */
+ index = parm[parms++]; /* pitch index */
- if (i_subfr == 0) { /* if first subframe */
- i = parm[parms++]; /* get parity check result */
- bad_pitch = bfi+ i;
- if( bad_pitch == 0)
- {
- DecLag.dec_lag3(index, LD8KConstants.PIT_MIN,
LD8KConstants.PIT_MAX, i_subfr, t0, t0_frac);
- old_t0 = t0.value;
- }
- else /* Bad frame, or parity error */
- {
- t0.value = old_t0;
- t0_frac.value = 0;
- old_t0++;
- if( old_t0> LD8KConstants.PIT_MAX) {
- old_t0 = LD8KConstants.PIT_MAX;
- }
- }
- t0_first.value = t0.value; /* If first frame */
- }
- else /* second subframe */
- {
- if( bfi == 0)
- {
- DecLag.dec_lag3(index, LD8KConstants.PIT_MIN,
LD8KConstants.PIT_MAX, i_subfr, t0, t0_frac);
- old_t0 = t0.value;
- }
- else
- {
- t0.value = old_t0;
- t0_frac.value = 0;
- old_t0++;
- if( old_t0 >LD8KConstants.PIT_MAX) {
- old_t0 = LD8KConstants.PIT_MAX;
- }
- }
- }
-
+ if (i_subfr == 0) { /* if first subframe */
+ i = parm[parms++]; /* get parity check result */
+ bad_pitch = bfi + i;
+ if (bad_pitch == 0) {
+ DecLag.dec_lag3(index, LD8KConstants.PIT_MIN, LD8KConstants.PIT_MAX,
i_subfr, t0, t0_frac);
+ old_t0 = t0.value;
+ } else /* Bad frame, or parity error */
+ {
+ t0.value = old_t0;
+ t0_frac.value = 0;
+ old_t0++;
+ if (old_t0 > LD8KConstants.PIT_MAX) {
+ old_t0 = LD8KConstants.PIT_MAX;
+ }
+ }
+ t0_first.value = t0.value; /* If first frame */
+ } else /* second subframe */
+ {
+ if (bfi == 0) {
+ DecLag.dec_lag3(index, LD8KConstants.PIT_MIN, LD8KConstants.PIT_MAX,
i_subfr, t0, t0_frac);
+ old_t0 = t0.value;
+ } else {
+ t0.value = old_t0;
+ t0_frac.value = 0;
+ old_t0++;
+ if (old_t0 > LD8KConstants.PIT_MAX) {
+ old_t0 = LD8KConstants.PIT_MAX;
+ }
+ }
+ }
- /*-------------------------------------------------*
- * - Find the adaptive codebook vector. *
- *--------------------------------------------------*/
+ /*-------------------------------------------------*
+ * - Find the adaptive codebook vector. *
+ *--------------------------------------------------*/
- PredLt.pred_lt_3(old_exc_array, exc+i_subfr, t0.value, t0_frac.value,
LD8KConstants.L_SUBFR);
+ PredLt.pred_lt_3(old_exc_array, exc + i_subfr, t0.value, t0_frac.value,
LD8KConstants.L_SUBFR);
- /*-------------------------------------------------------*
- * - Decode innovative codebook. *
- * - Add the fixed-gain pitch contribution to code[]. *
- *-------------------------------------------------------*/
+ /*-------------------------------------------------------*
+ * - Decode innovative codebook. *
+ * - Add the fixed-gain pitch contribution to code[]. *
+ *-------------------------------------------------------*/
- if(bfi != 0) { /* Bad Frame Error Concealment */
- parm[parms+0] = (int) (Util.random_g729() & 0x1fff); /* 13 bits
random*/
- parm[parms+1]= (int) (Util.random_g729() & 0x000f); /* 4 bits
random */
- }
+ if (bfi != 0) { /* Bad Frame Error Concealment */
+ parm[parms + 0] = (int) (Util.random_g729() & 0x1fff); /*
+ * 13 bits random
+ */
+ parm[parms + 1] = (int) (Util.random_g729() & 0x000f); /*
+ * 4 bits random
+ */
+ }
- DecAcelp.decod_ACELP(parm[parms+1], parm[parms+0], code);
- parms +=2;
- for (i = t0.value; i < LD8KConstants.L_SUBFR; i++) code[i] += sharp
* code[i-t0.value];
+ DecAcelp.decod_ACELP(parm[parms + 1], parm[parms + 0], code);
+ parms += 2;
+ for (i = t0.value; i < LD8KConstants.L_SUBFR; i++)
+ code[i] += sharp * code[i - t0.value];
- /*-------------------------------------------------*
- * - Decode pitch and codebook gains. *
- *-------------------------------------------------*/
+ /*-------------------------------------------------*
+ * - Decode pitch and codebook gains. *
+ *-------------------------------------------------*/
- index = parm[parms++]; /* index of energy VQ */
- decGain.dec_gain(index, code, LD8KConstants.L_SUBFR, bfi, gain_pitch,
gain_code);
+ index = parm[parms++]; /* index of energy VQ */
+ decGain.dec_gain(index, code, LD8KConstants.L_SUBFR, bfi, gain_pitch,
gain_code);
- /*-------------------------------------------------------------*
- * - Update pitch sharpening "sharp" with quantized gain_pitch *
- *-------------------------------------------------------------*/
+ /*-------------------------------------------------------------*
+ * - Update pitch sharpening "sharp" with quantized gain_pitch *
+ *-------------------------------------------------------------*/
- sharp = gain_pitch.value;
- if (sharp > LD8KConstants.SHARPMAX) sharp = LD8KConstants.SHARPMAX;
- if (sharp < LD8KConstants.SHARPMIN) sharp = LD8KConstants.SHARPMIN;
+ sharp = gain_pitch.value;
+ if (sharp > LD8KConstants.SHARPMAX)
+ sharp = LD8KConstants.SHARPMAX;
+ if (sharp < LD8KConstants.SHARPMIN)
+ sharp = LD8KConstants.SHARPMIN;
- /*-------------------------------------------------------*
- * - Find the total excitation. *
- *-------------------------------------------------------*/
+ /*-------------------------------------------------------*
+ * - Find the total excitation. *
+ *-------------------------------------------------------*/
- if(bfi != 0 ) {
- if(voicing == 0) { /* for unvoiced frame */
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
- old_exc_array[exc+i+i_subfr] = gain_code.value*code[i];
- }
- } else { /* for voiced frame */
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
- old_exc_array[exc+i+i_subfr] =
gain_pitch.value*old_exc_array[exc+i+i_subfr];
- }
- }
- } else { /* No frame errors */
- for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
- old_exc_array[exc+i+i_subfr] =
gain_pitch.value*old_exc_array[exc+i+i_subfr] + gain_code.value*code[i];
- }
- }
+ if (bfi != 0) {
+ if (voicing == 0) { /* for unvoiced frame */
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ old_exc_array[exc + i + i_subfr] = gain_code.value * code[i];
+ }
+ } else { /* for voiced frame */
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ old_exc_array[exc + i + i_subfr] = gain_pitch.value *
old_exc_array[exc + i + i_subfr];
+ }
+ }
+ } else { /* No frame errors */
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ old_exc_array[exc + i + i_subfr] = gain_pitch.value *
old_exc_array[exc + i + i_subfr]
+ + gain_code.value * code[i];
+ }
+ }
- /*-------------------------------------------------------*
- * - Find synthesis speech corresponding to exc[]. *
- *-------------------------------------------------------*/
+ /*-------------------------------------------------------*
+ * - Find synthesis speech corresponding to exc[]. *
+ *-------------------------------------------------------*/
- Filter.syn_filt(A_t, Az, old_exc_array, exc+i_subfr, synth,
ss+i_subfr, LD8KConstants.L_SUBFR, mem_syn, 0, 1);
+ Filter.syn_filt(A_t, Az, old_exc_array, exc + i_subfr, synth, ss +
i_subfr, LD8KConstants.L_SUBFR, mem_syn,
+ 0, 1);
- Az += LD8KConstants.MP1; /* interpolated LPC parameters for
next subframe */
- }
+ Az += LD8KConstants.MP1; /*
+ * interpolated LPC parameters for next subframe
+ */
+ }
- /*--------------------------------------------------*
- * Update signal for next frame. *
- * -> shift to the left by L_FRAME exc[] *
- *--------------------------------------------------*/
- Util.copy(old_exc_array, LD8KConstants.L_FRAME, old_exc_array, 0,
LD8KConstants.PIT_MAX+LD8KConstants.L_INTERPOL);
+ /*--------------------------------------------------*
+ * Update signal for next frame. *
+ * -> shift to the left by L_FRAME exc[] *
+ *--------------------------------------------------*/
+ Util.copy(old_exc_array, LD8KConstants.L_FRAME, old_exc_array, 0,
LD8KConstants.PIT_MAX
+ + LD8KConstants.L_INTERPOL);
- return;
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/DecLag.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/DecLag.java Thu Feb 21
09:21:48 2013
@@ -1,8 +1,9 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class DecLag {
-
+
/*------------------------------------------------------------------------*
* Function dec_lag3
*
* ~~~~~~~~
*
@@ -10,52 +11,47 @@
* See "enc_lag3.c" for more details about the encoding procedure.
*
*------------------------------------------------------------------------*/
- public static void dec_lag3( /* Decode the pitch
lag */
- int index, /* input : received pitch index */
- int pit_min, /* input : minimum pitch lag */
- int pit_max, /* input : maximum pitch lag */
- int i_subfr, /* input : subframe flag */
- IntegerPointer T0, /* output: integer part of pitch lag */
- IntegerPointer T0_frac /* output: fractional part of pitch lag */
- )
- {
- int i;
- int T0_min, T0_max;
+ public static void dec_lag3( /* Decode the pitch lag */
+ int index, /* input : received pitch index */
+ int pit_min, /* input : minimum pitch lag */
+ int pit_max, /* input : maximum pitch lag */
+ int i_subfr, /* input : subframe flag */
+ IntegerPointer T0, /* output: integer part of pitch lag */
+ IntegerPointer T0_frac /* output: fractional part of pitch lag */
+ ) {
+ int i;
+ int T0_min, T0_max;
- if (i_subfr == 0) /* if 1st subframe */
- {
- if (index < 197)
- {
- T0.value = (index+2)/3 + 19;
- T0_frac.value = index - T0.value*3 + 58;
- }
- else
- {
- T0.value = index - 112;
- T0_frac.value = 0;
- }
- }
+ if (i_subfr == 0) /* if 1st subframe */
+ {
+ if (index < 197) {
+ T0.value = (index + 2) / 3 + 19;
+ T0_frac.value = index - T0.value * 3 + 58;
+ } else {
+ T0.value = index - 112;
+ T0_frac.value = 0;
+ }
+ }
- else /* second subframe */
- {
- /* find T0_min and T0_max for 2nd subframe */
+ else /* second subframe */
+ {
+ /* find T0_min and T0_max for 2nd subframe */
- T0_min = T0.value - 5;
- if (T0_min < pit_min)
- T0_min = pit_min;
+ T0_min = T0.value - 5;
+ if (T0_min < pit_min)
+ T0_min = pit_min;
- T0_max = T0_min + 9;
- if(T0_max > pit_max)
- {
- T0_max = pit_max;
- T0_min = T0_max -9;
- }
+ T0_max = T0_min + 9;
+ if (T0_max > pit_max) {
+ T0_max = pit_max;
+ T0_min = T0_max - 9;
+ }
- i = (index+2)/3 - 1;
- T0.value = i + T0_min;
- T0_frac.value = index - 2 - i*3;
- }
- return;
+ i = (index + 2) / 3 - 1;
+ T0.value = i + T0_min;
+ T0_frac.value = index - 2 - i * 3;
+ }
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Decoder.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Decoder.java Thu Feb 21
09:21:48 2013
@@ -1,123 +1,117 @@
package org.red5.codecs.g729;
-
import org.red5.sip.app.BufferUtils;
-
public class Decoder {
- float[] synth_buf = new float[ LD8KConstants.L_FRAME + LD8KConstants.M
]; // Synthesis
+ float[] synth_buf = new float[LD8KConstants.L_FRAME + LD8KConstants.M];
// Synthesis
- float[] Az_dec = new float[ 2 * LD8KConstants.MP1 ];
+ float[] Az_dec = new float[2 * LD8KConstants.MP1];
- float[] pst_out = new float[ LD8KConstants.L_FRAME ]; // postfilter
output
+ float[] pst_out = new float[LD8KConstants.L_FRAME]; // postfilter output
- short[] serial = new short[ LD8KConstants.SERIAL_SIZE ]; // Serial
stream
+ short[] serial = new short[LD8KConstants.SERIAL_SIZE]; // Serial stream
- int[] parm = new int[ LD8KConstants.PRM_SIZE + 1 ]; // Synth
parameters BFI
+ int[] parm = new int[LD8KConstants.PRM_SIZE + 1]; // Synth parameters BFI
- int synth;
+ int synth;
- int ptr_Az; // Decoded Az for post-filter
+ int ptr_Az; // Decoded Az for post-filter
- int voicing; // voicing for previous subframe
+ int voicing; // voicing for previous subframe
- IntegerPointer t0_first = new IntegerPointer();
+ IntegerPointer t0_first = new IntegerPointer();
- IntegerPointer sf_voic = new IntegerPointer( 0 ); // voicing for
subframe
+ IntegerPointer sf_voic = new IntegerPointer(0); // voicing for subframe
- DecLD8K decLD = new DecLD8K();
+ DecLD8K decLD = new DecLD8K();
- PostFil postFil = new PostFil();
+ PostFil postFil = new PostFil();
- PostPro postPro = new PostPro();
+ PostPro postPro = new PostPro();
+ public Decoder() {
- public Decoder() {
+ for (int i = 0; i < LD8KConstants.M; i++) {
+ synth_buf[i] = (float) 0.0;
+ }
- for ( int i = 0; i < LD8KConstants.M; i++ ) {
- synth_buf[ i ] = (float) 0.0;
- }
+ synth = 0 + LD8KConstants.M;
- synth = 0 + LD8KConstants.M;
+ decLD.init_decod_ld8k();
+ postFil.init_post_filter();
+ postPro.init_post_process();
+ voicing = 60;
+ }
- decLD.init_decod_ld8k();
- postFil.init_post_filter();
- postPro.init_post_process();
- voicing = 60;
- }
+ // Recebe um array de byte de 20 ou 30 posi��es
+ // processa de 10 em 10 Bytes e retorna um array de float de 160 ou 240
+ // Bytes
+ public void decode(byte[] bufferIn, float[] bufferOut) {
+ int inOffset = 0;
+ int outOffset = 0;
+ int steps = bufferIn.length / LD8KConstants.L_ENC_FRAME;
- // Recebe um array de byte de 20 ou 30 posi��es
- // processa de 10 em 10 Bytes e retorna um array de float de 160 ou 240
- // Bytes
- public void decode( byte[] bufferIn, float[] bufferOut ) {
+ for (int i = 0; i < steps; i++) {
+ byte[] tempBufferIn = new byte[LD8KConstants.L_ENC_FRAME];
+ float[] tempBufferOut = new float[LD8KConstants.L_FRAME];
- int inOffset = 0;
- int outOffset = 0;
- int steps = bufferIn.length / LD8KConstants.L_ENC_FRAME;
+ // Encode bufferIn
+ BufferUtils.byteBufferIndexedCopy(tempBufferIn, 0, bufferIn, inOffset,
LD8KConstants.L_ENC_FRAME);
+ tempBufferOut = process(tempBufferIn);
- for ( int i = 0; i < steps; i++ ) {
- byte[] tempBufferIn = new byte[ LD8KConstants.L_ENC_FRAME ];
- float[] tempBufferOut = new float[ LD8KConstants.L_FRAME ];
-
- // Encode bufferIn
- BufferUtils.byteBufferIndexedCopy( tempBufferIn, 0, bufferIn,
inOffset, LD8KConstants.L_ENC_FRAME );
- tempBufferOut = process( tempBufferIn );
-
- // Copy decoded data to bufferOut
- BufferUtils.floatBufferIndexedCopy(bufferOut, outOffset,
tempBufferOut, 0, LD8KConstants.L_FRAME);
-
- inOffset += LD8KConstants.L_ENC_FRAME;
- outOffset += LD8KConstants.L_FRAME;
- }
- }
+ // Copy decoded data to bufferOut
+ BufferUtils.floatBufferIndexedCopy(bufferOut, outOffset, tempBufferOut,
0, LD8KConstants.L_FRAME);
+ inOffset += LD8KConstants.L_ENC_FRAME;
+ outOffset += LD8KConstants.L_FRAME;
+ }
+ }
- /**
- * Perform compression.
- *
- * @param input
- * media
- * @return compressed media.
- */
- private float[] process( byte[] media ) {
+ /**
+ * Perform compression.
+ *
+ * @param input
+ * media
+ * @return compressed media.
+ */
+ private float[] process(byte[] media) {
- serial = Bits.fromRealBits( media );
- // serial = Util.byteArrayToShortArray(media);
- Bits.bits2prm_ld8k( serial, 2, parm, 1 );
+ serial = Bits.fromRealBits(media);
+ // serial = Util.byteArrayToShortArray(media);
+ Bits.bits2prm_ld8k(serial, 2, parm, 1);
- /*
- * the hardware detects frame erasures by checking if all bits are
set
- * to zero
- */
- parm[ 0 ] = 0; /* No frame erasure */
- for ( int i = 2; i < LD8KConstants.SERIAL_SIZE; i++ ) {
- if ( serial[ i ] == 0 ) {
- parm[ 0 ] = 1; /* frame erased */
- }
- }
+ /*
+ * the hardware detects frame erasures by checking if all bits are set
to zero
+ */
+ parm[0] = 0; /* No frame erasure */
+ for (int i = 2; i < LD8KConstants.SERIAL_SIZE; i++) {
+ if (serial[i] == 0) {
+ parm[0] = 1; /* frame erased */
+ }
+ }
- /* check parity and put 1 in parm[4] if parity error */
+ /* check parity and put 1 in parm[4] if parity error */
- parm[ 4 ] = PParity.check_parity_pitch( parm[ 3 ], parm[ 4 ] );
+ parm[4] = PParity.check_parity_pitch(parm[3], parm[4]);
- decLD.decod_ld8k( parm, 0, voicing, synth_buf, synth, Az_dec,
t0_first ); /* Decoder */
+ decLD.decod_ld8k(parm, 0, voicing, synth_buf, synth, Az_dec, t0_first);
/* Decoder */
- /* Post-filter and decision on voicing parameter */
- voicing = 0;
- ptr_Az = 0;// Az_dec;
- for ( int i = 0; i < LD8KConstants.L_FRAME; i +=
LD8KConstants.L_SUBFR ) {
- postFil.post( t0_first.value, synth_buf, synth + i, Az_dec,
ptr_Az, pst_out, i, sf_voic );
- if ( sf_voic.value != 0 ) {
- voicing = sf_voic.value;
- }
- ptr_Az += LD8KConstants.MP1;
- }
- Util.copy( synth_buf, LD8KConstants.L_FRAME, synth_buf, 0,
LD8KConstants.M );
+ /* Post-filter and decision on voicing parameter */
+ voicing = 0;
+ ptr_Az = 0;// Az_dec;
+ for (int i = 0; i < LD8KConstants.L_FRAME; i += LD8KConstants.L_SUBFR) {
+ postFil.post(t0_first.value, synth_buf, synth + i, Az_dec, ptr_Az,
pst_out, i, sf_voic);
+ if (sf_voic.value != 0) {
+ voicing = sf_voic.value;
+ }
+ ptr_Az += LD8KConstants.MP1;
+ }
+ Util.copy(synth_buf, LD8KConstants.L_FRAME, synth_buf, 0,
LD8KConstants.M);
- postPro.post_process( pst_out, LD8KConstants.L_FRAME );
+ postPro.post_process(pst_out, LD8KConstants.L_FRAME);
- return pst_out;
- }
+ return pst_out;
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Encoder.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Encoder.java Thu Feb 21
09:21:48 2013
@@ -1,67 +1,63 @@
package org.red5.codecs.g729;
-
import org.red5.sip.app.BufferUtils;
-
public class Encoder {
- private CodLD8K encoder = new CodLD8K();
+ private CodLD8K encoder = new CodLD8K();
- private PreProc preProc = new PreProc();
-
- private short[] serial = new short[ LD8KConstants.SERIAL_SIZE ];
-
- private int[] prm = new int[ LD8KConstants.PRM_SIZE ];
+ private PreProc preProc = new PreProc();
+ private short[] serial = new short[LD8KConstants.SERIAL_SIZE];
- public Encoder() {
+ private int[] prm = new int[LD8KConstants.PRM_SIZE];
- preProc.init_pre_process();
- encoder.init_coder_ld8k();
- }
+ public Encoder() {
+ preProc.init_pre_process();
+ encoder.init_coder_ld8k();
+ }
- // Recebe um array de float de 160 ou 240 Bytes
- // processa de 80 em 80 Bytes e retorna um array de byte de 20 ou 30
posi��es
- public void encode( float[] bufferIn, byte[] bufferOut ) {
+ // Recebe um array de float de 160 ou 240 Bytes
+ // processa de 80 em 80 Bytes e retorna um array de byte de 20 ou 30
+ // posi��es
+ public void encode(float[] bufferIn, byte[] bufferOut) {
- int inOffset = 0;
- int outOffset = 0;
- int steps = bufferIn.length / LD8KConstants.L_FRAME;
+ int inOffset = 0;
+ int outOffset = 0;
+ int steps = bufferIn.length / LD8KConstants.L_FRAME;
- for ( int i = 0; i < steps; i++ ) {
- byte[] tempBufferOut = new byte[ LD8KConstants.L_ENC_FRAME ];
- float[] tempBufferIn = new float[ LD8KConstants.L_FRAME ];
+ for (int i = 0; i < steps; i++) {
+ byte[] tempBufferOut = new byte[LD8KConstants.L_ENC_FRAME];
+ float[] tempBufferIn = new float[LD8KConstants.L_FRAME];
- // Encode bufferIn
- BufferUtils.floatBufferIndexedCopy( tempBufferIn, 0, bufferIn,
inOffset, LD8KConstants.L_FRAME );
- tempBufferOut = process( tempBufferIn );
-
- // Copy encoded data to bufferOut
- BufferUtils.byteBufferIndexedCopy(bufferOut, outOffset,
tempBufferOut, 0, LD8KConstants.L_ENC_FRAME);
+ // Encode bufferIn
+ BufferUtils.floatBufferIndexedCopy(tempBufferIn, 0, bufferIn, inOffset,
LD8KConstants.L_FRAME);
+ tempBufferOut = process(tempBufferIn);
- inOffset += LD8KConstants.L_FRAME;
- outOffset += LD8KConstants.L_ENC_FRAME;
- }
- }
+ // Copy encoded data to bufferOut
+ BufferUtils.byteBufferIndexedCopy(bufferOut, outOffset, tempBufferOut,
0, LD8KConstants.L_ENC_FRAME);
+ inOffset += LD8KConstants.L_FRAME;
+ outOffset += LD8KConstants.L_ENC_FRAME;
+ }
+ }
- /**
- * Perform G729 encoding
- *
- * @param input
- * media
- * @return compressed media.
- */
- private byte[] process( float[] media ) {
+ /**
+ * Perform G729 encoding
+ *
+ * @param input
+ * media
+ * @return compressed media.
+ */
+ private byte[] process(float[] media) {
- preProc.pre_process( media, LD8KConstants.L_FRAME );
+ preProc.pre_process(media, LD8KConstants.L_FRAME);
- encoder.loadSpeech( media );
- encoder.coder_ld8k( prm, 0 );
+ encoder.loadSpeech(media);
+ encoder.coder_ld8k(prm, 0);
- Bits.prm2bits_ld8k( prm, serial );
- return Bits.toRealBits( serial );
- }
+ Bits.prm2bits_ld8k(prm, serial);
+ return Bits.toRealBits(serial);
+ }
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Filter.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Filter.java Thu Feb 21
09:21:48 2013
@@ -1,101 +1,107 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class Filter {
-
/*-----------------------------------------------------------*
* convolve - convolve vectors x and h and put result in y *
*-----------------------------------------------------------*/
- public static void convolve(
- float x[], int xs, /* input : input vector
x[0:l] */
- float h[], int hs, /* input : impulse response or second
input h[0:l] */
- float y[], int ys, /* output: x convolved with h ,
y[0:l] */
- int l /* input : dimension of all
vectors */
- )
- {
- float temp;
- int i, n;
+ public static void convolve(float x[], int xs, /*
+ * input : input vector x[0:l]
+ */
+ float h[], int hs, /*
+ * input : impulse response or second input h[0:l]
+ */
+ float y[], int ys, /* output: x convolved with h , y[0:l] */
+ int l /* input : dimension of all vectors */
+ ) {
+ float temp;
+ int i, n;
- for (n = 0; n < l; n++)
- {
- temp = (float)0.0;
- for (i = 0; i <= n; i++)
- temp += x[xs+i]*h[hs+n-i];
- y[ys+n] = temp;
- }
+ for (n = 0; n < l; n++) {
+ temp = (float) 0.0;
+ for (i = 0; i <= n; i++)
+ temp += x[xs + i] * h[hs + n - i];
+ y[ys + n] = temp;
+ }
- return;
+ return;
}
/*-----------------------------------------------------------*
* syn_filt - filter with synthesis filter 1/A(z) *
*-----------------------------------------------------------*/
- public static void syn_filt(
- float a[],int as, /* input : predictor coefficients a[0:m] */
- float x[],int xs, /* input : excitation signal */
- float y[],int ys, /* output: filtered output signal */
- int l, /* input : vector dimension */
- float mem[],int mems, /* in/out: filter memory */
- int update /* input : 0 = no memory update, 1 = update */
- )
- {
- int i,j;
+ public static void syn_filt(float a[], int as, /*
+ * input : predictor coefficients a[0:m]
+ */
+ float x[], int xs, /* input : excitation signal */
+ float y[], int ys, /* output: filtered output signal */
+ int l, /* input : vector dimension */
+ float mem[], int mems, /* in/out: filter memory */
+ int update /* input : 0 = no memory update, 1 = update */
+ ) {
+ int i, j;
- /* This is usually done by memory allocation (l+m) */
- float yy_b[] = new float[LD8KConstants.L_SUBFR+LD8KConstants.M];
- double s;
- int yy, py, pa;
+ /* This is usually done by memory allocation (l+m) */
+ float yy_b[] = new float[LD8KConstants.L_SUBFR + LD8KConstants.M];
+ double s;
+ int yy, py, pa;
- /* Copy mem[] to yy[] */
+ /* Copy mem[] to yy[] */
- yy = 0;//yy_b;
- for (i = 0; i <LD8KConstants.M; i++) yy_b[yy++] = mem[mems++];
+ yy = 0;// yy_b;
+ for (i = 0; i < LD8KConstants.M; i++)
+ yy_b[yy++] = mem[mems++];
- /* Filtering */
+ /* Filtering */
- for (i = 0; i < l; i++)
- {
- py=yy;
- pa=0;//a
- s = x[xs++];
- for (j = 0; j <LD8KConstants.M; j++) s -= (a[as+ ++pa]) *
(double)(yy_b[--py]);
- yy_b[yy++] = (float)s;
- y[ys++] = (float)s;
- }
+ for (i = 0; i < l; i++) {
+ py = yy;
+ pa = 0;// a
+ s = x[xs++];
+ for (j = 0; j < LD8KConstants.M; j++)
+ s -= (a[as + ++pa]) * (double) (yy_b[--py]);
+ yy_b[yy++] = (float) s;
+ y[ys++] = (float) s;
+ }
- /* Update memory if required */
+ /* Update memory if required */
- if(update !=0 ) for (i = 0; i <LD8KConstants.M; i++) mem[--mems]
=yy_b[--yy];
+ if (update != 0)
+ for (i = 0; i < LD8KConstants.M; i++)
+ mem[--mems] = yy_b[--yy];
- return;
+ return;
}
/*-----------------------------------------------------------*
* residu - filter input vector with all-zero filter A(Z) *
*-----------------------------------------------------------*/
- public static void residu( /* filter
A(z) */
- float []a,int as, /* input : prediction coefficients a[0:m+1],
a[0]=1. */
- float []x,int xs, /* input : input signal x[0:l-1], x[-1:m] are
needed */
- float []y,int ys, /* output: output signal y[0:l-1] NOTE: x[] and
y[]
- cannot point to same array */
- int l /* input : dimension of x and y */
- )
- {
- double s;
- int i, j;
- int ya = 0;
+ public static void residu( /* filter A(z) */
+ float[] a, int as, /* input : prediction coefficients a[0:m+1], a[0]=1. */
+ float[] x, int xs, /*
+ * input : input signal x[0:l-1], x[-1:m] are needed
+ */
+ float[] y, int ys, /*
+ * output: output signal y[0:l-1] NOTE: x[] and y[] cannot point
to same array
+ */
+ int l /* input : dimension of x and y */
+ ) {
+ double s;
+ int i, j;
+ int ya = 0;
- for (i = 0; i < l; i++)
- {
- s = x[xs+i];
- for (j = 1; j <= LD8KConstants.M; j++) s += a[as+j]*(double)x[xs+i-j];
- y[ys+ya++] = (float)s;
- }
- return;
+ for (i = 0; i < l; i++) {
+ s = x[xs + i];
+ for (j = 1; j <= LD8KConstants.M; j++)
+ s += a[as + j] * (double) x[xs + i - j];
+ y[ys + ya++] = (float) s;
+ }
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/FloatPointer.java Fri
Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/FloatPointer.java Thu
Feb 21 09:21:48 2013
@@ -1,11 +1,14 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class FloatPointer {
public Float value = null;
+
public FloatPointer(Float v) {
value = v;
}
+
public FloatPointer() {
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/GainPred.java Fri Feb
10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/GainPred.java Thu Feb
21 09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class GainPred {
@@ -9,55 +10,55 @@
* MA prediction is performed on the innovation energy (in dB with
mean *
*
removed). *
*---------------------------------------------------------------------------*/
- public static void gain_predict(
- float past_qua_en[], /* (i) :Past quantized energies */
- float code[], /* (i) :Innovative vector. */
- int l_subfr, /* (i) :Subframe length. */
- FloatPointer gcode0 /* (o) :Predicted codebook gain
*/
- )
- {
- float ener_code, pred_code;
- int i;
+ public static void gain_predict(float past_qua_en[], /*
+ * (i) :Past quantized energies
+ */
+ float code[], /* (i) :Innovative vector. */
+ int l_subfr, /* (i) :Subframe length. */
+ FloatPointer gcode0 /* (o) :Predicted codebook gain */
+ ) {
+ float ener_code, pred_code;
+ int i;
- pred_code = LD8KConstants.MEAN_ENER ;
+ pred_code = LD8KConstants.MEAN_ENER;
- /* innovation energy */
- ener_code = (float)0.01;
- for(i=0; i<l_subfr; i++)
- ener_code += code[i] * code[i];
- ener_code = (float)10.0 * (float)Math.log10(ener_code /(float)l_subfr);
+ /* innovation energy */
+ ener_code = (float) 0.01;
+ for (i = 0; i < l_subfr; i++)
+ ener_code += code[i] * code[i];
+ ener_code = (float) 10.0 * (float) Math.log10(ener_code / (float)
l_subfr);
- pred_code -= ener_code;
+ pred_code -= ener_code;
- /* predicted energy */
- for (i=0; i<4; i++) pred_code += TabLD8k.pred[i]*past_qua_en[i];
+ /* predicted energy */
+ for (i = 0; i < 4; i++)
+ pred_code += TabLD8k.pred[i] * past_qua_en[i];
- /* predicted codebook gain */
- gcode0.value = pred_code;
- gcode0.value =
(float)Math.pow((double)10.0,(double)(gcode0.value/20.0)); /* predicted
gain */
+ /* predicted codebook gain */
+ gcode0.value = pred_code;
+ gcode0.value = (float) Math.pow((double) 10.0, (double) (gcode0.value /
20.0)); /* predicted gain */
- return;
+ return;
}
-
/*---------------------------------------------------------------------------*
* Function
gain_update *
*
~~~~~~~~~~~~~~~~~~~~~~ *
* update table of past quantized
energies *
*---------------------------------------------------------------------------*/
- public static void gain_update(
- float past_qua_en[], /* input/output :Past quantized energies */
- float g_code /* input: gbk1[indice1][1]+gbk2[indice2][1] */
- )
- {
- int i;
+ public static void gain_update(float past_qua_en[], /*
+ * input/output :Past quantized energies
+ */
+ float g_code /* input: gbk1[indice1][1]+gbk2[indice2][1] */
+ ) {
+ int i;
- /* update table of past quantized energies */
- for (i = 3; i > 0; i--)
- past_qua_en[i] = past_qua_en[i-1];
- past_qua_en[0] = (float)20.0*(float)Math.log10((double)g_code);
+ /* update table of past quantized energies */
+ for (i = 3; i > 0; i--)
+ past_qua_en[i] = past_qua_en[i - 1];
+ past_qua_en[0] = (float) 20.0 * (float) Math.log10((double) g_code);
- return;
+ return;
}
/*---------------------------------------------------------------------------*
@@ -71,25 +72,25 @@
* av_pred_en = av_pred_en*0.25 -
4.0; *
* if (av_pred_en < -14.0) av_pred_en =
-14.0; *
*---------------------------------------------------------------------------*/
- public static void gain_update_erasure(
- float past_qua_en[] /* input/output:Past quantized energies
*/
- )
- {
- int i;
- float av_pred_en;
+ public static void gain_update_erasure(float past_qua_en[] /*
+ * input/output:Past quantized energies
+ */
+ ) {
+ int i;
+ float av_pred_en;
- av_pred_en = (float)0.0;
- for (i = 0; i < 4; i++)
- av_pred_en += past_qua_en[i];
- av_pred_en = av_pred_en*(float)0.25 - (float)4.0;
- if (av_pred_en < (float)-14.0) av_pred_en = (float)-14.0;
+ av_pred_en = (float) 0.0;
+ for (i = 0; i < 4; i++)
+ av_pred_en += past_qua_en[i];
+ av_pred_en = av_pred_en * (float) 0.25 - (float) 4.0;
+ if (av_pred_en < (float) -14.0)
+ av_pred_en = (float) -14.0;
- for (i = 3; i > 0; i--)
- past_qua_en[i] = past_qua_en[i-1];
- past_qua_en[0] = av_pred_en;
+ for (i = 3; i > 0; i--)
+ past_qua_en[i] = past_qua_en[i - 1];
+ past_qua_en[0] = av_pred_en;
- return;
+ return;
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/GenericPointer.java Fri
Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/GenericPointer.java Thu
Feb 21 09:21:48 2013
@@ -1,13 +1,17 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class GenericPointer<T> {
public T value = null;
+
public GenericPointer(T v) {
value = v;
}
+
public GenericPointer() {
}
+
public void setValue(T a) {
value = a;
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/IntegerPointer.java Fri
Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/IntegerPointer.java Thu
Feb 21 09:21:48 2013
@@ -1,13 +1,17 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class IntegerPointer {
public Integer value = null;
+
public IntegerPointer(Integer v) {
value = v;
}
+
public IntegerPointer() {
}
+
public void setValue(Integer a) {
value = a;
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/LD8KConstants.java Fri
Feb 10 07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/LD8KConstants.java Thu
Feb 21 09:21:48 2013
@@ -1,159 +1,221 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class LD8KConstants {
- public static final float PI = (float)3.14159265358979323846;
- public static final float PI2 = (float)6.283185307;
- public static final float FLT_MAX_G729 = (float)1.e38 ; /*
largest floating point number */
- public static final float FLT_MIN_G729 = -FLT_MAX_G729; /*
largest floating point number */
+ public static final float PI = (float) 3.14159265358979323846;
+ public static final float PI2 = (float) 6.283185307;
+ public static final float FLT_MAX_G729 = (float) 1.e38; /*
+ * largest floating point number
+ */
+ public static final float FLT_MIN_G729 = -FLT_MAX_G729; /*
+ * largest floating point number
+ */
- public static final short L_TOTAL = 240 ; /* Total size of
speech buffer */
- public static final short L_FRAME = 80 ; /* LPC update frame
size */
- public static final short L_ENC_FRAME = 10 ; /* Encoded frame
size */
- public static final short L_SUBFR = 40 ; /* Sub-frame
size */
+ public static final short L_TOTAL = 240; /* Total size of speech buffer */
+ public static final short L_FRAME = 80; /* LPC update frame size */
+ public static final short L_ENC_FRAME = 10; /* Encoded frame size */
+ public static final short L_SUBFR = 40; /* Sub-frame size */
/*---------------------------------------------------------------------------*
* constants for bitstream
packing *
*---------------------------------------------------------------------------*/
- public static final short BIT_1 = (short)0x0081; /* definition of
one-bit in bit-stream */
- public static final short BIT_0 = (short)0x007f; /* definition of
zero-bit in bit-stream */
- public static final short SYNC_WORD= (short)0x6b21; /* definition of
frame erasure flag */
- public static final short SIZE_WORD = 80 ; /* size of bitstream
frame */
- public static final short PRM_SIZE = 11 ; /* number of
parameters per 10 ms frame */
- public static final short SERIAL_SIZE= 82 ; /* bits per
frame */
+ public static final short BIT_1 = (short) 0x0081; /*
+ * definition of one-bit in bit-stream
+ */
+ public static final short BIT_0 = (short) 0x007f; /*
+ * definition of zero-bit in bit-stream
+ */
+ public static final short SYNC_WORD = (short) 0x6b21; /*
+ * definition of frame erasure flag
+ */
+ public static final short SIZE_WORD = 80; /* size of bitstream frame */
+ public static final short PRM_SIZE = 11; /*
+ * number of parameters per 10 ms frame
+ */
+ public static final short SERIAL_SIZE = 82; /* bits per frame */
/*---------------------------------------------------------------------------*
* constants for lpc analysis and lsp
quantizer *
*---------------------------------------------------------------------------*/
- public static final short L_WINDOW = 240 ; /* LPC analysis
window size */
- public static final short L_NEXT = 40 ; /* Samples of next
frame needed for LPC ana. */
+ public static final short L_WINDOW = 240; /* LPC analysis window size */
+ public static final short L_NEXT = 40; /*
+ * Samples of next frame needed for LPC ana.
+ */
- public static final short M = 10 ; /* LPC
order */
- public static final short MP1 = (M+1) ; /* LPC
order+1 */
- public static final short GRID_POINTS = 60 ; /* resolution of lsp
search */
+ public static final short M = 10; /* LPC order */
+ public static final short MP1 = (M + 1); /* LPC order+1 */
+ public static final short GRID_POINTS = 60; /* resolution of lsp search */
- public static final short MA_NP = 4 ; /* MA prediction
order for LSP */
- public static final short MODE = 2 ; /* number of modes
for MA prediction */
- public static final short NC0_B = 7 ; /* number of bits in
first stage */
- public static final short NC0 = (1<<NC0_B); /* number of entries
in first stage */
- public static final short NC1_B = 5 ; /* number of bits in
second stage */
- public static final short NC1 = (1<<NC1_B); /* number of entries
in second stage */
- public static final short NC = (M/2) ; /* LPC order /
2 */
+ public static final short MA_NP = 4; /* MA prediction order for LSP */
+ public static final short MODE = 2; /* number of modes for MA prediction
*/
+ public static final short NC0_B = 7; /* number of bits in first stage */
+ public static final short NC0 = (1 << NC0_B); /*
+ * number of entries in first stage
+ */
+ public static final short NC1_B = 5; /* number of bits in second stage */
+ public static final short NC1 = (1 << NC1_B); /*
+ * number of entries in second stage
+ */
+ public static final short NC = (M / 2); /* LPC order / 2 */
- public static final float L_LIMIT = (float)0.005 ; /* */
- public static final float M_LIMIT = (float)3.135 ; /* */
- public static final float GAP1 = (float)0.0012; /* */
- public static final float GAP2 = (float)0.0006 ; /* */
- public static final float GAP3 = (float)0.0392; /* */
- public static final float PI04 = PI*(float)0.04 ; /* pi*0.04 */
- public static final float PI92 = PI*(float)0.92 ; /* pi*0.92 */
- public static final float CONST12 = (float)1.2;
+ public static final float L_LIMIT = (float) 0.005; /* */
+ public static final float M_LIMIT = (float) 3.135; /* */
+ public static final float GAP1 = (float) 0.0012; /* */
+ public static final float GAP2 = (float) 0.0006; /* */
+ public static final float GAP3 = (float) 0.0392; /* */
+ public static final float PI04 = PI * (float) 0.04; /* pi*0.04 */
+ public static final float PI92 = PI * (float) 0.92; /* pi*0.92 */
+ public static final float CONST12 = (float) 1.2;
/*-------------------------------------------------------------------------
* pwf constants
*-------------------------------------------------------------------------
*/
- public static final float THRESH_L1 = (float)-1.74;
- public static final float THRESH_L2 = (float)-1.52;
- public static final float THRESH_H1 = (float)0.65;
- public static final float THRESH_H2 = (float)0.43;
- public static final float GAMMA1_0 = (float)0.98;
- public static final float GAMMA2_0_H = (float)0.7;
- public static final float GAMMA2_0_L = (float)0.4;
- public static final float GAMMA1_1 = (float)0.94;
- public static final float GAMMA2_1 = (float)0.6;
- public static final float ALPHA = (float)-6.0;
- public static final float BETA = (float)1.0;
+ public static final float THRESH_L1 = (float) -1.74;
+ public static final float THRESH_L2 = (float) -1.52;
+ public static final float THRESH_H1 = (float) 0.65;
+ public static final float THRESH_H2 = (float) 0.43;
+ public static final float GAMMA1_0 = (float) 0.98;
+ public static final float GAMMA2_0_H = (float) 0.7;
+ public static final float GAMMA2_0_L = (float) 0.4;
+ public static final float GAMMA1_1 = (float) 0.94;
+ public static final float GAMMA2_1 = (float) 0.6;
+ public static final float ALPHA = (float) -6.0;
+ public static final float BETA = (float) 1.0;
/*----------------------------------------------------------------------------
* Constants for long-term predictor
*----------------------------------------------------------------------------
*/
- public static final short PIT_MIN = 20 ; /* Minimum pitch lag
in samples */
- public static final short PIT_MAX = 143 ; /* Maximum pitch lag
in samples */
- public static final short L_INTERPOL = (10+1) ; /* Length of filter
for interpolation. */
- public static final short L_INTER10 = 10 ; /* Length for pitch
interpolation */
- public static final short L_INTER4 = 4 ; /* upsampling ration
for pitch search */
- public static final short UP_SAMP = 3 ; /* resolution of
fractional delays */
- public static final float THRESHPIT =(float)0.85 ; /* Threshold to
favor smaller pitch lags */
- public static final float GAIN_PIT_MAX =(float)1.2 ; /* maximum
adaptive codebook gain */
- public static final short FIR_SIZE_ANA =(UP_SAMP*L_INTER4+1);
- public static final short FIR_SIZE_SYN =(UP_SAMP*L_INTER10+1);
+ public static final short PIT_MIN = 20; /* Minimum pitch lag in samples */
+ public static final short PIT_MAX = 143; /* Maximum pitch lag in samples
*/
+ public static final short L_INTERPOL = (10 + 1); /*
+ * Length of filter for interpolation.
+ */
+ public static final short L_INTER10 = 10; /* Length for pitch
interpolation */
+ public static final short L_INTER4 = 4; /*
+ * upsampling ration for pitch search
+ */
+ public static final short UP_SAMP = 3; /* resolution of fractional delays
*/
+ public static final float THRESHPIT = (float) 0.85; /*
+ * Threshold to favor smaller pitch lags
+ */
+ public static final float GAIN_PIT_MAX = (float) 1.2; /*
+ * maximum adaptive codebook gain
+ */
+ public static final short FIR_SIZE_ANA = (UP_SAMP * L_INTER4 + 1);
+ public static final short FIR_SIZE_SYN = (UP_SAMP * L_INTER10 + 1);
/*---------------------------------------------------------------------------*
* constants for fixed
codebook *
*---------------------------------------------------------------------------*/
- public static final short DIM_RR = 616; /* size of correlation
matrix */
- public static final short NB_POS = 8 ; /* Number of positions for each
pulse */
- public static final short STEP = 5 ; /* Step betweem position of the
same pulse. */
- public static final short MSIZE = 64 ; /* Size of vectors for
cross-correlation between 2 pulses*/
+ public static final short DIM_RR = 616; /* size of correlation matrix */
+ public static final short NB_POS = 8; /* Number of positions for each
pulse */
+ public static final short STEP = 5; /*
+ * Step betweem position of the same pulse.
+ */
+ public static final short MSIZE = 64; /*
+ * Size of vectors for cross-correlation between 2 pulses
+ */
- public static final float SHARPMAX = (float)0.7945 ; /* Maximum
value of pitch sharpening */
- public static final float SHARPMIN = (float)0.2 ; /* minimum
value of pitch sharpening */
+ public static final float SHARPMAX = (float) 0.7945; /*
+ * Maximum value of pitch sharpening
+ */
+ public static final float SHARPMIN = (float) 0.2; /*
+ * minimum value of pitch sharpening
+ */
-
/*--------------------------------------------------------------------------*
- * Example values for threshold and approximated worst case
complexity: *
-
* *
- * threshold=0.40 maxtime= 75 extra=30 Mips =
6.0 *
-
*--------------------------------------------------------------------------*/
- public static final float THRESHFCB = (float)0.40 ; /* */
- public static final short MAX_TIME = 75 ; /* */
+
/*--------------------------------------------------------------------------*
+ * Example values for threshold and approximated worst case
complexity: *
+
* *
+ * threshold=0.40 maxtime= 75 extra=30 Mips =
6.0 *
+
*--------------------------------------------------------------------------*/
+ public static final float THRESHFCB = (float) 0.40; /* */
+ public static final short MAX_TIME = 75; /* */
/*--------------------------------------------------------------------------*
* Constants for taming procedure. *
*--------------------------------------------------------------------------*/
- public static final float GPCLIP =(float)0.95 ; /* Maximum pitch
gain if taming is needed */
- public static final float GPCLIP2 =(float)0.94 ; /* Maximum pitch
gain if taming is needed */
- public static final float GP0999 =(float)0.9999 ; /* Maximum pitch
gain if taming is needed */
- public static final float THRESH_ERR =(float)60000. ; /* Error
threshold taming */
- public static final float INV_L_SUBFR =(float)
((float)1./(float)L_SUBFR) ;/* =0.025 */
+ public static final float GPCLIP = (float) 0.95; /*
+ * Maximum pitch gain if taming is needed
+ */
+ public static final float GPCLIP2 = (float) 0.94; /*
+ * Maximum pitch gain if taming is needed
+ */
+ public static final float GP0999 = (float) 0.9999; /*
+ * Maximum pitch gain if taming is needed
+ */
+ public static final float THRESH_ERR = (float) 60000.; /*
+ * Error threshold taming
+ */
+ public static final float INV_L_SUBFR = (float) ((float) 1. / (float)
L_SUBFR);/*
+ * = 0.025
+ */
/*-------------------------------------------------------------------------
* gain quantizer constants
*-------------------------------------------------------------------------
*/
- public static final float MEAN_ENER = (float)36.0 ; /* average
innovation energy */
- public static final short NCODE1_B = 3 ; /* number of
Codebook-bit */
- public static final short NCODE2_B = 4 ; /* number of
Codebook-bit */
- public static final short NCODE1 = (1<<NCODE1_B) ; /* Codebook 1
size */
- public static final short NCODE2 =(1<<NCODE2_B); /* Codebook 2
size */
- public static final float NCAN1 = 4 ; /* Pre-selecting
order for #1 */
- public static final float NCAN2 = 8 ; /* Pre-selecting
order for #2 */
- public static final float INV_COEF =(float)-0.032623;
+ public static final float MEAN_ENER = (float) 36.0; /*
+ * average innovation energy
+ */
+ public static final short NCODE1_B = 3; /* number of Codebook-bit */
+ public static final short NCODE2_B = 4; /* number of Codebook-bit */
+ public static final short NCODE1 = (1 << NCODE1_B); /* Codebook 1 size */
+ public static final short NCODE2 = (1 << NCODE2_B); /* Codebook 2 size */
+ public static final float NCAN1 = 4; /* Pre-selecting order for #1 */
+ public static final float NCAN2 = 8; /* Pre-selecting order for #2 */
+ public static final float INV_COEF = (float) -0.032623;
/*---------------------------------------------------------------------------
* Constants for postfilter
*---------------------------------------------------------------------------
*/
- /* INT16 term pst parameters : */
- public static final float GAMMA1_PST = (float)0.7 ; /* denominator
weighting factor */
- public static final float GAMMA2_PST = (float)0.55 ; /* numerator
weighting factor */
- public static final short LONG_H_ST = 20 ; /* impulse response
length */
- public static final float GAMMA3_PLUS = (float)0.2 ; /* tilt
weighting factor when k1>0 */
- public static final float GAMMA3_MINUS = (float)0.9 ; /* tilt
weighting factor when k1<0 */
+ /* INT16 term pst parameters : */
+ public static final float GAMMA1_PST = (float) 0.7; /*
+ * denominator weighting factor
+ */
+ public static final float GAMMA2_PST = (float) 0.55; /*
+ * numerator weighting factor
+ */
+ public static final short LONG_H_ST = 20; /* impulse response length */
+ public static final float GAMMA3_PLUS = (float) 0.2; /*
+ * tilt weighting factor when k1>0
+ */
+ public static final float GAMMA3_MINUS = (float) 0.9; /*
+ * tilt weighting factor when k1<0
+ */
- /* long term pst parameters : */
- public static final short L_SUBFRP1= (L_SUBFR + 1); /* Sub-frame size +
1 */
- public static final short F_UP_PST = 8 ; /* resolution for
fractionnal delay */
- public static final short LH2_S = 4 ; /* length of INT16
interp. subfilters */
- public static final short LH2_L = 16 ; /* length of long
interp. subfilters */
- public static final float THRESCRIT = (float)0.5 ; /* threshold
LT pst switch off */
- public static final float GAMMA_G = (float)0.5 ; /* LT
weighting factor */
- public static final float AGC_FAC = (float)0.9875 ; /* gain
adjustment factor */
+ /* long term pst parameters : */
+ public static final short L_SUBFRP1 = (L_SUBFR + 1); /* Sub-frame size +
1 */
+ public static final short F_UP_PST = 8; /* resolution for fractionnal
delay */
+ public static final short LH2_S = 4; /* length of INT16 interp.
subfilters */
+ public static final short LH2_L = 16; /* length of long interp.
subfilters */
+ public static final float THRESCRIT = (float) 0.5; /*
+ * threshold LT pst switch off
+ */
+ public static final float GAMMA_G = (float) 0.5; /* LT weighting factor */
+ public static final float AGC_FAC = (float) 0.9875; /*
+ * gain adjustment factor
+ */
- public static final float AGC_FAC1 = ((float)1. - AGC_FAC); /*
gain adjustment factor */
- public static final short LH_UP_S = (LH2_S/2);
- public static final short LH_UP_L = (LH2_L/2);
- public static final short LH2_L_P1 = (LH2_L + 1);
- public static final float MIN_GPLT = ((float)1. / ((float)1. +
GAMMA_G)); /* LT gain minimum */
+ public static final float AGC_FAC1 = ((float) 1. - AGC_FAC); /*
+ * gain adjustment factor
+ */
+ public static final short LH_UP_S = (LH2_S / 2);
+ public static final short LH_UP_L = (LH2_L / 2);
+ public static final short LH2_L_P1 = (LH2_L + 1);
+ public static final float MIN_GPLT = ((float) 1. / ((float) 1. +
GAMMA_G)); /*
+ * LT gain minimum
+ */
/* Array sizes */
- public static final short MEM_RES2 =(PIT_MAX + 1 + LH_UP_L);
- public static final short SIZ_RES2 =(MEM_RES2 + L_SUBFR);
- public static final short SIZ_Y_UP =((F_UP_PST-1) * L_SUBFRP1);
- public static final short SIZ_TAB_HUP_L =((F_UP_PST-1) * LH2_L);
- public static final short SIZ_TAB_HUP_S =((F_UP_PST-1) * LH2_S);
-
+ public static final short MEM_RES2 = (PIT_MAX + 1 + LH_UP_L);
+ public static final short SIZ_RES2 = (MEM_RES2 + L_SUBFR);
+ public static final short SIZ_Y_UP = ((F_UP_PST - 1) * L_SUBFRP1);
+ public static final short SIZ_TAB_HUP_L = ((F_UP_PST - 1) * LH2_L);
+ public static final short SIZ_TAB_HUP_S = ((F_UP_PST - 1) * LH2_S);
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Lpc.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Lpc.java Thu Feb 21
09:21:48 2013
@@ -1,36 +1,34 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class Lpc {
-
+
/*----------------------------------------------------------------------------
* autocorr - compute the auto-correlations of windowed speech signal
*----------------------------------------------------------------------------
*/
- void autocorr(
- float []x, /* input : input signal x[0:L_WINDOW] */
- int m, /* input : LPC order */
- float []r /* output: auto-correlation vector r[0:M]*/
- )
- {
- float y[] = new float[LD8KConstants.L_WINDOW];
- float sum;
- int i, j;
+ void autocorr(float[] x, /* input : input signal x[0:L_WINDOW] */
+ int m, /* input : LPC order */
+ float[] r /* output: auto-correlation vector r[0:M] */
+ ) {
+ float y[] = new float[LD8KConstants.L_WINDOW];
+ float sum;
+ int i, j;
+ for (i = 0; i < LD8KConstants.L_WINDOW; i++)
+ y[i] = x[i] * TabLD8k.hamwindow[i];
- for (i = 0; i < LD8KConstants.L_WINDOW; i++)
- y[i] = x[i]*TabLD8k.hamwindow[i];
+ for (i = 0; i <= m; i++) {
+ sum = (float) 0.0;
+ for (j = 0; j < LD8KConstants.L_WINDOW - i; j++)
+ sum += y[j] * y[j + i];
+ r[i] = sum;
+ }
+ if (r[0] < (float) 1.0)
+ r[0] = (float) 1.0;
- for (i = 0; i <= m; i++)
- {
- sum = (float)0.0;
- for (j = 0; j < LD8KConstants.L_WINDOW-i; j++)
- sum += y[j]*y[j+i];
- r[i] = sum;
- }
- if (r[0]<(float)1.0) r[0]=(float)1.0;
-
- return;
+ return;
}
/*-------------------------------------------------------------*
@@ -39,56 +37,50 @@
* lag windowing of the autocorrelations *
*-------------------------------------------------------------*/
- void lag_window(
- int m, /* input : LPC order */
- float r[] /* in/out: correlation */
- )
- {
- int i;
+ void lag_window(int m, /* input : LPC order */
+ float r[] /* in/out: correlation */
+ ) {
+ int i;
- for (i=1; i<= m; i++)
- r[i] *= TabLD8k.lwindow[i-1];
+ for (i = 1; i <= m; i++)
+ r[i] *= TabLD8k.lwindow[i - 1];
- return;
+ return;
}
-
/*----------------------------------------------------------------------------
* levinson - levinson-durbin recursion to compute LPC parameters
*----------------------------------------------------------------------------
*/
- float levinson( /* output: prediction error (energy) */
- float []r, /* input : auto correlation coefficients r[0:M]
*/
- float []a, /* output: lpc coefficients a[0] = 1 */
- float []rc /* output: reflection coefficients rc[0:M-1]
*/
- )
- {
- float s, at, err;
- int i, j, l;
+ float levinson( /* output: prediction error (energy) */
+ float[] r, /* input : auto correlation coefficients r[0:M] */
+ float[] a, /* output: lpc coefficients a[0] = 1 */
+ float[] rc /* output: reflection coefficients rc[0:M-1] */
+ ) {
+ float s, at, err;
+ int i, j, l;
- rc[0] = (-r[1])/r[0];
- a[0] = (float)1.0;
- a[1] = rc[0];
- err = r[0] + r[1]*rc[0];
- for (i = 2; i <= LD8KConstants.M; i++)
- {
- s = (float)0.0;
- for (j = 0; j < i; j++)
- s += r[i-j]*a[j];
- rc[i-1]= (-s)/(err);
- for (j = 1; j <= (i/2); j++)
- {
- l = i-j;
- at = a[j] + rc[i-1]*a[l];
- a[l] += rc[i-1]*a[j];
- a[j] = at;
- }
- a[i] = rc[i-1];
- err += rc[i-1]*s;
- if (err <= (float)0.0)
- err = (float)0.001;
- }
- return (err);
+ rc[0] = (-r[1]) / r[0];
+ a[0] = (float) 1.0;
+ a[1] = rc[0];
+ err = r[0] + r[1] * rc[0];
+ for (i = 2; i <= LD8KConstants.M; i++) {
+ s = (float) 0.0;
+ for (j = 0; j < i; j++)
+ s += r[i - j] * a[j];
+ rc[i - 1] = (-s) / (err);
+ for (j = 1; j <= (i / 2); j++) {
+ l = i - j;
+ at = a[j] + rc[i - 1] * a[l];
+ a[l] += rc[i - 1] * a[j];
+ a[j] = at;
+ }
+ a[i] = rc[i - 1];
+ err += rc[i - 1] * s;
+ if (err <= (float) 0.0)
+ err = (float) 0.001;
+ }
+ return (err);
}
/*------------------------------------------------------------------*
@@ -103,106 +95,100 @@
*------------------------------------------------------------------*/
/* prototypes of local functions */
+ void az_lsp(float[] a, /* input : LP filter coefficients */
+ float[] lsp, /* output: Line spectral pairs (in the cosine domain) */
+ float[] old_lsp /* input : LSP vector from past frame */
+ ) {
+ int i, j, nf, ip;
+ float xlow, ylow, xhigh, yhigh, xmid, ymid, xint;
+ float[] coef;
- void az_lsp(
- float []a, /* input : LP filter
coefficients */
- float []lsp, /* output: Line spectral pairs (in the cosine
domain) */
- float []old_lsp /* input : LSP vector from past
frame */
- )
- {
- int i, j, nf, ip;
- float xlow,ylow,xhigh,yhigh,xmid,ymid,xint;
- float[] coef;
+ float f1[] = new float[LD8KConstants.NC + 1], f2[] = new
float[LD8KConstants.NC + 1];
- float f1[] = new float[LD8KConstants.NC+1], f2[] = new
float[LD8KConstants.NC+1];
+ /*-------------------------------------------------------------*
+ * find the sum and diff polynomials F1(z) and F2(z) *
+ * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) *
+ * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) *
+ *-------------------------------------------------------------*/
- /*-------------------------------------------------------------*
- * find the sum and diff polynomials F1(z) and F2(z) *
- * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) *
- * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) *
- *-------------------------------------------------------------*/
-
- f1[0] = (float)1.0;
- f2[0] = (float)1.0;
- for (i=1, j=LD8KConstants.M; i<=LD8KConstants.NC; i++, j--){
- f1[i] = a[i]+a[j]-f1[i-1];
- f2[i] = a[i]-a[j]+f2[i-1];
- }
+ f1[0] = (float) 1.0;
+ f2[0] = (float) 1.0;
+ for (i = 1, j = LD8KConstants.M; i <= LD8KConstants.NC; i++, j--) {
+ f1[i] = a[i] + a[j] - f1[i - 1];
+ f2[i] = a[i] - a[j] + f2[i - 1];
+ }
- /*---------------------------------------------------------------------*
- * Find the LSPs (roots of F1(z) and F2(z) ) using the *
- * Chebyshev polynomial evaluation. *
- * The roots of F1(z) and F2(z) are alternatively searched. *
- * We start by finding the first root of F1(z) then we switch *
- * to F2(z) then back to F1(z) and so on until all roots are found. *
- * *
- * - Evaluate Chebyshev pol. at grid points and check for sign change.*
- * - If sign change track the root by subdividing the interval *
- * NO_ITER times and ckecking sign change. *
- *---------------------------------------------------------------------*/
+ /*---------------------------------------------------------------------*
+ * Find the LSPs (roots of F1(z) and F2(z) ) using the *
+ * Chebyshev polynomial evaluation. *
+ * The roots of F1(z) and F2(z) are alternatively searched. *
+ * We start by finding the first root of F1(z) then we switch *
+ * to F2(z) then back to F1(z) and so on until all roots are found. *
+ * *
+ * - Evaluate Chebyshev pol. at grid points and check for sign change.*
+ * - If sign change track the root by subdividing the interval *
+ * NO_ITER times and ckecking sign change. *
+ *---------------------------------------------------------------------*/
- nf=0; /* number of found frequencies */
- ip=0; /* flag to first polynomial */
+ nf = 0; /* number of found frequencies */
+ ip = 0; /* flag to first polynomial */
- coef = f1; /* start with F1(z) */
+ coef = f1; /* start with F1(z) */
- xlow=TabLD8k.grid[0];
- ylow = chebyshev(xlow,f1,LD8KConstants.NC);
+ xlow = TabLD8k.grid[0];
+ ylow = chebyshev(xlow, f1, LD8KConstants.NC);
- j = 0;
- while ( (nf < LD8KConstants.M) && (j < LD8KConstants.GRID_POINTS) )
- {
- j++;
- xhigh = xlow;
- yhigh = ylow;
- xlow = TabLD8k.grid[j];
- ylow = chebyshev(xlow,coef,LD8KConstants.NC);
+ j = 0;
+ while ((nf < LD8KConstants.M) && (j < LD8KConstants.GRID_POINTS)) {
+ j++;
+ xhigh = xlow;
+ yhigh = ylow;
+ xlow = TabLD8k.grid[j];
+ ylow = chebyshev(xlow, coef, LD8KConstants.NC);
- if (ylow*yhigh <= (float)0.0) /* if sign change new root exists */
- {
- j--;
+ if (ylow * yhigh <= (float) 0.0) /* if sign change new root exists */
+ {
+ j--;
- /* divide the interval of sign change by 4 */
+ /* divide the interval of sign change by 4 */
- for (i = 0; i < 4; i++)
- {
- xmid = (float)0.5*(xlow + xhigh);
- ymid = chebyshev(xmid,coef,LD8KConstants.NC);
- if (ylow*ymid <= (float)0.0)
- {
- yhigh = ymid;
- xhigh = xmid;
- }
- else
- {
- ylow = ymid;
- xlow = xmid;
- }
- }
+ for (i = 0; i < 4; i++) {
+ xmid = (float) 0.5 * (xlow + xhigh);
+ ymid = chebyshev(xmid, coef, LD8KConstants.NC);
+ if (ylow * ymid <= (float) 0.0) {
+ yhigh = ymid;
+ xhigh = xmid;
+ } else {
+ ylow = ymid;
+ xlow = xmid;
+ }
+ }
- /* linear interpolation for evaluating the root */
+ /* linear interpolation for evaluating the root */
- xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow);
+ xint = xlow - ylow * (xhigh - xlow) / (yhigh - ylow);
- lsp[nf] = xint; /* new root */
- nf++;
+ lsp[nf] = xint; /* new root */
+ nf++;
- ip = 1 - ip; /* flag to other polynomial */
- coef = ip!=0 ? f2 : f1; /* pointer to other polynomial */
+ ip = 1 - ip; /* flag to other polynomial */
+ coef = ip != 0 ? f2 : f1; /* pointer to other polynomial */
- xlow = xint;
- ylow = chebyshev(xlow,coef,LD8KConstants.NC);
- }
- }
+ xlow = xint;
+ ylow = chebyshev(xlow, coef, LD8KConstants.NC);
+ }
+ }
- /* Check if M roots found */
- /* if not use the LSPs from previous frame */
+ /* Check if M roots found */
+ /* if not use the LSPs from previous frame */
- if ( nf < LD8KConstants.M)
- for(i=0; i<LD8KConstants.M; i++) lsp[i] = old_lsp[i];
+ if (nf < LD8KConstants.M)
+ for (i = 0; i < LD8KConstants.M; i++)
+ lsp[i] = old_lsp[i];
- return;
+ return;
}
+
/*------------------------------------------------------------------*
* End procedure az_lsp() *
*------------------------------------------------------------------*/
@@ -218,25 +204,25 @@
* C(x) = T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2 *
*--------------------------------------------------------------*/
- static float chebyshev(/* output: the value of the polynomial C(x) */
- float x, /* input : value of evaluation; x=cos(freq) */
- float []f, /* input : coefficients of sum or diff polynomial */
- int n /* input : order of polynomial */
- )
- {
- float b1, b2, b0, x2;
- int i; /* for the special case of 10th
order */
- /* filter
(n=5) */
- x2 = (float)2.0*x; /* x2 =
2.0*x; */
- b2 = (float)1.0; /* f[0] */
/* */
- b1 = x2 + f[1]; /* b1 = x2 +
f[1]; */
- for (i=2; i<n; i++) {
/* */
- b0 = x2*b1 - b2 + f[i]; /* b0 = x2 * b1 - 1. +
f[2]; */
- b2 = b1; /* b2 = x2 * b0 - b1 +
f[3]; */
- b1 = b0; /* b1 = x2 * b2 - b0 +
f[4]; */
- }
/* */
- return (x*b1 - b2 + (float)0.5*f[n]); /* return (x*b1 - b2 +
0.5*f[5]); */
+ static float chebyshev(/* output: the value of the polynomial C(x) */
+ float x, /* input : value of evaluation; x=cos(freq) */
+ float[] f, /* input : coefficients of sum or diff polynomial */
+ int n /* input : order of polynomial */
+ ) {
+ float b1, b2, b0, x2;
+ int i; /* for the special case of 10th order */
+ /* filter (n=5) */
+ x2 = (float) 2.0 * x; /* x2 = 2.0*x; */
+ b2 = (float) 1.0; /* f[0] *//* */
+ b1 = x2 + f[1]; /* b1 = x2 + f[1]; */
+ for (i = 2; i < n; i++) { /* */
+ b0 = x2 * b1 - b2 + f[i]; /* b0 = x2 * b1 - 1. + f[2]; */
+ b2 = b1; /* b2 = x2 * b0 - b1 + f[3]; */
+ b1 = b0; /* b1 = x2 * b2 - b0 + f[4]; */
+ } /* */
+ return (x * b1 - b2 + (float) 0.5 * f[n]); /*
+ * return (x*b1 - b2 + 0.5*f[5]);
+ */
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/LpcFunc.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/LpcFunc.java Thu Feb 21
09:21:48 2013
@@ -1,175 +1,159 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class LpcFunc {
-
/*-----------------------------------------------------------------------------
* lsp_az - convert LSPs to predictor coefficients a[]
*-----------------------------------------------------------------------------
*/
- public static void lsp_az(
- float []lsp,int lsps, /* input : lsp[0:M-1] */
- float []a ,int as /* output: predictor coeffs a[0:M], a[0]
= 1. */
- )
- {
+ public static void lsp_az(float[] lsp, int lsps, /* input : lsp[0:M-1] */
+ float[] a, int as /* output: predictor coeffs a[0:M], a[0] = 1. */
+ ) {
- float f1[] = new float[LD8KConstants.NC+1], f2[] = new
float[LD8KConstants.NC+1];
- int i,j;
+ float f1[] = new float[LD8KConstants.NC + 1], f2[] = new
float[LD8KConstants.NC + 1];
+ int i, j;
+ get_lsp_pol(lsp, lsps, f1, 0);
+ get_lsp_pol(lsp, lsps + 1, f2, 0);
- get_lsp_pol(lsp,lsps,f1,0);
- get_lsp_pol(lsp,lsps+1,f2,0);
+ for (i = LD8KConstants.NC; i > 0; i--) {
+ f1[i] += f1[i - 1];
+ f2[i] -= f2[i - 1];
+ }
+ a[as + 0] = (float) 1.0;
+ for (i = 1, j = LD8KConstants.M; i <= LD8KConstants.NC; i++, j--) {
+ a[as + i] = (float) 0.5 * (f1[i] + f2[i]);
+ a[as + j] = (float) 0.5 * (f1[i] - f2[i]);
+ }
- for (i = LD8KConstants.NC; i > 0; i--)
- {
- f1[i] += f1[i-1];
- f2[i] -= f2[i-1];
- }
- a[as+0] = (float)1.0;
- for (i = 1, j = LD8KConstants.M; i <= LD8KConstants.NC; i++, j--)
- {
- a[as+i] = (float)0.5*(f1[i] + f2[i]);
- a[as+j] = (float)0.5*(f1[i] - f2[i]);
- }
-
- return;
+ return;
}
-
/*----------------------------------------------------------------------------
* get_lsp_pol - find the polynomial F1(z) or F2(z) from the LSFs
*----------------------------------------------------------------------------
*/
- public static void get_lsp_pol(
- float lsp[], int lsps, /* input : line spectral freq.
(cosine domain) */
- float f[] , int fs /* output: the coefficients of F1 or F2
*/
- )
- {
- float b;
- int i,j;
+ public static void get_lsp_pol(float lsp[], int lsps, /*
+ * input : line spectral freq. (cosine domain)
+ */
+ float f[], int fs /* output: the coefficients of F1 or F2 */
+ ) {
+ float b;
+ int i, j;
- f[fs+0] = (float)1.0;
- b = (float)-2.0*lsp[lsps+0];
- f[fs+1] = b;
- for (i = 2; i <= LD8KConstants.NC; i++)
- {
- b = (float)-2.0*lsp[lsps+2*i-2];
- f[i] = b*f[fs+i-1] + (float)2.0*f[fs+i-2];
- for (j = i-1; j > 1; j--)
- f[fs+j] += b*f[fs+j-1] + f[fs+j-2];
- f[fs+1] += b;
- }
- return;
+ f[fs + 0] = (float) 1.0;
+ b = (float) -2.0 * lsp[lsps + 0];
+ f[fs + 1] = b;
+ for (i = 2; i <= LD8KConstants.NC; i++) {
+ b = (float) -2.0 * lsp[lsps + 2 * i - 2];
+ f[i] = b * f[fs + i - 1] + (float) 2.0 * f[fs + i - 2];
+ for (j = i - 1; j > 1; j--)
+ f[fs + j] += b * f[fs + j - 1] + f[fs + j - 2];
+ f[fs + 1] += b;
+ }
+ return;
}
/*----------------------------------------------------------------------------
* lsf_lsp - convert from lsf[0..M-1 to lsp[0..M-1]
*----------------------------------------------------------------------------
*/
- public static void lsf_lsp(
- float lsf[], /* input : lsf */
- float lsp[], /* output: lsp */
- int m
- )
- {
- int i;
- for ( i = 0; i < m; i++ )
- lsp[i] = (float)Math.cos((double)lsf[i]);
- return;
+ public static void lsf_lsp(float lsf[], /* input : lsf */
+ float lsp[], /* output: lsp */
+ int m) {
+ int i;
+ for (i = 0; i < m; i++)
+ lsp[i] = (float) Math.cos((double) lsf[i]);
+ return;
}
/*----------------------------------------------------------------------------
* lsp_lsf - convert from lsp[0..M-1 to lsf[0..M-1]
*----------------------------------------------------------------------------
*/
- public static void lsp_lsf(
- float lsp[], /* input : lsp coefficients */
- float lsf[], /* output: lsf (normalized frequencies */
- int m
- )
- {
- int i;
+ public static void lsp_lsf(float lsp[], /* input : lsp coefficients */
+ float lsf[], /* output: lsf (normalized frequencies */
+ int m) {
+ int i;
- for ( i = 0; i < m; i++ )
- lsf[i] = (float)Math.acos((double)lsp[i]);
- return;
+ for (i = 0; i < m; i++)
+ lsf[i] = (float) Math.acos((double) lsp[i]);
+ return;
}
-
/*---------------------------------------------------------------------------
* weigh_az: Weighting of LPC coefficients ap[i] = a[i] * (gamma ** i)
*---------------------------------------------------------------------------
*/
- public static void weight_az(
- float []a, int as, /* input : lpc coefficients a[0:m] */
- float gamma, /* input : weighting factor */
- int m, /* input : filter order */
- float []ap, int aps /* output: weighted coefficients ap[0:m]
*/
+ public static void weight_az(float[] a, int as, /*
+ * input : lpc coefficients a[0:m]
+ */
+ float gamma, /* input : weighting factor */
+ int m, /* input : filter order */
+ float[] ap, int aps /* output: weighted coefficients ap[0:m] */
- )
- {
- float fac;
- int i;
+ ) {
+ float fac;
+ int i;
- ap[aps] = a[as];
- fac = gamma;
- for (i = 1; i <m; i++) {
- ap[aps+i] = fac * a[as+i];
- fac *= gamma;
- }
- ap[aps+m] = fac * a[as+m];
- return;
+ ap[aps] = a[as];
+ fac = gamma;
+ for (i = 1; i < m; i++) {
+ ap[aps + i] = fac * a[as + i];
+ fac *= gamma;
+ }
+ ap[aps + m] = fac * a[as + m];
+ return;
}
-
-
/*-----------------------------------------------------------------------------
* int_qlpc - interpolated M LSP parameters and convert to M+1 LPC coeffs
*-----------------------------------------------------------------------------
*/
- public static void int_qlpc(
- float lsp_old[], /* input : LSPs for past frame (0:M-1) */
- float lsp_new[], /* input : LSPs for present frame (0:M-1) */
- float az[] /* output: filter parameters in 2 subfr (dim
2(m+1)) */
- )
- {
- int i;
- float lsp[] = new float[LD8KConstants.M];
+ public static void int_qlpc(float lsp_old[], /*
+ * input : LSPs for past frame (0:M-1)
+ */
+ float lsp_new[], /* input : LSPs for present frame (0:M-1) */
+ float az[] /* output: filter parameters in 2 subfr (dim 2(m+1)) */
+ ) {
+ int i;
+ float lsp[] = new float[LD8KConstants.M];
- for (i = 0; i < LD8KConstants.M; i++)
- lsp[i] = lsp_old[i]*(float)0.5 + lsp_new[i]*(float)0.5;
+ for (i = 0; i < LD8KConstants.M; i++)
+ lsp[i] = lsp_old[i] * (float) 0.5 + lsp_new[i] * (float) 0.5;
- lsp_az(lsp,0, az,0);
- lsp_az(lsp_new,0, az,LD8KConstants.M+1);
+ lsp_az(lsp, 0, az, 0);
+ lsp_az(lsp_new, 0, az, LD8KConstants.M + 1);
- return;
+ return;
}
+
/*-----------------------------------------------------------------------------
* int_lpc - interpolated M LSP parameters and convert to M+1 LPC coeffs
*-----------------------------------------------------------------------------
*/
- public static void int_lpc(
- float lsp_old[], /* input : LSPs for past frame (0:M-1) */
- float lsp_new[], /* input : LSPs for present frame (0:M-1) */
- float lsf_int[], /* output: interpolated lsf coefficients */
- float lsf_new[], /* input : LSFs for present frame (0:M-1) */
- float az[] /* output: filter parameters in 2 subfr (dim
2(m+1)) */
- )
- {
- int i;
- float lsp[] = new float[LD8KConstants.M];
-
+ public static void int_lpc(float lsp_old[], /*
+ * input : LSPs for past frame (0:M-1)
+ */
+ float lsp_new[], /* input : LSPs for present frame (0:M-1) */
+ float lsf_int[], /* output: interpolated lsf coefficients */
+ float lsf_new[], /* input : LSFs for present frame (0:M-1) */
+ float az[] /* output: filter parameters in 2 subfr (dim 2(m+1)) */
+ ) {
+ int i;
+ float lsp[] = new float[LD8KConstants.M];
- for (i = 0; i < LD8KConstants.M; i++)
- lsp[i] = lsp_old[i]*(float)0.5 + lsp_new[i]*(float)0.5;
+ for (i = 0; i < LD8KConstants.M; i++)
+ lsp[i] = lsp_old[i] * (float) 0.5 + lsp_new[i] * (float) 0.5;
- lsp_az(lsp,0, az,0);
+ lsp_az(lsp, 0, az, 0);
- lsp_lsf(lsp, lsf_int, LD8KConstants.M);
- lsp_lsf(lsp_new, lsf_new, LD8KConstants.M);
+ lsp_lsf(lsp, lsf_int, LD8KConstants.M);
+ lsp_lsf(lsp_new, lsf_new, LD8KConstants.M);
- return;
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/LspDec.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/LspDec.java Thu Feb 21
09:21:48 2013
@@ -1,101 +1,97 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class LspDec {
/* static memory */
- float freq_prev[][] = new float[LD8KConstants.MA_NP][LD8KConstants.M];
/* previous LSP vector */
- float freq_prev_reset[] = new float[]{ /* previous LSP vector(init) */
- (float)0.285599, (float)0.571199, (float)0.856798, (float)1.142397,
(float)1.427997,
- (float)1.713596, (float)1.999195, (float)2.284795, (float)2.570394,
(float)2.855993
- }; /* PI*(float)(j+1)/(float)(M+1) */
+ float freq_prev[][] = new float[LD8KConstants.MA_NP][LD8KConstants.M]; /*
+ * previous LSP vector
+ */
+ float freq_prev_reset[] = new float[] { /* previous LSP vector(init) */
+ (float) 0.285599, (float) 0.571199, (float) 0.856798, (float) 1.142397,
(float) 1.427997, (float) 1.713596,
+ (float) 1.999195, (float) 2.284795, (float) 2.570394, (float) 2.855993
}; /*
+ * PI*(float) ( j+1)/(float )(M+1)
+ */
/* static memory for frame erase operation */
- static int prev_ma; /* previous MA prediction coef.*/
- static float prev_lsp[] = new float[LD8KConstants.M]; /*
previous LSP vector */
-
+ static int prev_ma; /* previous MA prediction coef. */
+ static float prev_lsp[] = new float[LD8KConstants.M]; /* previous LSP
vector */
/*----------------------------------------------------------------------------
* Lsp_decw_reset - set the previous LSP vectors
*----------------------------------------------------------------------------
*/
- void lsp_decw_reset()
- {
- int i;
+ void lsp_decw_reset() {
+ int i;
- for(i=0; i<LD8KConstants.MA_NP; i++)
- Util.copy (freq_prev_reset, freq_prev[i], LD8KConstants.M );
+ for (i = 0; i < LD8KConstants.MA_NP; i++)
+ Util.copy(freq_prev_reset, freq_prev[i], LD8KConstants.M);
- prev_ma = 0;
+ prev_ma = 0;
- Util.copy (freq_prev_reset, prev_lsp, LD8KConstants.M );
+ Util.copy(freq_prev_reset, prev_lsp, LD8KConstants.M);
- return;
+ return;
}
-
/*----------------------------------------------------------------------------
* lsp_iqua_cs - LSP main quantization routine
*----------------------------------------------------------------------------
*/
- public void lsp_iqua_cs(
- int prm[], int prms, /* input : codes of the selected LSP */
- float lsp_q[], /* output: Quantized LSP parameters */
- int erase /* input : frame erase information */
- )
- {
- int mode_index;
- int code0;
- int code1;
- int code2;
- float buf[] = new float[LD8KConstants.M];
+ public void lsp_iqua_cs(int prm[], int prms, /*
+ * input : codes of the selected LSP
+ */
+ float lsp_q[], /* output: Quantized LSP parameters */
+ int erase /* input : frame erase information */
+ ) {
+ int mode_index;
+ int code0;
+ int code1;
+ int code2;
+ float buf[] = new float[LD8KConstants.M];
-
- if(erase==0) /* Not frame erasure */
- {
- mode_index = (prm[prms+0] >> LD8KConstants.NC0_B) & 1;
- code0 = prm[prms+0] & (short)(LD8KConstants.NC0 - 1);
- code1 = (prm[prms+1] >> LD8KConstants.NC1_B) &
(short)(LD8KConstants.NC1 - 1);
- code2 = prm[prms+1] & (short)(LD8KConstants.NC1 - 1);
+ if (erase == 0) /* Not frame erasure */
+ {
+ mode_index = (prm[prms + 0] >> LD8KConstants.NC0_B) & 1;
+ code0 = prm[prms + 0] & (short) (LD8KConstants.NC0 - 1);
+ code1 = (prm[prms + 1] >> LD8KConstants.NC1_B) & (short)
(LD8KConstants.NC1 - 1);
+ code2 = prm[prms + 1] & (short) (LD8KConstants.NC1 - 1);
- LspGetq.lsp_get_quant(TabLD8k.lspcb1, TabLD8k.lspcb2, code0,
code1, code2, TabLD8k.fg[mode_index],
- freq_prev, lsp_q, TabLD8k.fg_sum[mode_index]);
+ LspGetq.lsp_get_quant(TabLD8k.lspcb1, TabLD8k.lspcb2, code0, code1,
code2, TabLD8k.fg[mode_index],
+ freq_prev, lsp_q, TabLD8k.fg_sum[mode_index]);
- Util.copy(lsp_q, prev_lsp, LD8KConstants.M );
- prev_ma = mode_index;
- }
- else /* Frame erased */
- {
- Util.copy(prev_lsp, lsp_q, LD8KConstants.M );
+ Util.copy(lsp_q, prev_lsp, LD8KConstants.M);
+ prev_ma = mode_index;
+ } else /* Frame erased */
+ {
+ Util.copy(prev_lsp, lsp_q, LD8KConstants.M);
- /* update freq_prev */
- LspGetq.lsp_prev_extract(prev_lsp, buf,
- TabLD8k.fg[prev_ma], freq_prev, TabLD8k.fg_sum_inv[prev_ma]);
- LspGetq.lsp_prev_update(buf, freq_prev);
- }
- return;
+ /* update freq_prev */
+ LspGetq.lsp_prev_extract(prev_lsp, buf, TabLD8k.fg[prev_ma], freq_prev,
TabLD8k.fg_sum_inv[prev_ma]);
+ LspGetq.lsp_prev_update(buf, freq_prev);
+ }
+ return;
}
+
/*----------------------------------------------------------------------------
* d_lsp - decode lsp parameters
*----------------------------------------------------------------------------
*/
- public void d_lsp(
- int index[], int is, /* input : indexes */
- float lsp_q[], /* output: decoded lsp */
- int bfi /* input : frame erase information */
- )
- {
- int i;
+ public void d_lsp(int index[], int is, /* input : indexes */
+ float lsp_q[], /* output: decoded lsp */
+ int bfi /* input : frame erase information */
+ ) {
+ int i;
- lsp_iqua_cs(index, is, lsp_q,bfi); /* decode quantized information */
+ lsp_iqua_cs(index, is, lsp_q, bfi); /* decode quantized information */
- /* Convert LSFs to LSPs */
+ /* Convert LSFs to LSPs */
- for (i=0; i<LD8KConstants.M; i++ )
- lsp_q[i] = (float)Math.cos(lsp_q[i]);
+ for (i = 0; i < LD8KConstants.M; i++)
+ lsp_q[i] = (float) Math.cos(lsp_q[i]);
- return;
+ return;
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/LspGetq.java Sun Feb 17
19:49:41 2013
+++ /branches/red5sip/src/java/org/red5/codecs/g729/LspGetq.java Thu Feb 21
09:21:48 2013
@@ -2,223 +2,209 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class LspGetq {
- protected static Logger log = LoggerFactory.getLogger(LspGetq.class);
-
+ protected static Logger log = LoggerFactory.getLogger(LspGetq.class);
+
/*----------------------------------------------------------------------------
* lsp_get_quant - reconstruct quantized LSP parameter and check the
stabilty
*----------------------------------------------------------------------------
*/
- public static void lsp_get_quant(
- float lspcb1[][], /*input : first stage LSP codebook */
- float lspcb2[][], /*input : Second stage LSP codebook */
- int code0, /*input : selected code of first stage */
- int code1, /*input : selected code of second stage*/
- int code2, /*input : selected code of second stage*/
- float fg[][], /*input : MA prediction coef. */
- float freq_prev[][], /*input : previous LSP vector */
- float lspq[], /*output: quantized LSP parameters */
- float fg_sum[] /*input : present MA prediction coef. */
- )
- {
- int j;
- float buf[] = new float[LD8KConstants.M];
+ public static void lsp_get_quant(float lspcb1[][], /*
+ * input : first stage LSP codebook
+ */
+ float lspcb2[][], /* input : Second stage LSP codebook */
+ int code0, /* input : selected code of first stage */
+ int code1, /* input : selected code of second stage */
+ int code2, /* input : selected code of second stage */
+ float fg[][], /* input : MA prediction coef. */
+ float freq_prev[][], /* input : previous LSP vector */
+ float lspq[], /* output: quantized LSP parameters */
+ float fg_sum[] /* input : present MA prediction coef. */
+ ) {
+ int j;
+ float buf[] = new float[LD8KConstants.M];
+ for (j = 0; j < LD8KConstants.NC; j++)
+ buf[j] = lspcb1[code0][j] + lspcb2[code1][j];
+ for (j = LD8KConstants.NC; j < LD8KConstants.M; j++)
+ buf[j] = lspcb1[code0][j] + lspcb2[code2][j];
- for(j=0; j<LD8KConstants.NC; j++)
- buf[j] = lspcb1[code0][j] + lspcb2[code1][j];
- for(j=LD8KConstants.NC; j<LD8KConstants.M; j++)
- buf[j] = lspcb1[code0][j] + lspcb2[code2][j];
+ /* check */
+ lsp_expand_1_2(buf, LD8KConstants.GAP1);
+ lsp_expand_1_2(buf, LD8KConstants.GAP2);
- /* check */
- lsp_expand_1_2(buf, LD8KConstants.GAP1);
- lsp_expand_1_2(buf, LD8KConstants.GAP2);
+ /* reconstruct quantized LSP parameters */
+ lsp_prev_compose(buf, lspq, fg, freq_prev, fg_sum);
- /* reconstruct quantized LSP parameters */
- lsp_prev_compose(buf, lspq, fg, freq_prev, fg_sum);
+ lsp_prev_update(buf, freq_prev);
- lsp_prev_update(buf, freq_prev);
+ lsp_stability(lspq); /* check the stabilty */
- lsp_stability( lspq ); /* check the stabilty */
-
- return;
+ return;
}
/*----------------------------------------------------------------------------
* lsp_expand_1 - check for lower (0-4)
*----------------------------------------------------------------------------
*/
- public static void lsp_expand_1(
- float buf[], /* in/out: lsp vectors */
- float gap
- )
- {
- int j;
- float diff, tmp;
+ public static void lsp_expand_1(float buf[], /* in/out: lsp vectors */
+ float gap) {
+ int j;
+ float diff, tmp;
- for(j=1; j<LD8KConstants.NC; j++) {
- diff = buf[j-1] - buf[j];
- tmp = (diff + gap) * (float)0.5;
- if(tmp > 0) {
- buf[j-1] -= tmp;
- buf[j] += tmp;
- }
- }
- return;
+ for (j = 1; j < LD8KConstants.NC; j++) {
+ diff = buf[j - 1] - buf[j];
+ tmp = (diff + gap) * (float) 0.5;
+ if (tmp > 0) {
+ buf[j - 1] -= tmp;
+ buf[j] += tmp;
+ }
+ }
+ return;
}
/*----------------------------------------------------------------------------
* lsp_expand_2 - check for higher (5-9)
*----------------------------------------------------------------------------
*/
- public static void lsp_expand_2(
- float buf[], /*in/out: lsp vectors */
- float gap
+ public static void lsp_expand_2(float buf[], /* in/out: lsp vectors */
+ float gap
- )
- {
- int j;
- float diff, tmp;
+ ) {
+ int j;
+ float diff, tmp;
- for(j=LD8KConstants.NC; j<LD8KConstants.M; j++) {
- diff = buf[j-1] - buf[j];
- tmp = (diff + gap) * (float)0.5;
- if(tmp > 0) {
- buf[j-1] -= tmp;
- buf[j] += tmp;
- }
- }
- return;
+ for (j = LD8KConstants.NC; j < LD8KConstants.M; j++) {
+ diff = buf[j - 1] - buf[j];
+ tmp = (diff + gap) * (float) 0.5;
+ if (tmp > 0) {
+ buf[j - 1] -= tmp;
+ buf[j] += tmp;
+ }
+ }
+ return;
}
/*----------------------------------------------------------------------------
* lsp_expand_1_2 - ..
*----------------------------------------------------------------------------
*/
- public static void lsp_expand_1_2(
- float buf[], /*in/out: LSP parameters */
- float gap /*input */
- )
- {
- int j;
- float diff, tmp;
+ public static void lsp_expand_1_2(float buf[], /* in/out: LSP parameters
*/
+ float gap /* input */
+ ) {
+ int j;
+ float diff, tmp;
- for(j=1; j<LD8KConstants.M; j++) {
- diff = buf[j-1] - buf[j];
- tmp = (diff + gap) * (float)0.5;
- if(tmp > 0) {
- buf[j-1] -= tmp;
- buf[j] += tmp;
- }
- }
- return;
+ for (j = 1; j < LD8KConstants.M; j++) {
+ diff = buf[j - 1] - buf[j];
+ tmp = (diff + gap) * (float) 0.5;
+ if (tmp > 0) {
+ buf[j - 1] -= tmp;
+ buf[j] += tmp;
+ }
+ }
+ return;
}
-
-
/*
- Functions which use previous LSP parameter (freq_prev).
- */
-
+ * Functions which use previous LSP parameter (freq_prev).
+ */
/*
- compose LSP parameter from elementary LSP with previous LSP.
- */
- public static void lsp_prev_compose(
- float lsp_ele[], /* (i) Q13 : LSP vectors */
- float lsp[], /* (o) Q13 : quantized LSP parameters */
- float fg[][], /* (i) Q15 : MA prediction coef. */
- float freq_prev[][], /* (i) Q13 : previous LSP vector */
- float fg_sum[] /* (i) Q15 : present MA prediction coef. */
- )
- {
- int j, k;
+ * compose LSP parameter from elementary LSP with previous LSP.
+ */
+ public static void lsp_prev_compose(float lsp_ele[], /* (i) Q13 : LSP
vectors */
+ float lsp[], /* (o) Q13 : quantized LSP parameters */
+ float fg[][], /* (i) Q15 : MA prediction coef. */
+ float freq_prev[][], /* (i) Q13 : previous LSP vector */
+ float fg_sum[] /* (i) Q15 : present MA prediction coef. */
+ ) {
+ int j, k;
- for(j=0; j<LD8KConstants.M; j++) {
- lsp[j] = lsp_ele[j] * fg_sum[j];
- for(k=0; k<LD8KConstants.MA_NP; k++) lsp[j] +=
freq_prev[k][j]*fg[k][j];
- }
- return;
+ for (j = 0; j < LD8KConstants.M; j++) {
+ lsp[j] = lsp_ele[j] * fg_sum[j];
+ for (k = 0; k < LD8KConstants.MA_NP; k++)
+ lsp[j] += freq_prev[k][j] * fg[k][j];
+ }
+ return;
}
/*
- extract elementary LSP from composed LSP with previous LSP
- */
- public static void lsp_prev_extract(
- float lsp[], /* (i) Q13 : unquantized LSP parameters */
- float lsp_ele[], /* (o) Q13 : target vector */
- float fg[][], /* (i) Q15 : MA prediction coef. */
- float freq_prev[][], /* (i) Q13 : previous LSP vector */
- float fg_sum_inv[] /* (i) Q12 : inverse previous LSP vector */
- )
- {
- int j, k;
+ * extract elementary LSP from composed LSP with previous LSP
+ */
+ public static void lsp_prev_extract(float lsp[], /*
+ * (i) Q13 : unquantized LSP parameters
+ */
+ float lsp_ele[], /* (o) Q13 : target vector */
+ float fg[][], /* (i) Q15 : MA prediction coef. */
+ float freq_prev[][], /* (i) Q13 : previous LSP vector */
+ float fg_sum_inv[] /* (i) Q12 : inverse previous LSP vector */
+ ) {
+ int j, k;
- /*----- compute target vectors for each MA coef.-----*/
- for( j = 0 ; j < LD8KConstants.M ; j++ ) {
- lsp_ele[j]=lsp[j];
- for ( k = 0 ; k < LD8KConstants.MA_NP ; k++ )
- lsp_ele[j] -= freq_prev[k][j] * fg[k][j];
- lsp_ele[j] *= fg_sum_inv[j];
- }
+ /*----- compute target vectors for each MA coef.-----*/
+ for (j = 0; j < LD8KConstants.M; j++) {
+ lsp_ele[j] = lsp[j];
+ for (k = 0; k < LD8KConstants.MA_NP; k++)
+ lsp_ele[j] -= freq_prev[k][j] * fg[k][j];
+ lsp_ele[j] *= fg_sum_inv[j];
+ }
- return;
+ return;
}
+
/*
- update previous LSP parameter
- */
- public static void lsp_prev_update(
- float lsp_ele[], /* input : LSP vectors */
- float freq_prev[][] /* input/output: previous LSP vectors */
- )
- {
- int k;
+ * update previous LSP parameter
+ */
+ public static void lsp_prev_update(float lsp_ele[], /* input : LSP
vectors */
+ float freq_prev[][] /* input/output: previous LSP vectors */
+ ) {
+ int k;
- for ( k = LD8KConstants.MA_NP-1 ; k > 0 ; k-- )
- Util.copy(freq_prev[k-1], freq_prev[k], LD8KConstants.M);
+ for (k = LD8KConstants.MA_NP - 1; k > 0; k--)
+ Util.copy(freq_prev[k - 1], freq_prev[k], LD8KConstants.M);
- Util. copy(lsp_ele, freq_prev[0], LD8KConstants.M);
- return;
+ Util.copy(lsp_ele, freq_prev[0], LD8KConstants.M);
+ return;
}
+
/*----------------------------------------------------------------------------
* lsp_stability - check stability of lsp coefficients
*----------------------------------------------------------------------------
*/
- public static void lsp_stability(
- float buf[] /*in/out: LSP parameters */
- )
- {
- int j;
- float diff, tmp;
-
+ public static void lsp_stability(float buf[] /* in/out: LSP parameters */
+ ) {
+ int j;
+ float diff, tmp;
- for(j=0; j<LD8KConstants.M-1; j++) {
- diff = buf[j+1] - buf[j];
- if( diff < (float)0. ) {
- tmp = buf[j+1];
- buf[j+1] = buf[j];
- buf[j] = tmp;
- }
- }
+ for (j = 0; j < LD8KConstants.M - 1; j++) {
+ diff = buf[j + 1] - buf[j];
+ if (diff < (float) 0.) {
+ tmp = buf[j + 1];
+ buf[j + 1] = buf[j];
+ buf[j] = tmp;
+ }
+ }
- if( buf[0] < LD8KConstants.L_LIMIT ) {
- buf[0] = LD8KConstants.L_LIMIT;
- log.warn("warning LSP Low \n");
- }
- for(j=0; j<LD8KConstants.M-1; j++) {
- diff = buf[j+1] - buf[j];
- if( diff < LD8KConstants.GAP3 ) {
- buf[j+1] = buf[j]+ LD8KConstants.GAP3;
- }
- }
- if( buf[LD8KConstants.M-1] > LD8KConstants.M_LIMIT ) {
- buf[LD8KConstants.M-1] = LD8KConstants.M_LIMIT;
- log.warn("warning LSP High \n");
- }
- return;
+ if (buf[0] < LD8KConstants.L_LIMIT) {
+ buf[0] = LD8KConstants.L_LIMIT;
+ log.warn("warning LSP Low \n");
+ }
+ for (j = 0; j < LD8KConstants.M - 1; j++) {
+ diff = buf[j + 1] - buf[j];
+ if (diff < LD8KConstants.GAP3) {
+ buf[j + 1] = buf[j] + LD8KConstants.GAP3;
+ }
+ }
+ if (buf[LD8KConstants.M - 1] > LD8KConstants.M_LIMIT) {
+ buf[LD8KConstants.M - 1] = LD8KConstants.M_LIMIT;
+ log.warn("warning LSP High \n");
+ }
+ return;
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/PParity.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/PParity.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class PParity {
@@ -7,45 +8,43 @@
* parity_pitch - compute parity bit for first 6 MSBs *
*-----------------------------------------------------*/
- public static int parity_pitch( /* output: parity bit (XOR of 6 MSB
bits) */
- int pitch_index /* input : index for which parity is computed */
- )
- {
- int temp, sum, i, bit;
+ public static int parity_pitch( /* output: parity bit (XOR of 6 MSB bits)
*/
+ int pitch_index /* input : index for which parity is computed */
+ ) {
+ int temp, sum, i, bit;
- temp = pitch_index >> 1;
+ temp = pitch_index >> 1;
- sum = 1;
- for (i = 0; i <= 5; i++) {
- temp >>= 1;
- bit = temp & 1;
- sum = sum + bit;
- }
- sum = sum & 1;
- return (sum);
+ sum = 1;
+ for (i = 0; i <= 5; i++) {
+ temp >>= 1;
+ bit = temp & 1;
+ sum = sum + bit;
+ }
+ sum = sum & 1;
+ return (sum);
}
/*--------------------------------------------------------------------*
* check_parity_pitch - check parity of index with transmitted parity *
*--------------------------------------------------------------------*/
- public static int check_parity_pitch( /* output: 0 = no error, 1= error
*/
- int pitch_index, /* input : index of parameter */
- int parity /* input : parity bit */
- )
- {
- int temp, sum, i, bit;
- temp = pitch_index >> 1;
+ public static int check_parity_pitch( /* output: 0 = no error, 1= error */
+ int pitch_index, /* input : index of parameter */
+ int parity /* input : parity bit */
+ ) {
+ int temp, sum, i, bit;
+ temp = pitch_index >> 1;
- sum = 1;
- for (i = 0; i <= 5; i++) {
- temp >>= 1;
- bit = temp & 1;
- sum = sum + bit;
- }
- sum += parity;
- sum = sum & 1;
- return (sum);
+ sum = 1;
+ for (i = 0; i <= 5; i++) {
+ temp >>= 1;
+ bit = temp & 1;
+ sum = sum + bit;
+ }
+ sum += parity;
+ sum = sum & 1;
+ return (sum);
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/Pitch.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/Pitch.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class Pitch {
@@ -7,182 +8,179 @@
* pitch_ol - compute the open loop pitch lag
*----------------------------------------------------------------------------
*/
- public static int pitch_ol( /* output: open-loop pitch lag */
- float signal[],int signals, /* input : signal to compute pitch */
- /* s[-PIT_MAX : l_frame-1] */
- int pit_min, /* input : minimum pitch
lag */
- int pit_max, /* input : maximum pitch
lag */
- int l_frame /* input : error minimization window */
- )
- {
- FloatPointer max1 = new FloatPointer(), max2 =new FloatPointer(),
max3 = new FloatPointer();
- int p_max1, p_max2, p_max3;
+ public static int pitch_ol( /* output: open-loop pitch lag */
+ float signal[], int signals, /* input : signal to compute pitch */
+ /* s[-PIT_MAX : l_frame-1] */
+ int pit_min, /* input : minimum pitch lag */
+ int pit_max, /* input : maximum pitch lag */
+ int l_frame /* input : error minimization window */
+ ) {
+ FloatPointer max1 = new FloatPointer(), max2 = new FloatPointer(), max3
= new FloatPointer();
+ int p_max1, p_max2, p_max3;
- /*--------------------------------------------------------------------*
- * The pitch lag search is divided in three sections. *
- * Each section cannot have a pitch multiple. *
- * We find a maximum for each section. *
- * We compare the maxima of each section by favoring small lag. *
- * *
- * First section: lag delay = PIT_MAX to 80 *
- * Second section: lag delay = 79 to 40 *
- * Third section: lag delay = 39 to 20 *
-
*--------------------------------------------------------------------*/
+ /*--------------------------------------------------------------------*
+ * The pitch lag search is divided in three sections. *
+ * Each section cannot have a pitch multiple. *
+ * We find a maximum for each section. *
+ * We compare the maxima of each section by favoring small lag. *
+ * *
+ * First section: lag delay = PIT_MAX to 80 *
+ * Second section: lag delay = 79 to 40 *
+ * Third section: lag delay = 39 to 20 *
+ *--------------------------------------------------------------------*/
- p_max1 = lag_max(signal, signals, l_frame, pit_max, 80 , max1);
- p_max2 = lag_max(signal, signals, l_frame, 79 , 40 , max2);
- p_max3 = lag_max(signal, signals, l_frame, 39 , pit_min , max3);
+ p_max1 = lag_max(signal, signals, l_frame, pit_max, 80, max1);
+ p_max2 = lag_max(signal, signals, l_frame, 79, 40, max2);
+ p_max3 = lag_max(signal, signals, l_frame, 39, pit_min, max3);
- /*--------------------------------------------------------------------*
- * Compare the 3 sections maxima, and favor small lag. *
-
*--------------------------------------------------------------------*/
+ /*--------------------------------------------------------------------*
+ * Compare the 3 sections maxima, and favor small lag. *
+ *--------------------------------------------------------------------*/
- if ( max1.value * LD8KConstants.THRESHPIT < max2.value ) {
- max1.value = max2.value;
- p_max1 = p_max2;
- }
+ if (max1.value * LD8KConstants.THRESHPIT < max2.value) {
+ max1.value = max2.value;
+ p_max1 = p_max2;
+ }
- if ( max1.value * LD8KConstants.THRESHPIT < max3.value ) p_max1 =
p_max3;
+ if (max1.value * LD8KConstants.THRESHPIT < max3.value)
+ p_max1 = p_max3;
- return (p_max1);
+ return (p_max1);
}
+
/*----------------------------------------------------------------------------
* lag_max - Find the lag that has maximum correlation
*----------------------------------------------------------------------------
*/
- public static int lag_max( /* output: lag found */
- float signal[], int signals, /* input : Signal to compute the
open loop pitch
- signal[-142:-1] should be known.
*/
- int l_frame, /* input : Length of frame to compute pitch
*/
- int lagmax, /* input : maximum lag
*/
- int lagmin, /* input : minimum lag
*/
- FloatPointer cor_max /* input : normalized correlation of
selected lag */
- )
- {
- int i, j;
- int p=0, p1;
- float max, t0;
- int p_max=0;
+ public static int lag_max( /* output: lag found */
+ float signal[], int signals, /*
+ * input : Signal to compute the open loop pitch signal[-142:-1]
should be known.
+ */
+ int l_frame, /* input : Length of frame to compute pitch */
+ int lagmax, /* input : maximum lag */
+ int lagmin, /* input : minimum lag */
+ FloatPointer cor_max /*
+ * input : normalized correlation of selected lag
+ */
+ ) {
+ int i, j;
+ int p = 0, p1;
+ float max, t0;
+ int p_max = 0;
- max = LD8KConstants.FLT_MIN_G729;
+ max = LD8KConstants.FLT_MIN_G729;
- for (i = lagmax; i >= lagmin; i--) {
- p = 0;//signal;
- p1 = -i;//&signal[-i];
- t0 = (float)0.0;
+ for (i = lagmax; i >= lagmin; i--) {
+ p = 0;// signal;
+ p1 = -i;// &signal[-i];
+ t0 = (float) 0.0;
- for (j=0; j<l_frame; j++) {
- t0 += signal[signals + p++] * signal[signals + p1++];
- }
+ for (j = 0; j < l_frame; j++) {
+ t0 += signal[signals + p++] * signal[signals + p1++];
+ }
- if (t0 >= max) {
- max = t0;
- p_max = i;
- }
- }
+ if (t0 >= max) {
+ max = t0;
+ p_max = i;
+ }
+ }
- /* compute energy */
+ /* compute energy */
- t0 = (float)0.01; /* to avoid division by zero */
- p = -p_max;
- for(i=0; i<l_frame; i++, p++) {
- t0 += signal[signals + p] * signal[signals + p];
- }
- t0 = inv_sqrt(t0); /* 1/sqrt(energy) */
+ t0 = (float) 0.01; /* to avoid division by zero */
+ p = -p_max;
+ for (i = 0; i < l_frame; i++, p++) {
+ t0 += signal[signals + p] * signal[signals + p];
+ }
+ t0 = inv_sqrt(t0); /* 1/sqrt(energy) */
- cor_max.value = max * t0; /* max/sqrt(energy) */
+ cor_max.value = max * t0; /* max/sqrt(energy) */
- return(p_max);
+ return (p_max);
}
-
/*----------------------------------------------------------------------------
* pitch_fr3 - find the pitch period with 1/3 subsample resolution
*----------------------------------------------------------------------------
*/
- public static int pitch_fr3( /* output: integer part of pitch
period */
- float exc[],int excs, /* input : excitation
buffer */
- float xn[],int xns, /* input : target
vector */
- float h[], int hs, /* input : impulse response of
filters. */
- int l_subfr, /* input : Length of frame to compute pitch */
- int t0_min, /* input : minimum value in the searched range */
- int t0_max, /* input : maximum value in the searched range */
- int i_subfr, /* input : indicator for first subframe */
- IntegerPointer pit_frac /* output: chosen
fraction */
- )
- {
- int i, frac;
- int lag, t_min, t_max;
- float max;
- float corr_int;
- float corr_v[] = new float[10+2*LD8KConstants.L_INTER4]; /* size:
2*L_INTER4+t0_max-t0_min+1 */
- int corr;
+ public static int pitch_fr3( /* output: integer part of pitch period */
+ float exc[], int excs, /* input : excitation buffer */
+ float xn[], int xns, /* input : target vector */
+ float h[], int hs, /* input : impulse response of filters. */
+ int l_subfr, /* input : Length of frame to compute pitch */
+ int t0_min, /* input : minimum value in the searched range */
+ int t0_max, /* input : maximum value in the searched range */
+ int i_subfr, /* input : indicator for first subframe */
+ IntegerPointer pit_frac /* output: chosen fraction */
+ ) {
+ int i, frac;
+ int lag, t_min, t_max;
+ float max;
+ float corr_int;
+ float corr_v[] = new float[10 + 2 * LD8KConstants.L_INTER4]; /*
+ * size: 2*L_INTER4 + t0_max-t0_min +1
+ */
+ int corr;
- /* Find interval to compute normalized correlation */
+ /* Find interval to compute normalized correlation */
- t_min = t0_min - LD8KConstants.L_INTER4;
- t_max = t0_max + LD8KConstants.L_INTER4;
+ t_min = t0_min - LD8KConstants.L_INTER4;
+ t_max = t0_max + LD8KConstants.L_INTER4;
- corr = -t_min; /* corr[t_min:t_max] */
+ corr = -t_min; /* corr[t_min:t_max] */
- /* Compute normalized correlation between target and filtered
excitation */
+ /* Compute normalized correlation between target and filtered excitation
*/
- norm_corr(exc, excs, xn, xns, h, hs, l_subfr, t_min, t_max, corr_v,
corr);
+ norm_corr(exc, excs, xn, xns, h, hs, l_subfr, t_min, t_max, corr_v,
corr);
- /* find integer pitch */
+ /* find integer pitch */
- max = corr_v[corr+t0_min];
- lag = t0_min;
+ max = corr_v[corr + t0_min];
+ lag = t0_min;
- for(i= t0_min+1; i<=t0_max; i++)
- {
- if( corr_v[corr+i] >= max)
- {
- max = corr_v[corr+i];
- lag = i;
- }
- }
+ for (i = t0_min + 1; i <= t0_max; i++) {
+ if (corr_v[corr + i] >= max) {
+ max = corr_v[corr + i];
+ lag = i;
+ }
+ }
- /* If first subframe and lag > 84 do not search fractionnal pitch */
+ /* If first subframe and lag > 84 do not search fractionnal pitch */
- if( (i_subfr == 0) && (lag > 84) )
- {
- pit_frac.value = 0;
- return(lag);
- }
+ if ((i_subfr == 0) && (lag > 84)) {
+ pit_frac.value = 0;
+ return (lag);
+ }
- /* test the fractions around lag and choose the one which maximizes
- the interpolated normalized correlation */
+ /*
+ * test the fractions around lag and choose the one which maximizes the
interpolated normalized correlation
+ */
- max = interpol_3(corr_v, corr+lag, -2);
- frac = -2;
+ max = interpol_3(corr_v, corr + lag, -2);
+ frac = -2;
- for (i = -1; i <= 2; i++)
- {
- corr_int = interpol_3(corr_v, corr+lag, i);
- if(corr_int > max)
- {
- max = corr_int;
- frac = i;
- }
- }
+ for (i = -1; i <= 2; i++) {
+ corr_int = interpol_3(corr_v, corr + lag, i);
+ if (corr_int > max) {
+ max = corr_int;
+ frac = i;
+ }
+ }
- /* limit the fraction value in the interval [-1,0,1] */
+ /* limit the fraction value in the interval [-1,0,1] */
- if (frac == -2)
- {
- frac = 1;
- lag -= 1;
- }
- if (frac == 2)
- {
- frac = -1;
- lag += 1;
- }
+ if (frac == -2) {
+ frac = 1;
+ lag -= 1;
+ }
+ if (frac == 2) {
+ frac = -1;
+ lag += 1;
+ }
- pit_frac.value = frac;
+ pit_frac.value = frac;
- return lag;
+ return lag;
}
/*----------------------------------------------------------------------------
@@ -190,100 +188,103 @@
* the filtered past excitation.
*----------------------------------------------------------------------------
*/
- public static void norm_corr(
- float exc[],int excs, /* input : excitation buffer */
- float xn[],int xns, /* input : target vector */
- float h[],int hs, /* input : imp response of synth and
weighting flt */
- int l_subfr, /* input : Length of frame to compute pitch */
- int t_min, /* input : minimum value of searched range */
- int t_max, /* input : maximum value of search range */
- float corr_norm[], int cs /* output: normalized correlation
(correlation between
- target and filtered excitation divided
by
- the square root of energy of filtered
- excitation) */
- )
- {
- int i, j, k;
- float excf[] = new float[LD8KConstants.L_SUBFR]; /* filtered past
excitation */
- float alp, s, norm;
-
- k = -t_min;
-
- /* compute the filtered excitation for the first delay t_min */
+ public static void norm_corr(float exc[], int excs, /*
+ * input : excitation buffer
+ */
+ float xn[], int xns, /* input : target vector */
+ float h[], int hs, /*
+ * input : imp response of synth and weighting flt
+ */
+ int l_subfr, /* input : Length of frame to compute pitch */
+ int t_min, /* input : minimum value of searched range */
+ int t_max, /* input : maximum value of search range */
+ float corr_norm[], int cs /*
+ * output: normalized correlation (correlation between target and
filtered
+ * excitation divided by the square root of energy of filtered
excitation)
+ */
+ ) {
+ int i, j, k;
+ float excf[] = new float[LD8KConstants.L_SUBFR]; /*
+ * filtered past excitation
+ */
+ float alp, s, norm;
- Filter.convolve(exc,excs+k, h, 0, excf, 0, l_subfr);
+ k = -t_min;
- /* loop for every possible period */
+ /* compute the filtered excitation for the first delay t_min */
- for (i = t_min; i <= t_max; i++)
- {
- /* Compute 1/sqrt(energie of excf[]) */
+ Filter.convolve(exc, excs + k, h, 0, excf, 0, l_subfr);
- alp = (float)0.01;
- for (j = 0; j < l_subfr; j++)
- alp += excf[j]*excf[j];
+ /* loop for every possible period */
- norm = inv_sqrt(alp);
+ for (i = t_min; i <= t_max; i++) {
+ /* Compute 1/sqrt(energie of excf[]) */
+ alp = (float) 0.01;
+ for (j = 0; j < l_subfr; j++)
+ alp += excf[j] * excf[j];
- /* Compute correlation between xn[] and excf[] */
+ norm = inv_sqrt(alp);
- s = (float)0.0;
- for (j = 0; j < l_subfr; j++) s += xn[xns+j]*excf[j];
+ /* Compute correlation between xn[] and excf[] */
+ s = (float) 0.0;
+ for (j = 0; j < l_subfr; j++)
+ s += xn[xns + j] * excf[j];
- /* Normalize correlation = correlation * (1/sqrt(energie)) */
+ /* Normalize correlation = correlation * (1/sqrt(energie)) */
- corr_norm[cs+i] = s*norm;
+ corr_norm[cs + i] = s * norm;
- /* modify the filtered excitation excf[] for the next iteration */
+ /* modify the filtered excitation excf[] for the next iteration */
- if (i != t_max)
- {
- k--;
- for (j = l_subfr-1; j > 0; j--)
- excf[j] = excf[j-1] + exc[excs+k]*h[j];
- excf[0] = exc[excs+k];
- }
- }
+ if (i != t_max) {
+ k--;
+ for (j = l_subfr - 1; j > 0; j--)
+ excf[j] = excf[j - 1] + exc[excs + k] * h[j];
+ excf[0] = exc[excs + k];
+ }
+ }
- return;
+ return;
}
+
/*----------------------------------------------------------------------------
* g_pitch - compute adaptive codebook gain and compute <y1,y1> ,
-2<xn,y1>
*----------------------------------------------------------------------------
*/
- public static float g_pitch( /* output: pitch gain */
- float xn[],int xns, /* input : target vector */
- float y1[],int y1s, /* input : filtered adaptive codebook
vector */
- float g_coeff[],int gs, /* output: <y1,y1> and -2<xn,y1> */
- int l_subfr /* input : vector dimension */
- )
- {
- float xy, yy, gain;
- int i;
+ public static float g_pitch( /* output: pitch gain */
+ float xn[], int xns, /* input : target vector */
+ float y1[], int y1s, /* input : filtered adaptive codebook vector */
+ float g_coeff[], int gs, /* output: <y1,y1> and -2<xn,y1> */
+ int l_subfr /* input : vector dimension */
+ ) {
+ float xy, yy, gain;
+ int i;
- xy = (float)0.0;
- for (i = 0; i < l_subfr; i++) {
- xy += xn[xns+i] * y1[y1s+i];
- }
- yy = (float)0.01;
- for (i = 0; i < l_subfr; i++) {
- yy += y1[y1s+i] * y1[y1s+i]; /* energy of filtered
excitation */
- }
- g_coeff[gs+0] = yy;
- g_coeff[gs+1] = (float)-2.0*xy +(float)0.01;
+ xy = (float) 0.0;
+ for (i = 0; i < l_subfr; i++) {
+ xy += xn[xns + i] * y1[y1s + i];
+ }
+ yy = (float) 0.01;
+ for (i = 0; i < l_subfr; i++) {
+ yy += y1[y1s + i] * y1[y1s + i]; /* energy of filtered excitation */
+ }
+ g_coeff[gs + 0] = yy;
+ g_coeff[gs + 1] = (float) -2.0 * xy + (float) 0.01;
- /* find pitch gain and bound it by [0,1.2] */
+ /* find pitch gain and bound it by [0,1.2] */
- gain = xy/yy;
+ gain = xy / yy;
- if (gain<(float)0.0) gain = (float)0.0;
- if (gain>LD8KConstants.GAIN_PIT_MAX) gain =
LD8KConstants.GAIN_PIT_MAX;
+ if (gain < (float) 0.0)
+ gain = (float) 0.0;
+ if (gain > LD8KConstants.GAIN_PIT_MAX)
+ gain = LD8KConstants.GAIN_PIT_MAX;
- return gain;
+ return gain;
}
/*----------------------------------------------------------------------*
@@ -310,86 +311,82 @@
* The period in the 2nd subframe is encoded with 5 bits: *
* index = (T-(t_min-1))*3 + frac - 1; where T[t_min-1 .. t_max+1] *
*----------------------------------------------------------------------*/
- public static int enc_lag3( /* output: Return index of encoding */
- int T0, /* input : Pitch delay */
- int T0_frac, /* input : Fractional pitch delay */
- IntegerPointer T0_min, /* in/out: Minimum search delay */
- IntegerPointer T0_max, /* in/out: Maximum search delay */
- int pit_min, /* input : Minimum pitch delay */
- int pit_max, /* input : Maximum pitch delay */
- int pit_flag /* input : Flag for 1st subframe */
- )
- {
- int index;
+ public static int enc_lag3( /* output: Return index of encoding */
+ int T0, /* input : Pitch delay */
+ int T0_frac, /* input : Fractional pitch delay */
+ IntegerPointer T0_min, /* in/out: Minimum search delay */
+ IntegerPointer T0_max, /* in/out: Maximum search delay */
+ int pit_min, /* input : Minimum pitch delay */
+ int pit_max, /* input : Maximum pitch delay */
+ int pit_flag /* input : Flag for 1st subframe */
+ ) {
+ int index;
- if (pit_flag == 0) /* if 1st subframe */
- {
- /* encode pitch delay (with fraction) */
+ if (pit_flag == 0) /* if 1st subframe */
+ {
+ /* encode pitch delay (with fraction) */
- if (T0 <= 85)
- index = T0*3 - 58 + T0_frac;
- else
- index = T0 + 112;
+ if (T0 <= 85)
+ index = T0 * 3 - 58 + T0_frac;
+ else
+ index = T0 + 112;
- /* find T0_min and T0_max for second subframe */
+ /* find T0_min and T0_max for second subframe */
- T0_min.value = T0 - 5;
- if (T0_min.value < pit_min) T0_min.value = pit_min;
- T0_max.value = T0_min.value + 9;
- if (T0_max.value > pit_max)
- {
- T0_max.value = pit_max;
- T0_min.value = T0_max.value - 9;
- }
- }
+ T0_min.value = T0 - 5;
+ if (T0_min.value < pit_min)
+ T0_min.value = pit_min;
+ T0_max.value = T0_min.value + 9;
+ if (T0_max.value > pit_max) {
+ T0_max.value = pit_max;
+ T0_min.value = T0_max.value - 9;
+ }
+ }
- else /* second subframe */
- {
- index = T0 - T0_min.value;
- index = index*3 + 2 + T0_frac;
- }
- return index;
+ else /* second subframe */
+ {
+ index = T0 - T0_min.value;
+ index = index * 3 + 2 + T0_frac;
+ }
+ return index;
}
/*----------------------------------------------------------------------------
* interpol_3 - For interpolating the normalized correlation
*----------------------------------------------------------------------------
*/
- public static float interpol_3( /* output: interpolated value */
- float []x,int xs, /* input : function to be interpolated */
- int frac /* input : fraction value to evaluate */
- )
- {
- int i;
- float s;
- int x1, x2, c1, c2;
-
+ public static float interpol_3( /* output: interpolated value */
+ float[] x, int xs, /* input : function to be interpolated */
+ int frac /* input : fraction value to evaluate */
+ ) {
+ int i;
+ float s;
+ int x1, x2, c1, c2;
- if (frac < 0) {
- frac += LD8KConstants.UP_SAMP;
- xs--;
- }
- x1 = 0;
- x2 = 1;
- c1 = frac;//&inter_3[frac];
- c2 = LD8KConstants.UP_SAMP-frac;//&inter_3[LD8KConstants.UP_SAMP-frac];
+ if (frac < 0) {
+ frac += LD8KConstants.UP_SAMP;
+ xs--;
+ }
+ x1 = 0;
+ x2 = 1;
+ c1 = frac;// &inter_3[frac];
+ c2 = LD8KConstants.UP_SAMP - frac;//
&inter_3[LD8KConstants.UP_SAMP-frac];
- s = (float)0.0;
- for(i=0; i< LD8KConstants.L_INTER4; i++, c1+=LD8KConstants.UP_SAMP,
c2+=LD8KConstants.UP_SAMP)
- s+= (x[xs+x1--]) * (TabLD8k.inter_3[c1]) + (x[xs+x2++]) *
(TabLD8k.inter_3[c2]);
+ s = (float) 0.0;
+ for (i = 0; i < LD8KConstants.L_INTER4; i++, c1 +=
LD8KConstants.UP_SAMP, c2 += LD8KConstants.UP_SAMP)
+ s += (x[xs + x1--]) * (TabLD8k.inter_3[c1]) + (x[xs + x2++]) *
(TabLD8k.inter_3[c2]);
- return s;
+ return s;
}
/*----------------------------------------------------------------------------
* inv_sqrt - compute y = 1 / sqrt(x)
*----------------------------------------------------------------------------
*/
- static float inv_sqrt( /* output: 1/sqrt(x) */
- float x /* input : value of x */
- )
- {
- return ((float)1.0 / (float)Math.sqrt((double)x) );
+ static float inv_sqrt( /* output: 1/sqrt(x) */
+ float x /* input : value of x */
+ ) {
+ return ((float) 1.0 / (float) Math.sqrt((double) x));
}
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/PostFil.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/PostFil.java Thu Feb 21
09:21:48 2013
@@ -1,38 +1,41 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class PostFil {
/* Static arrays and variables */
- float apond2[] = new float[LD8KConstants.LONG_H_ST]; /* s.t.
numerator coeff. */
- float mem_stp[] = new float[LD8KConstants.M]; /* s.t.
postfilter memory */
- float mem_zero[] = new float[LD8KConstants.M]; /* null memory to
compute h_st */
- float res2[] = new float[LD8KConstants.SIZ_RES2]; /* A(gamma2)
residual */
+ float apond2[] = new float[LD8KConstants.LONG_H_ST]; /* s.t. numerator
coeff. */
+ float mem_stp[] = new float[LD8KConstants.M]; /* s.t. postfilter memory */
+ float mem_zero[] = new float[LD8KConstants.M]; /*
+ * null memory to compute h_st
+ */
+ float res2[] = new float[LD8KConstants.SIZ_RES2]; /* A(gamma2) residual */
/* Static pointers */
int res2_ptr;
int ptr_mem_stp;
/* Variables */
- FloatPointer gain_prec = new FloatPointer((float)0); /* for
gain adjustment */
+ FloatPointer gain_prec = new FloatPointer((float) 0); /* for gain
adjustment */
- /**** Short term postfilter : *****/
- /* Hst(z) = Hst0(z) Hst1(z) */
- /* Hst0(z) = 1/g0 A(gamma2)(z) / A(gamma1)(z) */
- /* if {hi} = i.r. filter A(gamma2)/A(gamma1) (truncated) */
- /* g0 = SUM(|hi|) if > 1 */
- /* g0 = 1. else */
- /* Hst1(z) = 1/(1+ |mu|) (1 + mu z-1) */
- /* with mu = 1st parcor calculated on {hi} */
- /**** Long term postfilter : *****/
- /* harmonic postfilter : H0(z) = gl * (1 + b * z-p) */
- /* b = gamma_g * gain_ltp */
- /* gl = 1 / 1 + b */
- /* copmuation of delay on A(gamma2)(z) s(z) */
- /* sub optimal research */
- /* 1. search best integer delay */
- /* 2. search around integer sub multiples (3 val. / sub mult) */
- /* 3. search around integer with fractionnal delays (1/8) */
+ /**** Short term postfilter : *****/
+ /* Hst(z) = Hst0(z) Hst1(z) */
+ /* Hst0(z) = 1/g0 A(gamma2)(z) / A(gamma1)(z) */
+ /* if {hi} = i.r. filter A(gamma2)/A(gamma1) (truncated) */
+ /* g0 = SUM(|hi|) if > 1 */
+ /* g0 = 1. else */
+ /* Hst1(z) = 1/(1+ |mu|) (1 + mu z-1) */
+ /* with mu = 1st parcor calculated on {hi} */
+ /**** Long term postfilter : *****/
+ /* harmonic postfilter : H0(z) = gl * (1 + b * z-p) */
+ /* b = gamma_g * gain_ltp */
+ /* gl = 1 / 1 + b */
+ /* copmuation of delay on A(gamma2)(z) s(z) */
+ /* sub optimal research */
+ /* 1. search best integer delay */
+ /* 2. search around integer sub multiples (3 val. / sub mult) */
+ /* 3. search around integer with fractionnal delays (1/8) */
/************************************************************************/
/*----------------------------------------------------------------------------
@@ -40,442 +43,450 @@
*----------------------------------------------------------------------------
*/
public void init_post_filter(
-
- )
- {
- int i;
- /* Initialize arrays and pointers */
+ ) {
+ int i;
- /* A(gamma2) residual */
- for(i=0; i<LD8KConstants.MEM_RES2; i++) res2[i] = (float)0.0;
- res2_ptr = 0 + LD8KConstants.MEM_RES2;
+ /* Initialize arrays and pointers */
- /* 1/A(gamma1) memory */
- for(i=0; i<LD8KConstants.M; i++) mem_stp[i] = (float)0.0;
- ptr_mem_stp = 0 + LD8KConstants.M - 1;
+ /* A(gamma2) residual */
+ for (i = 0; i < LD8KConstants.MEM_RES2; i++)
+ res2[i] = (float) 0.0;
+ res2_ptr = 0 + LD8KConstants.MEM_RES2;
- /* fill apond2[M+1->LONG_H_ST-1] with zeroes */
- for(i=LD8KConstants.MP1; i<LD8KConstants.LONG_H_ST; i++) apond2[i] =
(float)0.0;
+ /* 1/A(gamma1) memory */
+ for (i = 0; i < LD8KConstants.M; i++)
+ mem_stp[i] = (float) 0.0;
+ ptr_mem_stp = 0 + LD8KConstants.M - 1;
- /* null memory to compute i.r. of A(gamma2)/A(gamma1) */
- for(i=0; i<LD8KConstants.M; i++) mem_zero[i] = (float)0.0;
+ /* fill apond2[M+1->LONG_H_ST-1] with zeroes */
+ for (i = LD8KConstants.MP1; i < LD8KConstants.LONG_H_ST; i++)
+ apond2[i] = (float) 0.0;
- /* for gain adjustment */
- gain_prec.value =(float)1.;
+ /* null memory to compute i.r. of A(gamma2)/A(gamma1) */
+ for (i = 0; i < LD8KConstants.M; i++)
+ mem_zero[i] = (float) 0.0;
- return;
+ /* for gain adjustment */
+ gain_prec.value = (float) 1.;
+
+ return;
}
/*----------------------------------------------------------------------------
* post - adaptive postfilter main function
*----------------------------------------------------------------------------
*/
- public void post(
- int t0, /* input : pitch delay given by coder */
- float[] signal_ptr, int signals, /* input : input signal (pointer to
current subframe */
- float []coeff, int coeffs, /* input : LPC coefficients for
current subframe */
- float []sig_out, int outs, /* output: postfiltered output */
- IntegerPointer vo /* output: voicing decision 0 = uv, >
0 delay */
- )
- {
- float apond1[] = new float[LD8KConstants.MP1]; /* s.t.
denominator coeff. */
- float sig_ltp[] = new float[LD8KConstants.L_SUBFRP1]; /* H0 output
signal */
- int sig_ltp_ptr;
- FloatPointer parcor0 = new FloatPointer();
+ public void post(int t0, /* input : pitch delay given by coder */
+ float[] signal_ptr, int signals, /*
+ * input : input signal (pointer to current subframe
+ */
+ float[] coeff, int coeffs, /*
+ * input : LPC coefficients for current subframe
+ */
+ float[] sig_out, int outs, /* output: postfiltered output */
+ IntegerPointer vo /* output: voicing decision 0 = uv, > 0 delay */
+ ) {
+ float apond1[] = new float[LD8KConstants.MP1]; /*
+ * s.t. denominator coeff.
+ */
+ float sig_ltp[] = new float[LD8KConstants.L_SUBFRP1]; /* H0 output
signal */
+ int sig_ltp_ptr;
+ FloatPointer parcor0 = new FloatPointer();
- /* Compute weighted LPC coefficients */
- LpcFunc.weight_az(coeff, coeffs, LD8KConstants.GAMMA1_PST,
LD8KConstants.M, apond1, 0);
- LpcFunc.weight_az(coeff, coeffs, LD8KConstants.GAMMA2_PST,
LD8KConstants.M, apond2, 0);
+ /* Compute weighted LPC coefficients */
+ LpcFunc.weight_az(coeff, coeffs, LD8KConstants.GAMMA1_PST,
LD8KConstants.M, apond1, 0);
+ LpcFunc.weight_az(coeff, coeffs, LD8KConstants.GAMMA2_PST,
LD8KConstants.M, apond2, 0);
- /* Compute A(gamma2) residual */
- Filter.residu(apond2, 0, signal_ptr, signals, res2, res2_ptr,
LD8KConstants.L_SUBFR);
+ /* Compute A(gamma2) residual */
+ Filter.residu(apond2, 0, signal_ptr, signals, res2, res2_ptr,
LD8KConstants.L_SUBFR);
- /* Harmonic filtering */
- sig_ltp_ptr = 1;//sig_ltp + 1;
- pst_ltp(t0, res2, res2_ptr, sig_ltp, sig_ltp_ptr, vo);
+ /* Harmonic filtering */
+ sig_ltp_ptr = 1;// sig_ltp + 1;
+ pst_ltp(t0, res2, res2_ptr, sig_ltp, sig_ltp_ptr, vo);
- /* Save last output of 1/A(gamma1) */
- /* (from preceding subframe) */
- sig_ltp[0] = mem_stp[ptr_mem_stp];
+ /* Save last output of 1/A(gamma1) */
+ /* (from preceding subframe) */
+ sig_ltp[0] = mem_stp[ptr_mem_stp];
- /* Control short term pst filter gain and compute parcor0 */
- calc_st_filt(apond2, 0, apond1, 0, parcor0, sig_ltp, sig_ltp_ptr);
+ /* Control short term pst filter gain and compute parcor0 */
+ calc_st_filt(apond2, 0, apond1, 0, parcor0, sig_ltp, sig_ltp_ptr);
- /* 1/A(gamma1) filtering, mem_stp is updated */
- Filter.syn_filt(apond1, 0, sig_ltp, sig_ltp_ptr, sig_ltp,
sig_ltp_ptr, LD8KConstants.L_SUBFR, mem_stp, 0, 1);
+ /* 1/A(gamma1) filtering, mem_stp is updated */
+ Filter.syn_filt(apond1, 0, sig_ltp, sig_ltp_ptr, sig_ltp, sig_ltp_ptr,
LD8KConstants.L_SUBFR, mem_stp, 0, 1);
- /* (1 + mu z-1) tilt filtering */
- filt_mu(sig_ltp, 0, sig_out, outs, parcor0.value);
+ /* (1 + mu z-1) tilt filtering */
+ filt_mu(sig_ltp, 0, sig_out, outs, parcor0.value);
- /* gain control */
- scale_st(signal_ptr, signals, sig_out, outs, gain_prec);
+ /* gain control */
+ scale_st(signal_ptr, signals, sig_out, outs, gain_prec);
- /**** Update for next frame */
- Util.copy(res2,LD8KConstants.L_SUBFR, res2, 0,
LD8KConstants.MEM_RES2);
+ /**** Update for next frame */
+ Util.copy(res2, LD8KConstants.L_SUBFR, res2, 0, LD8KConstants.MEM_RES2);
- return;
+ return;
}
/*----------------------------------------------------------------------------
* pst_ltp - harmonic postfilter
*----------------------------------------------------------------------------
*/
- public void pst_ltp(
- int t0, /* input : pitch delay given by coder */
- float []ptr_sig_in, int ins, /* input : postfilter input filter
(residu2) */
- float []ptr_sig_pst0, int psts, /* output: harmonic postfilter output
*/
- IntegerPointer vo /* output: voicing decision 0 = uv, >
0 delay */
- )
- {
+ public void pst_ltp(int t0, /* input : pitch delay given by coder */
+ float[] ptr_sig_in, int ins, /*
+ * input : postfilter input filter (residu2)
+ */
+ float[] ptr_sig_pst0, int psts, /*
+ * output: harmonic postfilter output
+ */
+ IntegerPointer vo /* output: voicing decision 0 = uv, > 0 delay */
+ ) {
- /**** Declare variables */
- IntegerPointer ltpdel = new IntegerPointer(0), phase = new
IntegerPointer(0);
- FloatPointer num_gltp = new FloatPointer((float)0), den_gltp = new
FloatPointer((float)0);
- FloatPointer num2_gltp = new FloatPointer((float)0), den2_gltp = new
FloatPointer((float)0);
- float gain_plt;
- float y_up[] = new float[LD8KConstants.SIZ_Y_UP];
- int ptr_y_up;
- float[] ptr_y_up_array;
- IntegerPointer off_yup = new IntegerPointer();
+ /**** Declare variables */
+ IntegerPointer ltpdel = new IntegerPointer(0), phase = new
IntegerPointer(0);
+ FloatPointer num_gltp = new FloatPointer((float) 0), den_gltp = new
FloatPointer((float) 0);
+ FloatPointer num2_gltp = new FloatPointer((float) 0), den2_gltp = new
FloatPointer((float) 0);
+ float gain_plt;
+ float y_up[] = new float[LD8KConstants.SIZ_Y_UP];
+ int ptr_y_up;
+ float[] ptr_y_up_array;
+ IntegerPointer off_yup = new IntegerPointer();
- /* Sub optimal delay search */
- search_del(t0, ptr_sig_in, ins, ltpdel, phase, num_gltp, den_gltp,
- y_up, off_yup);
- vo.value = ltpdel.value;
+ /* Sub optimal delay search */
+ search_del(t0, ptr_sig_in, ins, ltpdel, phase, num_gltp, den_gltp, y_up,
off_yup);
+ vo.value = ltpdel.value;
- //HACK:FIXME
- if(num_gltp.value == (float)0.) {
- Util.copy(ptr_sig_in, ins, ptr_sig_pst0, psts,
LD8KConstants.L_SUBFR);
- }
- else {
+ // HACK:FIXME
+ if (num_gltp.value == (float) 0.) {
+ Util.copy(ptr_sig_in, ins, ptr_sig_pst0, psts, LD8KConstants.L_SUBFR);
+ } else {
- if(phase.value == 0) {
- ptr_y_up = ins - ltpdel.value;//ptr_sig_in
- ptr_y_up_array = ptr_sig_in;
- }
+ if (phase.value == 0) {
+ ptr_y_up = ins - ltpdel.value;// ptr_sig_in
+ ptr_y_up_array = ptr_sig_in;
+ }
- else {
- /* Filtering with long filter */
- compute_ltp_l(ptr_sig_in, ins, ltpdel.value, phase.value,
ptr_sig_pst0, psts,
- num2_gltp, den2_gltp);
+ else {
+ /* Filtering with long filter */
+ compute_ltp_l(ptr_sig_in, ins, ltpdel.value, phase.value,
ptr_sig_pst0, psts, num2_gltp, den2_gltp);
- if(select_ltp(num_gltp.value, den_gltp.value,
num2_gltp.value, den2_gltp.value) == 1) {
+ if (select_ltp(num_gltp.value, den_gltp.value, num2_gltp.value,
den2_gltp.value) == 1) {
- /* select short filter */
- ptr_y_up = 0 + ((phase.value-1) * LD8KConstants.L_SUBFRP1
+ off_yup.value);
- ptr_y_up_array = y_up;
- }
- else {
- /* select long filter */
- num_gltp = num2_gltp;
- den_gltp = den2_gltp;
- ptr_y_up = psts;
- ptr_y_up_array = ptr_sig_pst0;
- }
- }
+ /* select short filter */
+ ptr_y_up = 0 + ((phase.value - 1) * LD8KConstants.L_SUBFRP1 +
off_yup.value);
+ ptr_y_up_array = y_up;
+ } else {
+ /* select long filter */
+ num_gltp = num2_gltp;
+ den_gltp = den2_gltp;
+ ptr_y_up = psts;
+ ptr_y_up_array = ptr_sig_pst0;
+ }
+ }
- if(num_gltp.value > den_gltp.value) {
- /* beta bounded to 1 */
- gain_plt = LD8KConstants.MIN_GPLT;
- }
- else {
- gain_plt = den_gltp.value / (den_gltp.value +
LD8KConstants.GAMMA_G * num_gltp.value);
- }
+ if (num_gltp.value > den_gltp.value) {
+ /* beta bounded to 1 */
+ gain_plt = LD8KConstants.MIN_GPLT;
+ } else {
+ gain_plt = den_gltp.value / (den_gltp.value + LD8KConstants.GAMMA_G *
num_gltp.value);
+ }
- /** filtering by H0(z) (harmonic filter) **/
- filt_plt(ptr_sig_in, ins, ptr_y_up_array, ptr_y_up, ptr_sig_pst0,
psts, gain_plt);
+ /** filtering by H0(z) (harmonic filter) **/
+ filt_plt(ptr_sig_in, ins, ptr_y_up_array, ptr_y_up, ptr_sig_pst0, psts,
gain_plt);
- }
+ }
- return;
+ return;
}
/*----------------------------------------------------------------------------
* search_del: computes best (shortest) integer LTP delay + fine search
*----------------------------------------------------------------------------
*/
- static void search_del(
- int t0, /* input : pitch delay given by coder */
- float []ptr_sig_in, int ins, /* input : input signal (with delay
line) */
- IntegerPointer ltpdel, /* output: delay = *ltpdel - *phase /
f_up */
- IntegerPointer phase, /* output: phase */
- FloatPointer num_gltp, /* output: numerator of LTP gain */
- FloatPointer den_gltp, /* output: denominator of LTP gain */
- float []y_up, /* : */
- IntegerPointer off_yup /* : */
- )
- {
+ static void search_del(int t0, /* input : pitch delay given by coder */
+ float[] ptr_sig_in, int ins, /*
+ * input : input signal (with delay line)
+ */
+ IntegerPointer ltpdel, /* output: delay = *ltpdel - *phase / f_up */
+ IntegerPointer phase, /* output: phase */
+ FloatPointer num_gltp, /* output: numerator of LTP gain */
+ FloatPointer den_gltp, /* output: denominator of LTP gain */
+ float[] y_up, /* : */
+ IntegerPointer off_yup /* : */
+ ) {
- /* pointers on tables of constants */
- int ptr_h;
+ /* pointers on tables of constants */
+ int ptr_h;
- /* Variables and local arrays */
- float tab_den0[] = new float[LD8KConstants.F_UP_PST-1], tab_den1[] =
new float[LD8KConstants.F_UP_PST-1];
- int ptr_den0, ptr_den1;
- int ptr_sig_past, ptr_sig_past0;
- int ptr1;
+ /* Variables and local arrays */
+ float tab_den0[] = new float[LD8KConstants.F_UP_PST - 1], tab_den1[] =
new float[LD8KConstants.F_UP_PST - 1];
+ int ptr_den0, ptr_den1;
+ int ptr_sig_past, ptr_sig_past0;
+ int ptr1;
- int i, n, ioff, i_max;
- float ener, num, numsq, den0, den1;
- float den_int, num_int;
- float den_max, num_max, numsq_max;
- int phi_max;
- int lambda, phi;
- float temp0, temp1;
- int ptr_y_up;
+ int i, n, ioff, i_max;
+ float ener, num, numsq, den0, den1;
+ float den_int, num_int;
+ float den_max, num_max, numsq_max;
+ int phi_max;
+ int lambda, phi;
+ float temp0, temp1;
+ int ptr_y_up;
- /*****************************************/
- /* Compute current signal energy */
- /*****************************************/
+ /*****************************************/
+ /* Compute current signal energy */
+ /*****************************************/
- ener = (float)0.;
- for(i=0; i<LD8KConstants.L_SUBFR; i++) {
- ener += ptr_sig_in[i+ins] * ptr_sig_in[i+ins];
- }
- if(ener < (float)0.1) {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- return;
- }
+ ener = (float) 0.;
+ for (i = 0; i < LD8KConstants.L_SUBFR; i++) {
+ ener += ptr_sig_in[i + ins] * ptr_sig_in[i + ins];
+ }
+ if (ener < (float) 0.1) {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ return;
+ }
- /*************************************/
- /* Selects best of 3 integer delays */
- /* Maximum of 3 numerators around t0 */
- /* coder LTP delay */
- /*************************************/
+ /*************************************/
+ /* Selects best of 3 integer delays */
+ /* Maximum of 3 numerators around t0 */
+ /* coder LTP delay */
+ /*************************************/
- lambda = t0-1;
+ lambda = t0 - 1;
- ptr_sig_past = 0 - lambda; // ptr_sig_in
+ ptr_sig_past = 0 - lambda; // ptr_sig_in
- num_int = (float)-1.0e30;
+ num_int = (float) -1.0e30;
- /* initialization used only to suppress Microsoft Visual C++ warnings
*/
- i_max = 0;
- for(i=0; i<3; i++) {
- num=(float)0.;
- for(n=0; n<LD8KConstants.L_SUBFR; n++) {
- num += ptr_sig_in[ins+n]* ptr_sig_in[ins+ptr_sig_past+n];
- }
- if(num > num_int) {
- i_max = i;
- num_int = num;
- }
- ptr_sig_past--;
- }
- if(num_int <= (float)0.) {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- return;
- }
+ /* initialization used only to suppress Microsoft Visual C++ warnings */
+ i_max = 0;
+ for (i = 0; i < 3; i++) {
+ num = (float) 0.;
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ num += ptr_sig_in[ins + n] * ptr_sig_in[ins + ptr_sig_past + n];
+ }
+ if (num > num_int) {
+ i_max = i;
+ num_int = num;
+ }
+ ptr_sig_past--;
+ }
+ if (num_int <= (float) 0.) {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ return;
+ }
- /* Calculates denominator for lambda_max */
- lambda += i_max;
- ptr_sig_past = 0 - lambda;
- den_int=(float)0.;
- for(n=0; n<LD8KConstants.L_SUBFR; n++) {
- den_int += ptr_sig_in[ins+ptr_sig_past+n]*
ptr_sig_in[ins+ptr_sig_past+n];
- }
- if(den_int < (float)0.1) {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- return;
- }
- /***********************************/
- /* Select best phase around lambda */
- /***********************************/
+ /* Calculates denominator for lambda_max */
+ lambda += i_max;
+ ptr_sig_past = 0 - lambda;
+ den_int = (float) 0.;
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ den_int += ptr_sig_in[ins + ptr_sig_past + n] * ptr_sig_in[ins +
ptr_sig_past + n];
+ }
+ if (den_int < (float) 0.1) {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ return;
+ }
+ /***********************************/
+ /* Select best phase around lambda */
+ /***********************************/
- /* Compute y_up & denominators */
- /*******************************/
- ptr_y_up = 0;//y_up;
- den_max = 0;//den_int;
- ptr_den0 = 0;//tab_den0;
- ptr_den1 = 0;//tab_den1;
- ptr_h = 0;//tab_hup_s;
- ptr_sig_past0 = 0 + LD8KConstants.LH_UP_S - 1 - lambda;//ptr_sig_in +
LD8KConstants.LH_UP_S - 1 - lambda; /* points on lambda_max+1 */
+ /* Compute y_up & denominators */
+ /*******************************/
+ ptr_y_up = 0;// y_up;
+ den_max = 0;// den_int;
+ ptr_den0 = 0;// tab_den0;
+ ptr_den1 = 0;// tab_den1;
+ ptr_h = 0;// tab_hup_s;
+ ptr_sig_past0 = 0 + LD8KConstants.LH_UP_S - 1 - lambda;// ptr_sig_in +
+ // LD8KConstants.LH_UP_S
+ // - 1 - lambda;
+ // /* points on
+ // lambda_max+1
+ // */
- /* loop on phase */
- for(phi=1; phi<LD8KConstants.F_UP_PST; phi++) {
+ /* loop on phase */
+ for (phi = 1; phi < LD8KConstants.F_UP_PST; phi++) {
- /* Computes criterion for (lambda_max+1) - phi/F_UP_PST */
- /* and lambda_max - phi/F_UP_PST */
- ptr_sig_past = ptr_sig_past0;
- /* computes y_up[n] */
- for(n = 0; n<=LD8KConstants.L_SUBFR; n++) {
- ptr1 = ptr_sig_past++;
- temp0 = (float)0.;
- for(i=0; i<LD8KConstants.LH2_S; i++) {
- temp0 += TabLD8k.tab_hup_s[ptr_h+i] *
ptr_sig_in[ins+ptr1-i];
- }
- y_up[ptr_y_up+n] = temp0;
- }
+ /* Computes criterion for (lambda_max+1) - phi/F_UP_PST */
+ /* and lambda_max - phi/F_UP_PST */
+ ptr_sig_past = ptr_sig_past0;
+ /* computes y_up[n] */
+ for (n = 0; n <= LD8KConstants.L_SUBFR; n++) {
+ ptr1 = ptr_sig_past++;
+ temp0 = (float) 0.;
+ for (i = 0; i < LD8KConstants.LH2_S; i++) {
+ temp0 += TabLD8k.tab_hup_s[ptr_h + i] * ptr_sig_in[ins + ptr1 - i];
+ }
+ y_up[ptr_y_up + n] = temp0;
+ }
- /* recursive computation of den0 (lambda_max+1) and den1
(lambda_max) */
+ /*
+ * recursive computation of den0 (lambda_max+1) and den1 (lambda_max)
+ */
- /* common part to den0 and den1 */
- temp0 = (float)0.;
- for(n=1; n<LD8KConstants.L_SUBFR; n++) {
- temp0 += y_up[ptr_y_up+n] * y_up[ptr_y_up+n];
- }
+ /* common part to den0 and den1 */
+ temp0 = (float) 0.;
+ for (n = 1; n < LD8KConstants.L_SUBFR; n++) {
+ temp0 += y_up[ptr_y_up + n] * y_up[ptr_y_up + n];
+ }
- /* den0 */
- den0 = temp0 + y_up[ptr_y_up+0] * y_up[ptr_y_up+0];
- tab_den0[ptr_den0++] = den0;
+ /* den0 */
+ den0 = temp0 + y_up[ptr_y_up + 0] * y_up[ptr_y_up + 0];
+ tab_den0[ptr_den0++] = den0;
- /* den1 */
- den1 = temp0 + y_up[ptr_y_up+LD8KConstants.L_SUBFR] *
y_up[ptr_y_up+LD8KConstants.L_SUBFR];
- tab_den1[ptr_den1++] = den1;
+ /* den1 */
+ den1 = temp0 + y_up[ptr_y_up + LD8KConstants.L_SUBFR] * y_up[ptr_y_up +
LD8KConstants.L_SUBFR];
+ tab_den1[ptr_den1++] = den1;
-
if(Math.abs(y_up[ptr_y_up+0])>Math.abs(y_up[ptr_y_up+LD8KConstants.L_SUBFR]))
{
- if(den0 > den_max) {
- den_max = den0;
- }
- }
- else {
- if(den1 > den_max) {
- den_max = den1;
- }
- }
- ptr_y_up += LD8KConstants.L_SUBFRP1;
- ptr_h += LD8KConstants.LH2_S;
- }
- if(den_max < (float)0.1 ) {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- return;
- }
- /* Computation of the numerators */
- /* and selection of best num*num/den */
- /* for non null phases */
+ if (Math.abs(y_up[ptr_y_up + 0]) > Math.abs(y_up[ptr_y_up +
LD8KConstants.L_SUBFR])) {
+ if (den0 > den_max) {
+ den_max = den0;
+ }
+ } else {
+ if (den1 > den_max) {
+ den_max = den1;
+ }
+ }
+ ptr_y_up += LD8KConstants.L_SUBFRP1;
+ ptr_h += LD8KConstants.LH2_S;
+ }
+ if (den_max < (float) 0.1) {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ return;
+ }
+ /* Computation of the numerators */
+ /* and selection of best num*num/den */
+ /* for non null phases */
- /* Initialize with null phase */
- num_max = num_int;
- den_max = den_int;
- numsq_max = num_max * num_max;
- phi_max = 0;
- ioff = 1;
+ /* Initialize with null phase */
+ num_max = num_int;
+ den_max = den_int;
+ numsq_max = num_max * num_max;
+ phi_max = 0;
+ ioff = 1;
- ptr_den0 = 0;//tab_den0;
- ptr_den1 = 0;//tab_den1;
- ptr_y_up = 0;//y_up;
+ ptr_den0 = 0;// tab_den0;
+ ptr_den1 = 0;// tab_den1;
+ ptr_y_up = 0;// y_up;
- /* if den_max = 0 : will be selected and declared unvoiced */
- /* if num!=0 & den=0 : will be selected and declared unvoiced */
- /* degenerated seldom cases, switch off LT is OK */
+ /* if den_max = 0 : will be selected and declared unvoiced */
+ /* if num!=0 & den=0 : will be selected and declared unvoiced */
+ /* degenerated seldom cases, switch off LT is OK */
- /* Loop on phase */
- for(phi=1; phi<LD8KConstants.F_UP_PST; phi++) {
+ /* Loop on phase */
+ for (phi = 1; phi < LD8KConstants.F_UP_PST; phi++) {
+ /* computes num for lambda_max+1 - phi/F_UP_PST */
+ num = (float) 0.;
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ num += ptr_sig_in[ins + n] * y_up[ptr_y_up + n];
+ }
+ if (num < (float) 0.)
+ num = (float) 0.;
+ numsq = num * num;
- /* computes num for lambda_max+1 - phi/F_UP_PST */
- num = (float)0.;
- for(n = 0; n<LD8KConstants.L_SUBFR; n++) {
- num += ptr_sig_in[ins+n] * y_up[ptr_y_up+n];
- }
- if(num < (float)0.) num = (float)0.;
- numsq = num * num;
+ /* selection if num/sqrt(den0) max */
+ den0 = tab_den0[ptr_den0++];
+ temp0 = numsq * den_max;
+ temp1 = numsq_max * den0;
+ if (temp0 > temp1) {
+ num_max = num;
+ numsq_max = numsq;
+ den_max = den0;
+ ioff = 0;
+ phi_max = phi;
+ }
- /* selection if num/sqrt(den0) max */
- den0 = tab_den0[ptr_den0++];
- temp0 = numsq * den_max;
- temp1 = numsq_max * den0;
- if(temp0 > temp1) {
- num_max = num;
- numsq_max = numsq;
- den_max = den0;
- ioff = 0;
- phi_max = phi;
- }
+ /* computes num for lambda_max - phi/F_UP_PST */
+ ptr_y_up++;
+ num = (float) 0.;
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ num += ptr_sig_in[ins + n] * y_up[ptr_y_up + n];
+ }
+ if (num < (float) 0.)
+ num = (float) 0.;
+ numsq = num * num;
- /* computes num for lambda_max - phi/F_UP_PST */
- ptr_y_up++;
- num = (float)0.;
- for(n = 0; n<LD8KConstants.L_SUBFR; n++) {
- num += ptr_sig_in[ins+n] * y_up[ptr_y_up+n];
- }
- if(num < (float)0.) num = (float)0.;
- numsq = num * num;
+ /* selection if num/sqrt(den1) max */
+ den1 = tab_den1[ptr_den1++];
+ temp0 = numsq * den_max;
+ temp1 = numsq_max * den1;
+ if (temp0 > temp1) {
+ num_max = num;
+ numsq_max = numsq;
+ den_max = den1;
+ ioff = 1;
+ phi_max = phi;
+ }
+ ptr_y_up += LD8KConstants.L_SUBFR;
+ }
- /* selection if num/sqrt(den1) max */
- den1 = tab_den1[ptr_den1++];
- temp0 = numsq * den_max;
- temp1 = numsq_max * den1;
- if(temp0 > temp1) {
- num_max = num;
- numsq_max = numsq;
- den_max = den1;
- ioff = 1;
- phi_max = phi;
- }
- ptr_y_up += LD8KConstants.L_SUBFR;
- }
+ /***************************************************/
+ /*** test if normalised crit0[iopt] > THRESCRIT ***/
+ /***************************************************/
- /***************************************************/
- /*** test if normalised crit0[iopt] > THRESCRIT ***/
- /***************************************************/
+ if ((num_max == (float) 0.) || (den_max <= (float) 0.1)) {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ return;
+ }
- if((num_max == (float)0.) || (den_max <= (float)0.1)) {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- return;
- }
-
- /* comparison num * num */
- /* with ener * den x THRESCRIT */
- temp1 = den_max * ener * LD8KConstants.THRESCRIT;
- if(numsq_max >= temp1) {
- ltpdel.value = lambda + 1 - ioff;
- off_yup.value = ioff;
- phase.value = phi_max;
- num_gltp.value = num_max;
- den_gltp.value = den_max;
- }
- else {
- num_gltp.value = (float)0.;
- den_gltp.value = (float)1.;
- ltpdel.value = 0;
- phase.value = 0;
- }
- return;
+ /* comparison num * num */
+ /* with ener * den x THRESCRIT */
+ temp1 = den_max * ener * LD8KConstants.THRESCRIT;
+ if (numsq_max >= temp1) {
+ ltpdel.value = lambda + 1 - ioff;
+ off_yup.value = ioff;
+ phase.value = phi_max;
+ num_gltp.value = num_max;
+ den_gltp.value = den_max;
+ } else {
+ num_gltp.value = (float) 0.;
+ den_gltp.value = (float) 1.;
+ ltpdel.value = 0;
+ phase.value = 0;
+ }
+ return;
}
/*----------------------------------------------------------------------------
* filt_plt - ltp postfilter
*----------------------------------------------------------------------------
*/
- void filt_plt(
- float []s_in,int ins, /* input : input signal with past*/
- float []s_ltp,int ltps, /* input : filtered signal with gain 1 */
- float []s_out,int outs, /* output: output signal */
- float gain_plt /* input : filter gain */
- )
- {
+ void filt_plt(float[] s_in, int ins, /* input : input signal with past */
+ float[] s_ltp, int ltps, /* input : filtered signal with gain 1 */
+ float[] s_out, int outs, /* output: output signal */
+ float gain_plt /* input : filter gain */
+ ) {
- /* Local variables */
- int n;
- float temp;
- float gain_plt_1;
+ /* Local variables */
+ int n;
+ float temp;
+ float gain_plt_1;
- gain_plt_1 = (float)1. - gain_plt;
+ gain_plt_1 = (float) 1. - gain_plt;
- for(n=0; n<LD8KConstants.L_SUBFR; n++) {
- /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */
- temp = gain_plt * s_in[n+ins];
- temp += gain_plt_1 * s_ltp[n+ltps];
- s_out[n+outs] = temp;
- }
- return;
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */
+ temp = gain_plt * s_in[n + ins];
+ temp += gain_plt_1 * s_ltp[n + ltps];
+ s_out[n + outs] = temp;
+ }
+ return;
}
/*----------------------------------------------------------------------------
@@ -484,77 +495,73 @@
* with long interpolation filter
*----------------------------------------------------------------------------
*/
- static void compute_ltp_l(
- float []s_in, int ins, /* input signal with past*/
- int ltpdel, /* delay factor */
- int phase, /* phase factor */
- float []y_up, int ys, /* delayed signal */
- FloatPointer num, /* numerator of LTP gain */
- FloatPointer den /* denominator of LTP gain */
- )
- {
+ static void compute_ltp_l(float[] s_in, int ins, /* input signal with
past */
+ int ltpdel, /* delay factor */
+ int phase, /* phase factor */
+ float[] y_up, int ys, /* delayed signal */
+ FloatPointer num, /* numerator of LTP gain */
+ FloatPointer den /* denominator of LTP gain */
+ ) {
- /* Pointer on table of constants */
- int ptr_h;
+ /* Pointer on table of constants */
+ int ptr_h;
- /* Local variables */
- int n, i, ptr2;
- float temp;
+ /* Local variables */
+ int n, i, ptr2;
+ float temp;
- /* Filtering with long filter */
- ptr_h = (phase-1) * LD8KConstants.LH2_L;//TabLD8k.tab_hup_l
- ptr2 = 0 - ltpdel + LD8KConstants.LH_UP_L;//s_in
+ /* Filtering with long filter */
+ ptr_h = (phase - 1) * LD8KConstants.LH2_L;// TabLD8k.tab_hup_l
+ ptr2 = 0 - ltpdel + LD8KConstants.LH_UP_L;// s_in
- /* Compute y_up */
- for(n = 0; n<LD8KConstants.L_SUBFR; n++) {
- temp = (float)0.;
- for(i=0; i<LD8KConstants.LH2_L; i++) {
- temp += TabLD8k.tab_hup_l[ptr_h+i] * s_in[ins+ptr2--];
- }
- y_up[ys+n] = temp;
- ptr2 += LD8KConstants.LH2_L_P1;
- }
+ /* Compute y_up */
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ temp = (float) 0.;
+ for (i = 0; i < LD8KConstants.LH2_L; i++) {
+ temp += TabLD8k.tab_hup_l[ptr_h + i] * s_in[ins + ptr2--];
+ }
+ y_up[ys + n] = temp;
+ ptr2 += LD8KConstants.LH2_L_P1;
+ }
- num.value = (float)0.;
- /* Compute num */
- for(n = 0; n<LD8KConstants.L_SUBFR; n++) {
- num.value += y_up[ys+n]* s_in[ins+n];
- }
- if(num.value < (float)0.0) num.value = (float)0.0;
+ num.value = (float) 0.;
+ /* Compute num */
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ num.value += y_up[ys + n] * s_in[ins + n];
+ }
+ if (num.value < (float) 0.0)
+ num.value = (float) 0.0;
- den.value = (float)0.;
- /* Compute den */
- for(n = 0; n<LD8KConstants.L_SUBFR; n++) {
- den.value += y_up[ys+n]* y_up[ys+n];
- }
+ den.value = (float) 0.;
+ /* Compute den */
+ for (n = 0; n < LD8KConstants.L_SUBFR; n++) {
+ den.value += y_up[ys + n] * y_up[ys + n];
+ }
- return;
+ return;
}
+
/*----------------------------------------------------------------------------
* select_ltp : selects best of (gain1, gain2)
* with gain1 = num1 / den1
* and gain2 = num2 / den2
*----------------------------------------------------------------------------
*/
- static int select_ltp( /* output : 1 = 1st gain, 2 = 2nd gain */
- float num1, /* input : numerator of gain1 */
- float den1, /* input : denominator of gain1 */
- float num2, /* input : numerator of gain2 */
- float den2 /* input : denominator of gain2 */
- )
- {
- if(den2 == (float)0.) {
- return(1);
- }
- if(num2 * num2 * den1> num1 * num1 * den2) {
- return(2);
- }
- else {
- return(1);
- }
+ static int select_ltp( /* output : 1 = 1st gain, 2 = 2nd gain */
+ float num1, /* input : numerator of gain1 */
+ float den1, /* input : denominator of gain1 */
+ float num2, /* input : numerator of gain2 */
+ float den2 /* input : denominator of gain2 */
+ ) {
+ if (den2 == (float) 0.) {
+ return (1);
+ }
+ if (num2 * num2 * den1 > num1 * num1 * den2) {
+ return (2);
+ } else {
+ return (1);
+ }
}
-
-
/*----------------------------------------------------------------------------
* calc_st_filt - computes impulse response of A(gamma2) / A(gamma1)
@@ -562,84 +569,86 @@
* SUMn (abs (h[n])) and computes parcor0
*----------------------------------------------------------------------------
***The diff for this file has been truncated for email.***
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/PostPro.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/PostPro.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class PostPro {
@@ -23,41 +24,36 @@
* a[3] = {0.10000000E+01, +0.19330735E+01, -0.93589199E+00};
*
*-----------------------------------------------------------------------*/
- float x0, x1; /* high-pass fir memory */
- float y1, y2; /* high-pass iir memory */
+ float x0, x1; /* high-pass fir memory */
+ float y1, y2; /* high-pass iir memory */
- public void init_post_process(
- )
- {
- x0 = x1 = (float)0.0;
- y2 = y1 = (float)0.0;
- return;
+ public void init_post_process() {
+ x0 = x1 = (float) 0.0;
+ y2 = y1 = (float) 0.0;
+ return;
}
- public void post_process(
- float signal[], /* (i/o) : signal */
- int lg /* (i) : lenght of signal */
- )
- {
- int i;
- float x2;
- float y0;
+ public void post_process(float signal[], /* (i/o) : signal */
+ int lg /* (i) : lenght of signal */
+ ) {
+ int i;
+ float x2;
+ float y0;
- for(i=0; i<lg; i++)
- {
- x2 = x1;
- x1 = x0;
- x0 = signal[i];
+ for (i = 0; i < lg; i++) {
+ x2 = x1;
+ x1 = x0;
+ x0 = signal[i];
- y0 = y1*TabLD8k.a100[1] + y2*TabLD8k.a100[2] + x0*TabLD8k.b100[0] +
x1*TabLD8k.b100[1] + x2*TabLD8k.b100[2];
+ y0 = y1 * TabLD8k.a100[1] + y2 * TabLD8k.a100[2] + x0 * TabLD8k.b100[0]
+ x1 * TabLD8k.b100[1] + x2
+ * TabLD8k.b100[2];
- signal[i] = y0;
- y2 = y1;
- y1 = y0;
- }
+ signal[i] = y0;
+ y2 = y1;
+ y1 = y0;
+ }
- return;
+ return;
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/PreProc.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/PreProc.java Thu Feb 21
09:21:48 2013
@@ -1,4 +1,5 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class PreProc {
@@ -16,43 +17,37 @@
* a[3] = {0.10000000E+01, 0.19059465E+01, -0.91140240E+00};
*
*-----------------------------------------------------------------------*/
+ float x0, x1; /* high-pass fir memory */
+ float y1, y2; /* high-pass iir memory */
- float x0, x1; /* high-pass fir memory */
- float y1, y2; /* high-pass iir memory */
+ public void init_pre_process() {
+ x0 = x1 = (float) 0.0;
+ y2 = y1 = (float) 0.0;
- public void init_pre_process(
- )
- {
- x0 = x1 = (float)0.0;
- y2 = y1 = (float)0.0;
-
- return;
+ return;
}
- public void pre_process(
- float signal[], /* (i/o) : signal */
- int lg /* (i) : lenght of signal */
- )
- {
- int i;
- float x2;
- float y0;
+ public void pre_process(float signal[], /* (i/o) : signal */
+ int lg /* (i) : lenght of signal */
+ ) {
+ int i;
+ float x2;
+ float y0;
- for(i=0; i<lg; i++)
- {
- x2 = x1;
- x1 = x0;
- x0 = signal[i];
+ for (i = 0; i < lg; i++) {
+ x2 = x1;
+ x1 = x0;
+ x0 = signal[i];
- y0 = y1*TabLD8k.a140[1] + y2*TabLD8k.a140[2] + x0*TabLD8k.b140[0] +
x1*TabLD8k.b140[1] + x2*TabLD8k.b140[2];
+ y0 = y1 * TabLD8k.a140[1] + y2 * TabLD8k.a140[2] + x0 * TabLD8k.b140[0]
+ x1 * TabLD8k.b140[1] + x2
+ * TabLD8k.b140[2];
- signal[i] = y0;
- y2 = y1;
- y1 = y0;
- }
+ signal[i] = y0;
+ y2 = y1;
+ y1 = y0;
+ }
- return;
+ return;
}
-
}
=======================================
--- /branches/red5sip/src/java/org/red5/codecs/g729/PredLt.java Fri Feb 10
07:37:46 2012
+++ /branches/red5sip/src/java/org/red5/codecs/g729/PredLt.java Thu Feb 21
09:21:48 2013
@@ -1,9 +1,9 @@
package org.red5.codecs.g729;
+
//package org.mobicents.media.server.impl.dsp.audio.g729;
public class PredLt {
-
/*-------------------------------------------------------------------*
* Function Pred_lt_3() *
* ~~~~~~~~~~~ *
@@ -15,42 +15,39 @@
* (adaptive codebook excitation) *
*-------------------------------------------------------------------*/
- public static void pred_lt_3( /* Compute adaptive
codebook */
- float exc[],int excs, /* in/out: excitation vector,
exc[0:l_sub-1] = out */
- int t0, /* input : pitch
lag */
- int frac, /* input : Fraction of pitch lag (-1, 0, 1) /
3 */
- int l_subfr /* input : length of
subframe. */
- )
- {
+ public static void pred_lt_3( /* Compute adaptive codebook */
+ float exc[], int excs, /* in/out: excitation vector, exc[0:l_sub-1] = out
*/
+ int t0, /* input : pitch lag */
+ int frac, /* input : Fraction of pitch lag (-1, 0, 1) / 3 */
+ int l_subfr /* input : length of subframe. */
+ ) {
- int i, j, k;
- float s;
- int x0, x1, x2, c1, c2;
+ int i, j, k;
+ float s;
+ int x0, x1, x2, c1, c2;
+ x0 = -t0;// &exc[-t0];
- x0 = -t0;//&exc[-t0];
+ frac = -frac;
+ if (frac < 0) {
+ frac += LD8KConstants.UP_SAMP;
+ x0--;
+ }
- frac = -frac;
- if (frac < 0) {
- frac += LD8KConstants.UP_SAMP;
- x0--;
- }
-
- for (j=0; j<l_subfr; j++)
- {
- x1 = x0++;
- x2 = x0;
- c1 = frac;//&inter_3l[frac];
- c2 =
LD8KConstants.UP_SAMP-frac;//&inter_3l[LD8KConstants.UP_SAMP-frac];
+ for (j = 0; j < l_subfr; j++) {
+ x1 = x0++;
+ x2 = x0;
+ c1 = frac;// &inter_3l[frac];
+ c2 = LD8KConstants.UP_SAMP - frac;//
&inter_3l[LD8KConstants.UP_SAMP-frac];
- s = (float)0.0;
- for(i=0, k=0; i< LD8KConstants.L_INTER10; i++,
k+=LD8KConstants.UP_SAMP)
- s+= exc[excs+x1-i] * TabLD8k.inter_3l[c1+k] + exc[excs+x2+i] *
TabLD8k.inter_3l[c2+k];
+ s = (float) 0.0;
+ for (i = 0, k = 0; i < LD8KConstants.L_INTER10; i++, k +=
LD8KConstants.UP_SAMP)
+ s += exc[excs + x1 - i] * TabLD8k.inter_3l[c1 + k] + exc[excs + x2 +
i] * TabLD8k.inter_3l[c2 + k];
- exc[excs+j] = s;
- }
+ exc[excs + j] = s;
+ }
- return;
+ return;
}
}
=======================================
***Additional files exist in this changeset.***