How to read large data files
Hello all, I recently found ChucK, and have started to work with it in putting together some music. I am trying to use fractal data as a control for various parameters. I rewrote my fractal program in ChucK, but because of how the floats are of limited percision, I am getting different results than the same program written in C. I had thought about two (three?) different approaches to solving the problem, the first would be to use my C program to generate the fractal data, and write it to a file. My program can write this data to an audio file, which would then be imported into ChucK. BUT, it would appear that it is not possible to access the underlying sample data from a 'sndbuf' object. I had looked to see if there was a generic function to read raw data from a disk file, but could not find anything. Also, would this be practical to read, as these datafile can have as many as 20,000 samples per file, these into an Array? How much overhead is there in using an array of floating point values on the order of 20,000 elements? The last idea would be to write a UGEN object in C++, and then recompile ChucK to include this new object. Is there a limitation to how many outputs a UGEN can produce in a single iteration? Several of the fractals that I am working with output more than one value per iteration (each output values represents a different variable in the fractal algorithm). Any suggestions would be appreciated. Thanks.
Welcome Michael,
I recently found ChucK, and have started to work with it in putting together some music. I am trying to use fractal data as a control for various parameters. I rewrote my fractal program in ChucK, but because of how the floats are of limited percision, I am getting different results than the same program written in C.
There is currently one floating point type 'float' in ChucK, which is actually double precision internally.
I had thought about two (three?) different approaches to solving the problem, the first would be to use my C program to generate the fractal data, and write it to a file. My program can write this data to an audio file, which would then be imported into ChucK. BUT, it would appear that it is not possible to access the underlying sample data from a 'sndbuf' object.
I had looked to see if there was a generic function to read raw data from a disk file, but could not find anything.
General file I/O is a disaster zone right now (it's not yet implemented). We are hoping to add this most essential functionality/API asap. Stay tuned.
Also, would this be practical to read, as these datafile can have as many as 20,000 samples per file, these into an Array? How much overhead is there in using an array of floating point values on the order of 20,000 elements?
ChucK arrays have a small constant memory overhead per array (it's more complicated if using multi-dimensional arrays). There is no per-element memory overhead.
The last idea would be to write a UGEN object in C++, and then recompile ChucK to include this new object. Is there a limitation to how many outputs a UGEN can produce in a single iteration?
If I understand this correctly, the answer currently is no - each ugen outputs one sample value mapped to a particular chuck time. The framework caches this value and will not ask a ugen to recompute until the next time increment. I hope this helps - please post if you have additional questions. Best, Ge!
On 1/4/06, Ge Wang
Welcome Michael,
Thank you, and congratulations on ChucK. So far, this looks very promising for some of the ideas that I would like to implement. Basically, I tried to do this using PD, and things get a little cumbersome (at least for me) having to deal with a "graphical" programming language for large projects. I am definetly more of a "text" programmer.
I recently found ChucK, and have started to work with it in putting together some music. I am trying to use fractal data as a control for various parameters. I rewrote my fractal program in ChucK, but because of how the floats are of limited percision, I am getting different results than the same program written in C.
There is currently one floating point type 'float' in ChucK, which is actually double precision internally.
Hum... I have written these fractal algorithms in 4 different languages (C, Java, PD, and now ChucK), and so far, the only thing that I can gauge this with is to compare the results I got from the book I found these algorithms in, which was written in "Pseudo-C", and the results from each version of the program. None of the implementation produce the same stream of data, after about 20 or so iterations of the fractal algorithm, the numbers start to diverge from each other. I can only attribute this to the precision of the underlying floating point numbers.
If I understand this correctly, the answer currently is no - each ugen outputs one sample value mapped to a particular chuck time. The framework caches this value and will not ask a ugen to recompute until the next time increment.
Well, actually, what I was getting at, is each fractal that I have implemented produces more than a single value for each iteration of the algorithm. It would be like a Multi-channel UGen. At the same time, these fractals would not be like other UGens in that they wouldn't be used to generate sample data, unless it was being used for audio. I am primarily interested in using these things to control other parameters, somewhere below the audio rate.
I hope this helps - please post if you have additional questions.
I will. Thanks again. Mike
participants (2)
-
Ge Wang
-
Mike McGonagle