2016-06-05 23:21:36 +02:00
|
|
|
-- ****************************************************************************
|
|
|
|
-- Play file with pcm module.
|
|
|
|
--
|
|
|
|
-- Upload jump_8k.u8 to spiffs before running this script.
|
|
|
|
--
|
|
|
|
-- ****************************************************************************
|
|
|
|
|
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
local function cb_drained()
|
2016-06-05 23:21:36 +02:00
|
|
|
print("drained "..node.heap())
|
|
|
|
|
|
|
|
file.seek("set", 0)
|
|
|
|
-- uncomment the following line for continuous playback
|
|
|
|
--d:play(pcm.RATE_8K)
|
|
|
|
end
|
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
local function cb_stopped()
|
2016-06-05 23:21:36 +02:00
|
|
|
print("playback stopped")
|
|
|
|
file.seek("set", 0)
|
|
|
|
end
|
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
local function cb_paused()
|
2016-06-05 23:21:36 +02:00
|
|
|
print("playback paused")
|
|
|
|
end
|
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
do
|
|
|
|
file.open("jump_8k.u8", "r")
|
2016-06-05 23:21:36 +02:00
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
local drv = pcm.new(pcm.SD, 1)
|
2016-06-05 23:21:36 +02:00
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
-- fetch data in chunks of FILE_READ_CHUNK (1024) from file
|
|
|
|
drv:on("data", function(driver) return file.read() end) -- luacheck: no unused
|
2016-06-05 23:21:36 +02:00
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
-- get called back when all samples were read from the file
|
|
|
|
drv:on("drained", cb_drained)
|
2016-06-05 23:21:36 +02:00
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
drv:on("stopped", cb_stopped)
|
|
|
|
drv:on("paused", cb_paused)
|
2016-06-05 23:21:36 +02:00
|
|
|
|
2019-12-31 00:53:54 +01:00
|
|
|
-- start playback
|
|
|
|
drv:play(pcm.RATE_8K)
|
|
|
|
end
|