caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.14k stars 260 forks source link

Can't seem to increase volume over 100% #1085

Closed cluder closed 3 years ago

cluder commented 3 years ago

It should be possible to set the volume to 200%, which does not seem to work.

boolean uk.co.caprica.vlcj.player.base.AudioApi.setVolume(int volume) Set the volume. The volume is actually a percentage of full volume, setting a volume over100 may cause audible distortion. Parameters: volume volume, a percentage of full volume in the range 0 to 200

public static void main(String[] args) throws Exception {
    AudioPlayerComponent audioMediaPlayerComponent = new AudioPlayerComponent() {
        @Override
        public void mediaPlayerReady(MediaPlayer mediaPlayer) {
            System.out.println(mediaPlayer.audio().setVolume(177));
        }
    };
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = loader.getResource("icq.mp3");
    if (url == null) {
        System.out.println("could not find " + url);
        return;
    }

    File file = new File(url.toURI());
    audioMediaPlayerComponent.mediaPlayer().media().play(file.getAbsolutePath());

    Thread.sleep(5000);
}

Any value over 100 seems to be the same loudness. setVolume() returns true

using version 4.7.1

    <dependency>
        <groupId>uk.co.caprica</groupId>
        <artifactId>vlcj</artifactId>
        <version>4.7.1</version>
    </dependency>
caprica commented 3 years ago

This is the vlcj code to set the volume:

public boolean setVolume(int volume) {
    return libvlc_audio_set_volume(mediaPlayerInstance, volume) == 0;
}

As you can see, it just calls the native LibVLC API directly.

I just tested this on Linux and it's working, I can hear an overcharged volume at 180 with some distortion for example. My OS audio mixer shows 100 (max) no matter what values I set over 100, but the volume does change.

So if the volume is not setting over 100%, it's some issue with the audio output that you are using via LibVLC. Indeed, it may be the case that some audio outputs don't support setting volume over 100.

You can maybe get some warning messages if you pass "-vvv" when you create the MediaPlayerFactory, but the bottom line is there is no problem in vlcj here.

cluder commented 3 years ago

i tried -vvv and got some debug output maybe the from -64 to +0 db is relevant ?

[000001d2555c7780] mmdevice audio output debug: using default device
[000001d2555c7780] mmdevice audio output debug: version 2 session control unavailable
[000001d2555c7780] mmdevice audio output debug: volume from -64.000000 dB to +0.000000 dB with 1.000000 dB increments
[000001d2555c7780] main audio output debug: using audio output module "mmdevice"
[000001d255854ed0] main generic debug: keeping audio output
[000001ea4ee29830] main libvlc debug: VLC media player - 3.0.11 Vetinari
[000001ea4ee29830] main libvlc debug: Copyright © 1996-2020 the VideoLAN team
[000001ea4ee29830] main libvlc debug: revision 3.0.11-0-gdc0c5ced72
[000001ea4ee29830] main libvlc debug: configured with ../extras/package/win32/../../../configure  '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=x86_64-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' 'host_alias=x86_64-w64-mingw32' 'PKG_CONFIG_LIBDIR=/home/jenkins/workspace/vlc-release/windows/vlc-release-win32-x64/contrib/x86_64-w64-mingw32/lib/pkgconfig'
[000001ea4ee29830] main libvlc debug: searching plug-in modules
[000001ea4ee29830] main libvlc debug: loading plugins cache file C:\Program Files\VideoLAN\VLC\plugins\plugins.dat
[000001ea4ee29830] main libvlc debug: recursively browsing `C:\Program Files\VideoLAN\VLC\plugins'
[000001ea4ee29830] main libvlc debug: loading plugins cache file C:\Program Files\VideoLAN\VLC\plugins\plugins.dat
[000001ea4ee29830] main libvlc debug: recursively browsing `C:\Program Files\VideoLAN\VLC\plugins'
[000001ea4ee29830] main libvlc debug: plug-ins loaded: 987 modules
[000001ea4ee4cf60] main logger debug: looking for logger module matching "any": 4 candidates
[000001ea4ee4cf60] main logger debug: using logger module "console"
[000001ea4ee29830] main libvlc debug: translation test: code is "de"
[000001ea4ee75da0] main keystore debug: looking for keystore module matching "memory": 6 candidates
[000001ea4ee75da0] main keystore debug: using keystore module "memory"
[000001ea4ee29830] main libvlc debug: CPU has capabilities MMX MMXEXT SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 FPU 
[000001ea4ee71410] main generic debug: creating audio output
[000001ea4ecd5b60] main audio output debug: looking for audio output module matching "any": 12 candidates
[000001ea4ecd5b60] mmdevice audio output debug: using default device
[000001ea4ecd5b60] mmdevice audio output debug: display name changed: VLC media player (LibVLC 3.0.11)
[000001ea4ecd5b60] mmdevice audio output debug: version 2 session control unavailable
[000001ea4ecd5b60] mmdevice audio output debug: volume from -64.000000 dB to +0.000000 dB with 1.000000 dB increments
[000001ea4ecd5b60] main audio output debug: using audio output module "mmdevice"
[000001ea4ee71410] main generic debug: keeping audio output
[000001ea4ef45610] main generic debug: creating audio output
[000001ea4ecd61a0] main audio output debug: looking for audio output module matching "any": 12 candidates
[000001ea4ecd61a0] mmdevice audio output debug: using default device
[000001ea4ecd61a0] mmdevice audio output debug: version 2 session control unavailable
[000001ea4ecd61a0] mmdevice audio output debug: volume from -64.000000 dB to +0.000000 dB with 1.000000 dB increments
[000001ea4ecd61a0] main audio output debug: using audio output module "mmdevice"
[000001ea4ef45610] main generic debug: keeping audio output
[000001ea4ecd61a0] main audio output debug: removing module "mmdevice"
[000001ea4ecd5b60] main audio output debug: removing module "mmdevice"
[000001ea4ef1fb70] main input debug: Creating an input for 'icq.mp3'
[000001ea4ef1fb70] main input debug: using timeshift granularity of 50 MiB
[000001ea4ef1fb70] main input debug: using timeshift path: ...
[000001ea4ef1fb70] main input debug: ....
[000001ea4ee4d1a0] main input source debug: creating demux: access='file' demux='any' location=...
[000001ea4ef34760] main demux debug: looking for access_demux module matching "file": 30 candidates
[000001ea4ef34760] main demux debug: no access_demux modules matched
[000001ea4ef464e0] main stream debug: creating access: file://...
[000001ea4ef464e0] main stream debug:  (path: ...)
[000001ea4ef464e0] main stream debug: looking for access module matching "file": 52 candidates
[000001ea4ef464e0] main stream debug: using access module "filesystem"
[000001ea4ef46660] main stream debug: looking for stream_filter module matching "prefetch,cache_read": 48 candidates
[000001ea4ef46660] cache_read stream debug: Using stream method for AStream*
[000001ea4ef46660] cache_read stream debug: starting pre-buffering
[000001ea4ef46660] cache_read stream debug: received first data after 0 ms
[000001ea4ef46660] cache_read stream debug: pre-buffering done 1024 bytes in 0s - 1000000 KiB/s
[000001ea4ef46660] main stream debug: using stream_filter module "cache_read"
[000001ea4ef46060] main stream debug: looking for stream_filter module matching "any": 48 candidates
[000001ea4ef46660] skiptags stream debug: ID3v2.3 revision 0 tag found, skipping 43 bytes
[000001ea4ef46060] main stream debug: using stream_filter module "skiptags"
[000001ea4ef46060] main stream debug: stream filter added to 000001ea4ef46660
[000001ea4ef467e0] main stream debug: looking for stream_filter module matching "any": 48 candidates
[000001ea4ef467e0] lua stream debug: Trying Lua scripts in ....
[000001ea4ef467e0] main stream debug: no stream_filter modules matched
[000001ea4ee4e410] main stream_directory debug: looking for stream_directory module matching "any": 2 candidates
[000001ea4ee4e410] main stream_directory debug: no stream_directory modules matched
[000001ea4ee4d1a0] main input source debug: attachment of directory-extractor failed for file:///...
[000001ea4ef46960] main stream debug: looking for stream_filter module matching "record": 48 candidates
[000001ea4ef46960] main stream debug: using stream_filter module "record"
[000001ea4ee4d1a0] main input source debug: creating demux: access='file' demux='any' location='/C:/....
[000001ea4ef34760] main demux debug: looking for demux module matching "any": 110 candidates
[000001ea4ef34760] es demux debug: xing vbr value present (80)
[000001ea4ef34760] es demux debug: xing frames&bytes value present (72631 bytes, 121 frames, 1152 samples/frame)
[000001ea4ef34760] es demux debug: detected format mpga
[000001ea4ef8e4e0] main demux packetizer debug: looking for packetizer module matching "any": 50 candidates
[000001ea4ef8e4e0] main demux packetizer debug: using packetizer module "mpegaudio"
[000001ea4ef8e4e0] mpegaudio demux packetizer debug: MPGA channels:2 samplerate:44100 bitrate:128
[000001ea4ef1fb70] main input debug: selecting program id=0
[000001ea4ef34760] main demux debug: using demux module "es"
[000001ea4ef1fb70] main input debug: looking for a subtitle file in C:\...
[000001ea4ef8ec70] main decoder debug: looking for audio decoder module matching "any": 46 candidates
[000001ea4ef8ec70] mpg123 decoder debug: mpga->f32l, bits per sample: 32
[000001ea4ef8ec70] main decoder debug: using audio decoder module "mpg123"
[000001ea4ef488f0] main demux meta debug: looking for meta reader module matching "any": 4 candidates
[000001ea4ef488f0] main demux meta debug: using meta reader module "taglib"
[000001ea4ef34760] main demux debug: removing module "taglib"
[000001ea4ef1fb70] main input debug: `file:///C:...' successfully opened
[000001ea4ef1fb70] main input debug: Buffering 0%
[000001ea4ef1fb70] main input debug: Buffering 2%
[000001ea4ef1fb70] main input debug: Buffering 5%
[000001ea4ee71410] main generic debug: creating audio output
[000001ea4ecd5b60] main audio output debug: looking for audio output module matching "any": 12 candidates
[000001ea4ef1fb70] main input debug: Buffering 7%
[000001ea4ef1fb70] main input debug: Buffering 10%
[000001ea4ef1fb70] main input debug: Buffering 13%
[000001ea4ef1fb70] main input debug: Buffering 15%
[000001ea4ef1fb70] main input debug: Buffering 18%
[000001ea4ef1fb70] main input debug: Buffering 20%
[000001ea4ef1fb70] main input debug: Buffering 23%
[000001ea4ef1fb70] main input debug: Buffering 26%
[000001ea4ef1fb70] main input debug: Buffering 28%
[000001ea4ef1fb70] main input debug: Buffering 31%
[000001ea4ef1fb70] main input debug: Buffering 33%
[000001ea4ef1fb70] main input debug: Buffering 36%
[000001ea4ef1fb70] main input debug: Buffering 39%
[000001ea4ecd5b60] mmdevice audio output debug: using default device
[000001ea4ef1fb70] main input debug: Buffering 41%
[000001ea4ef1fb70] main input debug: Buffering 44%
[000001ea4ef1fb70] main input debug: Buffering 47%
[000001ea4ef1fb70] main input debug: Buffering 49%
[000001ea4ef1fb70] main input debug: Buffering 52%
[000001ea4ef1fb70] main input debug: Buffering 54%
[000001ea4ef1fb70] main input debug: Buffering 57%
[000001ea4ef1fb70] main input debug: Buffering 60%
[000001ea4ef1fb70] main input debug: Buffering 62%
[000001ea4ef1fb70] main input debug: Buffering 65%
[000001ea4ecd5b60] mmdevice audio output debug: version 2 session control unavailable
[000001ea4ecd5b60] mmdevice audio output debug: volume from -64.000000 dB to +0.000000 dB with 1.000000 dB increments
[000001ea4ef1fb70] main input debug: Buffering 67%
[000001ea4ef1fb70] main input debug: Buffering 70%
[000001ea4ecd5b60] main audio output debug: using audio output module "mmdevice"
[000001ea4ef1fb70] main input debug: Buffering 73%
[000001ea4ef1fb70] main input debug: Buffering 75%
[000001ea4ef59160] main generic debug: looking for aout stream module matching "any": 4 candidates
[000001ea4ef1fb70] main input debug: Buffering 78%
[000001ea4ef1fb70] main input debug: Buffering 80%
[000001ea4ef1fb70] main input debug: Buffering 83%
[000001ea4ef1fb70] main input debug: Buffering 86%
[000001ea4ef1fb70] main input debug: Buffering 88%
[000001ea4ef1fb70] main input debug: Buffering 91%
[000001ea4ef1fb70] main input debug: Buffering 94%
[000001ea4ef1fb70] main input debug: Buffering 96%
[000001ea4ef59160] wasapi generic debug: modified format
[000001ea4ef1fb70] main input debug: Buffering 99%
[000001ea4ef1fb70] main input debug: Stream buffering done (1018 ms in 20 ms)
[000001ea4ef59160] wasapi generic debug: buffer size    : 96000 frames
[000001ea4ef59160] wasapi generic debug: maximum latency: 000 ns
[000001ea4ef59160] wasapi generic debug: default period : 10000000 ns
[000001ea4ef59160] wasapi generic debug: minimum period : 3000000 ns
[000001ea4ef59160] main generic debug: using aout stream module "wasapi"
[000001ea4ecd5b60] main audio output debug: output 'f32l' 48000 Hz 3F2M2R/LFE frame=1 samples/32 bytes
[000001ea4ef5a260] main volume debug: looking for audio volume module matching "any": 4 candidates
[000001ea4ef5a260] main volume debug: using audio volume module "float_mixer"
[000001ea4ecd5b60] main audio output debug: input 'f32l' 44100 Hz Stereo frame=1 samples/8 bytes
[000001ea4ef9afb0] main audio filter debug: looking for audio filter module matching "scaletempo": 32 candidates
[000001ea4ef9afb0] scaletempo audio filter debug: format: 44100 rate, 2 nch, 4 bps, fl32
[000001ea4ef9afb0] scaletempo audio filter debug: params: 30 stride, 0.200 overlap, 14 search
[000001ea4ef9afb0] scaletempo audio filter debug: 1.000 scale, 1323.000 stride_in, 1323 stride_out, 1059 standing, 264 overlap, 617 search, 2204 queue, fl32 mode
[000001ea4ef9afb0] main audio filter debug: using audio filter module "scaletempo"
[000001ea4ecd5b60] main audio output debug: conversion: 'f32l'->'f32l' 44
cluder commented 3 years ago

i found a workaround by setting the --gain=x (1-8) argument when creating the mediaplayer, which does increase the volume nicely

MediaPlayerFactory factory = new MediaPlayerFactory("-vvv", "--gain=4");

caprica commented 3 years ago

I don't know but I suspect this is a limitation of the audio output you're using. I don't use Windows so I can't really say, but maybe there's an option to choose a different audio output. I can say for sure though that on Linux it allows you to set a volume over 100.

The issue with your workaround is that you can't change it dynamically of course.

caprica commented 3 years ago

There is apparently another audio output available on Windows that you could try.

You select the audio output with a MediaPlayerFactory argument (similar to your gain switch), in this case it's something like:

{ "--aout=whatever-the-name-is" }

You can probably discover the name somewhere in the output of "vlc --list", searching for "audio output" should fine them.

caprica commented 3 years ago

I don't think there's anything more to be said. The issue can be reopened if anything new comes to light.