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

2D Java Discussion :

waveform avec java


Sujet :

2D Java

  1. #1
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 46
    Par défaut waveform avec java
    bonjour,
    comment créer le waveform d'un signal audio avec java
    c'es une pb que je soufre d'elle depuis deux semaine
    merci pour vos aides

  2. #2
    Membre Expert Avatar de Uther
    Homme Profil pro
    Tourneur Fraiseur
    Inscrit en
    Avril 2002
    Messages
    4 680
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Tourneur Fraiseur

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 680
    Par défaut
    Qu'est ce qui te poses, problème?
    l'enregistrement, l'affichage?

  3. #3
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 46
    Par défaut waveform avec java
    bonjour,
    mon pb exactement c'es comment tracer la forme d'onde d'un son choisi
    c'es à dire lire un son w au meme temps tracer sa forme d'onde
    merci pour vos aides

  4. #4
    Membre Expert Avatar de Uther
    Homme Profil pro
    Tourneur Fraiseur
    Inscrit en
    Avril 2002
    Messages
    4 680
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Tourneur Fraiseur

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 680
    Par défaut
    Je répète ma question soit plus précis sur ce qui te pose poblème sinon il va être dur de t'aider.

    Le son est il acquis sur la carte son ou lu depuis un fichier?
    Dans le cas d'un ficher, quel format?
    Est-ce l'aquisition/lecture des donnéeés qui te pose problème?
    Est-ce le dessin de la waveform?

  5. #5
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 46
    Par défaut waveform avec java
    bonjour,
    le son depuis un fichier
    extension .wav
    le problem c'es de dessiner sa waveform
    je peux vous donné mon code
    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
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    /**
     * @(#)Framework.java
     *
     *
     * @author 
     * @version 1.00 2010/1/3
     */
     import java.io.File;
    import javax.swing.JLabel;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.event.*;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.*;
    import javax.swing.SwingUtilities;
    import javax.swing.filechooser.*;
    import javax.swing.JSlider;
    import javax.swing.JOptionPane;
    import java.io.*;
    import javax.sound.sampled.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.sound.sampled.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.File;
    import java.io.IOException;
    import java.text.DecimalFormat;
    import java.util.Vector;
     
     
     
    /* Framework.java requires no other files. */
    public class Framework extends WindowAdapter  {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
     
        public Framework() {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            maxX = screenSize.width - 50;
            maxY = screenSize.height - 50;
            makeNewWindow();
     
        }
     
        public void makeNewWindow() {
     
     
        	JFrame frame = new MyFrame(this);
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
     
     
     
     
     
     
            if (lastLocation != null) {
                //Move the window over and down 40 pixels.
                lastLocation.translate(40, 40);
                if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                    lastLocation.setLocation(0, 0);
                }
                frame.setLocation(lastLocation);
            } else {
                lastLocation = frame.getLocation();
            }
     
             System.out.println("Frame location: " + lastLocation);
             frame.setVisible(true);
     
        }
     
        //This method must be evoked from the event-dispatching thread.
        public void quit(JFrame frame) {
            if (quitConfirmed(frame)) {
                System.out.println("Quitting.");
                System.exit(0);
            }
            System.out.println("Quit operation not confirmed; staying alive.");
        }
     
     
       public void windowClosed(WindowEvent e) {
            numWindows--;
            System.out.println("Number of windows = " + numWindows);
            if (numWindows <= 0) {
                System.out.println("All windows gone.  Bye bye!");
                System.exit(0);
            }
        }
        private boolean quitConfirmed(JFrame frame) {
            String s1 = "Quit";
            String s2 = "Cancel";
            Object[] options = {s1, s2};
            int n = JOptionPane.showOptionDialog(frame,
                    "Vous voulez vraiment Quiter?",
                    "Quit Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    options,
                    s1);
            if (n == JOptionPane.YES_OPTION) {
                return true;
            } else {
                return false;
            }
        }
     
     
     
     
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            Framework framework = new Framework();
     
        }
     
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
     
        class MyFrame extends JFrame implements ActionListener {
            protected Dimension defaultSize = new Dimension(900, 600);
            protected Framework framework = null;
            private JLabel l1;
            private  JButton b_play;
            private JButton b_stop;
            private JButton b_ouvrir;
            private JCheckBox ch5;
            private File fichier = null;
            private AudioFormat format;
            private byte[] samples;
            private JFileChooser jfc = new JFileChooser();
     
            JFileChooser fc;
     
            public void sound()
        {
            try
            {
                AudioInputStream stream = AudioSystem.getAudioInputStream(this.fichier);
                this.format = stream.getFormat();
                this.getSamples(stream);
            }
                catch (Exception e){}
        }
        public void getSamples(AudioInputStream stream)
        {
            int length = (int)(stream.getFrameLength() * format.getFrameSize());
            this.samples = new byte[length];
            DataInputStream in = new DataInputStream(stream);
            try
            {
                in.readFully(this.samples);
            }
                catch (IOException e){}
        }
     
        public byte[] getSamples()
        {
            return this.samples;
        }
        public void play(InputStream source)
        {
            // 100 ms buffer for real time change to the sound stream
            int bufferSize = this.format.getFrameSize() * Math.round(this.format.getSampleRate() / 10);
            byte[] buffer = new byte[bufferSize];
            SourceDataLine line;
            try
            {
                DataLine.Info info = new DataLine.Info(SourceDataLine.class, this.format);
                line = (SourceDataLine)AudioSystem.getLine(info);
                line.open(this.format, bufferSize);
                line.start();
                int numBytesRead = 0;
                while (numBytesRead != -1)
                {
                    numBytesRead = source.read(buffer, 0, buffer.length);
                    if (numBytesRead != -1)
                        line.write(buffer, 0, numBytesRead);
                }
                line.drain();
                line.close();
            }
                catch (Exception e){}
        }
        public void ouvrir()
        {
            this.jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            this.jfc.addChoosableFileFilter(new FiltreExtension(".wav", "Fichier wav"));
            this.jfc.addChoosableFileFilter(new FiltreExtension(".wav", "Fichier wav"));
            int returnVal = this.jfc.showOpenDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION)
            {
                this.fichier = this.jfc.getSelectedFile();
            }
        }
         private class Lecture
                extends Thread
        {
            public void run()
            {
                play(new ByteArrayInputStream(getSamples()));
            }
        }
            public MyFrame(Framework controller) {
                super("Traitement Numérique de signal ");
                framework = controller;
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                addWindowListener(framework);
                setLocation(50,50);
                setLayout(new BorderLayout());
     
     
                  JPanel p2 =new JPanel();
     
     
                   b_ouvrir = new JButton("Ouvrir");
                  p2.add(b_ouvrir);
     
                 this.b_ouvrir.addActionListener(this);
                  JLabel l1=new JLabel("***son***");
                  p2.add(l1);
                   b_play = new JButton("Play");
                  p2.add(b_play);
                  this.b_play.addActionListener(this);
                   b_stop = new JButton("Stop");
                  p2.add(b_stop);
                  this.b_stop.addActionListener(this);
     
     
     
     
     
                    	JLabel l2=new JLabel("***visualiser signal***");
                    	p2.add(l2);
                  JButton b5 = new JButton("play");
                  p2.add(b5);
                   JButton b7 = new JButton("stop");
                  p2.add(b7);
                   JButton b4 = new JButton("Spectr");
                  p2.add(b4);
     
     
                  JButton b6 = new JButton("EXIT");
                  p2.add(b6);
                  b6.addActionListener(new ActionListener() {//exit
                    public void actionPerformed(ActionEvent e) {
                         new VoicePromptPlayer();
     
     
     
                    	}});
                  add("North",p2);
     
     
                  JPanel p1=new JPanel();
                  p1.setLayout(new BorderLayout());           
                  JPanel p3=new JPanel();
     
     
                  JCheckBox ch5= new JCheckBox("son");
                  p3.add(ch5);
     
     
                  JButton b10 = new JButton("fiche signal");
                  b10.setBounds(0,10,10,10);
                  p3.add(b10);
     
     
                  JButton b11 = new JButton("view");
                  b11.setBounds(0,110,10,10);
     
                  p3.add(b11);
     
     
     
     
                  p1.setBounds(0,100,100,100);
                  p1.add("North",p3);
     
     
                  add("West",p1);
     
     
     
                  Canvas c = new EssaiCanvas(); 
     
     
                  c.setBackground(Color.black);
     
     
                  add("Center",c);
     
               /*  JPanel p4=new JPanel();
                 JLabel lz= new JLabel("zoum en amplitude");
                 p4.add(lz);
                 
                 JSlider s3=new JSlider();
                  s3.setBounds(0,10,10,10);
                  
                  p4.add(s3);
                  
               
                 
                add("South",p4);*/
     
     
                  JMenu menu = new JMenu("File");
                  menu.setMnemonic(KeyEvent.VK_W);
                  JMenuItem item = null;
                //close
                item = new JMenuItem("Close");
                item.setMnemonic(KeyEvent.VK_C);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Close window");
                        MyFrame.this.setVisible(false);
                        MyFrame.this.dispose();
                    }
                });
                menu.add(item);
     
     
                //new
                item = new JMenuItem("New");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("New window");
                        framework.makeNewWindow();
                    }
                });
                menu.add(item);
                //open
                item = new JMenuItem("Open");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu.add(item);
                //Enregistrer..
                 item = new JMenuItem("Save..");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                       JFileChooser fc=new JFileChooser();
                        fc.showSaveDialog(MyFrame.this);
                    }
                });
                menu.add(item);
                //Enregistrer sous
                item = new JMenuItem("Save as...");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                       JFileChooser fc=new JFileChooser();
                        fc.showSaveDialog(MyFrame.this);
     
                    }
                });
                menu.add(item);
                //Import un siganl wav ou mp3
                item = new JMenuItem("Importer un signal..");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu.add(item);
     
     
     
                //quit
                item = new JMenuItem("Quit");
                item.setMnemonic(KeyEvent.VK_Q);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Quit request");
                        framework.quit(MyFrame.this);
                    }
                });
                menu.add(item);
     
                JMenuBar menuBar = new JMenuBar();
                menuBar.add(menu);
                setJMenuBar(menuBar);
     
                setSize(defaultSize);
                JMenu menu1 = new JMenu("Edit");
                menu.setMnemonic(KeyEvent.VK_W);
     
               // selection
               item = new JMenuItem("Select....");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Edit");
     
     
                    }
                });
                menu1.add(item);
                // Cut
               item = new JMenuItem("Cut");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Copier");
     
                    }
                });
                menu1.add(item);
                // Copier
               item = new JMenuItem("Copie");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Copier");
     
                    }
                });
                menu1.add(item);
     
                //coller
     
               item = new JMenuItem("Paste");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Coller");
     
                    }
                });
                menu1.add(item);
     
     
     
                menuBar.add(menu1);
                setJMenuBar(menuBar);
                JMenu menu2 = new JMenu("Aide");
                menu.setMnemonic(KeyEvent.VK_W);
     
               // Aide
               item = new JMenuItem("Aide");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu2.add(item);
     
     
                menuBar.add(menu2);
                setJMenuBar(menuBar);
            }
            public void actionPerformed(ActionEvent e){
            	Lecture t = new Lecture();
     
            	if(e.getSource().equals(this.b_ouvrir))
            {
                this.ouvrir();
            }
            	 if(e.getSource().equals(this.b_play))
            {
                if(this.fichier == null)
                {
                    this.ouvrir();
                    this.sound();
     
                    t.start();
                }
                else
                {
     
                    this.sound();
                    t.start();
                }
            }
           if(e.getSource().equals(this.b_stop)&&this.fichier!=null)
     
            { 
            	this.sound();
     
            	t.stop();	
     
     
     
              }
     
        }
     
     
        }
        class EssaiCanvas extends Canvas { 
     
     
     
      public void paint (Graphics g){  
     
      int x1;
      int y1;
      int x2;
      int y2;
     
     
       g.setColor( Color.white );
       g.drawLine(700,160,00,160);
       g.drawString("0",22,160); 
       g.setColor( Color.white );
       g.drawLine(700,350,00,350);
     
       g.setColor( Color.white );
       g.drawString("0",22,345);
       g.drawLine(20,00,20,700);
      g.drawString("temps",620,180);
      g.drawString("temps",620,380);
      g.drawString("Fr",25,20); 
     g.drawString("Signal",305,20);
     g.drawString("Spectrogramme",305,450);
     
      }  
     
     
     
     
    } 
     
    }
     
        class FiltreExtension
            extends javax.swing.filechooser.FileFilter
    {
        private String extension;
        private String description;
        public FiltreExtension(String extension, String description)
        {
     
            if (extension.indexOf('.') == -1)
                extension = "." + extension;
     
            this.extension = extension;
            this.description = description;
        }
        public boolean accept(File fichier)
        {
     
            if (fichier.getName().endsWith(extension))
                return true;
            // les répertoires aussi doivent être affichés dans la fenêtre du JFileChooser
            else if (fichier.isDirectory())
                return true;
            return false;
        }
        public String getDescription()
        {
            // la description du fichier, que lâ€Ton associe à  son extension, on a un
            // affichage du type: "Fichier JPEG (*.jpg)"
            return this.description + "(*" + extension + ")";
        }
    }
     
    class VoicePromptPlayer extends JFrame implements ActionListener
    {
    	Player player = new Player();
     
    	AudioInputStream audioInputStream;
     
    	JButton buttonPlayPause = new JButton();
        JButton buttonStop = new JButton();
        JButton buttonClose = new JButton();
        JLabel lblPosition = new JLabel();
        JLabel lblLength = new JLabel();
        JLabel lblPositionSeconds = new JLabel();
        JLabel lblLengthSeconds = new JLabel();
        JLabel lblSecond1 = new JLabel();
        JLabel lblSecond2 = new JLabel();
     
     
        JPanel topPanel = new JPanel(new BorderLayout());
        JPanel positionPanel = new JPanel();
        JPanel lengthPanel = new JPanel();
        JPanel bottomPanel = new JPanel(new BorderLayout());
        JPanel controlButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
     
    	int lengthInMilliseconds, seconds;
    	Vector lines = new Vector();
     
     
    	public VoicePromptPlayer()
        {
            super("Player");
     
    		this.getContentPane().setLayout(new BorderLayout());
     
            setupTopPanel();
     
            buttonPlayPause.setText("Play");
            buttonPlayPause.setActionCommand("Play");
            buttonPlayPause.addActionListener(this);
            buttonPlayPause.setEnabled(false);
            buttonPlayPause.setFocusPainted(false);
            buttonStop.setText("Stop");
            buttonStop.setActionCommand("Stop");
            buttonStop.addActionListener(this);
            buttonStop.setEnabled(false);
            buttonStop.setFocusPainted(false);
            buttonClose.setText("Close");
            buttonClose.addActionListener(this);
     
            buttonPanel.add(buttonClose);
            controlButtonPanel.add(buttonPlayPause);
            controlButtonPanel.add(buttonStop);
            controlButtonPanel.add(buttonPanel);
            bottomPanel.add(controlButtonPanel, BorderLayout.WEST);
            bottomPanel.add(buttonPanel, BorderLayout.EAST);
     
            this.getContentPane().add(topPanel, BorderLayout.NORTH);
            this.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
     
            createAudioInputStream();
            lblPosition.setText("Position: ");
            lblPositionSeconds.setText(formatMilliseconds(0));
            lblLength.setText("Length: ");
            lblLengthSeconds.setText(formatMilliseconds((long)lengthInMilliseconds));
            lblSecond1.setText(" sec.");
            lblSecond2.setText(" sec.");
     
            if (audioInputStream != null)
            {
                buttonPlayPause.setEnabled(true);
            }
            this.setResizable(false);
            this.addWindowListener(new MyWindowAdapter());
            this.pack();
            this.setLocationRelativeTo(null);
    	}
     
        private void setupTopPanel()
        {
            GridBagLayout gbLayout = new GridBagLayout();
            GridBagConstraints gbc = new GridBagConstraints();
     
            positionPanel.setLayout(gbLayout);
     
            gbc.weightx      = 0.0;
            gbc.weighty      = 0.0;
            gbc.gridheight   = 1;
            gbc.gridwidth    = 1;
            gbc.insets       = new Insets(4, 4, 0, 0);
            gbc.ipadx        = 0;
            gbc.ipady        = 0;
            gbc.gridx        = 0;
            gbc.gridy        = 0;
            gbc.fill         = GridBagConstraints.NONE;
            gbc.anchor       = GridBagConstraints.WEST;
     
            gbLayout.setConstraints(lblPosition, gbc);
            positionPanel.add(lblPosition);
     
    		gbc.insets       = new Insets(4, 0, 0, 0);
            gbc.gridx        = 1;
            positionPanel.add(lblPositionSeconds, gbc);
     
            gbc.weightx      = 1.0;
            gbc.gridx        = 2;
            positionPanel.add(lblSecond1, gbc);
            topPanel.add(positionPanel, BorderLayout.WEST);
     
            gbLayout = new GridBagLayout();
            lengthPanel.setLayout(gbLayout);
     
            gbc.gridx        = 0;
            gbc.anchor       = GridBagConstraints.EAST;
            lengthPanel.add(lblLength, gbc);
            gbc.weightx      = 0.0;
            gbc.gridx        = 1;
            lengthPanel.add(lblLengthSeconds, gbc);
    		gbc.insets       = new Insets(4, 0, 0, 4);
            gbc.gridx        = 2;
            lengthPanel.add(lblSecond2, gbc);
            topPanel.add(lengthPanel, BorderLayout.EAST);
        }
     
     
     
        public static void main(String args[])
        {
            VoicePromptPlayer player = new VoicePromptPlayer();
            player.setVisible(true);
        }
     
     
    	public String toString()
    	{
    		return ("Player");
    	}
     
     
    	public void actionPerformed(ActionEvent e)
        {
    		Object obj = e.getSource();
    		if (obj.equals(buttonPlayPause))
            {
    			if (buttonPlayPause.getActionCommand().equals("Play"))
                {
                    // Need to start play or resume
                    if (player.isPaused())
        				player.resume();
                    else
                        player.play();
     
                    // Either way modify the button
                    setPauseButton();
                    buttonStop.setEnabled(true);
    			}
                else
                {
    				player.pause();
                    setPlayButton();
    			}
                pack();
    		}
            else if (obj.equals(buttonStop))
            {
                player.stop();
                buttonStop.setEnabled(false);
                if (buttonPlayPause.getActionCommand().equals("Pause"))
                    setPlayButton();
    		}
            else if (obj.equals(buttonClose))
            {
                player.stop();
                this.dispose();
    		}
        }
     
     
        private String formatMilliseconds(long milliseconds)
        {
            DecimalFormat format = new DecimalFormat("0.00");
            double seconds = milliseconds / 1000.0;
            String formattedOutput = format.format(seconds);
            return formattedOutput;
        }
     
        private void setPlayButton()
        {
            buttonPlayPause.setText("Play");
            buttonPlayPause.setActionCommand("Play");
        }
     
        private void setPauseButton()
        {
            buttonPlayPause.setText("Pause");
            buttonPlayPause.setActionCommand("Pause");
        }
     
    	public void createAudioInputStream()
        {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            chooser.showOpenDialog(this);
     
            File file = chooser.getSelectedFile();
     
            try {
                audioInputStream = AudioSystem.getAudioInputStream(file);
            } catch (Exception e) {}
     
            if (audioInputStream != null)
            {
                player.initialize();
                lengthInMilliseconds = (int)((audioInputStream.getFrameLength() * 1000) / audioInputStream.getFormat().getFrameRate());
            }
     
    	}
     
     
    	/**
             * Voice prompt player.
             */
    	public class Player implements ActionListener
        {
            Timer timer;
            Clip clip;
            boolean paused = false;
     
            public Player()
            {
                timer = new Timer(100, this);
                timer.setRepeats(true);
            }
     
            public void actionPerformed(ActionEvent e)
            {
                long usec = clip.getMicrosecondPosition();
     
                System.out.println("Clip position: " + usec + " usec, isRunning: " + clip.isRunning());
                System.out.println("Timer time: " + System.currentTimeMillis() + " msec");
                if ( (clip.isRunning() == false))
                {
                   // At end of playback
                    if (buttonStop.isEnabled())
                        buttonStop.doClick();
                }
     
                lblPositionSeconds.setText(formatMilliseconds((long) usec/1000));
                lblPosition.repaint();
            }
     
            public boolean isPaused()
            {
                return paused;
            }
     
    		public void play()
            {
                if(clip == null)
                {
                  JOptionPane.showMessageDialog(null, "There is no loaded audio to playback.",
                                                "Play Problem",JOptionPane.WARNING_MESSAGE);
                  return;
                }
                System.out.println("\nClip starting");
                System.out.println("Clip position: " + clip.getMicrosecondPosition() + " usec, isRunning: " + clip.isRunning());
                clip.start();
                System.out.println("Clip started");
                System.out.println("Clip position: " + clip.getMicrosecondPosition() + " usec, isRunning: " + clip.isRunning());
                System.out.println("Start time: " + System.currentTimeMillis() + " msec");
     
                timer.start();
    		}
     
            public void pause()
            {
                if (timer != null)
                    timer.stop();
                if (clip != null)
                    clip.stop();
                paused = true;
            }
     
            public void resume()
            {
                if (clip != null)
                    clip.start();
                if (timer != null)
                   timer.restart();
                paused = false;
            }
     
    		public void stop()
            {
                if (timer != null)
                    timer.stop();
     
                if (clip != null)
                {
                    clip.stop();
                    clip.setFramePosition(0);
                }
                paused = false;
    		}
     
    		private void shutDown(String message)
            {
    			if (message != null)
                {
    				System.err.println(message);
    			}
                    setPlayButton();
                    buttonStop.setEnabled(false);
    		}
     
            public void setPosition(long microseconds)
            {
                clip.setMicrosecondPosition(microseconds);
            }
     
    		public void initialize()
            {
    			// make sure we have something to play
    			if (audioInputStream == null) {
    				shutDown("There is no loaded audio to playback.");
    				return;
    			}
     
    			// define the required attributes for our line,
    			// and make sure a compatible line is supported.
     
                AudioFormat format = audioInputStream.getFormat();
                DataLine.Info clipInfo = new DataLine.Info(Clip.class, format);
    			if (!AudioSystem.isLineSupported(clipInfo))
                {
    				shutDown("A line matching desired info not supported" + ": " + clipInfo);
    				return;
    			}
     
    			// get and open the source data line for playback.
     
    			try
                {
                    clip = (Clip)AudioSystem.getLine(clipInfo);   // Create the clip
                    clip.open(audioInputStream);
                    clip.setFramePosition(0);
    			}
                catch (IOException e)
                {
                    shutDown("Unable to open clip" + ": " + e);
                    return;
                }
                catch (LineUnavailableException ex)
                {
    				shutDown("Unable to open line" + ": " + ex);
    				return;
    			}
     
     
    		}
    	} // End class Player
     
     
        class MyWindowAdapter extends WindowAdapter
        {
            public void windowClosing(WindowEvent e)
            {
                player.stop();
            }
        }
    }

  6. #6
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 46
    Par défaut
    bonjour,
    à ce point mon travail est trés compliqué ou quoi?
    aucune réponse?????????,

  7. #7
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    C'est tout simplement car tu ne donne pas l'impression d'essayer quoi que ce soit et que tu attends qu'on fasse le travail à ta place. Ce qui n'arrivera pas. D'autant plus que la recherche google n'a pas l'air d'être ton fort non plus.
    http://codeidol.com/java/swing/Audio...eform-Display/

  8. #8
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    46
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 46
    Par défaut representation graphique java
    bonjour,
    j'ai presque tous les astuces mais j'arrive pas de représenté la forme d'onde de signal
    mon code ne compile pas
    merci pour vos aides
    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
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    /**
     * @(#)Framework.java
     *
     *
     * @author 
     * @version 1.00 2010/1/3
     */
     import java.io.File;
    import javax.swing.JLabel;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.event.*;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.*;
    import javax.swing.SwingUtilities;
    import javax.swing.filechooser.*;
    import javax.swing.JSlider;
    import javax.swing.JOptionPane;
    import java.io.*;
    import javax.sound.sampled.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.sound.sampled.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.File;
    import java.io.IOException;
    import java.text.DecimalFormat;
    import java.util.Vector;
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import javax.swing.*;
     import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.NoninvertibleTransformException;
    import java.awt.geom.Point2D;
     
     
    /* Framework.java requires no other files. */
    public class Framework extends WindowAdapter  {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
     
        public Framework() {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            maxX = screenSize.width - 50;
            maxY = screenSize.height - 50;
            makeNewWindow();
     
        }
     
        public void makeNewWindow() {
     
     
        	JFrame frame = new MyFrame(this);
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
     
     
     
     
     
     
            if (lastLocation != null) {
                //Move the window over and down 40 pixels.
                lastLocation.translate(40, 40);
                if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                    lastLocation.setLocation(0, 0);
                }
                frame.setLocation(lastLocation);
            } else {
                lastLocation = frame.getLocation();
            }
     
             System.out.println("Frame location: " + lastLocation);
             frame.setVisible(true);
     
        }
     
        //This method must be evoked from the event-dispatching thread.
        public void quit(JFrame frame) {
            if (quitConfirmed(frame)) {
                System.out.println("Quitting.");
                System.exit(0);
            }
            System.out.println("Quit operation not confirmed; staying alive.");
        }
     
     
       public void windowClosed(WindowEvent e) {
            numWindows--;
            System.out.println("Number of windows = " + numWindows);
            if (numWindows <= 0) {
                System.out.println("All windows gone.  Bye bye!");
                System.exit(0);
            }
        }
        private boolean quitConfirmed(JFrame frame) {
            String s1 = "Quit";
            String s2 = "Cancel";
            Object[] options = {s1, s2};
            int n = JOptionPane.showOptionDialog(frame,
                    "Vous voulez vraiment Quiter?",
                    "Quit Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    options,
                    s1);
            if (n == JOptionPane.YES_OPTION) {
                return true;
            } else {
                return false;
            }
        }
     
     
     
     
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            Framework framework = new Framework();
     
        }
     
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
     
        class MyFrame extends JFrame implements ActionListener {
            protected Dimension defaultSize = new Dimension(900, 600);
            protected Framework framework = null;
            private JLabel l1;
            private  JButton b_play;
            private JButton b_stop;
            private JButton b_ouvrir;
            private JCheckBox ch5;
            private File fichier = null;
            private AudioFormat format;
            private byte[] samples;
            private JFileChooser jfc = new JFileChooser();
     
            JFileChooser fc;
     
            public void sound()
        {
            try
            {
                AudioInputStream stream = AudioSystem.getAudioInputStream(this.fichier);
                this.format = stream.getFormat();
                this.getSamples(stream);
            }
                catch (Exception e){}
        }
        public void getSamples(AudioInputStream stream)
        {
            int length = (int)(stream.getFrameLength() * format.getFrameSize());
            this.samples = new byte[length];
            DataInputStream in = new DataInputStream(stream);
            try
            {
                in.readFully(this.samples);
            }
                catch (IOException e){}
        }
     
        public byte[] getSamples()
        {
            return this.samples;
        }
        public void play(InputStream source)
        {
            // 100 ms buffer for real time change to the sound stream
            int bufferSize = this.format.getFrameSize() * Math.round(this.format.getSampleRate() / 10);
            byte[] buffer = new byte[bufferSize];
            SourceDataLine line;
            try
            {
                DataLine.Info info = new DataLine.Info(SourceDataLine.class, this.format);
                line = (SourceDataLine)AudioSystem.getLine(info);
                line.open(this.format, bufferSize);
                line.start();
                int numBytesRead = 0;
               while (numBytesRead != -1 && ! Thread.currentThread().interrupted()) 
                {
                    numBytesRead = source.read(buffer, 0, buffer.length);
                    if (numBytesRead != -1)
                        line.write(buffer, 0, numBytesRead);
                }
                line.drain();
                line.close();
            }
                catch (Exception e){}
        }
        public void ouvrir()
        {
            this.jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            this.jfc.addChoosableFileFilter(new FiltreExtension(".wav", "Fichier wav"));
            this.jfc.addChoosableFileFilter(new FiltreExtension(".wav", "Fichier wav"));
            int returnVal = this.jfc.showOpenDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION)
            {
                this.fichier = this.jfc.getSelectedFile();
            }
        }
         private class Lecture
                extends Thread
        {
            public void run()
            {
                play(new ByteArrayInputStream(getSamples()));
            }
        }
     
        protected double biggestSample;
        private AudioInputStream audioInputStream;
      private int[][] samplesContainer;
      public void AudioInfo(AudioInputStream stream) {
            this.audioInputStream = stream;
           sound();
        }
        public double getFileLengthSeconds(){
        	return audioInputStream.getFrameLength() / audioInputStream.getFormat().getFrameRate();
        }
         public int getNumberOfChannels(){
            int numBytesPerSample = audioInputStream.getFormat().getSampleSizeInBits() / 8;
            return audioInputStream.getFormat().getFrameSize() / numBytesPerSample;
        }
        public double getXScaleFactor(int panelWidth){
            return (panelWidth / ((double) samplesContainer[0].length));
        }
     
        public double getYScaleFactor(int panelHeight){
            return (panelHeight / (biggestSample * 2 * 1.2));
        }
     
        public int[] getAudio(int channel){
            return samplesContainer[channel];
        }
     
        protected int getIncrement(double xScale) {
            try {
                int increment = (int) (samplesContainer[0].length / (samplesContainer[0].length * xScale));
                return increment;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
       protected void drawWaveform(Graphics g, int[] samples) {
            if (samples == null) {
                return;
            }
     
            int oldX = 0;
            int oldY = (int) (getHeight() / 2);
            int xIndex = 0;
     
            int increment = audioInputStream.getIncrement(audioInputStream.getXScaleFactor(getHeight()));
            g.setColor(Color.red);
     
            int t = 0;
     
            for (t = 0; t < increment; t += increment) {
                g.drawLine(oldX, oldY, xIndex, oldY);
                xIndex++;
                oldX = xIndex;
            }
     
            for (; t < samples.length; t += increment) {
                double scaleFactor = audioInputStream.getYScaleFactor(getHeight());
                double scaledSample = samples[t] * scaleFactor;
                int y = (int) ((getHeight() / 2) - (scaledSample));
                g.drawLine(oldX, oldY, xIndex, y);
     
                xIndex++;
                oldX = xIndex;
                oldY = y;
            }
        }
     
     
            public MyFrame(Framework controller) {
                super("Traitement Numérique de signal ");
                framework = controller;
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                addWindowListener(framework);
                setLocation(50,50);
                setLayout(new BorderLayout());
     
     
                  JPanel p2 =new JPanel();
     
     
                   b_ouvrir = new JButton("Ouvrir");
                  p2.add(b_ouvrir);
     
                 this.b_ouvrir.addActionListener(this);
                  JLabel l1=new JLabel("***son***");
                  p2.add(l1);
                   b_play = new JButton("Play");
                  p2.add(b_play);
                  this.b_play.addActionListener(this);
                   b_stop = new JButton("Stop");
                  p2.add(b_stop);
                  this.b_stop.addActionListener(this);
     
     
     
     
     
                    	JLabel l2=new JLabel("***visualiser signal***");
                    	p2.add(l2);
                  JButton b5 = new JButton("play");
                  p2.add(b5);
                   JButton b7 = new JButton("stop");
                  p2.add(b7);
                   JButton b4 = new JButton("Spectr");
                  p2.add(b4);
     
     
                  JButton b6 = new JButton("EXIT");
                  p2.add(b6);
                  b6.addActionListener(new ActionListener() {//exit
                    public void actionPerformed(ActionEvent e) {
                        System.exit(0);
     
     
     
                    	}});
                  add("North",p2);
     
     
                  JPanel p1=new JPanel();
                  p1.setLayout(new BorderLayout());           
                  JPanel p3=new JPanel();
     
     
                  JCheckBox ch5= new JCheckBox("son");
                  p3.add(ch5);
     
     
                  JButton b10 = new JButton("fiche signal");
                  b10.setBounds(0,10,10,10);
                  p3.add(b10);
     
     
                  JButton b11 = new JButton("view");
                  b11.setBounds(0,110,10,10);
     
                  p3.add(b11);
     
     
     
     
                  p1.setBounds(0,100,100,100);
                  p1.add("North",p3);
     
     
                  add("West",p1);
     
     
     
                  Canvas c = new EssaiCanvas(); 
                  c.setBackground(Color.black);
     
     
                  add("Center",c);
     
               /*  JPanel p4=new JPanel();
                 JLabel lz= new JLabel("zoum en amplitude");
                 p4.add(lz);
                 
                 JSlider s3=new JSlider();
                  s3.setBounds(0,10,10,10);
                  
                  p4.add(s3);
                  
               
                 
                add("South",p4);*/
     
     
                  JMenu menu = new JMenu("File");
                  menu.setMnemonic(KeyEvent.VK_W);
                  JMenuItem item = null;
                //close
                item = new JMenuItem("Close");
                item.setMnemonic(KeyEvent.VK_C);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Close window");
                        MyFrame.this.setVisible(false);
                        MyFrame.this.dispose();
                    }
                });
                menu.add(item);
     
     
                //new
                item = new JMenuItem("New");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("New window");
                        framework.makeNewWindow();
                    }
                });
                menu.add(item);
                //open
                item = new JMenuItem("Open");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu.add(item);
                //Enregistrer..
                 item = new JMenuItem("Save..");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                       JFileChooser fc=new JFileChooser();
                        fc.showSaveDialog(MyFrame.this);
                    }
                });
                menu.add(item);
                //Enregistrer sous
                item = new JMenuItem("Save as...");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                       JFileChooser fc=new JFileChooser();
                        fc.showSaveDialog(MyFrame.this);
     
                    }
                });
                menu.add(item);
                //Import un siganl wav ou mp3
                item = new JMenuItem("Importer un signal..");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu.add(item);
     
     
     
                //quit
                item = new JMenuItem("Quit");
                item.setMnemonic(KeyEvent.VK_Q);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Quit request");
                        framework.quit(MyFrame.this);
                    }
                });
                menu.add(item);
     
                JMenuBar menuBar = new JMenuBar();
                menuBar.add(menu);
                setJMenuBar(menuBar);
     
                setSize(defaultSize);
                JMenu menu1 = new JMenu("Edit");
                menu.setMnemonic(KeyEvent.VK_W);
     
               // selection
               item = new JMenuItem("Select....");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Edit");
     
     
                    }
                });
                menu1.add(item);
                // Cut
               item = new JMenuItem("Cut");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Copier");
     
                    }
                });
                menu1.add(item);
                // Copier
               item = new JMenuItem("Copie");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Copier");
     
                    }
                });
                menu1.add(item);
     
                //coller
     
               item = new JMenuItem("Paste");
                item.setMnemonic(KeyEvent.VK_N);
                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Coller");
     
                    }
                });
                menu1.add(item);
     
     
     
                menuBar.add(menu1);
                setJMenuBar(menuBar);
                JMenu menu2 = new JMenu("Aide");
                menu.setMnemonic(KeyEvent.VK_W);
     
               // Aide
               item = new JMenuItem("Aide");
                item.setMnemonic(KeyEvent.VK_N);
     
                menu2.add(item);
     
     
                menuBar.add(menu2);
                setJMenuBar(menuBar);
            }
            public void actionPerformed(ActionEvent e){
            	Lecture t = new Lecture();
     
            	if(e.getSource().equals(this.b_ouvrir))
            {
                this.ouvrir();
            }
            	 if(e.getSource().equals(this.b_play))
            {
                if(this.fichier == null)
                {
                    this.ouvrir();
                    this.sound();
     
                    t.start();
                }
                else
                {
     
                    this.sound();
                    t.start();
                }
            }
           if (e.getSource().equals(this.b_stop)) {
                    this.sound();
                    //t.stop();
                    t.interrupt();
                    t = null;
                }
     
        }
     
     
        }
        class EssaiCanvas extends Canvas { 
     
          private boolean init = true;
     
     
     
        private ZoomAndPanListener zoomAndPanListener;
     
       public EssaiCanvas() {
            this.zoomAndPanListener = new ZoomAndPanListener(this);
            this.addMouseListener(zoomAndPanListener);
           // this.addMouseMotionListener(zoomAndPanListener);
            this.addMouseWheelListener(zoomAndPanListener);
        }
     
       public void paint(Graphics g1) {
            Graphics2D g = (Graphics2D) g1;
            g.setBackground(Color.black);
     
          if (init) {
                // Initialize the viewport by moving the origin to the center of the window,
                // and inverting the y-axis to point upwards.
                init = false;
     
               zoomAndPanListener.setCoordTransform(g.getTransform());
            } else {
                // Restore the viewport after it was updated by the ZoomAndPanListener
                g.setTransform(zoomAndPanListener.getCoordTransform());
            }
     
     
             g.setColor(Color.lightGray);
             int lineHeight = getHeight() / 2;
             g.drawLine(0, lineHeight, (int)getWidth(), lineHeight);
     
       }
     
     
     
     
    } 
     
    }
     
        class FiltreExtension
            extends javax.swing.filechooser.FileFilter
    {
        private String extension;
        private String description;
        public FiltreExtension(String extension, String description)
        {
     
            if (extension.indexOf('.') == -1)
                extension = "." + extension;
     
            this.extension = extension;
            this.description = description;
        }
        public boolean accept(File fichier)
        {
     
            if (fichier.getName().endsWith(extension))
                return true;
            // les répertoires aussi doivent être affichés dans la fenêtre du JFileChooser
            else if (fichier.isDirectory())
                return true;
            return false;
        }
        public String getDescription()
        {
            // la description du fichier, que lâ€Ton associe à  son extension, on a un
            // affichage du type: "Fichier JPEG (*.jpg)"
            return this.description + "(*" + extension + ")";
        }
    }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    class ZoomAndPanListener implements MouseListener, MouseMotionListener, MouseWheelListener {
        public static final int DEFAULT_MIN_ZOOM_LEVEL = -20;
        public static final int DEFAULT_MAX_ZOOM_LEVEL = 10;
        public static final double DEFAULT_ZOOM_MULTIPLICATION_FACTOR = 1.2;
     
        private Component targetComponent;
     
        private int zoomLevel = 0;
        private int minZoomLevel = DEFAULT_MIN_ZOOM_LEVEL;
        private int maxZoomLevel = DEFAULT_MAX_ZOOM_LEVEL;
        private double zoomMultiplicationFactor = DEFAULT_ZOOM_MULTIPLICATION_FACTOR;
     
        private Point dragStartScreen;
        private Point dragEndScreen;
        private AffineTransform coordTransform = new AffineTransform();
     
        public ZoomAndPanListener(Component targetComponent) {
            this.targetComponent = targetComponent;
        }
     
        public ZoomAndPanListener(Component targetComponent, int minZoomLevel, int maxZoomLevel, double zoomMultiplicationFactor) {
            this.targetComponent = targetComponent;
            this.minZoomLevel = minZoomLevel;
            this.maxZoomLevel = maxZoomLevel;
            this.zoomMultiplicationFactor = zoomMultiplicationFactor;
        }
     
     
        public void mouseClicked(MouseEvent e) {
        }
     
        public void mousePressed(MouseEvent e) {
            dragStartScreen = e.getPoint();
            dragEndScreen = null;
        }
     
        public void mouseReleased(MouseEvent e) {
    //        moveCamera(e);
        }
     
        public void mouseEntered(MouseEvent e) {
        }
     
        public void mouseExited(MouseEvent e) {
        }
     
        public void mouseMoved(MouseEvent e) {
        }
     
        public void mouseDragged(MouseEvent e) {
            moveCamera(e);
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
    //        System.out.println("============= Zoom camera ============");
            zoomCamera(e);
        }
     
        private void moveCamera(MouseEvent e) {
    //        System.out.println("============= Move camera ============");
            try {
                dragEndScreen = e.getPoint();
                Point2D.Float dragStart = transformPoint(dragStartScreen);
                Point2D.Float dragEnd = transformPoint(dragEndScreen);
                double dx = dragEnd.getX() - dragStart.getX();
                double dy = dragEnd.getY() - dragStart.getY();
                coordTransform.translate(dx, dy);
                dragStartScreen = dragEndScreen;
                dragEndScreen = null;
                targetComponent.repaint();
            } catch (NoninvertibleTransformException ex) {
                ex.printStackTrace();
            }
        }
     
        private void zoomCamera(MouseWheelEvent e) {
            try {
                int wheelRotation = e.getWheelRotation();
                Point p = e.getPoint();
                if (wheelRotation > 0) {
                    if (zoomLevel < maxZoomLevel) {
                        zoomLevel++;
                        Point2D p1 = transformPoint(p);
                        coordTransform.scale(1 / zoomMultiplicationFactor, 1 / zoomMultiplicationFactor);
                        Point2D p2 = transformPoint(p);
                        coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
                        targetComponent.repaint();
                    }
                } else {
                    if (zoomLevel > minZoomLevel) {
                        zoomLevel--;
                        Point2D p1 = transformPoint(p);
                        coordTransform.scale(zoomMultiplicationFactor, zoomMultiplicationFactor);
                        Point2D p2 = transformPoint(p);
                        coordTransform.translate(p2.getX() - p1.getX(), p2.getY() - p1.getY());
                        targetComponent.repaint();
                    }
                }
            } catch (NoninvertibleTransformException ex) {
                ex.printStackTrace();
            }
        }
     
        private Point2D.Float transformPoint(Point p1) throws NoninvertibleTransformException {
    //        System.out.println("Model -> Screen Transformation:");
    //        showMatrix(coordTransform);
            AffineTransform inverse = coordTransform.createInverse();
    //        System.out.println("Screen -> Model Transformation:");
    //        showMatrix(inverse);
     
            Point2D.Float p2 = new Point2D.Float();
            inverse.transform(p1, p2);
            return p2;
        }
     
        private void showMatrix(AffineTransform at) {
            double[] matrix = new double[6];
            at.getMatrix(matrix);  // { m00 m10 m01 m11 m02 m12 }
            int[] loRow = {0, 0, 1};
            for (int i = 0; i < 2; i++) {
                System.out.print("[ ");
                for (int j = i; j < matrix.length; j += 2) {
                    System.out.printf("%5.1f ", matrix[j]);
                }
                System.out.print("]\n");
            }
            System.out.print("[ ");
            for (int i = 0; i < loRow.length; i++) {
                System.out.printf("%3d   ", loRow[i]);
            }
            System.out.print("]\n");
            System.out.println("---------------------");
        }
     
     
        public int getZoomLevel() {
            return zoomLevel;
        }
     
        public void setZoomLevel(int zoomLevel) {
            this.zoomLevel = zoomLevel;
        }
     
        public AffineTransform getCoordTransform() {
            return coordTransform;
        }
     
        public void setCoordTransform(AffineTransform coordTransform) {
            this.coordTransform = coordTransform;
        }
    }

  9. #9
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 900
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 900
    Billets dans le blog
    54
    Par défaut
    Et l'erreur de compilation est ?
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

Discussions similaires

  1. meilleure base de données avec java
    Par mial dans le forum JDBC
    Réponses: 11
    Dernier message: 10/11/2010, 11h49
  2. [LDAP] recherche dans differents container LDAP avec Java
    Par touinth dans le forum Autres SGBD
    Réponses: 2
    Dernier message: 01/07/2004, 16h06
  3. [CR][Java] imprimer un état CR avec java
    Par wassimb dans le forum SDK
    Réponses: 2
    Dernier message: 24/05/2004, 16h40
  4. Réponses: 3
    Dernier message: 27/01/2004, 16h15
  5. [JNDI] Equivalent avec Java Web Start ?
    Par cameleon2002 dans le forum Java EE
    Réponses: 8
    Dernier message: 18/09/2003, 18h55

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