API Mod Player
Tracker module music playback: MOD files only, the ProTracker family. Supported: modules tagged M.K., M!K!, FLT4, 1CHN–9CHN or 10CH–32CH (1 to 32 channels), and untagged 15-sample Soundtracker modules. XM, S3M, IT and FLT8 modules are not supported: load returns false. A file may be at most 512 KB.
The player renders the module on Core 1 at 22,050 Hz. Its output shares one PCM stream with the FilePlayer and picocalc.audio.startStream, so stop whichever of them is playing before you start another; starting one does not stop the others. SamplePlayers, tones and the MP3Player mix with it, so sound effects play over the music.
Performance. The player renders on the second core, but it reads the module’s samples from PSRAM through the cache it shares with your app, so it slows your app’s own code. Measured in a gfx3d game at 200 MHz with busy test modules (every channel starting a note on every row, 16 KB looping samples): a 4-channel module made each frame about 14% slower, an 8-channel one about 24%. A looping WAV through a FilePlayer cost 2.5%; 44.1 kHz stereo MP3 music cost nothing in a game that paces itself with time to spare and about 21% in one that does not (see Audio and Sound). A module’s whole soundtrack is tens of KB, against about 2.6 MB per minute of 22.05 kHz mono WAV.
picocalc.modplayer
Section titled “picocalc.modplayer”Functions
Section titled “Functions”picocalc.modplayer.create()
Section titled “picocalc.modplayer.create()”Create a new mod player instance.
- Parameters: None
- Returns: (userdata) Player object, or
nil, errorStringon failure
local player, err = picocalc.modplayer.create()if not player then picocalc.repl.print("Error: " .. err)endPlayer Methods
Section titled “Player Methods”Objects returned by picocalc.modplayer.create(). There is one MOD player:
create() returns the one live handle (calling it again returns the same
object while it is alive). It is cleaned up by the garbage collector; a
destroyed handle raises on use. Volume is 0-100.
player:load(path)
Section titled “player:load(path)”Load a tracker module file from the SD card.
- Parameters:
path(string): Path to a MOD file
- Returns: (boolean)
trueif the file was loaded;falseif it is missing, larger than 512 KB, or not a MOD file the player can read
local ok = player:load("/apps/myapp/music.mod")player:play([loop])
Section titled “player:play([loop])”Start playback of the loaded module.
- Parameters:
loop(boolean, optional): Whether to loop playback. Defaultfalse.
- Returns: None
player:play(true) -- play with loopingplayer:stop()
Section titled “player:stop()”Stop playback.
- Parameters: None
- Returns: None
player:stop()player:pause()
Section titled “player:pause()”Pause playback at the current position.
- Parameters: None
- Returns: None
player:pause()player:resume()
Section titled “player:resume()”Resume paused playback.
- Parameters: None
- Returns: None
player:resume()player:isPlaying()
Section titled “player:isPlaying()”Check whether the player is currently playing.
- Parameters: None
- Returns: (boolean)
trueif playback is active
if player:isPlaying() then picocalc.repl.print("Playing...")endplayer:setVolume(vol)
Section titled “player:setVolume(vol)”Set the playback volume.
- Parameters:
vol(number): Volume level from 0 (silent) to 100 (maximum)
- Returns: None
player:setVolume(75)player:getVolume()
Section titled “player:getVolume()”Get the current playback volume.
- Parameters: None
- Returns: (number) Current volume level (0-100)
local vol = player:getVolume()player:setLoop(enabled)
Section titled “player:setLoop(enabled)”Enable or disable looping on the current module.
- Parameters:
enabled(boolean):trueto loop,falseto play once
- Returns: None
player:setLoop(true)