com.xuggle.xuggler
Class IAudioSamples

Package class diagram package IAudioSamples
java.lang.Object
  extended by com.xuggle.ferry.RefCounted
      extended by com.xuggle.xuggler.IMediaData
          extended by com.xuggle.xuggler.IAudioSamples

public class IAudioSamples
extends IMediaData

A set of raw (decoded) samples, plus a timestamp for when to play those samples relative to other items in a given IContainer. The timestamp value in decoded data is always in Microseonds.


Nested Class Summary
static class IAudioSamples.ChannelLayout
           
static class IAudioSamples.Format
           
 
Field Summary
 
Fields inherited from class com.xuggle.xuggler.IMediaData
DEFAULT_TIME_STAMP_FORMAT
 
Fields inherited from class com.xuggle.ferry.RefCounted
swigCMemOwn
 
Constructor Summary
protected IAudioSamples(long cPtr, boolean cMemoryOwn)
          Internal Only.
protected IAudioSamples(long cPtr, boolean cMemoryOwn, AtomicLong ref)
          Internal Only.
 
Method Summary
 IAudioSamples copyReference()
          Create a new IAudioSamples object that is actually referring to the exact same underlying native object.
static long defaultPtsToSamples(long duration, int sampleRate)
          Converts a duration in microseconds into a number of samples, assuming a given sampleRate.
 boolean equals(Object obj)
          Compares two values, returning true if the underlying objects in native code are the same object.
static long findSampleBitDepth(IAudioSamples.Format format)
          A convenience method that returns the # of bits in a given format.
 int getChannels()
          Return the number of channels of the samples in this buffer.
static long getCPtr(IAudioSamples obj)
          Internal Only.
 IAudioSamples.Format getFormat()
          Find the Format of the samples in this buffer.
 long getMaxBufferSize()
           
 long getMaxSamples()
           
 long getMyCPtr()
          Internal Only.
 long getNextPts()
          What would be the next Presentation Time Stamp after all the samples in this buffer were played?
 long getNumSamples()
          Get the number of samples in this video.
 long getPts()
          What is the Presentation Time Stamp of this set of audio samples.
 int getSample(long sampleIndex, int channel, IAudioSamples.Format format)
          Get the sample at the given sampleIndex and channel, and return it in the asked for format.
 long getSampleBitDepth()
          Find out the bit-depth of the samples in this buffer.
 int getSampleRate()
          Find the sample rate of the samples in this audio buffer.
 long getSampleSize()
           
 int hashCode()
          Get a hashable value for this object.
 boolean isComplete()
          Returns whether or not we think this buffer has been filled with data.
static IAudioSamples make(IBuffer buffer, int channels, IAudioSamples.Format format)
          Creates an IAudioSamples object by wrapping an object.
static IAudioSamples make(long numSamples, long numChannels)
          Get a new audio samples buffer.
static IAudioSamples make(long numSamples, long numChannels, IAudioSamples.Format format)
          Get a new audio samples buffer.
static long samplesToDefaultPts(long samples, int sampleRate)
          Converts a number of samples at a given sampleRate into Microseconds.
 void setComplete(boolean complete, long numSamples, int sampleRate, int channels, IAudioSamples.Format format, long pts)
          Call this if you modify the samples and are now done.
 void setPts(long aValue)
          Set the Presentation Time Stamp for this set of samples.
 int setSample(long sampleIndex, int channel, IAudioSamples.Format format, int sample)
          Sets the sample at the given index and channel to the sample.
 String toString()
          info about this packet
 
Methods inherited from class com.xuggle.xuggler.IMediaData
delete, get, get, get, get, get, get, get, getByteBuffer, getByteBuffer, getCPtr, getData_internal, getData, getDataCached, getFormattedTimeStamp, getFormattedTimeStamp, getSize, getTimeBase, getTimeStamp, isKey, put, put, put, put, put, put, put, setData_internal, setData, setTimeBase, setTimeStamp
 
Methods inherited from class com.xuggle.ferry.RefCounted
acquire, getCPtr, getCurrentRefCount, getJavaRefCount, release
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IAudioSamples

protected IAudioSamples(long cPtr,
                        boolean cMemoryOwn)
Internal Only.


IAudioSamples

protected IAudioSamples(long cPtr,
                        boolean cMemoryOwn,
                        AtomicLong ref)
Internal Only.

Method Detail

getCPtr

public static long getCPtr(IAudioSamples obj)
Internal Only. Not part of public API. Get the raw value of the native object that obj is proxying for.

Parameters:
obj - The java proxy object for a native object.
Returns:
The raw pointer obj is proxying for.

getMyCPtr

public long getMyCPtr()
Internal Only. Not part of public API. Get the raw value of the native object that we're proxying for.

Overrides:
getMyCPtr in class IMediaData
Returns:
The raw pointer we're proxying for.

copyReference

public IAudioSamples copyReference()
Create a new IAudioSamples object that is actually referring to the exact same underlying native object.

Overrides:
copyReference in class IMediaData
Returns:
the new Java object.

equals

public boolean equals(Object obj)
Compares two values, returning true if the underlying objects in native code are the same object. That means you can have two different Java objects, but when you do a comparison, you'll find out they are the EXACT same object.

Overrides:
equals in class IMediaData
Returns:
True if the underlying native object is the same. False otherwise.

hashCode

public int hashCode()
Get a hashable value for this object.

Overrides:
hashCode in class IMediaData
Returns:
the hashable value.

toString

public String toString()
info about this packet

Overrides:
toString in class Object
Returns:
information about this packet

isComplete

public boolean isComplete()
Returns whether or not we think this buffer has been filled with data.


getSampleRate

public int getSampleRate()
Find the sample rate of the samples in this audio buffer.

Returns:
The Sampling Rate of the samples in this buffer (e.g. 22050).

getChannels

public int getChannels()
Return the number of channels of the samples in this buffer. For example, 1 is mono, 2 is stereo.

Returns:
The number of channels.

getSampleBitDepth

public long getSampleBitDepth()
Find out the bit-depth of the samples in this buffer.

Returns:
Number of bits in a raw sample (per channel)

getFormat

public IAudioSamples.Format getFormat()
Find the Format of the samples in this buffer. Right now only FMT_S16 is supported.

Returns:
The format of the samples.

getNumSamples

public long getNumSamples()
Get the number of samples in this video. audio in this buffer, there are 25 samples. If you have 100 bytes of mono (1-channel) 16-bit audio in this buffer, you have 50 samples.

Returns:
The number of samples.

getMaxBufferSize

public long getMaxBufferSize()
Returns:
Maximum number of bytes that can be put in this buffer. To get the number of samples you can put in this IAudioSamples instance, do the following num_samples = getMaxBufferSize() (getSampleSize())

getMaxSamples

public long getMaxSamples()
Returns:
Maximum number of samples this buffer can hold.

getSampleSize

public long getSampleSize()
Returns:
Number of bytes in a single sample of audio (including channels). You can also get this by getSampleBitDepth()*getChannels()/8.

getPts

public long getPts()
What is the Presentation Time Stamp of this set of audio samples.

Returns:
the presentation time stamp (pts)

setPts

public void setPts(long aValue)
Set the Presentation Time Stamp for this set of samples.

Parameters:
aValue - the new value

getNextPts

public long getNextPts()
What would be the next Presentation Time Stamp after all the samples in this buffer were played?

Returns:
the next presentation time stamp (pts)

setComplete

public void setComplete(boolean complete,
                        long numSamples,
                        int sampleRate,
                        int channels,
                        IAudioSamples.Format format,
                        long pts)
Call this if you modify the samples and are now done. This updates the pertinent information in the structure.

Parameters:
complete - Is this set of samples complete?
numSamples - Number of samples in this update (note that 4 shorts of 16-bit audio in stereo is actually 1 sample).
sampleRate - The sample rate (in Hz) of this set of samples.
channels - The number of channels in this set of samples.
format - The sample-format of this set of samples.
pts - The presentation time stamp of the starting sample in this buffer. Caller must ensure pts is in units of 1/1,000,000 of a second

setSample

public int setSample(long sampleIndex,
                     int channel,
                     IAudioSamples.Format format,
                     int sample)
Sets the sample at the given index and channel to the sample. In theory we assume input is the given Format, and will convert if needed, but right now we only support FMT_S16 anyway.

Parameters:
channel - The zero-based channel number. If this set of samples doesn't have that given channel, an error is returned.
format - The format of the given sample
sample - The actual sample
Returns:
>= 0 on success; -1 on error.

getSample

public int getSample(long sampleIndex,
                     int channel,
                     IAudioSamples.Format format)
Get the sample at the given sampleIndex and channel, and return it in the asked for format.

Parameters:
sampleIndex - The zero-based index into this set of samples.
channel - The zero-based channel to get the sample from
format - The format to return in
Returns:
The sample if available. If that sample is not available (e.g. because the channel doesn't exist, or the samples have not been #setComplete(bool, uint32_t, int32_t, int32_t, Format, int64_t)), then this method returns 0. It is up to the caller to ensure

findSampleBitDepth

public static long findSampleBitDepth(IAudioSamples.Format format)
A convenience method that returns the # of bits in a given format. Be aware that right now this library only supports 16-bit audio.

Parameters:
format - The format you want to find the number of bits in.

make

public static IAudioSamples make(long numSamples,
                                 long numChannels)
Get a new audio samples buffer.

Note that any buffers this objects needs will be lazily allocated (i.e. we won't actually grab all the memory until we need it).

Parameters:
numSamples - The minimum number of samples you're going to want to put in this buffer. We may (and probably will) return a larger buffer, but you cannot assume that.
numChannels - The number of channels in the audio you'll want to put in this buffer.
Returns:
A new object, or null if we can't allocate one.

samplesToDefaultPts

public static long samplesToDefaultPts(long samples,
                                       int sampleRate)
Converts a number of samples at a given sampleRate into Microseconds.

Parameters:
samples - Number of samples.
sampleRate - sample rate that those samples are recorded at.
Returns:
number of microseconds it would take to play that audio.

defaultPtsToSamples

public static long defaultPtsToSamples(long duration,
                                       int sampleRate)
Converts a duration in microseconds into a number of samples, assuming a given sampleRate.

Parameters:
duration - The duration in microseconds.
sampleRate - sample rate that you want to use.
Returns:
The number of samples it would take (at the given sampleRate) to take duration microseconds to play.

make

public static IAudioSamples make(IBuffer buffer,
                                 int channels,
                                 IAudioSamples.Format format)
Creates an IAudioSamples object by wrapping an object.

If you are decoding into this buffer, the buffer must be at least 192k*channels large (an FFmpeg requirement) or the decodeAudio call on IStreamCoder will fail with an error. If you are encoding from, any size should do.

Parameters:
buffer - the buffer to wrap
channels - the number of channels of audio you will put it the buffer
format - the audio sample format
Returns:
a new IAudioSamples object, or null on error.

make

public static IAudioSamples make(long numSamples,
                                 long numChannels,
                                 IAudioSamples.Format format)
Get a new audio samples buffer.

Note that any buffers this objects needs will be lazily allocated (i.e. we won't actually grab all the memory until we need it).

Parameters:
numSamples - The minimum number of samples you're going to want to put in this buffer. We may (and probably will) return a larger buffer, but you cannot assume that.
numChannels - The number of channels in the audio you'll want to put in this buffer.
format - The format of this buffer
Returns:
A new object, or null if we can't allocate one.


Copyright © 2008, 2010 Xuggle