Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current sound level of the current audio output device?

I'm looking for a way to tap into the current audio output on a Mac, then return a value representing the current sound level.

By sound level, I mean the amount of noise being generated by the output. I'm NOT asking how to get the current volume level of the output device.

like image 307
Pétur Ingi Egilsson Avatar asked Aug 09 '12 23:08

Pétur Ingi Egilsson


People also ask

How do I know my audio level?

Measure the sound level with a Sound Meter. What is this? A sound or decibel meter is a device to measure sound levels in decibels (dB). With this device, you can make use of the decibel chart above to measure if your headphones are too loud for you.

What does verifying current audio output mean?

Thus, with the present invention, a verification is made that the client device is presently outputting audio via the client device speakers in order to ensure that the user is listening to audio data sent to the client device.


1 Answers

the following code is pulled from Apple's Sample AVRecorder … this particular bit of code acquires a set of connections from this class's movieFileOutput's connections methods, gets the AVCaptureAudioChannel for each connection, and calculates decibel power based upon that. i would presume that if you are looking for an output "noise level", you would be able to capture similar information. if you are looking for something lower level than this, try the HAL (Hardware Abstraction Layer) framework.

- (void)updateAudioLevels:(NSTimer *)timer
{
    NSInteger channelCount = 0;
    float decibels = 0.f;

    // Sum all of the average power levels and divide by the number of channels
    for (AVCaptureConnection *connection in [[self movieFileOutput] connections]) {
        for (AVCaptureAudioChannel *audioChannel in [connection audioChannels]) {
            decibels += [audioChannel averagePowerLevel];
            channelCount += 1;
        }
    }

    decibels /= channelCount;

    [[self audioLevelMeter] setFloatValue:(pow(10.f, 0.05f * decibels) * 20.0f)];
}
like image 101
john.k.doe Avatar answered Oct 07 '22 04:10

john.k.doe