1 /* Synaesthesia - program to display sound graphically
2 Copyright (C) 1997 Paul Francis Harrison
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
18 The author may be contacted at:
19 phar6@student.monash.edu.au
21 27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
28 /***************************************/
29 /* For the incurably fiddle prone: */
31 /* log2 of sample size */
32 #define LogSize 10 //was 9
35 #define Brightness 150
38 #define Frequency 22050
40 #define DefaultWidth 200
41 #define DefaultHeight 200
43 /***************************************/
45 #define NumSamples (1<<LogSize)
46 #define RecSize (1<<LogSize-Overlap)
50 typedef unsigned short sampleType
;
54 typedef short sampleType
;
58 #warning This target has not been tested!
64 #include <machine/endian.h>
69 #if BYTE_ORDER == BIG_ENDIAN
75 void error(char *str
,bool syscall
=false);
76 void inline attempt(int x
,char *y
,bool syscall
=false) { if (x
== -1) error(y
,syscall
); }
77 void warning(char *str
,bool syscall
=false);
78 void inline attemptNoDie(int x
,char *y
,bool syscall
=false) { if (x
== -1) warning(y
,syscall
); }
82 virtual bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
) = 0;
83 virtual void setPalette(unsigned char *palette
) = 0;
84 virtual void end() = 0;
85 virtual void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
) = 0;
86 virtual void show() = 0;
87 virtual void toggleFullScreen() { }
90 struct SvgaScreen
: public BaseScreen
{
91 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
92 void setPalette(unsigned char *palette
);
94 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
98 struct SdlScreen
: public BaseScreen
{
99 bool init(int xHint
, int yHint
, int widthHint
, int heightHint
, bool fullscreen
);
100 void setPalette(unsigned char *palette
);
102 void inputUpdate(int &mouseX
,int &mouseY
,int &mouseButtons
,char &keyHit
);
104 void toggleFullScreen();
107 struct XScreen
: 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
);
116 extern BaseScreen
*screen
;
117 extern sampleType
*data
;
118 extern Bitmap
<unsigned short> outputBmp
, lastOutputBmp
, lastLastOutputBmp
;
119 #define output ((unsigned char*)outputBmp.data)
120 #define lastOutput ((unsigned char*)lastOutputBmp.data)
121 #define lastLastOutput ((unsigned char*)lastLastOutputBmp.data)
124 static unsigned short combine(unsigned short a
,unsigned short b
) {
125 //Not that i want to give the compiler a hint or anything...
126 unsigned char ah
= a
>>8, al
= a
&255, bh
= b
>>8, bl
= b
&255;
127 if (ah
< 64) ah
*= 4; else ah
= 255;
128 if (al
< 64) al
*= 4; else al
= 255;
129 if (bh
> ah
) ah
= bh
;
130 if (bl
> al
) al
= bl
;
135 extern PolygonEngine
<unsigned short,Combiner
,2> polygonEngine
;
137 extern int outWidth
, outHeight
;
139 void allocOutput(int w
,int h
);
142 void setStarSize(double size
);
147 void interfaceInit();
148 void interfaceSyncToState();
154 Play
, Pause
, Stop
, SkipFwd
, SkipBack
,
155 Handle
, Pointer
, Open
, NoCD
, Exit
,
156 Zero
, One
, Two
, Three
, Four
,
157 Five
, Six
, Seven
, Eight
, Nine
,
158 Slider
, Selector
, Plug
, Loop
, Box
, Bar
,
159 Flame
, Wave
, Stars
, Star
, Diamond
, Size
, FgColor
, BgColor
,
160 Save
, Reset
, TrackSelect
,
164 /* State information */
166 extern SymbolID state
;
167 extern int track
, frames
;
168 extern double trackProgress
;
169 extern char **playList
;
170 extern int playListLength
, playListPosition
;
171 extern SymbolID fadeMode
;
172 extern bool pointsAreDiamonds
;
173 extern double brightnessTwiddler
;
174 extern double starSize
;
175 extern double fgRedSlider
, fgGreenSlider
, bgRedSlider
, bgGreenSlider
;
177 extern double volume
;
179 void setStateToDefaults();
182 void putString(char *string
,int x
,int y
,int red
,int blue
);
185 enum SoundSource
{ SourceLine
, SourceCD
, SourcePipe
, SourceESD
};
187 void cdOpen(char *cdromName
);
189 void cdGetStatus(int &track
, int &frames
, SymbolID
&state
);
190 void cdPlay(int trackFrame
, int endFrame
=-1);
195 void cdCloseTray(void);
196 int cdGetTrackCount(void);
197 int cdGetTrackFrame(int track
);
198 void openSound(SoundSource sound
, int downFactor
, char *dspName
, char *mixerName
);
200 void setupMixer(double &loudness
);
201 void setVolume(double loudness
);
202 int getNextFragment(void);