2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // eamoon@meadgroup.com
36 // Represents a buffer of audio data. Derived from RawBuffer;
37 // adds simple audio-specific operations.
39 #ifndef __AudioBuffer_H__
40 #define __AudioBuffer_H__
42 #include "RawBuffer.h"
43 #include <MediaDefs.h>
47 typedef RawBuffer _inherited
;
50 static const media_raw_audio_format defaultFormat
;
52 public: // ctor/dtor/accessors
53 virtual ~AudioBuffer();
55 // initialize empty buffer
57 const media_raw_audio_format
& format
=defaultFormat
,
58 rtm_pool
* pFromPool
=0);
60 // allocate buffer of given format & size
62 const media_raw_audio_format
& format
,
65 rtm_pool
* pFromPool
=0);
67 // point to given buffer
69 const media_raw_audio_format
& format
,
73 rtm_pool
* pFromPool
=0);
75 // +++++ add a flag to disallow adopt()
77 const media_raw_audio_format
& format
,
78 class BBuffer
* pBuffer
,
81 // generate a reference (point) to the target's buffer
82 AudioBuffer(const AudioBuffer
& clone
);
83 AudioBuffer
& operator=(const AudioBuffer
& clone
);
85 void setFormat(const media_raw_audio_format
& format
);
86 const media_raw_audio_format
& format() const;
88 // extra adoption support
90 const media_raw_audio_format
& format
,
94 rtm_pool
* pFromPool
=0);
96 // as with RawBuffer::adopt(), returns false if the target
97 // doesn't own its buffer, but references it anyway
101 public: // operations
103 // test for format equivalence against target buffer
104 // (ie. determine whether any conversion would be necessary
105 // for copy/mix operations)
108 const AudioBuffer
& target
) const;
110 // copy to target audio buffer, applying any necessary
111 // format conversions. behaves like rawCopyTo().
115 uint32
* pioFromFrame
,
116 uint32
* pioTargetFrame
,
117 uint32 frames
) const; //nyi
119 // as above; copies all frames
123 uint32
* pioFromFrame
,
124 uint32
* pioTargetFrame
) const;
126 // mix to target audio buffer, applying any necessary
127 // format conversions. behaves like rawCopyTo().
131 uint32
* pioFromFrame
,
132 uint32
* pioTargetFrame
,
134 float fGain
=1.0) const; //nyi
136 // calculate minimum & maximum peak levels
137 // (converted/scaled to given type if necessary)
138 // pMin and pMax must point to arrays with enough room
139 // for one value per channel. existing array values aren't
142 // (if pMin isn't provided, the maximum _absolute_ levels will
143 // be written to pMax)
145 // if fromFrame and frameCount are given, scans that range.
146 // if pAt is given, it's expected to point to an array with
147 // room for one frame value per channel: this stores the
148 // frame indices at which the peak levels were found, or
149 // ULONG_MAX if no peak was found for the given channel.
151 void findMin(float* pMin
, uint32
* pAt
=0) const;
152 uint32
findMin(uint32 fromFrame
, uint32 frameCount
,
153 float* pMin
, uint32
* pAt
=0) const;
155 void findMax(float* pMax
, uint32
* pAt
=0) const;
156 uint32
findMax(uint32 fromFrame
, uint32 frameCount
,
157 float* pMax
, uint32
* pAt
=0) const;
159 void findPeaks(float* pPeaks
, uint32
* pAt
=0) const;
160 uint32
findPeaks(uint32 fromFrame
, uint32 frameCount
,
161 float* pPeaks
, uint32
* pAt
=0) const;
163 // find average level
164 // (converted/scaled as necessary)
165 // pAverage must point to an array with enough room
166 // for one value per channel.
168 void average(float* pAverage
) const; //nyi
169 uint32
average(uint32 fromFrame
, uint32 frameCount
,
170 float* pAverage
) const; //nyi
172 protected: // members
173 media_raw_audio_format m_format
;
176 #endif /* __AudioBuffer_H__ */