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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioUtilities.cpp

Issue 2582323003: Test for power of two safely (Closed)
Patch Set: Created 3 years, 12 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 float minAudioBufferSampleRate() { 66 float minAudioBufferSampleRate() {
67 // crbug.com/344375 67 // crbug.com/344375
68 return 3000; 68 return 3000;
69 } 69 }
70 70
71 float maxAudioBufferSampleRate() { 71 float maxAudioBufferSampleRate() {
72 // <video> tags support sample rates up 384 kHz so audio context 72 // <video> tags support sample rates up 384 kHz so audio context
73 // should too. 73 // should too.
74 return 384000; 74 return 384000;
75 } 75 }
76
77 bool isPowerOfTwo(size_t x) {
78 // From Hacker's Delight. x & (x - 1) turns off (zeroes) the
79 // rightmost 1-bit in the word x. If x is a power of two, then the
80 // result is, of course, 0.
81 return x > 0 && ((x & (x - 1)) == 0);
82 }
83
76 } // namespace AudioUtilities 84 } // namespace AudioUtilities
77 85
78 } // namespace blink 86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698