btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / cortex / addons / common / AudioBuffer.h
blob11e372ad698e7d288104170c33e8fe18d6eca951
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
32 // AudioBuffer.h
33 // eamoon@meadgroup.com
34 // 31mar99
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>
45 class AudioBuffer :
46 public RawBuffer {
47 typedef RawBuffer _inherited;
49 public: // constants
50 static const media_raw_audio_format defaultFormat;
52 public: // ctor/dtor/accessors
53 virtual ~AudioBuffer();
55 // initialize empty buffer
56 AudioBuffer(
57 const media_raw_audio_format& format=defaultFormat,
58 rtm_pool* pFromPool=0);
60 // allocate buffer of given format & size
61 AudioBuffer(
62 const media_raw_audio_format& format,
63 uint32 frames,
64 bool bCircular=true,
65 rtm_pool* pFromPool=0);
67 // point to given buffer
68 AudioBuffer(
69 const media_raw_audio_format& format,
70 void* pData,
71 uint32 frames,
72 bool bCircular=true,
73 rtm_pool* pFromPool=0);
75 // +++++ add a flag to disallow adopt()
76 AudioBuffer(
77 const media_raw_audio_format& format,
78 class BBuffer* pBuffer,
79 bool bCircular=true);
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
89 void adopt(
90 const media_raw_audio_format& format,
91 void* pData,
92 uint32 frames,
93 bool bCircular=true,
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
98 bool adopt(
99 AudioBuffer& target);
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)
107 bool formatSameAs(
108 const AudioBuffer& target) const;
110 // copy to target audio buffer, applying any necessary
111 // format conversions. behaves like rawCopyTo().
113 uint32 copyTo(
114 AudioBuffer& target,
115 uint32* pioFromFrame,
116 uint32* pioTargetFrame,
117 uint32 frames) const; //nyi
119 // as above; copies all frames
121 uint32 copyTo(
122 AudioBuffer& target,
123 uint32* pioFromFrame,
124 uint32* pioTargetFrame) const;
126 // mix to target audio buffer, applying any necessary
127 // format conversions. behaves like rawCopyTo().
129 uint32 mixTo(
130 AudioBuffer& target,
131 uint32* pioFromFrame,
132 uint32* pioTargetFrame,
133 uint32 frames,
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
140 // cleared first.
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__ */