AudioQueueGetProperty返回kAudioQueueProperty_CurrentLevelMeter属性的范围外的值

时间:2022-03-21 16:44:17

I'm writing an application that requires the user be in a quiet environment. To do this, I periodically check the power reading off the microphone. (I'm aware of the returned value being in dBFS or, in this case, a float in the interval [0, 1]. )

我正在编写一个应用程序,它要求用户处于安静的环境中。为此,我定期检查麦克风的电源读数。(我知道返回值在dBFS中,或者在本例中,在区间[0,1]中有一个浮点数)。

My problem is that the below code works just fine... except when it returns 18466064732283753157623808.00000. I see no NSLog output indicating AudioQueueGetProperty returning a failure. The weird value is always the mentioned value.

我的问题是下面的代码很好…除非返回18466064732283753157623808.00000。我没有看到显示AudioQueueGetProperty返回失败的NSLog输出。奇怪的值总是被提到的值。

-(float)instantaneousPeakPower {
  UInt32 dataSize = sizeof(AudioQueueLevelMeterState) * recordFormat.mChannelsPerFrame;
  AudioQueueLevelMeterState *levels = (AudioQueueLevelMeterState*)malloc(dataSize);

  OSStatus rc = AudioQueueGetProperty(audioQueue, kAudioQueueProperty_CurrentLevelMeter, levels, &dataSize);
  if (rc) {
    NSLog(@"NoiseLeveMeter>>takeSample - AudioQueueGetProperty(CurrentLevelMeter) returned %@", rc);
  }

  float channelAvg = 0;
  for (int i = 0; i < recordFormat.mChannelsPerFrame; i++) {
    channelAvg += levels[i].mPeakPower;
  }
  free(levels);

  // This works because in this particular case one channel always has an mAveragePower of 0.
  return channelAvg;
}

What gives? Does the bit pattern of the value perhaps give a clue?

到底发生了什么事?值的位模式可能提供线索吗?

1 个解决方案

#1


6  

Did you enabled audio level metering?

你启用了音频电平测量吗?

UInt32 trueValue = true;
AudioQueueSetProperty(audioQueue,kAudioQueueProperty_EnableLevelMetering,&trueValue,sizeof (UInt32));

#1


6  

Did you enabled audio level metering?

你启用了音频电平测量吗?

UInt32 trueValue = true;
AudioQueueSetProperty(audioQueue,kAudioQueueProperty_EnableLevelMetering,&trueValue,sizeof (UInt32));