blob: f439dacbcff91ac562639dd1d8c62533845b0e75 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org02d71742012-04-24 19:47:00 +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
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000011#ifndef WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_
12#define WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pbos@webrtc.org8b062002013-07-12 08:28:10 +000014#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16namespace webrtc {
17
18class AudioFrame;
19
andrew@webrtc.org294be772012-05-22 03:28:41 +000020// TODO(andrew): consolidate this with utility.h and audio_frame_manipulator.h.
andrew@webrtc.org459955f2012-05-29 22:13:14 +000021// Change reference parameters to pointers. Consider using a namespace rather
22// than a class.
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000023class AudioFrameOperations {
24 public:
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000025 // Upmixes mono |src_audio| to stereo |dst_audio|. This is an out-of-place
26 // operation, meaning src_audio and dst_audio must point to different
27 // buffers. It is the caller's responsibility to ensure that |dst_audio| is
28 // sufficiently large.
29 static void MonoToStereo(const int16_t* src_audio, int samples_per_channel,
30 int16_t* dst_audio);
31 // |frame.num_channels_| will be updated. This version checks for sufficient
32 // buffer size and that |num_channels_| is mono.
33 static int MonoToStereo(AudioFrame* frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000035 // Downmixes stereo |src_audio| to mono |dst_audio|. This is an in-place
36 // operation, meaning |src_audio| and |dst_audio| may point to the same
37 // buffer.
38 static void StereoToMono(const int16_t* src_audio, int samples_per_channel,
39 int16_t* dst_audio);
40 // |frame.num_channels_| will be updated. This version checks that
41 // |num_channels_| is stereo.
42 static int StereoToMono(AudioFrame* frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000044 // Swap the left and right channels of |frame|. Fails silently if |frame| is
45 // not stereo.
46 static void SwapStereoChannels(AudioFrame* frame);
andrew@webrtc.org02d71742012-04-24 19:47:00 +000047
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000048 // Zeros out the audio and sets |frame.energy| to zero.
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000049 static void Mute(AudioFrame& frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000050
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000051 static int Scale(float left, float right, AudioFrame& frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000052
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000053 static int ScaleWithSat(float scale, AudioFrame& frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000054};
55
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000056} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000057
andrew@webrtc.org9c4f6a52012-04-26 22:32:03 +000058#endif // #ifndef WEBRTC_VOICE_ENGINE_AUDIO_FRAME_OPERATIONS_H_