MATLAB: How to control the audio volume when using AUDIOPLAYER in MATLAB
audioplayercontrolMATLABvolume
I am using AUDIOPLAYER function to play an audio file and would like to control the audio volume.
Best Answer
A function to control audio volume directly is not available as of MATLAB R2015a.
As a workaround, you can modify the value of the signal data to control volume. Please see the code below for an example:
load handel; % 'handel' is a MAT-file which is shipped with MATLAB as an example
x = y/5; % Decrease volume
player = audioplayer(x, Fs);
play(player,[1 (get(player, 'SampleRate')*3)]);
x = y*5; % Increase volume
player = audioplayer(x, Fs);
play(player,[1 (get(player, 'SampleRate')*3)]);
As an additional workaround, you might try using the File Exchange submission called "SoundVolume", which sets or gets the computer system's speaker sound volume using Java. This submission can be found at the following link:
You should use the Audio Systems Toolbox. At each point you would fetch a batch of samples and multiply them by the current slider value, and queue them to be played as audio.
Creating a separate audio player for each batch of sounds is too much overhead, and there is no feasible way to update the sound samples of an audioplayer once it is built.
Best Answer