Hi guys,
I am have a problem here.
I have a masm version 8 environment, with the DirectX 8 header and lib files. All ok so far.
The only problem I have is I want to use the API invoke "GetCurrentPosition" to retrieve the offset in bytes from the play-cursor and write-cursor in a buffered-loop scenario, wher I want to put my sample bytes in manualy via the CPU.
The invoke want 3 input parameters, but when I look on msdn online, directx8 function "GetCurrentPosition" needs only two, only two offsets where two dwords are put as a result by win32 api.
What kind of input parameter is the 1st one in the invoke command exactly? If i give it a value of 0 or NULL, my app. crashes.
Here is a small snipet of code (all comments I do not use as instructions now, I found a directsound example for masm many years ago, I dont know anymore where I got this example from).
; mov eax, sizeof(pcm_sound);
; mov ecx,0
; mul ecx
; mov ecx, eax
DSBINVOKE GetCurrentPosition,sound_fx[ecx].dsbuffer,ADDR ds_pos_play, ADDR ds_pos_write
It is the part "sound_fx[ecx].dsbuffer" I need explanation of.
When I look at the invoke line, i guess it needs a pointer (dword) to a directsound buffer, right ?
But there stops my knowledge. For masm32 there is not so much to find with examples with DirectX. Especially with DirectSound, is difficult to find something.
By the way, I want to use this for my Commodore 64 emulator, to make the sound better (I have lots of strange weird sounds because now sometimes I write byte to the buffer where the playcursor is. That is bad. I want to enhance the sound output quality. I wan to do that by check at regular intervals the playcursor and writecursor and then see where I can safely write my samplebyte to be played.
The original website I used years ago was:
http://www.gamedev.net/reference/articles/article909.asp
Unfortunately the webpage does not exist anymore.
A part of my dsound.inc file I use for including:
;=======================================
; The DirectSoundBuffer interface
;=======================================
IDirectSoundBufferVtbl STRUC
; IUnknown methods
STDMETHOD QueryInterface, :PTR IDirectSoundBuffer, :PTR, :PTR PTR
STDMETHOD AddRef, :PTR IDirectSoundBuffer
STDMETHOD Release, :PTR IDirectSoundBuffer
; IDirectSoundBuffer methods
STDMETHOD GetCaps, :PTR IDirectSoundBuffer,:DWORD
STDMETHOD GetCurrentPosition, :PTR IDirectSoundBuffer,:DWORD,:DWORD <=============== THIS ONE !
STDMETHOD GetFormat, :PTR IDirectSoundBuffer,:DWORD,:DWORD,:DWORD
STDMETHOD GetVolume, :PTR IDirectSoundBuffer,:DWORD
STDMETHOD GetPan, :PTR IDirectSoundBuffer,:DWORD
STDMETHOD GetFrequency, :PTR IDirectSoundBuffer,:DWORD
STDMETHOD GetStatus, :PTR IDirectSoundBuffer,:DWORD
STDMETHOD Initialize, :PTR IDirectSoundBuffer,:DWORD,:DWORD
STDMETHOD mLock, :PTR IDirectSoundBuffer,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
STDMETHOD Play, :PTR IDirectSoundBuffer,:DWORD,:DWORD,:DWORD
STDMETHOD SetCurrentPosition, :PTR IDirectSoundBuffer,:DWORD
Hope someone can help me out with this !
Thanks in advance.
Merry Christmas and a happy coding year in 2009 !
Cheers,
Erik de Keijzer
The Netherlands
It's a 'method' rather than just a flat function.
The first (hidden) parameter is the instance of the object you want the method to act upon - the sound buffer, in this case. Otherwise, how does it know which sound buffer you want to get the current position of?
You must've either gained or created a sound buffer, so for any methods you want to call on that buffer, you must supply it in the calls to those methods (as the first parameter; even though it's not listed in the api docs, because they're meant for C++ where it's done automatically for you by the compiler.)
Hello Folks
This source code for streaming DirectSound buffers maybe of some interrest for you
It also includes the "GetCurrentPosition" function.
http://members.home.nl/siekmanski/DSound_Streaming.zip
greetings and a happy newyear
Siekmanski, (also from The Netherlands) :lol
Inserted missing dir.
Btw, this here is MASM code:
EnterHostedClass
class IASIO,,C++ compatible
; this one needs special handing, since it's a mixture of COM and C++ classes
;virtual QueryInterface ; this one's taken from the real Destructor
virtual AddRef
virtual Release:pThis
virtual init:sysHandle
virtual getDriverName:char *name
virtual getDriverVersion:
virtual getErrorMessage:char *string
virtual start:
virtual stop:
virtual getChannels:long *numInputChannels, long *numOutputChannels
virtual getLatencies:long *inputLatency, long *outputLatency
virtual getBufferSize:long *minSize, long *maxSize,long *preferredSize, long *granularity
virtual canSampleRate:ASIOSampleRate sampleRate
virtual getSampleRate:ASIOSampleRate *sampleRate
virtual setSampleRate:ASIOSampleRate sampleRate
virtual getClockSources:ASIOClockSource *clocks, long *numSources
virtual setClockSource:long reference
virtual getSamplePosition:ASIOSamples *sPos, ASIOTimeStamp *tStamp
virtual getChannelInfo:ASIOChannelInfo *info
virtual createBuffers:ASIOBufferInfo *bufferInfos, long numChannels,long bufferSize, ASIOCallbacks *callbacks
virtual disposeBuffers:
virtual controlPanel:
virtual future:long selector,void *opt
virtual outputReady:
endclass
LeaveHostedClass
ASIOChannelInfo struct
channel dd ?
isInput dd ?
isActive dd ?
channelGroup dd ?
sampleType dd ?
chanName db 32 dup (?)
ASIOChannelInfo ends
ASIOCallbacks struct
bufferSwitch dd ?
sampleRateDidChange dd ?
asioMessage dd ?
bufferSwitchTimeInfo dd ?
ASIOCallbacks ends
...
.data
pAsioDrv dd 0
set pAsioDrv as IASIO
.code
...
ASIO_GetSampleRate proc uses ebx ecx edx
local dblSamRate:real8,intSamRate:DWORD
pcall pAsioDrv.getSampleRate,addr dblSamRate
fld dblSamRate
fistp intSamRate
mov eax,intSamRate
ret
ASIO_GetSampleRate endp