Re: sound gets out of time

Discussion in 'Java' started by active_ksa@msn.com, Jul 23, 2003.

  1. Guest

    "webster" <> wrote in message news:<aKmTa.9169$>...
    > I have a program that plays drum samples. The problem is when i select 2
    > check boxes close together it gets out of time a bit. I was just wondering
    > if there is a way of overcoming this? Some body has told me that i cant fix
    > it cos that's just what java does. I have included a sample of my program so
    > you can see what I'm on about.
    > thanks
    > matt
    >
    > import java.awt.*;
    > import java.awt.event.*;
    > import javax.swing.*;
    > import java.applet.*;
    > import java.net.*;
    > public class TBtest extends JFrame implements ActionListener{
    > JCheckBox box1,box2,box3,box4;
    > JButton play;
    > public TBtest(){
    > super("Test for sound using tickBox and button");
    > setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    > setSize(200,100);
    > setVisible(true);
    > Container contentArea = getContentPane();
    > contentArea.setLayout(new FlowLayout());
    > box1 = new JCheckBox();
    > box2 = new JCheckBox();
    > box3 = new JCheckBox();
    > box4 = new JCheckBox();
    > play = new JButton("play");
    > play.addActionListener(this);
    > contentArea.add(box1);
    > contentArea.add(box2);
    > contentArea.add(box3);
    > contentArea.add(box4);
    > contentArea.add(play);
    > setContentPane(contentArea);
    > }
    > void pause(int duration) {
    > try {
    > Thread.sleep(duration);
    > }catch (InterruptedException e) {}
    > }
    > public void actionPerformed(ActionEvent event) {
    > String command = event.getActionCommand();
    > if(event.getSource() == play)
    > { try
    > { URL Basefile = new URL("file:base.wav");
    > AudioClip Base = JApplet.newAudioClip(Basefile);
    > URL Snarefile = new URL("file:snare.wav");
    > AudioClip Snare = JApplet.newAudioClip(Snarefile);
    > if (box1.isSelected())
    > Base.play();
    > if (box2.isSelected())
    > Snare.play();
    > pause(800);
    > if (box3.isSelected())
    > Base.play();
    > if (box4.isSelected())
    > Snare.play();
    > }
    > catch (MalformedURLException error) {}
    > }
    > }
    > public static void main(String[] args)
    > {TBtest Drum = new TBtest();}
    > }

    it is easy
     
    , Jul 23, 2003
    #1
    1. Advertising

  2. webster Guest

    what does "it is easy" mean does that mean you know the answer to my
    problem?
    <> wrote in message
    news:...
    > "webster" <> wrote in message

    news:<aKmTa.9169$>...
    > > I have a program that plays drum samples. The problem is when i select 2
    > > check boxes close together it gets out of time a bit. I was just

    wondering
    > > if there is a way of overcoming this? Some body has told me that i cant

    fix
    > > it cos that's just what java does. I have included a sample of my

    program so
    > > you can see what I'm on about.
    > > thanks
    > > matt
    > >
    > > import java.awt.*;
    > > import java.awt.event.*;
    > > import javax.swing.*;
    > > import java.applet.*;
    > > import java.net.*;
    > > public class TBtest extends JFrame implements ActionListener{
    > > JCheckBox box1,box2,box3,box4;
    > > JButton play;
    > > public TBtest(){
    > > super("Test for sound using tickBox and button");
    > > setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    > > setSize(200,100);
    > > setVisible(true);
    > > Container contentArea = getContentPane();
    > > contentArea.setLayout(new FlowLayout());
    > > box1 = new JCheckBox();
    > > box2 = new JCheckBox();
    > > box3 = new JCheckBox();
    > > box4 = new JCheckBox();
    > > play = new JButton("play");
    > > play.addActionListener(this);
    > > contentArea.add(box1);
    > > contentArea.add(box2);
    > > contentArea.add(box3);
    > > contentArea.add(box4);
    > > contentArea.add(play);
    > > setContentPane(contentArea);
    > > }
    > > void pause(int duration) {
    > > try {
    > > Thread.sleep(duration);
    > > }catch (InterruptedException e) {}
    > > }
    > > public void actionPerformed(ActionEvent event) {
    > > String command = event.getActionCommand();
    > > if(event.getSource() == play)
    > > { try
    > > { URL Basefile = new URL("file:base.wav");
    > > AudioClip Base = JApplet.newAudioClip(Basefile);
    > > URL Snarefile = new URL("file:snare.wav");
    > > AudioClip Snare = JApplet.newAudioClip(Snarefile);
    > > if (box1.isSelected())
    > > Base.play();
    > > if (box2.isSelected())
    > > Snare.play();
    > > pause(800);
    > > if (box3.isSelected())
    > > Base.play();
    > > if (box4.isSelected())
    > > Snare.play();
    > > }
    > > catch (MalformedURLException error) {}
    > > }
    > > }
    > > public static void main(String[] args)
    > > {TBtest Drum = new TBtest();}
    > > }

    > it is easy
     
    webster, Jul 23, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luc The Perverse

    Sound Quality In Sound API

    Luc The Perverse, Oct 30, 2005, in forum: Java
    Replies:
    4
    Views:
    1,501
    Andrew Thompson
    Oct 31, 2005
  2. Replies:
    0
    Views:
    517
  3. Stefan Mueller
    Replies:
    5
    Views:
    534
    Steven Saunderson
    Jul 10, 2006
  4. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    362
    John Joyce
    Mar 26, 2007
  5. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    201
    John Joyce
    Apr 23, 2007
Loading...

Share This Page