1 /* Synaesthesia - program to display sound graphically
2 Copyright (C) 1997 Paul Francis Harrison
3 Copyright (C) 2009 RafaĆ Rzepecki <divided.mind@gmail.com>
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The author may be contacted at:
20 phar6@student.monash.edu.au
22 27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
29 /***************************************/
30 /* For the incurably fiddle prone: */
32 /* log2 of sample size */
33 #define LogSize 10 //was 9
36 #define Brightness 150
39 #define Frequency 22050
41 #define DefaultWidth 200
42 #define DefaultHeight 200
44 /***************************************/
46 #define NumSamples (1<<LogSize)
47 #define RecSize (1<<LogSize-Overlap)
51 typedef unsigned short sampleType
;
55 typedef short sampleType
;
59 #warning This target has not been tested!
65 #include <machine/endian.h>
70 #if BYTE_ORDER == BIG_ENDIAN
76 void error(char *str
,bool syscall
=false);
77 void inline attempt(int x
,char *y
,bool syscall
=false) { if (x
== -1) error(y
,syscall
); }
78 void warning(char *str
,bool syscall
=false);
79 void inline attemptNoDie(int x
,char *y
,bool syscall
=false) { if (x
== -1) warning(y
,syscall
); }
83 virtual bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
) = 0;
84 virtual void setPalette(unsigned char *palette
) = 0;
85 virtual void end() = 0;
86 virtual void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
) = 0;
87 virtual void show() = 0;
88 virtual void toggleFullScreen() { }
91 struct SvgaScreen
: public BaseScreen
{
92 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
93 void setPalette(unsigned char *palette
);
95 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
99 struct RawScreen
: public BaseScreen
{
100 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
101 void setPalette(unsigned char *palette
);
103 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
107 struct SdlScreen
: public BaseScreen
{
108 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
109 void setPalette(unsigned char *palette
);
111 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
113 void toggleFullScreen();
116 struct XScreen
: public BaseScreen
{
117 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
118 void setPalette(unsigned char *palette
);
120 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
125 extern BaseScreen
*screen
;
126 extern sampleType
*data
;
127 extern Bitmap
<unsigned short> outputBmp
, lastOutputBmp
, lastLastOutputBmp
;
128 #define output ((unsigned char*)outputBmp.data)
129 #define lastOutput ((unsigned char*)lastOutputBmp.data)
130 #define lastLastOutput ((unsigned char*)lastLastOutputBmp.data)
133 static unsigned short combine(unsigned short a
,unsigned short b
) {
134 //Not that i want to give the compiler a hint or anything...
135 unsigned char ah
= a
>>8, al
= a
&255, bh
= b
>>8, bl
= b
&255;
136 if (ah
< 64) ah
*= 4; else ah
= 255;
137 if (al
< 64) al
*= 4; else al
= 255;
138 if (bh
> ah
) ah
= bh
;
139 if (bl
> al
) al
= bl
;
144 extern PolygonEngine
<unsigned short,Combiner
,2> polygonEngine
;
146 extern int outWidth
, outHeight
;
148 void allocOutput(int w
,int h
);
151 void setStarSize(double size
);
156 void interfaceInit();
157 void interfaceSyncToState();
163 Play
, Pause
, Stop
, SkipFwd
, SkipBack
,
164 Handle
, Pointer
, Open
, NoCD
, Exit
,
165 Zero
, One
, Two
, Three
, Four
,
166 Five
, Six
, Seven
, Eight
, Nine
,
167 Slider
, Selector
, Plug
, Loop
, Box
, Bar
,
168 Flame
, Wave
, Stars
, Star
, Diamond
, Size
, FgColor
, BgColor
,
169 Save
, Reset
, TrackSelect
,
173 /* State information */
175 extern SymbolID state
;
176 extern int track
, frames
;
177 extern double trackProgress
;
178 extern char **playList
;
179 extern int playListLength
, playListPosition
;
180 extern SymbolID fadeMode
;
181 extern bool pointsAreDiamonds
;
182 extern double brightnessTwiddler
;
183 extern double starSize
;
184 extern double fgRedSlider
, fgGreenSlider
, bgRedSlider
, bgGreenSlider
;
186 extern double volume
;
188 void setStateToDefaults();
191 void putString(char *string
,int x
,int y
,int red
,int blue
);
194 enum SoundSource
{ SourceLine
, SourceCD
, SourcePipe
, SourceESD
};
196 void cdOpen(char *cdromName
);
198 void cdGetStatus(int &track
, int &frames
, SymbolID
&state
);
199 void cdPlay(int trackFrame
, int endFrame
=-1);
204 void cdCloseTray(void);
205 int cdGetTrackCount(void);
206 int cdGetTrackFrame(int track
);
207 void openSound(SoundSource sound
, int downFactor
, char *dspName
, char *mixerName
);
209 void setupMixer(double &loudness
);
210 void setVolume(double loudness
);
211 int getNextFragment(void);