1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
18#define RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
19
20#include <vector>
21
22#include "base/integral_types.h"
23#include "base/audio_buffer.h"
24#include "base/logging.h"
25
26namespace vraudio {
27
28// Copies interleaved audio data from a raw float pointer into separate channel
29// buffers specified by a vector of raw float pointers.
30//
31// @param interleaved_buffer Raw float pointer to interleaved audio data.
32// @param num_input_frames Size of |interleaved_buffer| in frames.
33// @param num_input_channels Number of channels in interleaved audio data.
34// @param planar_buffer_ptr Raw float pointers to each planar channel buffer.
35// @param num_output_frames Number of frames per channel in output buffer.
36void PlanarFromInterleaved(const float* interleaved_buffer,
37 size_t num_input_frames, size_t num_input_channels,
38 const std::vector<float*>& planar_buffer_ptr,
39 size_t num_output_frames);
40
41// Copies interleaved audio data from a raw int16 pointer into separate channel
42// buffers specified by a vector of raw float pointers.
43//
44// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
45// @param num_input_frames Size of |interleaved_buffer| in frames.
46// @param num_input_channels Number of channels in interleaved audio data.
47// @param planar_buffer_ptr Raw float pointers to each planar channel buffer.
48// @param num_output_frames Number of frames per channel in output buffer.
49void PlanarFromInterleaved(const int16* interleaved_buffer,
50 size_t num_input_frames, size_t num_input_channels,
51 const std::vector<float*>& planar_buffer_ptr,
52 size_t num_output_frames);
53
54// Copies interleaved audio data from a raw float pointer into a planar
55// |AudioBuffer|. Note that the number of output channels and frames is defined
56// by the target |AudioBuffer| instance.
57//
58// @param interleaved_buffer Raw float pointer to interleaved audio data.
59// @param num_input_frames Size of interleaved_buffer in frames.
60// @param num_input_channels Number of channels in interleaved audio data.
61// @param output Target output buffer.
62void FillAudioBuffer(const float* interleaved_buffer, size_t num_input_frames,
63 size_t num_input_channels, AudioBuffer* output);
64
65// Copies interleaved audio data from a raw int16 pointer into a planar
66// |AudioBuffer|. Note that the number of output channels and frames is defined
67// by the target |AudioBuffer| instance.
68//
69// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
70// @param num_input_frames Size of interleaved_buffer in frames.
71// @param num_input_channels Number of channels in interleaved audio data.
72// @param output Target output buffer.
73void FillAudioBuffer(const int16* interleaved_buffer, size_t num_input_frames,
74 size_t num_input_channels, AudioBuffer* output);
75
76// Copies interleaved audio data from a float vector into a planar
77// |AudioBuffer|. Note that the number of output channels and frames is defined
78// by the target |AudioBuffer| instance.
79//
80// @param interleaved_buffer Interleaved audio data.
81// @param num_input_channels Number of channels in interleaved audio data.
82// @param output Target output buffer.
83void FillAudioBuffer(const std::vector<float>& interleaved_buffer,
84 size_t num_input_channels, AudioBuffer* output);
85
86// Copies interleaved audio data from a int16 vector into a planar
87// |AudioBuffer|. Note that the number of output channels and frames is defined
88// by the target |AudioBuffer| instance.
89//
90// @param interleaved_buffer Interleaved audio data.
91// @param num_input_channels Number of channels in interleaved audio data.
92// @param output Target output buffer.
93void FillAudioBuffer(const std::vector<int16>& interleaved_buffer,
94 size_t num_input_channels, AudioBuffer* output);
95
96// Copies raw planar float audio data into a planar |AudioBuffer|. Note that the
97// number of output channels and frames is defined by the target |AudioBuffer|
98// instance.
99//
100// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
101// @param num_input_frames Size of planar input in frames.
102// @param num_input_channels Number of channels in planar input buffer.
103// @param output Target output buffer.
104void FillAudioBuffer(const float* const* planar_ptrs, size_t num_input_frames,
105 size_t num_input_channels, AudioBuffer* output);
106
107// Copies raw planar int16 audio data into a planar |AudioBuffer|. Note that the
108// number of output channels and frames is defined by the target |AudioBuffer|
109// instance.
110//
111// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
112// @param num_input_frames Size of planar input in frames.
113// @param num_input_channels Number of channels in planar input buffer.
114// @param output Target output buffer.
115void FillAudioBuffer(const int16* const* planar_ptrs, size_t num_input_frames,
116 size_t num_input_channels, AudioBuffer* output);
117
118// Copies interleaved audio data from a raw float pointer into a planar
119// |AudioBuffer| with a specified output frame offset. Note that the
120// number of output channels is defined by the target |AudioBuffer| instance.
121//
122// @param interleaved_buffer Raw float pointer to interleaved audio data.
123// @param num_input_frames Size of |interleaved_buffer| in frames.
124// @param num_input_channels Number of channels in interleaved audio data.
125// @param input_frame_offset First source frame position in input.
126// @param output_frame_offset First frame destination in output.
127// @param num_frames_to_copy Number of frames per copy.
128// @param output Target output buffer.
129void FillAudioBufferWithOffset(const float* interleaved_buffer,
130 size_t num_input_frames,
131 size_t num_input_channels,
132 size_t input_frame_offset,
133 size_t output_frame_offset,
134 size_t num_frames_to_copy, AudioBuffer* output);
135
136// Copies interleaved audio data from a raw int16 pointer into a planar
137// |AudioBuffer| with a specified output frame offset. Note that the
138// number of output channels is defined by the target |AudioBuffer| instance.
139//
140// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
141// @param num_input_frames Size of |interleaved_buffer| in frames.
142// @param num_input_channels Number of channels in interleaved audio data.
143// @param input_frame_offset First source frame position in input.
144// @param output_frame_offset First frame destination in output.
145// @param num_frames_to_copy Number of frames per copy.
146// @param output Target output buffer.
147void FillAudioBufferWithOffset(const int16* interleaved_buffer,
148 size_t num_input_frames,
149 size_t num_input_channels,
150 size_t input_frame_offset,
151 size_t output_frame_offset,
152 size_t num_frames_to_copy, AudioBuffer* output);
153
154// Copies raw planar float audio data into a planar |AudioBuffer| with a
155// specified output frame offset. Note that the number of output channels is
156// defined by the target |AudioBuffer| instance.
157//
158// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
159// @param num_input_frames Size of |interleaved_buffer| in frames.
160// @param num_input_channels Number of channels in interleaved audio data.
161// @param input_frame_offset First source frame position in input.
162// @param output_frame_offset First frame destination in output.
163// @param num_frames_to_copy Number of frames per copy.
164// @param output Target output buffer.
165void FillAudioBufferWithOffset(const float* const* planar_ptrs,
166 size_t num_input_frames,
167 size_t num_input_channels,
168 size_t input_frame_offset,
169 size_t output_frame_offset,
170 size_t num_frames_to_copy, AudioBuffer* output);
171
172// Copies raw planar int16 audio data into a planar |AudioBuffer| with a
173// specified output frame offset. Note that the number of output channels is
174// defined by the target |AudioBuffer| instance.
175//
176// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
177// @param num_input_frames Size of |interleaved_buffer| in frames.
178// @param num_input_channels Number of channels in interleaved audio data.
179// @param input_frame_offset First source frame position in input.
180// @param output_frame_offset First frame destination in output.
181// @param num_frames_to_copy Number of frames per copy.
182// @param output Target output buffer.
183void FillAudioBufferWithOffset(const int16* const* planar_ptrs,
184 size_t num_input_frames,
185 size_t num_input_channels,
186 size_t input_frame_offset,
187 size_t output_frame_offset,
188 size_t num_frames_to_copy, AudioBuffer* output);
189
190// Copies interleaved audio data from a raw int16 pointer into a planar
191// |AudioBuffer|. The |channel_map| argument allows to reorder the channel
192// mapping between the interleaved input and output buffer. The i'th channel in
193// the output buffer corresponds to the |channel_map[i]|'th input channel. Note
194// that the number of output channels and frames is derived from the target
195// |AudioBuffer| instance.
196//
197// @param interleaved_buffer Raw int16 pointer to interleaved audio data.
198// @param num_input_frames Size of interleaved_buffer in frames.
199// @param num_input_channels Number of input channels.
200// @param channel_map Mapping that maps output channels to input channels
201// @param output Target output buffer.
202void FillAudioBufferWithChannelRemapping(const int16* interleaved_buffer,
203 size_t num_input_frames,
204 size_t num_input_channels,
205 const std::vector<size_t>& channel_map,
206 AudioBuffer* output);
207
208// Copies interleaved audio data from a raw float pointer into a planar
209// |AudioBuffer|. The |channel_map| argument allows to reorder the channel
210// mapping between the interleaved input and output buffer. The i'th channel in
211// the output buffer corresponds to the |channel_map[i]| input channel. Note
212// that the number of output channels and frames is derived from the target
213// |AudioBuffer| instance.
214//
215// @param interleaved_buffer Raw float pointer to interleaved audio data.
216// @param num_input_frames Size of interleaved_buffer in frames.
217// @param num_input_channels Number of input channels.
218// @param channel_map Mapping that maps output channels to input channels
219// @param output Target output buffer.
220void FillAudioBufferWithChannelRemapping(const float* interleaved_buffer,
221 size_t num_input_frames,
222 size_t num_input_channels,
223 const std::vector<size_t>& channel_map,
224 AudioBuffer* output);
225
226// Copies raw planar float audio data into a planar |AudioBuffer|. The
227// |channel_map| argument allows to reorder the channel mapping between the
228// planar input and output buffer. The i'th channel in the output buffer
229// corresponds to the |channel_map[i]| input channel. Note that the number of
230// output channels and frames is derived from the target |AudioBuffer| instance.
231//
232// @param planar_ptrs Pointer to an array of pointers to raw float channel data.
233// @param num_input_frames Size of interleaved_buffer in frames.
234// @param num_input_channels Number of input channels.
235// @param channel_map Mapping that maps output channels to input channels
236// @param output Target output buffer.
237void FillAudioBufferWithChannelRemapping(const float* const* planar_ptr,
238 size_t num_input_frames,
239 size_t num_input_channels,
240 const std::vector<size_t>& channel_map,
241 AudioBuffer* output);
242
243// Copies raw planar int16 audio data into a planar |AudioBuffer|. The
244// |channel_map| argument allows to reorder the channel mapping between the
245// planar input and output buffer. The i'th channel in the output buffer
246// corresponds to the |channel_map[i]| input channel. Note that the number of
247// output channels and frames is derived from the target |AudioBuffer| instance.
248//
249// @param planar_ptrs Pointer to an array of pointers to raw int16 channel data.
250// @param num_input_frames Size of interleaved_buffer in frames.
251// @param num_input_channels Number of input channels.
252// @param channel_map Mapping that maps output channels to input channels
253// @param output Target output buffer.
254void FillAudioBufferWithChannelRemapping(const int16* const* planar_ptr,
255 size_t num_input_frames,
256 size_t num_input_channels,
257 const std::vector<size_t>& channel_map,
258 AudioBuffer* output);
259
260// Copies planar audio data from an |AudioBuffer| to an external interleaved
261// float vector. Note this method resizes the target vector to match number of
262// input samples.
263//
264// @param input Input audio buffer.
265// @param output interleaved output vector.
266void FillExternalBuffer(const AudioBuffer& input, std::vector<float>* output);
267
268// Copies and converts planar audio data from an |AudioBuffer| to an external
269// interleaved int16 vector. Note this method resizes the target vector to match
270// number of input samples.
271//
272// @param input Input audio buffer.
273// @param output interleaved output vector.
274void FillExternalBuffer(const AudioBuffer& input, std::vector<int16>* output);
275
276// Copies planar audio data from an |AudioBuffer| to an external planar raw
277// float buffer. Note that the input and output buffer must match in terms of
278// number of channels and frames.
279//
280// @param input Input audio buffer.
281// @param planar_output_ptrs Planar output vector.
282// @param num_output_frames Number of frames in output buffer.
283// @param num_output_channels Number of channels in output buffer.
284void FillExternalBuffer(const AudioBuffer& input,
285 float* const* planar_output_ptrs,
286 size_t num_output_frames, size_t num_output_channels);
287
288// Copies and converts audio data from an |AudioBuffer| to an external planar
289// int16 buffer. Note that the input and output buffer must match in terms of
290// number of channels and frames.
291//
292// @param input Input audio buffer.
293// @param planar_output_ptrs Planar output vector.
294// @param num_output_frames Number of frames in output buffer.
295// @param num_output_channels Number of channels in output buffer.
296void FillExternalBuffer(const AudioBuffer& input,
297 int16* const* planar_output_ptrs,
298 size_t num_output_frames, size_t num_output_channels);
299
300// Copies and converts planar audio data from an |AudioBuffer| to an external
301// interleaved raw int16 buffer. Note that the input and output buffer must
302// match in terms of number of channels and frames.
303//
304// @param input Input audio buffer.
305// @param interleaved_output_buffer Interleaved output vector.
306// @param num_output_frames Number of frames in output buffer.
307// @param num_output_channels Number of channels in output buffer.
308void FillExternalBuffer(const AudioBuffer& input,
309 int16* interleaved_output_buffer,
310 size_t num_output_frames, size_t num_output_channels);
311
312// Copies planar audio data from an |AudioBuffer| to an external interleaved
313// raw float buffer. Note that the input and output buffer must match in terms
314// of number of channels and frames.
315//
316// @param input Input audio buffer.
317// @param interleaved_output_buffer Interleaved output vector.
318// @param num_output_frames Number of frames in output buffer.
319// @param num_output_channels Number of channels in output buffer.
320void FillExternalBuffer(const AudioBuffer& input,
321 float* interleaved_output_buffer,
322 size_t num_output_frames, size_t num_output_channels);
323
324// Copies and converts audio data from an |AudioBuffer| to an external
325// planar raw int16 buffer with the ability to specify an offset into the
326// input and output buffer.
327//
328// @param input Input audio buffer.
329// @param input_offset_frames Offset into input buffer in frames.
330// @param planar_output_ptrs Planar output vector.
331// @param num_output_frames Number of frames in output buffer.
332// @param num_output_channels Number of channels in output buffer.
333// @param output_offset_frames Offset into the output buffer in frames.
334// @param num_frames_convert_and_copy Number of frames to be processed.
335void FillExternalBufferWithOffset(const AudioBuffer& input,
336 size_t input_offset_frames,
337 int16* const* planar_output_ptrs,
338 size_t num_output_frames,
339 size_t num_output_channels,
340 size_t output_offset_frames,
341 size_t num_frames_convert_and_copy);
342
343// Copies audio data from an |AudioBuffer| to an external planar raw float
344// buffer with the ability to specify an offset into the input and output
345// buffer.
346//
347// @param input Input audio buffer.
348// @param input_offset_frames Offset into input buffer in frames.
349// @param planar_output_ptrs Planar output vector.
350// @param num_output_frames Number of frames in output buffer.
351// @param num_output_channels Number of channels in output buffer.
352// @param output_offset_frames Offset into the output buffer in frames.
353// @param num_frames_convert_and_copy Number of frames to be processed.
354void FillExternalBufferWithOffset(const AudioBuffer& input,
355 size_t input_offset_frames,
356 float* const* planar_output_ptrs,
357 size_t num_output_frames,
358 size_t num_output_channels,
359 size_t output_offset_frames,
360 size_t num_frames_convert_and_copy);
361
362// Copies and converts audio data from an |AudioBuffer| to an external
363// interleaved raw int16 buffer with the ability to specify an offset into the
364// input and output buffer.
365//
366// @param input Input audio buffer.
367// @param input_offset_frames Offset into input buffer in frames.
368// @param interleaved_output_buffer Interleaved output vector.
369// @param num_output_frames Number of frames in output buffer.
370// @param num_output_channels Number of channels in output buffer.
371// @param output_offset_frames Offset into the output buffer in frames.
372// @param num_frames_convert_and_copy Number of frames to be processed.
373void FillExternalBufferWithOffset(const AudioBuffer& input,
374 size_t input_offset_frames,
375 int16* interleaved_output_buffer,
376 size_t num_output_frames,
377 size_t num_output_channels,
378 size_t output_offset_frames,
379 size_t num_frames_convert_and_copy);
380
381// Copies and audio data from an |AudioBuffer| to an external interleaved raw
382// float buffer with the ability to specify an offset into the input and output
383// buffer.
384//
385// @param input Input audio buffer.
386// @param input_offset_frames Offset into input buffer in frames.
387// @param interleaved_output_buffer Interleaved output vector.
388// @param num_output_frames Number of frames in output buffer.
389// @param num_output_channels Number of channels in output buffer.
390// @param output_offset_frames Offset into the output buffer in frames.
391// @param num_frames_convert_and_copy Number of frames to be processed.
392void FillExternalBufferWithOffset(const AudioBuffer& input,
393 size_t input_offset_frames,
394 float* interleaved_output_buffer,
395 size_t num_output_frames,
396 size_t num_output_channels,
397 size_t output_offset_frames,
398 size_t num_frames_convert_and_copy);
399
400// Generates a vector of mutable float pointers to the beginning of each channel
401// buffer in an |AudioBuffer|. The size of the |channel_ptr_vector| output
402// vector must match the number of channels in |audio_buffer|.
403//
404// @param audio_buffer Audio buffer.
405// @param channel_ptr_vector Output std::vector<float*> vector.
406void GetRawChannelDataPointersFromAudioBuffer(
407 AudioBuffer* audio_buffer, std::vector<float*>* channel_ptr_vector);
408
409// Generates a vector of immutable float pointers to the beginning of each
410// channel buffer in an |AudioBuffer|. The size of the |channel_ptr_vector|
411// output vector must match the number of channels in |audio_buffer|.
412//
413// @param audio_buffer Audio buffer.
414// @param channel_ptr_vector Output std::vector<const float*> vector.
415void GetRawChannelDataPointersFromAudioBuffer(
416 const AudioBuffer& audio_buffer,
417 std::vector<const float*>* channel_ptr_vector);
418
419} // namespace vraudio
420
421#endif // RESONANCE_AUDIO_UTILS_PLANAR_INTERLEAVED_CONVERSION_H_
422

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/utils/planar_interleaved_conversion.h