Sound volume

Discussion and questions about programming with Ultibo.
User avatar
Rassamaha78
Posts: 44
Joined: Wed Dec 20, 2017 1:09 am
Location: Russia

Sound volume

Postby Rassamaha78 » Sun Jun 10, 2018 12:47 pm

I know that I can change the sound level through changing the sample of the WAV file, but this is a very long process,
Is it possible to control the volume directly through BCM chip ( HDMI and 3.5 Jack output ) ?
pjde
Posts: 375
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Sound volume

Postby pjde » Sun Jun 10, 2018 10:28 pm

If you are using OMX you can change the volume by setting the OMX_IndexConfigAudioChannelVolume parameter.

You will need to define the OMX_AUDIO_CONFIG_VOLUMETYPE record type.

You can use a similar method to adjust the bass and treble.

Regards

Paul
pik33
Posts: 704
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Sound volume

Postby pik33 » Mon Jun 11, 2018 10:10 am

You have to understand what is a volume change and how the audio is generated in RPi

(1) HDMI. The digital audio stream is transmitted via HDMI and converted to analog in the receiver (for example TV)

(2) Audio jack. There is no DAC, the audio is generated using PWM (Pulse Width Modulation). There are two drivers for Raspberry Pi/Raspbian. One of them uses 11-bit sampling with noise added to mask the distortions caused by low bit depth. Second (newer) one uses advanced signal processing technique (noise shaping) which can make SNR much higher than "stupid" PWM. This is also the method I used in SimpleAudio driver.

In both cases you have to change your audio volume by multiplying every sample by constant. You can do it for yourself. You can also tell the driver what volume you want from it, but this is technically no difference: the samples are multiplied by constant inside the driver instead of outside.

The official drivers (I think they are used by OMX too) have sample rate fixed to 48 kHz.

Now warning: using "official" "old style" audio jack driver with volume control means you lose 1 bit of resolution with every 6 dB. The best volume control method is then using a volume control knob in your amplifier.

The "new style" audio driver (audio_pwm_mode=2) has better dynamic range so you may try to control the volume there.

SimpleAudio driver has also high dynamic range and built-in volume control function.
User avatar
Rassamaha78
Posts: 44
Joined: Wed Dec 20, 2017 1:09 am
Location: Russia

Re: Sound volume

Postby Rassamaha78 » Mon Jun 11, 2018 4:42 pm

Im use hello_audio lib from hello_pi librarries. I wrote my classes for multithreaded playback WAV files with hello_audio lib, but unfortunately this library has no function to change the volume.
So the only way for me is to change the sampled data independently by multiplying them by a constant ?
User avatar
Ultibo
Site Admin
Posts: 1895
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Sound volume

Postby Ultibo » Tue Jun 12, 2018 1:07 am

Rassamaha78 wrote:Im use hello_audio lib from hello_pi librarries. I wrote my classes for multithreaded playback WAV files with hello_audio lib, but unfortunately this library has no function to change the volume.
So the only way for me is to change the sampled data independently by multiplying them by a constant ?

The hello_audio example uses OMX so the OMX_IndexConfigAudioChannelVolume setting referred to above by Paul could be a valid option for changing the volume.

This post discusses it and shows the approximate code needed to set the volume, while the OP in that post says that OMX_IndexConfigAudioChannelVolume is not documented (and not supported) by the Pi it does appear in the audio_render documentation now (so things may have changed since that post).

You would need to create a modified version of the audio.c file from hello_audio and include extra functions to set the volume, it is probably worth some quick experiments to see if you can get it to work before deciding which way to go.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 375
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Sound volume

Postby pjde » Tue Jun 12, 2018 5:33 am

Looking at the OMX Player source, i noticed that it uses the OMX_CONFIG_BRCMAUDIODOWNMIXCOEFFICIENTS8x8 parameter to change the volume settings.

As this is a custom broadcom parameter it should work.

I have tried neither this or the OMX_IndexConfigAudioChannelVolume parameter so would be curious to see if either work.

Regards

Paul
pjde
Posts: 375
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Sound volume

Postby pjde » Fri Jun 15, 2018 11:00 pm

I did a quick test.

It seems that you can adjust the input volume and mix of an audio_mixer component, but not of the audio_decoder component.

Regards

Paul

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest