Using/programming a sound card

For issues with communication ports, protocols, etc.
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Using/programming a sound card

Postby darkblacklife » Aug 07, 2008 2:53

Hi, I was reading this webpages (for QBasic):

http://www.fys.ruu.nl/%7Ebergmann/soundblaster.html
http://www.qbasicnews.com/abc/showsnipp ... snippet=96

And I adapted this code (using "lang -qb" compilation) for soundblaster card detection:

Code: Select all

' The following functions will detect the soundblaster by using OUT and INP
' and not by simply reading the autoexec.bat
' Some code was found in a C program and from Ethan Brodky (http://www.xraylith.wisc.edu/~ebrodsky/)
' Reactions can be sent to Alex....@yahoo.com, so is my name Alexander
' Works in QBASIC and QuickBASIC, probably PowerBASIC and Visual Basic for DOS
'
DEFINT A-Z
DECLARE FUNCTION DspRead ()
DECLARE FUNCTION DspReset ()
DECLARE SUB DspWrite (byte AS INTEGER)
DECLARE SUB GetDspVersion (returnmajorversion AS INTEGER, returnminorversion AS INTEGER)
DECLARE FUNCTION GetSbBaseport ()
DECLARE FUNCTION GetSbIrq ()
DECLARE FUNCTION GetSbLowerDma ()
DECLARE FUNCTION GetSbUpperDma ()
DECLARE FUNCTION IsSb ()
DIM minorversion AS INTEGER, majorversion AS INTEGER
DIM SHARED baseport AS INTEGER

CLS
IF IsSb = 0 THEN
  PRINT "Baseport: "; HEX$(GetSbBaseport)
  PRINT "IRQ:"; GetSbIrq
  PRINT "Lower DMA:"; GetSbLowerDma
  PRINT "Upper DMA:"; GetSbUpperDma
  GetDspVersion majorversion, minorversion
  PRINT "Lower DSP version:"; minorversion
  PRINT "Upper DSP version:"; majorversion
ELSE
  PRINT "Soundblaster not detected"
END IF
SLEEP

FUNCTION DspRead
  DO
  LOOP UNTIL INP(baseport + &HE) AND &H80
  DspRead = INP(baseport + &HA)
END FUNCTION
 
FUNCTION DspReset
  DIM ct AS INTEGER, stat AS INTEGER
  OUT baseport + &H6, &H1
  FOR ct = 1 TO 100
  NEXT ct
  OUT baseport + &H6, &H0
  ct = 0
  stat = 0
  WHILE (stat <> &HAA) AND (ct < 100)
    stat = INP(baseport + &HE)
    stat = INP(baseport + &HA)
    ct = ct + 1
  WEND
  IF stat = &HAA THEN DspReset = 0 ELSE DspReset = -1
END FUNCTION
 
SUB DspWrite (byte AS INTEGER)
  DO
  LOOP UNTIL (INP(baseport + &HC) AND &H80) = 0
  OUT baseport + &HC, byte
END SUB
 
SUB GetDspVersion (returnmajorversion AS INTEGER, returnminorversion AS INTEGER)
  DspWrite &HE1
  returnmajorversion = DspRead
  returnminorversion = DspRead
END SUB
 
FUNCTION GetSbBaseport
  GetSbBaseport = baseport
END FUNCTION
 
FUNCTION GetSbIrq
  OUT baseport + &H4, &H80
  SELECT CASE INP(baseport + &H5) AND &HF
    CASE &H1
      GetSbIrq = 2
    CASE &H2
      GetSbIrq = 5
    CASE &H4
      GetSbIrq = 7
    CASE &H8
      GetSbIrq = 10
    CASE ELSE
      GetSbIrq = -1
  END SELECT
END FUNCTION
 
FUNCTION GetSbLowerDma
  OUT baseport + &H4, &H81
  SELECT CASE INP(baseport + &H5) AND &HB
    CASE &H1
      GetSbLowerDma = 0
    CASE &H2
      GetSbLowerDma = 1
    CASE &H8
      GetSbLowerDma = 3
    CASE ELSE
      GetSbLowerDma = -1
  END SELECT
END FUNCTION
 
FUNCTION GetSbUpperDma
  DIM lowerdma AS INTEGER
  lowerdma = GetSbLowerDma
  OUT baseport + &H4, &H81
  SELECT CASE INP(baseport + &H5) \ &H20
    CASE &H1
      GetSbUpperDma = 5
    CASE &H2
      GetSbUpperDma = 6
    CASE &H4
      GetSbUpperDma = 7
    CASE ELSE
      GetSbUpperDma = lowerdma
  END SELECT
END FUNCTION
 
FUNCTION IsSb
  DIM sbdetected AS INTEGER
  baseport = &H220
  sbdetected = -1
  WHILE (baseport <= &H280) AND (sbdetected = -1)
    sbdetected = DspReset
    IF sbdetected = -1 THEN baseport = baseport + &H20
  WEND
  IsSb = sbdetected
END FUNCTION


The original source code (http://www.qbasicnews.com/abc/showsnipp ... snippet=96) in qbasic (usind DosBox for emulation) works nice...

When I run the program (on windows xp) it get me "Soundblaster not detected"...

My Sound card is "sound maker value 5.1" (Genius, pci, with chipset cmi8738) and user's manual say "fully sound blaster, sound blaster pro compatible"... so why it can't see my sound card???

I'm using windows xp but I want write code for linux platform too, I want write my own multi-platform sound libraries...

Please, some body help me... :) thanks
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Aug 07, 2008 4:21

fully sound blaster, sound blaster pro compatible

I can only guess that it came with DOS drivers to allow this emulation - un-usable in winXP unless emulated as well

The fact it is PCI equates to that as a lie, *true* SB compatble was ISA bus based - in other words - its either marketing bull crap, or relevant only in DOS, likely for DOS games, with an emulating driver.

So, you may have to compile that for DOS and run in DOS, and likely using the DOS drivers for that sound card.

I havent seen such marketing verbage since win31/95/98 - (for existing DOS games that were programmed for SB compatibles for its sound - wave and midi)??
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 07, 2008 22:49

maddogg6 wrote:So, you may have to compile that for DOS and run in DOS, and likely using the DOS drivers for that sound card.


No way... I want use my sound card or any sound card on windows and linux.

how can I make functions that use the sound card?
I want play tones, .wav files and other stuff... I don't want use libraries like sdl, openal, allegro... I want make my own code... I want learn sound card programming (sorry for my bad english)

Can I do this with freebasic? how? any link with "theory" about sound card programming?

Thanks :)
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 07, 2008 23:57

I clone this topic here:
http://www.freebasic.net/forum/viewtopi ... sound+card
I think it must be in this section...

sorry :)
yetifoot
Posts: 1710
Joined: Sep 11, 2005 7:08
Location: England
Contact:

Postby yetifoot » Aug 08, 2008 4:23

darkblacklife wrote:I clone this topic here:
http://www.freebasic.net/forum/viewtopi ... sound+card
I think it must be in this section...

sorry :)


Hi darkblacklife, I removed that other topic as a duplicate, I'm not sure where the right place is really, but it's better to only have one topic.

I think what you want to learn about, are things like waveout* functions on windows, and perhaps /dev/dsp on linux.

To get started, try search google for

MSDN waveoutwrite

and

linux /dev/dsp

they will allow you to send raw PCM data to the soundcard, the /dev/dsp on linux is really use to use, the WinAPI one is a little tougher.

For DOS, they way you are going, with accessing SB by port access/asm is probably the best.

Sorry I can't supply more info or examples right now.
D.J.Peters
Posts: 8024
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Aug 08, 2008 16:08

you can try fbsound it's open source
FBSound = 0$ for Win and Lin commercial apps too
BASS >2000$ for Win and Lin commercial apps
FMOD >4000$ for Win and Lin commercial apps

take a look to the source code if you like
mme-plug.bas = Windows (95, 98, Me, XP, VISTA)
dsp-plug.bas = Linux x86 /dev/dsp
alsa-plug.bas = Linux x86 Sound System
arts-plug.bas = Linux x86 KDE Sound Server
Frank Dodd
Posts: 444
Joined: Mar 10, 2006 19:22

Postby Frank Dodd » Aug 08, 2008 17:08

At the risk of being labeled IrrDodd there is also a thread on the forum for a cross platform library called IrrKlang :)

I have tried IrrKlang out and it works very well playing multiple sound files in 3D while also supporting music formats like ogg.
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 08, 2008 19:44

D.J.Peters wrote:you can try fbsound it's open source
FBSound = 0$ for Win and Lin commercial apps too


I never could compile fbsound (on freebasic 0.18) and I didn't know where begin to read... I'll try this modules, thanks!
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 08, 2008 20:10

Frank Dodd wrote:At the risk of being labeled IrrDodd there is also a thread on the forum for a cross platform library called IrrKlang :)

I have tried IrrKlang out and it works very well playing multiple sound files in 3D while also supporting music formats like ogg.


the links that I found in
http://www.freebasic.net/forum/viewtopi ... t=irrklang
don't work... are these freebasic code? (I don't think so)

thanks
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 08, 2008 20:36

D.J.Peters wrote:take a look to the source code if you like
mme-plug.bas = Windows (95, 98, Me, XP, VISTA)
dsp-plug.bas = Linux x86 /dev/dsp
alsa-plug.bas = Linux x86 Sound System
arts-plug.bas = Linux x86 KDE Sound Server


I'm watching a line with:
#inclib "winmm"
I don't want use libraries, I want direct-hardware programming

Why Do I need diferent code for diferent platform? The hardware doesn't change (and memory directions, and values that I must write in this directions), only de Operating System (linux or windows)... right?

thanks
D.J.Peters
Posts: 8024
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Aug 08, 2008 20:56

darkblacklife wrote:Why Do I need diferent code for diferent platform?
nice question ;-)
why do you need diffrent "outfits" for diffrent girls/womans :lol:
fun by side i'm curently on a party and was only checking my online things

i will post tomorror but i'm sure here are more persons with better english then me and will be answer your questions too and more quckly.

Joshy
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 08, 2008 22:39

D.J.Peters wrote:
darkblacklife wrote:Why Do I need diferent code for diferent platform?
nice question ;-)


I was thinking that only I would need memory directions and "key values" in order to take control of the sound card (sorry for my english). For DOS/QBasic I was watching examples with IN/OUT commands and I was thinking that some thing like this for Linux or Windows...

A pure FreeBasic code multi-platform...
Mysoft
Posts: 777
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Postby Mysoft » Aug 08, 2008 23:13

the basic problem is... the code for SoundBlaster will not work cuz your card isnt a soundblaster... access to direct I/O for those are virtualized and maybe will not work as expected... also your program will only work for your soundcard, and last... the way to program your soundcard requires a hardware manual of it... thing that isnt that easy to found... since the hardware manufcturer just release the driver... you have the driver for your card in linux? then learn how it works... (its C, i know) but if you can't then you shouldnt be playing with those things anyway... that's all i have to say

GOOD LUCK =)
darkblacklife
Posts: 149
Joined: Jun 18, 2008 22:10

Postby darkblacklife » Aug 08, 2008 23:41

Mysoft wrote:the basic problem is... the code for SoundBlaster will not work cuz your card isnt a soundblaster... access to direct I/O for those are virtualized and maybe will not work as expected... also your program will only work for your soundcard, and last... the way to program your soundcard requires a hardware manual of it... thing that isnt that easy to found... since the hardware manufcturer just release the driver... you have the driver for your card in linux? then learn how it works... (its C, i know) but if you can't then you shouldnt be playing with those things anyway... that's all i have to say

GOOD LUCK =)


are not all sound cards soundblaster compatible?
so... don't all sound cards use the same code?
searching on google I read that today all the sound cards are soundblaster compatible.

on linux, the kernel detect my sound card, I don't need any driver.

thanks
Mysoft
Posts: 777
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Postby Mysoft » Aug 09, 2008 1:32

sound blaster compatible... in terms of capabilities... not that all have the same address/IO etc..
as was stated earlier... many of them provide "wrappers" to have the same usage as a SoundBlaster (DOS only) ... but that will be in the end the same thing as you using the Default System libraries (aka MMSYSTEM in windows)

other than that the try to achieve some compatibility... but, linux only detect it, cuz it have lots of differents drivers internally... provided by the sound cards owners...

also you will get NO advantege into doing this.. if its for learn... then i suggest you to use DOSBOX and try some DOS soundcard programming... cuz dealing with DSP require good timing... and using DMA isnt freely alowed by modern systems... except in drivers... so...

in windows you can check the I/O ports and DMA that they are using. And you will se that is TOTALLY different than I/O 220 ... mainly cuz SB is designed to run in 16bpp system... in protected mode... they have restriction of memory usage... and a lot of things that... will just bother you anyway... so... i hope that you will understand now...

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest