Make simple music program with beep(freq, duration) with Pascal - The Koch Family
The Koch Family The Koch Family

Latest news

جاري التحميل ...

Make simple music program with beep(freq, duration) with Pascal

Pascal is my first programing language when I have studied in high school. It was really exciting for me. :)

The Pascal programming language was created by Niklaus Wirth in 1970. It was named after Blaise Pascal, a famous French Mathematician. It was made as a language to teach programming and to be reliable and efficient. Pascal has since become more than just an academic language and is now used commercially.

I tried to make a simple music program by using Lazarus IDE on MS Window 7, 64-bit. It frustrated me a few times how difficulty to use Sound command to make a sound. Sound did not work on my compiler and my platform anymore. So far, I just could use beep(freq, duration) from window unit to implement my work.

Here is my code. ;)
program mysong;

uses
Windows,
crt;
const
C: Integer = 512; { x = A * EXP(LN(2)/12)}
C_: Integer = 542;
D: Integer = 574;
D_: Integer = 608;
E: Integer = 644;
F: Integer = 682;
F_: Integer = 723;
G: Integer = 766;
G_: Integer = 812;
A: Integer = 860;
A_: Integer = 911;
B: Integer = 965;

WHITE: Integer = 1600; {x = B/2}
BLACK: Integer = 800;
SINGLE: Integer = 400;
DOUBLE: Integer = 200;
TRIPLE: Integer = 100;

procedure play(freq,duration: Integer);
begin
Windows.Beep(freq,duration);
end;
begin
{ A Time For US }
Clrscr;
play(A, SINGLE);
play(C*2, SINGLE);
play(B, SINGLE);
play(E, BLACK + SINGLE);

play(E, SINGLE);
play(G, SINGLE);
play(E, SINGLE);
play(A, BLACK + SINGLE);

play(A, SINGLE);
play(G, SINGLE);
play(F, SINGLE);
play(G, BLACK + SINGLE);

play(G, SINGLE);
play(F, SINGLE);
play(E, SINGLE);
play(D, BLACK + SINGLE);

play(E, DOUBLE);
play(D, DOUBLE);
play(C, SINGLE);
play(D, SINGLE);
play(E, BLACK + SINGLE);

end.

I just chose frequency's Do note is 512. Next, I inferred the frequency of other notes by "afterNote = beforeNote * EXP(LN(2)/12)".

Reference:
[1]. http://kon-phum.com/tutors/pascal/programming_pascal_learn01.html
[2]. http://stackoverflow.com/questions/23249175/how-to-use-sound-in-pascal

Comments



If you like the content of our blog, we hope to stay in constant communication, just enter your email to subscribe to the blog's express mail to receive new blog updates, and you can send a message by clicking on the button next ...

إتصل بنا

About the site

author The Koch Family <<  Welcome! I'm so glad that you stopped by Your Modern Family blog. Together, we will talk about raising kids, organizing the home and saving money! and Tips & tricks and more…

< Learn more ←

Blog stats

Sparkline 2513183

All Copyrights Reserved

The Koch Family

2020