Nugget
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
modplayer.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2021 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 MOD_Load returns, these values will be valid.
32// Unless specified, consider them read only, but
33// modifying them might be doable if you know what you are doing.
34extern unsigned MOD_Channels;
35extern unsigned MOD_SongLength;
36extern unsigned MOD_CurrentOrder;
37extern unsigned MOD_CurrentPattern;
38extern unsigned MOD_CurrentRow;
39extern unsigned MOD_Speed;
40extern unsigned MOD_Tick;
41extern unsigned MOD_BPM;
42extern unsigned MOD_LoopStart;
43extern unsigned MOD_LoopCount;
44extern uint8_t MOD_PatternDelay;
45
46// This is a pointer to the current row that's
47// being played. Used for decoding. The number
48// of relevant bytes for a row is 4 * MOD_Channels.
49extern const uint8_t* MOD_RowPointer;
50
51// These four are fine to change outside of MOD_Poll.
52// The first two are booleans, and the next two are the values
53// you need them to be set at when MOD_Poll is called next.
54// If you need immediate row / pattern change, also set
55// MOD_Tick to MOD_Speed.
56extern int MOD_ChangeRowNextTick;
58extern unsigned MOD_NextRow;
59extern unsigned MOD_NextOrder;
60
61// This can be used to decode MOD_RowPointer.
62extern const uint16_t MOD_PeriodTable[];
63
64// Internal HIT file structure, but conformant to
65// http://www.aes.id.au/modformat.html
66struct MODFileFormat;
67
68// Returns the number of channel from this module,
69// or 0 if the module is invalid.
70unsigned MOD_Check(const struct MODFileFormat* module);
71
72// Loads the specified module and gets it ready for
73// playback. Returns the number of bytes needed if
74// relocation is desired. The pointer has to be
75// aligned to a 4-bytes boundary. Will also setup
76// the SPU.
77uint32_t MOD_Load(const struct MODFileFormat* module);
78
79// Loads the specified module and gets it ready for
80// playback. The pointers have to be aligned to a
81// 4-bytes boundary. Will also setup the SPU. This
82// call is meant to be used with the separate .smp
83// file, which the new modconv.exe tool can generate.
84// Returns the number of channels from the module,
85// or 0 if the module is invalid. No relocation is
86// needed, and the sampleData pointer can simply be
87// freed after this call. If sampleData is NULL, the
88// function considers the samples are already loaded
89// in the SPU.
90unsigned MOD_LoadEx(const struct MODFileFormat* module, const uint8_t* sampleData);
91
92// Call this function periodically to play sound. The
93// frequency at which this is called will determine the
94// actual playback speed of the module. Most modules will
95// not change the default tempo, which requires calling
96// MOD_Poll 50 times per second, or exactly the vertical
97// refresh rate in PAL. Preferably call this from timer1's
98// IRQ however, and look up MOD_hblanks to decide of the
99// next target value to use.
100// To pause or stop playback, simply stop calling this
101// function. The internal player doesn't need any
102// sort of cleanup, and switching to another song simply
103// requires calling MOD_Load with a new file.
104void MOD_Poll();
105
106// New APIs from the original code from there on.
107
108// Defaults to 0. This is a boolean indicating if we
109// want the volume settings to be monaural or the same
110// as the original Amiga's Paula chip.
111extern int MOD_Stereo;
112
113// Indicates the number of hblank ticks to wait before
114// calling MOD_Poll. This value may or may not change
115// after a call to MOD_Poll, if the track requested a
116// tempo change.
117extern uint32_t MOD_hblanks;
118
119// It is possible to reclaim memory from the initial call
120// to MOD_Load, in case the module was loaded from an
121// external source. The number of bytes needed for the
122// player will be returned by MOD_Load. Call MOD_Relocate
123// with a new memory buffer that has at least this many bytes.
124// Caller is responsible for managing the memory.
125// It is fine to reuse the same buffer as the original input,
126// if you wish to simply realloc it after relocating it,
127// provided your realloc implementation guarantees that the
128// shrunk buffer will remain at the same location.
129//
130// For example, this pseudo-code is valid:
131// bool load_mod_file(File mod_file) {
132// void * buffer = malloc(file_size(mod_file));
133// readfile(mod_file, buffer);
134// uint32_t size = MOD_Load(buffer);
135// if (size == 0) {
136// free(buffer);
137// return false;
138// }
139// MOD_Relocate(buffer);
140// void * newbuffer = realloc(buffer, size);
141// if (newbuffer != buffer) {
142// free(newbuffer);
143// return false;
144// }
145// return true;
146// }
147void MOD_Relocate(uint8_t* buffer);
148
149// Set MOD Volume to musicVolume, where musicVolume is between 0 and 65535.
150// Defaults to 16384, and won't be reset by a subsequent MOD_Load, as it
151// behaves as a master music volume throughout the lifetime of the app.
152void MOD_SetMusicVolume(uint32_t musicVolume);
153
154// Plays an arbitrary note from the MOD's samples bank.
155// The volume will always be centered, so the sample will
156// be monaural. The voiceID ideally should be set to a
157// value that is above MOD_Channels. Remember the PS1
158// has 24 channels total, so voiceID can be between 0 and 23.
159// The note is a value between 0 and 35. The exact note played
160// is on the normal 12-notes, C, C#, D, ... scale, and there
161// are three octaves available, which gives the 12*3=36
162// interval value of the note argument. The volume argument
163// is between 0 and 63. You can simulate KeyOff by simply
164// setting the volume of the voice to 0. The volume will
165// be affected by the music volume as set by the function above.
166void MOD_PlayNote(unsigned voiceID, unsigned sampleID, unsigned note, int16_t volume);
167
168// Plays a sound effect.
169// As opposed to MOD_PlayNote(), MOD_PlaySoundEffect()'s volume
170// won't be affected by the global volume setting.
171// 0 == mute, 63 == max SPU voice volume
172void MOD_PlaySoundEffect(unsigned channel, unsigned sampleID, unsigned note, int16_t volume);
173
174// Added API to reset the SPU and silence everything.
175void MOD_Silence();
void MOD_Relocate(uint8_t *buffer)
Definition modplayer.c:293
unsigned MOD_LoopCount
Definition modplayer.c:187
int MOD_ChangeRowNextTick
Definition modplayer.c:181
unsigned MOD_CurrentRow
Definition modplayer.c:172
unsigned MOD_Tick
Definition modplayer.c:174
uint8_t MOD_PatternDelay
Definition modplayer.c:185
void MOD_Silence()
Definition modplayer.c:286
void MOD_Poll()
Definition modplayer.c:778
unsigned MOD_LoadEx(const struct MODFileFormat *module, const uint8_t *sampleData)
Definition modplayer.c:281
int MOD_ChangeOrderNextTick
Definition modplayer.c:183
int MOD_Stereo
Definition modplayer.c:188
const uint16_t MOD_PeriodTable[]
Definition modplayer.c:322
const uint8_t * MOD_RowPointer
Definition modplayer.c:180
void MOD_SetMusicVolume(uint32_t musicVolume)
Definition modplayer.c:826
unsigned MOD_NextRow
Definition modplayer.c:182
unsigned MOD_Check(const struct MODFileFormat *module)
Definition modplayer.c:155
void MOD_PlaySoundEffect(unsigned channel, unsigned sampleID, unsigned note, int16_t volume)
Definition modplayer.c:819
unsigned MOD_CurrentPattern
Definition modplayer.c:171
unsigned MOD_Speed
Definition modplayer.c:173
void MOD_PlayNote(unsigned voiceID, unsigned sampleID, unsigned note, int16_t volume)
Definition modplayer.c:805
unsigned MOD_NextOrder
Definition modplayer.c:184
unsigned MOD_CurrentOrder
Definition modplayer.c:170
uint32_t MOD_Load(const struct MODFileFormat *module)
Definition modplayer.c:279
unsigned MOD_BPM
Definition modplayer.c:177
unsigned MOD_LoopStart
Definition modplayer.c:186
uint32_t MOD_hblanks
Definition modplayer.c:189
unsigned MOD_SongLength
Definition modplayer.c:166
unsigned MOD_Channels
Definition modplayer.c:165
Definition modplayer.c:50
static void * buffer
Definition syscalls.h:230
void uint32_t(classId, spec)