Difference between revisions of "GW-Basic/SoundCard"
|Line 35:||Line 35:|
That's about all there is to it; there are, of course, many more commands
That's about all there is to it; there are, of course, many more commands such &H20, which reads a byte from the input port of the sound card , though these are beyond the scope of this article. In the future, I plan to post articles about controlling the FM chip to generate multiple-track synthesized music, but this should be enough to chew on for now. Good luck with your programming efforts, and have fun!
Latest revision as of 05:02, 4 February 2014
Using A Sound Card In GW-Basic Programs
!!!!! Big, Fat, IMPORTANT NOTICE: !!!!!
Versions of Microsoft Windows later than Win 98 are apparently retarded, and they want to play God with the sound card and other hardware, so if you try & run this program in a standard "Dos" window, you'll soon be hearing a whole lot of NUTHIN'! For this reason, you need to download and install a "Dos Emulator" program with digital audio support to get the sound card to work. I use "DosBox", which can be downloaded for free from their Web site ( Just Google 'em - you'll find it. ), and I've had no troubles playing sounds in GW-Basic or any other Dos program. So, if you don't hear anything, don't come cryin' to me - all I know is it works on my box, so just give it a shot & hope for the best!
Now, then: The following program asks the user to input the name of a sound file, and then plays the file in 8-bit, mono format. You will of course want to set the value of the "BASEPT" variable to match the actual base port settings of your sound card. Also, the "PATH$" variable should be modified to indicate whichever folder your sound files are located in. The program first sets up the hardware addresses of the various input/output ports ( Base, Reset & Command ports ), resets the sound card, and turns on the speaker. Next, it gets input from the user to determine which file to play, and opens the appropriate file in "Random" mode, with a length of 1 byte per record. It then reads the file data, 1 byte at a time ( GET #1 ), and sends the command to output the next byte to the sound card ( OUT COMMANDPT, &H10 ), followed by the actual data byte ( OUT COMMANDPT, ASC(DAT$) ). The program just repeats these three steps until it reaches the end of the file.
1 LOCATE 1,1: PRINT "GWave.bas Copyright 2009 By: Daryl R. Dubbs" 2 BASEPT = &H220: RESETPT = BASEPT + 6: COMMANDPT = BASEPT + 12 3 FOR T = 1 TO 10: OUT RESETPT, 1: NEXT T 4 FOR T = 1 TO 10: OUT RESETPT, 0: NEXT T 5 OUT COMMANDPT, &HD1 'Turn on speaker. 6 GOSUB 100 'Close open files, get and open new file 7 GOSUB 200 'Read wave file & output to speakers 8 GOTO 6 100 CLS: LOCATE 1,1: PRINT"GWave3.bas Copyright 2010 By: Daryl R. Dubbs" 101 INPUT "Please select file to play (Press ENTER to quit.): ",FILENAME$ 102 IF LEN(FILENAME$)= 0 THEN END 103 PATH$ ="C:\Waves\": FILENAME$ = PATH$ + FILENAME$ 104 CLOSE #1: OPEN FILENAME$ FOR RANDOM AS #1 LEN =1 105 RETURN 200 FIELD 1,1 AS DAT$ 201 WHILE EOF(1) = 0 202 GET #1 203 OUT COMMANDPT, &H10 204 OUT COMMANDPT, ASC(DAT$) 205 WEND 206 RETURN
That's about all there is to it; there are, of course, many more commands ( such as &H20, which reads a byte from the input port of the sound card ), though these are beyond the scope of this article. In the future, I plan to post articles about controlling the FM chip to generate multiple-track synthesized music, but this should be enough to chew on for now. Good luck with your programming efforts, and have fun!