<div dir="ltr"><div class="gmail_quote"><div> <span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">My sonification project is done! You can hear the results at <a href="https://soundcloud.com/fcahoon/shumann-resonance-at-tomsk">https://soundcloud.com/fcahoon/shumann-resonance-at-tomsk</a> .</span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I've been manipulating the data a lot, so it was simple to switch to tab-separated instead of comma-separated values, which </span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">ChucK reads without issue. The first few lines of my data looks like</span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div>7.8975 6.0000 13.6870 4.6500 19.0720 4.7200 25.5000 2.6200<br>7.9165 6.0000 13.6030 4.6500 19.0300 4.7200 25.5500 2.6200<br>7.9355 7.2000 13.5400 4.1200 18.9670 4.3800 25.6000 2.6200<br>7.9640 7.2000 13.4980 4.1200 18.9250 4.3800 25.6250 2.6200<br>...<br>These are four frequency/amplitude pairs on each line.</div><div class="gmail_quote"><br></div><div class="gmail_quote">I still did my interpolation sample-by-sample, but was not too difficult. Here is my ChucK code (it seems short enough to post):</div><div class="gmail_quote"><br></div><div class="gmail_quote">
<span></span>
16.0 => float FREQ_MULT;<br>0.008 => float GAIN_MULT;<br>441 => int SAMPLES_PER_DATAPOINT;<br><br>SinOsc sig[4];<br><br>for ( 0 => int i ; i < sig.cap() ; i++) {<br> sig[i] => dac;<br> sig[i].gain(0);<br>}<br>// open file<br>me.sourceDir() + "tomsk_2017-05-10_000.dat" => string fname;<br>FileIO fio;<br>fio.open(fname, FileIO.READ);<br>if( !fio.good() )<br>{<br> cherr <= "can't open file: " <= fname <= " for reading..."<br> <= IO.newline();<br> me.exit();<br>}
float old_freq[4];<br>float old_gain[4];<br>float new_freq[4];<br>float new_gain[4];<br>float freq_incr[4];<br>float gain_incr[4];<br><br>// read first line<br>for (0 => int i; i < 4; i++) {<br> fio => old_freq[i];<br> fio => old_gain[i];<br>}<br><br>while (fio.more()) {<br> // read next line<br> for (0 => int i; i < 4; i++) {<br> fio => new_freq[i];<br> fio => new_gain[i];<br> }<br><br> // calculate linear interpolation increments<br> for (0 => int i; i < 4; i++) {<br> (new_freq[i] - old_freq[i])/SAMPLES_PER_DATAPOINT => freq_incr[i];<br> (new_gain[i] - old_gain[i])/SAMPLES_PER_DATAPOINT => gain_incr[i];<br> }<br> // Interpolate all samples between datapoints:<br> for (0 => int step; step < SAMPLES_PER_DATAPOINT; step++) {<br> // calculate interpolated freqs and gains for this sample<br> for (0 => int i; i < 4; i++) {<br> (old_freq[i] + (step*freq_incr[i])) * FREQ_MULT => sig[i].freq;<br> (old_gain[i] + (step*gain_incr[i])) * GAIN_MULT => sig[i].gain;<br> }<br> //render the sample<br> 1::samp => now;<br> }<br> // save last datapoint values read as "old" in preparation for <br> // reading the next set of "new" datapoint values<br> for (0 => int i; i < 4; i++) {<br> new_freq[i] => old_freq[i];<br> new_gain[i] => old_gain[i];<br> }<br>}</div><div class="gmail_quote"><div> </div><div>I'm sure my code must have some non-idiomatic or inefficient things in it; it is my first real ChucK program. Any advice would be appreciated.</div></div></div>