Nugget
Loading...
Searching...
No Matches
psmplayer.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2025 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31// PSM Player - Real-time MIDI playback via PSM event stream + VAB instrument bank
32//
33// Usage:
34// 1. PSM_LoadBank(vabData, vabSize) - parse VAB, DMA samples to SPU RAM
35// 2. PSM_LoadSong(psmData, psmSize) - parse PSM header, point to event array
36// 3. Poll with hblank timer using PSM_hblanks interval
37// 4. PSM_Poll() each tick to advance playback
38//
39// The player allocates voices 0 through (PSM_voiceCount-1) for music.
40// Voices above PSM_voiceCount are available for sound effects.
41
42// Number of hblank ticks between PSM_Poll() calls.
43// Updated when the song contains tempo changes.
45
46// Maximum voices used for music playback (default 16, set before PSM_LoadSong).
47extern unsigned PSM_voiceCount;
48
49// Current event index (read-only, for display/debugging).
51
52// Total event count in current song.
54
55// 1 if playback is active, 0 if stopped/finished.
56extern int PSM_playing;
57
58// Load a combined VAB file (VH header + VB sample body in one buffer).
59// Parses the header, program/tone tables, and DMA uploads all VAG
60// sample data to SPU RAM starting at 0x1010.
61// Returns the number of programs, or 0 on failure.
62unsigned PSM_LoadBank(const void* vabData, uint32_t vabSize);
63
64// Load a VAB with separate VH (header) and VB (sample body) buffers.
65// The VB buffer contains only the raw concatenated VAG ADPCM data and
66// can be freed after this call returns - it is DMA'd to SPU RAM during
67// loading. If vbData is NULL, samples are assumed to already be in SPU
68// RAM (e.g. from a previous call).
69// Returns the number of programs, or 0 on failure.
70unsigned PSM_LoadBankEx(const void* vhData, uint32_t vhSize,
71 const void* vbData, uint32_t vbSize);
72
73// Load a PSM event stream for playback. Must be called after PSM_LoadBank.
74// Returns the event count, or 0 on failure.
75uint32_t PSM_LoadSong(const void* psmData, uint32_t psmSize);
76
77// Advance playback by one tick. Call this at the rate indicated by PSM_hblanks.
78void PSM_Poll(void);
79
80// Stop all playback and silence all voices.
81void PSM_Silence(void);
unsigned PSM_voiceCount
Definition psmplayer.c:288
void PSM_Silence(void)
Definition psmplayer.c:882
uint32_t PSM_hblanks
Definition psmplayer.c:287
unsigned PSM_LoadBank(const void *vabData, uint32_t vabSize)
Definition psmplayer.c:525
uint32_t PSM_eventCount
Definition psmplayer.c:290
unsigned PSM_LoadBankEx(const void *vhData, uint32_t vhSize, const void *vbData, uint32_t vbSize)
Definition psmplayer.c:544
uint32_t PSM_currentEvent
Definition psmplayer.c:289
void PSM_Poll(void)
Definition psmplayer.c:838
int PSM_playing
Definition psmplayer.c:291
uint32_t PSM_LoadSong(const void *psmData, uint32_t psmSize)
Definition psmplayer.c:572
void uint32_t(classId, spec)