[vlc-commits] Audiotrack: use API for volume management
Geoffrey Métais
git at videolan.org
Wed Nov 28 17:00:21 CET 2018
vlc/vlc-3.0 | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 26 16:07:05 2018 +0100| [b1dadb2c6c04c918b44a5a8438c0b64b377e90a5] | committer: Thomas Guillem
Audiotrack: use API for volume management
Do like mmdevice: use AudioTrack volume API for volume in [0;1] range, and soft
gain for volume in ]1;2] range.
(cherry picked from commit b3139ace006e232da3d7e83a0a50a3ccf170d354)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=b1dadb2c6c04c918b44a5a8438c0b64b377e90a5
---
modules/audio_output/audiotrack.c | 80 ++++++++++++++++++++++++++++++++++-----
1 file changed, 71 insertions(+), 9 deletions(-)
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index 238826bb95..a6a8a78d74 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -80,13 +80,11 @@ static const struct {
};
struct aout_sys_t {
- /* sw gain */
- float soft_gain;
- bool soft_mute;
-
enum at_dev at_dev;
jobject p_audiotrack; /* AudioTrack ref */
+ float volume;
+ bool mute;
audio_sample_format_t fmt; /* fmt setup by Start */
@@ -168,8 +166,6 @@ struct aout_sys_t {
} circular;
};
-/* Soft volume helper */
-#include "audio_output/volume.h"
// Don't use Float for now since 5.1/7.1 Float is down sampled to Stereo Float
//#define AUDIOTRACK_USE_FLOAT
@@ -190,7 +186,6 @@ vlc_module_begin ()
add_integer( "audiotrack-session-id", 0,
AUDIOTRACK_SESSION_ID_TEXT, NULL, true )
change_private()
- add_sw_gain()
add_shortcut( "audiotrack" )
set_callbacks( Open, Close )
vlc_module_end ()
@@ -218,6 +213,8 @@ static struct
jmethodID getTimestamp;
jmethodID getMinBufferSize;
jmethodID getNativeOutputSampleRate;
+ jmethodID setVolume;
+ jmethodID setStereoVolume;
jint STATE_INITIALIZED;
jint MODE_STREAM;
jint ERROR;
@@ -358,6 +355,11 @@ InitJNIFields( audio_output_t *p_aout, JNIEnv* env )
GET_ID( GetStaticMethodID, AudioTrack.getNativeOutputSampleRate,
"getNativeOutputSampleRate", "(I)I", true );
#endif
+ GET_ID( GetMethodID, AudioTrack.setVolume,
+ "setVolume", "(F)I", false );
+ if( !jfields.AudioTrack.setVolume )
+ GET_ID( GetMethodID, AudioTrack.setStereoVolume,
+ "setStereoVolume", "(FF)I", true );
GET_CONST_INT( AudioTrack.STATE_INITIALIZED, "STATE_INITIALIZED", true );
GET_CONST_INT( AudioTrack.MODE_STREAM, "MODE_STREAM", true );
GET_CONST_INT( AudioTrack.ERROR, "ERROR", true );
@@ -1332,8 +1334,10 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
CHECK_AT_EXCEPTION( "play" );
*p_fmt = p_sys->fmt;
- aout_SoftVolumeStart( p_aout );
+ p_aout->volume_set(p_aout, p_sys->volume);
+ if (p_sys->mute)
+ p_aout->mute_set(p_aout, true);
aout_FormatPrint( p_aout, "VLC will output:", &p_sys->fmt );
return VLC_SUCCESS;
@@ -1898,6 +1902,61 @@ bailout:
vlc_mutex_unlock( &p_sys->lock );
}
+static int
+VolumeSet( audio_output_t *p_aout, float volume )
+{
+ aout_sys_t *p_sys = p_aout->sys;
+ JNIEnv *env;
+ float gain = 1.0f;
+
+ if (volume > 1.f)
+ {
+ p_sys->volume = 1.f;
+ gain = volume;
+ }
+ else
+ p_sys->volume = volume;
+
+ if( !p_sys->b_error && p_sys->p_audiotrack != NULL && ( env = GET_ENV() ) )
+ {
+ if( jfields.AudioTrack.setVolume )
+ {
+ JNI_AT_CALL_INT( setVolume, volume );
+ CHECK_AT_EXCEPTION( "setVolume" );
+ } else
+ {
+ JNI_AT_CALL_INT( setStereoVolume, volume, volume );
+ CHECK_AT_EXCEPTION( "setStereoVolume" );
+ }
+ }
+ aout_VolumeReport(p_aout, volume);
+ aout_GainRequest(p_aout, gain * gain * gain);
+ return 0;
+}
+
+static int
+MuteSet( audio_output_t *p_aout, bool mute )
+{
+ aout_sys_t *p_sys = p_aout->sys;
+ JNIEnv *env;
+ p_sys->mute = mute;
+
+ if( !p_sys->b_error && p_sys->p_audiotrack != NULL && ( env = GET_ENV() ) )
+ {
+ if( jfields.AudioTrack.setVolume )
+ {
+ JNI_AT_CALL_INT( setVolume, mute ? 0.0f : p_sys->volume );
+ CHECK_AT_EXCEPTION( "setVolume" );
+ } else
+ {
+ JNI_AT_CALL_INT( setStereoVolume, mute ? 0.0f : p_sys->volume, mute ? 0.0f : p_sys->volume );
+ CHECK_AT_EXCEPTION( "setStereoVolume" );
+ }
+ }
+ aout_MuteReport(p_aout, mute);
+ return 0;
+}
+
static int DeviceSelect(audio_output_t *p_aout, const char *p_id)
{
aout_sys_t *p_sys = p_aout->sys;
@@ -1981,7 +2040,10 @@ Open( vlc_object_t *obj )
for( unsigned int i = 0; at_devs[i].id; ++i )
aout_HotplugReport(p_aout, at_devs[i].id, at_devs[i].name);
- aout_SoftVolumeInit( p_aout );
+ p_aout->volume_set = VolumeSet;
+ p_aout->mute_set = MuteSet;
+ p_sys->volume = 1.0f;
+ p_sys->mute = false;
return VLC_SUCCESS;
}
More information about the vlc-commits
mailing list