1515
1616#define SAMPLERATE 48000
1717
18+ #define DATADIR string (" ../../../data/" )
19+
1820using namespace std;
1921
2022int main ()
2123{
22- Window::Create (sf::VideoMode (800 , 600 ), " Sound Generator" );
24+ string title = " Sound Generator" ;
25+
26+ Window::Create (sf::VideoMode (1280 , 720 ), title);
2327
2428 // Load font
2529 sf::Font font;
26- if (!font.loadFromFile (" ../../../data/ font/consola.ttf" ))
30+ if (!font.loadFromFile (DATADIR + " font/consola.ttf" ))
2731 {
2832 printf (" Error when loading font" );
2933 }
@@ -106,35 +110,35 @@ int main()
106110
107111 IconButton btnLoad (10 , 10 , 30 , 30 , style);
108112 btnLoad.setIconSize (32 , 32 );
109- btnLoad.setIcon (" ../../../data/ Images/icon_open.png" );
113+ btnLoad.setIcon (DATADIR + " Images/icon_open.png" );
110114
111115 IconButton btnSave (10 , 10 , 30 , 30 , style);
112116 btnSave.setIconSize (32 , 32 );
113- btnSave.setIcon (" ../../../data/ Images/icon_save.png" );
117+ btnSave.setIcon (DATADIR + " Images/icon_save.png" );
114118
115119 IconButton btnStart (10 , 10 , 30 , 30 , style);
116120 btnStart.setIconSize (32 , 32 );
117- btnStart.setIcon (" ../../../data/ Images/icon_start.png" );
121+ btnStart.setIcon (DATADIR + " Images/icon_start.png" );
118122
119123 IconButton btnPlay (10 , 10 , 30 , 30 , style);
120124 btnPlay.setIconSize (32 , 32 );
121- btnPlay.setIcon (" ../../../data/ Images/icon_play.png" );
125+ btnPlay.setIcon (DATADIR + " Images/icon_play.png" );
122126
123127 IconButton btnPause (10 , 10 , 30 , 30 , style);
124128 btnPause.setIconSize (32 , 32 );
125- btnPause.setIcon (" ../../../data/ Images/icon_pause.png" );
129+ btnPause.setIcon (DATADIR + " Images/icon_pause.png" );
126130
127131 IconButton btnStop (10 , 10 , 30 , 30 , style);
128132 btnStop.setIconSize (32 , 32 );
129- btnStop.setIcon (" ../../../data/ Images/icon_stop.png" );
133+ btnStop.setIcon (DATADIR + " Images/icon_stop.png" );
130134
131135 IconButton btnEnd (10 , 10 , 30 , 30 , style);
132136 btnEnd.setIconSize (32 , 32 );
133- btnEnd.setIcon (" ../../../data/ Images/icon_end.png" );
137+ btnEnd.setIcon (DATADIR + " Images/icon_end.png" );
134138
135139 IconButton btnExport (10 , 10 , 30 , 30 , style);
136140 btnExport.setIconSize (32 , 32 );
137- btnExport.setIcon (" ../../../data/ Images/icon_export.png" );
141+ btnExport.setIcon (DATADIR + " Images/icon_export.png" );
138142
139143 Label labelVolume (0 , 0 , 100 , 30 , style);
140144 labelVolume.setText (" Volume" );
@@ -143,12 +147,12 @@ int main()
143147 // InputField Example
144148 InputField inputDuration (10 , 90 , 150 , 30 , style);
145149 inputDuration.setMaxLength (10 );
146- inputDuration.setFloat (0 . 1f );
150+ inputDuration.setFloat (1 . 0f );
147151 inputDuration.setPlaceholder (" Test" );
148152
149153 InputField inputVolume (90 , 50 , 70 , 30 , style);
150154 inputVolume.setMaxLength (5 );
151- inputVolume.setFloat (10 .0f );
155+ inputVolume.setFloat (20 .0f );
152156 inputVolume.setPlaceholder (" Volume" );
153157
154158
@@ -264,47 +268,23 @@ int main()
264268 Window::Close ();
265269 }
266270
267- Window::GetWindow ()->setTitle (" Sound Generator | FPS: " + floatToStr (Time::GetFps (), 0 ));
271+ Window::GetWindow ()->setTitle (title + " | FPS: " + floatToStr (Time::GetFps (), 0 ));
268272
269273 if (button.click ())
270274 {
271275 samples.clear ();
272- // vertices.clear();
273276
274277 float duration = inputDuration.getFloat ();
275278
276- // float step = Window::GetWidth() / (duration * SAMPLERATE);
277- // float frequency = input.getInt();
278- // float attenuation = 0.5f;
279-
280279 sf::Uint64 totalSample = duration * SAMPLERATE ;
281280 output.init ();
282281
283282 for (int i = 0 ; i < totalSample; i++)
284283 {
285- // samples.push_back(Random::Range(-128, 128));
286284 float x = (float )i / SAMPLERATE ;
287- // attenuation = 1.0f;
288- /* if (x > fadeout_last || x < fadein_first)
289- {
290- attenuation = 0;
291- }
292- else {
293- if (x >= fadein_first && x <= fadein_last)
294- {
295- attenuation *= mapValue(x, fadein_first, fadein_last, 0, 1);
296- }
297- if (x >= fadeout_first && x <= fadeout_last)
298- {
299- attenuation *= mapValue(x, fadeout_first, fadeout_last, 1, 0);
300- }
301- }*/
302- // samples.push_back(0x8000 * 0.999f * attenuation * sinf(frequency * 2 * 3.1415926f * x));
303-
304285 samples.push_back (0x7FFF * clamp (output.getOutput (x), -1 .0f , 1 .0f ));
305- // vertices.append(sf::Vertex(sf::Vector2f(i * step, 0.5f * Window::GetWidth() + mapValue(samples[i], -512, 512, -200, 200)), sf::Color::White));
306286 }
307- // buffer.loadFromSamples(samples.data(), SAMPLERATE, 1, SAMPLERATE);
287+
308288 signal.setData (samples);
309289 cout << " Signal sample count: " << signal.getSampleCount () << endl;
310290
@@ -460,11 +440,11 @@ int main()
460440 }
461441 }
462442
463- if (Input::GetMouseButtonDown (sf::Mouse::Left))
464- {
465- sf::Vector2f mousePos = Input::GetMousePosition ();
466- // cout << "Mouse position: (" << mousePos.x << "," << mousePos.y << ")" << endl;
467- }
443+ // if (Input::GetMouseButtonDown(sf::Mouse::Left))
444+ // {
445+ // sf::Vector2f mousePos = Input::GetMousePosition();
446+ // //cout << "Mouse position: (" << mousePos.x << "," << mousePos.y << ")" << endl;
447+ // }
468448
469449 // ///////////////////////// START DRAW
470450 Window::Clear ();
0 commit comments