IRatePitch.c revision d2a7f0d6883a6d3835642e7b282f05ed1c54fe63
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17/* RatePitch implementation */ 18 19#include "sles_allinclusive.h" 20 21static SLresult IRatePitch_SetRate(SLRatePitchItf self, SLpermille rate) 22{ 23 IRatePitch *this = (IRatePitch *) self; 24 if (!(this->mMinRate <= rate && rate <= this->mMaxRate)) 25 return SL_RESULT_PARAMETER_INVALID; 26 interface_lock_poke(this); 27 this->mRate = rate; 28 interface_unlock_poke(this); 29 return SL_RESULT_SUCCESS; 30} 31 32static SLresult IRatePitch_GetRate(SLRatePitchItf self, SLpermille *pRate) 33{ 34 if (NULL == pRate) 35 return SL_RESULT_PARAMETER_INVALID; 36 IRatePitch *this = (IRatePitch *) self; 37 interface_lock_peek(this); 38 SLpermille rate = this->mRate; 39 interface_unlock_peek(this); 40 *pRate = rate; 41 return SL_RESULT_SUCCESS; 42} 43 44static SLresult IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self, 45 SLpermille *pMinRate, SLpermille *pMaxRate) 46{ 47 // per spec, each is optional, and does not require that at least one must be non-NULL 48#if 0 49 if (NULL == pMinRate && NULL == pMaxRate) 50 return SL_RESULT_PARAMETER_INVALID; 51#endif 52 IRatePitch *this = (IRatePitch *) self; 53 // const, so no lock required 54 SLpermille minRate = this->mMinRate; 55 SLpermille maxRate = this->mMaxRate; 56 if (NULL != pMinRate) 57 *pMinRate = minRate; 58 if (NULL != pMaxRate) 59 *pMaxRate = maxRate; 60 return SL_RESULT_SUCCESS; 61} 62 63static const struct SLRatePitchItf_ IRatePitch_Itf = { 64 IRatePitch_SetRate, 65 IRatePitch_GetRate, 66 IRatePitch_GetRatePitchCapabilities 67}; 68 69void IRatePitch_init(void *self) 70{ 71 IRatePitch *this = (IRatePitch *) self; 72 this->mItf = &IRatePitch_Itf; 73 this->mRate = 0; 74 // const 75 this->mMinRate = 500; 76 this->mMaxRate = 2000; 77} 78