14 Replies - 14656 Views - Last Post: 08 February 2009 - 05:45 PM Rate Topic: -----

#1 matthew82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-January 09

beep

Posted 18 January 2009 - 09:10 AM

Hi everyone, i have a beep code i have compiled but i need to make a new code to play a little tune, any help would be awsome, thanks guys...

Heres my beep code...
#include <iostream>  //Input Output header for cout
#include <windows.h> // Windows header for beep

using namespace std;

int main()
{	
	cout << "Beep at 440 Hz for 500mS \n";  //Display Message
	Beep(440,500);	// 440 hertz (A4) for half a second
	cout << "Beep at 494 Hz for 500mS \n";  //Display Message
	Beep(494,500);	// 494 hertz for half a second
	cout << "Beep at 523 Hz for 500mS \n";  //Display Message
	Beep(523,500);	// 523 hertz for half a second
	cout << "Beep at 587 Hz for 500mS \n";  //Display Message
	Beep(587,500);	// 587 hertz for half a second
	cout << "Beep at 659 Hz for 500mS \n";  //Display Message
	Beep(659,500);	// 659 hertz for half a second
	
	return 0;
}


Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: beep

#2 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: beep

Posted 18 January 2009 - 09:12 AM

So, what is it you need help with?
Was This Post Helpful? 0
  • +
  • -

#3 matthew82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-January 09

Re: beep

Posted 18 January 2009 - 09:22 AM

View PostPwn, on 18 Jan, 2009 - 08:12 AM, said:

So, what is it you need help with?



I need help creating a programme that will play a tune ie nursary rhyme
Was This Post Helpful? 0
  • +
  • -

#4 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: beep

Posted 18 January 2009 - 09:26 AM

ok, so what do you need help with? I'm not very good at mind-reading.

This post has been edited by Pwn: 18 January 2009 - 09:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: beep

Posted 18 January 2009 - 05:23 PM

Can you guess this tune? It would be better if you put a slight pause where I commented that a pause should go! And I did not change the words that will be displayed, just the code. So you'd have to change some of that, but at least this sort of plays a tune:
#include <iostream>  //Input Output header for cout
#include <windows.h> // Windows header for beep

using namespace std;

int main()
{ 

       for (int x = 0; x<2;x++)
       {
       cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
       }
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,800);    // 523 hertz for half a second
       //how do you make it pause for a little bit here?
              for (int x = 0; x<2;x++)
       {
       cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
       }
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,800);    // 523 hertz for half a second
       //another pause should be here, for just a little bit
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
    //cout << "Beep at 587 Hz for 500mS \n";  //Display Message
    //Beep(587,500);    // 587 hertz for half a second
    cout << "Beep at 659 Hz for 500mS \n";  //Display Message
    Beep(659,400);    // 659 hertz for half a second
        cout << "Beep at 440 Hz for 500mS \n";  //Display Message
    Beep(440,400);    // 440 hertz (A4) for half a second

    cout << "Beep at 494 Hz for 500mS \n";  //Display Message
    Beep(494,400);    // 494 hertz for half a second
           cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,400);    // 523 hertz for half a second
    return 0;
}

:D
Was This Post Helpful? 0
  • +
  • -

#6 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: beep

Posted 18 January 2009 - 05:30 PM

Cool ... or should I say it's cold up here ... Was that Jingle Bells ... all the way ..oh what fun, it is to ride in a one horse open sleigh ... eh ?

:D

O^O /
-

Over ...
Was This Post Helpful? 0
  • +
  • -

#7 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: beep

Posted 18 January 2009 - 05:36 PM

Yes it was!!!! :D

What I did:
took the existing code and thought of each beep as a number...the first one is 1, second is 2, etc.

Because there were 5 total I could do the intro to Jingle Bells: 3, 3, 3,...3, 3, 3,...3, 5, 1, 2, 3

You can do it with any song that you can assign their notes to numbers, or would it be vice versa? :)

Do you know how to add a slight pause?

p.s. I hope this answers your question, Matthew!

This post has been edited by OliveOyl3471: 18 January 2009 - 05:37 PM

Was This Post Helpful? 0
  • +
  • -

#8 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: beep

Posted 18 January 2009 - 05:58 PM

Bingo ... B)

Shalom shalom OO
Was This Post Helpful? 0
  • +
  • -

#9 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: beep

Posted 18 January 2009 - 06:20 PM

P.S.

Here's some code you can use to program a delay ...

#include <stdio.h>
#include <time.h>


int main()
{
    float pause=2.0; /* seconds */
    clock_t start;
    printf( " Starting ... " );
    start = clock();
    while( clock() < start + pause*CLOCKS_PER_SEC );
    printf( "Times up ...  Press 'Enter' to exit ... " );
    getchar();
    return 0;
}

This post has been edited by David W: 19 January 2009 - 09:38 AM

Was This Post Helpful? 0
  • +
  • -

#10 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: beep

Posted 18 January 2009 - 06:49 PM

Thank you! I love this game. :D This one should be much better than the other one:

#include <iostream>  //Input Output header for cout
#include <windows.h> // Windows header for beep
#include <stdio.h>
#include <time.h>
using namespace std;

int main()
{ 
   int pause=100;  
   clock_t start; 
       for (int x = 0; x<2;x++)
       {
        cout << "Beep #3 at 523 Hz for 500mS \n";  //Display Message
        Beep(523,500);    // 523 hertz for half a second
       }
              cout << "Beep #3 at 523 Hz for 800mS \n";  //Display Message
       Beep(523,800);    // 523 hertz 
       
       //pause for a little bit here
       start = clock();
           while( clock() < start + pause ) 
           printf( "*" ); //just to fill the screen while you wait, lol
           
       for (int x = 0; x<2;x++)
       {
        cout << "Beep #3 at 523 Hz for 500mS \n"; 
        Beep(523,500);    // 523 hertz for half a second
       }
       cout << "Beep #3 at 523 Hz for 800mS \n";
       Beep(523,800);    // 523 hertz
        
       //another pause here
       start = clock();
           while( clock() < start + pause ) 
           printf( "*" ); //just to fill the screen while you wait, lol
           
    cout << "Beep #3 at 523 Hz for 500mS \n";  
    Beep(523,500);    // 523 hertz for half a second

    cout << "Beep #5 at 659 Hz for 400mS \n";  
    Beep(659,400);    // 659 hertz
        cout << "Beep #1 at 440 Hz for 400mS \n"; 
    Beep(440,400);    // 440 hertz (A4) 

    cout << "Beep #2 at 494 Hz for 400mS \n"; 
    Beep(494,400);    // 494 hertz
    cout << "Beep #3 at 523 Hz for 800mS \n"; 
    Beep(523,800);    // 523 hertz
    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#11 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: beep

Posted 18 January 2009 - 07:14 PM

What's with all the stars and stripes ... ?

You must be an all American lady ... :D

Really ... the notes could use a little sharpening ... if you know what I mean?

Yeah ... OO ... will do as MUSIC for coronation day.
Was This Post Helpful? 0
  • +
  • -

#12 Mitsoloth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-January 09

Re: beep

Posted 18 January 2009 - 07:59 PM

Hi there, i wondered if anyone has made a code that makes the pc beep sound like it's singing Happy birthday to you. A friend of mine has his birthday in some days and i thought this would be interesting.
Was This Post Helpful? 0
  • +
  • -

#13 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: beep

Posted 18 January 2009 - 08:07 PM

http://wc.pima.edu/~...0per%20note.jpg

Might be of help.

This post has been edited by Hyper: 18 January 2009 - 08:08 PM

Was This Post Helpful? 0
  • +
  • -

#14 lavamonstaar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-January 09

Re: beep

Posted 26 January 2009 - 06:08 PM

View PostOliveOyl3471, on 18 Jan, 2009 - 04:23 PM, said:

Can you guess this tune? It would be better if you put a slight pause where I commented that a pause should go! And I did not change the words that will be displayed, just the code. So you'd have to change some of that, but at least this sort of plays a tune:
#include <iostream>  //Input Output header for cout
#include <windows.h> // Windows header for beep

using namespace std;

int main()
{ 

       for (int x = 0; x<2;x++)
       {
       cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
       }
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,800);    // 523 hertz for half a second
       //how do you make it pause for a little bit here?
              for (int x = 0; x<2;x++)
       {
       cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
       }
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,800);    // 523 hertz for half a second
       //another pause should be here, for just a little bit
              cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,500);    // 523 hertz for half a second
    //cout << "Beep at 587 Hz for 500mS \n";  //Display Message
    //Beep(587,500);    // 587 hertz for half a second
    cout << "Beep at 659 Hz for 500mS \n";  //Display Message
    Beep(659,400);    // 659 hertz for half a second
        cout << "Beep at 440 Hz for 500mS \n";  //Display Message
    Beep(440,400);    // 440 hertz (A4) for half a second

    cout << "Beep at 494 Hz for 500mS \n";  //Display Message
    Beep(494,400);    // 494 hertz for half a second
           cout << "Beep at 523 Hz for 500mS \n";  //Display Message
       Beep(523,400);    // 523 hertz for half a second
    return 0;
}

:D



















You definately should use the sleep function instead of that clock that whoever else suggested you use.

you do:

Sleep(x) where x is however long you want it to pause.

Sleep(500) is half a second, Sleep(1000) is one second and so on.

of course you have to #include "windows.h"
Was This Post Helpful? 0
  • +
  • -

#15 valleymonkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 09

Re: beep

Posted 08 February 2009 - 05:45 PM

View PostMitsoloth, on 18 Jan, 2009 - 06:59 PM, said:

Hi there, i wondered if anyone has made a code that makes the pc beep sound like it's singing Happy birthday to you. A friend of mine has his birthday in some days and i thought this would be interesting.


i borrowed the code from this site and added the music its happy bday but the hi c can use some work anyway heres all the notes i found
int scale[] = {220,233,247,262,277,294,311,330,349,370,392,415,440,0 };
// a a# b c c# d d# e f f# g g# a


#include <iostream> //Input Output header for cout
#include <windows.h> // Windows header for beep

using namespace std;

int main()
{
cout << "Beep at 440 Hz for 500mS \n"; //Display Message
Beep(262,200); // a hertz (A4) for half a second
cout << "Beep at 494 Hz for 500mS \n"; //Display Message
Beep(262,200); // a# 4 hertz for half a second
cout << "Beep at 523 Hz for 500mS \n"; //Display Message
Beep(294,200); // b hertz for half a second
cout << "Beep at 587 Hz for 500mS \n"; //Display Message
Beep(262,200); // c hertz for half a second
cout << "Beep at 659 Hz for 500mS \n"; //Display Message
Beep(349,200); // c# hertz for half a second
cout << "Beep at 440 Hz for 500mS \n"; //Display Message

Beep(330,200); // d hertz (A4) for half a second
cout << "Beep at 494 Hz for 500mS \n"; //Display Message
Beep(262,200); // d# hertz for half a second
cout << "Beep at 523 Hz for 500mS \n"; //Display Message
Beep(262,200); // e hertz for half a second
cout << "Beep at 587 Hz for 500mS \n"; //Display Message
Beep(294,200); // f hertz for half a second
cout << "Beep at 659 Hz for 500mS \n"; //Display Message
Beep(262,200); // f# hertz for half a second
cout << "Beep at 440 Hz for 500mS \n"; //Display Message
Beep(392,200); // g hertz (A4) for half a second
cout << "Beep at 494 Hz for 500mS \n"; //Display Message
Beep(349,200); // g# hertz for half a second
cout << "Beep at 523 Hz for 500mS \n"; //Display Message
Beep(262,200); // a hertz for half a second
cout << "Beep at 587 Hz for 500mS \n"; //Display Message
Beep(262,200); // 587 hertz for half a second
cout << "Beep at 659 Hz for 500mS \n"; //Display Message
Beep(482,200); // 659 hertz for half a second
cout << "Beep at 440 Hz for 500mS \n"; //Display Message
Beep(440,200); // d hertz (A4) for half a second
cout << "Beep at 494 Hz for 500mS \n"; //Display Message
Beep(349,200); // d# hertz for half a second
cout << "Beep at 523 Hz for 500mS \n"; //Display Message
Beep(330,200); // e hertz for half a second
cout << "Beep at 587 Hz for 500mS \n"; //Display Message
Beep(294,200); // f hertz for half a second
cout << "Beep at 659 Hz for 500mS \n"; //Display Message
Beep(482,200); // f# hertz for half a second
cout << "Beep at 440 Hz for 500mS \n"; //Display Message
Beep(482,200); // g hertz (A4) for half a second
cout << "Beep at 494 Hz for 500mS \n"; //Display Message
Beep(440,200); // g# hertz for half a second
cout << "Beep at 523 Hz for 500mS \n"; //Display Message
Beep(349,200); // a hertz for half a second
cout << "Beep at 587 Hz for 500mS \n"; //Display Message
Beep(392,200); // 587 hertz for half a second
cout << "Beep at 659 Hz for 500mS \n"; //Display Message
Beep(349,200); // 659 hertz for half a second
cout << "Beep at 440 Hz for 500mS \n"; //Display Message




return 0;
}

This post has been edited by valleymonkey: 08 February 2009 - 05:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1