I multiplied the samples by the AVPlayer's volume level and then do an RMS calculation on the resulting samples.
I send the leftVol and rightVol values off to a NSLevelIndicator instances -- on which I then do a pair of clever NSView overlays to get a lagging indication of peak volume levels.
float scalar = player.volume;
for (NSInteger i=0; i<bufferListInOut->mNumberBuffers; i++)
vDSP_vsmul(bufferListInOut->mBuffers[i].mData, 1, &scalar,
bufferListInOut->mBuffers[i].mData, 1,
bufferListInOut->mBuffers[i].mDataByteSize / sizeof(float));
float leftVol, rightVol;
for (NSInteger i=0; i<bufferListInOut->mNumberBuffers; i++) {
AudioBuffer *pBuffer = &bufferListInOut->mBuffers[i];
float rms = 0.0f;
vDSP_rmsqv(pBuffer->mData, 1, &rms, numberFrames*pBuffer->mNumberChannels);
if (i==0)
leftVol = rms;
if (i==1)
rightVol = rms;
}
Topic:
Media Technologies
SubTopic:
Audio
Tags: