Sound Blaster output

DOS specific questions.
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Sound Blaster output

Postby Fox » Jul 06, 2008 9:13

Hi,

I'm trying to make working my Sound Blaster sound card using FreeBASIC. I saw that there are many QB programs which do that using INP/OUT statements only. I took one of such program, modified it to be FB-compatible, and tried to generate some sounds.
I do get some noise from my sound card, but no "clear" sound.

Here's the code:

Code: Select all

DECLARE FUNCTION RDTSC() AS ULONGINT
DECLARE SUB uSLEEP(dur AS INTEGER)

DIM SHARED AS INTEGER x, f
DIM SHARED AS ULONGINT CpuClock
DIM SHARED AS DOUBLE HoldTimer

REM  ***  Calculating CPU freq
PRINT " * Calculating CPU frequency... ";
HoldTimer = TIMER
CpuClock = RDTSC()
DO: LOOP UNTIL TIMER - HoldTimer >= 1
CpuClock = (RDTSC() - CpuClock)
PRINT CpuClock \ 1000000; "MHz"

REM  ***  START OF RESET SECTION
OUT &H226, 1
uSLEEP(5)    ' Should wait 5 us
OUT &H226, 0
DO
x = INP(&H22E)
IF x AND 128 THEN
        x = INP(&H22A)
        IF x = &HAA THEN
'               PRINT "reset!"
                EXIT DO
        END IF
END IF
LOOP
PRINT " * DSP reset done. Press any key to turn the speaker ON..."
DO: SLEEP: LOOP UNTIL INKEY <> ""

REM  ***  TURN SPEAKER ON
DO
  x = INP(&H22C)
LOOP WHILE x AND 128
OUT &H22C, &HD1                         ' Send "speaker ON" code

PRINT " * Speaker turned ON. Press any key to send the signal..."
DO: SLEEP: LOOP UNTIL INKEY <> ""
PRINT " * Generating signal... You should hear it now. Press any key to exit...";

DO
  FOR x = 1 TO 1000                     ' Start of the loop
    OUT &H22C, &H10                     ' Prepare the DSP to receive raw data
    OUT &H22C, f                        ' send no.
    uSLEEP(10)                          ' delay (10us)
    IF f = 255 THEN f = 0 ELSE f = 255  ' alternate between 0 and 255
  NEXT x                                ' End of the loop
LOOP UNTIL INKEY <> ""                  ' Exit if any key pressed

END


REM  ***  END OF THE PROGRAM  ***


FUNCTION RDTSC() AS ULONGINT
   ASM
     rdtsc
     mov [Function], eax
     mov [Function+4], edx
   END ASM
END FUNCTION


SUB uSLEEP(dur AS INTEGER)
  DIM Waitloop AS ULONGINT
  Waitloop = RDTSC()
  DO
  LOOP UNTIL (RDTSC() - Waitloop) > (CpuClock / 1000000 * dur)
END SUB


Could anyone tell me if this is the way to go? Maybe someone already got SoundBlaster working with FreeBASIC? The original QB code I took is at http://www.petesqbsite.com/sections/tut ... een_13.txt
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Re: Sound Blaster output

Postby DOS386 » Jul 06, 2008 12:39

Fox wrote:trying to make working my Sound Blaster sound card using FreeBASIC.


:-) But you are aware that ISA SB code will NOT work with PCI soundcards (OK, bad SBEMU hack with I/O debug + EMM386 + ...) ? Maybe you reveal your card model ?

saw that there are many QB programs which do that using INP/OUT statements only


OK, INP/OUT is the way to talk to the hardware ;-)

Could anyone tell me if this is the way to go?


YES, but:

1. Your code seems ways too trivial to me ...
2. I don't know ISA SB too much since I have PCI only ...
3. For DMA, you will (later ?) need a buffer, in low memory (no big problem)
Laaca
Posts: 22
Joined: Dec 31, 2007 14:24

Postby Laaca » Jul 07, 2008 18:03

About non working PCI soundcards:

1) he hears the sound clicks so it means that something works there
2) most probably he has running windows so it will work with PCI cards too
Fox
Posts: 353
Joined: Aug 08, 2006 13:39
Location: Lille, France
Contact:

Postby Fox » Jul 07, 2008 18:37

Laaca wrote:1) he hears the sound clicks so it means that something works there
2) most probably he has running windows so it will work with PCI cards too


Hi,

Just to clarify things: :-)
What I hear is not really "clicks", but rather some fuzzy "shhhhhhh" :-)
I do not run Windows, but native FreeDOS on a PIII 450MHz, with a Sound Blaster 64 ISA sound card.

I tried to run the code (from the URL I pointed on previously) on QuickBasic, and I have exactly the same output than with FreeBASIC. Therefore I assume it's not a FB issue. I will have to found a QB code which is working for me on QB, and then try to port it to FreeBasic...

Thank you all for your replies! ;-)
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Jul 07, 2008 19:41

Wouldn't you need to have the old dos drivers to make this work?

(its really just a question, not some kind of hint to an answer, btw - I have no clue - just remember what a pain it was managing driver/memory in the old dos days - and SB drivers were usually a must have).
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Postby DOS386 » Jul 08, 2008 5:18

Laaca wrote:he hears the sound clicks so it means that something works there

obviously
most probably he has running windows so it will work with PCI cards

not very helpful
Fox wrote:I do not run Windows, but native FreeDOS

:-)
on a PIII 450MHz, with a Sound Blaster 64 ISA sound card.

:-) Should work then.

Therefore I assume it's not a FB issue. I will have to found a QB code which is working for me on QB, and then try to port it to FreeBasic...

Exactly. The code above is obviously immature / incomplete. ISA SB ports are very same in FB as in QB, the DMA buffer allocation and filling will need adjustments.

maddogg6 wrote:Wouldn't you need to have the old dos drivers to make this work?
Heh, No ..

(its really just a question, not some kind of hint to an answer, btw - I have no clue - just remember what a pain it was managing driver/memory in the old dos days - and SB drivers were usually a must have).

1. Low memory wars and EMS indeed was and is a horrible pain ... but FB uses DPMI32 ;-)
2. For ISA cards, usually no drivers were required : direct port access by applications. Obviously, this soon turned out to be very faulty design :-( OTOH "SBEMU" drivers were/are "required" for PCI cards ... with final success hardly justifying the pain :-(

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 16 guests