This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Need help writing non-gui JMF program

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to write a program that will convert a WAV file from a ULAW format to a GSM WAV file format. I first tried this with the Java Sound API and the WAV file format of GSM was not supported so I stumbled across JMF.

I can use the JMStudio and Export GUI programs that come with JMF to convert the wav file as needed. But now I'm trying to write a batch program (non-gui) to convert the file on the fly.

First, is this possible. Second, does anyone have any code samples of a batch java program using JMF in batch.

Thanks,
Scott
 
Scott Wade
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out. Include the JMF.jar in your project and here is the code.

import java.io.IOException;

import javax.media.DataSink;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoDataSourceException;
import javax.media.Processor;
import javax.media.control.TrackControl;
import javax.media.format.AudioFormat;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;

import jmapps.util.StateHelper;

public class TestAudio5 {

public static void main(String[] args) {


try {
Processor p = null;
StateHelper sh = null;

DataSource inSource = Manager.createDataSource(
new MediaLocator("file:c:\\ASSURANCE_THREE_MINUTE.wav"));

p = Manager.createProcessor(inSource);
sh = new StateHelper(p);
//Configure the processor
if (!sh.configure(10000)) {
System.out.println("can't configure");
System.exit(-1);
}
p.setContentDescriptor(new
FileTypeDescriptor(FileTypeDescriptor.WAVE));


//AudioFormat(java.lang.String encoding, double sampleRate, int sampleSizeInBits, int channels)
//AudioFormat(
//java.lang.String encoding,
//double sampleRate,
//int sampleSizeInBits,
//int channels,
//int endian,
//int signed,
//int frameSizeInBits,
//double frameRate,
//java.lang.Class dataType)

AudioFormat outputFormat = new javax.media.format.AudioFormat(
AudioFormat.GSM_MS,
8000.0,
0,
1,
0,
1,
520,
1625.0,
null);


System.out.println("outputFormat: " + outputFormat.toString());
TrackControl tc[] = p.getTrackControls();
for ( int i = 0; i < tc.length; i++ ) {

tc[i].setEnabled(true);
System.out.println("before format: " + tc[i].getFormat().toString());
tc[i].setFormat(outputFormat);
System.out.println("after format: " + tc[i].getFormat().toString());

}

if (!sh.realize(10000)) {
System.out.println("can't realize");
System.exit(-1);
}

// get the output of the processor
DataSource source = p.getDataOutput();
// create a File protocol MediaLocator with the location
// of the file to which bits are to be written
MediaLocator dest = new MediaLocator("file://c:\\test.wav");
// create a datasink to do the file writing & open the
// sink to make sure we can write to it.
DataSink filewriter = null;

filewriter = Manager.createDataSink(source, dest);
filewriter.open();


// now start the filewriter and processor

filewriter.start();

sh.playToEndOfMedia(5000);
sh.close();

filewriter.close();


} catch (NoDataSourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("done!");
System.exit(-1);
}
}
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic