本文整理汇总了C++中QAudioFormat::bytesPerFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::bytesPerFrame方法的具体用法?C++ QAudioFormat::bytesPerFrame怎么用?C++ QAudioFormat::bytesPerFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::bytesPerFrame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void AudioBuffer::init(QAudioBuffer &qtbuffer){
qDebug() << "void AudioBuffer::init(...) called";
QAudioFormat audioFormat = qtbuffer.format();
this->hzFreq = audioFormat.sampleRate();
this->durationInMs = qtbuffer.duration()*1000;
QAudioFormat::SampleType sampleType
= audioFormat.sampleType();
int frameCount = qtbuffer.frameCount();
int nChannels = audioFormat.channelCount();
int bytesPerFrame = audioFormat.bytesPerFrame();
int bytesPerValue = bytesPerFrame/nChannels;
void *firstData = qtbuffer.data();
this->bufferSize = frameCount;
this->buffer = QSharedPointer<SharedBuffer>(
new SharedBuffer);
this->buffer->buffer = new int[this->bufferSize];
this->mean = 0;
const int tempReducFactor = 500;
qint64 meanOfSquare = 0;
for(int i=0; i<frameCount; i++){
int currentValue = 0;
for(int j=0; j<nChannels; j++){
int currentPos
= i*bytesPerFrame
+ j*bytesPerValue;
void *valPos = (void *)(((quint8 *)firstData) + currentPos);
if(sampleType == QAudioFormat::SignedInt){
if(bytesPerValue == 1){
quint8 val = *((quint8*)valPos);
currentValue += val;
}else if(bytesPerValue == 2){
quint16 val = *((quint16*)valPos);
currentValue += val;
}else if(bytesPerValue == 4){
quint32 val = *((quint32*)valPos);
currentValue += val;
}else if(bytesPerValue == 8){
quint64 val = *((quint64*)valPos);
currentValue += val;
}
}else if(sampleType == QAudioFormat::UnSignedInt){
if(bytesPerValue == 1){
qint8 val = *((qint8*)valPos);
currentValue += val;
}else if(bytesPerValue == 2){
qint16 val = *((qint16*)valPos);
currentValue += val;
}else if(bytesPerValue == 4){
qint32 val = *((qint32*)valPos);
currentValue += val;
}else if(bytesPerValue == 8){
qint64 val = *((qint64*)valPos);
currentValue += val;
}
}else if(sampleType == QAudioFormat::Float){
qreal val = *((qreal*)valPos);
currentValue += val;
}
}
currentValue /= nChannels;
currentValue /= tempReducFactor;
this->buffer->buffer[i] = currentValue;
this->mean += currentValue;
meanOfSquare += currentValue*currentValue;
if(meanOfSquare < 0){
Q_ASSERT(false);
}
}
this->mean /= frameCount;
meanOfSquare /= frameCount;
qint64 squaredMean =
this->mean
* this->mean;
this->var = meanOfSquare
- squaredMean;
this->var *= tempReducFactor * tempReducFactor;
this->mean *= tempReducFactor;
this->sd = qSqrt(this->var);
qDebug() << "void AudioBuffer::init(...) end";
}