NXEngine v1.0.0.3
[NXEngine.git] / sound / org.h
blob2cf25aa7cb5d0c32f67cb2f1faffe5ca655f771a
2 #ifndef _ORG_H
3 #define _ORG_H
5 // SSChannel # to play the music on
6 #define ORG_CHANNEL 15
8 // maximum possible volume of an org instrument (in the file)
9 // i hear according to orgmaker you can't go higher than F8 but a few
10 // songs actually do go all the way to FF.
11 #define ORG_MAX_VOLUME 255
13 // which panning value is perfectly centered
14 #define ORG_PAN_CENTERED 6
15 #define ORG_PAN_FULL_RIGHT (ORG_PAN_CENTERED + ORG_PAN_CENTERED)
17 #define KEYS_OCTAVE 12
18 #define NUM_NOTES (8 * KEYS_OCTAVE) // range of note values: 00-this.
19 #define NUM_DRUMS 12 // max # of drum instruments to load
21 // if you care to know which music note an org note is, modulus it by
22 // KEYS_OCTAVE and compare to the following constants.
23 #define NOTE_C 0
24 #define NOTE_CS 1
25 #define NOTE_D 2
26 #define NOTE_DS 3
27 #define NOTE_E 4
28 #define NOTE_F 5
29 #define NOTE_FS 6
30 #define NOTE_G 7
31 #define NOTE_GS 8
32 #define NOTE_A 9
33 #define NOTE_AS 10
34 #define NOTE_B 11
36 #define MAX_SONG_LENGTH 5000 // max song length to allocate for, in notes
39 // this handles the actual synthesis
40 struct stNoteChannel
42 signed short *outbuffer;
44 // position inside outbuffer (not the same as samples_so_far because org module outputs stereo.
45 // outpos counts data, samples_so_far counts samples. samples_so_far=outpos*2)
46 int outpos; // incs by 2 for each samples_so_far, one for left ch one for right ch
47 int samples_so_far; // number of samples generated so far into outbuffer
49 double phaseacc; // current read position inside wavetable sample
50 double sample_inc; // speed at which to iterate over the wavetable waveform
52 // for drums
53 double master_volume_ratio, volume_left_ratio, volume_right_ratio;
55 int wave; // index into wavetable (which instrument we're using)
56 int volume; // last volume value sent to note_gen
57 int panning; // last panning value sent to note_gen
58 int length; // # of beats of the current note left to generate
60 int number; // the chanel number of this channel
64 struct stNote
66 int beat; // beat no. that note starts on
67 uchar note; // 00 - 5F, starts on a C
68 uchar length; // in beats
69 uchar volume; // 00 - F8
70 uchar panning; // 00 - 0C
73 // keeps track of instrument settings for a track
74 struct stInstrument
76 int pitch;
77 int wave; // which wave (00-99) to use
78 // if pi is set all notes on the channel play for 1024 samples regardless
79 // of length or tempo settings. pi only has meaning on the instrument tracks.
80 bool pi;
82 int curnote; // current note (during playback)
83 int loop_note; // used when looping back to the beginning of a song at beat loop_end
85 int nnotes;
86 stNote note[MAX_SONG_LENGTH];
89 struct stSong
91 bool playing;
92 int volume;
94 int ms_per_beat, ms_of_last_beat_of_note;
95 int beats_per_step;
96 int steps_per_bar;
97 int beats_per_bar; // == (beats_per_step * steps_per_bar)
99 int samples_per_beat; // # of samples in each beat
100 int note_closing_samples; // # of samples of note to generate at the last beat of a note
102 int loop_start, loop_end;
104 stInstrument instrument[16];
106 int beat;
107 char haslooped;
109 bool fading;
110 uint32_t last_fade_time;
113 #endif