PokittoSound.h
Go to the documentation of this file.
1 /**************************************************************************/
35 /**************************************************************************/
36 
37 
38 #ifndef POKITTOSOUND_H
39 #define POKITTOSOUND_H
40 
41 #include <stdint.h>
42 #include "Pokitto_settings.h"
43 #include "GBcompatibility.h"
44 #include "PokittoFakeavr.h"
45 #include "PokittoGlobs.h"
46 
47 extern void pokPauseStream();
48 extern void pokPlayStream();
49 extern uint8_t pokStreamPaused();
50 
51 //volume levels
52 #define GLOBVOL_SHIFT 5 //shift global volume to allow for finer increments
53 #ifndef MAX_VOL_TEST
54  #define VOLUME_SPEAKER_MAX 255 //((8<<GLOBVOL_SHIFT)-1)
55  #define VOLUME_HEADPHONE_MAX (1<<GLOBVOL_SHIFT)
56  #define VOLUME_STARTUP ((1<<GLOBVOL_SHIFT)/2)
57 #else
58  #define VOLUME_SPEAKER_MAX ((8<<GLOBVOL_SHIFT)-1)
59  #define VOLUME_HEADPHONE_MAX VOLUME_SPEAKER_MAX
60  #define VOLUME_STARTUP VOLUME_SPEAKER_MAX
61 #endif // MAXVOLTEST
62 
63 #ifdef POK_SIM
64 #define VOLUME_STEP 1
65 #else
66 #define VOLUME_STEP 8
67 #endif
68 
69 
70 //commands
71 #define CMD_VOLUME 0
72 #define CMD_INSTRUMENT 1
73 #define CMD_SLIDE 2
74 #define CMD_ARPEGGIO 3
75 #define CMD_TREMOLO 4
76 
77 #define STR_PLAYING 0x1
78 #define STR_VISUALIZER 0x2
79 #define STR_LOOP 0x4
80 #define STR_PAUSED 0x8
81 
82 namespace Pokitto {
83 
92 extern void audio_IRQ(); // audio interrupt
93 
94 class Sound {
95 private:
96  static uint16_t volumeMax;
97 public:
98  static void begin();
99 
100  // Headphonemode
101  static void setMaxVol(int16_t);
102  static uint16_t getMaxVol();
103  static void volumeUp();
104  static void volumeDown();
105 
106  // Original functions
107  static void updateStream();
108  static void playTone(uint8_t os, int frq, uint8_t amp, uint8_t wav,uint8_t arpmode);
109  static void playTone(uint8_t os, uint16_t freq, uint8_t volume, uint32_t duration);
110  static uint8_t ampIsOn();
111  static void ampEnable(uint8_t);
112  static int playMusicStream(char* filename, uint8_t options);
113  static int playMusicStream(char* filename);
114  static int playMusicStream();
115  static void pauseMusicStream();
116 
117  // GB compatibility functions
118  static void playTrack(const uint16_t* track, uint8_t channel);
119  static void updateTrack(uint8_t channel);
120  static void updateTrack();
121  static void stopTrack(uint8_t channel);
122  static void stopTrack();
123  static void changePatternSet(const uint16_t* const* patterns, uint8_t channel);
124  static bool trackIsPlaying[NUM_CHANNELS];
125 
126  static void playPattern(const uint16_t* pattern, uint8_t channel);
127  static void changeInstrumentSet(const uint16_t* const* instruments, uint8_t channel);
128  static void updatePattern(uint8_t i);
129  static void updatePattern();
130  static void setPatternLooping(bool loop, uint8_t channel);
131  static void stopPattern(uint8_t channel);
132  static void stopPattern();
133  static bool patternIsPlaying[NUM_CHANNELS];
134 
135  static void command(uint8_t cmd, uint8_t X, int8_t Y, uint8_t i);
136  static void playNote(uint8_t pitch, uint8_t duration, uint8_t channel);
137  static void updateNote();
138  static void updateNote(uint8_t i);
139  static void stopNote(uint8_t channel);
140  static void stopNote();
141 
142  static uint8_t outputPitch[NUM_CHANNELS];
143  static int8_t outputVolume[NUM_CHANNELS];
144 
145  static void setMasterVolume(uint8_t);
146  static uint8_t GetMasterVolume();
147  static void setVolume(int16_t volume);
148  static uint16_t getVolume();
149  static void setVolume(int8_t volume, uint8_t channel);
150  static uint8_t getVolume(uint8_t channel);
151 
152  static void playOK();
153  static void playCancel();
154  static void playTick();
155 
156  static uint8_t prescaler;
157 
158  static void setChannelHalfPeriod(uint8_t channel, uint8_t halfPeriod);
159 
160  static void generateOutput();
161  static uint16_t globalVolume;
162 
163 
164 #if (NUM_CHANNELS > 0)
165  //tracks data
166  static uint16_t *trackData[NUM_CHANNELS];
167  static uint8_t trackCursor[NUM_CHANNELS];
168  static uint16_t **patternSet[NUM_CHANNELS];
169  static int8_t patternPitch[NUM_CHANNELS];
170 
171  // pattern data
172  static uint16_t *patternData[NUM_CHANNELS];
173  static uint16_t **instrumentSet[NUM_CHANNELS];
174  static bool patternLooping[NUM_CHANNELS];
175  static uint16_t patternCursor[NUM_CHANNELS];
176 
177  // note data
178  static uint8_t notePitch[NUM_CHANNELS];
179  static uint8_t noteDuration[NUM_CHANNELS];
180  static int8_t noteVolume[NUM_CHANNELS];
181  static bool notePlaying[NUM_CHANNELS];
182 
183  // commands data
184  static int8_t commandsCounter[NUM_CHANNELS];
185  static int8_t volumeSlideStepDuration[NUM_CHANNELS];
186  static int8_t volumeSlideStepSize[NUM_CHANNELS];
187  static uint8_t arpeggioStepDuration[NUM_CHANNELS];
188  static int8_t arpeggioStepSize[NUM_CHANNELS];
189  static uint8_t tremoloStepDuration[NUM_CHANNELS];
190  static int8_t tremoloStepSize[NUM_CHANNELS];
191 
192 
193  // instrument data
194  static uint16_t *instrumentData[NUM_CHANNELS];
195  static uint8_t instrumentLength[NUM_CHANNELS]; //number of steps in the instrument
196  static uint8_t instrumentLooping[NUM_CHANNELS]; //how many steps to loop on when the last step of the instrument is reached
197  static uint16_t instrumentCursor[NUM_CHANNELS]; //which step is being played
198  static uint8_t instrumentNextChange[NUM_CHANNELS]; //how many frames before the next step
199 
200  //current step data
201  static int8_t stepVolume[NUM_CHANNELS];
202  static uint8_t stepPitch[NUM_CHANNELS];
203 
204  static uint8_t chanVolumes[NUM_CHANNELS];
205 #endif
206  static void updateOutput();
207 };
208 
209 }
210 
211 #endif // POKITTOSOUND_H
212 
213 
214 
215 
216 
Definition: PokittoBacklight.h:42
Definition: PokittoSound.h:94
static uint16_t globalVolume
\ DO NOT USE
Definition: PokittoSound.h:161