1

I am going to output some audio in a java program, to a sound card with multiple chanels (8 channels). For this I want to send different sounds on different channels on the sound card (so it can be played on different speakers) The audio being sent is different files (maybe mp3).

Do anyone have any suggestions on how to do this with java? What I have tried so far is the javax.sound.sampled library. I did manage to just send some sound out on the speakers, but not to decide what channels to use. I have tried using Port.Info, but can't seem to handle its syntax.

Here is the code so far, and this work:

// open up an audio stream
private static void init() {
    try {
        // 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian
        AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false);
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
        //Port.Info port = new Port.Info((Port.class), Port.Info.SPEAKER, false);

        //Port.Info pi = new Port.Info((Port.class), "HEADPHONES", false);

        line = (SourceDataLine) AudioSystem.getLine(info);
        //line = (SourceDataLine) AudioSystem.getLine(port);
        line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE);

        // the internal buffer is a fraction of the actual buffer size, this choice is arbitrary
        // it gets divided because we can't expect the buffered data to line up exactly with when
        // the sound card decides to push out its samples.
        buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE/3];
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }

    // no sound gets made before this call
    line.start();
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
TorK
  • 567
  • 2
  • 10
  • 27

0 Answers0