MCPcopy Create free account
hub / github.com/HackerPoet/FractalSoundExplorer / onGetData

Method onGetData

Main.cpp:160–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158 }
159
160 virtual bool onGetData(Chunk& data) override {
161 //Setup the chunk info
162 data.samples = m_samples;
163 data.sampleCount = AUDIO_BUFF_SIZE;
164 memset(m_samples, 0, sizeof(m_samples));
165
166 //Check if audio needs to reset
167 if (audio_reset) {
168 m_audio_time = 0;
169 play_cx = (jx < 1e8 ? jx : play_nx);
170 play_cy = (jy < 1e8 ? jy : play_ny);
171 play_x = play_nx;
172 play_y = play_ny;
173 play_px = play_nx;
174 play_py = play_ny;
175 mean_x = play_nx;
176 mean_y = play_ny;
177 volume = 8000.0;
178 audio_reset = false;
179 }
180
181 //Check if paused
182 if (audio_pause) {
183 return true;
184 }
185
186 //Generate the tones
187 const int steps = sample_rate / max_freq;
188 for (int i = 0; i < AUDIO_BUFF_SIZE; i+=2) {
189 const int j = m_audio_time % steps;
190 if (j == 0) {
191 play_px = play_x;
192 play_py = play_y;
193 fractal(play_x, play_y, play_cx, play_cy);
194 if (play_x*play_x + play_y*play_y > escape_radius_sq) {
195 audio_pause = true;
196 return true;
197 }
198
199 if (normalized) {
200 dpx = play_px - play_cx;
201 dpy = play_py - play_cy;
202 dx = play_x - play_cx;
203 dy = play_y - play_cy;
204 if (dx != 0.0 || dy != 0.0) {
205 double dpmag = 1.0 / std::sqrt(1e-12 + dpx*dpx + dpy*dpy);
206 double dmag = 1.0 / std::sqrt(1e-12 + dx*dx + dy*dy);
207 dpx *= dpmag;
208 dpy *= dpmag;
209 dx *= dmag;
210 dy *= dmag;
211 }
212 } else {
213 //Point is relative to mean
214 dx = play_x - mean_x;
215 dy = play_y - mean_y;
216 dpx = play_px - mean_x;
217 dpy = play_py - mean_y;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected