Doraemon's Song <this song will be out in internal spekaers>

gabriel_wadley 0 Tallied Votes 6K Views Share

this's daoremon's song code

i hope you ever see doraemon's movie...

#include <iostream>

#include <windows.h>



using namespace std;



int main()

{ cout<<"Program Lagu Doraemon ; By : Gabriel Sebastian Wangsadipura / 0522084";

  Beep(220,300);

  Beep(294,300);

  Beep(294,300);

  Beep(370,300);

  Beep(494,300);

  Beep(370,300);

  Beep(440,800);

  /* */

  Beep(440,300);

  Beep(494,300);

  Beep(440,300);

  Beep(370,300);

  Beep(392,300);

  Beep(370,300);

  Beep(330,800);

  /* */

  Beep(247,300);

  Beep(330,300);

  Beep(330,300);

  Beep(370,300);

  Beep(555,300);

  Beep(555,300);

  Beep(494,300);

  Beep(440,300);

  Beep(392,800);

  Beep(392,300);

  Beep(370,300);

  Beep(247,800);

  Beep(278,300);

  Beep(294,300);

  Beep(330,2600);

  /* */

  Beep(220,300);

  Beep(294,300);

  Beep(294,300);

  Beep(370,300);

  Beep(494,300);

  Beep(370,300);

  Beep(440,800);

  /* */

  Beep(440,300);

  Beep(494,300);

  Beep(440,300);

  Beep(370,300);

  Beep(392,300);

  Beep(370,300);

  Beep(330,800);

  /* */

  Beep(247,300);

  Beep(330,300);

  Beep(330,300);

  Beep(370,300);

  Beep(555,300);

  Beep(555,300);

  Beep(494,300);

  Beep(440,300);

  Beep(392,800);

  Beep(392,300);

  Beep(370,300);

  Beep(278,600);

  Beep(330,600);

  Beep(294,2600);

  /*Reff : */

  Beep(494,300);

  Beep(494,300);

  Beep(494,300);

  Beep(440,300);

  Beep(392,200);

  Beep(440,200);

  Beep(494,200);

  Beep(440,800);

  Beep(330,300);

  Beep(370,300);

  Beep(416,300);

  Beep(330,300);

  Beep(440,2000);

  /* */

  Beep(494,800);

  Beep(440,800);

  Beep(392,1600);

  /* */

  Beep(555,300);

  Beep(555,300);

  Beep(555,300);

  Beep(494,300);

  Beep(440,300);

  Beep(494,300);

  Beep(440,300);

  Beep(392,1400);

  /* */

  Beep(440,300);

  Beep(494,300);

  Beep(370,1100);

  Beep(330,300);

  Beep(294,1800);

  /* */

  Beep(494,800);

  Beep(440,800);

  Beep(392,1600);

  /* */

  Beep(555,300);

  Beep(555,300);

  Beep(555,300);

  Beep(494,300);

  Beep(440,300);

  Beep(494,300);

  Beep(440,300);

  Beep(392,1400);

  /* */

  Beep(440,300);

  Beep(494,300);

  Beep(370,1100);

  Beep(330,300);

  Beep(294,1800);





  cin.get();

  return 0;

}

Dani AI

Generated

Nice start. A simple way to keep melody code short and readable is to store notes as MIDI numbers and compute their frequency at runtime, then call the platform beep. On Windows you can use the Win32 Beep API; this plays on the system speaker/audio device and avoids hard-coding frequencies.

// Windows-only example: build with cl /EHsc beep.cpp
#include <windows.h>
#include <cmath>

static double freq_from_midi(int midi) {
    return 440.0 * std::pow(2.0, (midi - 69) / 12.0); // A4 = MIDI 69
}

struct Note { int midi; int ms; };

int main() {
    Note melody[] = {
        {72,250},{76,250},{79,250},{84,500}, // C5 E5 G5 C6
        {79,250},{76,250},{72,500},          // G5 E5 C5
        {-1,100}                              // rest (sleep only)
    };
    for (auto n : melody) {
        if (n.midi >= 0) {
            DWORD f = static_cast<DWORD>(freq_from_midi(n.midi));
            Beep(f, n.ms);
        } else {
            Sleep(n.ms); // rest
        }
        Sleep(10); // tiny gap between notes
    }
}

Tips:

  • Keep timing in milliseconds; a quarter note at 120 BPM is 500 ms.
  • Add small sleeps between notes to avoid clicks.
  • Many modern PCs have no internal PC speaker; if Beep is silent, use your normal audio device or a library (e.g., SDL2, PortAudio) to synthesize a square wave.
  • Win32 Beep docs: .
manutd 2 Junior Poster

Use code tags!

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Has been taken care of, thanks for the notification once again.

gabriel_wadley 0 Newbie Poster

okey, thank you for your comment. i still beginner ini programing. I hope, my programming skill can be good... :cheesy:

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Glad to see someone is interested in music! You can simplify your code a little by calculating the frequency for a given musical note. See this snippet:
http://www.daniweb.com/code/snippet359.html

It is written in Python and should be very easy to understand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.