/* * GSMEncoder.java * * This file is part of the Java Sound Examples. */ /* * Copyright (c) 1999, 2000 by Matthias Pfisterer * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ import java.io.IOException; import java.io.File; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; // not portable, but cannot be avoided currently import org.tritonus.share.sampled.AudioFileTypes; import org.tritonus.share.sampled.Encodings; // TODO: try a single conversion to 8kHz, 16 bit linear signed, mono /* +DocBookXML Encoding an audio file to GSM 06.10 Purpose Encodes a PCM audio file, writes the result as a GSM 06.10 file. Level advanced Usage java GSMEncoder pcmfile gsmfile Parameters the name of the PCM input file. the name of the GSM output file. Bugs, limitations The input file has to be 8 kHz, 16 bit linear signed, mono. GSM 06.10 can only be handled natively by Tritonus. If you want to use this format with the Sun jdk1.3, you have to install the respective plug-in from Tritonus Plug-ins. Source code GSMEncoder.java -DocBookXML */ public class GSMEncoder { public static void main(String[] args) { if (args.length != 2) { printUsageAndExit(); } File pcmFile = new File(args[0]); File gsmFile = new File(args[1]); AudioInputStream ais = null; try { ais = AudioSystem.getAudioInputStream(pcmFile); } catch (Exception e) { e.printStackTrace(); } if (ais == null) { System.out.println("cannot open audio file"); System.exit(1); } AudioFormat.Encoding targetEncoding = Encodings.getEncoding("GSM0610"); AudioInputStream gsmAIS = AudioSystem.getAudioInputStream(targetEncoding, ais); AudioFileFormat.Type fileType = AudioFileTypes.getType("GSM", ".gsm"); int nWrittenFrames = 0; try { nWrittenFrames = AudioSystem.write(gsmAIS, fileType, gsmFile); } catch (IOException e) { e.printStackTrace(); } } private static void printUsageAndExit() { System.out.println("GSMEncoder: usage:"); System.out.println("\tjava GSMEncoder "); System.exit(1); } } /*** GSMEncoder.java ***/