blob: 87003c42581cd99337e3176fb3b1c2c772d438bc [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
braveyao@webrtc.orgd7131432012-03-29 10:39:44 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11/*
12 * Contains functions often used by different parts of VoiceEngine.
13 */
14
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000015#ifndef WEBRTC_VOICE_ENGINE_UTILITY_H_
16#define WEBRTC_VOICE_ENGINE_UTILITY_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000017
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +000018#include "webrtc/common_audio/resampler/include/push_resampler.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000019#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000023class AudioFrame;
niklase@google.com470e71d2011-07-07 08:21:25 +000024
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000025namespace voe {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000027// Upmix or downmix and resample the audio in |src_frame| to |dst_frame|.
andrew@webrtc.org1fddd612014-05-30 17:28:50 +000028// Expects |dst_frame| to have its sample rate and channels members set to the
29// desired values. Updates the samples per channel member accordingly. No other
30// members will be changed.
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000031void RemixAndResample(const AudioFrame& src_frame,
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +000032 PushResampler<int16_t>* resampler,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000033 AudioFrame* dst_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000035// Downmix and downsample the audio in |src_data| to |dst_af| as necessary,
36// specified by |codec_num_channels| and |codec_rate_hz|. |mono_buffer| is
37// temporary space and must be of sufficient size to hold the downmixed source
38// audio (recommend using a size of kMaxMonoDataSizeSamples).
andrew@webrtc.org1fddd612014-05-30 17:28:50 +000039//
40// |dst_af| will have its data and format members (sample rate, channels and
41// samples per channel) set appropriately. No other members will be changed.
42// TODO(ajm): For now, this still calls Reset() on |dst_af|. Remove this, as
43// it shouldn't be needed.
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000044void DownConvertToCodecFormat(const int16_t* src_data,
Peter Kastingdce40cf2015-08-24 14:52:23 -070045 size_t samples_per_channel,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000046 int num_channels,
47 int sample_rate_hz,
48 int codec_num_channels,
49 int codec_rate_hz,
50 int16_t* mono_buffer,
andrew@webrtc.orgf5a33f12014-04-19 00:32:07 +000051 PushResampler<int16_t>* resampler,
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000052 AudioFrame* dst_af);
niklase@google.com470e71d2011-07-07 08:21:25 +000053
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000054void MixWithSat(int16_t target[],
55 int target_channel,
56 const int16_t source[],
57 int source_channel,
Peter Kastingdce40cf2015-08-24 14:52:23 -070058 size_t source_len);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000060} // namespace voe
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000061} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000062
andrew@webrtc.org40ee3d02014-04-03 21:56:01 +000063#endif // WEBRTC_VOICE_ENGINE_UTILITY_H_