Timing is correct now! Forgot to update samples_per_tick when parsing the 0xf effect.
[pineappletracker.git] / hvl_replay.h
blob9b0687ad3371b359987e69403c64033c2e17e1e7
1 /* AHX originally by Pink/Abyss and bigup Xeron for Hivelytracker! */
3 typedef char int8;
4 typedef unsigned char uint8;
5 typedef short int16;
6 typedef unsigned short uint16;
7 typedef int int32;
8 typedef unsigned int uint32;
9 typedef double float64;
10 typedef char TEXT;
11 typedef int BOOL;
13 #define TRUE 1
14 #define FALSE 0
16 // Woohoo!
17 #define MAX_CHANNELS 16
19 #define Period2Freq(period) ((3546897.f * 65536.f) / (period))
20 #define FREQ 48000
21 #define HIVELY_LEN FREQ/50
22 #define OUTPUT_LEN 4096
24 struct hvl_envelope
26 int16 aFrames, aVolume;
27 int16 dFrames, dVolume;
28 int16 sFrames;
29 int16 rFrames, rVolume;
30 int16 pad;
33 struct hvl_plsentry
35 uint8 ple_Note;
36 uint8 ple_Waveform;
37 int16 ple_Fixed;
38 int8 ple_FX[2];
39 int8 ple_FXParam[2];
42 struct hvl_plist
44 int16 pls_Speed;
45 int16 pls_Length;
46 struct hvl_plsentry *pls_Entries;
49 struct hvl_instrument
51 TEXT ins_Name[128];
52 uint8 ins_Volume;
53 uint8 ins_WaveLength;
54 uint8 ins_FilterLowerLimit;
55 uint8 ins_FilterUpperLimit;
56 uint8 ins_FilterSpeed;
57 uint8 ins_SquareLowerLimit;
58 uint8 ins_SquareUpperLimit;
59 uint8 ins_SquareSpeed;
60 uint8 ins_VibratoDelay;
61 uint8 ins_VibratoSpeed;
62 uint8 ins_VibratoDepth;
63 uint8 ins_HardCutRelease;
64 uint8 ins_HardCutReleaseFrames;
65 struct hvl_envelope ins_Envelope;
66 struct hvl_plist ins_PList;
69 struct hvl_position
71 uint8 pos_Track[MAX_CHANNELS];
72 int8 pos_Transpose[MAX_CHANNELS];
75 struct hvl_step
77 uint8 stp_Note;
78 uint8 stp_Instrument;
79 uint8 stp_FX;
80 uint8 stp_FXParam;
81 uint8 stp_FXb;
82 uint8 stp_FXbParam;
85 struct hvl_voice
87 int16 vc_Track;
88 int16 vc_NextTrack;
89 int16 vc_Transpose;
90 int16 vc_NextTranspose;
91 int16 vc_OverrideTranspose; // 1.5
92 int32 vc_ADSRVolume;
93 struct hvl_envelope vc_ADSR;
94 struct hvl_instrument *vc_Instrument;
95 uint32 vc_SamplePos;
96 uint32 vc_Delta;
97 uint16 vc_InstrPeriod;
98 uint16 vc_TrackPeriod;
99 uint16 vc_VibratoPeriod;
100 uint16 vc_WaveLength;
101 int16 vc_NoteMaxVolume;
102 uint16 vc_PerfSubVolume;
103 uint8 vc_NewWaveform;
104 uint8 vc_Waveform;
105 uint8 vc_PlantPeriod;
106 uint8 vc_VoiceVolume;
107 uint8 vc_PlantSquare;
108 uint8 vc_IgnoreSquare;
109 uint8 vc_FixedNote;
110 int16 vc_VolumeSlideUp;
111 int16 vc_VolumeSlideDown;
112 int16 vc_HardCut;
113 uint8 vc_HardCutRelease;
114 int16 vc_HardCutReleaseF;
115 uint8 vc_PeriodSlideOn;
116 int16 vc_PeriodSlideSpeed;
117 int16 vc_PeriodSlidePeriod;
118 int16 vc_PeriodSlideLimit;
119 int16 vc_PeriodSlideWithLimit;
120 int16 vc_PeriodPerfSlideSpeed;
121 int16 vc_PeriodPerfSlidePeriod;
122 uint8 vc_PeriodPerfSlideOn;
123 int16 vc_VibratoDelay;
124 int16 vc_VibratoSpeed;
125 int16 vc_VibratoCurrent;
126 int16 vc_VibratoDepth;
127 int16 vc_SquareOn;
128 int16 vc_SquareInit;
129 int16 vc_SquareWait;
130 int16 vc_SquareLowerLimit;
131 int16 vc_SquareUpperLimit;
132 int16 vc_SquarePos;
133 int16 vc_SquareSign;
134 int16 vc_SquareSlidingIn;
135 int16 vc_SquareReverse;
136 uint8 vc_FilterOn;
137 uint8 vc_FilterInit;
138 int16 vc_FilterWait;
139 int16 vc_FilterSpeed;
140 int16 vc_FilterUpperLimit;
141 int16 vc_FilterLowerLimit;
142 int16 vc_FilterPos;
143 int16 vc_FilterSign;
144 int16 vc_FilterSlidingIn;
145 int16 vc_IgnoreFilter;
146 int16 vc_PerfCurrent;
147 int16 vc_PerfSpeed;
148 int16 vc_PerfWait;
149 struct hvl_plist *vc_PerfList;
150 int8 *vc_AudioPointer;
151 int8 *vc_AudioSource;
152 uint8 vc_NoteDelayOn;
153 uint8 vc_NoteCutOn;
154 int16 vc_NoteDelayWait;
155 int16 vc_NoteCutWait;
156 int16 vc_AudioPeriod;
157 int16 vc_AudioVolume;
158 int32 vc_WNRandom;
159 int8 *vc_MixSource;
160 int8 vc_SquareTempBuffer[0x80];
161 int8 vc_VoiceBuffer[0x282*4];
162 uint8 vc_VoiceNum;
163 uint8 vc_TrackMasterVolume;
164 uint8 vc_TrackOn;
165 int16 vc_VoicePeriod;
166 uint32 vc_Pan;
167 uint32 vc_SetPan; // New for 1.4
168 uint32 vc_PanMultLeft;
169 uint32 vc_PanMultRight;
170 uint32 vc_RingSamplePos;
171 uint32 vc_RingDelta;
172 int8 *vc_RingMixSource;
173 uint8 vc_RingPlantPeriod;
174 int16 vc_RingInstrPeriod;
175 int16 vc_RingBasePeriod;
176 int16 vc_RingAudioPeriod;
177 int8 *vc_RingAudioSource;
178 uint8 vc_RingNewWaveform;
179 uint8 vc_RingWaveform;
180 uint8 vc_RingFixedPeriod;
181 int8 vc_RingVoiceBuffer[0x282*4];
184 struct hvl_tune
186 char ht_Name[128];
187 uint16 ht_SongNum;
188 uint32 ht_Frequency;
189 float64 ht_FreqF;
190 int8 *ht_WaveformTab[MAX_CHANNELS];
191 uint16 ht_Restart;
192 uint16 ht_PositionNr;
193 uint8 ht_SpeedMultiplier;
194 uint8 ht_TrackLength;
195 uint8 ht_TrackNr;
196 uint8 ht_InstrumentNr;
197 uint8 ht_SubsongNr;
198 uint16 ht_PosJump;
199 uint32 ht_PlayingTime;
200 int16 ht_Tempo;
201 int16 ht_PosNr;
202 int16 ht_StepWaitFrames;
203 int16 ht_NoteNr;
204 uint16 ht_PosJumpNote;
205 uint8 ht_GetNewPosition;
206 uint8 ht_PatternBreak;
207 uint8 ht_SongEndReached;
208 uint8 ht_Stereo;
209 uint16 *ht_Subsongs;
210 uint16 ht_Channels;
211 struct hvl_position *ht_Positions;
212 struct hvl_step ht_Tracks[256][64];
213 struct hvl_instrument *ht_Instruments;
214 struct hvl_voice ht_Voices[MAX_CHANNELS];
215 int32 ht_defstereo;
216 int32 ht_defpanleft;
217 int32 ht_defpanright;
218 int32 ht_mixgain;
219 uint8 ht_Version;
220 //added for pineappletracker
221 uint8 curNote;
222 uint8 curInstr;
223 int16 hivelyLeft[HIVELY_LEN], hivelyRight[HIVELY_LEN];
226 void hvl_DecodeFrame( struct hvl_tune *ht, int8 *buf1, int8 *buf2, int32 bufmod );
227 void hvl_InitReplayer( void );
228 BOOL hvl_InitSubsong( struct hvl_tune *ht, uint32 nr );
229 struct hvl_tune *hvl_LoadTune( TEXT *name, uint32 freq, uint32 defstereo );
230 void hvl_FreeTune( struct hvl_tune *ht );
232 void hvl_process_step( struct hvl_tune *ht, struct hvl_voice *voice );
233 void hvl_process_frame( struct hvl_tune *ht, struct hvl_voice *voice );
234 void hvl_set_audio( struct hvl_voice *voice, float64 freqf );
235 //void hvl_playNote(struct hvl_tune *ht, int8 *buf1, int8 *buf2, int32 bufmod, struct hvl_voice *voice);
236 void hvl_iedplonk(int note, int instr, void *t);
238 void hvl_play_irq( struct hvl_tune *ht );
239 void hvl_mixchunk( struct hvl_tune *ht, uint32 samples, int8 *buf1, int8 *buf2, int32 bufmod );
241 struct hvl_tune *htTune;
243 void hvlSdlCallBack( struct hvl_tune *ht, uint8 *stream, int length );
246 //int16 hivelyLeft[HIVELY_LEN], hivelyRight[HIVELY_LEN];
247 int hivelyIndex;
249 //int play;
250 //int plonked;