Nugget
Loading...
Searching...
No Matches
spdplayer.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// Once SPD_Load returns, these values will be valid.
32extern unsigned SPD_VoiceCount;
33extern unsigned SPD_OrderCount;
34extern unsigned SPD_CurrentOrder;
35extern unsigned SPD_PatternCount;
36extern unsigned SPD_SampleCount;
37
38// Indicates the number of hblank ticks to wait before
39// calling SPD_Poll. This value may change after a call
40// to SPD_Poll if the stream contains a tick rate change.
42
43// Validates an SPUDUMP file. Returns 1 if valid, 0 if not.
44unsigned SPD_Check(const void* data, uint32_t size);
45
46// Loads the specified SPUDUMP file and gets it ready for
47// playback. Uploads sample data to SPU RAM and parses the
48// order table and pattern offsets. Returns the voice count,
49// or 0 if the file is invalid.
50unsigned SPD_Load(const void* data, uint32_t size);
51
52// Loads the specified SPUDUMP file with separate sample data.
53// The sampleData pointer contains the raw sample data file
54// (a standalone SPUDUMP file containing only sample directory
55// and sample data packets). The sampleData buffer can be freed
56// after this call returns, as it is DMA'd to SPU RAM during
57// loading. If sampleData is NULL, the function assumes samples
58// are already loaded in SPU RAM (e.g. from a previous call).
59// Returns the voice count, or 0 if invalid.
60unsigned SPD_LoadEx(const void* data, uint32_t size,
61 const void* sampleData, uint32_t sampleSize);
62
63// Call this function periodically to play sound. The
64// frequency at which this is called is determined by the
65// tick rate embedded in the file. Use SPD_hblanks with
66// timer1's hblank counter to determine when to call next.
67// To pause playback, simply stop calling this function.
68void SPD_Poll();
69
70// Seek to a specific order position. The pattern at the
71// given order is entered cold using its SPU state snapshot.
72// Playback continues from the start of that pattern on the
73// next call to SPD_Poll.
74void SPD_Seek(unsigned order);
75
76// These are fine to change outside of SPD_Poll.
77// SPD_ChangeOrderNextTick is a boolean; SPD_NextOrder is
78// the target order index. Setting the boolean causes the
79// player to jump to the specified order on the next tick.
81extern unsigned SPD_NextOrder;
82
83// Set master volume (0-65535). Defaults to 16384.
84// Not reset by subsequent SPD_Load calls.
85void SPD_SetMasterVolume(uint32_t volume);
86
87// Play a sound effect on a spare voice (above SPD_VoiceCount).
88// The pitch is a raw SPU sample rate register value (0x1000 = 44100 Hz).
89// Volume is 0-16383. The voice must be >= SPD_VoiceCount.
90void SPD_PlaySoundEffect(unsigned voice, unsigned sampleID, uint16_t pitch, int16_t volume);
91
92// Stop all playback and reset the SPU.
93void SPD_Silence();
void SPD_PlaySoundEffect(unsigned voice, unsigned sampleID, uint16_t pitch, int16_t volume)
Definition spdplayer.c:525
int SPD_ChangeOrderNextTick
Definition spdplayer.c:82
unsigned SPD_Check(const void *data, uint32_t size)
Definition spdplayer.c:253
void SPD_Silence()
Definition spdplayer.c:549
unsigned SPD_NextOrder
Definition spdplayer.c:83
unsigned SPD_OrderCount
Definition spdplayer.c:77
void SPD_SetMasterVolume(uint32_t volume)
Definition spdplayer.c:519
uint32_t SPD_hblanks
Definition spdplayer.c:81
unsigned SPD_CurrentOrder
Definition spdplayer.c:78
unsigned SPD_PatternCount
Definition spdplayer.c:79
unsigned SPD_SampleCount
Definition spdplayer.c:80
void SPD_Poll()
Definition spdplayer.c:455
void SPD_Seek(unsigned order)
Definition spdplayer.c:420
unsigned SPD_VoiceCount
Definition spdplayer.c:76
unsigned SPD_Load(const void *data, uint32_t size)
Definition spdplayer.c:411
unsigned SPD_LoadEx(const void *data, uint32_t size, const void *sampleData, uint32_t sampleSize)
Definition spdplayer.c:415
static int size
Definition string.h:32
void uint32_t(classId, spec)