Musical scale: Difference between revisions

Content deleted Content added
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.


==={{header|Borland's Turbo C}}===
===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.


<lang c>/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
<lang C>
/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
#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;
}</lang>
}
</lang>


==={{header|Windows C}}===
===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>/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
<lang C>
/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
#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>
}
</lang>


=={{header|J}}==
=={{header|J}}==