[RK3288][Android6.0] Audio中的放音重采样小结

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

AudioFlinger::MixerThread::prepareTracks_l -> Threads.cpp
  mAudioMixer->setParameter -> //参数有AudioMixer::RESAMPLE
    AudioMixer::setParameter -> AudioMixer.cpp
      track.setResampler ->
        AudioMixer::track_t::setResampler //trackSampleRate为源,devSampleRate为硬件支持采样率。


bool AudioMixer::track_t::setResampler(uint32_t trackSampleRate, uint32_t devSampleRate)
{
    if (trackSampleRate != devSampleRate || resampler != NULL) {
        if (sampleRate != trackSampleRate) {
            sampleRate = trackSampleRate;
            if (resampler == NULL) {
                ALOGV("Creating resampler from track %d Hz to device %d Hz",
                        trackSampleRate, devSampleRate);
                AudioResampler::src_quality quality;
......
//如果是采样率低于AUDIO_PROCESSING_MUSIC_RATE即40k,那么就用最低质量DYN_LOW_QUALITY。
//如果你对音频的质量有要求,可以修改此值,当然质量越高,肯定越耗cpu.
                if (isMusicRate(trackSampleRate)) {
                    quality = AudioResampler::DEFAULT_QUALITY;
                } else {
                    quality = AudioResampler::DYN_LOW_QUALITY;
                }
......
//和录音重采样用的同一个接口。
                resampler = AudioResampler::create(
                        mMixerInFormat,
                        resamplerChannelCount,
                        devSampleRate, quality);
                resampler->setLocalTimeFreq(sLocalTimeFreq);
            }
            return true;
        }
    }
    return false;
}


AudioResampler::create():
AudioResampler* AudioResampler::create(audio_format_t format, int inChannelCount,  
        int32_t sampleRate, src_quality quality) {  
......  
    //根据不同的quality选择不同的采样算法  
    case LOW_QUALITY:  
        ALOGV("Create linear Resampler");  
        LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT);  
        resampler = new AudioResamplerOrder1(inChannelCount, sampleRate);  
        break;  
    case MED_QUALITY:  
        ALOGV("Create cubic Resampler");  
        LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT);  
        resampler = new AudioResamplerCubic(inChannelCount, sampleRate);  
        break;  
    case HIGH_QUALITY:  
        ALOGV("Create HIGH_QUALITY sinc Resampler");  
        LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT);  
        resampler = new AudioResamplerSinc(inChannelCount, sampleRate);  
        break;  
    case VERY_HIGH_QUALITY:  
        ALOGV("Create VERY_HIGH_QUALITY sinc Resampler = %d", quality);  
        LOG_ALWAYS_FATAL_IF(format != AUDIO_FORMAT_PCM_16_BIT);  
        resampler = new AudioResamplerSinc(inChannelCount, sampleRate, quality);  
        break;  
    case DYN_LOW_QUALITY:  
    case DYN_MED_QUALITY:  
    case DYN_HIGH_QUALITY:  
......  
            resampler = new AudioResamplerDyn<float, float, float>(inChannelCount,  
......  
} 

参考:
http://blog.csdn.net/kris_fei/article/details/72830677
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页