Giter Club home page Giter Club logo

Comments (6)

ewjmulder avatar ewjmulder commented on July 18, 2024

Below a test program and output when no USB sound cards are connected. Then both index 0 (default_ and 1 (plughw:0,0) will work. Maybe with internal sound card both work and with USB sound cards only default when that is set? Can test by plugging USB sound card and changing back default output.

Maybe use this pseudo code:

  1. find right plughw
    a. if works, fine
    b. if not works, try default instead

Test program:

    public static void main(String[] args) throws Exception {
        for (int i = 0; i < AudioSystem.getMixerInfo().length; i++) {
            System.out.println(AudioSystem.getMixerInfo()[i].getName());
            for (int k : new int[] { 8, 11, 22, 32, 44, 48 }) {
                File url = new File("/home/emulder/Downloads/game-music-mono-" + k + "k.wav");
                final AudioInputStream stream = AudioSystem.getAudioInputStream(url);

                AudioFormat inputFormat = stream.getFormat();
                // Explicitly set to stereo to control each speaker individually.
                AudioFormat outputFormat = new AudioFormat(inputFormat.getEncoding(), inputFormat.getSampleRate(), inputFormat.getSampleSizeInBits(),
                        2, 4, inputFormat.getFrameRate(), inputFormat.isBigEndian());
                try {
                    Mixer.Info[] q = AudioSystem.getMixerInfo();
                    SourceDataLine line = AudioSystem.getSourceDataLine(outputFormat, AudioSystem.getMixerInfo()[i]);
                    // SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info(SourceDataLine.class, format));
                    line.open();
                    line.close();
                    System.out.println(" OK : [" + i + "] - " + k);
                } catch (IllegalArgumentException e) {
                    System.out.println("FAIL: [" + i + "] - " + k);
                }
            }
        }
    }

Output:

default [default]
 OK : [0] - 8
 OK : [0] - 11
 OK : [0] - 22
 OK : [0] - 32
 OK : [0] - 44
 OK : [0] - 48
PCH [plughw:0,0]
 OK : [1] - 8
 OK : [1] - 11
 OK : [1] - 22
 OK : [1] - 32
 OK : [1] - 44
 OK : [1] - 48
PCH [plughw:0,3]
 OK : [2] - 8
 OK : [2] - 11
 OK : [2] - 22
 OK : [2] - 32
 OK : [2] - 44
 OK : [2] - 48
PCH [plughw:0,7]
 OK : [3] - 8
 OK : [3] - 11
 OK : [3] - 22
 OK : [3] - 32
 OK : [3] - 44
 OK : [3] - 48
PCH [plughw:0,8]
 OK : [4] - 8
 OK : [4] - 11
 OK : [4] - 22
 OK : [4] - 32
 OK : [4] - 44
 OK : [4] - 48
Port PCH [hw:0]
FAIL: [5] - 8
FAIL: [5] - 11
FAIL: [5] - 22
FAIL: [5] - 32
FAIL: [5] - 44
FAIL: [5] - 48

from immerse.

ewjmulder avatar ewjmulder commented on July 18, 2024

Actually without the USB sound cards it was the case. It seemed not, but that was because the default was not the internal sound card, but some 'Dummy device' that popped up somewhere during testing. So the behavior is consistent.

from immerse.

ewjmulder avatar ewjmulder commented on July 18, 2024

New output when running without dummy device (plughw:0,0 is default others are HDMI devices):

default [default]
 OK : [0] - 8
 OK : [0] - 11
 OK : [0] - 22
 OK : [0] - 32
 OK : [0] - 44
 OK : [0] - 48
PCH [plughw:0,0]
FAIL: [1] - 8
FAIL: [1] - 11
FAIL: [1] - 22
FAIL: [1] - 32
FAIL: [1] - 44
FAIL: [1] - 48
PCH [plughw:0,3]
 OK : [2] - 8
 OK : [2] - 11
 OK : [2] - 22
 OK : [2] - 32
 OK : [2] - 44
 OK : [2] - 48
PCH [plughw:0,7]
 OK : [3] - 8
 OK : [3] - 11
 OK : [3] - 22
 OK : [3] - 32
 OK : [3] - 44
 OK : [3] - 48
PCH [plughw:0,8]
 OK : [4] - 8
 OK : [4] - 11
 OK : [4] - 22
 OK : [4] - 32
 OK : [4] - 44
 OK : [4] - 48
Port PCH [hw:0]
FAIL: [5] - 8
FAIL: [5] - 11
FAIL: [5] - 22
FAIL: [5] - 32
FAIL: [5] - 44
FAIL: [5] - 48

from immerse.

ewjmulder avatar ewjmulder commented on July 18, 2024

Hmm, after a few trial runs it seems like when opening the default internal audio device sometimes it throws an exception and sometimes is doesn't. But with the current code that is ok, since it will work both ways.

from immerse.

ewjmulder avatar ewjmulder commented on July 18, 2024

Could it be related to the order in which lines are opened? Cause the sound cards are in a set it can vary. With the index 0 not being first it works (one test):

NOT an exception for systemMixerInfo: Set [plughw:2,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: PCH [plughw:0,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: Device [plughw:1,0], version 4.8.0-040800-generic

Another:

NOT an exception for systemMixerInfo: Device [plughw:1,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: PCH [plughw:0,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: Set [plughw:2,0], version 4.8.0-040800-generic

Hmm no, wrong again:

NOT an exception for systemMixerInfo: PCH [plughw:0,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: Set [plughw:2,0], version 4.8.0-040800-generic
NOT an exception for systemMixerInfo: Device [plughw:1,0], version 4.8.0-040800-generic

from immerse.

ewjmulder avatar ewjmulder commented on July 18, 2024

Newer testing shows very consistent behavior: the device that is set to be the OS default will always throw an exception and work when using 'null' for the default. So taking that as a 'known issue' for now in the code and documentation. If any future tests show otherwise, a new issue (bug) can be created for that.

from immerse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.