ios音量线性下降

直接上代码吧

//second 几秒内下降为0
- (void)reduceVolume:(int)second {
    KGVoicePlayer *player = [KGVoicePlayer defaultPlayer];
    
    if (!_flag) {
        _tempVolume = player.volume;
        _flag = YES;
    }

    // 经测试-45db已经可以当作静音
    player.volume = dBToLinear(-4.5*(10 - second));
}

static const float M_LN = 2.30258509299404568402; /* natural log of 10 */
static inline float dBToLinear( int dB )
{
    return exp( ( dB ) * M_LN * 0.05 );
}
如果您觉得我的文章给了您帮助,请为我买一杯饮料吧!以下是我的支付宝,意思一下我将非常感激!

猜你喜欢

转载自bewithme.iteye.com/blog/2214774