putting args into a class

How would I load the files in this code into the next program AudioConcat.

public class AudioTest
{
      public static void main(String[] args)
      {
            args =
                  new String[] {
                        "-c",  // concatenation mode
                        "-o",  // output file specified
                        "c:/test/test.wav", // output file
                        "c:/test/wav/kp1.wav", // input file 1
                        "c:/test/wav/kp2.wav", // input file 2
                        "c:/test/wav/kp3.wav", // input file 3
                        "c:/test/wav/kp4.wav" // input file 4
                        };

            AudioConcat.main(args);
      }
}



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 ***/
Drop_of_RainAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mmuruganandamConnect With a Mentor Commented:
You can use the Same AudioTest.java to invoke the AudioConcat program.

Regards,
Muruga
0
 
WebstormCommented:
What is the problem ?

If the files are not found, replace / by \ in the file paths: "c:\\test\\test.wav"
0
 
Drop_of_RainAuthor Commented:
I ran into a problem with an error exception previus question: Exception in thread "main" java.lang.NoC...

So I thoughI would work right from within the class.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Drop_of_RainAuthor Commented:
I put this at the command line and got this info:

C:\>cd test

C:\test>java AudioConcat -c -o c:/test/wav/test.wav,c:/test/wav/kp1.wav,c:/test/
wav/kp2.wav
Exception in thread "main" java.lang.NoClassDefFoundError: AudioConcat

C:\test>java AudioConcat -c -o c:/test/wav/test.wav,c:/test/wav/kp1.wav.c:/test/
wav/kp2.wav
Exception in thread "main" java.lang.UnsupportedClassVersionError: AudioConcat (
Unsupported major.minor version 48.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Here the info on the program


Purpose. 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 -c) or containing a mixdown of all the other files (mixing mode, option -m). For concatenation, the input files must have the same audio format. They need not have the same file type.

Usage.  

java AudioConcat -h

java AudioConcat [ -D ] [ -c ] | [ -m ] -o outputfile inputfile ...


Parameters.

-c
selects concatenation mode

-m
selects mixing mode

-o outputfile
The filename of the output file

inputfile
the name(s) of input file(s)





I put this at the command line and got this info:

0
 
searlasCommented:
Seems like AudioConcat was compiled with a different (newer) version of Java then the one you are using to run it.
0
 
Drop_of_RainAuthor Commented:
I compiled it in a ide I only have one java that I know of. What do you think I shoud try.

Did I enter the args correctly?
0
 
Drop_of_RainAuthor Commented:
I will try from the command line to compile it. I did get this from someone else already compiled.
0
 
objectsCommented:
C:\test>java AudioConcat -c -o c:/test/wav/test.wav,c:/test/wav/kp1.wav,c:/test/
wav/kp2.wav
Exception in thread "main" java.lang.NoClassDefFoundError: AudioConcat

C:\test>java AudioConcat -c -o c:/test/wav/test.wav,c:/test/wav/kp1.wav.c:/test/
wav/kp2.wav
Exception in thread "main" java.lang.UnsupportedClassVersionError: AudioConcat (
Unsupported major.minor version 48.0)


Which error is it u get when you run this?
0
 
Drop_of_RainAuthor Commented:
I got all of that at the same time. I think I found the problem. I will be working on it a little later, I will go from there. I didn't have a class that was needed, I was going by so9mething I was told. Let me work on this for a few hours from now, and we can start from there.

I will have some other questions at that time as well!
0
 
Drop_of_RainAuthor Commented:
I am having problems with this part of the program as well MixingAudioInputStream(audioFormat, audioInputStreamList); so I just want to let this go for now.
0
 
Drop_of_RainAuthor Commented:
Thanks everyone
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.