Solved

what do I do to use these programs

Posted on 2004-04-11
24
434 Views
Last Modified: 2013-11-23
I have the code to get streams into code #1 I also have the  gnu.getopt.jar file.

I have to get this part worked out, this part is the foundation of my program.

Can you tell me what I am suppose to do to use these programs to make my single audio files out of a lot of small files.




Code #1

/*
 *      SequenceAudioInputStream.java
 *
 *      This file is part of the Java Sound Examples.
 */

/*
 *  Copyright (c) 1999 - 2001 by Matthias Pfisterer <Matthias.Pfisterer@web.de>
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/*
|<---            this code is formatted to fit into 80 columns             --->|
//SequenceAudioInputStream.java

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.BooleanControl;



public class SequenceAudioInputStream
      extends            AudioInputStream
{
      private static final boolean      DEBUG = true;

      private List                  m_audioInputStreamList;
      private      int                  m_nCurrentStream;



      public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams)
      {
            super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED);
            m_audioInputStreamList = new ArrayList(audioInputStreams);
            m_nCurrentStream = 0;
      }



      // TODO: remove
      private boolean addAudioInputStream(AudioInputStream audioStream)
      {
            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): called.");
            }
            // Contract.check(audioStream != null);
            if (!getFormat().matches(audioStream.getFormat()))
            {
                  if (DEBUG)
                  {
                        out("SequenceAudioInputStream.addAudioInputStream(): audio formats do not match, trying to convert.");
                  }
                  AudioInputStream      asold = audioStream;
                  audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);
                  if (audioStream == null)
                  {
                        out("###  SequenceAudioInputStream.addAudioInputStream(): could not convert.");
                        return false;
                  }
                  if (DEBUG)
                  {
                        out(" converted");
                  }
            }
            // Contract.check(audioStream != null);
            synchronized (m_audioInputStreamList)
            {
                  m_audioInputStreamList.add(audioStream);
                  m_audioInputStreamList.notifyAll();
            }
            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): enqueued " + audioStream);
            }
            return true;
      }



      private AudioInputStream getCurrentStream()
      {
            return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
      }



      private boolean advanceStream()
      {
            m_nCurrentStream++;
            boolean      bAnotherStreamAvailable = (m_nCurrentStream < m_audioInputStreamList.size());
            return bAnotherStreamAvailable;
      }



      public long getFrameLength()
      {
            long      lLengthInFrames = 0;
            Iterator      streamIterator = m_audioInputStreamList.iterator();
            while (streamIterator.hasNext())
            {
                  AudioInputStream      stream = (AudioInputStream) streamIterator.next();
                  long      lLength = stream.getFrameLength();
                  if (lLength == AudioSystem.NOT_SPECIFIED)
                  {
                        return AudioSystem.NOT_SPECIFIED;
                  }
                  else
                  {
                        lLengthInFrames += lLength;
                  }
            }
            return lLengthInFrames;
      }



      public int read()
            throws      IOException
      {
            AudioInputStream      stream = getCurrentStream();
            int      nByte = stream.read();
            if (nByte == -1)
            {
                  /*
                    The end of the current stream has been signaled.
                    We try to advance to the next stream.
                  */
                  boolean      bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                          There is another stream. We recurse into this method
                          to read from it.
                        */
                        return read();
                  }
                  else
                  {
                        /*
                          No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                    The most common case: We return the byte.
                  */
                  return nByte;
            }
      }



      public int read(byte[] abData, int nOffset, int nLength)
            throws      IOException
      {
            AudioInputStream      stream = getCurrentStream();
            int      nBytesRead = stream.read(abData, nOffset, nLength);
            if (nBytesRead == -1)
            {
                  /*
                    The end of the current stream has been signaled.
                    We try to advance to the next stream.
                  */
                  boolean      bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                          There is another stream. We recurse into this method
                          to read from it.
                        */
                        return read(abData, nOffset, nLength);
                  }
                  else
                  {
                        /*
                          No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                    The most common case: We return the length.
                  */
                  return nBytesRead;
            }
      }



      public long skip(long lLength)
            throws      IOException
      {
            throw new IOException("skip() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public int available()
            throws      IOException
      {
            return getCurrentStream().available();
      }



      public void close()
            throws      IOException
      {
            // TODO: should we close all streams in the list?
      }



      public void mark(int nReadLimit)
      {
            throw new RuntimeException("mark() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public void reset()
            throws      IOException
      {
            throw new IOException("reset() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public boolean markSupported()
      {
            return false;
      }



      private static void out(String strMessage)
      {
            System.out.println(strMessage);
      }
}



/*** SequenceAudioInputStream.java ***/


/*
 *      AudioConcat.java
 *
 *      This file is part of the Java Sound Examples.
 */

/*
 *  Copyright (c) 1999 - 2001 by Matthias Pfisterer <Matthias.Pfisterer@web.de>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/*
|<---            this code is formatted to fit into 80 columns             --->|
*/

import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.AudioFileFormat;
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;

/*      If the compilation fails because this class is not available,
      get gnu.getopt from the URL given in the comment below.
*/
import gnu.getopt.Getopt;


// TODO: the name AudioConcat is no longer appropriate. There should be a name that is neutral to concat/mix.

/**      <titleabbrev>AudioConcat</titleabbrev>
      <title>Concatenating or mixing audio files</title>

      <formalpara><title>Purpose</title>
      <para>This program reads multiple audio files and
      writes a single one either
      containing the data of all the other
      files in order (concatenation mode, option <option>-c</option>)
      or containing a mixdown of all the other files
      (mixing mode, option <option>-m</option>).
      For concatenation, the input files must have the same audio
      format. They need not have the same file type.</para>
      </formalpara>

      <formalpara><title>Level</title>
      <para>experienced</para>
      </formalpara>

      <formalpara><title>Usage</title>
      <para>
      <cmdsynopsis>
      <command>java AudioConcat</command>
      <arg choice="plain"><option>-h</option></arg>
      </cmdsynopsis>
      <cmdsynopsis>
      <command>java AudioConcat</command>
      <arg choice="opt"><option>-D</option></arg>
      <group choice="plain">
      <arg><option>-c</option></arg>
      <arg><option>-m</option></arg>
      </group>
      <arg choice="plain"><option>-o <replaceable>outputfile</replaceable></option></arg>
      <arg choice="plain" rep="repeat"><replaceable>inputfile</replaceable></arg>
      </cmdsynopsis>
      </para>
      </formalpara>

      <formalpara><title>Parameters</title>
      <variablelist>
      <varlistentry>
      <term><option>-c</option></term>
      <listitem><para>selects concatenation mode</para></listitem>
      </varlistentry>
      <varlistentry>
      <term><option>-m</option></term>
      <listitem><para>selects mixing mode</para></listitem>
      </varlistentry>
      <varlistentry>
      <term><option>-o <replaceable>outputfile</replaceable></option></term>
      <listitem><para>The filename of the output file</para></listitem>
      </varlistentry>
      <varlistentry>
      <term><replaceable>inputfile</replaceable></term>
      <listitem><para>the name(s) of input file(s)</para></listitem>
      </varlistentry>
      </variablelist>
      </formalpara>

      <formalpara><title>Bugs, limitations</title>
      <para>
      This program is not well-tested. Output is always a WAV
      file. Future versions should be able to convert
      different audio formats to a dedicated target format.
      </para></formalpara>

      <formalpara><title>Source code</title>
      <para>
      <ulink url="AudioConcat.java.html">AudioConcat.java</ulink>,
      <ulink url="SequenceAudioInputStream.java.html">SequenceAudioInputStream.java</ulink>,
      <ulink url="MixingAudioInputStream.java.html">MixingAudioInputStream.java</ulink>,
      <ulink url="http://www.urbanophile.com/arenn/hacking/download.html">gnu.getopt.Getopt</ulink>
      </para>
      </formalpara>

*/
public class AudioConcat
{
      private static final int      MODE_NONE = 0;
      private static final int      MODE_MIXING = 1;
      private static final int      MODE_CONCATENATION = 2;

      /**      Flag for debugging messages.
       *      If true, some messages are dumped to the console
       *      during operation.      
       */
      private static boolean      DEBUG = false;



      public static void main(String[] args)
      {
            /**      Mode of operation.
                  Determines what to do with the input files:
                  either mixing or concatenation.
             */
            int            nMode = MODE_NONE;
            String            strOutputFilename = null;
            AudioFormat      audioFormat = null;
            List            audioInputStreamList = new ArrayList();

            // int      nExternalBufferSize = DEFAULT_EXTERNAL_BUFFER_SIZE;
            // int      nInternalBufferSize = AudioSystem.NOT_SPECIFIED;


            /*
             *      Parsing of command-line options takes place...
             */
            Getopt      g = new Getopt("AudioConcat", args, "hDcmo:");
            int      c;
            while ((c = g.getopt()) != -1)
            {
                  switch (c)
                  {
                  case 'h':
                        printUsageAndExit();

                  case 'o':
                        strOutputFilename = g.getOptarg();
                        if (DEBUG) { out("AudioConcat.main(): output filename: " + strOutputFilename); }
                        break;

                  case 'c':
                        nMode = MODE_CONCATENATION;
                        break;

                  case 'm':
                        nMode = MODE_MIXING;
                        break;

                  case 'D':
                        DEBUG = true;
                        break;

                  case '?':
                        printUsageAndExit();

                  default:
                        out("AudioConcat.main(): getopt() returned " + c);
                        break;
                  }
            }

            /*
             *      All remaining arguments are assumed to be filenames of
             *      soundfiles we want to play.
             */
            String      strFilename = null;
            for (int i = g.getOptind(); i < args.length; i++)
            {
                  strFilename = args[i];
                  File      soundFile = new File(strFilename);

                  /*
                   *      We have to read in the sound file.
                   */
                  AudioInputStream      audioInputStream = null;
                  try
                  {
                        audioInputStream = AudioSystem.getAudioInputStream(soundFile);
                  }
                  catch (Exception e)
                  {
                        /*
                         *      In case of an exception, we dump the exception
                         *      including the stack trace to the console output.
                         *      Then, we exit the program.
                         */
                        e.printStackTrace();
                        System.exit(1);
                  }
                  AudioFormat      format = audioInputStream.getFormat();
                  /*
                    The first input file determines the audio format. This stream's
                    AudioFormat is stored. All other streams are checked against
                    this format.
                   */
                  if (audioFormat == null)
                  {
                        audioFormat = format;
                        if (DEBUG) { out("AudioConcat.main(): format: " + audioFormat); }
                  }
                  else if ( ! audioFormat.matches(format))
                  {
                        // TODO: try to convert
                        out("AudioConcat.main(): WARNING: AudioFormats don't match");
                        out("AudioConcat.main(): master format: " + audioFormat);
                        out("AudioConcat.main(): this format: " + format);
                  }
                  audioInputStreamList.add(audioInputStream);
            }

            if (audioFormat == null)
            {
                  out("No input filenames!");
                  printUsageAndExit();
            }
            AudioInputStream      audioInputStream = null;
            switch (nMode)
            {
            case MODE_CONCATENATION:
                  audioInputStream = new SequenceAudioInputStream(audioFormat, audioInputStreamList);
                  break;

            case MODE_MIXING:
                  audioInputStream = new MixingAudioInputStream(audioFormat, audioInputStreamList);
                  break;

            default:
                  out("you have to specify a mode (either -m or -c).");
                  printUsageAndExit();
            }

            if (strOutputFilename == null)
            {
                  out("you have to specify an output filename (using -o <filename>).");
                  printUsageAndExit();
            }
            File      outputFile = new File(strOutputFilename);
            try
            {
                  AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, outputFile);
            }
            catch (IOException e)
            {
                  e.printStackTrace();
            }

            if (DEBUG) { out("AudioConcat.main(): before exit"); }
            System.exit(0);
      }



      private static void printUsageAndExit()
      {
            out("AudioConcat: usage:");
            out("\tjava AudioConcat -h");
            out("\tjava AudioConcat [-D] -c|-m -o <outputfile> <inputfile> ...");
            System.exit(1);
      }



      private static void out(String strMessage)
      {
            System.out.println(strMessage);
      }
}



/*** AudioConcat.java ***/


0
Comment
Question by:Drop_of_Rain
  • 7
  • 7
  • 7
  • +1
24 Comments
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 50 total points
Comment Utility
Not very sure what the code exactly does and what the: >> gnu.getopt.jar file contains.

But you have a main () method in your class. Why don't you run that class and see what happens?
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 200 total points
Comment Utility
If I understood your requirement properly,

Then to concat all your audio files into a single file

you have to use  SequenceAudioInputStream  all the small audio files as a collection which should be passed to the constructor of "SequenceAudioInputStream" with AudioFormat.

Am I missing somewhere?  If that is the case, then let me know your exact requirement.

Regards,
Muruga.
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
I get a error message @  boolean bAnotherStreamAvailable = advanceStream in
SequenceAudioInputStream interface or class expected can we fix this problem

Let me ask you this,  I have the import gnu.getopt.Getopt; its a jar file. I tried running the program through the main it say the gnu.getopt package doesn't exist. How could I get this reconizied so I can get through the rest of it.
0
 
LVL 9

Assisted Solution

by:mmuruganandam
mmuruganandam earned 200 total points
Comment Utility
Keep that jar file in the classpath of your application.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> boolean bAnotherStreamAvailable = advanceStream

Perhaps you have closed an extra } before it. Which is why it expects a class or interface declaration to start there.
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
I am no where that yet. I am building this using a program call BlueJ. It compiles classes and you can test things without have to compile the whole program.

Are you trying to find the error problem, just reminding you if you got distracted by the jar question.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
You asked:

>> I get a error message @  boolean bAnotherStreamAvailable = advanceStream in

and:

>> I tried running the program through the main it say the gnu.getopt package doesn't exist

?
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
That is the jar file email me and I will email it to you chrisminor@thestream.org
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
> I tried running the program through the main it say the gnu.getopt package doesn't exist.

You need to run it in command prompt because the IDE may no see it.

run it like :

javac AudioConcat.java
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Are you using an IDE? If you want to compile it from your IDE, then add the JAR to the IDE's class-path because it will probably not use the System classpath.
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
Or you can add the jar file from your IDE's classpath.
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
It is a jar file, I have it and I will email it to you.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Expert Comment

by:Javatm
Comment Utility
I have it and I tested it because I've already downloaded it, so you can try my solution now by going into the comand prompt
or dos prompt.

Go to your home folder in Dos :

c:\YourFolder>

Compile the file w/ the jar file :

c:\YourFolder> c:\javac\bin\javac AudioConcat.java
0
 
LVL 9

Expert Comment

by:mmuruganandam
Comment Utility
>> c:\YourFolder> c:\javac\bin\javac AudioConcat.java

c:\YourFolder> c:\javac\bin\javac  -classpath <jar which contains "gnu.getopt.Getopt"> AudioConcat.java
c:\YourFolder> c:\javac\bin\java  -classpath <jar which contains "gnu.getopt.Getopt"> AudioConcat
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
I got a illegal start of expression here. I included the code again



else
            {
                  /*
                    The most common case: We return the length.
                  */
                  return nBytesRead;
            }




import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.BooleanControl;



public class SequenceAudioInputStream
      extends            AudioInputStream
{
      private static final boolean      DEBUG = true;

      private List                  m_audioInputStreamList;
      private      int                  m_nCurrentStream;



      public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams)
      {
            super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED);
            m_audioInputStreamList = new ArrayList(audioInputStreams);
            m_nCurrentStream = 0;
      }



      // TODO: remove
      private boolean addAudioInputStream(AudioInputStream audioStream)
      {
            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): called.");
            }
            // Contract.check(audioStream != null);
            if (!getFormat().matches(audioStream.getFormat()))
            {
                  if (DEBUG)
                  {
                        out("SequenceAudioInputStream.addAudioInputStream(): audio formats do not match, trying to convert.");
                  }
                  AudioInputStream      asold = audioStream;
                  audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);
                  if (audioStream == null)
                  {
                        out("###  SequenceAudioInputStream.addAudioInputStream(): could not convert.");
                        return false;
                  }
                  if (DEBUG)
                  {
                        out(" converted");
                  }
            }
            // Contract.check(audioStream != null);
            synchronized (m_audioInputStreamList)
            {
                  m_audioInputStreamList.add(audioStream);
                  m_audioInputStreamList.notifyAll();
            }
            if (DEBUG)
            {
                  out("SequenceAudioInputStream.addAudioInputStream(): enqueued " + audioStream);
            }
            return true;
      }



      private AudioInputStream getCurrentStream()
      {
            return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
      }



      private boolean advanceStream()
      {
            m_nCurrentStream++;
            boolean      bAnotherStreamAvailable = (m_nCurrentStream < m_audioInputStreamList.size());
            return bAnotherStreamAvailable;
      }



      public long getFrameLength()
      {
            long      lLengthInFrames = 0;
            Iterator      streamIterator = m_audioInputStreamList.iterator();
            while (streamIterator.hasNext())
            {
                  AudioInputStream      stream = (AudioInputStream) streamIterator.next();
                  long      lLength = stream.getFrameLength();
                  if (lLength == AudioSystem.NOT_SPECIFIED)
                  {
                        return AudioSystem.NOT_SPECIFIED;
                  }
                  else
                  {
                        lLengthInFrames += lLength;
                  }
            }
            return lLengthInFrames;
      }



      public int read()
            throws      IOException
      {
            AudioInputStream      stream = getCurrentStream();
            int      nByte = stream.read();
            if (nByte == -1)
            {
                  /*
                    The end of the current stream has been signaled.
                    We try to advance to the next stream.
                  
                  boolean      bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                          There is another stream. We recurse into this method
                          to read from it.
                        */
                        return read();
                  }
                  else
                  {
                        /*
                          No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                    The most common case: We return the byte.
                  */
                  return nByte;
            }
      }



      public int read(byte[] abData, int nOffset, int nLength)
            throws      IOException
      {
            AudioInputStream      stream = getCurrentStream();
            int      nBytesRead = stream.read(abData, nOffset, nLength);
            if (nBytesRead == -1)
            {
                  /*
                    The end of the current stream has been signaled.
                    We try to advance to the next stream.
                  */
                  boolean      bAnotherStreamAvailable = advanceStream();
                  if (bAnotherStreamAvailable)
                  {
                        /*
                          There is another stream. We recurse into this method
                          to read from it.
                        */
                        return read(abData, nOffset, nLength);
                  }
                  else
                  {
                        /*
                          No more data. We signal EOF.
                        */
                        return -1;
                  }
            }
            else
            {
                  /*
                    The most common case: We return the length.
                  */
                  return nBytesRead;
            }
      }



      public long skip(long lLength)
            throws      IOException
      {
            throw new IOException("skip() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public int available()
            throws      IOException
      {
            return getCurrentStream().available();
      }



      public void close()
            throws      IOException
      {
            // TODO: should we close all streams in the list?
      }



      public void mark(int nReadLimit)
      {
            throw new RuntimeException("mark() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public void reset()
            throws      IOException
      {
            throw new IOException("reset() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }



      public boolean markSupported()
      {
            return false;
      }



      private static void out(String strMessage)
      {
            System.out.println(strMessage);
      }
}



/*** SequenceAudioInputStream.java ***/
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
> c:\YourFolder> c:\javac\bin\javac  -classpath <jar which contains "gnu.getopt.Getopt"> AudioConcat.java
> c:\YourFolder> c:\javac\bin\java  -classpath <jar which contains "gnu.getopt.Getopt"> AudioConcat

Where c:\javac is the jdk folder

c:\YourFolder> c:\javac\bin\javac -classpath java-getopt-1.0.9.jar AudioConcat.java
c:\YourFolder> c:\javac\bin\java -classpath java-getopt-1.0.9.jar AudioConcat

Hope that helps . . .
Javatm
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> I got a illegal start of expression here

That else statement is there in more than one method. Can you specify which one gives the error?
0
 
LVL 15

Assisted Solution

by:Javatm
Javatm earned 250 total points
Comment Utility
Try this :

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.BooleanControl;

public class SequenceAudioInputStream extends AudioInputStream {

        private static final boolean DEBUG = true;
        private List m_audioInputStreamList;
        private int m_nCurrentStream;

      public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams)
      {
      super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED);
      m_audioInputStreamList = new ArrayList(audioInputStreams);
      m_nCurrentStream = 0;
      }

      private boolean addAudioInputStream(AudioInputStream audioStream)
      {
      if (DEBUG) {
      out("SequenceAudioInputStream.addAudioInputStream(): called.");
      }

      if (!getFormat().matches(audioStream.getFormat()))
      {
      if (DEBUG) {
      out("SequenceAudioInputStream.addAudioInputStream(): audio formats do not match, trying to convert.");
      }

      AudioInputStream asold = audioStream;
      audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);
      if (audioStream == null) {
      out("### SequenceAudioInputStream.addAudioInputStream(): could not convert.");
      return false;
      }

      if (DEBUG) {
      out(" converted");
      }
      }

      synchronized (m_audioInputStreamList)
      {
      m_audioInputStreamList.add(audioStream);
      m_audioInputStreamList.notifyAll();
      }

      if (DEBUG) {
      out("SequenceAudioInputStream.addAudioInputStream(): enqueued " + audioStream);
      }
      return true;
      }

      private AudioInputStream getCurrentStream()
      {
      return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
      }

      private boolean advanceStream()
      {
      m_nCurrentStream++;
      boolean bAnotherStreamAvailable = (m_nCurrentStream < m_audioInputStreamList.size());
      return bAnotherStreamAvailable;
      }

      public long getFrameLength()
      {
      long lLengthInFrames = 0;
      Iterator streamIterator = m_audioInputStreamList.iterator();
      while (streamIterator.hasNext())
      {
      AudioInputStream stream = (AudioInputStream) streamIterator.next();
      long lLength = stream.getFrameLength();
      if (lLength == AudioSystem.NOT_SPECIFIED)
      {
      return AudioSystem.NOT_SPECIFIED;
      }
      else {
      lLengthInFrames += lLength;
      }
      }
      return lLengthInFrames;
      }

      public int read() throws IOException {
      AudioInputStream stream = getCurrentStream();
      int nByte = stream.read();
      if (nByte == -1)
      {
      /*
      The end of the current stream has been signaled.
      We try to advance to the next stream.
      */
      boolean bAnotherStreamAvailable = advanceStream();
      if (bAnotherStreamAvailable)
      {
      /*
      There is another stream. We recurse into this method
      to read from it.
      */
      return read();
      }
      else
      {
      /*
      No more data. We signal EOF.
      */
      return -1;
      }
      }
      else
      {
      /*
      The most common case: We return the byte.
      */
      return nByte;
      }
      }

      public int read(byte[] abData, int nOffset, int nLength) throws IOException
      {
      AudioInputStream stream = getCurrentStream();
      int nBytesRead = stream.read(abData, nOffset, nLength);
      if (nBytesRead == -1)
      {                  
      /*
      The end of the current stream has been signaled.
      We try to advance to the next stream.
      */
      boolean bAnotherStreamAvailable = advanceStream();
      if (bAnotherStreamAvailable)
      {
      /*
      There is another stream. We recurse into this method
      to read from it.
      */
      return read(abData, nOffset, nLength);
      }
      else
      {
      /*
      No more data. We signal EOF.
      */
      return -1;
      }
      }
      else
      {
      /*
      The most common case: We return the length.
      */
      return nBytesRead;
      }
      }

      public long skip(long lLength) throws IOException {
      throw new IOException("skip() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }

      public int available()
      throws IOException
      {
      return getCurrentStream().available();
      }

      public void close() throws IOException {
      // TODO: should we close all streams in the list?
      }

      public void mark(int nReadLimit)
      {
      throw new RuntimeException("mark() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }

      public void reset() throws IOException
      {
      throw new IOException("reset() is not implemented in class SequenceInputStream. Mail <Matthias.Pfisterer@web.de> if you need this feature.");
      }

      public boolean markSupported() {
      return false;
      }

      private static void out(String strMessage)
      {
      System.out.println(strMessage);
      }
}

0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Ah, sorry, I guess its there in only one method. I guess the else block is somehow misplaced (though it doesn't look like it is).
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
Javatm that fixed it I emailed you.
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
Ha ha I very happy for you great !
Need to go home now, thanks . . .

Friend : Javatm
0
 

Author Comment

by:Drop_of_Rain
Comment Utility
Javatm Are we going to be able to use it in the program
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
What is the problem now?
0
 
LVL 15

Expert Comment

by:Javatm
Comment Utility
> Javatm Are we going to be able to use it in the program

Yes, We can we just need to know how to use it in your situation.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now