Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sunybcs!rutgers!netnews.upenn.edu!cps3xx!usenet From: usenet@cps3xx.UUCP (Usenet file owner) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: Need routine(s) to generate sound for MSC 5.1 Keywords: sound msc Message-ID: <6748@cps3xx.UUCP> Date: 6 Mar 90 01:47:16 GMT References: <365@trux.UUCP> Reply-To: draper@cpsin1.UUCP (Patrick J Draper) Organization: Engineering, Michigan State Univ., E. Lansing Lines: 76 In article <365@trux.UUCP> car@trux.UUCP (Chris Rende) writes: >I need a routine that generates sound from MSC 5.1: A beep, a tone/duration, >play a script, etc... > >Please post or Email: I have not FTP or Aonon UUCP ability. > >If there is interest and I receive some code I'll post a summary. > >Thanks, > >car. >-- >Christopher A. Rende Central Cartage (Nixdorf/Pyramid/SysVR2/BSD4.3) >uunet!edsews!rphroy!trux!car Multics,DTSS,Unix,Shortwave,Scanners,StarTrek > trux!car@uunet.uu.net Minix 1.2,PC/XT,Mac+,TRS-80 Model I,1802 ELF > "I don't ever remember forgetting anything." - Chris Rende Here's a little something. I can't remember what type of sound the main routine generates, but I think it's some kind of laser blast. This code will work under MSC 5.1 and Turbo C 1.5, which I have tested myself. Patrick Draper *********************************************************************** /* sound generation subroutine from Lee Adams' book :' high performance graphics in c ' tab books */ #include /* supports port manipulation */ #define outportb outp #define inportb inp void noise(int hertz,int duration); /* subroutine: generate a sound enter with frequency, expressed as hert in the range 40 to 4660. a comfortable frequency range for the human ear is 40 to 2400. enter with the duation, expressed as an integer to be used in a simple for... next loop. */ main(){ int reps=0; for(reps=0;reps<10000;reps+=20){ noise(reps % 2000,5002); } /* for */ } void noise(int hertz,int duration){ int tl=1,high_byte=0,low_byte=0; short count=0; unsigned char old_port=0, new_port=0; if (hertz<40) return; /* avoid math overflow for int count*/ if (hertz >4660) return; /* avoid math underflow for low_byte*/ count=1193180l/hertz; /* determine timer count */ high_byte=count/256; low_byte=count-(high_byte*256); outportb(0x43,0xb6); /*prep the timer register */ outportb(0x42,low_byte); /* send the low_byte */ outportb(0x42,high_byte); /* send the high_byte */ old_port=inportb(0x61); /* store the existing port value */ new_port=( old_port| 0x03); /* use or to set bits0 and 1 to on*/ outportb(0x61,new_port); /* turn on the speaker */ for (tl=1;tl