-
Notifications
You must be signed in to change notification settings - Fork 5
/
syna.h
255 lines (210 loc) · 6.88 KB
/
syna.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* Synaesthesia - program to display sound graphically
Copyright (C) 1997 Paul Francis Harrison
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 2 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.,
675 Mass Ave, Cambridge, MA 02139, USA.
The author may be contacted at:
or
27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
*/
#include "config.h"
#include "polygon.h"
/***************************************/
/* For the incurably fiddle prone: */
/* log2 of sample size */
#if defined(WINAMP) || defined(AUDACIOUS)
#define LogSize 9 // Winamp only gives 576, Audacious 512
#else
#define LogSize 10 //was 9
#endif
/* Brightness */
#define Brightness 150
/* Sample frequency*/
#if defined(WINAMP) || defined(AUDACIOUS)
#define Frequency 44100
#else
#define Frequency 22050
#endif
#define DefaultWidth 400
#define DefaultHeight 400
/***************************************/
#define NumSamples (1<<LogSize)
#define RecSize (1<<LogSize-Overlap)
#ifdef __FreeBSD__
typedef unsigned short sampleType;
#elif defined(EMSCRIPTEN) || defined(AUDACIOUS)
typedef float sampleType;
#else
typedef short sampleType;
#if !defined(__linux__) && !defined(WIN32)
#warning This target has not been tested!
#endif
#endif
#if !defined(BIGENDIAN) && !defined(LITTLEENDIAN)
#ifdef __FreeBSD__
#include <machine/endian.h>
#else
#include <endian.h>
#endif
#if BYTE_ORDER == BIG_ENDIAN
#define BIGENDIAN
#else
#define LITTLEENDIAN
#endif
#endif /* !defined(BIGENDIAN) && !defined(LITTLEENDIAN) */
#if !defined(HAVE_PORTAUDIO) && !defined(WIN32) && !defined(HAVE_SDLAUDIO)
#define HAVE_PLAYBACK
#endif
#ifdef HAVE_PORTAUDIO
#ifdef WIN32
#define MONITOR_NAME "Stereo Mix"
#elif defined(__linux__)
#define MONITOR_NAME "pulse_monitor"
#endif
#endif /* HAVE_PORTAUDIO */
#if defined(HAVE_PORTAUDIO) || defined(HAVE_SDLAUDIO)
#define HAVE_FPS
#endif
void error(const char *str,bool syscall=false);
void inline attempt(int x,const char *y,bool syscall=false) { if (x == -1) error(y,syscall); }
void warning(const char *str,bool syscall=false);
void inline attemptNoDie(int x,const char *y,bool syscall=false) { if (x == -1) warning(y,syscall); }
/* *wrap */
#define SYN_DBL_CLICK (1 << 30)
struct BaseScreen {
virtual bool init(int xHint, int yHint, int widthHint, int heightHint,
bool fullscreen, int depth = 8) = 0;
virtual void setPalette(unsigned char *palette) = 0;
virtual void end() = 0;
virtual void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit) = 0;
virtual void show() = 0;
virtual void toggleFullScreen() { }
virtual int getDepth() { return 8; }
virtual void getPixelFormat(int *rshift, unsigned long *rmask,
int *gshift, unsigned long *gmask,
int *bshift, unsigned long *bmask,
int *ashift, unsigned long *amask) = 0;
};
struct SdlScreen : public BaseScreen {
bool init(int xHint, int yHint, int widthHint, int heightHint,
bool fullscreen, int depth);
void setPalette(unsigned char *palette);
void end();
void inputUpdate(int &mouseX,int &mouseY,int &mouseButtons,char &keyHit);
void show();
void toggleFullScreen();
int getDepth();
void getPixelFormat(int *rshift, unsigned long *rmask,
int *gshift, unsigned long *gmask,
int *bshift, unsigned long *bmask,
int *ashift, unsigned long *amask);
};
/* core */
extern BaseScreen *screen;
extern sampleType *data;
extern Bitmap<unsigned short> outputBmp, lastOutputBmp, lastLastOutputBmp;
#define output ((unsigned char*)outputBmp.data)
#define lastOutput ((unsigned char*)lastOutputBmp.data)
#define lastLastOutput ((unsigned char*)lastLastOutputBmp.data)
struct Combiner {
static unsigned short combine(unsigned short a,unsigned short b) {
//Not that i want to give the compiler a hint or anything...
unsigned char ah = a>>8, al = a&255, bh = b>>8, bl = b&255;
if (ah < 64) ah *= 4; else ah = 255;
if (al < 64) al *= 4; else al = 255;
if (bh > ah) ah = bh;
if (bl > al) al = bl;
return ah*256+al;
}
};
extern PolygonEngine<unsigned short,Combiner,2> polygonEngine;
extern int outWidth, outHeight;
void allocOutput(int w,int h);
void coreInit(bool logfreq, bool window, bool addsq);
void setStarSize(double size);
int coreGo();
void fade();
/* ui */
void interfaceInit();
void interfaceSyncToState();
void interfaceEnd();
bool interfaceGo();
enum SymbolID {
Speaker, Bulb,
Play, Pause, Stop, SkipFwd, SkipBack,
Handle, Pointer, Open, NoCD, Exit,
Zero, One, Two, Three, Four,
Five, Six, Seven, Eight, Nine,
Slider, Selector, Plug, Loop, Box, Bar,
Flame, Wave, Stars, Star, Diamond, Size, FgColor, BgColor,
Save, Reset, TrackSelect,
NotASymbol
};
/* State information */
extern SymbolID state;
#ifdef HAVE_CD_PLAYER
extern int track, frames;
extern double trackProgress;
extern char **playList;
extern int playListLength, playListPosition;
#endif /* HAVE_CD_PLAYER */
extern SymbolID fadeMode;
extern bool pointsAreDiamonds;
extern double brightnessTwiddler;
extern double starSize;
extern double fgRedSlider, fgGreenSlider, bgRedSlider, bgGreenSlider;
extern double volume;
void setStateToDefaults();
void saveConfig();
void putString(char *string,int x,int y,int red,int blue);
/* sound */
enum SoundSource {
SourceLine,
#ifdef HAVE_CD_PLAYER
SourceCD,
#endif /* HAVE_CD_PLAYER */
#ifdef HAVE_PLAYBACK
SourcePipe,
#endif /* HAVE_PLAYBACK */
#ifdef HAVE_LIBESD
SourceESD,
#endif /* HAVE_LIBESD */
#ifdef MONITOR_NAME
SourceMonitor,
#endif /* MONITOR_NAME */
};
#ifdef HAVE_CD_PLAYER
void cdOpen(char *cdromName);
void cdClose(void);
void cdGetStatus(int &track, int &frames, SymbolID &state);
void cdPlay(int trackFrame, int endFrame=-1);
void cdStop(void);
void cdPause(void);
void cdResume(void);
void cdEject(void);
void cdCloseTray(void);
int cdGetTrackCount(void);
int cdGetTrackFrame(int track);
#endif /* HAVE_CD_PLAYER */
void openSound(SoundSource sound, int downFactor, char *dspName, char *mixerName
#ifdef HAVE_FPS
, unsigned int chunk_size
#endif
);
void closeSound();
void setupMixer(double &loudness);
void setVolume(double loudness);
int getNextFragment(void);
void sndbuf_init(unsigned int min_new_samples);
void sndbuf_store(const sampleType *input, unsigned int len);
void sndbuf_quit(void);
void sdlError(const char *str);