×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Sound

Sound

(OP)
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)

RE: Sound

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:
http://qb45.com/qbasic/pn/modules.php?op=modload&name=D...
and
http://qb45.com/qbasic/pn/modules.php?op=modload&name=D...

Qbsupermario1.5 and GIMI

RE: Sound

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.

RE: Sound

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).

RE: Sound

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$("BLASTER")) = 0 THEN PRINT "BLASTER environment variable not set.": EXIT SUB
FOR Length = 1 TO LEN(ENVIRON$("BLASTER"))
   SELECT CASE MID$(ENVIRON$("BLASTER"), Length, 1)
      CASE "A"
        BasePort = VAL("&H" + MID$(ENVIRON$("BLASTER"), Length + 1, 3))
      CASE "I"
        IRQ = VAL(MID$(ENVIRON$("BLASTER"), Length + 1, 1))
      CASE "D"
        DMA = VAL(MID$(ENVIRON$("BLASTER"), 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 "Sound Blaster not detected. Do you"
   PRINT "wish to disable sound? (y,n)"
   DO: sel$ = INKEY$: LOOP WHILE UCASE$(sel$) <> "Y" AND UCASE$(sel$) <> "N"
   IF UCASE$(sel$) = "N" 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.  

RE: Sound

(OP)
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 !

RE: Sound

Glad I could help.

RE: Sound

OK...
So is there anyway to make midi's play in QB on XP machines?

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

http://cubee.topcities.com

RE: Sound

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

*from the crowd: "What talents?"* ;)

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close