aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-03-29 11:10:28 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-03-29 11:10:28 +0000
commit42025f82fb09089933442641ac0e0e0db11630ff (patch)
treeb64a861f1c99ea08adc7e1c1ae3eeb45fe9a92dc
parentb5c18d41cc8a7118828dafcd50fa152fa4276b92 (diff)
downloadjitsi-42025f82fb09089933442641ac0e0e0db11630ff.zip
jitsi-42025f82fb09089933442641ac0e0e0db11630ff.tar.gz
jitsi-42025f82fb09089933442641ac0e0e0db11630ff.tar.bz2
Eliminates duplicate code and thus uses the same logic for increasing/decreasing the capture volume as used for the playback volume i.e. clips the captured audio samples instead of wrapping them and assigns the range from 0% to 200% to the capture volume scale in the call dialog.
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java50
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java28
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java52
3 files changed, 59 insertions, 71 deletions
diff --git a/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java b/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
index a03b50f..1531ef1 100644
--- a/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
+++ b/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
@@ -111,6 +111,56 @@ public abstract class AbstractVolumeControl
}
/**
+ * Applies the gain specified by <tt>gainControl</tt> to the signal defined
+ * by the <tt>length</tt> number of samples given in <tt>buffer</tt>
+ * starting at <tt>offset</tt>.
+ *
+ * @param gainControl the <tt>GainControl</tt> which specifies the gain to
+ * apply
+ * @param buffer the samples of the signal to apply the gain to
+ * @param offset the start of the samples of the signal in <tt>buffer</tt>
+ * @param length the number of samples of the signal given in
+ * <tt>buffer</tt>
+ */
+ public static void applyGain(
+ GainControl gainControl,
+ byte[] buffer, int offset, int length)
+ {
+ if (gainControl.getMute())
+ Arrays.fill(buffer, offset, offset + length, (byte) 0);
+ else
+ {
+ // Assign the maximum of 200% to the volume scale.
+ float level = gainControl.getLevel() * 2;
+
+ if (level != 1)
+ {
+ for (int i = offset, toIndex = offset + length;
+ i < toIndex;
+ i += 2)
+ {
+ int i1 = i + 1;
+ short s = (short) ((buffer[i] & 0xff) | (buffer[i1] << 8));
+
+ /* Clip, don't wrap. */
+ int si = s;
+
+ si = (int) (si * level);
+ if (si > Short.MAX_VALUE)
+ s = Short.MAX_VALUE;
+ else if (si < Short.MIN_VALUE)
+ s = Short.MIN_VALUE;
+ else
+ s = (short) si;
+
+ buffer[i] = (byte) s;
+ buffer[i1] = (byte) (s >> 8);
+ }
+ }
+ }
+ }
+
+ /**
* Current volume value.
*
* @return the current volume level.
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
index 10bae4a..b10d179 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
@@ -7,7 +7,6 @@
package net.java.sip.communicator.impl.neomedia.jmfext.media.protocol.portaudio;
import java.io.*;
-import java.util.*;
import javax.media.*;
import javax.media.control.*;
@@ -23,7 +22,7 @@ import net.java.sip.communicator.util.*;
* Implements <tt>PullBufferStream</tt> for PortAudio.
*
* @author Damian Minkov
- * @author Lubomir Marinov
+ * @author Lyubomir Marinov
*/
public class PortAudioStream
extends AbstractPullBufferStream
@@ -190,28 +189,9 @@ public class PortAudioStream
// if we have some volume setting apply them
if(volumeControl != null)
{
- if(volumeControl.getMute())
- {
- Arrays.fill(bufferData, (byte) 0);
- }
- else if(volumeControl.getDB() != 0)
- {
- // increase/decrease a little more than
- // if using levels for factor
- // we use factor = pow(10, dB/10),
- // but level = pow(10, dB/20);
- double factor = Math.pow(10, (volumeControl.getDB() / 10d));
-
- for (int i = 0; i < bufferData.length; i+=2)
- {
- short s = (short)((bufferData[i]&0xff)
- | (bufferData[i + 1]<<8));
- s = (short)(s*factor);
-
- bufferData[i] = (byte) s;
- bufferData[i+1] = (byte) (s >> 8);
- }
- }
+ AbstractVolumeControl.applyGain(
+ volumeControl,
+ bufferData, 0, bytesPerBuffer);
}
long bufferTimeStamp = System.nanoTime();
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
index b7f0bbd..543c07b 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
@@ -177,52 +177,6 @@ public class PortAudioRenderer
}
/**
- * Applies the gain specified by {@link #gainControl} to the signal defined
- * by the <tt>length</tt> number of samples given in <tt>buffer</tt>
- * starting at <tt>offset</tt>.
- *
- * @param buffer the samples of the signal to apply the gain to
- * @param offset the start of the samples of the signal in <tt>buffer</tt>
- * @param length the number of samples of the signal given in
- * <tt>buffer</tt>
- */
- private void applyGain(byte[] buffer, int offset, int length)
- {
- if (gainControl.getMute())
- Arrays.fill(buffer, offset, offset + length, (byte) 0);
- else
- {
- // Assign the maximum of 200% to the volume scale.
- float level = gainControl.getLevel() * 2;
-
- if (level != 1)
- {
- for (int i = offset, toIndex = offset + length;
- i < toIndex;
- i += 2)
- {
- int i1 = i + 1;
- short s = (short) ((buffer[i] & 0xff) | (buffer[i1] << 8));
-
- /* Clip, don't wrap. */
- int si = s;
-
- si = (int) (si * level);
- if (si > Short.MAX_VALUE)
- s = Short.MAX_VALUE;
- else if (si < Short.MIN_VALUE)
- s = Short.MIN_VALUE;
- else
- s = (short) si;
-
- buffer[i] = (byte) s;
- buffer[i1] = (byte) (s >> 8);
- }
- }
- }
- }
-
- /**
* Closes this <tt>PlugIn</tt>.
*/
public synchronized void close()
@@ -552,7 +506,11 @@ public class PortAudioRenderer
{
// if we have some volume setting apply them
if (gainControl != null)
- applyGain(buffer, offset, length);
+ {
+ AbstractVolumeControl.applyGain(
+ gainControl,
+ buffer, offset, length);
+ }
PortAudio.Pa_WriteStream(
stream,