Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sound

Status
Not open for further replies.

fancom

Programmer
Feb 7, 2001
46
TR
Hey you there......
When i download a source like sfxplay.bas etc. it does not work i tried so hard but there was no changes.Can we play sound from sound card (SB) in qb ?.Or is there a source that really works ?....
10x you all..(especially qbasicking , barok and Cube101)
 
Yes, there are a lot of programs out there that work, but also a lot that don't. Mainly because sound cards vary so much, there is no universal code for them, they are very specific. There are also hundreds of types of sound files. .wav is not a format, there are many many .wav formats, and qbasic code is usaully specific to one of them.

Some libraries are pretty good about figureing out the sound card problem, but not the format one. Also I have never had a sound library that worked under Windows XP

Two programs that I have seen that have really good .wav players are:
and

Qbsupermario1.5 and GIMI
 
A solution to this is to use the same things windows uses to play sound files. Its easy, but slow. You could:

SHELL "start /m sndrec32.exe /play /close " + wavfile$

thats one way that I know works on all windows versions I think.

THe faster one is:

SHELL "rundll mmsystem,sndplaysound " + wavfile$

which i think only works on some versions of windows.

To play other media types u'd have to use this i think:

SHELL "rundll mmsystem,mcisendstring " + arguments$

'm not sure how it works in qbasic, but in c++ you can get it 2 work.
 
Oh yeah, you should get a program that can change the bitrate of wav files so you can make them smaller in size (since they take up a lot of space).
 
Taking just the wva player out of the programs that I mentioned is a lot of work, but since I needed to do it for myself anyway, I did it for you. This is the wav player from QBSuperMario1.5:

DECLARE SUB SBDETECT ()
DECLARE SUB RESETDSP ()
DECLARE SUB DMAPLAY (Segment&, Offset&, buflen&)
DECLARE SUB GetBLASTER (DMA, BasePort, IRQ)
DECLARE SUB WRITEDSP (ibyte)
DECLARE SUB PLAYMUSIC ()
DECLARE SUB LOADFX (file$)
DECLARE SUB PUTFONT (fontnum$, xstart)
COMMON SHARED repeat, buflen&
COMMON SHARED BasePort, LenPort, Channel, nosound
CONST timeconst = 256 - 1000000 \ 22050
'Bit Rate - 176kbps
'Audio sample size - 8 bit
'channels 1(mono)
'audio sample rate 22kHz
'audio format PCM

'$DYNAMIC
DIM SHARED WavBuffer(0 TO 0) AS STRING * 32767

'$STATIC
DIM SHARED snds(1 TO 6) AS STRING * 30
DEF SEG
SBDETECT
IF nosound = 0 THEN
GetBLASTER Channel, BasePort, IRQ
RESETDSP
END IF
OPEN directory$ + path$ FOR BINARY AS #2
GET #2, , WavBuffer(0): buflen& = 32767
IF nosound = 0 THEN PLAYMUSIC
DO: LOOP WHILE INKEY$ <> CHR$(13)

SUB DMAPLAY (Segment&, Offset&, buflen&)
Page = 0
MemLoc& = Segment& * 16 + Offset&
SELECT CASE Channel
CASE 0
PgPort = &H87
AddPort = &H0
LenPort = &H1
ModeReg = &H48
CASE 1
PgPort = &H83
AddPort = &H2
LenPort = &H3
ModeReg = &H49
CASE 2
PgPort = &H81
AddPort = &H4
LenPort = &H5
ModeReg = &H4A
CASE 3
PgPort = &H82
AddPort = &H6
LenPort = &H7
ModeReg = &H4B
END SELECT
OUT &HA, &H4 + Channel
OUT &HC, &H0
OUT &HB, ModeReg
OUT AddPort, MemLoc& AND &HFF
OUT AddPort, (MemLoc& AND &HFFFF&) \ &H100
IF (MemLoc& AND 65536) THEN Page = Page + 1
IF (MemLoc& AND 131072) THEN Page = Page + 2
IF (MemLoc& AND 262144) THEN Page = Page + 4
IF (MemLoc& AND 524288) THEN Page = Page + 8
OUT PgPort, Page
OUT LenPort, buflen& AND &HFF
OUT LenPort, (buflen& AND &HFFFF&) \ &H100
OUT &HA, Channel
WRITEDSP &H40
WRITEDSP timeconst
WRITEDSP &H14
WRITEDSP (buflen& AND &HFF)
WRITEDSP ((buflen& AND &HFFFF&) \ &H100)
END SUB

SUB GetBLASTER (DMA, BasePort, IRQ)
IF LEN(ENVIRON$(&quot;BLASTER&quot;)) = 0 THEN PRINT &quot;BLASTER environment variable not set.&quot;: EXIT SUB
FOR Length = 1 TO LEN(ENVIRON$(&quot;BLASTER&quot;))
SELECT CASE MID$(ENVIRON$(&quot;BLASTER&quot;), Length, 1)
CASE &quot;A&quot;
BasePort = VAL(&quot;&H&quot; + MID$(ENVIRON$(&quot;BLASTER&quot;), Length + 1, 3))
CASE &quot;I&quot;
IRQ = VAL(MID$(ENVIRON$(&quot;BLASTER&quot;), Length + 1, 1))
CASE &quot;D&quot;
DMA = VAL(MID$(ENVIRON$(&quot;BLASTER&quot;), Length + 1, 1))
END SELECT
NEXT
END SUB

SUB LOADFX (file$)
OPEN file$ FOR BINARY AS #1
DIM id AS STRING * 4
GET #1, , id
GET #1, , NumSound
FOR i = 1 TO NumSound
IF EOF(1) THEN EXIT FOR
GET #1, , snds(i)
temp$ = SPACE$(20)
GET #1, , temp$
NEXT i
CLOSE #1
END SUB

SUB PLAYMUSIC
DEF SEG
RESETDSP
IF repeat >= 0 THEN DMAPLAY VARSEG(WavBuffer(0)), VARPTR(WavBuffer(0)), buflen&
IF EOF(2) THEN
SEEK #2, 44
IF repeat <= 0 THEN repeat = repeat - 1
END IF
buflen& = LOF(2) - LOC(2)
IF buflen& > 32767 THEN buflen& = 32767
GET #2, , WavBuffer(0)
END SUB

SUB RESETDSP
OUT BasePort + 6, 1
FOR Count = 1 TO 4
junk = INP(BasePort + 6)
NEXT
OUT BasePort + 6, 0
END SUB

SUB SBDETECT
nosound = 1
FOR port = &H210 TO &H280 STEP &H10
OUT port + &H6, 1
FOR Count = 1 TO 100
OUT port + &H6, 0
Stat = INP(port + &HE)
Stat = INP(port + &HA)
IF Stat = &HAA THEN nosound = 0: EXIT SUB
NEXT Count
NEXT port
IF nosound = 1 THEN
PRINT &quot;Sound Blaster not detected. Do you&quot;
PRINT &quot;wish to disable sound? (y,n)&quot;
DO: sel$ = INKEY$: LOOP WHILE UCASE$(sel$) <> &quot;Y&quot; AND UCASE$(sel$) <> &quot;N&quot;
IF UCASE$(sel$) = &quot;N&quot; THEN END
END IF
END SUB

SUB WRITEDSP (ibyte)
DO: LOOP WHILE INP(BasePort + 12) AND &H80
OUT BasePort + 12, ibyte
END SUB

Fill in directory$ and path$ with a wav file that is 22kHz mono PCM. You can make files like this with Windows XP's Sound Recorder.
 
I did not tried your source yet qbking..But gonna make a game in screen 13 with no flickers and need some sound...
There had to be a way with out cmmnd and i was sure you would post it!.

any way i will try it as soon as possible and finish the game...There will be Baroks and your name in credits..10x a lot for adresses..Now it is assembler time !
 
OK...
So is there anyway to make midi's play in QB on XP machines?

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
thanks, it's nice to know that my talents are recognized...

*from the crowd: &quot;What talents?&quot;* ;)

you might also want to look at dmaplay.bas and the ff2 clone for wav players. as for midi, you need libs for that.

qmidi
sbmidi
ds4qb
ds4qb2
ds4qb++

i'm not sure, but i think ds4qb++ is the best. also to note, for some reason midi libs won't work in windows xp. it's microsoft's fault! what else? they're obviously shamed at their creation of ms-dos, so they do their best to make windows less and less compatible with dos with each version!

maybe you can run midi libs through cmd.exe? just a thought, as it's running through a dos emulator and not xp. just a thought.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top