Need help with sound in java
Results 1 to 4 of 4

Thread: Need help with sound in java

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    2

    Need help with sound in java

    hey guys, im new here to antionline and i needed some help with one of my programs in Java. im sitting in my computer science class and there are some students that think its funny to playannoying music. my response?

    public class h3r3tic
    {
    public static void main(String args[])
    {
    int intVal=7;

    for(int k=1;k<=5000000;k++)
    {
    System.out.println((char) + intVal);
    k--;
    }
    }
    }


    however i was talking to my teacher and she said that in C++ and many other programming languages you can change the pitch and mhz of the constant an ever-so-vengeful beeping. or even add orchange a different sound? any help woudl be great and if you want my personal email for a more personal response its imburninurhouse@gmail.com
    any help you guys can provide would be more than appreciated.

  2. #2
    Senior Member Deeboe's Avatar
    Join Date
    Nov 2005
    Posts
    185
    public class h3r3tic
    {
    public static void main(String args[])
    {
    int intVal=7;

    for(int k=1;k<=5000000;k++)
    {
    System.out.println((char) + intVal);
    k--;
    }
    }
    }
    I dont understand, is there more to this? Seems like System.out.println((char) + intVal); will print some "char" on the screen plus 7, 5,000,000 times. I dont have a compiler on this PC, but I dont see what this will accomplish. Also, why would you want to make the thing make annoying sounds? When I took Java, seems like we made useful programs.

    -Deeboe
    If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.
    - Sun Tzu, The Art of War

    http://tazforum.**********.com/

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    2
    ok, not having a compiler i can understand you not knowing what it does by just looking at it, i wouldnt etiehr probably. that 7 starts out as a 7, not as a character but as an integer. this program converts the integer 7 into its "char" equivalent. so one would naturally think that the "char" equivalent of 7 was a 7, right? wrong! the equivalent is a single beep. putting the conversion in a for statement it does it 5000000 times right? wrong again! if youll look in the brackets of the for statement it has the command 'k--;' which tells java to subtract 1 from integer k (the integer running the for statement) every time it runs through the for statement. so in essence it will sit and beep unendingly.

    as to your "why" question. in my post i talked about a rather large group of annoying studnets that like to play annoying music and sounds out of their computers almost constantly in the classroom. this is simply my way of making them stop (it works by the way) im just trying to see if i cant raise or lower the pitch or even get an entirely new sound altogether.

  4. #4
    Senior Member Deeboe's Avatar
    Join Date
    Nov 2005
    Posts
    185
    Originally posted here by janosa
    the equivalent is a single beep. putting the conversion in a for statement it does it 5000000 times right? wrong again! if youll look in the brackets of the for statement it has the command 'k--;' which tells java to subtract 1 from integer k (the integer running the for statement) every time it runs through the for statement. so in essence it will sit and beep unendingly.
    Ahhh... I see. Seems like a roundabout way of doing it.

    You could really cut your code down by doing this:

    while(true)
    System.out.println((char) + 7);


    Of course you need all your brackets and every other call needed to run it, but still.

    Anyway, none of that answers your question on changing the pitch. I'm sure there is a way to do it, possibly by creating a .wav file that it calls over and over again. However, the reasoning for doing it just doesn't click with me and I don't really want to work on finding a solution for such a useless cause.

    Good luck in your studies!

    -Deeboe
    If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.
    - Sun Tzu, The Art of War

    http://tazforum.**********.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •