Musical scale: Difference between revisions
Content deleted Content added
→{{header|Racket}}: Add Python. |
m →{{header|C}}: Removed wrong header templates |
||
Line 13: | Line 13: | ||
Although C provides low level access to devices, there is no standardized way. Here are illustrated two approaches. |
Although C provides low level access to devices, there is no standardized way. Here are illustrated two approaches. |
||
=== |
===Borland's Turbo C=== |
||
Borland's Turbo C system has the dos.h header file which contains the functions sound() and nosound(). sound takes an argument which is the frequency of the note to be played through the device speaker. delay(), also part of dos.h tells the code how long to suspend execution. The sound will however still be playing. It is therefore essential to call nosound() at the end which ends the speaker output, otherwise the Turbo C (DOS) session will have to be ended. |
Borland's Turbo C system has the dos.h header file which contains the functions sound() and nosound(). sound takes an argument which is the frequency of the note to be played through the device speaker. delay(), also part of dos.h tells the code how long to suspend execution. The sound will however still be playing. It is therefore essential to call nosound() at the end which ends the speaker output, otherwise the Turbo C (DOS) session will have to be ended. |
||
⚫ | |||
⚫ | |||
⚫ | |||
#include<stdio.h> |
#include<stdio.h> |
||
#include<conio.h> |
#include<conio.h> |
||
Line 30: | Line 29: | ||
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; |
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; |
||
int main() |
int main(void) |
||
{ |
{ |
||
int i=0; |
int i=0; |
||
Line 44: | Line 43: | ||
nosound(); |
nosound(); |
||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
⚫ | |||
=== |
===Windows C=== |
||
I named it Windows C for want of a better name. This is actually more constrained than the above example since although it will run on any Windows machine, Beep can only play integer frequencies and thus the tones are noticeably lower than the ones played by sound() above. |
I named it Windows C for want of a better name. This is actually more constrained than the above example since although it will run on any Windows machine, Beep can only play integer frequencies and thus the tones are noticeably lower than the ones played by sound() above. |
||
⚫ | |||
<lang C> |
|||
⚫ | |||
#include<windows.h> |
#include<windows.h> |
||
#include<stdio.h> |
#include<stdio.h> |
||
Line 63: | Line 60: | ||
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; |
note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; |
||
int main() |
int main(void) |
||
{ |
{ |
||
int i=0; |
int i=0; |
||
Line 75: | Line 72: | ||
} |
} |
||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |