-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsoundplayer.h
133 lines (120 loc) · 5.06 KB
/
soundplayer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Colditz Escape - Rewritten Engine for "Escape From Colditz"
* copyright (C) 2008-2017 Aperture Software
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ---------------------------------------------------------------------------
* soundplayer.h: header for Colditz MOD and SFX audio engine
* ---------------------------------------------------------------------------
*/
#pragma once
// This #define is used to convert an Amiga period number to a frequency.
// The frequency returned is the frequency that the sample should be played at.
// 3579545.25f / 428 = 8363.423 Hz for Middle C (PAL)
#define Period2Freq(period) (3579545.25f / (period))
// These next few lines determine how the sound will be mixed.
// Set PLAYBACK_FREQ to whatever you want.
#define PLAYBACK_FREQ 44100
// OVERSAMPLE can be commented out to disable that function
// (takes up less CPU time, but doesnt sound as good).
#define OVERSAMPLE
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
// The NoteData structure stores the information for a single note and/or effect.
typedef struct {
int sample_num; // The sample number (ie "instrument") to play, 1->31
int period_index; // This effectively stores the frequency to play the
// sample, although it's actually an index into
// PeriodTable.
int effect; // Contains the effect code
int effect_parms; // Used to store control parameters for the
// various effects
} NoteData;
// RowData stores all the information for a single row. If there are 8 tracks
// in this mod then this structure will be filled with 8 elements of NoteData,
// one for each track.
typedef struct {
int numnotes;
NoteData *note;
} RowData;
// Pattern contains all the information for a single pattern.
// It is filled with 64 elements of type RowData.
typedef struct {
int numrows;
RowData *row;
} Pattern;
// The Sample structure is used to store all the information for a single
// sample, or "instrument". Most of the member's should be self-explanatory.
// The "data" member is an array of bytes containing the raw sample data
// in 8-bit signed format.
typedef struct {
char szName[100];
int nLength, nFineTune, nVolume, nLoopStart, nLoopLength, nLoopEnd;
int data_length;
char *data;
} Sample;
// TrackData is used to store ongoing information about a particular track.
typedef struct {
int sample; // The current sample being played (0 for none)
int pos; // The current playback position in the sample,
// stored in fixed-point format
int period_index; // Which note to play, stored as an index into the
// PeriodTable array
int period; // The period number that period_index corresponds to
// (needed for various effects)
float freq; // This is the actual frequency used to do the mixing.
// It's a combination of the value calculated from the
// period member and an "adjustment" made by various effects.
int volume; // Volume that this track is to be mixed at
int mixvol; // This is the actual volume used to do the mixing.
// It's a combination of the volume member and an
// "adjustment" made by various effects.
int porta; // Used by the porta effect, this stores the note we're
// porta-ing (?) to
int portasp; // The speed at which to porta
int vibspe; // Vibrato speed
int vibdep; // Vibrato depth
int tremspe; // Tremolo speed
int tremdep; // Tremolo depth
int panval; // Pan value....this player doesn't actually do panning,
// so this member is ignored (but included for future use)
int sinepos; // These next two values are pointers to the sine table.
// They're used to do
int sineneg; // various effects.
} TrackData;
// Function prototypes
bool audio_init();
bool audio_release();
bool mod_init(char *filename);
void mod_release();
bool mod_play();
bool is_mod_playing();
void mod_pause();
bool mod_stop();
bool play_sample(int channel, unsigned int volume, void *address, unsigned int length,
unsigned int frequency, unsigned int bits_per_sample, bool loop);
bool play_loop(unsigned int volume, void *address, unsigned int length,
unsigned int frequency, unsigned int bits_per_sample);
void stop_loop();
#if defined(PSP)
bool psp_upsample(short **dst_address, unsigned long *dst_length, char *src_sample,
unsigned long src_numsamples, unsigned short src_frequency);
#endif
#ifdef __cplusplus
}
#endif