[vlc-commits] Audiotrack: use API for volume management

Geoffrey Métais git at videolan.org
Mon Nov 26 17:05:25 CET 2018


vlc | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 26 16:07:05 2018 +0100| [b3139ace006e232da3d7e83a0a50a3ccf170d354] | 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.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b3139ace006e232da3d7e83a0a50a3ccf170d354
---

 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 92a13326b0..8aef4aecfe 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -81,13 +81,11 @@ static const struct {
 
 typedef struct
 {
-    /* 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 */
 
@@ -169,8 +167,6 @@ typedef struct
     } circular;
 } aout_sys_t;
 
-/* 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
@@ -191,7 +187,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 ()
@@ -220,6 +215,8 @@ static struct
         jmethodID getTimestamp;
         jmethodID getMinBufferSize;
         jmethodID getNativeOutputSampleRate;
+        jmethodID setVolume;
+        jmethodID setStereoVolume;
         jint STATE_INITIALIZED;
         jint MODE_STREAM;
         jint ERROR;
@@ -378,6 +375,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 );
@@ -1481,8 +1483,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;
@@ -2048,6 +2052,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;
@@ -2131,7 +2190,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