How to set an absolute volume using [NSSound setVolume:]? Not regarding the volume of the system?

I have a beep. I never want it to be “loud” and amazing, so I reduce it with [NSSound setVolume] to a loud sound that is not loud.

But it seems that the volume is set relative to the current system volume. Therefore, if I reduce it for the case with the maximum system capacity, I can not hear it in the case of a low system volume.

If I use: [sound setVolume:0.1];

It sounds great when the system is set to full volume. But it is not heard at all if the volume of the system is 1/3.

Basically, I want to set the maximum volume level for sound. If the system volume is higher, it will play at my pre-set maximum volume. But if the volume of the system is below this, it worsens in accordance with the volume of the system.

Like this:

System = 1
-Sound = .3

System = .7
-Sound = .3

System = .3
-Sound = .3

System = .2
-Sound = .2

Is this the only way to do this to manually check the volume of the system sound and adjust your sound accordingly?

+4
source share
4 answers

The NSSound volume corresponds to the volume slider that you see in QuickTime Player, iTunes, etc. This is the volume for this particular sound, separate from and, as you have seen, is subject to the system volume.

You can get the current system volume by requesting the audio hardware API. Get the default audio output device, then get its volume. Then you can see if it will be above or below the desired volume level.

(It is worth noting that, in fact, there is not a single global “system volume." There are two default output devices and any number of specific output devices, each with its own volume. The "system volume" usually refers to the default output device volume. .)

Remember, however, that this is not how any other application in the system works, so this behavior will seem unpredictable to the user. Expect error messages in the lines "the volume slider does not work if the volume of the system is above a certain level."

+1
source

I suspect this is so (think about what happens if the user changes the system volume while playing your sound).

You can also make it available to the user. Expensive headphones are often very sensitive (i.e. Loud); I suspect 0.1 is loud if the scale is linear.

+1
source

Not the answer to my exact original question, but where does it lead: playing an audio file as a “system sound” that respects the user’s “volume level” and sound alerts:

http://iosdeveloperzone.com/2011/05/23/snippet-playing-a-system-sound/

 // Required import... Also need AudioToolbox.framework #import <AudioToolbox/AudioToolbox.h> // ivar SystemSoundID mBeep; // Create the sound ID NSString* path = [[NSBundle mainBundle] pathForResource:@"Beep" ofType:@"aiff"]; NSURL* url = [NSURL fileURLWithPath:path]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep); // Play the sound AudioServicesPlaySystemSound(mBeep); // Dispose of the sound AudioServicesDisposeSystemSoundID(mBeep); 
+1
source

Unable to install system volume. You can only set relative volume levels no matter how low the objective-c level allows you to switch. Even with CoreAudio, you can only set relative levels.

Gw

-1
source

Source: https://habr.com/ru/post/1435698/


All Articles