Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

audio - how do I get Mixer channels layout in java

I thought I can find anything on this great site but now I seem to face the issue with no answer :) Please help!

Thing is, I need to play up to 6 different wav files with 1 channel each into 6 channels supported by system mixer (left, right, surround left, etc).

Using 6 different SourceDataLines looks logical but from what I see, Mixer cannot do per-sample synchronisation for them, so I came up with interleaving them in separate thread and use only one SourceDataLine to play it. It works fine for two channels, left and right but for more channels I need to know precise channels layout (may be different on diff. system, and sound cards). I thought that one of system Mixers (I have two: "linear input" and "java sound system mixer") might have this metadata but I can't find it.

Does anybody know how to get this info?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My friend and I just figured out that java7 sound system supports 6 channels and all the variants of their using with different bits, etc.

Here is the code to list what your java can do:

        Mixer.Info[] mi = AudioSystem.getMixerInfo();
        for (Mixer.Info info : mi) {
            System.out.println("info: " + info);
            Mixer m = AudioSystem.getMixer(info);
            System.out.println("mixer " + m);
            Line.Info[] sl = m.getSourceLineInfo();
            for (Line.Info info2 : sl) {
                System.out.println("    info: " + info2);
                Line line = AudioSystem.getLine(info2);
                if (line instanceof SourceDataLine) {
                    SourceDataLine source = (SourceDataLine) line;

                    DataLine.Info i = (DataLine.Info) source.getLineInfo();
                    for (AudioFormat format : i.getFormats()) {
                        System.out.println("    format: " + format);
                    }
                }
            }
        }

This is output from my macbook pro with usb connected external sound card:

info: Default Audio Device, version Unknown Version
mixer com.sun.media.sound.DirectAudioDevice@67310bf
    info: interface SourceDataLine supporting 14 audio formats, and buffers of at least 32 bytes
    format: PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, big-endian
    format: PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, big-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian
    info: interface Clip supporting 14 audio formats, and buffers of at least 32 bytes
info: Built-in Input, version Unknown Version
mixer com.sun.media.sound.DirectAudioDevice@2edf98c4
info: Built-in Output, version Unknown Version
mixer com.sun.media.sound.DirectAudioDevice@59a683e6
    info: interface SourceDataLine supporting 14 audio formats, and buffers of at least 32 bytes
    format: PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, big-endian
    format: PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, big-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian
    info: interface Clip supporting 14 audio formats, and buffers of at least 32 bytes
info: SB X-Fi Surround 5.1 Pro, version Unknown Version
mixer com.sun.media.sound.DirectAudioDevice@431d9f05
    info: interface SourceDataLine supporting 20 audio formats, and buffers of at least 32 bytes
    format: PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, big-endian
    format: PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, big-endian
    format: PCM_UNSIGNED unknown sample rate, 8 bit, 6 channels, 6 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 8 bit, 6 channels, 6 bytes/frame, 
    format: PCM_SIGNED unknown sample rate, 16 bit, 6 channels, 12 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 16 bit, 6 channels, 12 bytes/frame, big-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, 6 channels, 18 bytes/frame, little-endian
    format: PCM_SIGNED unknown sample rate, 24 bit, 6 channels, 18 bytes/frame, big-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
    format: PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian
    info: interface Clip supporting 20 audio formats, and buffers of at least 32 bytes
info: SB X-Fi Surround 5.1 Pro, version Unknown Version
mixer com.sun.media.sound.DirectAudioDevice@4db323af
info: Port Built-in Input, version Unknown Version
mixer com.sun.media.sound.PortMixer@4b743fba
    info: Built-in Input source port
info: Port Built-in Output, version Unknown Version
mixer com.sun.media.sound.PortMixer@45d1edcc
info: Port SB X-Fi Surround 5.1 Pro, version Unknown Version
mixer com.sun.media.sound.PortMixer@59530fe3
info: Port SB X-Fi Surround 5.1 Pro, version Unknown Version
mixer com.sun.media.sound.PortMixer@5c382de5
    info: SB X-Fi Surround 5.1 Pro source port

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...