1. Save the code below into a folder together with a short stereo sample named 'test.wav' and the Csound library dll (download and run Setup_Csound6_6.03.2.exe from http://sourceforge.net/projects/csound/ ... sound6.03/).
2. Run the code and press the space bar quickly a number of times (usually less than 40).
Code: Select all
OpenLibrary(0, "csound64.dll")
PrototypeC.l ftype1()
PrototypeC.i ftype2(*p1)
PrototypeC.i ftype3(*p1, s.p-ascii)
PrototypeC.i ftype4(*p1, *p2)
Global csoundCreate.ftype1 = GetFunction(0, "csoundCreate")
Global csoundSetOption.ftype3 = GetFunction(0, "csoundSetOption")
Global csoundCompileOrc.ftype3 = GetFunction(0, "csoundCompileOrc")
Global csoundStart.ftype2 = GetFunction(0, "csoundStart")
Global csoundStop.ftype2 = GetFunction(0, "csoundStop")
Global csoundReset.ftype2 = GetFunction(0, "csoundReset")
Global csoundDestroy.ftype2 = GetFunction(0, "csoundDestroy")
Global csoundPerform.ftype2 = GetFunction(0, "csoundPerform")
Global csoundPerformKsmps.ftype2 = GetFunction(0, "csoundPerformKsmps")
Global csoundInputMessage.ftype3 = GetFunction(0, "csoundInputMessage")
Global csoundInputMessage2.ftype4 = GetFunction(0, "csoundInputMessage")
Global csoundRewindScore.ftype2 = GetFunction(0, "csoundRewindScore")
Global csoundSetOutputChannelCallback.ftype4 = GetFunction(0, "csoundSetOutputChannelCallback")
ProcedureC InstrumentCallback(csound.l, channelname.l, value.l, type.l) ;if defined as InstrumentCallback() (with no parameters) the application does not crash
Debug PeekL(csound)
;if a debug print statement is put here the application does not crash
EndProcedure
Procedure CsoundThread(*csound)
csoundPerform(*csound)
EndProcedure
Procedure CheckKey(*csound)
Static isOn
If KeyboardPushed(#PB_Key_Space)
If Not isOn
isOn = #True
csoundInputMessage(*csound, "i 1 0 0.2")
EndIf
Else
If isOn
isOn = #False
EndIf
EndIf
EndProcedure
Procedure InitCsound()
*csound = csoundCreate()
csoundSetOption(*csound, "-odac")
csoundSetOutputChannelCallback(*csound, @InstrumentCallback()) ;if the callback is not registered the application does not crash
;create a csound 'instrument' which will call our callback every time it is first activated (at 'init time') to play a stereo sample which is loaded into 'ftable' number 1
csoundCompileOrc(*csound, "sr=44100" + Chr(10) +
"ksmps=10" + Chr(10) +
"nchnls=2" + Chr(10) +
"0dbfs=1" + Chr(10) +
"instr 1" + Chr(10) +
" kVal init 1" + Chr(10) +
" if kVal > 1 then" + Chr(10) +
" outvalue " + Chr(34) + "x" + Chr(34) + ", 1" + Chr(10) +
" kVal = 0" + Chr(10) +
" endif" + Chr(10) +
" aL, aR loscil 1, 1, 1, 1" + Chr(10) +
" outs aL, aR" + Chr(10) +
"endin")
csoundStart(*csound)
CreateThread(@CsoundThread(), *csound)
ProcedureReturn *csound
EndProcedure
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 600, 500, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1, 1)
*csound = InitCsound()
csoundInputMessage(*csound, "f 1 0 0 1 " + Chr(34) + "test.wav" + Chr(34) + " 0 0 0")
Repeat
Repeat
event = WindowEvent()
Select event
Case #PB_Event_CloseWindow
End
EndSelect
Until event = 0
FlipBuffers()
ExamineKeyboard()
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
CheckKey(*csound)
;if using only one CheckKey(*csound) call the application does not crash
ForEver