1 2 3 Previous Next 36 Replies Latest reply: Oct 26, 2010 12:13 PM by captfoss Go to original post RSS
      • 15. Re: JavaSound questions
        Will Pittenger
        captfoss wrote:
        I'm not sure that you're understanding a few key concepts...

        TargetDataLines don't attach to anything, they come pre-attached to mixers. The same way SourceDataLines come attached to mixers, just on the other side.

        Mixers dump into TDLs and you read from TDLs. You write to SDLs and they dump into Mixers.

        Input ports (microphone, line in, etc) are equviolent to SDLs. They dump into a Mixer.
        Output ports (speakers, line out, etc) are equivolent to TDLs. Mixers dump into them.

        The difference is, you can't read or write directly from a port, you have to read/write from output/input associated with the Mixer it's attached to.

        So, to "read" from a microphone port, you fine the port, get it's mixer, and get one of the TargetDataLines from the Mixer. If you need the microphone to feed into another Mixer, then you have to manually read data from the TDL on Mixer1 to the SDL on Mixer2...
        Well that helps. However, the mixer with the port has several source ports. Wouldn't that be an issue as far as ensuring the port is the microphone?
        captfoss wrote:
        Also as a P.S. I'm happy to help you with specific code snippets you can post on the forum, but I'm not going to go to external sites to look through full code files.
        Ok. Sorry.


        New item: I was testing with simply AudioSystem.getTargetDataLine. However, it won't provide a line when the AudioFormat that specifies ALAW or ULAW. Is PCM compressed?
        • 16. Re: JavaSound questions
          Will Pittenger
          Calling AudioSystem.getTargetDataLine with the mixer's info object as a parameter and AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false) as the audio format triggers an exception, line not supported.
          • 17. Re: JavaSound questions
            captfoss
            Will Pittenger wrote:
            Well that helps. However, the mixer with the port has several source ports. Wouldn't that be an issue as far as ensuring the port is the microphone?
            Again, you've proven you haven't read the article I keep linking you to ;-)
            http://www.vsj.co.uk/java/display.asp?id=370

            All of the ports on the system go to a specific mixer called the port mixer, and each port on that mixer has a "select" control on it. You select the port & deselect everything else.

            Do a CTRL+F for "Discovering Port Mixer and Controls" to learn more.
            captfoss wrote:
            Also as a P.S. I'm happy to help you with specific code snippets you can post on the forum, but I'm not going to go to external sites to look through full code files.
            Ok. Sorry.
            Not a big deal, just an FYI :-)
            New item: I was testing with simply AudioSystem.getTargetDataLine. However, it won't provide a line when the AudioFormat that specifies ALAW or ULAW. Is PCM compressed?
            PCM isn't compressed, no... but most of the time, your sound hardware is going to operate strictly in linear PCM. So unless you have some fancy hardware that supports recording / playing ALAW/ULAW, you'd have to transcode linear PCM into ALAW or ULAW.

            http://www.jsresources.org/examples/UlawEncoder.html

            That sample will do the conversion to ULAW for you...

            http://www.jsresources.org/examples/Mp3Encoder.html

            And that sample converts to MP3...
            • 18. Re: JavaSound questions
              Will Pittenger
              captfoss wrote:
              Again, you've proven you haven't read the article I keep linking you to ;-)
              http://www.vsj.co.uk/java/display.asp?id=370
              Well, I was trying to filter out stuff that wasn't relevant to what I was working on. :\
              captfoss wrote:
              All of the ports on the system go to a specific mixer called the port mixer, and each port on that mixer has a "select" control on it. You select the port & deselect everything else.

              Do a CTRL+F for "Discovering Port Mixer and Controls" to learn more.
              Interesting. That might explain both problems.
              captfoss wrote:
              PCM isn't compressed, no... but most of the time, your sound hardware is going to operate strictly in linear PCM. So unless you have some fancy hardware that supports recording / playing ALAW/ULAW, you'd have to transcode linear PCM into ALAW or ULAW.

              http://www.jsresources.org/examples/UlawEncoder.html

              That sample will do the conversion to ULAW for you...

              http://www.jsresources.org/examples/Mp3Encoder.html

              And that sample converts to MP3...
              I'll look at them. Note: The recordings will consist mainly of speech. I am not sure if my client is will to use Speechx or not.
              • 19. Re: JavaSound questions
                Will Pittenger
                Will Pittenger wrote:
                captfoss wrote:
                All of the ports on the system go to a specific mixer called the port mixer, and each port on that mixer has a "select" control on it. You select the port & deselect everything else.

                Do a CTRL+F for "Discovering Port Mixer and Controls" to learn more.
                Interesting. That might explain both problems.
                Well, I was hoping that would explain both how to ensure I had the microphone and why I couldn't get a line. However, my tests show that both the microphone port and the mixer it is attached to have no controls at all.

                Output from the program:
                ---------
                found mixer: com.sun.media.sound.PortMixer@1a40247
                Found microphone: com.sun.media.sound.PortMixer$PortMixerPort@151dcd6
                mixer's microphone port has 0 controls
                mixer has 0 controls
                • 20. Re: JavaSound questions
                  Will Pittenger
                  The code that output that, slightly simplified:
                  for(javax.sound.sampled.Mixer.Info mixerInfo : listOfMixers)
                  {
                       javax.sound.sampled.Mixer mixerTest = javax.sound.sampled.AudioSystem.getMixer(mixerInfo);
                       System.out.println("found mixer: " + mixerTest.toString());
                       if(mixerTest.isLineSupported(genericPortInfo))
                       {
                            java.util.ArrayList<javax.sound.sampled.Line.Info> listOfSrcLinesForMixer =
                            new java.util.ArrayList<javax.sound.sampled.Line.Info>(java.util.Arrays.asList(mixerTest.getSourceLineInfo()));
                  
                            for(javax.sound.sampled.Line.Info srcInfo : listOfSrcLinesForMixer)
                            {
                                 javax.sound.sampled.Port.Info pi = (javax.sound.sampled.Port.Info) srcInfo;
                                 if(pi == javax.sound.sampled.Port.Info.MICROPHONE || pi.getName().equalsIgnoreCase("MICROPHONE"))
                                 {
                                      javax.sound.sampled.Line port = mixerTest.getLine(pi);
                                      System.out.println("Found microphone: " + port.toString());
                                      javax.sound.sampled.Control[] controls = port.getControls();
                                      System.out.println("mixer's microphone port has " + Integer.toString(controls.length) + " controls");
                                      for(javax.sound.sampled.Control thisPortCtrl : controls)
                                           System.out.println("found control on microphone port: " + thisPortCtrl.toString());
                                      controls = mixerTest.getControls();
                                      System.out.println("mixer has " + Integer.toString(controls.length) + " controls");
                                      for(javax.sound.sampled.Control thisPortCtrl : controls)
                                           System.out.println("found control on microphone port: " + thisPortCtrl.toString());
                                      // Not shown: Code that ends the loops.
                                 }
                            }
                       }
                  }
                  • 21. Re: JavaSound questions
                    Will Pittenger
                    I am forced to conclude that the search code above isn't finding the correct mixer. I should note this machine has microphone ports in back and in front, plus stereo microphones built-into one of my monitors. Hence, there a several locations that might be seen by JavaSound as the microphone port. In any case, it definitely looks like the mixer found has just one line, labeled microphone, and it has no ports. I also can't get a target data line for that mixer. That suggests it isn't the correct mixer.
                    • 22. Re: JavaSound questions
                      Will Pittenger
                      I modified the code to keep looking if there are no controls for a mixer's microphone port. While it found a second port mixer, that mixer was identical to the first. One port. That port and the mixer had no controls what so ever.
                      • 23. Re: JavaSound questions
                        captfoss
                        It sounds like it could be a permissions problem.

                        What OS version & Java version are you using? Are you running the code as an administrator?
                        if(pi == javax.sound.sampled.Port.Info.MICROPHONE || pi.getName().equalsIgnoreCase("MICROPHONE"))
                        I don't believe that's the proper way to do that check... can you post the output of the port query code without the "Is this a microphone?" limitation?
                        • 24. Re: JavaSound questions
                          Will Pittenger
                          Well, it was recording something recognizable with whatever line I got with AudioSystem.getTargetDataLine with no mixer. But now it only gives me static which just happens to last the correct amount of time.
                          captfoss wrote:
                          It sounds like it could be a permissions problem.

                          What OS version & Java version are you using? Are you running the code as an administrator?
                          Windows Vista 64-bit SP2. Java 6 Update 21. I tried both the 32-bit version and a version that appears to be 64-bit. I am not running the program as an administrator if that is what you mean. I did not add any special permission code as the samples didn't have it.
                          if(pi == javax.sound.sampled.Port.Info.MICROPHONE || pi.getName().equalsIgnoreCase("MICROPHONE"))
                          I don't believe that's the proper way to do that check... can you post the output of the port query code without the "Is this a microphone?" limitation?
                          I don't follow you.
                          • 25. Re: JavaSound questions
                            captfoss
                            Will Pittenger wrote:
                            Well, it was recording something recognizable with whatever line I got with AudioSystem.getTargetDataLine with no mixer. But now it only gives me static which just happens to last the correct amount of time.
                            captfoss wrote:
                            It sounds like it could be a permissions problem.

                            What OS version & Java version are you using? Are you running the code as an administrator?
                            Windows Vista 64-bit SP2. Java 6 Update 21. I tried both the 32-bit version and a version that appears to be 64-bit. I am not running the program as an administrator if that is what you mean. I did not add any special permission code as the samples didn't have it.
                            Pretty sure 64-bit versions of JavaSound are buggy. I'd try it on a 32-bit OS if possible...
                            if(pi == javax.sound.sampled.Port.Info.MICROPHONE || pi.getName().equalsIgnoreCase("MICROPHONE"))
                            I don't believe that's the proper way to do that check... can you post the output of the port query code without the "Is this a microphone?" limitation?
                            I don't follow you.
                            Get rid of the IF statement... and post the results of running the code without it.
                            • 26. Re: JavaSound questions
                              Will Pittenger
                              I went back to the JRE I new was 32-bit. Still getting static. Results from the test you asked for:

                              found mixer: com.sun.media.sound.DirectAudioDevice@c62080
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@17fc44f
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13136e5
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@b2c64
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@18f7701
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@a37c6a
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13d21d6
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@7881db
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@1956391
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.HeadspaceMixer@bbf7aa
                              Mixer has source line interface SourceDataLine supporting 8 audio formats
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes
                              found mixer: com.sun.media.sound.PortMixer@1d8417c
                              Mixer has target line SPEAKER target port
                              found mixer: com.sun.media.sound.PortMixer@10872ce
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1a93f38
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@75b3ee
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@177fa9a
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1e5ba24
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.DirectAudioDevice@c62080
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@17fc44f
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13136e5
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@b2c64
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@18f7701
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@a37c6a
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13d21d6
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@7881db
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@1956391
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.HeadspaceMixer@bbf7aa
                              Mixer has source line interface SourceDataLine supporting 8 audio formats
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes
                              found mixer: com.sun.media.sound.PortMixer@1d8417c
                              Mixer has target line SPEAKER target port
                              found mixer: com.sun.media.sound.PortMixer@10872ce
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1a93f38
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@75b3ee
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@177fa9a
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1e5ba24
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.DirectAudioDevice@c62080
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@17fc44f
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13136e5
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@b2c64
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@18f7701
                              Mixer has source line interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@a37c6a
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@13d21d6
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@7881db
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.DirectAudioDevice@1956391
                              Mixer has target line interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
                              found mixer: com.sun.media.sound.HeadspaceMixer@bbf7aa
                              Mixer has source line interface SourceDataLine supporting 8 audio formats
                              Mixer has source line interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes
                              found mixer: com.sun.media.sound.PortMixer@1d8417c
                              Mixer has target line SPEAKER target port
                              found mixer: com.sun.media.sound.PortMixer@10872ce
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1a93f38
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@75b3ee
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@177fa9a
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              found mixer: com.sun.media.sound.PortMixer@1e5ba24
                              Mixer has source line MICROPHONE source port
                              Mixer has target line Master Volume target port
                              • 27. Re: JavaSound questions
                                captfoss
                                Will Pittenger wrote:
                                found mixer: com.sun.media.sound.PortMixer@1d8417c
                                Mixer has target line SPEAKER target port
                                found mixer: com.sun.media.sound.PortMixer@10872ce
                                Mixer has target line Master Volume target port
                                found mixer: com.sun.media.sound.PortMixer@1a93f38
                                Mixer has target line Master Volume target port
                                found mixer: com.sun.media.sound.PortMixer@75b3ee
                                Mixer has target line Master Volume target port
                                found mixer: com.sun.media.sound.PortMixer@177fa9a
                                Mixer has source line MICROPHONE source port
                                Mixer has target line Master Volume target port
                                found mixer: com.sun.media.sound.PortMixer@1e5ba24
                                Mixer has source line MICROPHONE source port
                                Mixer has target line Master Volume target port
                                Ok, so you're finding the port mixer just fine. I think I may be slightly misdescribing the steps outlined in the VJS article...or I was misunderstanding them, actually. You don't ever use the Port for anything, it's never directly connected to the data stream. You just use controls on it to make sure the Microphone is what's being recorded...

                                So, here's a step-by-step guide to getting it to work... with code.

                                Step 1 : Get a generic TargetDataLine from the system setup to record in your desired format...and open it.
                                AudioFormat recordingFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false);
                                
                                TargetDataLine recordLine = null;
                                recordLine = (TargetDataLine)AudioSystem.getTargetDataLine(recordingFormat);
                                recordLine.open(recordingFormat);
                                Step 2: Grab the port mixer and select the MICROPHONE port
                                Port.Info recPortInfo = new Port.Info(Port.class, "MICROPHONE", true);
                                Port recPort = (Port)AudioSystem.getLine(recPortInfo);
                                
                                recPort.open();
                                Control [] controls = recPort.getControls();
                                for(int i=0; i<controls.length; i++) {
                                  if(controls[i] instanceof CompoundControl) {
                                    Control[] members =((CompoundControl)controls).getMemberControls();
                                for(int j=0; j<members.length; j++) {
                                if(members[j].getType().toString().equals(“Select”)) {
                                ((BooleanControl)members[j]).setValue(true);
                                }
                                }
                                }
                                else {
                                if(controls[i].getType().toString().equals(“Select”)) {
                                ((BooleanControl)controls[i]).setValue(true);
                                }
                                }
                                }

                                recPort.close();
                                Step 3: Wrap the TDL in an AIS and record away
                                AudioInputStream ais = new AudioInputStream(recordLine);
                                AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new file("test.wav"));
                                Step 4: Add in null handling wherever necessary to keep your program from crashing ;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                • 28. Re: JavaSound questions
                                  Will Pittenger
                                  Except my code didn't find any controls in the port.
                                  • 29. Re: JavaSound questions
                                    captfoss
                                    Will Pittenger wrote:
                                    Except my code didn't find any controls in the port.
                                    I would attribute that to:
                                    1) Not running as an administrator
                                    2) Not using the 64-bit version of the JVM
                                    2) Using a 64-bit operating system

                                    If you're not running as an admin user, then you may not have access to get controls on the port.

                                    If you're running the 32-bit version of the JVM, the hardware interfaces may be all 64-bit and be inaccessible to 32-bit programs...

                                    If you're running a 64-bit OS, then you may very well be dealing with interfaces that Java just hasn't written / tested / fixed yet for interfacing with the hardware.

                                    Moral of the story is, your best best for testing purposes would be to run the code as an admin on 32-bit Windows XP Vista... Just to see if the code itself works.