AVPKit
com::avpkit::core::IAudioSamples Class Referenceabstract

A set of raw (decoded) samples, plus a timestamp for when to play those samples relative to other items in a given IContainer. More...

#include <IAudioSamples.h>

Inheritance diagram for com::avpkit::core::IAudioSamples:
Collaboration diagram for com::avpkit::core::IAudioSamples:

Public Types

enum  Format {
  FMT_NONE = -1 , FMT_U8 , FMT_S16 , FMT_S32 ,
  FMT_FLT , FMT_DBL , FMT_U8P , FMT_S16P ,
  FMT_S32P , FMT_FLTP , FMT_DBLP
}
 The format we use to represent audio. More...
 
enum class  ChannelLayout : uint64_t {
  CH_NONE = 0 , CH_FRONT_LEFT = 0x00000001 , CH_FRONT_RIGHT = 0x00000002 , CH_FRONT_CENTER = 0x00000004 ,
  CH_LOW_FREQUENCY = 0x00000008 , CH_BACK_LEFT = 0x00000010 , CH_BACK_RIGHT = 0x00000020 , CH_FRONT_LEFT_OF_CENTER = 0x00000040 ,
  CH_FRONT_RIGHT_OF_CENTER = 0x00000080 , CH_BACK_CENTER = 0x00000100 , CH_SIDE_LEFT = 0x00000200 , CH_SIDE_RIGHT = 0x00000400 ,
  CH_TOP_CENTER = 0x00000800 , CH_TOP_FRONT_LEFT = 0x00001000 , CH_TOP_FRONT_CENTER = 0x00002000 , CH_TOP_FRONT_RIGHT = 0x00004000 ,
  CH_TOP_BACK_LEFT = 0x00008000 , CH_TOP_BACK_CENTER = 0x00010000 , CH_TOP_BACK_RIGHT = 0x00020000 , CH_STEREO_LEFT = 0x20000000 ,
  CH_STEREO_RIGHT = 0x40000000 , CH_WIDE_LEFT = 0x0000000080000000ULL , CH_WIDE_RIGHT = 0x0000000100000000ULL , CH_SURROUND_DIRECT_LEFT = 0x0000000200000000ULL ,
  CH_SURROUND_DIRECT_RIGHT = 0x0000000400000000ULL , CH_LOW_FREQUENCY_2 = 0x0000000800000000ULL , CH_LAYOUT_NATIVE = 0x8000000000000000ULL , ,
  channel_mask_c , CH_LAYOUT_MONO = (CH_FRONT_CENTER) , CH_LAYOUT_STEREO = (CH_FRONT_LEFT|CH_FRONT_RIGHT) , CH_LAYOUT_2POINT1 = (CH_LAYOUT_STEREO|CH_LOW_FREQUENCY) ,
  CH_LAYOUT_2_1 = (CH_LAYOUT_STEREO|CH_BACK_CENTER) , CH_LAYOUT_SURROUND = (CH_LAYOUT_STEREO|CH_FRONT_CENTER) , CH_LAYOUT_3POINT1 = (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY) , CH_LAYOUT_4POINT0 = (CH_LAYOUT_SURROUND|CH_BACK_CENTER) ,
  CH_LAYOUT_4POINT1 = (CH_LAYOUT_4POINT0|CH_LOW_FREQUENCY) , CH_LAYOUT_2_2 = (CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT) , CH_LAYOUT_QUAD = (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_5POINT0 = (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT) ,
  CH_LAYOUT_5POINT1 = (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY) , CH_LAYOUT_5POINT0_BACK = (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_5POINT1_BACK = (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY) , CH_LAYOUT_6POINT0 = (CH_LAYOUT_5POINT0|CH_BACK_CENTER) ,
  CH_LAYOUT_6POINT0_FRONT = (CH_LAYOUT_2_2|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_HEXAGONAL = (CH_LAYOUT_5POINT0_BACK|CH_BACK_CENTER) , CH_LAYOUT_6POINT1 = (CH_LAYOUT_5POINT1|CH_BACK_CENTER) , CH_LAYOUT_6POINT1_BACK = (CH_LAYOUT_5POINT1_BACK|CH_BACK_CENTER) ,
  CH_LAYOUT_6POINT1_FRONT = (CH_LAYOUT_6POINT0_FRONT|CH_LOW_FREQUENCY) , CH_LAYOUT_7POINT0 = (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT) , CH_LAYOUT_7POINT0_FRONT = (CH_LAYOUT_5POINT0|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_7POINT1 = (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT) ,
  CH_LAYOUT_7POINT1_WIDE = (CH_LAYOUT_5POINT1|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_7POINT1_WIDE_BACK = (CH_LAYOUT_5POINT1_BACK|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) , CH_LAYOUT_OCTAGONAL = (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_CENTER|CH_BACK_RIGHT) , CH_LAYOUT_HEXADECAGONAL = (CH_LAYOUT_OCTAGONAL|CH_WIDE_LEFT|CH_WIDE_RIGHT|CH_TOP_BACK_LEFT|CH_TOP_BACK_RIGHT|CH_TOP_BACK_CENTER|CH_TOP_FRONT_CENTER|CH_TOP_FRONT_LEFT|CH_TOP_FRONT_RIGHT) ,
  CH_LAYOUT_STEREO_DOWNMIX = (CH_STEREO_LEFT|CH_STEREO_RIGHT)
}
 
typedef enum com::avpkit::core::IAudioSamples::Format Format
 The format we use to represent audio. More...
 

Public Member Functions

virtual bool isComplete ()=0
 Returns whether or not we think this buffer has been filled with data. More...
 
virtual int32_t getSampleRate ()=0
 Find the sample rate of the samples in this audio buffer. More...
 
virtual int32_t getChannels ()=0
 Return the number of channels of the samples in this buffer. More...
 
virtual int32_t getSampleBitDepth ()=0
 Find out the bit-depth of the samples in this buffer. More...
 
virtual Format getFormat ()=0
 Find the Format of the samples in this buffer. More...
 
virtual int32_t getNumSamples ()=0
 Get the number of samples in this video. More...
 
virtual int32_t getMaxBufferSize ()=0
 
virtual int32_t getMaxSamples ()=0
 
virtual int32_t getSampleSize ()=0
 
virtual int64_t getPts ()=0
 What is the Presentation Time Stamp of this set of audio samples. More...
 
virtual void setPts (int64_t aValue)=0
 Set the Presentation Time Stamp for this set of samples. More...
 
virtual int64_t getNextPts ()=0
 What would be the next Presentation Time Stamp after all the samples in this buffer were played? More...
 
virtual void setComplete (bool complete, int32_t numSamples, int32_t sampleRate, int32_t channels, Format format, int64_t pts)=0
 Call this if you modify the samples and are now done. More...
 
virtual short * getRawSamples (uint32_t startingSample)=0
 
virtual int32_t setSample (int32_t sampleIndex, int32_t channel, Format format, int32_t sample)=0
 Sets the sample at the given index and channel to the sample. More...
 
virtual int32_t getSample (int32_t sampleIndex, int32_t channel, Format format)=0
 Get the sample at the given sampleIndex and channel, and return it in the asked for format. More...
 
virtual ChannelLayout getChannelLayout ()=0
 
virtual void setComplete (bool complete, int32_t numSamples, int32_t sampleRate, int32_t channels, ChannelLayout channelLayout, Format format, int64_t pts)=0
 
- Public Member Functions inherited from com::avpkit::core::IMediaData
virtual int64_t getTimeStamp ()=0
 Get the time stamp of this object in getTimeBase() units. More...
 
virtual void setTimeStamp (int64_t aTimeStamp)=0
 Set the time stamp for this object in getTimeBase() units. More...
 
virtual IRationalgetTimeBase ()=0
 Get the time base that time stamps of this object are represented in. More...
 
virtual void setTimeBase (IRational *aBase)=0
 Set the time base that time stamps of this object are represented in. More...
 
virtual com::avpkit::ferry::IBuffergetData ()=0
 Get any underlying raw data available for this object. More...
 
virtual int32_t getSize ()=0
 Get the size in bytes of the raw data available for this object. More...
 
virtual bool isKey ()=0
 Is this object a key object? i.e. More...
 
virtual void setData (com::avpkit::ferry::IBuffer *buffer)=0
 Sets the underlying buffer used by this object. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static int32_t findSampleBitDepth (Format format)
 A convenience method that returns the # of bits in a given format. More...
 
static IAudioSamplesmake (int32_t numSamples, int32_t numChannels)
 Get a new audio samples buffer. More...
 
static int64_t samplesToDefaultPts (int64_t samples, int sampleRate)
 Converts a number of samples at a given sampleRate into Microseconds. More...
 
static int64_t defaultPtsToSamples (int64_t duration, int sampleRate)
 Converts a duration in microseconds into a number of samples, assuming a given sampleRate. More...
 
static IAudioSamplesmake (com::avpkit::ferry::IBuffer *buffer, int channels, IAudioSamples::Format format)
 Creates an IAudioSamples object by wrapping an object. More...
 
static IAudioSamplesmake (int32_t numSamples, int32_t numChannels, IAudioSamples::Format format)
 Get a new audio samples buffer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

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.

Definition at line 37 of file IAudioSamples.h.

Member Typedef Documentation

◆ Format

The format we use to represent audio.

Today only FMT_S16 (signed integer 16-bit audio) is supported.

Member Enumeration Documentation

◆ ChannelLayout

Enumerator
CH_STEREO_LEFT 

Stereo downmix.

CH_STEREO_RIGHT 

See CH_STEREO_LEFT.

CH_LAYOUT_NATIVE 

Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests the channel order of the decoder output to be the native codec channel order.

Definition at line 276 of file IAudioSamples.h.

276  : uint64_t {
277 CH_NONE= 0,
278 CH_FRONT_LEFT= 0x00000001,
279 CH_FRONT_RIGHT= 0x00000002,
280 CH_FRONT_CENTER= 0x00000004,
281 CH_LOW_FREQUENCY= 0x00000008,
282 CH_BACK_LEFT= 0x00000010,
283 CH_BACK_RIGHT= 0x00000020,
284 CH_FRONT_LEFT_OF_CENTER= 0x00000040,
285 CH_FRONT_RIGHT_OF_CENTER= 0x00000080,
286 CH_BACK_CENTER= 0x00000100,
287 CH_SIDE_LEFT= 0x00000200,
288 CH_SIDE_RIGHT= 0x00000400,
289 CH_TOP_CENTER= 0x00000800,
290 CH_TOP_FRONT_LEFT= 0x00001000,
291 CH_TOP_FRONT_CENTER= 0x00002000,
292 CH_TOP_FRONT_RIGHT= 0x00004000,
293 CH_TOP_BACK_LEFT= 0x00008000,
294 CH_TOP_BACK_CENTER= 0x00010000,
295 CH_TOP_BACK_RIGHT= 0x00020000,
296 CH_STEREO_LEFT= 0x20000000,
297 CH_STEREO_RIGHT= 0x40000000,
298 CH_WIDE_LEFT= 0x0000000080000000ULL,
299 CH_WIDE_RIGHT= 0x0000000100000000ULL,
300 CH_SURROUND_DIRECT_LEFT= 0x0000000200000000ULL,
301 CH_SURROUND_DIRECT_RIGHT= 0x0000000400000000ULL,
302 CH_LOW_FREQUENCY_2= 0x0000000800000000ULL,
303 
307 CH_LAYOUT_NATIVE= 0x8000000000000000ULL,
308 
314 CH_LAYOUT_MONO= (CH_FRONT_CENTER),
315 CH_LAYOUT_STEREO= (CH_FRONT_LEFT|CH_FRONT_RIGHT),
316 CH_LAYOUT_2POINT1= (CH_LAYOUT_STEREO|CH_LOW_FREQUENCY),
317 CH_LAYOUT_2_1= (CH_LAYOUT_STEREO|CH_BACK_CENTER),
318 CH_LAYOUT_SURROUND= (CH_LAYOUT_STEREO|CH_FRONT_CENTER),
319 CH_LAYOUT_3POINT1= (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY),
320 CH_LAYOUT_4POINT0= (CH_LAYOUT_SURROUND|CH_BACK_CENTER),
321 CH_LAYOUT_4POINT1= (CH_LAYOUT_4POINT0|CH_LOW_FREQUENCY),
322 CH_LAYOUT_2_2= (CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT),
323 CH_LAYOUT_QUAD= (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT),
324 CH_LAYOUT_5POINT0= (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT),
325 CH_LAYOUT_5POINT1= (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY),
326 CH_LAYOUT_5POINT0_BACK= (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT),
327 CH_LAYOUT_5POINT1_BACK= (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY),
328 CH_LAYOUT_6POINT0= (CH_LAYOUT_5POINT0|CH_BACK_CENTER),
329 CH_LAYOUT_6POINT0_FRONT= (CH_LAYOUT_2_2|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER),
330 CH_LAYOUT_HEXAGONAL= (CH_LAYOUT_5POINT0_BACK|CH_BACK_CENTER),
331 CH_LAYOUT_6POINT1= (CH_LAYOUT_5POINT1|CH_BACK_CENTER),
332 CH_LAYOUT_6POINT1_BACK= (CH_LAYOUT_5POINT1_BACK|CH_BACK_CENTER),
333 CH_LAYOUT_6POINT1_FRONT= (CH_LAYOUT_6POINT0_FRONT|CH_LOW_FREQUENCY),
334 CH_LAYOUT_7POINT0= (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT),
335 CH_LAYOUT_7POINT0_FRONT= (CH_LAYOUT_5POINT0|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER),
336 CH_LAYOUT_7POINT1= (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT),
337 CH_LAYOUT_7POINT1_WIDE= (CH_LAYOUT_5POINT1|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER),
338 CH_LAYOUT_7POINT1_WIDE_BACK= (CH_LAYOUT_5POINT1_BACK|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER),
339 CH_LAYOUT_OCTAGONAL= (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_CENTER|CH_BACK_RIGHT),
340 CH_LAYOUT_HEXADECAGONAL= (CH_LAYOUT_OCTAGONAL|CH_WIDE_LEFT|CH_WIDE_RIGHT|CH_TOP_BACK_LEFT|CH_TOP_BACK_RIGHT|CH_TOP_BACK_CENTER|CH_TOP_FRONT_CENTER|CH_TOP_FRONT_LEFT|CH_TOP_FRONT_RIGHT),
341 CH_LAYOUT_STEREO_DOWNMIX= (CH_STEREO_LEFT|CH_STEREO_RIGHT),
342 
343  } ;

◆ Format

The format we use to represent audio.

Today only FMT_S16 (signed integer 16-bit audio) is supported.

Enumerator
FMT_U8 

unsigned 8 bits

FMT_S16 

signed 16 bits

FMT_S32 

signed 32 bits

FMT_FLT 

float

FMT_DBL 

double

FMT_U8P 

unsigned 8 bits, planar

FMT_S16P 

signed 16 bits, planar

FMT_S32P 

signed 32 bits, planar

FMT_FLTP 

float, planar

FMT_DBLP 

double, planar

Definition at line 46 of file IAudioSamples.h.

46  {
47  FMT_NONE = -1,
48  FMT_U8,
49  FMT_S16,
50  FMT_S32,
51  FMT_FLT,
52  FMT_DBL,
53 
54  FMT_U8P,
55  FMT_S16P,
56  FMT_S32P,
57  FMT_FLTP,
58  FMT_DBLP,
59  } Format;
Format
The format we use to represent audio.
Definition: IAudioSamples.h:46
@ FMT_S32P
signed 32 bits, planar
Definition: IAudioSamples.h:56
@ FMT_U8P
unsigned 8 bits, planar
Definition: IAudioSamples.h:54
@ FMT_S16P
signed 16 bits, planar
Definition: IAudioSamples.h:55

Member Function Documentation

◆ defaultPtsToSamples()

int64_t com::avpkit::core::IAudioSamples::defaultPtsToSamples ( int64_t  duration,
int  sampleRate 
)
static

Converts a duration in microseconds into a number of samples, assuming a given sampleRate.

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

Definition at line 86 of file IAudioSamples.cpp.

87  {
88  int64_t retval = 0;
89  Global::init();
90  if (duration != Global::NO_PTS)
91  {
92  int64_t num = duration * sampleRate;
93  int64_t den = Global::DEFAULT_PTS_PER_SECOND;
94  long double calc = ((long double)num)/((long double)den);
95  retval = (int64_t)(calc);
96  }
97  return retval;
98  }
static const int64_t DEFAULT_PTS_PER_SECOND
The default time units per second that we use for decoded IAudioSamples and IVideoPicture objects.
Definition: Global.h:57
static const int64_t NO_PTS
A value that means no time stamp is set for a given object.
Definition: Global.h:50
static void init()
Internal Only.
Definition: Global.cpp:157

References com::avpkit::core::Global::DEFAULT_PTS_PER_SECOND, com::avpkit::core::Global::init(), and com::avpkit::core::Global::NO_PTS.

◆ findSampleBitDepth()

int32_t com::avpkit::core::IAudioSamples::findSampleBitDepth ( Format  format)
static

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
formatThe format you want to find the number of bits in.
Returns
The number of bits (not bytes) in the passed in format.

Definition at line 38 of file IAudioSamples.cpp.

39  {
40  int bits = av_get_bytes_per_sample((enum AVSampleFormat) format)<<3;
41  return bits;
42  }

Referenced by com::avpkit::core::AudioSamples::getSampleBitDepth(), and com::avpkit::core::AudioResampler::resample().

◆ getChannels()

virtual int32_t com::avpkit::core::IAudioSamples::getChannels ( )
pure virtual

Return the number of channels of the samples in this buffer.

For example, 1 is mono, 2 is stereo.

Returns
The number of channels.

Implemented in com::avpkit::core::AudioSamples.

Referenced by com::avpkit::core::AudioResampler::getMinimumNumSamplesRequiredInOutputSamples().

◆ getFormat()

virtual Format com::avpkit::core::IAudioSamples::getFormat ( )
pure virtual

Find the Format of the samples in this buffer.

Right now only FMT_S16 is supported.

Returns
The format of the samples.

Implemented in com::avpkit::core::AudioSamples.

Referenced by com::avpkit::core::AudioResampler::getMinimumNumSamplesRequiredInOutputSamples().

◆ getMaxBufferSize()

virtual int32_t com::avpkit::core::IAudioSamples::getMaxBufferSize ( )
pure virtual
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())

Implemented in com::avpkit::core::AudioSamples.

◆ getMaxSamples()

virtual int32_t com::avpkit::core::IAudioSamples::getMaxSamples ( )
pure virtual
Returns
Maximum number of samples this buffer can hold.

Implemented in com::avpkit::core::AudioSamples.

◆ getNextPts()

virtual int64_t com::avpkit::core::IAudioSamples::getNextPts ( )
pure virtual

What would be the next Presentation Time Stamp after all the samples in this buffer were played?

Returns
the next presentation time stamp (pts)

Implemented in com::avpkit::core::AudioSamples.

◆ getNumSamples()

virtual int32_t com::avpkit::core::IAudioSamples::getNumSamples ( )
pure virtual

Get the number of samples in this video.

For example, if you have 100 bytes of stereo (2-channel) 16-bit 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.

Implemented in com::avpkit::core::AudioSamples.

Referenced by com::avpkit::core::AudioResampler::getMinimumNumSamplesRequiredInOutputSamples().

◆ getPts()

virtual int64_t com::avpkit::core::IAudioSamples::getPts ( )
pure virtual

What is the Presentation Time Stamp of this set of audio samples.

Returns
the presentation time stamp (pts)

Implemented in com::avpkit::core::AudioSamples.

◆ getSample()

virtual int32_t com::avpkit::core::IAudioSamples::getSample ( int32_t  sampleIndex,
int32_t  channel,
Format  format 
)
pure virtual

Get the sample at the given sampleIndex and channel, and return it in the asked for format.

Parameters
sampleIndexThe zero-based index into this set of samples.
channelThe zero-based channel to get the sample from
formatThe 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, int32_t, int32_t, int32_t, Format, int64_t)), then this method returns 0. It is up to the caller to ensure the inputs are valid given that 0 is also a valid sample value.

Implemented in com::avpkit::core::AudioSamples.

◆ getSampleBitDepth()

virtual int32_t com::avpkit::core::IAudioSamples::getSampleBitDepth ( )
pure virtual

Find out the bit-depth of the samples in this buffer.

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

Implemented in com::avpkit::core::AudioSamples.

◆ getSampleRate()

virtual int32_t com::avpkit::core::IAudioSamples::getSampleRate ( )
pure virtual

Find the sample rate of the samples in this audio buffer.

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

Implemented in com::avpkit::core::AudioSamples.

Referenced by com::avpkit::core::AudioResampler::getMinimumNumSamplesRequiredInOutputSamples().

◆ getSampleSize()

virtual int32_t com::avpkit::core::IAudioSamples::getSampleSize ( )
pure virtual
Returns
Number of bytes in a single sample of audio (including channels). You can also get this by getSampleBitDepth()*getChannels()/8.

Implemented in com::avpkit::core::AudioSamples.

◆ isComplete()

virtual bool com::avpkit::core::IAudioSamples::isComplete ( )
pure virtual

Returns whether or not we think this buffer has been filled with data.

Returns
Has setComplete() been called and the buffer populated.

Implemented in com::avpkit::core::AudioSamples.

Referenced by com::avpkit::core::AudioResampler::getMinimumNumSamplesRequiredInOutputSamples().

◆ make() [1/3]

IAudioSamples * com::avpkit::core::IAudioSamples::make ( com::avpkit::ferry::IBuffer buffer,
int  channels,
IAudioSamples::Format  format 
)
static

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
bufferthe buffer to wrap
channelsthe number of channels of audio you will put it the buffer
formatthe audio sample format
Returns
a new IAudioSamples object, or null on error.

Definition at line 61 of file IAudioSamples.cpp.

63  {
64  Global::init();
65  return AudioSamples::make(buffer, channels, format);
66  }

References com::avpkit::core::Global::init().

◆ make() [2/3]

IAudioSamples * com::avpkit::core::IAudioSamples::make ( int32_t  numSamples,
int32_t  numChannels 
)
static

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
numSamplesThe 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.
numChannelsThe 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.

Definition at line 45 of file IAudioSamples.cpp.

46  {
47  Global::init();
48  return AudioSamples::make(numSamples, numChannels);
49  }

References com::avpkit::core::Global::init().

◆ make() [3/3]

IAudioSamples * com::avpkit::core::IAudioSamples::make ( int32_t  numSamples,
int32_t  numChannels,
IAudioSamples::Format  format 
)
static

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
numSamplesThe 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.
numChannelsThe number of channels in the audio you'll want to put in this buffer.
formatThe format of this buffer
Returns
A new object, or null if we can't allocate one.

Definition at line 52 of file IAudioSamples.cpp.

54  {
55  Global::init();
56  return AudioSamples::make(numSamples, numChannels, format);
57  }

References com::avpkit::core::Global::init().

◆ samplesToDefaultPts()

int64_t com::avpkit::core::IAudioSamples::samplesToDefaultPts ( int64_t  samples,
int  sampleRate 
)
static

Converts a number of samples at a given sampleRate into Microseconds.

Parameters
samplesNumber of samples.
sampleRatesample rate that those samples are recorded at.
Returns
number of microseconds it would take to play that audio.

Definition at line 69 of file IAudioSamples.cpp.

70  {
71  // Note: These need to always round up! a "partial sample" actually must
72  // be whole (and similar with time stamps).
73  int64_t retval = Global::NO_PTS;
74  Global::init();
75  if (sampleRate > 0)
76  {
77  int64_t num = samples * Global::DEFAULT_PTS_PER_SECOND;
78  int64_t den = sampleRate;
79  long double calc = ((long double)num)/((long double)den);
80  retval = (int64_t)(calc);
81  }
82  return retval;
83  }

References com::avpkit::core::Global::DEFAULT_PTS_PER_SECOND, com::avpkit::core::Global::init(), and com::avpkit::core::Global::NO_PTS.

Referenced by com::avpkit::core::AudioSamples::getNextPts(), and com::avpkit::core::AudioResampler::resample().

◆ setComplete()

virtual void com::avpkit::core::IAudioSamples::setComplete ( bool  complete,
int32_t  numSamples,
int32_t  sampleRate,
int32_t  channels,
Format  format,
int64_t  pts 
)
pure virtual

Call this if you modify the samples and are now done.

This updates the pertinent information in the structure.

Parameters
completeIs this set of samples complete?
numSamplesNumber of samples in this update (note that 4 shorts of 16-bit audio in stereo is actually 1 sample).
sampleRateThe sample rate (in Hz) of this set of samples.
channelsThe number of channels in this set of samples.
formatThe sample-format of this set of samples.
ptsThe 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

Implemented in com::avpkit::core::AudioSamples.

◆ setPts()

virtual void com::avpkit::core::IAudioSamples::setPts ( int64_t  aValue)
pure virtual

Set the Presentation Time Stamp for this set of samples.

Parameters
aValuethe new value

Implemented in com::avpkit::core::AudioSamples.

◆ setSample()

virtual int32_t com::avpkit::core::IAudioSamples::setSample ( int32_t  sampleIndex,
int32_t  channel,
Format  format,
int32_t  sample 
)
pure virtual

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
sampleIndexThe zero-based index into the set of samples
channelThe zero-based channel number. If this set of samples doesn't have that given channel, an error is returned.
formatThe format of the given sample
sampleThe actual sample
Returns
>= 0 on success; -1 on error.

Implemented in com::avpkit::core::AudioSamples.


The documentation for this class was generated from the following files: