Log In  


Hey everyone!

I'm trying to prototype a little beat game in Picotron, but I'm having some issues with SFX/Music sync. I've been some references in pico8 to using stat() to read the current play time of active music tracks and use that to play SFX in sync with the beat.

There is stat() in picotron, but it's undocumented. I've tried iterating over a bunch of stat codes, but seems like it's pretty much zero after a stat code of about 9

I was wondering if anyone has had additional info about the stat method, or where else I might pull music timing info from?

1


this should have what you need.


1

I'm not entirely certain either. However, I did some testing with the stat function and observed return values with stat codes reaching up to 987. I'm not sure how useful this will be, but here is the code I used along with the output:

function ShowStats(n)
	n = n or 1000
	for i = 0, n do
		local str = "stat("..i..")= "
		local length = #str
		local j, k = stat(i)
		if (j ~= nil and j ~= 0) str = str..tostr(j)
		if (k ~= nil and k ~= 0) str = str..", "..tostr(k)
		if (#str ~= length) print(str)
	end
end
ShowStats()

stat(1)= 0.0085008225448823
stat(5)= 7, 0.1.0g
stat(7)= 60.0
stat(86)= 1720797089.0
stat(87)= -3600.0
stat(301)= 0.0074851584292969
stat(308)= 1010.0
stat(309)= 4802032.0
stat(310)= 271.0
stat(311)= 16113.0
stat(312)= 4096.0
stat(465)= 512.0
stat(466)= -1
stat(985)= 1.0
stat(987)= 45467.0


Thanks Zevest - I did a little more investigation myself and it looks like the same Pico8 stats I need aren't implemented yet in Picotron.

Best I could find is Stat 400 range, which will let you know if a SFX is playing, eg Stat(407) will let you know if 8th channel of the pattern is playing. Regardless of the pattern number, it's always the index of the active pattern.

I've found a way to hack on that by creating a muted "Heartbeat" channel in a pattern which I can monitor for each beat.

I want to flesh out this concept further, using timers for beat subdivisions, but this is a good start.

function audio:update()
	if (not self.running) then return end

	local isHeartbeat = stat(407) == 1

	if (isHeartbeat and not self.wasHeartbeat) then
		self.wasHeartbeat = true
		self:nextBeat()
	elseif (not isHeartbeat and self.wasHeartbeat) then
		self.wasHeartbeat = false	
	end
end


[Please log in to post a comment]