1 Reply
      Latest reply on Feb 6, 2020 8:15 AM by Claude31
      TatianaMrl Level 1 Level 1 (0 points)

        Our question is about an AudioToolbox framework:

        In what time interval is measured the "mAveragePower" value in "AudioQueueLevelMeterState struct" ?

         

        Our app shows a decibel value to user.

        The code that we use for init an AudioQueue:

         

        fmt.mFormatID         = kAudioFormatLinearPCM;

        fmt.mSampleRate       = 8000.0;

        fmt.mChannelsPerFrame = 1;

        fmt.mBitsPerChannel   = 16;

        fmt.mChannelsPerFrame = 1;

        fmt.mFramesPerPacket  = 1;

        fmt.mBytesPerFrame = sizeof (SInt16);

        fmt.mBytesPerPacket = sizeof (SInt16);

         

         

        fmt.mFormatFlags =  kLinearPCMFormatFlagIsSignedInteger  | kLinearPCMFormatFlagIsPacked;

         

              __block OSStatus status = AudioQueueNewInput (

                                &fmt,

                                HandleInputBuffer,

                                &isWrite,

                                NULL,

                                kCFRunLoopCommonModes,

                                0,

                                &queue

                                );

          

         

            AudioQueueBufferRef  buffers[kNumberBuffers];

            UInt32 bufferByteSize = kSamplesSize;

            for (int i = 0; i < kNumberBuffers; ++i) {

                OSStatus allocateStatus;

                allocateStatus =  AudioQueueAllocateBuffer (

                                          queue,

                                          bufferByteSize,

                                          &buffers[i]

                                          );

                OSStatus  enqueStatus;

                NSLog(@"allocateStatus = %d" , allocateStatus);

                enqueStatus =   AudioQueueEnqueueBuffer (

                                         queue,

                                         buffers[i],

                                         0,

                                         NULL

                                         );

                NSLog(@"enqueStatus = %d" , enqueStatus);

            }

          

         

            UInt32 d = 1;

            status = AudioQueueSetProperty (queue, kAudioQueueProperty_EnableLevelMetering, &d, sizeof(UInt32));

         

            NSLog(@"audio enable metrics status = %d" , status);

         

            dispatch_async(dispatch_get_main_queue(), ^{

                status = AudioQueueStart (

                                 queue,

                                 NULL

                                 );

              

                NSLog(@"status of audio queue start = %ld" , status);

            });

         

         

         

        Once in 1/2 second we get metrics with  mAveragePower value:

         

        UInt32 dataSize = sizeof(AudioQueueLevelMeterState) * 1 ;

        AudioQueueLevelMeterState *levels = (AudioQueueLevelMeterState*)malloc(dataSize);

        OSStatus status = AudioQueueGetProperty(queue, kAudioQueueProperty_CurrentLevelMeterDB, levels, &dataSize);

        float decibelValue = levels->mAveragePower;

        free(levels);

         

         

        So, as I wrote in beginning, we don't understand on what time interval is computed an average in mAveragePower? If it is computed from last time we asked the metrics (a half second ago) or on some other time interval?

        • Re: During what time computed audio mAveragePower?
          Claude31 Level 8 Level 8 (8,085 points)

          Could not find it, even in this detailed doc:

          h ttp://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=E509E26763A8E1079E5F913A3C113BC2?doi=10.1.1.363.8872&rep=rep1&type=pdf

           

          You should ask the question to Developer support directly, or burn a DTS ticket if this information is critical to you.

           

          If you get an answer, that to feed it back here.