OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 RawFile* raw_file) { | 68 RawFile* raw_file) { |
69 if (wav_file) { | 69 if (wav_file) { |
70 wav_file->WriteSamples(data, length); | 70 wav_file->WriteSamples(data, length); |
71 } | 71 } |
72 if (raw_file) { | 72 if (raw_file) { |
73 raw_file->WriteSamples(data, length); | 73 raw_file->WriteSamples(data, length); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void WriteFloatData(const float* const* data, | 77 void WriteFloatData(const float* const* data, |
78 int samples_per_channel, | 78 size_t samples_per_channel, |
79 int num_channels, | 79 int num_channels, |
80 WavWriter* wav_file, | 80 WavWriter* wav_file, |
81 RawFile* raw_file) { | 81 RawFile* raw_file) { |
82 size_t length = num_channels * samples_per_channel; | 82 size_t length = num_channels * samples_per_channel; |
83 rtc::scoped_ptr<float[]> buffer(new float[length]); | 83 rtc::scoped_ptr<float[]> buffer(new float[length]); |
84 Interleave(data, samples_per_channel, num_channels, buffer.get()); | 84 Interleave(data, samples_per_channel, num_channels, buffer.get()); |
85 if (raw_file) { | 85 if (raw_file) { |
86 raw_file->WriteSamples(buffer.get(), length); | 86 raw_file->WriteSamples(buffer.get(), length); |
87 } | 87 } |
88 // TODO(aluebs): Use ScaleToInt16Range() from audio_util | 88 // TODO(aluebs): Use ScaleToInt16Range() from audio_util |
89 for (size_t i = 0; i < length; ++i) { | 89 for (size_t i = 0; i < length; ++i) { |
90 buffer[i] = buffer[i] > 0 ? | 90 buffer[i] = buffer[i] > 0 ? |
91 buffer[i] * std::numeric_limits<int16_t>::max() : | 91 buffer[i] * std::numeric_limits<int16_t>::max() : |
92 -buffer[i] * std::numeric_limits<int16_t>::min(); | 92 -buffer[i] * std::numeric_limits<int16_t>::min(); |
93 } | 93 } |
94 if (wav_file) { | 94 if (wav_file) { |
95 wav_file->WriteSamples(buffer.get(), length); | 95 wav_file->WriteSamples(buffer.get(), length); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 FILE* OpenFile(const std::string& filename, const char* mode) { | 99 FILE* OpenFile(const std::string& filename, const char* mode) { |
100 FILE* file = fopen(filename.c_str(), mode); | 100 FILE* file = fopen(filename.c_str(), mode); |
101 if (!file) { | 101 if (!file) { |
102 printf("Unable to open file %s\n", filename.c_str()); | 102 printf("Unable to open file %s\n", filename.c_str()); |
103 exit(1); | 103 exit(1); |
104 } | 104 } |
105 return file; | 105 return file; |
106 } | 106 } |
107 | 107 |
108 int SamplesFromRate(int rate) { | 108 size_t SamplesFromRate(int rate) { |
109 return AudioProcessing::kChunkSizeMs * rate / 1000; | 109 return static_cast<size_t>(AudioProcessing::kChunkSizeMs * rate / 1000); |
110 } | 110 } |
111 | 111 |
112 void SetFrameSampleRate(AudioFrame* frame, | 112 void SetFrameSampleRate(AudioFrame* frame, |
113 int sample_rate_hz) { | 113 int sample_rate_hz) { |
114 frame->sample_rate_hz_ = sample_rate_hz; | 114 frame->sample_rate_hz_ = sample_rate_hz; |
115 frame->samples_per_channel_ = AudioProcessing::kChunkSizeMs * | 115 frame->samples_per_channel_ = AudioProcessing::kChunkSizeMs * |
116 sample_rate_hz / 1000; | 116 sample_rate_hz / 1000; |
117 } | 117 } |
118 | 118 |
119 AudioProcessing::ChannelLayout LayoutFromChannels(int num_channels) { | 119 AudioProcessing::ChannelLayout LayoutFromChannels(int num_channels) { |
(...skipping 25 matching lines...) Expand all Loading... |
145 | 145 |
146 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, | 146 std::vector<Point> ParseArrayGeometry(const std::string& mic_positions, |
147 size_t num_mics) { | 147 size_t num_mics) { |
148 std::vector<Point> result = ParseArrayGeometry(mic_positions); | 148 std::vector<Point> result = ParseArrayGeometry(mic_positions); |
149 RTC_CHECK_EQ(result.size(), num_mics) | 149 RTC_CHECK_EQ(result.size(), num_mics) |
150 << "Could not parse mic_positions or incorrect number of points."; | 150 << "Could not parse mic_positions or incorrect number of points."; |
151 return result; | 151 return result; |
152 } | 152 } |
153 | 153 |
154 } // namespace webrtc | 154 } // namespace webrtc |
OLD | NEW |