You can subscribe to this list here.
| 2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(14) |
Dec
(33) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2002 |
Jan
(68) |
Feb
(19) |
Mar
(6) |
Apr
(97) |
May
(15) |
Jun
(28) |
Jul
(83) |
Aug
(21) |
Sep
(67) |
Oct
(16) |
Nov
|
Dec
(22) |
| 2003 |
Jan
(47) |
Feb
(17) |
Mar
(5) |
Apr
|
May
(5) |
Jun
(106) |
Jul
(25) |
Aug
|
Sep
(14) |
Oct
(7) |
Nov
(24) |
Dec
(5) |
| 2004 |
Jan
(54) |
Feb
(19) |
Mar
|
Apr
(33) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(6) |
Nov
(153) |
Dec
(6) |
| 2005 |
Jan
(178) |
Feb
(17) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
(2) |
Feb
(173) |
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(12) |
Dec
(14) |
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
(29) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2008 |
Jan
(29) |
Feb
(3) |
Mar
(5) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
|
| 2009 |
Jan
|
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2013 |
Jan
(7) |
Feb
|
Mar
(18) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Florian B. <fl...@us...> - 2008-01-07 16:02:24
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23951/src/classes/org/tritonus/share/sampled Modified Files: AudioUtils.java Log Message: added frame aligned versions of millis2Bytes(), added millis2Frames(), bytes2Millis(), frames2Millis(), Java Sound Audio Dngine detection, linear2decibel(), decibel2linear() Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/AudioUtils.java Index: AudioUtils.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/AudioUtils.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** AudioUtils.java 3 Jun 2007 19:51:51 -0000 1.4 --- AudioUtils.java 7 Jan 2008 16:02:27 -0000 1.5 *************** *** 35,42 **** --- 35,44 ---- import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; + import javax.sound.sampled.DataLine; import javax.sound.sampled.Mixer; + @SuppressWarnings("cast") public class AudioUtils { *************** *** 83,86 **** --- 85,89 ---- + @SuppressWarnings("unchecked") public static boolean containsFormat(AudioFormat sourceFormat, Iterator possibleFormats) *************** *** 105,162 **** } ! /** ! * Conversion milliseconds -> bytes ! */ ! public static long millis2Bytes(long ms, AudioFormat format) { ! return millis2Bytes(ms, format.getFrameRate(), format.getFrameSize()); } ! public static long millis2Bytes(long ms, double frameRate, int frameSize) { return (long) (ms*frameRate/1000*frameSize); } ! public static long millis2Bytes(double ms, AudioFormat format) { return millis2Bytes(ms, format.getFrameRate(), format.getFrameSize()); } ! public static long millis2Bytes(double ms, double frameRate, int frameSize) { ! return ((long) (ms*frameRate/1000.0))*frameSize; } ! /** ! * Conversion milliseconds -> bytes (bytes will be frame-aligned) ! */ public static long millis2BytesFrameAligned(long ms, AudioFormat format) { ! return millis2BytesFrameAligned(ms, format.getFrameRate(), format.getFrameSize()); } ! ! public static long millis2BytesFrameAligned(long ms, float frameRate, int frameSize) { return ((long) (ms*frameRate/1000))*frameSize; } ! /** ! * Conversion milliseconds -> frames ! */ public static long millis2Frames(long ms, AudioFormat format) { ! return millis2Frames(ms, format.getFrameRate()); } ! ! public static long millis2Frames(long ms, float frameRate) { ! return (long) (ms*frameRate/1000); } ! /** ! * Conversion bytes -> milliseconds ! */ public static long bytes2Millis(long bytes, AudioFormat format) { ! return (long) (bytes/format.getFrameRate()*1000/format.getFrameSize()); } ! ! /** ! * Conversion frames -> milliseconds ! */ public static long frames2Millis(long frames, AudioFormat format) { ! return (long) (frames/format.getFrameRate()*1000); } --- 108,225 ---- } ! /** Conversion milliseconds to bytes */ public static long millis2Bytes(long ms, AudioFormat format) { ! return millis2Bytes(ms, (double) format.getFrameRate(), format.getFrameSize()); } ! /** Conversion milliseconds to bytes */ public static long millis2Bytes(long ms, double frameRate, int frameSize) { return (long) (ms*frameRate/1000*frameSize); } ! /** convert milliseconds to bytes. Be careful to not exceed the integer maximum value */ ! public static int millis2Bytes(int ms, AudioFormat format) { ! return millis2Bytes(ms, (double) format.getFrameRate(), format.getFrameSize()); ! } ! /** convert milliseconds to bytes. Be careful to not exceed the integer maximum value */ ! public static int millis2Bytes(int ms, double frameRate, int frameSize) { ! return (int) (ms*frameRate/1000*frameSize); ! } ! /** convert milliseconds to bytes. */ public static long millis2Bytes(double ms, AudioFormat format) { return millis2Bytes(ms, format.getFrameRate(), format.getFrameSize()); } ! /** convert milliseconds to bytes. */ public static long millis2Bytes(double ms, double frameRate, int frameSize) { ! return (long) (ms*frameRate/1000.0*frameSize); } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ public static long millis2BytesFrameAligned(long ms, AudioFormat format) { ! return millis2BytesFrameAligned(ms, (double) format.getFrameRate(), format.getFrameSize()); } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ ! public static long millis2BytesFrameAligned(long ms, double frameRate, int frameSize) { ! return ((long) (ms*frameRate/1000))*frameSize; ! } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ ! public static int millis2BytesFrameAligned(int ms, AudioFormat format) { ! return millis2BytesFrameAligned(ms, (double) format.getFrameRate(), format.getFrameSize()); ! } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ ! public static int millis2BytesFrameAligned(int ms, double frameRate, int frameSize) { ! return ((int) (ms*frameRate/1000))*frameSize; ! } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ ! public static long millis2BytesFrameAligned(double ms, AudioFormat format) { ! return millis2BytesFrameAligned(ms, (double) format.getFrameRate(), format.getFrameSize()); ! } ! /** Conversion milliseconds to bytes, return value is frame-aligned */ ! public static long millis2BytesFrameAligned(double ms, double frameRate, int frameSize) { return ((long) (ms*frameRate/1000))*frameSize; } ! /** Conversion milliseconds to frames (samples) */ public static long millis2Frames(long ms, AudioFormat format) { ! return millis2Frames(ms, (double) format.getFrameRate()); } ! /** Conversion milliseconds to frames (samples) */ ! public static long millis2Frames(long ms, double frameRate) { ! return (long) (ms*frameRate/1000.0); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static int millis2Frames(int ms, AudioFormat format) { ! return millis2Frames(ms, (double) format.getFrameRate()); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static int millis2Frames(int ms, double frameRate) { ! return (int) (ms*frameRate/1000.0); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static long millis2Frames(double ms, AudioFormat format) { ! return (long) millis2FramesD(ms, (double) format.getFrameRate()); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static long millis2Frames(double ms, double frameRate) { ! return (long) millis2FramesD(ms, frameRate); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static double millis2FramesD(double ms, AudioFormat format) { ! return millis2FramesD(ms, (double) format.getFrameRate()); ! } ! /** Conversion milliseconds to frames (samples) */ ! public static double millis2FramesD(double ms, double frameRate) { ! return ms*frameRate/1000.0; } ! /** Conversion bytes to milliseconds */ public static long bytes2Millis(long bytes, AudioFormat format) { ! return (long) frames2MillisD(bytes/format.getFrameSize(), format.getFrameRate()); } ! /** Conversion bytes to milliseconds */ ! public static int bytes2Millis(int bytes, AudioFormat format) { ! return (int) frames2MillisD(bytes/format.getFrameSize(), format.getFrameRate()); ! } ! /** Conversion bytes to milliseconds */ ! public static double bytes2MillisD(long bytes, AudioFormat format) { ! return frames2MillisD(bytes/format.getFrameSize(), format.getFrameRate()); ! } ! /** Conversion bytes to milliseconds */ ! public static double bytes2MillisD(long bytes, double frameRate, int frameSize) { ! return frames2MillisD(bytes/frameSize, frameRate); ! } ! /** Conversion frames to milliseconds */ public static long frames2Millis(long frames, AudioFormat format) { ! return (long) frames2MillisD(frames, format.getFrameRate()); ! } ! /** Conversion frames to milliseconds */ ! public static int frames2Millis(int frames, AudioFormat format) { ! return (int) frames2MillisD(frames, format.getFrameRate()); ! } ! /** Conversion frames to milliseconds */ ! public static double frames2MillisD(long frames, AudioFormat format) { ! return frames2MillisD(frames, format.getFrameRate()); ! } ! /** Conversion frames to milliseconds */ ! public static double frames2MillisD(long frames, double frameRate) { ! return frames/frameRate*1000.0; } *************** *** 182,195 **** /** * Return if the passed mixer info is the Java Sound Audio Engine. * @param mixerInfo the mixer info to query * @return true if the mixer info describes the Java Sound Audio Engine */ public static boolean isJavaSoundAudioEngine(Mixer.Info mixerInfo) { ! return mixerInfo.getName().equals("Java Sound Audio Engine"); } /** * tries to guess if this program is running on a big endian platform ! * @return */ public static boolean isSystemBigEndian() { --- 245,276 ---- /** * Return if the passed mixer info is the Java Sound Audio Engine. + * * @param mixerInfo the mixer info to query * @return true if the mixer info describes the Java Sound Audio Engine */ public static boolean isJavaSoundAudioEngine(Mixer.Info mixerInfo) { ! return (mixerInfo != null) && (mixerInfo.getName() != null) ! && mixerInfo.getName().equals("Java Sound Audio Engine"); } /** + * Return if the passed line is writing to or reading from the Java Sound Audio Engine. + * + * @param line the data line to query + * @return true if the line is using the Java Sound Audio Engine + */ + public static boolean isJavaSoundAudioEngine(DataLine line) { + if (line != null) { + String clazz = line.getClass().toString(); + return clazz.indexOf("MixerSourceLine") >= 0 + || clazz.indexOf("MixerClip") >= 0 + || clazz.indexOf("SimpleInputDevice") >= 0; + } + return false; + } + + /** * tries to guess if this program is running on a big endian platform ! * @return true if the system's native endianness is big endian */ public static boolean isSystemBigEndian() { *************** *** 215,219 **** NS_or_number(((int)format.getSampleRate())) + "Hz-"+ (format.isBigEndian() ? "be" : "le"); ! } } --- 296,339 ---- NS_or_number(((int)format.getSampleRate())) + "Hz-"+ (format.isBigEndian() ? "be" : "le"); ! } ! ! /** ! * The value used for negative infinity in decibels. The default value is ! * -100.0, which is approximately the s/n ratio achieved with 16-bit samples. ! * If you use higher resolution, set this to a lower value, like -150.0. ! */ ! public static double SILENCE_DECIBEL = -100.0; ! ! /** ! * Get decibel from a linear factor. ! * ! * @param linearFactor 0..1..inf ! * @return the converted decibel (SILENCE_DECIBEL...0...inf) ! */ ! public final static double linear2decibel(double linearFactor) { ! if (linearFactor <= 0.0) { ! return SILENCE_DECIBEL; ! } ! double ret = Math.log10(linearFactor) * 20.0; ! if (ret < SILENCE_DECIBEL) { ! ret = SILENCE_DECIBEL; ! } ! return ret; ! } ! ! /** ! * Calculate the linear factor corresponding to the specified decibel level. ! * ! * @param decibels [SILENCE_DECIBEL...0...inf] ! * @return linear factor [0...1...inf] ! */ ! public final static double decibel2linear(double decibels) { ! if (decibels <= SILENCE_DECIBEL) { ! return 0.0; ! } ! return Math.pow(10.0, decibels * 0.05); ! } ! ! } |
|
From: Florian B. <fl...@us...> - 2008-01-07 15:59:39
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22495/src/classes/org/tritonus/share/sampled Modified Files: FloatSampleBuffer.java Log Message: added writeByteBuffer(), linearFade(), and overloaded versions of copyChannel(), mix(), copyTo() Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatSampleBuffer.java Index: FloatSampleBuffer.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatSampleBuffer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** FloatSampleBuffer.java 18 Jun 2007 14:41:20 -0000 1.8 --- FloatSampleBuffer.java 7 Jan 2008 15:59:42 -0000 1.9 *************** *** 358,361 **** --- 358,403 ---- } } + + /** + * Write the contents of the byte array to this buffer, overwriting existing + * data. If the byte array has fewer channels than this float buffer, only + * the first channels are written. Vice versa, if the byte buffer has more + * channels than this float buffer, only the first channels of the byte + * buffer are written to this buffer. + * <p> + * The format and the number of samples of this float buffer are not + * changed, so if the byte array has more samples than fit into this float + * buffer, it is not expanded. + * + * @param buffer the byte buffer to write to this float buffer + * @param srcByteOffset the offset in bytes in buffer where to start reading + * @param format the audio format of the bytes in buffer + * @param dstSampleOffset the offset in samples where to start writing the + * converted float data into this float buffer + * @param aSampleCount the number of samples to write + * @return the number of samples actually written + */ + public int writeByteBuffer(byte[] buffer, int srcByteOffset, + AudioFormat format, int dstSampleOffset, int aSampleCount) { + if (dstSampleOffset + aSampleCount > getSampleCount()) { + aSampleCount = getSampleCount() - dstSampleOffset; + } + int lChannels = format.getChannels(); + if (lChannels > getChannelCount()) { + lChannels = getChannelCount(); + } + if (lChannels > format.getChannels()) { + lChannels = format.getChannels(); + } + for (int channel = 0; channel < lChannels; channel++) { + float[] data = getChannel(channel); + + FloatSampleTools.byte2floatGeneric(buffer, srcByteOffset, + format.getFrameSize(), data, dstSampleOffset, aSampleCount, + format); + srcByteOffset += format.getFrameSize() / format.getChannels(); + } + return aSampleCount; + } /** *************** *** 598,602 **** --- 640,701 ---- } } + + /** + * Fade the volume level of this buffer from the given start volume to the end volume. + * E.g. to implement a fade in, use startVol=0 and endVol=1. + * + * @param startVol the start volume as a linear factor [0..1] + * @param endVol the end volume as a linear factor [0..1] + */ + public void linearFade(float startVol, float endVol) { + linearFade(startVol, endVol, 0, getSampleCount()); + } + /** + * Fade the volume level of this buffer from the given start volume to the end volume. + * The fade will start at the offset, and will have reached endVol after count samples. + * E.g. to implement a fade in, use startVol=0 and endVol=1. + * + * @param startVol the start volume as a linear factor [0..1] + * @param endVol the end volume as a linear factor [0..1] + * @param offset the offset in this buffer where to start the fade (in samples) + * @param count the number of samples to fade + */ + public void linearFade(float startVol, float endVol, int offset, int count) { + for (int channel = 0; channel < getChannelCount(); channel++) { + linearFade(channel, startVol, endVol, offset, count); + } + } + + /** + * Fade the volume level of the specified channel from the given start volume to + * the end volume. + * The fade will start at the offset, and will have reached endVol after count + * samples. + * E.g. to implement a fade in, use startVol=0 and endVol=1. + * + * @param channel the channel to do the fade + * @param startVol the start volume as a linear factor [0..1] + * @param endVol the end volume as a linear factor [0..1] + * @param offset the offset in this buffer where to start the fade (in samples) + * @param count the number of samples to fade + */ + public void linearFade(int channel, float startVol, float endVol, int offset, int count) { + if (count <= 0) return; + float end = count+offset; + float inc = (endVol - startVol) / count; + float[] samples = getChannel(channel); + float curr = startVol; + for (int i = offset; i < end; i++) { + samples[i] *= curr; + curr += inc; + } + } + + /** + * Add a channel to this buffer, e.g. adding a channel to a mono buffer will make it a stereo buffer. + * + * @param silent if true, the channel is explicitly silenced. Otherwise the new channel may contain random data. + */ public void addChannel(boolean silent) { // creates new, silent channel *************** *** 686,691 **** /** ! * both source and target channel have to exist. targetChannel will be ! * overwritten */ public void copyChannel(int sourceChannel, int targetChannel) { --- 785,791 ---- /** ! * Copy sourceChannel's audio data to targetChannel, identified by their ! * indices in the channel list. Both source and target channel have to ! * exist. targetChannel will be overwritten */ public void copyChannel(int sourceChannel, int targetChannel) { *************** *** 696,699 **** --- 796,813 ---- /** + * Copy sampleCount samples from sourceChannel at position srcOffset to + * targetChannel at position targetOffset. sourceChannel and targetChannel + * are indices in the channel list. Both source and target channel have to + * exist. targetChannel will be overwritten + */ + public void copyChannel(int sourceChannel, int sourceOffset, + int targetChannel, int targetOffset, int aSampleCount) { + float[] source = getChannel(sourceChannel); + float[] target = getChannel(targetChannel); + System.arraycopy(source, sourceOffset, target, targetOffset, + aSampleCount); + } + + /** * Copies data inside all channel. When the 2 regions overlap, the behavior * is not specified. *************** *** 761,765 **** /** ! * Mixes <code>buffer</code> to this buffer by adding all samples. At * most, <code>source</code>'s number of samples, number of channels are * mixed. None of the sample count, channel count or sample rate of either --- 875,879 ---- /** ! * Mixes <code>source</code> to this buffer by adding all samples. At * most, <code>source</code>'s number of samples, number of channels are * mixed. None of the sample count, channel count or sample rate of either *************** *** 788,791 **** --- 902,931 ---- /** + * Mixes <code>source</code> samples to this buffer by adding the sample values. + * None of the sample count, channel count or sample rate of either + * buffer are changed. In particular, the caller needs to assure that the + * sample rate of the buffers match. + * <p> + * This method is not error tolerant, in particular, runtime exceptions + * will be thrown if the channel counts do not match, or if the + * offsets and count exceed the buffer's capacity. + * + * @param source the source buffer from where to take samples and mix to this one + * @param sourceOffset offset in source where to start reading samples + * @param thisOffset offset in this buffer from where to start mixing samples + * @param count number of samples to mix + */ + public void mix(FloatSampleBuffer source, int sourceOffset, int thisOffset, int count) { + int localChannelCount = getChannelCount(); + for (int ch = 0; ch < localChannelCount; ch++) { + float[] thisChannel = getChannel(ch); + float[] otherChannel = source.getChannel(ch); + for (int i = 0; i < count; i++) { + thisChannel[i+thisOffset] += otherChannel[i+sourceOffset]; + } + } + } + + /** * Copies the contents of this buffer to the destination buffer at the * destOffset. At most, <code>dest</code>'s number of samples, number of *************** *** 798,805 **** * writing the samples of this buffer * @param count the number of samples to be copied */ ! public void copyTo(FloatSampleBuffer dest, int destOffset, int count) { ! if (count > getSampleCount()) { ! count = getSampleCount(); } if (count + destOffset > dest.getSampleCount()) { --- 938,964 ---- * writing the samples of this buffer * @param count the number of samples to be copied + * @return the number of samples copied + */ + public int copyTo(FloatSampleBuffer dest, int destOffset, int count) { + return copyTo(0, dest, destOffset, count); + } + + /** + * Copies the specified part of this buffer to the destination buffer. + * At most, <code>dest</code>'s number of samples, number of + * channels are copied. None of the sample count, channel count or sample + * rate of either buffer are changed. In particular, the caller needs to + * assure that the sample rate of the buffers match. + * + * @param srcOffset the start position in this buffer, where to start reading samples + * @param dest the buffer to write to + * @param destOffset the position in <code>dest</code> where to start + * writing the samples + * @param count the number of samples to be copied + * @return the number of samples copied */ ! public int copyTo(int srcOffset, FloatSampleBuffer dest, int destOffset, int count) { ! if (srcOffset + count > getSampleCount()) { ! count = getSampleCount() - srcOffset; } if (count + destOffset > dest.getSampleCount()) { *************** *** 811,817 **** } for (int ch = 0; ch < localChannelCount; ch++) { ! System.arraycopy(getChannel(ch), 0, dest.getChannel(ch), destOffset, count); } } --- 970,977 ---- } for (int ch = 0; ch < localChannelCount; ch++) { ! System.arraycopy(getChannel(ch), srcOffset, dest.getChannel(ch), destOffset, count); } + return count; } *************** *** 890,894 **** * @param keepOldSamples if true, the new buffer will keep the current * samples in the arrays ! * @see #changeSampleCount(int, boolean)ngeSampleCount(int, boolean) */ public void setSampleCount(int newSampleCount, boolean keepOldSamples) { --- 1050,1054 ---- * @param keepOldSamples if true, the new buffer will keep the current * samples in the arrays ! * @see #changeSampleCount(int, boolean) */ public void setSampleCount(int newSampleCount, boolean keepOldSamples) { |
|
From: Florian B. <fl...@us...> - 2008-01-07 15:58:08
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22051/src/classes/org/tritonus/share/sampled Modified Files: FloatInputStream.java Log Message: improve multithread operation by using local references Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java Index: FloatInputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** FloatInputStream.java 18 Jun 2007 14:41:20 -0000 1.4 --- FloatInputStream.java 7 Jan 2008 15:58:11 -0000 1.5 *************** *** 146,151 **** int byteBufferSize = buffer.getSampleCount() * getFormat().getFrameSize(); ! if (tempBuffer == null || byteBufferSize > tempBuffer.length) { ! tempBuffer = new byte[byteBufferSize]; } int readSamples = 0; --- 146,153 ---- int byteBufferSize = buffer.getSampleCount() * getFormat().getFrameSize(); ! byte[] lTempBuffer = tempBuffer; ! if (lTempBuffer == null || byteBufferSize > lTempBuffer.length) { ! lTempBuffer = new byte[byteBufferSize]; ! tempBuffer = lTempBuffer; } int readSamples = 0; *************** *** 154,158 **** int readBytes; try { ! readBytes = sourceStream.read(tempBuffer, byteOffset, byteBufferSize); } catch (IOException ioe) { --- 156,160 ---- int readBytes; try { ! readBytes = sourceStream.read(lTempBuffer, byteOffset, byteBufferSize); } catch (IOException ioe) { *************** *** 174,178 **** if (readSamples > 0) { // convert ! buffer.setSamplesFromBytes(tempBuffer, 0, getFormat(), offset, readSamples); } --- 176,180 ---- if (readSamples > 0) { // convert ! buffer.setSamplesFromBytes(lTempBuffer, 0, getFormat(), offset, readSamples); } *************** *** 212,215 **** --- 214,218 ---- // interface AudioInputStream + @Override public int read() throws IOException { if (getFormat().getFrameSize() != 1) { *************** *** 228,231 **** --- 231,235 ---- * @see #read(byte[], int, int) */ + @Override public int read(byte[] abData) throws IOException { return read(abData, 0, abData.length); *************** *** 238,241 **** --- 242,246 ---- * from an underlying FloatSampleInput stream and convert to a byte array. */ + @Override public int read(byte[] abData, int nOffset, int nLength) throws IOException { if (isDone()) { *************** *** 267,285 **** * Precondition: sourceInput!=null * ! * @param abData: the byte array to fill, or null if just skipping */ protected int readBytesFromFloatInput(byte[] abData, int nOffset, int nLength) throws IOException { ! if (sourceInput.isDone()) { return -1; } int frameCount = nLength / getFormat().getFrameSize(); ! if (tempFloatBuffer == null) { ! tempFloatBuffer = new FloatSampleBuffer(getFormat().getChannels(), frameCount, getFormat().getSampleRate()); } else { ! tempFloatBuffer.setSampleCount(frameCount, false); } - sourceInput.read(tempFloatBuffer); if (abData != null) { int writtenBytes = tempFloatBuffer.convertToByteArray(abData, --- 272,296 ---- * Precondition: sourceInput!=null * ! * @param abData the byte array to fill, or null if just skipping */ protected int readBytesFromFloatInput(byte[] abData, int nOffset, int nLength) throws IOException { ! FloatSampleInput lInput = sourceInput; ! if (lInput.isDone()) { return -1; } int frameCount = nLength / getFormat().getFrameSize(); ! FloatSampleBuffer lTempBuffer = tempFloatBuffer; ! if (lTempBuffer == null) { ! lTempBuffer = new FloatSampleBuffer(getFormat().getChannels(), frameCount, getFormat().getSampleRate()); + tempFloatBuffer = lTempBuffer; } else { ! lTempBuffer.setSampleCount(frameCount, false); ! } ! lInput.read(lTempBuffer); ! if (lInput.isDone()) { ! return -1; } if (abData != null) { int writtenBytes = tempFloatBuffer.convertToByteArray(abData, *************** *** 291,294 **** --- 302,306 ---- } + @Override public synchronized long skip(long nSkip) throws IOException { // only returns integral frames *************** *** 307,310 **** --- 319,323 ---- } + @Override public int available() throws IOException { if (sourceStream != null) { *************** *** 314,317 **** --- 327,331 ---- } + @Override public void mark(int readlimit) { if (sourceStream != null) { *************** *** 322,325 **** --- 336,340 ---- } + @Override public void reset() throws IOException { if (sourceStream != null) { *************** *** 330,333 **** --- 345,349 ---- } + @Override public boolean markSupported() { if (sourceStream != null) { *************** *** 337,340 **** --- 353,357 ---- } + @Override public void close() throws IOException { if (eofReached) { |
|
From: Florian B. <fl...@us...> - 2007-06-18 14:41:25
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9652/src/classes/org/tritonus/share/sampled Modified Files: FloatInputStream.java FloatSampleBuffer.java Log Message: formatted Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatSampleBuffer.java Index: FloatInputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** FloatInputStream.java 18 Jun 2007 14:13:02 -0000 1.3 --- FloatInputStream.java 18 Jun 2007 14:41:20 -0000 1.4 *************** *** 244,253 **** // read from sourceStream, if available if (sourceStream != null) { ! return readBytesFromInputStream(abData, nOffset,nLength); } // otherwise read from sourceInput ! return readBytesFromFloatInput(abData, nOffset,nLength); } ! /** * internal method to read from the underlying InputStream.<br> --- 244,253 ---- // read from sourceStream, if available if (sourceStream != null) { ! return readBytesFromInputStream(abData, nOffset, nLength); } // otherwise read from sourceInput ! return readBytesFromFloatInput(abData, nOffset, nLength); } ! /** * internal method to read from the underlying InputStream.<br> *************** *** 262,272 **** return readBytes; } ! /** * internal method to read from the underlying InputStream.<br> * Precondition: sourceInput!=null * @param abData: the byte array to fill, or null if just skipping */ ! protected int readBytesFromFloatInput(byte[] abData, int nOffset, int nLength) throws IOException { if (sourceInput.isDone()) { return -1; --- 262,274 ---- return readBytes; } ! /** * internal method to read from the underlying InputStream.<br> * Precondition: sourceInput!=null + * * @param abData: the byte array to fill, or null if just skipping */ ! protected int readBytesFromFloatInput(byte[] abData, int nOffset, ! int nLength) throws IOException { if (sourceInput.isDone()) { return -1; Index: FloatSampleBuffer.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatSampleBuffer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** FloatSampleBuffer.java 29 Nov 2006 12:34:18 -0000 1.7 --- FloatSampleBuffer.java 18 Jun 2007 14:41:20 -0000 1.8 *************** *** 1,994 **** ! /* ! * FloatSampleBuffer.java ! * ! * This file is part of Tritonus: http://www.tritonus.org/ ! */ ! ! /* ! * Copyright (c) 2000-2006 by Florian Bomers <http://www.bomers.de> ! * ! * This program is free software; you can redistribute it and/or modify [...1960 lines suppressed...] ! /** ! * @return the ditherBits parameter for the float2byte functions ! */ ! protected float getConvertDitherBits(int newFormatType) { ! // let's see whether dithering is necessary ! boolean doDither = false; ! switch (ditherMode) { ! case DITHER_MODE_AUTOMATIC: ! doDither = (originalFormatType & FloatSampleTools.F_SAMPLE_WIDTH_MASK) > (newFormatType & FloatSampleTools.F_SAMPLE_WIDTH_MASK); ! break; ! case DITHER_MODE_ON: ! doDither = true; ! break; ! case DITHER_MODE_OFF: ! doDither = false; ! break; ! } ! return doDither ? ditherBits : 0.0f; ! } ! } |
|
From: Florian B. <fl...@us...> - 2007-06-18 14:13:49
|
Update of /cvsroot/tritonus/tritonus/test/floatbuffer In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29567/test/floatbuffer Added Files: ConvertBackForth.java Log Message: simple test to assert that the buffer can convert and back and get the same byte array size Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/test/floatbuffer/ConvertBackForth.java --- NEW FILE: ConvertBackForth.java --- |
|
From: Florian B. <fl...@us...> - 2007-06-18 14:13:44
|
Update of /cvsroot/tritonus/tritonus/test/floatbuffer In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29553/test/floatbuffer Log Message: Directory /cvsroot/tritonus/tritonus/test/floatbuffer added to the repository Direct links to online-CVS: |
|
From: Florian B. <fl...@us...> - 2007-06-18 14:13:02
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv29153/src/classes/org/tritonus/share/sampled Modified Files: FloatInputStream.java Log Message: always do a readFully on the underlying input stream Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java Index: FloatInputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/FloatInputStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** FloatInputStream.java 14 Dec 2006 21:47:16 -0000 1.2 --- FloatInputStream.java 18 Jun 2007 14:13:02 -0000 1.3 *************** *** 149,164 **** tempBuffer = new byte[byteBufferSize]; } ! int readBytes; ! try { ! readBytes = sourceStream.read(tempBuffer, 0, byteBufferSize); ! } catch (IOException ioe) { ! readBytes = -1; } ! if (readBytes < 0) { ! eofReached = true; ! readBytes = 0; ! } ! int readSamples = readBytes / getFormat().getFrameSize(); ! buffer.setSampleCount(offset + readSamples, true); if (readSamples > 0) { // convert --- 149,175 ---- tempBuffer = new byte[byteBufferSize]; } ! int readSamples = 0; ! int byteOffset = 0; ! while (readSamples < sampleCount) { ! int readBytes; ! try { ! readBytes = sourceStream.read(tempBuffer, byteOffset, ! byteBufferSize); ! } catch (IOException ioe) { ! readBytes = -1; ! } ! if (readBytes < 0) { ! eofReached = true; ! readBytes = 0; ! break; ! } else if (readBytes == 0) { ! Thread.yield(); ! } else { ! readSamples += readBytes / getFormat().getFrameSize(); ! byteBufferSize -= readBytes; ! byteOffset += readBytes; ! } } ! buffer.setSampleCount(offset + readSamples, (offset > 0)); if (readSamples > 0) { // convert |
|
From: Florian B. <fl...@us...> - 2007-06-03 22:13:23
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv20392/src/classes/org/tritonus/sampled/convert Removed Files: UlawFormatConversionProvider.java AlawFormatConversionProvider.java Log Message: alaw/ulaw codecs superceded by LawDecoder and LawEncoder Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/UlawFormatConversionProvider.java http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/AlawFormatConversionProvider.java --- UlawFormatConversionProvider.java DELETED --- --- AlawFormatConversionProvider.java DELETED --- |
|
From: Florian B. <fl...@us...> - 2007-06-03 22:10:01
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18661/src/classes/org/tritonus/sampled/file Modified Files: WaveTool.java AiffTool.java AuTool.java Log Message: support for auto endian and sign conversion Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/WaveTool.java http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffTool.java http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuTool.java Index: WaveTool.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/WaveTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** WaveTool.java 13 Feb 2006 12:21:50 -0000 1.2 --- WaveTool.java 3 Jun 2007 22:10:00 -0000 1.3 *************** *** 77,108 **** public static short getFormatCode(AudioFormat format) { AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); ! boolean littleEndian = !format.isBigEndian(); ! boolean frameSizeOK=format.getFrameSize()==AudioSystem.NOT_SPECIFIED ! || format.getChannels()!=AudioSystem.NOT_SPECIFIED ! || format.getFrameSize()==nSampleSize/8*format.getChannels(); ! ! if (nSampleSize==8 && frameSizeOK ! && (encoding.equals(AudioFormat.Encoding.PCM_SIGNED) ! || encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED))) { ! return WAVE_FORMAT_PCM; ! } else if (nSampleSize>8 && frameSizeOK && littleEndian ! && encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) { return WAVE_FORMAT_PCM; } else if (encoding.equals(AudioFormat.Encoding.ULAW) ! && (nSampleSize==AudioSystem.NOT_SPECIFIED || nSampleSize == 8) ! && frameSizeOK) { return WAVE_FORMAT_ULAW; } else if (encoding.equals(AudioFormat.Encoding.ALAW) ! && (nSampleSize==AudioSystem.NOT_SPECIFIED || nSampleSize == 8) ! && frameSizeOK) { return WAVE_FORMAT_ALAW; } else if (encoding.equals(new AudioFormat.Encoding("IMA_ADPCM")) ! && nSampleSize == 4) ! { return WAVE_FORMAT_IMA_ADPCM; ! } ! else if (encoding.equals(GSM0610)) { return WAVE_FORMAT_GSM610; } --- 77,108 ---- public static short getFormatCode(AudioFormat format) { + // endianness is converted in audio output stream + // sign is converted for 8-bit files AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); ! boolean frameSizeOK = format.getFrameSize() == AudioSystem.NOT_SPECIFIED ! || format.getChannels() != AudioSystem.NOT_SPECIFIED ! || format.getFrameSize() == (nSampleSize + 7) / 8 ! * format.getChannels(); ! boolean signed = encoding.equals(AudioFormat.Encoding.PCM_SIGNED); ! boolean unsigned = encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED); ! if (nSampleSize == 8 && frameSizeOK && (signed || unsigned)) { ! // support signed and unsigned PCM for 8 bit ! return WAVE_FORMAT_PCM; ! } else if (nSampleSize > 8 && nSampleSize <= 32 && frameSizeOK && signed) { ! // support only signed PCM for > 8 bit return WAVE_FORMAT_PCM; } else if (encoding.equals(AudioFormat.Encoding.ULAW) ! && (nSampleSize == AudioSystem.NOT_SPECIFIED || nSampleSize == 8) ! && frameSizeOK) { return WAVE_FORMAT_ULAW; } else if (encoding.equals(AudioFormat.Encoding.ALAW) ! && (nSampleSize == AudioSystem.NOT_SPECIFIED || nSampleSize == 8) ! && frameSizeOK) { return WAVE_FORMAT_ALAW; } else if (encoding.equals(new AudioFormat.Encoding("IMA_ADPCM")) ! && nSampleSize == 4) { return WAVE_FORMAT_IMA_ADPCM; ! } else if (encoding.equals(GSM0610)) { return WAVE_FORMAT_GSM610; } *************** *** 112,114 **** } ! /*** WaveTool.java ***/ --- 112,114 ---- } ! /** * WaveTool.java ** */ Index: AiffTool.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AiffTool.java 13 Feb 2006 12:21:50 -0000 1.2 --- AiffTool.java 3 Jun 2007 22:10:00 -0000 1.3 *************** *** 56,70 **** public static int getFormatCode(AudioFormat format) { AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); - boolean bigEndian = format.isBigEndian(); // $$fb 2000-08-16: check the frame size, too. boolean frameSizeOK=format.getFrameSize()==AudioSystem.NOT_SPECIFIED || format.getChannels()!=AudioSystem.NOT_SPECIFIED || format.getFrameSize()==nSampleSize/8*format.getChannels(); ! ! if ((encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) ! && ((bigEndian && nSampleSize>=16 && nSampleSize<=32) || (nSampleSize==8)) ! && frameSizeOK) { return AIFF_COMM_PCM; } else if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) { --- 56,74 ---- public static int getFormatCode(AudioFormat format) { + // endianness is converted in audio output stream + // sign is converted for 8-bit files AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); // $$fb 2000-08-16: check the frame size, too. boolean frameSizeOK=format.getFrameSize()==AudioSystem.NOT_SPECIFIED || format.getChannels()!=AudioSystem.NOT_SPECIFIED || format.getFrameSize()==nSampleSize/8*format.getChannels(); ! boolean signed = encoding.equals(AudioFormat.Encoding.PCM_SIGNED); ! boolean unsigned = encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED); ! if (nSampleSize == 8 && frameSizeOK && (signed || unsigned)) { ! // support signed and unsigned PCM for 8 bit ! return AIFF_COMM_PCM; ! } else if (nSampleSize > 8 && nSampleSize <= 32 && frameSizeOK && signed) { ! // support only signed PCM for > 8 bit return AIFF_COMM_PCM; } else if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) { Index: AuTool.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AuTool.java 13 Feb 2006 12:21:50 -0000 1.2 --- AuTool.java 3 Jun 2007 22:10:00 -0000 1.3 *************** *** 63,86 **** public static int getFormatCode(AudioFormat format) { AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); - // must be big endian for >8 bit formats - boolean bigEndian = format.isBigEndian(); // $$fb 2000-08-16: check the frame size, too. ! boolean frameSizeOK=( ! format.getFrameSize()==AudioSystem.NOT_SPECIFIED || format.getChannels()!=AudioSystem.NOT_SPECIFIED || format.getFrameSize()==nSampleSize/8*format.getChannels()); if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) { return SND_FORMAT_MULAW_8; ! } else if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED) && frameSizeOK) { ! if (nSampleSize == 8) { ! return SND_FORMAT_LINEAR_8; ! } else if (nSampleSize == 16 && bigEndian) { return SND_FORMAT_LINEAR_16; ! } else if (nSampleSize == 24 && bigEndian) { return SND_FORMAT_LINEAR_24; ! } else if (nSampleSize == 32 && bigEndian) { return SND_FORMAT_LINEAR_32; } --- 63,89 ---- public static int getFormatCode(AudioFormat format) { + // endianness is converted in audio output stream + // sign is converted for 8-bit files AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); // $$fb 2000-08-16: check the frame size, too. ! boolean frameSizeOK=(format.getFrameSize()==AudioSystem.NOT_SPECIFIED || format.getChannels()!=AudioSystem.NOT_SPECIFIED || format.getFrameSize()==nSampleSize/8*format.getChannels()); + boolean signed = encoding.equals(AudioFormat.Encoding.PCM_SIGNED); + boolean unsigned = encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED); if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) { return SND_FORMAT_MULAW_8; ! } else if (nSampleSize == 8 && frameSizeOK && (signed || unsigned)) { ! // support signed and unsigned PCM for 8 bit ! return SND_FORMAT_LINEAR_8; ! } else if (signed && frameSizeOK) { ! // support only signed PCM for > 8 bit ! if (nSampleSize == 16) { return SND_FORMAT_LINEAR_16; ! } else if (nSampleSize == 24) { return SND_FORMAT_LINEAR_24; ! } else if (nSampleSize == 32) { return SND_FORMAT_LINEAR_32; } |
|
From: Florian B. <fl...@us...> - 2007-06-03 22:08:26
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18195/src/classes/org/tritonus/sampled/convert Modified Files: SampleRateConversionProvider.java Log Message: fixed wrong format for byte buffer size calculation improved debugging Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/SampleRateConversionProvider.java Index: SampleRateConversionProvider.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/SampleRateConversionProvider.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** SampleRateConversionProvider.java 3 Jun 2007 19:43:17 -0000 1.7 --- SampleRateConversionProvider.java 3 Jun 2007 22:08:25 -0000 1.8 *************** *** 113,117 **** && targetFormat.getSampleSizeInBits()!=AudioSystem.NOT_SPECIFIED && sourceFormat.getSampleSizeInBits()!=AudioSystem.NOT_SPECIFIED ! && isConversionSupported(sourceFormat, targetFormat)) { return new SampleRateConverterStream(sourceStream, targetFormat); } --- 113,117 ---- && targetFormat.getSampleSizeInBits()!=AudioSystem.NOT_SPECIFIED && sourceFormat.getSampleSizeInBits()!=AudioSystem.NOT_SPECIFIED ! && isConversionSupported(targetFormat, sourceFormat)) { return new SampleRateConverterStream(sourceStream, targetFormat); } *************** *** 362,365 **** --- 362,368 ---- // TODO: retain last samples and adjust dPos thisBuffer.changeSampleCount(bufferSize, true); + if (TDebug.TraceAudioConverter && DEBUG_STREAM) { + TDebug.out("Initialized thisBuffer and historyBuffer with "+bufferSize+" samples"); + } } *************** *** 371,377 **** */ private void readFromByteSourceStream() { ! int byteCount=thisBuffer.getByteArrayBufferSize(getFormat()); ! if (byteBuffer==null || byteBuffer.length<byteCount) { ! byteBuffer=new byte[byteCount]; } // finally read it --- 374,386 ---- */ private void readFromByteSourceStream() { ! int byteCount = thisBuffer.getByteArrayBufferSize(sourceStream.getFormat()); ! if (byteBuffer == null || byteBuffer.length < byteCount) { ! byteBuffer = new byte[byteCount]; ! } ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { ! TDebug.out("in readFromByteSourceStream: trying to read " ! + byteCount + " bytes = " ! + (byteCount / sourceStream.getFormat().getFrameSize()) ! + " samples from source stream"); } // finally read it *************** *** 394,397 **** --- 403,409 ---- } else { thisBuffer.initFromByteArray(byteBuffer, 0, bytesRead, sourceStream.getFormat()); + if (TDebug.TraceAudioConverter && DEBUG_STREAM) { + TDebug.out("in readFromByteSourceStream: initialized thisBuffer with "+thisBuffer.getSampleCount()+" samples"); + } } } *************** *** 426,436 **** historyBuffer=thisBuffer; thisBuffer=newBuffer; ! if (sourceFrameLength!=AudioSystem.NOT_SPECIFIED ! && thisBuffer.getSampleCount()+testInFramesRead>sourceFrameLength) { ! if (sourceFrameLength-testInFramesRead<=0) { ! close(); ! return; ! } ! thisBuffer.changeSampleCount((int) (sourceFrameLength-testInFramesRead), false); } --- 438,461 ---- historyBuffer=thisBuffer; thisBuffer=newBuffer; ! // ensure that we don't read more than the source stream claimed to have ! if (sourceFrameLength != AudioSystem.NOT_SPECIFIED ! && thisBuffer.getSampleCount() + testInFramesRead > sourceFrameLength) { ! long remaining = sourceFrameLength - testInFramesRead; ! if (remaining <= 0) { ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { ! TDebug.out("Read more than allowed from source stream:" ! + " sourceFrameLength=" + sourceFrameLength ! + " samples, inFramesRead=" + testInFramesRead ! + " samples."); ! } ! close(); ! return; ! } ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { ! TDebug.out("Reading from source stream: change from " ! + thisBuffer.getSampleCount()+" samples to" ! + remaining + " samples"); ! } ! thisBuffer.changeSampleCount((int) remaining, false); } *************** *** 440,448 **** readFromByteSourceStream(); } ! if (TDebug.TraceAudioConverter) { ! testInFramesRead+=thisBuffer.getSampleCount(); ! if (DEBUG_STREAM) { ! TDebug.out("Read "+thisBuffer.getSampleCount()+" frames from source stream. Total="+testInFramesRead); ! } } double inc=outSamples2inSamples(1.0); --- 465,477 ---- readFromByteSourceStream(); } ! ! int sampleCount = (thisBuffer==null)?0:thisBuffer.getSampleCount(); ! testInFramesRead += sampleCount; ! ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { ! String src = (sourceInput != null)?"source input":"source byte stream"; ! TDebug.out("Read " + sampleCount ! + " frames from "+src+" (requested="+oldSampleCount+"). Total=" ! + testInFramesRead); } double inc=outSamples2inSamples(1.0); *************** *** 737,741 **** throw new IllegalArgumentException("passed buffer has different channel count"); } ! if (TDebug.TraceAudioConverter) { TDebug.out(">SamplerateConverterStream.read("+count+" samples)"); } --- 766,770 ---- throw new IllegalArgumentException("passed buffer has different channel count"); } ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { TDebug.out(">SamplerateConverterStream.read("+count+" samples)"); } *************** *** 808,812 **** outBuffer.changeSampleCount(writtenSamples+offset, true); } ! if (TDebug.TraceAudioConverter) { testOutFramesReturned+=outBuffer.getSampleCount(); TDebug.out("< return "+outBuffer.getSampleCount()+"frames. Total="+testOutFramesReturned+" frames. Read total "+testInFramesRead+" frames from source stream"); --- 837,841 ---- outBuffer.changeSampleCount(writtenSamples+offset, true); } ! if (TDebug.TraceAudioConverter && DEBUG_STREAM) { testOutFramesReturned+=outBuffer.getSampleCount(); TDebug.out("< return "+outBuffer.getSampleCount()+"frames. Total="+testOutFramesReturned+" frames. Read total "+testInFramesRead+" frames from source stream"); |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:57:52
|
Update of /cvsroot/tritonus/tritonus In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26566 Modified Files: build-common.xml Log Message: add manifests to jar files Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/build-common.xml Index: build-common.xml =================================================================== RCS file: /cvsroot/tritonus/tritonus/build-common.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** build-common.xml 7 Feb 2006 20:42:00 -0000 1.24 --- build-common.xml 3 Jun 2007 19:57:52 -0000 1.25 *************** *** 56,60 **** <!-- CORE: contains public classes and SPI instantiation support --> ! <jar jarfile="${dist}/tritonus_core-${version}.jar"> <fileset dir="${build}"> <include name="javax/sound/" /> --- 56,61 ---- <!-- CORE: contains public classes and SPI instantiation support --> ! <jar jarfile="${dist}/tritonus_core-${version}.jar" ! manifest="${src}/packaging/tritonus_core/manifest.mf"> <fileset dir="${build}"> <include name="javax/sound/" /> *************** *** 76,80 **** <!-- ALSA: contains Alsa mixer and Alsa sequencer --> ! <jar jarfile="${dist}/tritonus_alsa-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/alsa/" /> --- 77,82 ---- <!-- ALSA: contains Alsa mixer and Alsa sequencer --> ! <jar jarfile="${dist}/tritonus_alsa-${version}.jar" ! manifest="${src}/packaging/tritonus_alsa/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/alsa/" /> *************** *** 86,90 **** <!-- ESD: contains Esd mixer --> ! <jar jarfile="${dist}/tritonus_esd-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/esd/" /> --- 88,93 ---- <!-- ESD: contains Esd mixer --> ! <jar jarfile="${dist}/tritonus_esd-${version}.jar" ! manifest="${src}/packaging/tritonus_esd/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/esd/" /> *************** *** 95,99 **** <!-- GSM: --> ! <jar jarfile="${dist}/tritonus_gsm-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/gsm/" /> --- 98,103 ---- <!-- GSM: --> ! <jar jarfile="${dist}/tritonus_gsm-${version}.jar" ! manifest="${src}/packaging/tritonus_gsm/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/gsm/" /> *************** *** 105,109 **** <!-- (native) VORBIS: --> ! <jar jarfile="${dist}/tritonus_vorbis-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/ogg/" /> --- 109,114 ---- <!-- (native) VORBIS: --> ! <jar jarfile="${dist}/tritonus_vorbis-${version}.jar" ! manifest="${src}/packaging/tritonus_vorbis/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/ogg/" /> *************** *** 121,125 **** <!-- (pure java) VORBIS: --> ! <jar jarfile="${dist}/tritonus_pvorbis-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/pogg/" /> --- 126,131 ---- <!-- (pure java) VORBIS: --> ! <jar jarfile="${dist}/tritonus_pvorbis-${version}.jar" ! manifest="${src}/packaging/tritonus_pvorbis/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/pogg/" /> *************** *** 137,141 **** <!-- JAVASEQUENCER: --> ! <jar jarfile="${dist}/tritonus_javasequencer-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/midi/device/java/" /> --- 143,148 ---- <!-- JAVASEQUENCER: --> ! <jar jarfile="${dist}/tritonus_javasequencer-${version}.jar" ! manifest="${src}/packaging/tritonus_javasequencer/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/midi/device/java/" /> *************** *** 145,149 **** <!-- FLUIDSYNTH: --> ! <jar jarfile="${dist}/tritonus_fluidsynth-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/midi/device/fluidsynth/" /> --- 152,157 ---- <!-- FLUIDSYNTH: --> ! <jar jarfile="${dist}/tritonus_fluidsynth-${version}.jar" ! manifest="${src}/packaging/tritonus_fluidsynth/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/midi/device/fluidsynth/" /> *************** *** 162,166 **** <!-- SRC: sample rate converter --> ! <jar jarfile="${dist}/tritonus_src-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/sampled/convert/SampleRateConversionProvider*.class" /> --- 170,175 ---- <!-- SRC: sample rate converter --> ! <jar jarfile="${dist}/tritonus_src-${version}.jar" ! manifest="${src}/packaging/tritonus_src/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/sampled/convert/SampleRateConversionProvider*.class" /> *************** *** 186,190 **** <!-- REMAINING:: --> ! <jar jarfile="${dist}/tritonus_remaining-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/midi/file/" /> --- 195,200 ---- <!-- REMAINING:: --> ! <jar jarfile="${dist}/tritonus_remaining-${version}.jar" ! manifest="${src}/packaging/tritonus_core/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/midi/file/" /> *************** *** 202,206 **** <!-- MP3: --> ! <jar jarfile="${dist}/tritonus_mp3-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/lowlevel/lame/" /> --- 212,217 ---- <!-- MP3: --> ! <jar jarfile="${dist}/tritonus_mp3-${version}.jar" ! manifest="${src}/packaging/tritonus_mp3/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/lowlevel/lame/" /> *************** *** 219,223 **** <!-- JORBIS: --> ! <jar jarfile="${dist}/tritonus_jorbis-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/sampled/convert/jorbis/" /> --- 230,235 ---- <!-- JORBIS: --> ! <jar jarfile="${dist}/tritonus_jorbis-${version}.jar" ! manifest="${src}/packaging/tritonus_jorbis/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/sampled/convert/jorbis/" /> *************** *** 239,243 **** <!-- MIDISHARE: --> ! <jar jarfile="${dist}/tritonus_midishare-${version}.jar" > <fileset dir="${build}" > <include name="org/tritonus/midi/device/midishare/" /> --- 251,256 ---- <!-- MIDISHARE: --> ! <jar jarfile="${dist}/tritonus_midishare-${version}.jar" ! manifest="${src}/packaging/tritonus_midishare/manifest.mf"> <fileset dir="${build}" > <include name="org/tritonus/midi/device/midishare/" /> |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:55:06
|
Update of /cvsroot/tritonus/tritonus/src/packaging/tritonus_core/META-INF/services In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25317/src/packaging/tritonus_core/META-INF/services Modified Files: javax.sound.sampled.spi.FormatConversionProvider Log Message: exclude sample rate converter from core/remaining package Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/packaging/tritonus_core/META-INF/services/javax.sound.sampled.spi.FormatConversionProvider Index: javax.sound.sampled.spi.FormatConversionProvider =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/packaging/tritonus_core/META-INF/services/javax.sound.sampled.spi.FormatConversionProvider,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** javax.sound.sampled.spi.FormatConversionProvider 1 Jun 2007 08:58:08 -0000 1.8 --- javax.sound.sampled.spi.FormatConversionProvider 3 Jun 2007 19:55:06 -0000 1.9 *************** *** 8,12 **** org.tritonus.sampled.convert.PCM2PCMConversionProvider #org.tritonus.sampled.convert.SmartFormatConversionProvider ! org.tritonus.sampled.convert.SampleRateConversionProvider #org.tritonus.sampled.convert.ImaAdpcmFormatConversionProvider --- 8,12 ---- org.tritonus.sampled.convert.PCM2PCMConversionProvider #org.tritonus.sampled.convert.SmartFormatConversionProvider ! #org.tritonus.sampled.convert.SampleRateConversionProvider #org.tritonus.sampled.convert.ImaAdpcmFormatConversionProvider |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:54:28
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv25265/src/classes/org/tritonus/share/sampled/file Modified Files: TAudioOutputStream.java Log Message: support for automatic sign and endianness conversion Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/file/TAudioOutputStream.java Index: TAudioOutputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/file/TAudioOutputStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** TAudioOutputStream.java 20 Jan 2005 07:47:17 -0000 1.1 --- TAudioOutputStream.java 3 Jun 2007 19:54:28 -0000 1.2 *************** *** 36,39 **** --- 36,44 ---- import javax.sound.sampled.AudioSystem; + import static org.tritonus.share.sampled.AudioUtils.isPCM; + import static org.tritonus.share.sampled.TConversionTool.convertSign8; + import static org.tritonus.share.sampled.TConversionTool.swapOrder16; + import static org.tritonus.share.sampled.TConversionTool.swapOrder24; + import static org.tritonus.share.sampled.TConversionTool.swapOrder32; import org.tritonus.share.TDebug; *************** *** 54,59 **** private boolean m_bDoBackPatching; private boolean m_bHeaderWritten; ! protected TAudioOutputStream(AudioFormat audioFormat, --- 59,67 ---- private boolean m_bDoBackPatching; private boolean m_bHeaderWritten; + /** if this flag is set, do sign conversion for 8-bit PCM data */ + private boolean m_doSignConversion; ! /** if this flag is set, do endian conversion for 16-bit PCM data */ ! private boolean m_doEndianConversion; protected TAudioOutputStream(AudioFormat audioFormat, *************** *** 70,74 **** --- 78,103 ---- } + /** + * descendants should call this method if implicit sign conversion for 8-bit + * data should be done + */ + protected void requireSign8bit(boolean signed) { + if (m_audioFormat.getSampleSizeInBits() == 8 && isPCM(m_audioFormat)) { + boolean si = m_audioFormat.getEncoding().equals( + AudioFormat.Encoding.PCM_SIGNED); + m_doSignConversion = signed != si; + } + } + /** + * descendants should call this method if implicit endian conversion should + * be done. Currently supported for 16, 24, and 32 bits per sample. + */ + protected void requireEndianness(boolean bigEndian) { + int ssib = m_audioFormat.getSampleSizeInBits(); + if ((ssib == 16 || ssib == 24 || ssib == 32) && isPCM(m_audioFormat)) { + m_doEndianConversion = bigEndian != m_audioFormat.isBigEndian(); + } + } public AudioFormat getFormat() *************** *** 102,105 **** --- 131,152 ---- return m_dataOutputStream; } + + /** do sign or endianness conversion */ + private void handleImplicitConversions(byte[] abData, int nOffset, int nLength) { + if (m_doSignConversion) { + convertSign8(abData, nOffset, nLength); + } + if (m_doEndianConversion) { + switch (m_audioFormat.getSampleSizeInBits()) { + case 16: swapOrder16(abData, nOffset, nLength / 2); + break; + case 24: swapOrder24(abData, nOffset, nLength / 3); + break; + case 32: + swapOrder32(abData, nOffset, nLength / 4); + break; + } + } + } *************** *** 134,139 **** --- 181,190 ---- // TODO: throw an exception if nLength==0 ? (to indicate end of file ?) if (nLength>0) { + handleImplicitConversions(abData, nOffset, nLength); m_dataOutputStream.write(abData, nOffset, nLength); m_lCalculatedLength += nLength; + // if we converted something, need to undo the conversion to + // guarantee integrity of data + handleImplicitConversions(abData, nOffset, nLength); } if (TDebug.TraceAudioOutputStream) |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:53:46
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24832/src/classes/org/tritonus/share/sampled/convert Modified Files: TSynchronousFilteredAudioInputStream.java Log Message: support for FloatSampleInput Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert/TSynchronousFilteredAudioInputStream.java Index: TSynchronousFilteredAudioInputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert/TSynchronousFilteredAudioInputStream.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** TSynchronousFilteredAudioInputStream.java 14 Dec 2006 21:47:47 -0000 1.4 --- TSynchronousFilteredAudioInputStream.java 3 Jun 2007 19:53:46 -0000 1.5 *************** *** 38,41 **** --- 38,43 ---- import org.tritonus.share.TDebug; import org.tritonus.share.sampled.AudioUtils; + import org.tritonus.share.sampled.FloatSampleBuffer; + import org.tritonus.share.sampled.FloatSampleInput; *************** *** 49,55 **** */ public abstract class TSynchronousFilteredAudioInputStream ! extends TAudioInputStream { private AudioInputStream originalStream; private AudioFormat originalFormat; /** 1 if original format's frame size is NOT_SPECIFIED */ --- 51,61 ---- */ public abstract class TSynchronousFilteredAudioInputStream ! extends TAudioInputStream implements FloatSampleInput { private AudioInputStream originalStream; + + /** the same originalStream cast to FloatSampleInput, if it is one */ + private FloatSampleInput originalStreamFloat; + private AudioFormat originalFormat; /** 1 if original format's frame size is NOT_SPECIFIED */ *************** *** 57,60 **** --- 63,68 ---- /** 1 if original format's frame size is NOT_SPECIFIED */ private int newFrameSize; + + private boolean EOF = false; /** *************** *** 72,75 **** --- 80,86 ---- */ private boolean m_bConvertInPlace = false; + + /** if this flag is set, convert(FloatSampleBuffer) is implemented by overriding classes */ + private boolean m_enableFloatConversion = false; public TSynchronousFilteredAudioInputStream(AudioInputStream audioInputStream, AudioFormat newFormat) { *************** *** 82,85 **** --- 93,99 ---- newFrameSize=(getFormat().getFrameSize()<=0) ? 1 : getFormat().getFrameSize(); + if (originalStream instanceof FloatSampleInput) { + originalStreamFloat = (FloatSampleInput) originalStream; + } if (TDebug.TraceAudioConverter) { TDebug.out("TSynchronousFilteredAudioInputStream: original format =" *************** *** 88,98 **** +AudioUtils.format2ShortStr(getFormat())); } - //$$fb 2000-07-17: convert in place has to be enabled explicitly with "enableConvertInPlace" - //if (getFormat().getFrameSize() == originalFormat.getFrameSize()) { - // m_bConvertInPlace = true; - //} m_bConvertInPlace = false; } protected boolean enableConvertInPlace() { if (newFrameSize >= originalFrameSize) { --- 102,114 ---- +AudioUtils.format2ShortStr(getFormat())); } m_bConvertInPlace = false; + m_enableFloatConversion = false; } + /** + * descendant classes should call this method if they have implemented + * convertInPlace(). ConvertInPlace will only be used if the converted frame + * size is larger than the original frame size. + */ protected boolean enableConvertInPlace() { if (newFrameSize >= originalFrameSize) { *************** *** 101,104 **** --- 117,130 ---- return m_bConvertInPlace; } + + /** + * Descendant classes should call this method if they have implemented + * convert(FloatSampleBuffer). That convert method will only be called + * if this class' FloatSampleInput.read() is used. + */ + protected void enableFloatConversion() { + m_enableFloatConversion = true; + } + *************** *** 123,129 **** */ protected void convertInPlace(byte[] buffer, int byteOffset, int frameCount) { ! throw new RuntimeException("Illegal call to convertInPlace"); } public int read() throws IOException { --- 149,170 ---- */ protected void convertInPlace(byte[] buffer, int byteOffset, int frameCount) { ! throw new RuntimeException("illegal call to convertInPlace"); ! } ! ! /** ! * Override this method to do the actual conversion in the ! * FloatSampleBuffer. Use buffer's methods to shrink the number of samples, ! * if necessary. This method will only be called if this stream is accessed ! * by way of FloatSampleInput methods. ! * ! * @param buffer the buffer to convert ! * @param offset the offset in buffer in samples ! * @param count the number of samples in buffer to convert ! */ ! protected void convert(FloatSampleBuffer buffer, int offset, int count) { ! throw new RuntimeException("illegal call to convert(FloatSampleBuffer)"); } + public int read() throws IOException { *************** *** 132,136 **** } // very ugly, but efficient. Who uses this method anyway ? - // TODO: use an instance variable byte[] temp = new byte[1]; int result = read(temp); --- 173,176 ---- *************** *** 146,152 **** ! private void clearBuffer() { m_buffer = null; } --- 186,193 ---- ! /** remove the temporary read buffer to save heap */ private void clearBuffer() { m_buffer = null; + m_floatByteBuffer = null; } *************** *** 165,169 **** * this method may read less than nLength bytes. */ ! public int read(byte[] abData, int nOffset, int nLength) throws IOException { // number of frames that we have to read from the underlying stream. --- 206,210 ---- * this method may read less than nLength bytes. */ ! public final int read(byte[] abData, int nOffset, int nLength) throws IOException { // number of frames that we have to read from the underlying stream. *************** *** 197,200 **** --- 238,242 ---- // end of stream clearBuffer(); + EOF = true; return -1; } *************** *** 236,239 **** --- 278,282 ---- public void close() throws IOException { + EOF = true; originalStream.close(); clearBuffer(); *************** *** 259,262 **** --- 302,413 ---- } + // interface FloatSampleInput + + public int getChannels() { + return format.getChannels(); + } + + public float getSampleRate() { + return format.getSampleRate(); + } + + public boolean isDone() { + // if this class was closed, never return open again + if (EOF) return true; + if (originalStreamFloat != null) { + return originalStreamFloat.isDone(); + } + return false; + } + + /** temporary byte buffer for conversion from/to byte/float arrays */ + private byte[] m_floatByteBuffer = null; + + /** + * read sampleCount converted samples at the specified offset. The current + * implementation requires that offset is 0 and sampleCount == + * buffer.getSampleCount(). + */ + public void read(FloatSampleBuffer buffer, int offset, int sampleCount) { + try { + // Case 1: reading cannot, but processing can be done in float + // layer, + // so read unconverted bytes, then convert to float and process + if (originalStreamFloat == null && m_enableFloatConversion) { + // currently cannot convert in the middle of the buffer + if (offset > 0 || sampleCount != buffer.getSampleCount()) { + throw new IllegalArgumentException( + "float reading with offset not supported"); + } + // allocate a byte array large enough to hold the byte data + int reqSize = sampleCount * originalFrameSize; + if (m_floatByteBuffer == null + || m_floatByteBuffer.length < reqSize) { + m_floatByteBuffer = new byte[reqSize]; + } + // read into byte array -- is already processed + int bytesRead = originalStream.read(m_floatByteBuffer, 0, + reqSize); + // convert the byte array to float + if (bytesRead <= 0) { + // EOF or nothing read + buffer.setSampleCount(0, false); + return; + } + // convert to float + buffer.initFromByteArray(m_floatByteBuffer, 0, bytesRead, + originalFormat); + // do the processing + convert(buffer, 0, buffer.getSampleCount()); + } else + // Case 2: reading or processing cannot be done in float layer, + // do the conversion with byte array and convert afterwards + if (originalStreamFloat == null || !m_enableFloatConversion) { + // currently cannot convert in the middle of the buffer + if (offset > 0 || sampleCount != buffer.getSampleCount()) { + throw new IllegalArgumentException( + "float reading with offset not supported"); + } + // allocate a byte array large enough to hold the converted data + int reqSize = sampleCount * format.getFrameSize(); + if (m_floatByteBuffer == null + || m_floatByteBuffer.length < reqSize) { + m_floatByteBuffer = new byte[reqSize]; + } + // read into byte array -- is already processed + int bytesRead = read(m_floatByteBuffer, 0, reqSize); + // convert the byte array to float + if (bytesRead <= 0) { + // EOF or nothing read + buffer.setSampleCount(0, false); + return; + } + // convert to float + buffer.initFromByteArray(m_floatByteBuffer, 0, bytesRead, + format); + } else { + // read from the source stream + originalStreamFloat.read(buffer, offset, sampleCount); + if (offset + sampleCount > buffer.getSampleCount()) { + sampleCount = buffer.getSampleCount() - offset; + if (sampleCount < 0) { + sampleCount = 0; + } + } + // do the actual processing + convert(buffer, offset, sampleCount); + } + + } catch (IOException ioe) { + if (TDebug.TraceAllExceptions) { + ioe.printStackTrace(); + } + buffer.setSampleCount(0, false); + } + } + + public void read(FloatSampleBuffer buffer) { + read(buffer, 0, buffer.getSampleCount()); + } } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:53:10
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24774/src/classes/org/tritonus/share/sampled/convert Modified Files: TSimpleFormatConversionProvider.java Log Message: correct calculation of frame size Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert/TSimpleFormatConversionProvider.java Index: TSimpleFormatConversionProvider.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/convert/TSimpleFormatConversionProvider.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** TSimpleFormatConversionProvider.java 20 Jan 2005 07:47:16 -0000 1.1 --- TSimpleFormatConversionProvider.java 3 Jun 2007 19:53:10 -0000 1.2 *************** *** 358,362 **** return AudioSystem.NOT_SPECIFIED; } ! return sampleSize*channels/8; } --- 358,362 ---- return AudioSystem.NOT_SPECIFIED; } ! return ((sampleSize + 7) / 8) * channels; } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:52:36
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24396/src/classes/org/tritonus/share/sampled Modified Files: TAudioFormat.java Log Message: added constructor with AudioFormat to create a copy. lazy creation of properties Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/TAudioFormat.java Index: TAudioFormat.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/TAudioFormat.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** TAudioFormat.java 20 Jan 2005 07:47:16 -0000 1.1 --- TAudioFormat.java 3 Jun 2007 19:52:37 -0000 1.2 *************** *** 63,67 **** --- 63,100 ---- } + /** + * Create an instance of TAudioFormat as a copy of the supplied audio + * format. + * + * @param format the instance to copy + */ + public TAudioFormat(AudioFormat format) + { + this(format.getEncoding(), + format.getSampleRate(), + format.getSampleSizeInBits(), + format.getChannels(), + format.getFrameSize(), + format.getFrameRate(), + format.isBigEndian(), + format.properties()); + } + /** + * Create an instance of TAudioFormat as a copy of the supplied audio + * format, adding the given properties to any properties supplied by + * <code>format</code>. Duplicate properties in the supplied + * <code>properties</code> will overwrite the ones in <code>format</code>. + * + * @param format the instance to copy + * @param properties properties to be added to this TAudioFormat + */ + public TAudioFormat(AudioFormat format, + Map<String, Object> properties) + { + this(format); + m_properties.putAll(properties); + } + public TAudioFormat(float sampleRate, int sampleSizeInBits, *************** *** 87,91 **** */ m_properties = new HashMap<String, Object>(); ! m_properties.putAll(properties); m_unmodifiableProperties = Collections.unmodifiableMap(m_properties); } --- 120,126 ---- */ m_properties = new HashMap<String, Object>(); ! if (properties != null) { ! m_properties.putAll(properties); ! } m_unmodifiableProperties = Collections.unmodifiableMap(m_properties); } *************** *** 93,105 **** public Map<String, Object> properties() { return m_unmodifiableProperties; } ! protected void setProperty(String key, Object value) { m_properties.put(key, value); } --- 128,158 ---- + @Override public Map<String, Object> properties() { + if (m_properties == null) + { + initMaps(null); + } return m_unmodifiableProperties; } + @Override + public Object getProperty(String key) + { + if (m_properties == null) + { + return null; + } + return m_properties.get(key); + } ! ! protected void setProperty(String key, Object value) { + if (m_properties == null) { + initMaps(null); + } m_properties.put(key, value); } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:51:52
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23976/src/classes/org/tritonus/share/sampled Modified Files: AudioUtils.java Log Message: added utility function for correct calculation of PCM frame size Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/share/sampled/AudioUtils.java Index: AudioUtils.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/share/sampled/AudioUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** AudioUtils.java 22 Nov 2006 15:45:30 -0000 1.3 --- AudioUtils.java 3 Jun 2007 19:51:51 -0000 1.4 *************** *** 96,99 **** --- 96,107 ---- return false; } + + /** @return the frame size, given the sample size in bits and number of channels */ + public static int getFrameSize(int channels, int sampleSizeInBits) { + if (channels < 0 || sampleSizeInBits < 0) { + return AudioSystem.NOT_SPECIFIED; + } + return ((sampleSizeInBits + 7) / 8) * channels; + } /** |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:50:15
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23448/src/classes/org/tritonus/sampled/file Modified Files: WaveAudioOutputStream.java Log Message: auto endian and sign conversion, always do backpatching for seekable files to ensure a correct header, remove instance variable for format code Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/WaveAudioOutputStream.java Index: WaveAudioOutputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/WaveAudioOutputStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** WaveAudioOutputStream.java 13 Feb 2006 12:21:50 -0000 1.2 --- WaveAudioOutputStream.java 3 Jun 2007 19:50:12 -0000 1.3 *************** *** 51,63 **** // this constant is used for chunk lengths when the length is not known yet private static final int LENGTH_NOT_KNOWN=-1; - private int formatCode; public WaveAudioOutputStream(AudioFormat audioFormat, long lLength, TDataOutputStream dataOutputStream) { super(audioFormat, lLength, dataOutputStream, ! lLength == AudioSystem.NOT_SPECIFIED && dataOutputStream.supportsSeek()); // wave cannot store more than 4GB if (lLength != AudioSystem.NOT_SPECIFIED --- 51,64 ---- // this constant is used for chunk lengths when the length is not known yet private static final int LENGTH_NOT_KNOWN=-1; public WaveAudioOutputStream(AudioFormat audioFormat, long lLength, TDataOutputStream dataOutputStream) { + // always do backpatching if the stream supports seeking, in case the + // reported stream length is longer than the actual data super(audioFormat, lLength, dataOutputStream, ! dataOutputStream.supportsSeek()); // wave cannot store more than 4GB if (lLength != AudioSystem.NOT_SPECIFIED *************** *** 71,79 **** throw new IllegalArgumentException("Wave files cannot be larger than 4GB."); } ! formatCode = WaveTool.getFormatCode(getFormat()); ! if (formatCode == WaveTool.WAVE_FORMAT_UNSPECIFIED) { ! throw new IllegalArgumentException("Unknown encoding/format for this wave file."); } - } --- 72,86 ---- throw new IllegalArgumentException("Wave files cannot be larger than 4GB."); } ! // double-check that we can write this audio format ! if (WaveTool.getFormatCode(getFormat()) == WaveTool.WAVE_FORMAT_UNSPECIFIED) { ! throw new IllegalArgumentException("Unknown encoding/format for WAVE file: "+audioFormat); ! } ! // WAVE requires unsigned 8-bit data ! requireSign8bit(false); ! // WAVE requires little endian ! requireEndianness(false); ! if (TDebug.TraceAudioOutputStream) { ! TDebug.out("Writing WAVE: "+audioFormat.getSampleSizeInBits()+" bits, "+audioFormat.getEncoding()); } } *************** *** 83,86 **** --- 90,94 ---- TDebug.out("WaveAudioOutputStream.writeHeader()"); } + int formatCode = WaveTool.getFormatCode(getFormat()); AudioFormat format = getFormat(); long lLength = getLength(); |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:49:29
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23093/src/classes/org/tritonus/sampled/file Modified Files: AuAudioOutputStream.java Log Message: hardened format check, auto endian and sign conversion, always do backpatching for seekable files to ensure a correct header Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuAudioOutputStream.java Index: AuAudioOutputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuAudioOutputStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AuAudioOutputStream.java 13 Feb 2006 12:21:50 -0000 1.2 --- AuAudioOutputStream.java 3 Jun 2007 19:49:29 -0000 1.3 *************** *** 82,90 **** long lLength, TDataOutputStream dataOutputStream) { // if length exceeds 2GB, set the length field to NOT_SPECIFIED super(audioFormat, lLength>0x7FFFFFFFl?AudioSystem.NOT_SPECIFIED:lLength, dataOutputStream, ! lLength == AudioSystem.NOT_SPECIFIED && dataOutputStream.supportsSeek()); } --- 82,104 ---- long lLength, TDataOutputStream dataOutputStream) { + // always do backpatching if the stream supports seeking, in case the + // reported stream length is longer than the actual data // if length exceeds 2GB, set the length field to NOT_SPECIFIED super(audioFormat, lLength>0x7FFFFFFFl?AudioSystem.NOT_SPECIFIED:lLength, dataOutputStream, ! dataOutputStream.supportsSeek()); ! // double-check that we can write this audio format ! if (AuTool.getFormatCode(audioFormat) == AuTool.SND_FORMAT_UNSPECIFIED) { ! throw new IllegalArgumentException("Unknown encoding/format for AU file: "+audioFormat); ! } ! // AU requires signed 8-bit data ! requireSign8bit(true); ! // AU requires big endian ! requireEndianness(true); ! if (TDebug.TraceAudioOutputStream) { ! TDebug.out("Writing AU: " + audioFormat.getSampleSizeInBits() ! + " bits, " + audioFormat.getEncoding()); ! } } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:46:22
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv21824/src/classes/org/tritonus/sampled/file Modified Files: AiffAudioOutputStream.java Log Message: hardened format check, auto endian and sign conversion Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffAudioOutputStream.java Index: AiffAudioOutputStream.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffAudioOutputStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** AiffAudioOutputStream.java 16 Jan 2005 12:45:51 -0000 1.1 --- AiffAudioOutputStream.java 3 Jun 2007 19:46:23 -0000 1.2 *************** *** 56,64 **** long lLength, TDataOutputStream dataOutputStream) { super(audioFormat, lLength, dataOutputStream, ! lLength == AudioSystem.NOT_SPECIFIED ! && dataOutputStream.supportsSeek()); // AIFF files cannot exceed 2GB if (lLength != AudioSystem.NOT_SPECIFIED && lLength>0x7FFFFFFFl) { --- 56,65 ---- long lLength, TDataOutputStream dataOutputStream) { + // always do backpatching if the stream supports seeking, in case the + // reported stream length is longer than the actual data super(audioFormat, lLength, dataOutputStream, ! dataOutputStream.supportsSeek()); // AIFF files cannot exceed 2GB if (lLength != AudioSystem.NOT_SPECIFIED && lLength>0x7FFFFFFFl) { *************** *** 73,76 **** --- 74,90 ---- m_FileType=AudioFileFormat.Type.AIFC; } + // double-check that we can write this audio format + if (AiffTool.getFormatCode(audioFormat) == AiffTool.AIFF_COMM_UNSPECIFIED) { + throw new IllegalArgumentException("Unknown encoding/format for AIFF file: "+audioFormat); + } + // AIFF requires signed 8-bit data + requireSign8bit(true); + // AIFF requires big endian + requireEndianness(true); + + if (TDebug.TraceAudioOutputStream) { + TDebug.out("Writing " + m_FileType + ": " + audioFormat.getSampleSizeInBits() + + " bits, " + audioFormat.getEncoding()); + } } *************** *** 141,147 **** // write header of SSND chunk - - - dos.writeInt(AiffTool.AIFF_SSND_MAGIC); // don't use lSSndChunkSize here ! --- 155,158 ---- *************** *** 176,182 **** // DON'T adjust calculated length ! } - - - super.close(); } --- 187,190 ---- |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:44:41
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv20994/src/classes/org/tritonus/sampled/file Modified Files: AuAudioFileReader.java Log Message: only set big endian if sample size > 8 Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuAudioFileReader.java Index: AuAudioFileReader.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AuAudioFileReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** AuAudioFileReader.java 14 Dec 2006 21:44:53 -0000 1.4 --- AuAudioFileReader.java 3 Jun 2007 19:44:42 -0000 1.5 *************** *** 171,175 **** calculateFrameSize(nSampleSize, nNumChannels), nSampleRate, ! true); AudioFileFormat audioFileFormat = new TAudioFileFormat( AudioFileFormat.Type.AU, --- 171,175 ---- calculateFrameSize(nSampleSize, nNumChannels), nSampleRate, ! nSampleSize > 8); AudioFileFormat audioFileFormat = new TAudioFileFormat( AudioFileFormat.Type.AU, |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:44:28
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv20970/src/classes/org/tritonus/sampled/file Modified Files: AiffAudioFileReader.java Log Message: only set big endian if sample size > 8 Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffAudioFileReader.java Index: AiffAudioFileReader.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/AiffAudioFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AiffAudioFileReader.java 13 Feb 2006 12:21:50 -0000 1.2 --- AiffAudioFileReader.java 3 Jun 2007 19:44:26 -0000 1.3 *************** *** 133,137 **** nFrameSize, fSampleRate, ! true); return format; } --- 133,137 ---- nFrameSize, fSampleRate, ! nSampleSize > 8); return format; } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:43:16
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv20545/src/classes/org/tritonus/sampled/convert Modified Files: SampleRateConversionProvider.java Log Message: fix premature end of converted stream, pass through properties, correct frame size calculation Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/SampleRateConversionProvider.java Index: SampleRateConversionProvider.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/SampleRateConversionProvider.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** SampleRateConversionProvider.java 25 May 2007 10:59:19 -0000 1.6 --- SampleRateConversionProvider.java 3 Jun 2007 19:43:17 -0000 1.7 *************** *** 184,188 **** ! // overriden public boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) { --- 184,188 ---- ! @Override public boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) { *************** *** 204,220 **** } ! protected static long convertLength(AudioFormat sourceFormat, AudioFormat targetFormat, long sourceLength) { ! if (sourceLength==AudioSystem.NOT_SPECIFIED) { return sourceLength; } ! return Math.round(targetFormat.getSampleRate()/sourceFormat.getSampleRate()*sourceLength); } ! protected static long convertLength(float sourceSR, float targetSR, long sourceLength) { ! if (sourceLength==AudioSystem.NOT_SPECIFIED) { return sourceLength; } ! return Math.round(targetSR/sourceSR*sourceLength); ! //return (long) (targetFormat.getSampleRate()/sourceFormat.getSampleRate()*sourceLength); } --- 204,222 ---- } ! protected static long convertLength(AudioFormat sourceFormat, ! AudioFormat targetFormat, long sourceLength) { ! if (sourceLength == AudioSystem.NOT_SPECIFIED) { return sourceLength; } ! return (long) (targetFormat.getSampleRate() ! / sourceFormat.getSampleRate() * sourceLength); } ! protected static long convertLength(float sourceSR, float targetSR, ! long sourceLength) { ! if (sourceLength == AudioSystem.NOT_SPECIFIED) { return sourceLength; } ! return (long) (targetSR / sourceSR * sourceLength); } *************** *** 397,403 **** /** pre-condition: sourceInput != null */ private void readFromSourceInput() { - sourceInput.read(thisBuffer); if (sourceInput.isDone()) { close(); } } --- 399,406 ---- /** pre-condition: sourceInput != null */ private void readFromSourceInput() { if (sourceInput.isDone()) { close(); + } else { + sourceInput.read(thisBuffer); } } *************** *** 653,657 **** } catch (ArrayIndexOutOfBoundsException aioobe) { ! if (DEBUG_STREAM_PROBLEMS) { TDebug.out("**** INDEX OUT OF BOUNDS ****** inSampleOffset=" + inSampleOffset --- 656,660 ---- } catch (ArrayIndexOutOfBoundsException aioobe) { ! if (DEBUG_STREAM_PROBLEMS || TDebug.TraceAllExceptions) { TDebug.out("**** INDEX OUT OF BOUNDS ****** inSampleOffset=" + inSampleOffset *************** *** 663,666 **** --- 666,672 ---- + outSamples.length); } + if (TDebug.TraceAllExceptions) { + aioobe.printStackTrace(); + } //throw aioobe; } *************** *** 798,801 **** --- 804,808 ---- dPos+=outSamples2inSamples((double) writeCount); } while (!isClosed() && writtenSamples<outBuffer.getSampleCount()); + if (writtenSamples<count) { outBuffer.changeSampleCount(writtenSamples+offset, true); *************** *** 878,885 **** } read(writeBuffer); ! if (eofReached) { return -1; } ! int written=writeBuffer.convertToByteArray(abData, nOffset, getFormat()); return written; } --- 885,894 ---- } read(writeBuffer); ! ! if (writeBuffer.getSampleCount() == 0 && eofReached) { return -1; } ! ! int written = writeBuffer.convertToByteArray(abData, nOffset, getFormat()); return written; } *************** *** 1000,1006 **** targetFormat.getSampleSizeInBits(), targetFormat.getChannels(), ! targetFormat.getChannels()*targetFormat.getSampleSizeInBits()/8, targetFormat.getSampleRate(), ! targetFormat.isBigEndian()); this.sampleRate=targetFormat.getSampleRate(); } --- 1009,1016 ---- targetFormat.getSampleSizeInBits(), targetFormat.getChannels(), ! AudioUtils.getFrameSize(targetFormat.getChannels(), targetFormat.getSampleSizeInBits()), targetFormat.getSampleRate(), ! targetFormat.isBigEndian(), ! targetFormat.properties()); this.sampleRate=targetFormat.getSampleRate(); } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:41:02
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv19299/src/classes/org/tritonus/sampled/convert Modified Files: PCM2PCMConversionProvider.java Log Message: through the AudioFormat.properties, made an instance of FloatSampleInput Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/PCM2PCMConversionProvider.java Index: PCM2PCMConversionProvider.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/convert/PCM2PCMConversionProvider.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** PCM2PCMConversionProvider.java 1 Jun 2007 07:17:15 -0000 1.5 --- PCM2PCMConversionProvider.java 3 Jun 2007 19:40:58 -0000 1.6 *************** *** 40,43 **** --- 40,44 ---- import org.tritonus.share.TDebug; import org.tritonus.share.sampled.AudioFormats; + import org.tritonus.share.sampled.AudioUtils; import org.tritonus.share.sampled.TConversionTool; import org.tritonus.share.sampled.FloatSampleBuffer; *************** *** 96,101 **** // only used as abbreviation ! public static AudioFormat.Encoding PCM_SIGNED = AudioFormat.Encoding.PCM_SIGNED; ! public static AudioFormat.Encoding PCM_UNSIGNED = AudioFormat.Encoding.PCM_UNSIGNED; private static final int ALL = AudioSystem.NOT_SPECIFIED; --- 97,102 ---- // only used as abbreviation ! public final static AudioFormat.Encoding PCM_SIGNED = AudioFormat.Encoding.PCM_SIGNED; ! public final static AudioFormat.Encoding PCM_UNSIGNED = AudioFormat.Encoding.PCM_UNSIGNED; private static final int ALL = AudioSystem.NOT_SPECIFIED; *************** *** 409,413 **** * rxpanding of channels. */ - class PCM2PCMStream extends TSynchronousFilteredAudioInputStream { private int conversionType; --- 410,413 ---- *************** *** 425,432 **** sourceStream.getFormat().getSampleRate(), targetFormat.getSampleSizeInBits(), ! targetFormat.getChannels(), targetFormat.getChannels() ! * targetFormat.getSampleSizeInBits() / 8, sourceStream.getFormat().getFrameRate(), ! targetFormat.isBigEndian())); if (TDebug.TraceAudioConverter) { TDebug.out("PCM2PCMStream: constructor. ConversionType=" --- 425,433 ---- sourceStream.getFormat().getSampleRate(), targetFormat.getSampleSizeInBits(), ! targetFormat.getChannels(), AudioUtils.getFrameSize( ! targetFormat.getChannels(), ! targetFormat.getSampleSizeInBits()), sourceStream.getFormat().getFrameRate(), ! targetFormat.isBigEndian(), targetFormat.properties())); if (TDebug.TraceAudioConverter) { TDebug.out("PCM2PCMStream: constructor. ConversionType=" *************** *** 461,467 **** sourceStream.getFormat().getSampleRate(), targetFormat.getSampleSizeInBits(), floatChannels, ! floatChannels * targetFormat.getSampleSizeInBits() / 8, sourceStream.getFormat().getFrameRate(), ! targetFormat.isBigEndian()); // with floatBuffer we need to copy anyway, so enable in-place // conversion --- 462,469 ---- sourceStream.getFormat().getSampleRate(), targetFormat.getSampleSizeInBits(), floatChannels, ! AudioUtils.getFrameSize(floatChannels, ! targetFormat.getSampleSizeInBits()), sourceStream.getFormat().getFrameRate(), ! targetFormat.isBigEndian(), targetFormat.properties()); // with floatBuffer we need to copy anyway, so enable in-place // conversion *************** *** 475,483 **** enableConvertInPlace(); } } // these functions only treat the highbyte of 16bit samples // obsolete: is handled with FloatBuffer because of dithering ! private void do16BTO8S(byte[] inBuffer, int inCounter, byte[] outBuffer, int outByteOffset, int sampleCount) { for (; sampleCount > 0; sampleCount--, inCounter++) { --- 477,488 ---- enableConvertInPlace(); } + + // can always convert in float layer + enableFloatConversion(); } // these functions only treat the highbyte of 16bit samples // obsolete: is handled with FloatBuffer because of dithering ! private final void do16BTO8S(byte[] inBuffer, int inCounter, byte[] outBuffer, int outByteOffset, int sampleCount) { for (; sampleCount > 0; sampleCount--, inCounter++) { *************** *** 487,491 **** // obsolete: is handled with FloatBuffer because of dithering ! private void do16BTO8U(byte[] inBuffer, int inCounter, byte[] outBuffer, int outByteOffset, int sampleCount) { for (; sampleCount > 0; sampleCount--, inCounter++) { --- 492,496 ---- // obsolete: is handled with FloatBuffer because of dithering ! private final void do16BTO8U(byte[] inBuffer, int inCounter, byte[] outBuffer, int outByteOffset, int sampleCount) { for (; sampleCount > 0; sampleCount--, inCounter++) { *************** *** 494,498 **** } ! private void do8STO16L(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { --- 499,503 ---- } ! private final void do8STO16L(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { *************** *** 502,506 **** } ! private void do8UTO16L(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { --- 507,511 ---- } ! private final void do8UTO16L(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { *************** *** 510,514 **** } ! private void do8STO16B(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { --- 515,519 ---- } ! private final void do8STO16B(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { *************** *** 518,522 **** } ! private void do8UTO16B(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { --- 523,527 ---- } ! private final void do8UTO16B(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int sampleCount) { for (int inCounter = 0; sampleCount > 0; sampleCount--) { *************** *** 526,532 **** } ! // copies the channels: in the buffer there is only one channel ! private void expandChannels(byte[] buffer, int offset, int frameCount, ! int bytesPerFrame, int channels) { int inOffset = offset + bytesPerFrame * frameCount; int outOffset = offset + bytesPerFrame * channels * frameCount; --- 531,537 ---- } ! /** copy the channels: in the buffer there is only one channel */ ! private final void expandChannels(byte[] buffer, int offset, ! int frameCount, int bytesPerFrame, int channels) { int inOffset = offset + bytesPerFrame * frameCount; int outOffset = offset + bytesPerFrame * channels * frameCount; *************** *** 579,583 **** } ! private void doFloatConversion(FloatSampleBuffer buffer, boolean expandChannels) { if (needMixDown) { --- 584,592 ---- } ! private final void doFloatConversion(FloatSampleBuffer buffer) { ! doFloatConversion(buffer, needExpandChannels); ! } ! ! private final void doFloatConversion(FloatSampleBuffer buffer, boolean expandChannels) { if (needMixDown) { *************** *** 589,596 **** } ! private void doFloatConversion(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount) { int byteCount = sampleCount ! * (getOriginalStream().getFormat().getSampleSizeInBits() / 8); if (floatBuffer == null) { floatBuffer = new FloatSampleBuffer(); --- 598,605 ---- } ! private final void doFloatConversion(byte[] inBuffer, int inByteOffset, byte[] outBuffer, int outByteOffset, int sampleCount) { int byteCount = sampleCount ! * ((getOriginalStream().getFormat().getSampleSizeInBits() + 7) / 8); if (floatBuffer == null) { floatBuffer = new FloatSampleBuffer(); *************** *** 598,607 **** floatBuffer.initFromByteArray(inBuffer, inByteOffset, byteCount, getOriginalStream().getFormat()); ! doFloatConversion(floatBuffer, false); // expansion is done on byte ! // array floatBuffer.convertToByteArray(outBuffer, outByteOffset, intermediateFloatBufferFormat); } protected int convert(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int inFrameCount) { --- 607,617 ---- floatBuffer.initFromByteArray(inBuffer, inByteOffset, byteCount, getOriginalStream().getFormat()); ! // expansion is done on byte array ! doFloatConversion(floatBuffer, false); floatBuffer.convertToByteArray(outBuffer, outByteOffset, intermediateFloatBufferFormat); } + @Override protected int convert(byte[] inBuffer, byte[] outBuffer, int outByteOffset, int inFrameCount) { *************** *** 669,673 **** if (needExpandChannels) { expandChannels(outBuffer, outByteOffset, inFrameCount, ! getFormat().getSampleSizeInBits() / 8, getFormat().getChannels()); } --- 679,683 ---- if (needExpandChannels) { expandChannels(outBuffer, outByteOffset, inFrameCount, ! (getFormat().getSampleSizeInBits() + 7) / 8, getFormat().getChannels()); } *************** *** 675,678 **** --- 685,689 ---- } + @Override protected void convertInPlace(byte[] buffer, int byteOffset, int frameCount) { *************** *** 697,701 **** if (needExpandChannels) { expandChannels(buffer, byteOffset, frameCount, ! getFormat().getSampleSizeInBits() / 8, getFormat().getChannels()); } --- 708,712 ---- if (needExpandChannels) { expandChannels(buffer, byteOffset, frameCount, ! (getFormat().getSampleSizeInBits() + 7) / 8, getFormat().getChannels()); } *************** *** 706,709 **** --- 717,729 ---- } } + + /** + * Convert this buffer. Since float buffers do not need to be PCM + * converted, offset and count are ignored. + */ + @Override + protected void convert(FloatSampleBuffer buffer, int offset, int count) { + doFloatConversion(buffer); + } } |
|
From: Florian B. <fl...@us...> - 2007-06-03 19:36:36
|
Update of /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/mpeg In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv17531/src/classes/org/tritonus/sampled/file/mpeg Modified Files: MpegAudioFileWriter.java Log Message: also write MPEG2 and MPEG2.5 files Direct links to online-CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tritonus/tritonus/src/classes/org/tritonus/sampled/file/mpeg/MpegAudioFileWriter.java Index: MpegAudioFileWriter.java =================================================================== RCS file: /cvsroot/tritonus/tritonus/src/classes/org/tritonus/sampled/file/mpeg/MpegAudioFileWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** MpegAudioFileWriter.java 20 Jan 2005 19:56:28 -0000 1.1 --- MpegAudioFileWriter.java 3 Jun 2007 19:36:36 -0000 1.2 *************** *** 51,58 **** // workaround for the fixed extension problem in AudioFileFormat.Type // see org.tritonus.share.sampled.AudioFileTypes.java ! new AudioFileFormat.Type("MP3", "mp3") }; ! public static AudioFormat.Encoding MPEG1L3=new AudioFormat.Encoding("MPEG1L3"); private static final AudioFormat[] AUDIO_FORMATS = { --- 51,61 ---- // workaround for the fixed extension problem in AudioFileFormat.Type // see org.tritonus.share.sampled.AudioFileTypes.java ! new AudioFileFormat.Type("MP3", "mp3"), ! new AudioFileFormat.Type("MP2", "mp2"), }; ! public static final AudioFormat.Encoding MPEG1L3 = new AudioFormat.Encoding("MPEG1L3"); ! public static final AudioFormat.Encoding MPEG2L3 = new AudioFormat.Encoding("MPEG2L3"); ! public static final AudioFormat.Encoding MPEG2DOT5L3 = new AudioFormat.Encoding("MPEG2DOT5L3"); private static final AudioFormat[] AUDIO_FORMATS = { *************** *** 61,64 **** --- 64,75 ---- new AudioFormat(MPEG1L3, ALL, ALL, 2, ALL, ALL, false), new AudioFormat(MPEG1L3, ALL, ALL, 2, ALL, ALL, true), + new AudioFormat(MPEG2L3, ALL, ALL, 1, ALL, ALL, false), + new AudioFormat(MPEG2L3, ALL, ALL, 1, ALL, ALL, true), + new AudioFormat(MPEG2L3, ALL, ALL, 2, ALL, ALL, false), + new AudioFormat(MPEG2L3, ALL, ALL, 2, ALL, ALL, true), + new AudioFormat(MPEG2DOT5L3, ALL, ALL, 1, ALL, ALL, false), + new AudioFormat(MPEG2DOT5L3, ALL, ALL, 1, ALL, ALL, true), + new AudioFormat(MPEG2DOT5L3, ALL, ALL, 2, ALL, ALL, false), + new AudioFormat(MPEG2DOT5L3, ALL, ALL, 2, ALL, ALL, true), }; |