I'm currently writing a program for outputting specific signals via soundcard. It already calculates them and stores in memory in raw format (each as an array of words). I've never dealed with soundcards before. Any suggestions how to make this prog do what it should do?:confused:
Posted on 2002-12-16 12:14:12 by longer
I dont really know the answer. But I think I can give you a start. :)

Here is goes: your sound card probably is Sound Blaster compatible. You might also search for good old DOSprogram sources that have done that. Then I think it will be good... but I think if you search Sound Blaster you will gather many good results... or maybe in the board... who knows?

Greets!

Wicrosoft
Posted on 2002-12-16 16:08:23 by wicr0s0ft
The low level WaveForm Audio API should do.
Take a look at the functions
waveOutGetDevCaps
waveOutOpen
waveOutPrepareHeader
waveOutWrite
In the Microsoft plataform SDK.

I hope this helps.

RValois.
Posted on 2002-12-16 17:35:02 by RValois
Thanks both of you!
I'll try it.
Posted on 2002-12-17 04:56:25 by longer
You can also try DIrectSound API, here is an example, dont forget to download DirectX includes.

DSINVOKE MACRO Mobject:REQ,method:REQ,ObjPtr:REQ,ArgList:VARARG
LOCAL this
this CATSTR <Mobject>,<method>
mcall ObjPtr,%this,ArgList
ENDM

InitDirectSound proc hWin:DWORD
; ================ Initialize DirectSound ================
invoke DirectSoundCreate,NULL,addr lpds,NULL
.if eax != DS_OK
invoke MessageBox,hWin,addr szErrNoDirectSound,ADDR szDisplayName,MB_OK
.endif

DSINVOKE IDirectSound_,SetCooperativeLevel,lpds,hWin,DSSCL_PRIORITY ; DSSCL_EXCLUSIVE
.if eax != DS_OK
invoke MessageBox,hWin,addr szErrNoCooperativeLevel,ADDR szDisplayName,MB_OK
.endif
ret
InitDirectSound endp

ReleaseDirectSound proc
; ========== Free DirectSound device ===========
.if lpds != NULL
DSINVOKE IDirectSound_,Release,lpds
mov , NULL
.endif
ret

ReleaseDirectSound endp

ReleaseSoundBuffer proc
.if dsbSound != NULL
DSINVOKE IDirectSoundBuffer_,Release,dsbSound
mov , NULL
.endif
ret
ReleaseSoundBuffer endp

---------------- here is playing -----------------------------

; * create sound buffer
DSINVOKE IDirectSound_,CreateSoundBuffer,lpds,addr dsbuffer,addr dsbSound, NULL
.if eax != DS_OK
invoke MessageBox,hWin,addr szErrNoSoundBuffer,ADDR szDisplayName,MB_OK
jmp dontplay
.endif

DSINVOKE IDirectSoundBuffer_,Lock,dsbSound,0,dsbLenght,addr dsbWrite1,addr dsbLenght1,addr dsbWrite2,addr dsbLenght2,0
.if eax != DS_OK
invoke MessageBox,hWin,addr szErrCantLockBuffer,ADDR szDisplayName,MB_OK
jmp dontplay
.endif
.if dsbWrite1
m2m dsbWrite,dsbWrite1
m2m dsbLenght1,dsbLenght
.else
m2m dsbWrite,dsbWrite2
m2m dsbLenght2,dsbLenght
.endif

; ----------- now copy your raw wave data to dsbWrite

DSINVOKE IDirectSoundBuffer_,Unlock,dsbSound,dsbWrite1,dsbLenght1,dsbWrite2,dsbLenght2

DSINVOKE IDirectSoundBuffer_,SetFrequency,dsbSound,dsbFreq ; set playing freq
DSINVOKE IDirectSoundBuffer_,SetCurrentPosition,dsbSound,eax
DSINVOKE IDirectSoundBuffer_,Play,dsbSound,0,0,0 ; play


take look also to the M$ DirectX API this is just schematic example


regards


frankie
Posted on 2002-12-17 05:05:04 by frankie
Hi, frankie!
Thanks for your reply.

Now I would like to know what method is more preferable: to use DSound or WaveForm Audio API? What are their advantages and disadvantages?
Posted on 2002-12-17 09:27:17 by longer
Depends what you wanna achieve with your program. If you need just simply play a wavefile then winapi is fine. If you wanna make something more serious (changing frequency, modulation, effect processing) then I reccomend you DirectSound.

regards

frankie
Posted on 2002-12-17 16:51:56 by frankie
Then I have no need in DSound, WinAPI will be enough.
Thanks again, frankie.
Posted on 2002-12-18 00:11:14 by longer