这是一个可以用键盘控制发声频率的程序。
/**************Beep.C*******************/
#define LINT_ARGS
#include <dos.h>
#include <conio.h>
#define ONTONE outp( 0x61, inp( 0x61 ) | 3 )
#define OFFTONE outp( 0x61, inp( 0x61 ) & 0xFC )
static void setfreq( count )
unsigned int count;
{
outp( 0x43, 0xB6 );
outp( 0x42, (int) (count & 0xFF) );
outp( 0x42, (int) (count >> 8) );
}
static unsigned long int getticks()
{
union REGS regs;
regs.h.ah = 0x00;
int86( 0x1A, ®s, ®s );
return( ((unsigned long int) regs.x.cx << 16) + regs.x.dx );
}
void beep( pitch, nticks )
unsigned int pitch,nticks;
{
unsigned long int ticks,ticksa;
setfreq( pitch );
ticksa = getticks();
while ( ( ticks = getticks() ) == ticksa )
;
ONTONE;
ticks = ticks + (unsigned long int) nticks;
while ( getticks() < ticks )
;
OFFTONE;
}
#ifdef DEBUG
#include <stdlib.h>
#include "beep.h"
void main()
{
beep( 200, 1 );
exit(0);
}
#endif
------------------------------------------------------------------
/*************CHAOS.C******************/
#include <stdio.h>
#include <conio.h>
#define R_MIN 2.95
#define R_MAX 4.0
void play( int );
void clear_screen();
void draw_screen();
void hide_cursor();
void do_chaos( r, f )
double r;
void (*f)();
{
int i,t;
double x = .3;
for ( i = 0; i < 250; i++ )
x = r*x*(1.0-x);
for ( ; ; )
{
x = r*x*(1.0-x);
t = 95.0*x;
(*f)( t );
if ( kbhit() )
break;
}
}
void play_chaos()
{
double r = (R_MAX + R_MIN)/2.0;
double dr = (R_MAX - R_MIN)/500.0;
double bigdr = dr*10.0;
char outstr[40];
int done = 0;
while ( !done )
{
sprintf( outstr, "r = %f\r", r );
print_centered( outstr );
do_chaos( r, play );
switch( getch() )
{
case 27 :
done = 1;
break;
case 0 :
switch( getch() )
{
case 73 :
r -= bigdr;
if ( r < R_MIN )
r = R_MIN;
break;
case 81 :
r += bigdr;
if ( r > R_MAX )
r = R_MAX;
break;
case 72 :
r -= dr;
if ( r < R_MIN )
r = R_MIN;
break;
case 80 :
r += dr;
if ( r > R_MAX )
r = R_MAX;
break;
default :
break;
}
default :
break;
}
}
}
void main()
{
clear_screen();
draw_screen();
play_chaos();
clear_screen();
}
------------------------------------------------------------------
/*************NOTES.C***********************/
#define FREQ 1193180.0
double pitch[95] = {
18.35,
19.45,
20.60,
21.83,
23.12,
24.50,
25.96,
27.50,
29.14,
30.87,
32.70,
34.65,
36.71,
38.89,
41.20,
43.65,
46.25,
49.00,
51.91,
55.00,
58.27,
61.74,
65.41,
69.30,
73.42,
77.78,
82.41,
87.31,
92.50,
98.00,
103.83,
110.00,
116.54,
123.47,
130.81,
138.59,
146.83,
155.56,
164.81,
174.61,
185.00,
196.00,
207.65,
220.00,
233.08,
246.94,
261.63,
277.18,
293.66,
311.13,
329.63,
349.23,
369.99,
392.00,
415.30,
440.00,
466.16,
493.88,
523.25,
554.37,
587.33,
622.25,
659.26,
698.46,
739.99,
783.99,
830.61,
880.00,
932.33,
987.77,
1046.50,
1108.73,
1174.66,
1244.51,
1328.51,
1396.91,
1479.98,
1567.98,
1661.22,
1760.00,
1864.66,
1975.53,
2093.00,
2217.46,
2349.32,
2489.02,
2637.02,
2793.83,
2959.96,
3135.96,
3322.44,
3520.00,
3729.31,
3951.07,
4186.01 };
void beep( unsigned int, unsigned int );
void play( note )
int note;
{
beep( FREQ/pitch[note], 2 );
}
#ifdef TEST
void main()
{
int note;
for (note = 0; note < 95; note++ )
play( note );
}
#endif /* TEST */
------------------------------------------------------------
/*****************SCREEN.C*******************/
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void clear_screen()
{
union REGS regs;
/* first clear the screen */
regs.h.ah = 6;
regs.h.al = 0;
regs.h.bh = 7;
regs.h.ch = 0;
regs.h.cl = 0;
regs.h.dh = 24;
regs.h.dl = 79;
int86( 0x10, ®s, ®s );
/* then put the cursor in the top left corner */
regs.h.ah = 2;
regs.h.dh = 0;
regs.h.dl = 0;
regs.h.bh = 0;
int86( 0x10, ®s, ®s );
}
void print_centered( s )
char *s;
{
int i;
for ( i = 0; i < (80 - strlen( s ))/2; i++ )
putch( ' ' );
cputs( s );
}
void draw_screen()
{
printf( "\n\n\n" );
print_centered( "Music from Chaos" );
printf( "\n\n" );
print_centered( "by" );
printf( "\n\n" );
print_centered( "Peter J. Becker" );
printf( "\n\n\n" );
print_centered( "\xDA\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xBF" );
printf( "\n" );
print_centered( "\xB3 \x18 to decrease r, small step \xB3" );
printf( "\n" );
print_centered( "\xB3 \x19 to increase r, small step \xB3" );
printf( "\n" );
print_centered( "\xB3 \xB3" );
printf( "\n" );
print_centered( "\xB3 PgUp to decrease r, large step \xB3" );
printf( "\n" );
print_centered( "\xB3 PgDn to increase r, large step \xB3" );
printf( "\n" );
print_centered( "\xB3 \xB3" );
printf( "\n" );
print_centered( "\xB3 ESC to exit \xB3" );
printf( "\n" );
print_centered( "\xC0\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xD9" );
printf( "\n\n" );
}
下载运行文件和源程序 >>>>
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |