IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Multimédia Java Discussion :

[Audio]Java et fichiers Wav


Sujet :

Multimédia Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    25
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 25
    Points : 23
    Points
    23
    Par défaut [Audio]Java et fichiers Wav
    Bonjour,

    Je souhaiterais decoder un fichier Wav en utilisant Java mais attention, je ne veux pas rediriger la sortie vers les haut parleurs mais seulement recuperer les valeurs numeriques d'echatillonage du fichier sonore. En effet, celles ci peuvent contituer les coordonnees d'un vecteur Pourriez vous m'aider?

  2. #2
    Membre expérimenté Avatar de yann2
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2004
    Messages
    897
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 897
    Points : 1 635
    Points
    1 635
    Par défaut
    Salut,

    Regarde le package javax.sound.sampled

    Faut que tu regardes tous.

    Tu as une classe AudioInputStream.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    25
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 25
    Points : 23
    Points
    23
    Par défaut
    Yahoo woupidoo... cela semble fonctionner a merveille. Je mets un peu de code pour ceux que cela interesse. Si vous voyez des erreurs, n'hesitez pas a me le dire

    Je ne le mets pas encore en resolu. Je ne le ferai que demain ou apres demain, en attente d'eventuelles remarques

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioFileFormat;
    import java.io.InputStream;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.util.Vector;
    import java.net.URL;
    import java.lang.Exception;
    import java.lang.Integer;
    import java.lang.Byte;
    import java.io.DataOutputStream;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.util.Enumeration;
     
    public class Testsound {
     
      static private URL inputURL;
      static private AudioFileFormat audioFileFormat;
      static private AudioInputStream audioInputStream;
      static private AudioFormat audioFormat;
      static private Vector samples;
      static private DataOutputStream output = null;
     
     
      public Testsound(String fichier) {
        try {
          inputURL = new URL("file:" + fichier);
          audioFileFormat = AudioSystem.getAudioFileFormat(inputURL);
          audioInputStream = AudioSystem.getAudioInputStream(inputURL);
          audioFormat = audioInputStream.getFormat();
          samples = new Vector();
        } catch (Exception e) {
          System.out.println("Constructor: " + e.toString());
        }
      }//End Testsound
     
     
      public static int unsignedByteToInt(byte b) {
        return (int) b & 0xFF;
      }//End unsignedByteToInt
     
     
      public static long byteArrayToInt(byte buf[], int size, boolean bigEndian) {
        long i = 0;
        int pos = 0;
        if (!bigEndian) {
          for (int j=size-1;j>=0;j--)
            i += (new Byte(buf[pos++])).intValue() << (8 * j);
        }
        else {
          for (int j=0;j<size;j++)
            i += (new Byte(buf[pos++])).intValue() << (8 * j);
        }
        return i;
      }//End byteArrayToInt
     
     
      public int numBytes(AudioInputStream a) {
        return (int) (a.getFrameLength() * a.getFormat().getFrameSize());
      }//End numBytes
     
     
      public void computeArray(ByteArrayInputStream a) {
        int cnt = 0;
        boolean bool = audioFormat.isBigEndian();
        int sampleSize = audioFormat.getSampleSizeInBits() / 8;
        byte tableau[] = new byte[sampleSize];
        if (audioFormat.getChannels() == 1) { //Mono
          while (cnt != -1) {
            cnt = a.read(tableau, 0, sampleSize);
            samples.add(new Integer((int) byteArrayToInt(tableau, sampleSize, bool)));
          }
        }
        if (audioFormat.getChannels() == 2) { //Stereo
          while (cnt != -1) {
            cnt = a.read(tableau, 0, sampleSize);
            samples.add(new Integer((int) byteArrayToInt(tableau, sampleSize, bool)));
            if (cnt != -1) cnt = a.read(tableau, 0, sampleSize);
          }
        }
      }//End computeArray
     
     
      public void readSound() {
        int cnt = 0;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte tempBuffer[] = new byte[10000];
        try {
          //Lecture du fichier audio par 10000 exemplaires a la fois
          while( (cnt = audioInputStream.read(tempBuffer, 0, tempBuffer.length)) != -1) byteArrayOutputStream.write(tempBuffer, 0, cnt);
          audioInputStream.close();
          byte audioData[] = byteArrayOutputStream.toByteArray();
          ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(audioData);
          computeArray(byteArrayInputStream);
        } catch (Exception e) {
          System.out.println("readSound: " + e.toString());
        }
      }//End readSound
     
     
      public Vector getSamples() {
        return samples;
      }//End getSamples
     
     
    	public void writeApplication(DataOutputStream out, String s) {
    		try {        
    			byte[] array = new byte[s.length()];
    			array = s.getBytes("UTF-8");
    			for (int i = 0; i < s.length(); i++) {
    	 	 		out.writeByte(array[i]);
    			} //end for
    		} catch (Exception e) {
    			System.out.println(e);	
    		} //end try
    	} //end writeApplication
     
     
      public void getSamplesCSV() {
        try {
          output = new DataOutputStream(new FileOutputStream(new File("test.csv")));
    			writeApplication(output, "\"");
    			for (Enumeration o=samples.elements(); o.hasMoreElements();) writeApplication(output, o.nextElement().toString() + "\",\n\"");
    			writeApplication(output, "\"");
    			output.close();
        } catch (Exception e) {
          System.out.println(e.toString());
        }
      }//End getSamplesCSV
     
     
      public static void main(String args[]) {
        Testsound t = new Testsound(args[0]);    
        t.readSound();
        t.getSamplesCSV(); //Pour faire un chart, c'est plus rapide... :D
      }//End main
    }//End class

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 13
    Points : 6
    Points
    6
    Par défaut
    ba wai c interessant mais cimer pour la doc...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ecriture du flux audio dans un fichier WAV
    Par firepolo dans le forum C++
    Réponses: 6
    Dernier message: 17/10/2012, 10h44
  2. Comment jouer des fichiers wav en java, simplement?
    Par Invité dans le forum Langage
    Réponses: 11
    Dernier message: 25/02/2009, 11h53
  3. [Audio] convertir fichier wav en mp3 ?!?
    Par solarien dans le forum Multimédia
    Réponses: 3
    Dernier message: 14/12/2008, 00h48
  4. [Audio] Gérer des fichiers sons en Java
    Par womannosky dans le forum Multimédia
    Réponses: 8
    Dernier message: 04/08/2008, 15h06
  5. Récuperer le signal audio d'un fichier .wav
    Par vienin dans le forum Multimédia
    Réponses: 2
    Dernier message: 11/10/2005, 16h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo