I use SuperCollider to write data directly into SoundFiles. The usual process is to get the data into a FloatArray, and then write that into the SoundFile (I don’t worry about the numbers being over 1 below -1, because afterwards I open it in a sound editor and Normalize/DC Offset).
Here’s the example, reduced to the parts I am unable to get to work. The resulting SoundFile should have [1,4,7] in the first channel, [2,5,8] in the second, etc.
a = [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ].asFloat;
b = a.as(FloatArray); //fails
b = Array.fill(3, {|i| a[i].as(FloatArray)}); //works, but then doesn't work when writing to a SoundFile
f = SoundFile.new.headerFormat_("AIFF").sampleFormat_("float").numChannels_(3);
f.openWrite("/Users/Me/Downloads/snippet.aif");
f.writeData(b);
f.close
a.as(FloatArray)
gives me the error: ERROR: Primitive ‘_ArrayAdd’ failed. Wrong type.
so I tried to make an Array of FloatArrays, b = Array.fill(3, {|i| a[i].as(FloatArray)})
which works, but SoundFIle doesn’t like it, giving the error: ERROR: Primitive ‘_SFWrite’ failed. Wrong type.
b = a.at(0).as(FloatArray)
works, and I can write to a SoundFile with it (just change numChannels =1)
How do I write this multichannel array of numbers into a SoundFile? It doesn’t seem possible to make a multidimension FloatArray, and an Array of FloatArrays also doesn’t work.
-Andy