C++ Sound Frequencies

Beeping Happy Birthday

Page 1 of 1

14 Replies - 22846 Views - Last Post: 21 September 2009 - 01:32 PM Rate Topic: -----

#1 sportyh4509  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 08

C++ Sound Frequencies

Post icon  Posted 22 September 2008 - 04:36 PM

#include<iostream.h>
#include<iomanip.h>
#include <windows.h>
using namespace std;

void main ()

{

        cout<<Beep ( , );

        system ("pause");

}



And my question is.. for the beep.. i have to create a tune.. and my teacher would like the happy birthday tune. I need to know the frequencies to put in the "Beep ( , );" ... or do you know of a better way?

Please help!
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Sound Frequencies

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: C++ Sound Frequencies

Posted 22 September 2008 - 04:48 PM

1) Use C++ notation~
#include<iostream> // no .h
#include<iomanip> // no .h
#include <windows.h> // keep the .h on this


2) main should return int, so you can return EXIT_SUCCESS or EXIT_FAILURE (0 or 1)

3) Beep() is a part of the windows API. It accepts 2 parameters, the frequency and the duration.

My laptop doesn't beep, so I can't help you out too much on this one. Basically though, it should look something like this:
#include <windows.h>

int main ()
{
    Beep(343, 444); // frequency in hurtz, duration in milliseconds
    Beep(422, 322);
    // etc
    return EXIT_SUCCESS; // the program ran successfully! w00t!
}

Hope this helps :)

By the way, think how some of the music loops.
Happy birthday to you, happy birthday to you
^Think of it as beeping "Happy birthday to you" then running it again. Maybe putting it into a function, since that line's repeated quite often.


So, that leaves you with a structure something like:
#include <windows.h>

void happyBirthdayToYou()
{
    // beep
    // beep
    // etc
}

int main ()
{
    happyBirthdayToYou();
    happyBirthdayToYou();
    // happy birthday dear gabehabe - this will be written seperately
    // beep
    // beep
    // beep
    // etc
    happyBirthdayToYou();
    return EXIT_SUCCESS; // the program ran successfully! w00t!
}

Was This Post Helpful? 0
  • +
  • -

#3 sportyh4509  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 08

Re: C++ Sound Frequencies

Posted 22 September 2008 - 05:48 PM

okay.. so you dont know the frequencies for happy birthday than? ... Does anyone know?? I understand that happy birthday to you line is there three times so if i just knew the frequencies for happy birthday to you than i would be okay. but i dont have c++ on my computer at home i only have it at school and i cant work on it and i been tryin to research it but i havent gotten anywhere thats why i am askin on here!
Was This Post Helpful? 0
  • +
  • -

#4 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 548
  • Joined: 24-July 08

Re: C++ Sound Frequencies

Posted 22 September 2008 - 06:37 PM

View Postsportyh4509, on 22 Sep, 2008 - 05:48 PM, said:

okay.. so you dont know the frequencies for happy birthday than? ... Does anyone know?? I understand that happy birthday to you line is there three times so if i just knew the frequencies for happy birthday to you than i would be okay. but i dont have c++ on my computer at home i only have it at school and i cant work on it and i been tryin to research it but i havent gotten anywhere thats why i am askin on here!



Just guess, there is no set frequency in a happy birthday. Just play it over and over in your head untill you go crazy then you'll get it.

Just think like this

med, med, low, low, high med.

What ever sounds right
Was This Post Helpful? 0
  • +
  • -

#5 Shukumei  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 80
  • Joined: 22-September 08

Re: C++ Sound Frequencies

Posted 22 September 2008 - 10:47 PM

Here is a list of musical notes and there corresponding pc speaker frequency: Copy and Past the chart into notepad and re-align the coloumns.
Sorry I dont know how to format is correctly in a post on here.

Octave 0 1 2 3 4 5 6 7
Note
C 16 33 65 131 262 523 1046 2093
C# 17 35 69 139 277 554 1109 2217
D 18 37 73 147 294 587 1175 2349
D# 19 39 78 155 311 622 1244 2489
E 21 41 82 165 330 659 1328 2637
F 22 44 87 175 349 698 1397 2794
F# 23 46 92 185 370 740 1480 2960
G 24 49 98 196 392 784 1568 3136
G# 26 52 104 208 415 831 1661 3322
A 27 55 110 220 440 880 1760 3520
A# 29 58 116 233 466 932 1865 3729
B 31 62 123 245 494 988 1975 3951

And here are the notes for Happy Birthday - the timing you can work on throught experiment yourself:

GGAGC#B GGAGD#C# GGG#E#C#BA F#F#E#C#DC#

I hope this helps you: I am not a music buff it may sound weird - Trial and Error my friend - eventually solves everything.
Was This Post Helpful? 0
  • +
  • -

#6 sportyh4509  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 08

Re: C++ Sound Frequencies

Posted 23 September 2008 - 06:36 PM

hmm alright. i will give that a shot and see how it works! thanks for helping. i hope that i can figure this out haha.

Thanks!!!
Was This Post Helpful? 0
  • +
  • -

#7 Shukumei  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 80
  • Joined: 22-September 08

Re: C++ Sound Frequencies

Posted 23 September 2008 - 08:00 PM

I hope the chart helped you :)
Was This Post Helpful? 0
  • +
  • -

#8 sportyh4509  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-September 08

Re: C++ Sound Frequencies

Posted 24 September 2008 - 01:15 PM

=) yes yes yes! :D Thanks so much for all of the help everyone! I got it up and running today at school, it did not take too long either. It sounded great. Thanks so much for the help, it was much appreciated!

THANKS AGAIN!
Was This Post Helpful? 0
  • +
  • -

#9 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: C++ Sound Frequencies

Posted 24 September 2008 - 01:24 PM

Why is this featured?
Was This Post Helpful? 0
  • +
  • -

#10 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,908
  • Joined: 13-October 07

Re: C++ Sound Frequencies

Posted 01 October 2008 - 12:38 PM

View Postsportyh4509, on 22 Sep, 2008 - 04:36 PM, said:

#include<iostream.h>
#include<iomanip.h>
#include <windows.h>
using namespace std;

void main ()

{

        cout<<Beep ( , );

        system ("pause");

}



And my question is.. for the beep.. i have to create a tune.. and my teacher would like the happy birthday tune. I need to know the frequencies to put in the "Beep ( , );" ... or do you know of a better way?

Please help!
Thanks!

I'm not at my piano so I couldn't tell you the notes right now, but here are the freq's for all of the notes:
http://wc.pima.edu/~...0per%20note.jpg

(darnit the "insert image" option is not working)

hey, just to be funny, you should have it play the "death march" instead! haha... no-wait,, that would probbaly get you in trouble.

** Edit ** Removed the image & provided a link
Was This Post Helpful? 0
  • +
  • -

#11 Techno Mage  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 10-June 07

Re: C++ Sound Frequencies

Posted 02 November 2008 - 04:57 PM

Quick question. Can I hurt myself or my card if I turn it up too high or low? Can I change the volume?
Was This Post Helpful? 0
  • +
  • -

#12 Lillefix  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 37
  • View blog
  • Posts: 204
  • Joined: 19-September 08

Re: C++ Sound Frequencies

Posted 03 November 2008 - 03:34 PM

Is there any way to do this without the windows-library?

Good luck on you code though, I'd love to hear the result.
Was This Post Helpful? 0
  • +
  • -

#13 Hyper  Icon User is offline

  • Banned

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

Re: C++ Sound Frequencies

Posted 03 November 2008 - 04:38 PM

My own personal funny tune (That somehow is an ear-worm to me):

    Beep(850, 350);
    Beep(850, 350);
    
    Beep(825, 150);
    Beep(825, 350);
    Beep(850, 500);



Hope it annoys you all! :D
Was This Post Helpful? 0
  • +
  • -

#14 bosch19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-September 09

Re: C++ Sound Frequencies

Posted 21 September 2009 - 12:44 PM

To help you out on the freq. there pretty staright forward.

I use:

hap C4 262 1/2 sec
py C4 262 1/2 sec
birth D4 294 1 sec
day C4 262 1 sec
to F4 349 1 sec
you E4 330 2 sec
hap C4 262 1/2 sec
py C4 262 1/2 sec
birth D4 294 1 sec
day C4 262 1 sec
to G4 392 1 sec
you F4 349 2 sec
hap C4 262 1/2 sec
py C4 262 1/2 sec
birth C5 523 1 sec
day A4 440 1 sec
dear F4 349 1 sec
so E4 330 1 sec
so D4 294 3 sec
hap B4b 466 1 sec
py B4b 466 1 sec
birth A4 440 1 sec
day F4 349 1 sec
to G4 392 1 sec
you! F4 349 2 sec


and there you have it the complete freq. list for happy birthday.

I hope this helps.
Was This Post Helpful? 0
  • +
  • -

#15 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: C++ Sound Frequencies

Posted 21 September 2009 - 01:32 PM

View Postgabehabe, on 24 Sep, 2008 - 12:24 PM, said:

Why is this featured?


Wondering the same thing

View PostTechno Mage, on 2 Nov, 2008 - 03:57 PM, said:

Quick question. Can I hurt myself or my card if I turn it up too high or low? Can I change the volume?


I dont know how would it hurt you O.o
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1