Code: Select all
Enumeration
#Window_0
#Window_Master
EndEnumeration
ExamineDesktops()
InitSound()
EnableJS
var SAMPLE_RATE = 44100;
var FRQ = 440
var PI_2 = Math.PI * 2;
function play_buffersource(SAMPLE_RATE,FRQ) {
if (! window.AudioContext) {
if (! window.webkitAudioContext) {
bad_browser();
return;
}
window.AudioContext = window.webkitAudioContext;
}
var ctx = new AudioContext();
var buffer = ctx.createBuffer(1, 2048, 44100);
var buf = buffer.getChannelData(0);
for (i = 0; i < 2048; ++i) {
buf[i] = Math.sin(FRQ * PI_2 * i / SAMPLE_RATE);
}
var node = ctx.createBufferSource(0);
node.buffer = buffer;
node.connect(ctx.destination);
node.start(ctx.currentTime + 0.1);
}
function cb(evt) {
var buffer = evt.outputBuffer;
for (var j = 0; j < buffer.numberOfChannels; ++j) {
var buf = evt.outputBuffer.getChannelData(j);
for (i = 0; i < buf.length; ++i) {
f = [Math.sin, Math.cos][j % 2];
buf[i] = Math.sin(440 * PI_2 * (cb.n + i) / SAMPLE_RATE) *
f(2 * PI_2 * (cb.n + i) / SAMPLE_RATE);
}
}
cb.n += i;
cb.n % SAMPLE_RATE;
if (cb.count++ > 10) {
cb.node.disconnect();
}
}
function play_jssource() {
if (! window.AudioContext) {
if (! window.webkitAudioContext) {
bad_browser();
return;
}
window.AudioContext = window.webkitAudioContext;
}
ctx = new AudioContext();
var node = ctx.createScriptProcessor(16384, 0, 1);
node.onaudioprocess = cb;
node.connect(ctx.destination);
cb.n = 0;
cb.count = 0;
cb.node = node;
}
DisableJS
procedure music()
;for i=0 to i=100
;next
;!play_buffersource(44100,640);
;RemoveWindowTimer(0, 0)
Debug "Timer event: " + EventTimer()
endprocedure
Procedure TimerEvents()
;Debug "Timer event: " + EventTimer()
;!play_buffersource(44100,640);
EndProcedure
If OpenWindow(#Window_0, 10, DesktopHeight(0)-180, 800, 120, "Timer example", #PB_Window_TitleBar | #PB_Window_SizeGadget)
AddWindowTimer(#Window_0, 0, 1000) ; First timer every seconds
ContainerGadget(0, 10, 8, 300, 133, #PB_Container_Raised)
TrackBarGadget(2, 10, 2, 40, 80, 0, 10000, #PB_TrackBar_Vertical)
SetGadgetState(2, 8000)
ButtonGadget(1, 10, 90, 15, 15, "x")
CloseGadgetList()
ContainerGadget(1, 320, 8, 300, 133, #PB_Container_Raised)
TrackBarGadget(3, 10, 2, 20, 80, 0, 10000, #PB_TrackBar_Vertical)
SetGadgetState(3, 8000)
ButtonGadget(4, 10, 90, 15, 15, "x")
CloseGadgetList()
!play_buffersource(44100,640);
BindEvent(#PB_Event_Timer, @TimerEvents(),#PB_All)
EndIf
If OpenWindow(#Window_Master, 50, 50, 600, 600, "Mixer", #PB_Window_TitleBar)
StickyWindow(#Window_Master, 1)
endif