1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 /* 3 bqaudioio 4 5 Copyright 2007-2016 Particular Programs Ltd. 6 7 Permission is hereby granted, free of charge, to any person 8 obtaining a copy of this software and associated documentation 9 files (the "Software"), to deal in the Software without 10 restriction, including without limitation the rights to use, copy, 11 modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be 16 included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 23 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26 Except as contained in this notice, the names of Chris Cannam and 27 Particular Programs Ltd shall not be used in advertising or 28 otherwise to promote the sale, use or other dealings in this 29 Software without prior written authorization. 30 */ 31 32 #ifndef BQAUDIOIO_GAINS_H 33 #define BQAUDIOIO_GAINS_H 34 35 #include <vector> 36 37 class Gains 38 { 39 public: 40 static gainsFor(float gain,float balance,size_t channelCount)41 std::vector<float> gainsFor(float gain, float balance, size_t channelCount) { 42 std::vector<float> gains(channelCount, gain); 43 for (int c = 0; c < int(channelCount); ++c) { 44 if (c == 0) { 45 if (balance > 0.f) gains[c] *= (1.0f - balance); 46 } else if (c == 1) { 47 if (balance < 0.f) gains[c] *= (balance + 1.0f); 48 } 49 } 50 return gains; 51 } 52 }; 53 54 #endif 55