[kaffe] CVS kaffe (dalibor): Resynced with Tritonus

Kaffe CVS cvs-commits at kaffe.org
Sun Sep 21 10:29:02 PDT 2003


PatchSet 4050 
Date: 2003/09/21 17:26:32
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with Tritonus

Updated out of date files with those from Tritonus.org CVS archive

Members: 
	ChangeLog:1.1646->1.1647 
	libraries/javalib/javax/sound/midi/MetaMessage.java:1.1->1.2 
	libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java:1.1->1.2 
	libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java:1.1->1.2 
	libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java:1.1->1.2 
	libraries/javalib/org/tritonus/sampled/file/AiffTool.java:1.1->1.2 
	libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java:1.1->1.2 
	libraries/javalib/org/tritonus/sampled/file/WaveTool.java:1.1->1.2 
	libraries/javalib/org/tritonus/share/TCircularBuffer.java:1.1->1.2 
	libraries/javalib/org/tritonus/share/TDebug.java:1.1->1.2 
	libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java:1.1->1.2 
	libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java:1.1->1.2 
	libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java:1.2->1.3 
	libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1646 kaffe/ChangeLog:1.1647
--- kaffe/ChangeLog:1.1646	Fri Sep 19 13:15:14 2003
+++ kaffe/ChangeLog	Sun Sep 21 17:26:32 2003
@@ -1,5 +1,22 @@
 2003-09-19  Dalibor Topic <robilad at kaffe.org>
 
+	* libraries/javalib/javax/sound/midi/MetaMessage.java,
+	libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java,
+	libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java,
+	libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java,
+	libraries/javalib/org/tritonus/sampled/file/AiffTool.java,
+	libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java,
+	libraries/javalib/org/tritonus/sampled/file/WaveTool.java,
+	libraries/javalib/org/tritonus/share/TCircularBuffer.java,
+	libraries/javalib/org/tritonus/share/TDebug.java,
+	libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java,
+	libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java,
+	libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java,
+	libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java:
+	Resynced with tritonus.
+	
+2003-09-19  Dalibor Topic <robilad at kaffe.org>
+
 	* kaffe/kaffevm/jit/machine.c,
 	kaffe/kaffevm/jit/machine.h:
 	Always declare and define globalMethod, which is used
Index: kaffe/libraries/javalib/javax/sound/midi/MetaMessage.java
diff -u kaffe/libraries/javalib/javax/sound/midi/MetaMessage.java:1.1 kaffe/libraries/javalib/javax/sound/midi/MetaMessage.java:1.2
--- kaffe/libraries/javalib/javax/sound/midi/MetaMessage.java:1.1	Mon Jan  6 17:14:33 2003
+++ kaffe/libraries/javalib/javax/sound/midi/MetaMessage.java	Sun Sep 21 17:26:33 2003
@@ -55,8 +55,6 @@
 
 
 
-	/**	TODO:
-	*/
 	/**	Create a container for a MIDI meta message.
 		This constructor does not create an object containing a legal
 		MIDI message. You have to use one of the setMessage() methods.
@@ -65,9 +63,7 @@
 		getData()) may have
 		undesired results.
 
-		@see #setMessage(int)
-		@see #setMessage(int, int, int)
-		@see #setMessage(int, int, int, int)
+		@see #setMessage(int, byte[], int)
 	*/
 	public MetaMessage()
 	{
Index: kaffe/libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java
diff -u kaffe/libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java:1.1 kaffe/libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java:1.2
--- kaffe/libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java:1.1	Mon Jan  6 17:14:34 2003
+++ kaffe/libraries/javalib/org/tritonus/lowlevel/alsa/AlsaPcm.java	Sun Sep 21 17:26:34 2003
@@ -294,7 +294,7 @@
 	   @param lOffset Offset where the data should be read from
 	   the buffer, in bytes.
 
-	   @lFrameCount Length of the data to write, in number of PCM
+	   @param lFrameCount Length of the data to write, in number of PCM
 	   frames.
 
 	 */
Index: kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java
diff -u kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java:1.1 kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java:1.2
--- kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java:1.1	Mon Jan  6 17:14:36 2003
+++ kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileReader.java	Sun Sep 21 17:26:35 2003
@@ -35,8 +35,8 @@
 import	javax.sound.sampled.AudioFormat;
 import	javax.sound.sampled.AudioFileFormat;
 import	javax.sound.sampled.AudioInputStream;
+import	javax.sound.sampled.AudioSystem;
 import	javax.sound.sampled.UnsupportedAudioFileException;
-import	javax.sound.sampled.spi.AudioFileReader;
 
 import	org.tritonus.share.sampled.file.TAudioFileFormat;
 import	org.tritonus.share.sampled.file.TAudioFileReader;
@@ -100,23 +100,35 @@
 			if (nEncoding==AiffTool.AIFF_COMM_PCM) {
 				// PCM - nothing to do
 			}
-			else
-				if (nEncoding==AiffTool.AIFF_COMM_ULAW) {
-					// ULAW
-					encoding=AudioFormat.Encoding.ULAW;
-					nSampleSize=8;
-				} else {
-					throw new UnsupportedAudioFileException(
-					    "Encoding 0x"+Integer.toHexString(nEncoding)
-					    +" of AIFF file not supported");
-				}
+			else if (nEncoding==AiffTool.AIFF_COMM_ULAW) {
+				// ULAW
+				encoding=AudioFormat.Encoding.ULAW;
+				nSampleSize=8;
+			}
+			else if (nEncoding==AiffTool.AIFF_COMM_IMA_ADPCM) {
+				encoding = Encodings.getEncoding("IMA_ADPCM");
+				nSampleSize=4;
+			}
+			else {
+				throw new UnsupportedAudioFileException(
+					"Encoding 0x"+Integer.toHexString(nEncoding)
+					+" of AIFF file not supported");
+			}
 		}
+		/* In case of IMA ADPCM, frame size is 0.5 bytes (since it is
+		   always mono). A value of 1 as frame size would be wrong.
+		   Handling of frame size 0 in defined nowhere. So the best
+		   solution is to set the frame size to unspecified (-1).
+		*/
+		int nFrameSize = (nSampleSize == 4) ?
+			AudioSystem.NOT_SPECIFIED :
+			(nSampleSize * nNumChannels) / 8;
 		skipChunk(dataInputStream, chunkLength, nRead);
 		AudioFormat format = new AudioFormat(encoding,
 		                                     fSampleRate,
 		                                     nSampleSize,
 		                                     nNumChannels,
-		                                     (nSampleSize * nNumChannels) / 8,
+		                                     nFrameSize,
 		                                     fSampleRate,
 		                                     true);
 		return format;
@@ -139,9 +151,10 @@
 
 
 	protected AudioFileFormat getAudioFileFormat(InputStream inputStream, long lFileSizeInBytes)
-	throws	UnsupportedAudioFileException, IOException {
-		DataInputStream	dataInputStream = new DataInputStream(inputStream);
+	throws	UnsupportedAudioFileException, IOException
+	{
 		if (TDebug.TraceAudioFileReader) {TDebug.out("AiffAudioFileReader.getAudioFileFormat(InputStream, long): begin"); }
+		DataInputStream	dataInputStream = new DataInputStream(inputStream);
 		int	nMagic = dataInputStream.readInt();
 		if (nMagic != AiffTool.AIFF_FORM_MAGIC) {
 			throw new UnsupportedAudioFileException(
Index: kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java
diff -u kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java:1.1 kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java:1.2
--- kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java:1.1	Mon Jan  6 17:14:36 2003
+++ kaffe/libraries/javalib/org/tritonus/sampled/file/AiffAudioFileWriter.java	Sun Sep 21 17:26:35 2003
@@ -35,6 +35,7 @@
 import	javax.sound.sampled.AudioSystem;
 
 import	org.tritonus.share.TDebug;
+import	org.tritonus.share.sampled.Encodings;
 import	org.tritonus.share.sampled.file.AudioOutputStream;
 import	org.tritonus.share.sampled.file.TAudioFileWriter;
 import	org.tritonus.share.sampled.file.TDataOutputStream;
@@ -55,18 +56,23 @@
 	    };
 
 	private static final int ALL=AudioSystem.NOT_SPECIFIED;
+	private static final AudioFormat.Encoding	PCM_SIGNED = AudioFormat.Encoding.PCM_SIGNED;
+	private static final AudioFormat.Encoding	ULAW = AudioFormat.Encoding.ULAW;
+	private static final AudioFormat.Encoding	IMA_ADPCM = Encodings.getEncoding("IMA_ADPCM");
 
 	// IMPORTANT: this array depends on the AudioFormat.match() algorithm which takes
 	//            AudioSystem.NOT_SPECIFIED into account !
 	private static final AudioFormat[]	AUDIO_FORMATS =
 	    {
-	        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, ALL, 8, ALL, ALL, ALL, true),
-	        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, ALL, 8, ALL, ALL, ALL, false),
-	        new AudioFormat(AudioFormat.Encoding.ULAW, ALL, 8, ALL, ALL, ALL, false),
-	        new AudioFormat(AudioFormat.Encoding.ULAW, ALL, 8, ALL, ALL, ALL, true),
-	        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, ALL, 16, ALL, ALL, ALL, true),
-	        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, ALL, 24, ALL, ALL, ALL, true),
-	        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, ALL, 32, ALL, ALL, ALL, true),
+	        new AudioFormat(PCM_SIGNED, ALL, 8, ALL, ALL, ALL, true),
+	        new AudioFormat(PCM_SIGNED, ALL, 8, ALL, ALL, ALL, false),
+	        new AudioFormat(ULAW, ALL, 8, ALL, ALL, ALL, false),
+	        new AudioFormat(ULAW, ALL, 8, ALL, ALL, ALL, true),
+	        new AudioFormat(PCM_SIGNED, ALL, 16, ALL, ALL, ALL, true),
+	        new AudioFormat(PCM_SIGNED, ALL, 24, ALL, ALL, ALL, true),
+	        new AudioFormat(PCM_SIGNED, ALL, 32, ALL, ALL, ALL, true),
+	        new AudioFormat(IMA_ADPCM, ALL, 4, ALL, ALL, ALL, true),
+	        new AudioFormat(IMA_ADPCM, ALL, 4, ALL, ALL, ALL, false),
 	    };
 
 	public AiffAudioFileWriter() {
Index: kaffe/libraries/javalib/org/tritonus/sampled/file/AiffTool.java
diff -u kaffe/libraries/javalib/org/tritonus/sampled/file/AiffTool.java:1.1 kaffe/libraries/javalib/org/tritonus/sampled/file/AiffTool.java:1.2
--- kaffe/libraries/javalib/org/tritonus/sampled/file/AiffTool.java:1.1	Mon Jan  6 17:14:36 2003
+++ kaffe/libraries/javalib/org/tritonus/sampled/file/AiffTool.java	Sun Sep 21 17:26:35 2003
@@ -29,6 +29,8 @@
 import	javax.sound.sampled.AudioFileFormat;
 import	javax.sound.sampled.AudioSystem;
 
+import org.tritonus.share.sampled.Encodings;
+
 /**
  * Common constants and methods for handling aiff and aiff-c files.
  *
@@ -64,6 +66,8 @@
 			return AIFF_COMM_PCM;
 		} else if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) {
 			return AIFF_COMM_ULAW;
+		} else if (encoding.equals(Encodings.getEncoding("IMA_ADPCM")) && nSampleSize == 4) {
+			return AIFF_COMM_IMA_ADPCM;
 		} else {
 			return AIFF_COMM_UNSPECIFIED;
 		}
Index: kaffe/libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java
diff -u kaffe/libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java:1.1 kaffe/libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java:1.2
--- kaffe/libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java:1.1	Mon Jan  6 17:14:36 2003
+++ kaffe/libraries/javalib/org/tritonus/sampled/file/WaveAudioFileReader.java	Sun Sep 21 17:26:35 2003
@@ -136,6 +136,7 @@
 		int frameSize=0;
 		float frameRate=(float) sampleRate;
 
+		int cbSize = 0;
 		switch (formatCode) {
 		case WaveTool.WAVE_FORMAT_PCM:
 			if (chunkLength<WaveTool.MIN_FMT_CHUNK_LENGTH+2) {
@@ -168,7 +169,7 @@
 				    "corrupt WAVE file: extra GSM bytes are missing");
 			}
 			sampleSizeInBits = readLittleEndianShort(dis); // sample Size (is 0 for GSM)
-			int cbSize=readLittleEndianShort(dis);
+			cbSize=readLittleEndianShort(dis);
 			if (cbSize < 2) {
 				throw new UnsupportedAudioFileException(
 				    "corrupt WAVE file: extra GSM bytes are corrupt");
@@ -185,6 +186,33 @@
 			frameRate=((float) sampleRate)/((float) decodedSamplesPerBlock);
 			read+=6;
 			break;
+
+		case WaveTool.WAVE_FORMAT_IMA_ADPCM:
+			if (chunkLength < WaveTool.MIN_FMT_CHUNK_LENGTH + 2)
+			{
+				throw new UnsupportedAudioFileException(
+					"corrupt WAVE file: extra GSM bytes are missing");
+			}
+			sampleSizeInBits = readLittleEndianShort(dis);
+			cbSize = readLittleEndianShort(dis);
+			if (cbSize < 2)
+			{
+				throw new UnsupportedAudioFileException(
+				    "corrupt WAVE file: extra IMA ADPCM bytes are corrupt");
+			}
+			int samplesPerBlock = readLittleEndianShort(dis) & 0xFFFF; // unsigned
+			if (TDebug.TraceAudioFileReader) {
+				debugAdd+=", wBitsPerSample="+sampleSizeInBits
+				          +", cbSize="+cbSize
+				          +", wSamplesPerBlock=" + samplesPerBlock;
+			}
+			sampleSizeInBits = AudioSystem.NOT_SPECIFIED;
+			encoding = WaveTool.GSM0610;
+			frameSize = blockAlign;
+			frameRate = ((float) sampleRate)/((float) samplesPerBlock);
+			read += 6;
+			break;
+
 		default:
 			throw new UnsupportedAudioFileException(
 			    "unsupported WAVE file: unknown format code "+formatCode);
@@ -222,6 +250,8 @@
 		           frameRate,
 		           false);
 	}
+
+
 
 	protected AudioFileFormat getAudioFileFormat(InputStream inputStream, long lFileLengthInBytes)
 	throws	UnsupportedAudioFileException, IOException {
Index: kaffe/libraries/javalib/org/tritonus/sampled/file/WaveTool.java
diff -u kaffe/libraries/javalib/org/tritonus/sampled/file/WaveTool.java:1.1 kaffe/libraries/javalib/org/tritonus/sampled/file/WaveTool.java:1.2
--- kaffe/libraries/javalib/org/tritonus/sampled/file/WaveTool.java:1.1	Mon Jan  6 17:14:36 2003
+++ kaffe/libraries/javalib/org/tritonus/sampled/file/WaveTool.java	Sun Sep 21 17:26:35 2003
@@ -50,11 +50,10 @@
 	public static final short WAVE_FORMAT_MS_ADPCM = 2;
 	public static final short WAVE_FORMAT_ALAW = 6;
 	public static final short WAVE_FORMAT_ULAW = 7;
-	public static final short WAVE_FORMAT_IMA_ADPCM = 17;
+	public static final short WAVE_FORMAT_IMA_ADPCM = 17; // same as DVI_ADPCM
 	public static final short WAVE_FORMAT_G723_ADPCM = 20;
-	public static final short WAVE_FORMAT_GSM_610 = 49;
+	public static final short WAVE_FORMAT_GSM610 = 49;
 	public static final short WAVE_FORMAT_G721_ADPCM = 64;
-	public static final short WAVE_FORMAT_GSM610 = 0x0031;
 	public static final short WAVE_FORMAT_MPEG = 80;
 
 	public static final int MIN_FMT_CHUNK_LENGTH=14;
@@ -92,7 +91,12 @@
 		           && (nSampleSize==AudioSystem.NOT_SPECIFIED || nSampleSize == 8)
 		           && frameSizeOK) {
 			return WAVE_FORMAT_ALAW;
-		} else if (encoding.equals(GSM0610)) {
+		} else if (encoding.equals(Encodings.getEncoding("IMA_ADPCM"))
+		           && nSampleSize == 4)
+		{
+			return WAVE_FORMAT_IMA_ADPCM;
+		}
+		else if (encoding.equals(GSM0610)) {
 			return WAVE_FORMAT_GSM610;
 		} else {
 			return WAVE_FORMAT_UNSPECIFIED;
Index: kaffe/libraries/javalib/org/tritonus/share/TCircularBuffer.java
diff -u kaffe/libraries/javalib/org/tritonus/share/TCircularBuffer.java:1.1 kaffe/libraries/javalib/org/tritonus/share/TCircularBuffer.java:1.2
--- kaffe/libraries/javalib/org/tritonus/share/TCircularBuffer.java:1.1	Mon Jan  6 17:14:37 2003
+++ kaffe/libraries/javalib/org/tritonus/share/TCircularBuffer.java	Sun Sep 21 17:26:35 2003
@@ -60,13 +60,13 @@
 	public void close()
 	{
 		m_bOpen = false;
+		// TODO: call notify() ?
 	}
 
 
 
 	public int availableRead()
 	{
-		// return (m_nWritePos - m_nReadPos) % m_nSize;
 		return m_nWritePos - m_nReadPos;
 	}
 
@@ -102,35 +102,35 @@
 
 	public int read(byte[] abData, int nOffset, int nLength)
 	{
-		if (TDebug.TraceCircularBuffer)
-		{
-			TDebug.out(">TCircularBuffer.read(): called.");
-			TDebug.out("m_nReadPos  = "+m_nReadPos+" ^= "+getReadPos());
-			TDebug.out("m_nWritePos = "+m_nWritePos+" ^= "+getWritePos());
-			TDebug.out("availableRead()  = "+availableRead());
-			TDebug.out("availableWrite() = "+availableWrite());
-		}
-		// TODO: shoudl be inside synchronized block?
 		if (!m_bOpen)
 		{
-			if (TDebug.TraceCircularBuffer)
+			if (availableRead() > 0)
+			{
+				nLength = Math.min(nLength, availableRead());
+			}
+			else
 			{
-				TDebug.out("< not open. returning -1.");
+				if (TDebug.TraceCircularBuffer) { TDebug.out("< not open. returning -1."); }
+				return -1;
 			}
-			return -1;
+		}
+		if (TDebug.TraceCircularBuffer)
+		{
+			TDebug.out(">TCircularBuffer.read(): called.");
+			TDebug.out("m_nReadPos  = " + m_nReadPos + " ^= "+getReadPos());
+			TDebug.out("m_nWritePos = " + m_nWritePos + " ^= "+getWritePos());
+			TDebug.out("availableRead()  = " + availableRead());
+			TDebug.out("availableWrite() = " + availableWrite());
 		}
 		synchronized (this)
 		{
+			if (m_trigger != null && availableRead() < nLength)
+			{
+				if (TDebug.TraceCircularBuffer) { TDebug.out("executing trigger."); }
+				m_trigger.execute();
+			}
 			if (!m_bBlockingRead)
 			{
-				if (m_trigger != null && availableRead() < nLength)
-				{
-					if (TDebug.TraceCircularBuffer)
-					{
-						TDebug.out("executing trigger.");
-					}
-					m_trigger.execute();
-				}
 				nLength = Math.min(availableRead(), nLength);
 			}
 			int nRemainingBytes = nLength;
@@ -165,11 +165,8 @@
 			if (TDebug.TraceCircularBuffer)
 			{
 				TDebug.out("After read:");
-				TDebug.out("m_nReadPos  = "+m_nReadPos+" ^= "+getReadPos());
-				TDebug.out("m_nWritePos = "+m_nWritePos+" ^= "+getWritePos());
-				TDebug.out("availableRead()  = "+availableRead());
-				TDebug.out("availableWrite() = "+availableWrite());
-				TDebug.out("< completed. Read "+nLength+" bytes");
+				dumpInternalState();
+				TDebug.out("< completed. Read " + nLength + " bytes");
 			}
 			return nLength;
 		}
@@ -188,17 +185,11 @@
 		if (TDebug.TraceCircularBuffer)
 		{
 			TDebug.out(">TCircularBuffer.write(): called; nLength: " + nLength);
-			TDebug.out("m_nReadPos  = "+m_nReadPos+" ^= "+getReadPos());
-			TDebug.out("m_nWritePos = "+m_nWritePos+" ^= "+getWritePos());
-			TDebug.out("availableRead()  = "+availableRead());
-			TDebug.out("availableWrite() = "+availableWrite());
+			dumpInternalState();
 		}
 		synchronized (this)
 		{
-			if (TDebug.TraceCircularBuffer)
-			{
-				TDebug.out("entered synchronized block.");
-			}
+			if (TDebug.TraceCircularBuffer) { TDebug.out("entered synchronized block."); }
 			if (!m_bBlockingWrite)
 			{
 				nLength = Math.min(availableWrite(), nLength);
@@ -236,16 +227,22 @@
 			if (TDebug.TraceCircularBuffer)
 			{
 				TDebug.out("After write:");
-				TDebug.out("m_nReadPos  = "+m_nReadPos+" ^= "+getReadPos());
-				TDebug.out("m_nWritePos = "+m_nWritePos+" ^= "+getWritePos());
-				TDebug.out("availableRead()  = "+availableRead());
-				TDebug.out("availableWrite() = "+availableWrite());
+				dumpInternalState();
 				TDebug.out("< completed. Wrote "+nLength+" bytes");
 			}
 			return nLength;
 		}
 	}
 
+
+
+	private void dumpInternalState()
+	{
+		TDebug.out("m_nReadPos  = " + m_nReadPos + " ^= "+getReadPos());
+		TDebug.out("m_nWritePos = " + m_nWritePos + " ^= "+getWritePos());
+		TDebug.out("availableRead()  = " + availableRead());
+		TDebug.out("availableWrite() = " + availableWrite());
+	}
 
 
 	public static interface Trigger
Index: kaffe/libraries/javalib/org/tritonus/share/TDebug.java
diff -u kaffe/libraries/javalib/org/tritonus/share/TDebug.java:1.1 kaffe/libraries/javalib/org/tritonus/share/TDebug.java:1.2
--- kaffe/libraries/javalib/org/tritonus/share/TDebug.java:1.1	Mon Jan  6 17:14:37 2003
+++ kaffe/libraries/javalib/org/tritonus/share/TDebug.java	Sun Sep 21 17:26:35 2003
@@ -70,6 +70,9 @@
 	public static boolean	TraceAlsaNative = getBooleanProperty("TraceAlsaNative");
 	public static boolean	TraceAlsaMixerNative = getBooleanProperty("TraceAlsaMixerNative");
 	public static boolean	TraceAlsaPcmNative = getBooleanProperty("TraceAlsaPcmNative");
+	public static boolean	TraceMixingAudioInputStream = getBooleanProperty("TraceMixingAudioInputStream");
+	public static boolean	TraceOggNative = getBooleanProperty("TraceOggNative");
+	public static boolean	TraceVorbisNative = getBooleanProperty("TraceVorbisNative");
 
 	// midi common implementation
 	public static boolean	TraceMidiSystem = getBooleanProperty("TraceMidiSystem");
Index: kaffe/libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java
diff -u kaffe/libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java:1.1 kaffe/libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java:1.2
--- kaffe/libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java:1.1	Mon Jan  6 17:14:37 2003
+++ kaffe/libraries/javalib/org/tritonus/share/sampled/FloatSampleBuffer.java	Sun Sep 21 17:26:35 2003
@@ -299,8 +299,8 @@
 		// save format for automatic dithering mode
 		originalFormatType=formatType;
 		for (int ch=0; ch<format.getChannels(); ch++) {
-			convertByteToFloat(buffer, offset, sampleCount, getChannel(ch),
-			                   bytesPerFrame, formatType);
+			convertByteToFloat(buffer, offset, bytesPerFrame, formatType, 
+			                   getChannel(ch), 0, sampleCount);
 			offset+=bytesPerSample; // next channel
 		}
 	}
@@ -598,6 +598,35 @@
 			removeChannel(ch);
 		}
 	}
+	
+	public void setSamplesFromBytes(byte[] srcBuffer, int srcOffset, AudioFormat format, 
+	                                int destOffset, int lengthInSamples) {
+		int bytesPerSample = (format.getSampleSizeInBits() + 7)/8;
+		int bytesPerFrame = bytesPerSample * format.getChannels();
+		
+		if (srcOffset + (lengthInSamples * bytesPerFrame) > srcBuffer.length) {
+			throw new IllegalArgumentException
+			("FloatSampleBuffer.setSamplesFromBytes: srcBuffer too small.");
+		}
+		if (destOffset + lengthInSamples > getSampleCount()) {
+			throw new IllegalArgumentException
+			("FloatSampleBuffer.setSamplesFromBytes: destBuffer too small.");
+		}
+		boolean signed = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
+		boolean unsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
+		if (!signed && !unsigned) {
+			throw new IllegalArgumentException
+			("FloatSampleBuffer: only PCM samples are possible.");
+		}
+		int formatType = getFormatType(format.getSampleSizeInBits(),
+		                               signed, format.isBigEndian());
+
+		for (int ch = 0; ch < format.getChannels(); ch++) {
+			convertByteToFloat(srcBuffer, srcOffset, bytesPerFrame, formatType,
+			                   getChannel(ch), destOffset, lengthInSamples);
+			srcOffset += bytesPerSample; // next channel
+		}
+	}
 
 	//////////////////////////////// properties /////////////////////////////////
 
@@ -730,66 +759,66 @@
 	private static final float invTwoPower31=1/twoPower31;
 
 	/*public*/
-	private static void convertByteToFloat(byte[] input, int offset, int sampleCount,
-	                                       float[] output, int bytesPerFrame,
-	                                       int formatType) {
+	private static void convertByteToFloat(byte[] input, int inputOffset, int bytesPerFrame, int formatType,
+	                                       float[] output, int outputOffset, int sampleCount) {
 		//if (TDebug.TraceAudioConverter) {
 		//    TDebug.out("FloatSampleBuffer.convertByteToFloat, formatType="
 		//           +formatType2Str(formatType));
 		//}
 		int sample;
-		for (sample=0; sample<sampleCount; sample++) {
+		int endCount = outputOffset + sampleCount;
+		for (sample = outputOffset; sample < endCount; sample++) {
 			// do conversion
 			switch (formatType) {
 			case CT_8S:
 				output[sample]=
-				    ((float) input[offset])*invTwoPower7;
+				    ((float) input[inputOffset])*invTwoPower7;
 				break;
 			case CT_8U:
 				output[sample]=
-				    ((float) ((input[offset] & 0xFF)-128))*invTwoPower7;
+				    ((float) ((input[inputOffset] & 0xFF)-128))*invTwoPower7;
 				break;
 			case CT_16SB:
 				output[sample]=
-				    ((float) ((input[offset]<<8)
-				              | (input[offset+1] & 0xFF)))*invTwoPower15;
+				    ((float) ((input[inputOffset]<<8)
+				              | (input[inputOffset+1] & 0xFF)))*invTwoPower15;
 				break;
 			case CT_16SL:
 				output[sample]=
-				    ((float) ((input[offset+1]<<8)
-				              | (input[offset] & 0xFF)))*invTwoPower15;
+				    ((float) ((input[inputOffset+1]<<8)
+				              | (input[inputOffset] & 0xFF)))*invTwoPower15;
 				break;
 			case CT_24SB:
 				output[sample]=
-				    ((float) ((input[offset]<<16)
-				              | ((input[offset+1] & 0xFF)<<8)
-				              | (input[offset+2] & 0xFF)))*invTwoPower23;
+				    ((float) ((input[inputOffset]<<16)
+				              | ((input[inputOffset+1] & 0xFF)<<8)
+				              | (input[inputOffset+2] & 0xFF)))*invTwoPower23;
 				break;
 			case CT_24SL:
 				output[sample]=
-				    ((float) ((input[offset+2]<<16)
-				              | ((input[offset+1] & 0xFF)<<8)
-				              | (input[offset] & 0xFF)))*invTwoPower23;
+				    ((float) ((input[inputOffset+2]<<16)
+				              | ((input[inputOffset+1] & 0xFF)<<8)
+				              | (input[inputOffset] & 0xFF)))*invTwoPower23;
 				break;
 			case CT_32SB:
 				output[sample]=
-				    ((float) ((input[offset]<<24)
-				              | ((input[offset+1] & 0xFF)<<16)
-				              | ((input[offset+2] & 0xFF)<<8)
-				              | (input[offset+3] & 0xFF)))*invTwoPower31;
+				    ((float) ((input[inputOffset]<<24)
+				              | ((input[inputOffset+1] & 0xFF)<<16)
+				              | ((input[inputOffset+2] & 0xFF)<<8)
+				              | (input[inputOffset+3] & 0xFF)))*invTwoPower31;
 				break;
 			case CT_32SL:
 				output[sample]=
-				    ((float) ((input[offset+3]<<24)
-				              | ((input[offset+2] & 0xFF)<<16)
-				              | ((input[offset+1] & 0xFF)<<8)
-				              | (input[offset] & 0xFF)))*invTwoPower31;
+				    ((float) ((input[inputOffset+3]<<24)
+				              | ((input[inputOffset+2] & 0xFF)<<16)
+				              | ((input[inputOffset+1] & 0xFF)<<8)
+				              | (input[inputOffset] & 0xFF)))*invTwoPower31;
 				break;
 			default:
 				throw new IllegalArgumentException
 				("Unsupported formatType="+formatType);
 			}
-			offset+=bytesPerFrame;
+			inputOffset += bytesPerFrame;
 		}
 	}
 
Index: kaffe/libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java
diff -u kaffe/libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java:1.1 kaffe/libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java:1.2
--- kaffe/libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java:1.1	Mon Jan  6 17:14:37 2003
+++ kaffe/libraries/javalib/org/tritonus/share/sampled/TVolumeUtils.java	Sun Sep 21 17:26:35 2003
@@ -3,8 +3,7 @@
  */
 
 /*
- *  Copyright (c) 1999 by Matthias Pfisterer <Matthias.Pfisterer at gmx.de>
- *
+ *  Copyright (c) 1999 by Matthias Pfisterer <Matthias.Pfisterer at web.de>
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU Library General Public License as published
@@ -19,9 +18,7 @@
  *   You should have received a copy of the GNU Library General Public
  *   License along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
  */
-
 
 package	org.tritonus.share.sampled;
 
Index: kaffe/libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java
diff -u kaffe/libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java:1.2 kaffe/libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java:1.3
--- kaffe/libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java:1.2	Thu Feb  6 21:35:10 2003
+++ kaffe/libraries/javalib/org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java	Sun Sep 21 17:26:36 2003
@@ -36,39 +36,61 @@
 import	org.tritonus.share.TCircularBuffer;
 
 
-/**
- * Base class for asynchronus converters.
- *
- * @author Matthias Pfisterer
- */
+/** Base class for asynchronus converters.
+    This class serves as base class for
+    converters that do not have a fixed
+    ratio between the size of a block of input
+    data and the size of a block of output data.
+    These types of converters therefore need an
+    internal buffer, which is realized in this
+    class.
 
+    @author Matthias Pfisterer
+*/
 public abstract class TAsynchronousFilteredAudioInputStream
-	extends		AudioInputStream
-	implements	TCircularBuffer.Trigger
+	extends AudioInputStream
+	implements TCircularBuffer.Trigger
 {
-	private static int		DEFAULT_BUFFER_SIZE = 327670;
+	private static final int	DEFAULT_BUFFER_SIZE = 327670;
+	private static final int	DEFAULT_MIN_AVAILABLE = 4096;
 	private static final byte[]	EMPTY_BYTE_ARRAY = new byte[0];
 
-	// ausnahmsweise ;-)
-	protected TCircularBuffer	m_circularBuffer;
+
+	private TCircularBuffer		m_circularBuffer;
+	private int			m_nMinAvailable;
 	private byte[]			m_abSingleByte;
 
 
-	/**
-	 * @param lLength length of this stream in frames
-	 */
+
+	/** Constructor.
+	    This constructor uses the default buffer size and the default
+	    min available amount.
+
+	    @param lLength length of this stream in frames. May be
+	    AudioSystem.NOT_SPECIFIED.
+	*/
 	public TAsynchronousFilteredAudioInputStream(AudioFormat outputFormat, long lLength)
 	{
-		this(outputFormat, lLength, DEFAULT_BUFFER_SIZE);
+		this(outputFormat, lLength,
+		     DEFAULT_BUFFER_SIZE,
+		     DEFAULT_MIN_AVAILABLE);
 	}
 
 
 
-	/**
-	 * @param lLength length of this stream in frames
-	 * @param nBufferSize size of the circular buffer in bytes
+	/** Constructor.
+	    With this constructor, the buffer size and the minimum
+	    available amount can be specified as parameters.
+
+	    @param lLength length of this stream in frames. May be
+	    AudioSystem.NOT_SPECIFIED.
+
+	    @param nBufferSize size of the circular buffer in bytes.
 	 */
-	public TAsynchronousFilteredAudioInputStream(AudioFormat outputFormat, long lLength, int nBufferSize)
+	public TAsynchronousFilteredAudioInputStream(
+		AudioFormat outputFormat, long lLength,
+		int nBufferSize,
+		int nMinAvailable)
 	{
 		/*	The usage of a ByteArrayInputStream is a hack.
 		 *	(the infamous "JavaOne hack", because I did it on June
@@ -89,10 +111,37 @@
 			false,	// blocking read
 			true,	// blocking write
 			this);	// trigger
+		m_nMinAvailable = nMinAvailable;
 		if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.<init>(): end"); }
 	}
 
 
+	/** Returns the circular buffer.
+	 */
+	protected TCircularBuffer getCircularBuffer()
+	{
+		return m_circularBuffer;
+	}
+
+
+
+	/** Check if writing more data to the circular buffer is recommanded.
+	    This checks the available write space in the circular buffer
+	    against the minimum available property. If the available write
+	    space is greater than th minimum available property, more
+	    writing is encouraged, so this method returns true.
+	    Note that this is only a  hint to subclasses. However,
+	    it is an important hint.
+
+	    @return true if more writing to the circular buffer is
+	    recommanden. Otherwise, false is returned.
+	*/
+	protected boolean writeMore()
+	{
+		return getCircularBuffer().availableWrite() > m_nMinAvailable;
+	}
+
+
 
 	public int read()
 		throws	IOException
@@ -122,9 +171,9 @@
 	public int read(byte[] abData)
 		throws	IOException
 	{
-		// if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[]): begin"); }
+		if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[]): begin"); }
 		int	nRead = read(abData, 0, abData.length);
-		// if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[]): end"); }
+		if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[]): end"); }
 		return nRead;
 	}
 
@@ -133,12 +182,12 @@
 	public int read(byte[] abData, int nOffset, int nLength)
 		throws	IOException
 	{
-		// if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[], int, int): begin"); }
+		if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[], int, int): begin"); }
 		//$$fb 2001-04-22: this returns at maximum circular buffer
 		// length. This is not very efficient...
 		//$$fb 2001-04-25: we should check that we do not exceed getFrameLength() !
 		int	nRead = m_circularBuffer.read(abData, nOffset, nLength);
-		// if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[], int, int): end"); }
+		if (TDebug.TraceAudioConverter) { TDebug.out("TAsynchronousFilteredAudioInputStream.read(byte[], int, int): end"); }
 		return nRead;
 	}
 
Index: kaffe/libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java
diff -u kaffe/libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java:1.1 kaffe/libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java:1.2
--- kaffe/libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java:1.1	Mon Jan  6 17:14:38 2003
+++ kaffe/libraries/javalib/org/tritonus/share/sampled/file/TAudioFileWriter.java	Sun Sep 21 17:26:36 2003
@@ -98,8 +98,10 @@
 	protected TAudioFileWriter(Collection fileTypes,
 				   Collection audioFormats)
 	{
+		if (TDebug.TraceAudioFileWriter) { TDebug.out("TAudioFileWriter.<init>(): begin"); }
 		m_audioFileTypes = fileTypes;
 		m_audioFormats = audioFormats;
+		if (TDebug.TraceAudioFileWriter) { TDebug.out("TAudioFileWriter.<init>(): end"); }
 	}
 
 	// implementing the interface




More information about the kaffe mailing list