Waveread java vs matlab

Fermé
meryem_yousfi Messages postés 1 Date d'inscription samedi 14 février 2015 Statut Membre Dernière intervention 15 février 2015 - 14 févr. 2015 à 12:02
 Utilisateur anonyme - 14 févr. 2015 à 12:36
hi every one
I am trying to read data of a .wav file both in java and matlab and save as an array of bytes.
In java the code looks as follows:

package mémoire_master;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
*
  • @author Lahmar Intel Info
  • /

public class ReadWav {
// declaration des variable
static int frameSample;
static int timeofFrame;
static int runTimes;
static int bps;
static int channels;
static double times;
static int bufSize;
static int frameSize;
static int frameRate;
long length;
public static int nomber_lignes ;
public static float Data1[] ;
public static float Data2[] ;
public static Byte F[] ;


FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
int k = 0;
int i = 0;
int m = 0;
int l = 0;


//////////////////////////
public void convert_to_matrice (String Path) throws UnsupportedAudioFileException, IOException{
try
{
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(Path));
File file = new File(Path);
length = file.length();
nomber_lignes=(int) ((length-44)/2);
Data1 = new float[(int)nomber_lignes] ;
Data2 = new float[(int)nomber_lignes] ;

System.out.println("nomber size : " + nomber_lignes); /*To get the file size*/
F = new Byte[(int)length] ;
System.out.println("File size : " + length); /*To get the file size*/
AudioFormat af = ais.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
///////////////////////
if (!AudioSystem.isLineSupported(info))
{
System.out.println("unsupported line");
System.exit(0);
}


//////////////////////
frameRate = (int)af.getFrameRate(); //the number of frames per second
System.out.println("Frame Rate: " + frameRate);

frameSize = af.getFrameSize(); // the number of bytes per frame
System.out.println("Frame Size: " + frameSize);

bufSize = frameRate * frameSize / 10;
System.out.println("Buffer Size: " + bufSize); // the number of bytes per second

channels = af.getChannels();
System.out.println("Channels : " + channels); // mono or stéreo

bps = af.getSampleSizeInBits();
System.out.println("Bits per sample : " + bps); // the number of bits in each sample

times = (double)(length / (frameRate * channels * bps / 8)); // Duration of the songs
System.out.println("Duration of the songs : " + times +" seconds");

timeofFrame = 20; //20ms
frameSample = (timeofFrame * frameRate) / 1000;
runTimes = (int) (times * 1000) / 20;

///////////////////////////
fis = new FileInputStream(Path);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
//////////////////////////
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
F[i] = dis.readByte();
System.out.println(F[i]);

if (i >= 44)
{
if ((i % 2)!= 0) {
Data1 [k] = F[i];
// System.out.println(Data1[k]);
k++;


}

else{
if ((i % 2)== 0)
{
Data2 [m] = F[i];
// System.out.println(Data2[m]);
m++;
}
}

} i++; }
// System.out.println("i "+i);


}
catch (Exception e)
{
System.out.println("exception "+e.toString());
}

}


}
In matlab I am using the wavread function:

y = wavread(path)

But the results I am getting are different?
A voir également:

1 réponse

Utilisateur anonyme
14 févr. 2015 à 12:36
Hello this forum is french speak langage.
So you have two possibility: ask your question in french or going to the international version of the forum http://en.kioskea.net/forum/programming-3.

I close this subject.

--
0