[comp.sys.ibm.pc.programmer] Need routine

car@trux.UUCP (Chris Rende) (03/05/90)

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

usenet@cps3xx.UUCP (Usenet file owner) (03/06/90)

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 <dos.h>        /* 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<duration; tl++);             /*wait           */
   outportb( 0x61,old_port ); /* turn off speaker         */
}

dixon@sagittarius.crd.ge.com (walt dixon) (03/06/90)

In a previous article Christopher A. 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.

The sample device driver I wrote for Chapter 11 of "The MS-DOS Papers"
will do what you want.  It recognizes a superset of the BASICA SOUND
statement as well as correcting some errors in the BASIC implementation.
Since this is a device driver,  one can open it and send characters
to it from any language.  The following C fragment

	fp=fopen("SOUND","w");
	fprints(fp,"%s","O3T100L8GFE-FGGGPFFF4");

plays "Mary Had a Little Lamb".  The complete source code for this driver
can be found at the end of the chapter.  If you don't feel like typing
it all in,  it is also available (from me) on a supplemental disk.  The
$10 fee I charge for each disk just covers reproduction,  materials,
and mailing costs.  All the code on this disk carries the following
notice:

	(c) W. V. Dixon.  All rights reserved.
	May be freely copied for personal, non profit use
	so long as this copyrite notice is retained and usage
	restrictions are observed.  This software may not be
	used in whole or in part in any program which is sold
	without prior written consent of the author.

This driver started out as a fairly simple example but grew into a
fairly sophisticated piece of code.

I hope this helps.

Walt Dixon		{arpa:		dixon@crd.ge.com	}
			{us mail:	ge crd			}
			{		po box 8		}
			{		schenectady, ny 12301	}
			{phone:		518-387-5798		}
Walt Dixon dixon@crd.ge.com

CMH117@psuvm.psu.edu (Charles Hannum) (03/06/90)

In article <5799@crdgw1.crd.ge.com>, dixon@sagittarius.crd.ge.com (walt dixon)
says:
>
>                                 The complete source code for this driver
>can be found at the end of the chapter.  If you don't feel like typing
>it all in,  it is also available (from me) on a supplemental disk.  The
>$10 fee I charge for each disk just covers reproduction,  materials,
>and mailing costs.  All the code on this disk carries the following
>notice:

If'n that's all ahd be payin' fer, how 'bout puttin' it on uh FTP site fer
uhs awl ta download?

[Aren't you glad people don't actually write the way they speak?  B-)]


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117@psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h@psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."

dixon@ra.crd.ge.com (walt dixon) (03/06/90)

In a follow up to my original posting  Charles Martin Hannum II writes:

>In article <5799@crdgw1.crd.ge.com>, dixon@sagittarius.crd.ge.com (walt dixon)
>says:
[part of original message deleted]
>>The
>>$10 fee I charge for each disk just covers reproduction,  materials,
>>and mailing costs.  All the code on this disk carries the following
>>notice:

>If'n that's all ahd be payin' fer, how 'bout puttin' it on uh FTP site fer
>uhs awl ta download?

Sorry,  I can't do this.  The contract I signed with the publisher had
specific provisions about the way code can be distributed.  The publisher
cannot gather names for his mailing list if code gets posted to public
access BBS.

Walt Dixon		{arpa:		dixon@crd.ge.com	}
			{us mail:	ge crd			}
			{		po box 8		}
			{		schenectady, ny 12301	}
			{phone:		518-387-5798		}
Walt Dixon dixon@crd.ge.com

CMH117@psuvm.psu.edu (Charles Hannum) (03/07/90)

In article <5802@crdgw1.crd.ge.com>, dixon@ra.crd.ge.com (walt dixon) says:
>
>Sorry,  I can't do this.  The contract I signed with the publisher had
>specific provisions about the way code can be distributed.  The publisher
>cannot gather names for his mailing list if code gets posted to public
>access BBS.

Okay.  No problem.


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117@psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h@psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."

wilber@nunki.usc.edu (John Wilber) (03/07/90)

I don't have any code fragments or routines to show, but you can check
out The NEW Programmer's Guide to the IBM PC and PS/2, by Peter Norton
and Richard Wilton, Microsoft Press, 1988.  Specifically, see chapter 7,
clocks, timers, and sound generation.  This should probably tell you
what you want to know.  If you're getting paid for doing this program,
you might even be able to deduct the ~$23 for the book from your taxes
(but not until you file for 1990, unfortunately).

/***********************************************************************\
* John J. Wilber               * Vote for Socialism.  Vote Democratic   *
* wilber@nunki.usc.edu         * Vote for Conformity.  Vote Republican. *
* Student, partier, anarchist, * Vote for a free country.  Vote ....?   *
* and fun-loving guy.          *    Damn!  Nobody left to vote for!     *
\***********************************************************************/