FroggerProgger aus dem PureBoard-Archiv herausgekramt und ihn auf
FMODEx umgebaut.
Da wird man ja noch blöd von den ganzen Flags...

Naja, auf jeden Fall klappt der Code jetzt und somit stelle ich ihn jetzt hier
mal rein:
Code: Alles auswählen
;- >> Sinemouse 0.3
;- FMOD-callback-example by Froggerprogger (23.01.05)
;- modified by NTQ (02.02.07)
Declare.l Buffercallback(hStream.l, BufferPointer.l, length.l)
Global Samplerate.l
Global Bits.l
Global Channels.l
Global max_samplevalue.w
Global fq.l, mpos.POINT
Macro Quote
"
EndMacro
Macro OK(a)
Debug Quote#a#Quote
Result = a
If Result
Debug FMOD_ErrorString(Result)
End
EndIf
EndMacro
Samplerate = 44100 : Bits = 16 : Channels = 2
max_samplevalue = (1 << (Bits - 1)) - 1
Init_FMOD()
OK(FMOD_System_Create(@*System))
exinfo.FMOD_CREATESOUNDEXINFO
With exinfo
\cbSize = SizeOf(FMOD_CREATESOUNDEXINFO)
\Numchannels = Channels ;Anzahl Kanäle (Stereo)
\defaultfrequency = Samplerate ;Die Samplerate (44100)
\Format = #FMOD_SOUND_FORMAT_PCM16 ;Das Format (16 Bit)
\length = Samplerate ;Die Länge des Samples (1 Sekunde)
\decodebuffersize = Samplerate / 40 ;Die Anzahl an Samples pro Callback-Aufruf (25 ms)
\pcmreadcallback = @Buffercallback() ;Der Pointer zum Callback
EndWith
OK(FMOD_System_Init(*System, Channels, #FMOD_INIT_NORMAL, 0))
OK(FMOD_System_CreateSound(*System, 0, #FMOD_2D | #FMOD_OPENUSER | #FMOD_SOFTWARE | #FMOD_CREATESTREAM | #FMOD_LOOP_NORMAL, @exinfo, @*Sound))
OK(FMOD_System_PlaySound(*System, #FMOD_CHANNEL_FREE, *Sound, #False, @*channel))
hwnd = OpenWindow(1, 0, 0, 240, 20, "Sinemouse 0.2, modified by NTQ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(hwnd)
TextGadget(1, 0,0, 150, 20, "")
TextGadget(2, 150, 0, 20, 20, "=")
TextGadget(3, 170, 0, 70, 20, "", #PB_Text_Right)
Repeat
SetGadgetText(1, "Mouseposition: " + Str(mpos\x) + ", " + Str(mpos\y))
SetGadgetText(3, Str(fq) + " Hz")
FMOD_System_Update(*System)
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
OK(FMOD_Channel_Stop(*channel))
OK(FMOD_Sound_Release(*Sound))
OK(FMOD_System_Release(*System))
End
Procedure.l Buffercallback(*Sound, *BufferPointer, length.l)
Static angle.f, signed_word.w, sample_act.l, sample_last.l
sample_act = 0
sample_last = length - 1
bytes_per_sample = Bits >> 3 * Channels
While sample_act < sample_last
GetCursorPos_(mpos)
fq = (mpos\y + mpos\x) * 2 + 90 ; -> so frequences from 90 Hz to ((screenwidth+screenheight)*2)+90 Hz
angle + 2 * #PI * (fq / Samplerate) ; -> increase radian measure for the 'complex pointer'
If angle > 2 * #PI : angle - 2 * #PI : EndIf ; -> avoid big (+ inaccurate) floats
signed_word = Int(max_samplevalue * Sin(angle)) ; -> calculate the real (sine) part of the cp
For offset = 0 To Channels -1 ; (ok, not really stereo, just 'multichannel-mono' ;-)
PokeW(*BufferPointer + sample_act + Bits >> 3 * offset, signed_word) ; -> poke the same actual value for each channel
Next
sample_act + bytes_per_sample ; -> next sample
Wend
ProcedureReturn #FMOD_OK
EndProcedure
z.B. so:
Code: Alles auswählen
\decodebuffersize = Samplerate / 20 ;für 50 ms