Author: remi Date: 2008-11-26 17:49:19 +0100 (Wed, 26 Nov 2008) New Revision: 2848
Modified:
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/audiotool/JSimpleAudioConverter.java
Log:
* refactored lame and sox wrappers
Modified:
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/audiotool/JSimpleAudioConverter.java
===================================================================
---
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/audiotool/JSimpleAudioConverter.java
2008-11-26 14:39:29 UTC (rev 2847)
+++
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/audiotool/JSimpleAudioConverter.java
2008-11-26 16:49:19 UTC (rev 2848)
@@ -22,27 +22,78 @@
package com.tuxisalive.audiotool;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
public class JSimpleAudioConverter
{
/*
*
*/
- private static Boolean execWait(String cmd)
+ private static Boolean execWait(String cmd[])
{
- Process p;
+ final Process p;
Boolean result = true;
-
+
try
{
p = Runtime.getRuntime().exec(cmd);
- p.getOutputStream().close();
- p.getInputStream().close();
- p.getErrorStream().close();
+
+ // Input stream consumation.
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ BufferedReader reader = new
BufferedReader(new InputStreamReader(p.getInputStream()));
+ try
+ {
+ while(reader.readLine()
!= null) {}
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+ catch(IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+ }.start();
+
+ // Error stream consumation.
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ BufferedReader reader = new
BufferedReader(new InputStreamReader(p.getErrorStream()));
+ try
+ {
+ while(reader.readLine()
!= null) {}
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+ catch(IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+ }.start();
+
+ // Wait the end of task
p.waitFor();
+
+ // Check the exit value (Must be 0 for no error)
int ret = p.exitValue();
-
if (ret != 0)
{
result = false;
@@ -68,12 +119,15 @@
if (!wavFilePath.toLowerCase().endsWith(".wav"))
{
- System.out.println("Bad wav");
return false;
}
- String cmd = String.format("lame --decode \"%s\" \"%s\"",
- mp3FilePath, wavFilePath);
+ String cmd[] = new String[] {
+ "lame",
+ "--decode",
+ mp3FilePath,
+ wavFilePath
+ };
return execWait(cmd);
}
@@ -155,9 +209,39 @@
return false;
}
- String cmd = String.format("sox -v 0.9 \"%s\" -r %s %s -c %d
\"%s\"",
- wavSrcFilePath, sr, br, channelCount,
wavDstFilePath);
+ String cmd[];
+ if (System.getProperty("os.name").contains("Windows"))
+ {
+ cmd = new String[] {
+ "sox",
+ "-v",
+ "0.9",
+ wavSrcFilePath,
+ "-r",
+ sr,
+ br,
+ "-c",
+ String.valueOf(channelCount),
+ wavDstFilePath
+ };
+ }
+ else
+ {
+ cmd = new String[] {
+ "sox",
+ "-v",
+ "0.9",
+ wavSrcFilePath,
+ "-r",
+ String.valueOf(sampleRate),
+ br,
+ "-c",
+ String.valueOf(channelCount),
+ wavDstFilePath
+ };
+ }
+
return execWait(cmd);
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn
