Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: webrtc/common_audio/blocker.h

Issue 1227203003: Update audio code to use size_t more correctly, webrtc/common_audio/ portion. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/common_audio/audio_util_unittest.cc ('k') | webrtc/common_audio/blocker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ 11 #ifndef WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
12 #define WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ 12 #define WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
13 13
14 #include "webrtc/base/scoped_ptr.h" 14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/common_audio/audio_ring_buffer.h" 15 #include "webrtc/common_audio/audio_ring_buffer.h"
16 #include "webrtc/common_audio/channel_buffer.h" 16 #include "webrtc/common_audio/channel_buffer.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 // The callback function to process audio in the time domain. Input has already 20 // The callback function to process audio in the time domain. Input has already
21 // been windowed, and output will be windowed. The number of input channels 21 // been windowed, and output will be windowed. The number of input channels
22 // must be >= the number of output channels. 22 // must be >= the number of output channels.
23 class BlockerCallback { 23 class BlockerCallback {
24 public: 24 public:
25 virtual ~BlockerCallback() {} 25 virtual ~BlockerCallback() {}
26 26
27 virtual void ProcessBlock(const float* const* input, 27 virtual void ProcessBlock(const float* const* input,
28 int num_frames, 28 size_t num_frames,
29 int num_input_channels, 29 int num_input_channels,
30 int num_output_channels, 30 int num_output_channels,
31 float* const* output) = 0; 31 float* const* output) = 0;
32 }; 32 };
33 33
34 // The main purpose of Blocker is to abstract away the fact that often we 34 // The main purpose of Blocker is to abstract away the fact that often we
35 // receive a different number of audio frames than our transform takes. For 35 // receive a different number of audio frames than our transform takes. For
36 // example, most FFTs work best when the fft-size is a power of 2, but suppose 36 // example, most FFTs work best when the fft-size is a power of 2, but suppose
37 // we receive 20ms of audio at a sample rate of 48000. That comes to 960 frames 37 // we receive 20ms of audio at a sample rate of 48000. That comes to 960 frames
38 // of audio, which is not a power of 2. Blocker allows us to specify the 38 // of audio, which is not a power of 2. Blocker allows us to specify the
(...skipping 17 matching lines...) Expand all
56 // 2. Instantiate a Blocker object |b|, passing in |bc|. 56 // 2. Instantiate a Blocker object |b|, passing in |bc|.
57 // 3. As you receive audio, call b.ProcessChunk() to get processed audio. 57 // 3. As you receive audio, call b.ProcessChunk() to get processed audio.
58 // 58 //
59 // A small amount of delay is added to the first received chunk to deal with 59 // A small amount of delay is added to the first received chunk to deal with
60 // the difference in chunk/block sizes. This delay is <= chunk_size. 60 // the difference in chunk/block sizes. This delay is <= chunk_size.
61 // 61 //
62 // Ownership of window is retained by the caller. That is, Blocker makes a 62 // Ownership of window is retained by the caller. That is, Blocker makes a
63 // copy of window and does not attempt to delete it. 63 // copy of window and does not attempt to delete it.
64 class Blocker { 64 class Blocker {
65 public: 65 public:
66 Blocker(int chunk_size, 66 Blocker(size_t chunk_size,
67 int block_size, 67 size_t block_size,
68 int num_input_channels, 68 int num_input_channels,
69 int num_output_channels, 69 int num_output_channels,
70 const float* window, 70 const float* window,
71 int shift_amount, 71 size_t shift_amount,
72 BlockerCallback* callback); 72 BlockerCallback* callback);
73 73
74 void ProcessChunk(const float* const* input, 74 void ProcessChunk(const float* const* input,
75 int chunk_size, 75 size_t chunk_size,
76 int num_input_channels, 76 int num_input_channels,
77 int num_output_channels, 77 int num_output_channels,
78 float* const* output); 78 float* const* output);
79 79
80 private: 80 private:
81 const int chunk_size_; 81 const size_t chunk_size_;
82 const int block_size_; 82 const size_t block_size_;
83 const int num_input_channels_; 83 const int num_input_channels_;
84 const int num_output_channels_; 84 const int num_output_channels_;
85 85
86 // The number of frames of delay to add at the beginning of the first chunk. 86 // The number of frames of delay to add at the beginning of the first chunk.
87 const int initial_delay_; 87 const size_t initial_delay_;
88 88
89 // The frame index into the input buffer where the first block should be read 89 // The frame index into the input buffer where the first block should be read
90 // from. This is necessary because shift_amount_ is not necessarily a 90 // from. This is necessary because shift_amount_ is not necessarily a
91 // multiple of chunk_size_, so blocks won't line up at the start of the 91 // multiple of chunk_size_, so blocks won't line up at the start of the
92 // buffer. 92 // buffer.
93 int frame_offset_; 93 size_t frame_offset_;
94 94
95 // Since blocks nearly always overlap, there are certain blocks that require 95 // Since blocks nearly always overlap, there are certain blocks that require
96 // frames from the end of one chunk and the beginning of the next chunk. The 96 // frames from the end of one chunk and the beginning of the next chunk. The
97 // input and output buffers are responsible for saving those frames between 97 // input and output buffers are responsible for saving those frames between
98 // calls to ProcessChunk(). 98 // calls to ProcessChunk().
99 // 99 //
100 // Both contain |initial delay| + |chunk_size| frames. The input is a fairly 100 // Both contain |initial delay| + |chunk_size| frames. The input is a fairly
101 // standard FIFO, but due to the overlap-add it's harder to use an 101 // standard FIFO, but due to the overlap-add it's harder to use an
102 // AudioRingBuffer for the output. 102 // AudioRingBuffer for the output.
103 AudioRingBuffer input_buffer_; 103 AudioRingBuffer input_buffer_;
104 ChannelBuffer<float> output_buffer_; 104 ChannelBuffer<float> output_buffer_;
105 105
106 // Space for the input block (can't wrap because of windowing). 106 // Space for the input block (can't wrap because of windowing).
107 ChannelBuffer<float> input_block_; 107 ChannelBuffer<float> input_block_;
108 108
109 // Space for the output block (can't wrap because of overlap/add). 109 // Space for the output block (can't wrap because of overlap/add).
110 ChannelBuffer<float> output_block_; 110 ChannelBuffer<float> output_block_;
111 111
112 rtc::scoped_ptr<float[]> window_; 112 rtc::scoped_ptr<float[]> window_;
113 113
114 // The amount of frames between the start of contiguous blocks. For example, 114 // The amount of frames between the start of contiguous blocks. For example,
115 // |shift_amount_| = |block_size_| / 2 for a Hann window. 115 // |shift_amount_| = |block_size_| / 2 for a Hann window.
116 int shift_amount_; 116 size_t shift_amount_;
117 117
118 BlockerCallback* callback_; 118 BlockerCallback* callback_;
119 }; 119 };
120 120
121 } // namespace webrtc 121 } // namespace webrtc
122 122
123 #endif // WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ 123 #endif // WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
OLDNEW
« no previous file with comments | « webrtc/common_audio/audio_util_unittest.cc ('k') | webrtc/common_audio/blocker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698