IRatePitch.c revision 262059f71a68edc5e510427c63f5f1623d3672a8
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 21 22static SLresult IRatePitch_SetRate(SLRatePitchItf self, SLpermille rate) 23{ 24 SL_ENTER_INTERFACE 25 26 IRatePitch *this = (IRatePitch *) self; 27 if (!(this->mMinRate <= rate && rate <= this->mMaxRate)) { 28 result = SL_RESULT_PARAMETER_INVALID; 29 } else { 30 interface_lock_poke(this); 31 this->mRate = rate; 32 interface_unlock_poke(this); 33 result = SL_RESULT_SUCCESS; 34 } 35 36 SL_LEAVE_INTERFACE 37} 38 39 40static SLresult IRatePitch_GetRate(SLRatePitchItf self, SLpermille *pRate) 41{ 42 SL_ENTER_INTERFACE 43 44 if (NULL == pRate) { 45 result = SL_RESULT_PARAMETER_INVALID; 46 } else { 47 IRatePitch *this = (IRatePitch *) self; 48 interface_lock_peek(this); 49 SLpermille rate = this->mRate; 50 interface_unlock_peek(this); 51 *pRate = rate; 52 result = SL_RESULT_SUCCESS; 53 } 54 55 SL_LEAVE_INTERFACE 56} 57 58 59static SLresult IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self, 60 SLpermille *pMinRate, SLpermille *pMaxRate) 61{ 62 SL_ENTER_INTERFACE 63 64 // per spec, each is optional, and does not require that at least one must be non-NULL 65#if 0 66 if (NULL == pMinRate && NULL == pMaxRate) 67 result = SL_RESULT_PARAMETER_INVALID; 68#endif 69 IRatePitch *this = (IRatePitch *) self; 70 // const, so no lock required 71 SLpermille minRate = this->mMinRate; 72 SLpermille maxRate = this->mMaxRate; 73 if (NULL != pMinRate) 74 *pMinRate = minRate; 75 if (NULL != pMaxRate) 76 *pMaxRate = maxRate; 77 result = SL_RESULT_SUCCESS; 78 79 SL_LEAVE_INTERFACE 80} 81 82 83static const struct SLRatePitchItf_ IRatePitch_Itf = { 84 IRatePitch_SetRate, 85 IRatePitch_GetRate, 86 IRatePitch_GetRatePitchCapabilities 87}; 88 89void IRatePitch_init(void *self) 90{ 91 IRatePitch *this = (IRatePitch *) self; 92 this->mItf = &IRatePitch_Itf; 93 this->mRate = 1000; 94 // const 95 this->mMinRate = 500; 96 this->mMaxRate = 2000; 97} 98