Audio volume


#1

Hey,

Working on an app and this library has been a huge help to me. My question is: Is there a way to control the output volume of an audio device? I know there is a function waveOutSetVolume in the windows API but I have no clue how to get the handle to the current device. Thanks.


#2

I’ve not added anything to do this because with some types of audio device, e.g. ASIO, it’s not possible. The best way to do it is to just use your own level control within your app, and leave the user in charge of their system volume.


#3

Could you explain what you mean by level control? I play a few wave files simultaneously. Each one to a single channel (four in total) and I want to be able to control the volume on all of them (not separately). The eventual goal is to be able to normalize the volume so that regardless of the maximum amplitude of the wave file, I will always have the same maximum output volume.

I looked at the demo and it didn’t have anything to control output volume.


#4

By level control I just mean scaling your audio data by the gain you want to apply. If you want to change the gain on all of them, just do this after you’ve mixed them together.


#5

Sorry for my inexperience. But you are saying in the audioDeviceIOCallback function I should just add or subtract a value from all output data?


#6

multiply would be more appropriate.


#7

AudioSampleBuffer has various applyGain methods to help with this.


#8

To ask a more complex question on this topic: do the gain parameters on AudioSampleBuffer::addFrom() apply gain changes at zero crossings to avoid clicks, or is the volume change slowly ramped? I was expecting clicks when changing volume with addFrom() but I’m not hearing them. Am I going deaf, or is Juce doing something clever here?


#9

No, addFrom just does what it says on the tin. There’s another method you can call to apply a ramp to the buffer.


#10

Hmm. I must have the volume too low to hear them.

I guess I’d rather have methods with zero crossings, preferably on the buffer objects. But I’m unsure about overloading the AudioSampleBuffer object. Are you likely to add additional parameters to its existing methods–so I should I create an entirely new object instead, rather than extend its signatures?


#11

Guess u need to use applyGain method of the AudioSampleBuffer to change the volume of the audio.


#12

Guess u need to use applyGain method of the AudioSampleBuffer to change the volume of the audio.


#13

[quote=“emeyer”]Hmm. I must have the volume too low to hear them.

I guess I’d rather have methods with zero crossings, preferably on the buffer objects. But I’m unsure about overloading the AudioSampleBuffer object. Are you likely to add additional parameters to its existing methods–so I should I create an entirely new object instead, rather than extend its signatures?[/quote]

No, don’t overload the class, better to just write an algorithm that takes a buffer.


#14

Hi Jules,

I have an application that I want to port to using the JUCE audio API. Today I use portaudio + portmixer, the latter for controlling volume of the audio device. This because the front end of the application is a virtual audio device, which exposes its volume control to the OS, so I just want to propagate this volume to the target audio device.

I propose an extension to the AudioIODevice class:

bool setInputVolume(float volume); // volume is 0.0f to 1.0f
float getInputVolume() const; // returns volume, or -1.0f if not supported

bool setOutputVolume(float volume); // volume is 0.0f to 1.0f
float getOutputVolume() const; // returns volume, or -1.0f if not supported

which would not be implemented on ASIO of course. However I do have the implementation for CoreAudio, WASAPI, DS, MME and ALSA, and I think it would be next to trivial to add this functionality to JUCE.

What do you think ? :)


#15

I never learn!! With a high probability a feature I want is already implemented. SystemAudioVolume. I'll see if that works for me, or if I really do need device specific volume.

 


#16

No, I do need the device specific volume. Since my virtual audio device is the system default audio device, that is what I end up setting the volume on with SystemAudioVolume. I need to be able to set it on device level...


#17

Sure - I guess nobody ever requested this before, and I didn't need it myself, but if you have the implementations for the different platforms I'd be happy to add it!