From efb81d8d1f6510ff10ca34a2ee243a7ab5fbd2cd Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Wed, 16 Jul 2014 08:36:52 +0000 Subject: [PATCH] int16<->float conversions: Use size_t for array length argument, not int size_t is more appropriate for array lengths, since int might theoretically be too small for a really large array. But more importantly, if the caller's value is naturally of type size_t and the function requires an int, VC++ will trigger warning C4267 (http://msdn.microsoft.com/en-us/library/6kck0s93.aspx) because the implicit cast might be lossy, forcing the caller to do a manual cast. Typing the function with size_t in the first place resolves the problem. R=aluebs@webrtc.org, andrew@webrtc.org, minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/21909004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6702 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/common_audio/audio_util.cc | 12 ++++++------ webrtc/common_audio/include/audio_util.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/webrtc/common_audio/audio_util.cc b/webrtc/common_audio/audio_util.cc index 0c961e1ad..f2936b071 100644 --- a/webrtc/common_audio/audio_util.cc +++ b/webrtc/common_audio/audio_util.cc @@ -14,18 +14,18 @@ namespace webrtc { -void RoundToInt16(const float* src, int size, int16_t* dest) { - for (int i = 0; i < size; ++i) +void RoundToInt16(const float* src, size_t size, int16_t* dest) { + for (size_t i = 0; i < size; ++i) dest[i] = RoundToInt16(src[i]); } -void ScaleAndRoundToInt16(const float* src, int size, int16_t* dest) { - for (int i = 0; i < size; ++i) +void ScaleAndRoundToInt16(const float* src, size_t size, int16_t* dest) { + for (size_t i = 0; i < size; ++i) dest[i] = ScaleAndRoundToInt16(src[i]); } -void ScaleToFloat(const int16_t* src, int size, float* dest) { - for (int i = 0; i < size; ++i) +void ScaleToFloat(const int16_t* src, size_t size, float* dest) { + for (size_t i = 0; i < size; ++i) dest[i] = ScaleToFloat(src[i]); } diff --git a/webrtc/common_audio/include/audio_util.h b/webrtc/common_audio/include/audio_util.h index 18fdbe2ad..9972a0e06 100644 --- a/webrtc/common_audio/include/audio_util.h +++ b/webrtc/common_audio/include/audio_util.h @@ -47,14 +47,14 @@ static inline float ScaleToFloat(int16_t v) { } // Round |size| elements of |src| to int16 with clamping and write to |dest|. -void RoundToInt16(const float* src, int size, int16_t* dest); +void RoundToInt16(const float* src, size_t size, int16_t* dest); // Scale (from [-1, 1]) and round |size| elements of |src| to full-range int16 // with clamping and write to |dest|. -void ScaleAndRoundToInt16(const float* src, int size, int16_t* dest); +void ScaleAndRoundToInt16(const float* src, size_t size, int16_t* dest); // Scale |size| elements of |src| to float [-1, 1] and write to |dest|. -void ScaleToFloat(const int16_t* src, int size, float* dest); +void ScaleToFloat(const int16_t* src, size_t size, float* dest); // Deinterleave audio from |interleaved| to the channel buffers pointed to // by |deinterleaved|. There must be sufficient space allocated in the