2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
#include <memory>
|
2016-03-31 10:24:26 -07:00
|
|
|
#include <vector>
|
2016-02-19 07:04:49 -08:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/channel_buffer.h"
|
|
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
class PushSincResampler;
|
|
|
|
|
class SplittingFilter;
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
enum Band { kBand0To8kHz = 0, kBand8To16kHz = 1, kBand16To24kHz = 2 };
|
|
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
// Stores any audio data in a way that allows the audio processing module to
|
|
|
|
|
// operate on it in a controlled manner.
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioBuffer {
|
|
|
|
|
public:
|
2019-08-23 21:29:17 +02:00
|
|
|
static const int kSplitBandSize = 160;
|
2019-08-29 23:38:40 +02:00
|
|
|
static const size_t kMaxSampleRate = 384000;
|
2019-08-22 11:51:13 +02:00
|
|
|
AudioBuffer(size_t input_rate,
|
|
|
|
|
size_t input_num_channels,
|
|
|
|
|
size_t buffer_rate,
|
|
|
|
|
size_t buffer_num_channels,
|
|
|
|
|
size_t output_rate,
|
|
|
|
|
size_t output_num_channels);
|
|
|
|
|
|
|
|
|
|
// The constructor below will be deprecated.
|
2019-08-21 17:52:28 +00:00
|
|
|
AudioBuffer(size_t input_num_frames,
|
2019-08-22 11:51:13 +02:00
|
|
|
size_t input_num_channels,
|
|
|
|
|
size_t buffer_num_frames,
|
|
|
|
|
size_t buffer_num_channels,
|
2019-08-21 17:52:28 +00:00
|
|
|
size_t output_num_frames);
|
2011-07-07 08:21:25 +00:00
|
|
|
virtual ~AudioBuffer();
|
|
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
AudioBuffer(const AudioBuffer&) = delete;
|
|
|
|
|
AudioBuffer& operator=(const AudioBuffer&) = delete;
|
|
|
|
|
|
|
|
|
|
// Specify that downmixing should be done by selecting a single channel.
|
|
|
|
|
void set_downmixing_to_specific_channel(size_t channel);
|
|
|
|
|
|
|
|
|
|
// Specify that downmixing should be done by averaging all channels,.
|
|
|
|
|
void set_downmixing_by_averaging();
|
|
|
|
|
|
|
|
|
|
// Set the number of channels in the buffer. The specified number of channels
|
|
|
|
|
// cannot be larger than the specified buffer_num_channels. The number is also
|
|
|
|
|
// reset at each call to CopyFrom or InterleaveFrom.
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
void set_num_channels(size_t num_channels);
|
2011-09-19 15:28:51 +00:00
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
size_t num_channels() const { return num_channels_; }
|
|
|
|
|
size_t num_frames() const { return buffer_num_frames_; }
|
|
|
|
|
size_t num_frames_per_band() const { return num_split_frames_; }
|
|
|
|
|
size_t num_bands() const { return num_bands_; }
|
|
|
|
|
|
|
|
|
|
// Returns pointer arrays to the full-band channels.
|
2015-02-26 21:52:20 +00:00
|
|
|
// Usage:
|
|
|
|
|
// channels()[channel][sample].
|
|
|
|
|
// Where:
|
2019-08-22 11:51:13 +02:00
|
|
|
// 0 <= channel < |buffer_num_channels_|
|
|
|
|
|
// 0 <= sample < |buffer_num_frames_|
|
|
|
|
|
float* const* channels() { return data_->channels(); }
|
|
|
|
|
const float* const* channels_const() const { return data_->channels(); }
|
2015-02-26 21:52:20 +00:00
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
// Returns pointer arrays to the bands for a specific channel.
|
2015-02-26 21:52:20 +00:00
|
|
|
// Usage:
|
|
|
|
|
// split_bands(channel)[band][sample].
|
|
|
|
|
// Where:
|
2019-08-22 11:51:13 +02:00
|
|
|
// 0 <= channel < |buffer_num_channels_|
|
2015-02-26 21:52:20 +00:00
|
|
|
// 0 <= band < |num_bands_|
|
|
|
|
|
// 0 <= sample < |num_split_frames_|
|
2019-08-22 11:51:13 +02:00
|
|
|
const float* const* split_bands_const(size_t channel) const {
|
|
|
|
|
return split_data_.get() ? split_data_->bands(channel)
|
|
|
|
|
: data_->bands(channel);
|
|
|
|
|
}
|
|
|
|
|
float* const* split_bands(size_t channel) {
|
|
|
|
|
return split_data_.get() ? split_data_->bands(channel)
|
|
|
|
|
: data_->bands(channel);
|
|
|
|
|
}
|
2015-02-26 21:52:20 +00:00
|
|
|
|
|
|
|
|
// Returns a pointer array to the channels for a specific band.
|
|
|
|
|
// Usage:
|
|
|
|
|
// split_channels(band)[channel][sample].
|
|
|
|
|
// Where:
|
|
|
|
|
// 0 <= band < |num_bands_|
|
2019-08-22 11:51:13 +02:00
|
|
|
// 0 <= channel < |buffer_num_channels_|
|
2015-02-26 21:52:20 +00:00
|
|
|
// 0 <= sample < |num_split_frames_|
|
2019-08-22 11:51:13 +02:00
|
|
|
const float* const* split_channels_const(Band band) const {
|
|
|
|
|
if (split_data_.get()) {
|
|
|
|
|
return split_data_->channels(band);
|
|
|
|
|
} else {
|
|
|
|
|
return band == kBand0To8kHz ? data_->channels() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copies data into the buffer.
|
2020-03-16 12:06:02 +01:00
|
|
|
void CopyFrom(const int16_t* const interleaved_data,
|
|
|
|
|
const StreamConfig& stream_config);
|
|
|
|
|
void CopyFrom(const float* const* stacked_data,
|
|
|
|
|
const StreamConfig& stream_config);
|
2019-08-22 11:51:13 +02:00
|
|
|
|
|
|
|
|
// Copies data from the buffer.
|
2020-03-16 12:06:02 +01:00
|
|
|
void CopyTo(const StreamConfig& stream_config,
|
|
|
|
|
int16_t* const interleaved_data);
|
|
|
|
|
void CopyTo(const StreamConfig& stream_config, float* const* stacked_data);
|
2019-10-09 13:02:14 +02:00
|
|
|
void CopyTo(AudioBuffer* buffer) const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
// Splits the buffer data into frequency bands.
|
2014-11-14 22:18:10 +00:00
|
|
|
void SplitIntoFrequencyBands();
|
2019-08-22 11:51:13 +02:00
|
|
|
|
|
|
|
|
// Recombines the frequency bands into a full-band signal.
|
2014-11-14 22:18:10 +00:00
|
|
|
void MergeFrequencyBands();
|
|
|
|
|
|
2019-08-20 09:19:21 +02:00
|
|
|
// Copies the split bands data into the integer two-dimensional array.
|
2019-11-22 18:22:04 +01:00
|
|
|
void ExportSplitChannelData(size_t channel,
|
|
|
|
|
int16_t* const* split_band_data) const;
|
2019-08-20 09:19:21 +02:00
|
|
|
|
|
|
|
|
// Copies the data in the integer two-dimensional array into the split_bands
|
|
|
|
|
// data.
|
2019-08-22 11:51:13 +02:00
|
|
|
void ImportSplitChannelData(size_t channel,
|
|
|
|
|
const int16_t* const* split_band_data);
|
2019-08-20 09:19:21 +02:00
|
|
|
|
|
|
|
|
static const size_t kMaxSplitFrameLength = 160;
|
|
|
|
|
static const size_t kMaxNumBands = 3;
|
|
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
// Deprecated methods, will be removed soon.
|
|
|
|
|
float* const* channels_f() { return channels(); }
|
|
|
|
|
const float* const* channels_const_f() const { return channels_const(); }
|
|
|
|
|
const float* const* split_bands_const_f(size_t channel) const {
|
|
|
|
|
return split_bands_const(channel);
|
|
|
|
|
}
|
|
|
|
|
float* const* split_bands_f(size_t channel) { return split_bands(channel); }
|
|
|
|
|
const float* const* split_channels_const_f(Band band) const {
|
|
|
|
|
return split_channels_const(band);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2016-06-30 15:33:37 -07:00
|
|
|
FRIEND_TEST_ALL_PREFIXES(AudioBufferTest,
|
|
|
|
|
SetNumChannelsSetsChannelBuffersNumChannels);
|
2019-08-22 11:51:13 +02:00
|
|
|
void RestoreNumChannels();
|
2014-03-04 20:58:13 +00:00
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t input_num_frames_;
|
2019-08-22 11:51:13 +02:00
|
|
|
const size_t input_num_channels_;
|
|
|
|
|
const size_t buffer_num_frames_;
|
|
|
|
|
const size_t buffer_num_channels_;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t output_num_frames_;
|
2019-08-22 11:51:13 +02:00
|
|
|
const size_t output_num_channels_;
|
2019-08-21 17:52:28 +00:00
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
size_t num_channels_;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t num_bands_;
|
|
|
|
|
size_t num_split_frames_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-08-22 11:51:13 +02:00
|
|
|
std::unique_ptr<ChannelBuffer<float>> data_;
|
|
|
|
|
std::unique_ptr<ChannelBuffer<float>> split_data_;
|
2016-02-19 07:04:49 -08:00
|
|
|
std::unique_ptr<SplittingFilter> splitting_filter_;
|
2016-03-31 10:24:26 -07:00
|
|
|
std::vector<std::unique_ptr<PushSincResampler>> input_resamplers_;
|
|
|
|
|
std::vector<std::unique_ptr<PushSincResampler>> output_resamplers_;
|
2019-08-22 11:51:13 +02:00
|
|
|
bool downmix_by_averaging_ = true;
|
|
|
|
|
size_t channel_for_downmixing_ = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_AUDIO_BUFFER_H_
|