Results 1 to 13 of 13
  1. #1
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Problem with mixers

    well,
    i was trying to make a UDP voice chat but i couldn't make the receive method work! so i just move on to work with TCP
    i found a simple code that i found it pretty easy to understand,but i couldn't make it work,always stuck within exception
    here is the output i got:

    Available mixers:

    Java Sound Audio Engine

    Microsoft Sound Mapper

    WinOS,waveOut,multi threaded

    java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED, 8000.0 Hz, 16 bit, mono, little-endian, audio data


    and here is the code

    sender:
    Java Code:
    package sender;
    
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.Mixer;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.TargetDataLine;
    
    
    
    public class sender {
            ServerSocket MyService;
            Socket clientSocket = null;
            BufferedInputStream input;
            TargetDataLine targetDataLine;
    
            BufferedOutputStream out;
              ByteArrayOutputStream byteArrayOutputStream;
              AudioFormat audioFormat;
    
              SourceDataLine sourceDataLine;
             byte tempBuffer[] = new byte[10000];
    
             sender() throws LineUnavailableException{
                try {
                        audioFormat = getAudioFormat();
                        DataLine.Info dataLineInfo =  new DataLine.Info( SourceDataLine.class,audioFormat);
                        sourceDataLine = (SourceDataLine)
                    AudioSystem.getLine(dataLineInfo);
                    sourceDataLine.open(audioFormat);
                    sourceDataLine.start();
                            MyService = new ServerSocket(500);
                            clientSocket = MyService.accept();
                            captureAudio();
                            input = new BufferedInputStream(clientSocket.getInputStream());
                            out=new BufferedOutputStream(clientSocket.getOutputStream());
    
                            while(input.read(tempBuffer)!=-1){
                                    sourceDataLine.write(tempBuffer,0,10000);
                            }
                    } catch (IOException e) {
    
                            e.printStackTrace();
                    }
    
            }
             private AudioFormat getAudioFormat(){
                        float sampleRate = 8000.0F;
                        int sampleSizeInBits = 16;
                        int channels = 1;
                        boolean signed = true;
                        boolean bigEndian = false;
                        return new AudioFormat(
                                          sampleRate,
                                          sampleSizeInBits,
                                          channels,
                                          signed,
                                          bigEndian);
                      }
            public static void main(String s[]) throws LineUnavailableException{
                     sender s2=new sender();
            }
    
    
            private void captureAudio() {
                    try {
    
                            Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
                            System.out.println("Available mixers:");
                            for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
                                    System.out.println(mixerInfo[cnt].getName());
                            }
                            audioFormat = getAudioFormat();
    
                            DataLine.Info dataLineInfo = new DataLine.Info(
                                            TargetDataLine.class, audioFormat);
    
                            Mixer mixer = AudioSystem.getMixer(mixerInfo[1]);
    
                            targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
    
                            targetDataLine.open(audioFormat);
                            targetDataLine.start();
    
                            Thread captureThread = new CaptureThread();
                            captureThread.start();
                    } catch (Exception e) {
                            System.out.println(e);
                            System.exit(0);
                    }
            }
    
            class CaptureThread extends Thread {
    
                    byte tempBuffer[] = new byte[10000];
    
                    public void run() {
                            try {
                                    while (true) {
                                            int cnt = targetDataLine.read(tempBuffer, 0,
                                                            tempBuffer.length);
                                            out.write(tempBuffer);
                                    }
    
                            } catch (Exception e) {
                                    System.out.println(e);
                                    System.exit(0);
                            }
                    }
            }
    
    }
    Tx:
    Java Code:
    package tx;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.net.Socket;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.Mixer;
    import javax.sound.sampled.SourceDataLine;
    
    import javax.sound.sampled.TargetDataLine;
    
    public class Tx {
            boolean stopCapture = false;
    
            ByteArrayOutputStream byteArrayOutputStream;
    
            AudioFormat audioFormat;
    
            TargetDataLine targetDataLine;
    
            AudioInputStream audioInputStream;
    
            BufferedOutputStream out = null;
    
            BufferedInputStream in = null;
    
            Socket sock = null;
    
            SourceDataLine sourceDataLine;
    
            public static void main(String[] args) {
                    Tx tx = new Tx();
                    tx.captureAudio();
    
            }
    
            private void captureAudio() {
                    try {
    
                            sock = new Socket("11.0.0.1", 500);
    
                            out = new BufferedOutputStream(sock.getOutputStream());
                            in = new BufferedInputStream(sock.getInputStream());
    
                            Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
                            System.out.println("Available mixers:");
                            for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
                                    System.out.println(mixerInfo[cnt].getName());
                            }
                            audioFormat = getAudioFormat();
    
                            DataLine.Info dataLineInfo = new DataLine.Info(
                                            TargetDataLine.class, audioFormat);
    
                            Mixer mixer = AudioSystem.getMixer(mixerInfo[1]);
    
                            targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
    
                            targetDataLine.open(audioFormat);
                            targetDataLine.start();
    
                            Thread captureThread = new CaptureThread();
                            captureThread.start();
    
                            DataLine.Info dataLineInfo1 = new DataLine.Info(
                                            SourceDataLine.class, audioFormat);
                            sourceDataLine = (SourceDataLine) AudioSystem
                                            .getLine(dataLineInfo1);
                            sourceDataLine.open(audioFormat);
                            sourceDataLine.start();
    
                            Thread playThread = new PlayThread();
                            playThread.start();
    
                    } catch (Exception e) {
                            System.out.println(e);
                            System.exit(0);
                    }
            }
    
            class CaptureThread extends Thread {
    
                    byte tempBuffer[] = new byte[10000];
    
                    public void run() {
                            byteArrayOutputStream = new ByteArrayOutputStream();
                            stopCapture = false;
                            try {
                                    while (!stopCapture) {
    
                                            int cnt = targetDataLine.read(tempBuffer, 0,
                                                            tempBuffer.length);
    
                                            out.write(tempBuffer);
    
                                            if (cnt > 0) {
    
                                                    byteArrayOutputStream.write(tempBuffer, 0, cnt);
    
                                            }
                                    }
                                    byteArrayOutputStream.close();
                            } catch (Exception e) {
                                    System.out.println(e);
                                    System.exit(0);
                            }
                    }
            }
    
            private AudioFormat getAudioFormat() {
                    float sampleRate = 8000.0F;
    
                    int sampleSizeInBits = 16;
    
                    int channels = 1;
    
                    boolean signed = true;
    
                    boolean bigEndian = false;
    
                    return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
                                    bigEndian);
            }
    
            class PlayThread extends Thread {
                    byte tempBuffer[] = new byte[10000];
    
                    public void run() {
                            try {
                                    while (in.read(tempBuffer) != -1) {
                                            sourceDataLine.write(tempBuffer, 0, 10000);
                                    }
                            } catch (IOException e) {
                                    e.printStackTrace();
                            }
                    }
            }
    
    }

    i tried to play with the index of mixerInfo array in the line
    Java Code:
    Mixer mixer = AudioSystem.getMixer(mixerInfo[1]);
    but nothing happened

    how i can fix that?

    thanks in advance

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: problem with mixers

    Is the problem with networking classes like socket etc
    or with the sound package classes?

  3. #3
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: problem with mixers

    i debugged the code,the exception occurred at

    Mixer mixer = AudioSystem.getMixer(mixerInfo[1]);

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: problem with mixers

    Then there is no problems with networking?

  5. #5
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: problem with mixers

    yes,i think

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Problem with mixers

    If this is not a networking problem, I have moved it out of the networking thread.

  7. #7
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem with mixers

    thanks
    and hope someone can help me here

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Problem with mixers

    Can you make a small simple program for testing that compiles and executes and shows the problem?

  9. #9
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem with mixers

    if you copy and paste the code in this link
    Java Sound, Getting Started, Part 2, Capture Using Specified Mixer - Developer.com

    it probably work just fine
    but with me,first i have this exception:java.lang.ArrayIndexOutOfBoundsException

    then when i try to change the index of the array in this line:Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);
    i get:java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED, 8000.0 Hz, 16 bit, mono, little-endian, audio data

    that's my problem

  10. #10
    sana'a is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem with mixers

    I DID IT!!
    it works!!

    netbeans solved my problem

  11. #11
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Re: Problem with mixers

    I have a more puzzling problem. I've worked in java sound and jmf for 15 years and never seen this, and can't figure it out. I just moved my java code onto another computer, a 32 bit Dell pc Window 7 Netbeans 1.8 and 1.7. I can't get it to play sound files or do speech synthesis through FreeTTS, both for the same reason when I dive into the execution: it says it has no Mixers. This computer plays video and sound just fine outside Java, and JMF works fine for video capture. I have sound.properties and speech.properties and jmf.properties all in place. I believe the PC has all the same mixers as my previous computer, so why cannot AudioSystem find them?

    I've tried several angles to list them, all with the same result, no Mixers. Here is one, it shows blank.
    private static void listSourceDataLines() {
    System.out.println("Available Mixers:");
    Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
    for (int i = 0; i < aInfos.length; i++)
    {
    Mixer mixer = AudioSystem.getMixer(aInfos[i]);
    //mixer.open();
    Line.Info[] lines = mixer.getSourceLineInfo();
    System.out.println(aInfos[i].getName());
    for (int j=0; j<lines.length; j++) {
    System.out.println(" "+lines[j].toString());
    if (lines[j] instanceof DataLine.Info) {
    AudioFormat[] formats = ((DataLine.Info)lines[j]).getFormats();
    for (int k=0; k<formats.length; k++) {
    System.out.println(" "+formats[k].toString());
    }
    }
    }
    }
    }

  12. #12
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Re: Problem with mixers

    I tried adding the standard entries to the sound.properties file (they aren't needed in my other computer, but I had to try), and it made no difference. I've tracked down the problem farther by getting the source code for these classes and stepping through. The system seems to have the Mixer providers, but
    in java.util.ServiceLoader.LazyIterator$nextService() it is looping through a set of javax.sound.sampled.spi.MixerProviders and it hits the following error:
    try {
    S p = service.cast(c.newInstance());
    providers.put(cn, p);
    return p;
    } catch (Throwable x) {
    fail(service,
    "Provider " + cn + " could not be instantiated",
    x);
    }
    Any suggestions?

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: Problem with mixers

    This thread is over 2 years old.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •