使用OpenSLES更改声音播放速度的简便方法

时间:2018-09-19 10:55:22

标签: android opensl

我在Android上使用OpenSLES从WAV资源(已加载QT)播放声音,其代码如下:

SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};

SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 2, SL_SAMPLINGRATE_44_1,
    SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
    SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT, SL_BYTEORDER_LITTLEENDIAN};

SLDataSource audioSrc = {&loc_bufq, &format_pcm};

// configure audio sink
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, oslContext.GetOutputMixObject()};
SLDataSink audioSnk = {&loc_outmix, nullptr};

//create audio player: fast audio does not support when SL_IID_EFFECTSEND is required, skip it for fast audio case

const SLInterfaceID ids[2] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_VOLUME};
const SLboolean req[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};

auto engine = oslContext.GetEngine();

CheckOsl((*engine)->CreateAudioPlayer(engine, &playerObj, &audioSrc, &audioSnk, 2, ids, req));

// realize the player
CheckOsl((*playerObj)->Realize(playerObj, SL_BOOLEAN_FALSE));

// get the play interface
CheckOsl((*playerObj)->GetInterface(playerObj, SL_IID_PLAY, &playI));

// get the buffer queue interface
CheckOsl((*playerObj)->GetInterface(playerObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueueI));

// get the volume interface
CheckOsl((*playerObj)->GetInterface(playerObj, SL_IID_VOLUME, &volumeI));

// register callback on the buffer queue
CheckOsl((*bufferQueueI)->RegisterCallback(bufferQueueI, OnBufferQueueEvent, this));

然后我打电话

CheckOsl((*bufferQueueI)->Enqueue(bufferQueueI, GetBuffer() , GetSize()));

如何更改声音播放速度以使声音“ ggggg”像“ gggggggggggg”或“ gg”一样播放,但不像“ zzzzz”或“ sssssss”(不失真)播放?

0 个答案:

没有答案