From e28a3b39e1e8caf3f6cf3bfe82efdaae818a6c7b Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Time -> Byte Count
+ *
+ * Byte Count -> Time
+ *
+ * Sample Count -> Time
+ *
* ( 1000f * sampleCount ) / sampleRate
*
+ * frameDuration
can be derived by sample count per frame and channel
* via {@link #getSamplesDuration(int)}.
*
+ * Frame Time -> Frame Count + *
* @param millisecs time in milliseconds * @param frameDuration duration per frame in milliseconds. */ @@ -130,21 +162,44 @@ public interface AudioSink { * sampleCount * ( sampleSize / 8 ) * *
- * Note: To retrieve the byte size for all channels, you need to pre-multiply sampleCount
- * with {@link #channelCount}.
+ * Note: To retrieve the byte size for all channels,
+ * you need to pre-multiply sampleCount
with {@link #channelCount}.
*
+ * Sample Count -> Byte Count + *
* @param sampleCount sample count */ - public final int getSamplesByteSize(int sampleCount) { + public final int getSamplesByteCount(int sampleCount) { return sampleCount * ( sampleSize >>> 3 ); } + /** + * Returns the sample count of given byte count + * according to the {@link #sampleSize}, i.e.: + *+ * ( byteCount * 8 ) / sampleSize + *+ *
+ * Note: If byteCount
covers all channels and you request the sample size per channel,
+ * you need to divide the result by sampleCount
by {@link #channelCount}.
+ *
+ * Byte Count -> Sample Count + *
+ * @param sampleCount sample count + */ + public final int getBytesSampleCount(int byteCount) { + return ( byteCount << 3 ) / sampleSize; + } + public String toString() { - return "AudioDataFormat[type "+dataType+", sampleRate "+sampleRate+", sampleSize "+sampleSize+", channelCount "+channelCount+ - ", signed "+signed+", fixedP "+fixedP+", "+(littleEndian?"little":"big")+"endian]"; } + return "AudioDataFormat[sampleRate "+sampleRate+", sampleSize "+sampleSize+", channelCount "+channelCount+ + ", signed "+signed+", fixedP "+fixedP+", "+(planar?"planar":"packed")+", "+(littleEndian?"little":"big")+"-endian]"; } } - /** Default {@link AudioDataFormat}, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, littleEndian]. */ - public static final AudioDataFormat DefaultFormat = new AudioDataFormat(AudioDataType.PCM, 44100, 16, 2, true /* signed */, true /* fixed point */, true /* littleEndian */); + /** Default {@link AudioFormat}, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian]. */ + public static final AudioFormat DefaultFormat = new AudioFormat(44100, 16, 2, true /* signed */, + true /* fixed point */, false /* planar */, true /* littleEndian */); public static abstract class AudioFrame extends TimeFrameI { protected int byteSize; @@ -227,38 +282,54 @@ public interface AudioSink { public boolean setVolume(float v); /** - * Returns the preferred {@link AudioDataFormat} by this sink. + * Returns the preferred {@link AudioFormat} by this sink. *- * The preferred format shall reflect this sinks most native format, + * The preferred format is guaranteed to be supported + * and shall reflect this sinks most native format, * i.e. best performance w/o data conversion. *
- * @see #initSink(AudioDataFormat) + *+ * Known {@link #AudioFormat} attributes considered by implementations: + *
- * Implementation shall try to match the given requestedFormat
{@link AudioDataFormat}
- * as close as possible, regarding it's capabilities.
+ * Implementation must match the given requestedFormat
{@link AudioFormat}.
*
- * A user may consider {@link #getPreferredFormat()} and pass this value - * to utilize best performance and behavior. - *
- * The {@link #DefaultFormat} should be supported by all implementations. + * Caller shall validaterequestedFormat
via {@link #isSupported(AudioFormat)}
+ * beforehand and try to find a suitable supported one.
+ * {@link #getPreferredFormat()} and {@link #getMaxSupportedChannels()} may help.
*
- * @param requestedFormat the requested {@link AudioDataFormat}.
+ * @param requestedFormat the requested {@link AudioFormat}.
* @param frameDuration average or fixed frame duration in milliseconds
* helping a caching {@link AudioFrame} based implementation to determine the frame count in the queue.
* See {@link #DefaultFrameDuration}.
* @param initialQueueSize initial time in milliseconds to queue in this sink, see {@link #DefaultInitialQueueSize}.
* @param queueGrowAmount time in milliseconds to grow queue if full, see {@link #DefaultQueueGrowAmount}.
* @param queueLimit maximum time in milliseconds the queue can hold (and grow), see {@link #DefaultQueueLimitWithVideo} and {@link #DefaultQueueLimitAudioOnly}.
- * @return if successful the chosen AudioDataFormat based on the requestedFormat
and this sinks capabilities, otherwise null
.
+ * @return true if successful, otherwise false
*/
- public AudioDataFormat init(AudioDataFormat requestedFormat, float frameDuration,
- int initialQueueSize, int queueGrowAmount, int queueLimit);
+ public boolean init(AudioFormat requestedFormat, float frameDuration,
+ int initialQueueSize, int queueGrowAmount, int queueLimit);
/**
* Returns true, if {@link #play()} has been requested and the sink is still playing,
@@ -285,7 +356,7 @@ public interface AudioSink {
/**
* Flush all queued buffers, implies {@link #pause()}.
* - * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
* @see #play() * @see #pause() @@ -298,17 +369,17 @@ public interface AudioSink { /** * Returns the number of allocated buffers as requested by - * {@link #init(AudioDataFormat, float, int, int, int)}. + * {@link #init(AudioFormat, float, int, int, int)}. */ public int getFrameCount(); - /** @return the current enqueued frames count since {@link #init(AudioDataFormat, float, int, int, int)}. */ + /** @return the current enqueued frames count since {@link #init(AudioFormat, float, int, int, int)}. */ public int getEnqueuedFrameCount(); /** * Returns the current number of frames queued for playing. *- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
*/ public int getQueuedFrameCount(); @@ -316,7 +387,7 @@ public interface AudioSink { /** * Returns the current number of bytes queued for playing. *- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
*/ public int getQueuedByteCount(); @@ -324,7 +395,7 @@ public interface AudioSink { /** * Returns the current queued frame time in milliseconds for playing. *- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
*/ public int getQueuedTime(); @@ -337,7 +408,7 @@ public interface AudioSink { /** * Returns the current number of frames in the sink available for writing. *- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
*/ public int getFreeFrameCount(); @@ -345,10 +416,10 @@ public interface AudioSink { /** * Enqueue the remaining bytes of the given {@link AudioDataFrame}'s direct ByteBuffer to this sink. *- * The data must comply with the chosen {@link AudioDataFormat} as returned by {@link #initSink(AudioDataFormat)}. + * The data must comply with the chosen {@link AudioFormat} as returned by {@link #initSink(AudioFormat)}. *
*- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
* @returns the enqueued internal {@link AudioFrame}, which may differ from the inputaudioDataFrame
.
* @deprecated User shall use {@link #enqueueData(int, ByteBuffer, int)}, which allows implementation
@@ -359,10 +430,10 @@ public interface AudioSink {
/**
* Enqueue byteCount
bytes of the remaining bytes of the given NIO {@link ByteBuffer} to this sink.
* - * The data must comply with the chosen {@link AudioDataFormat} as returned by {@link #initSink(AudioDataFormat)}. + * The data must comply with the chosen {@link AudioFormat} as returned by {@link #initSink(AudioFormat)}. *
*- * {@link #init(AudioDataFormat, float, int, int, int)} must be called first. + * {@link #init(AudioFormat, float, int, int, int)} must be called first. *
* @returns the enqueued internal {@link AudioFrame}. */ -- cgit v1.2.3