These are chat archives for supercollider/supercollider

28th
Mar 2017
Rainer Sch├╝tz
@bagong
Mar 28 2017 22:20
Somebody listening out there? ;)
is this legit code?
(
~data = { | sampleRate = 44100, numChan = 1, dur = 1, freq = 440 |

    var freqs, samples, sounds, channelArray, dataArray, return;

    freqs = Array.fill(numChan, { |i| freq });
    samples = freqs.collect({ |freq| (sampleRate/freq).floor });
    sounds = samples.collect({ |sample| Signal.sineFill(sample, [1]); });
    "created sounds".postln;
    channelArray = sounds.collect({ |snd| Array.fill(sampleRate * dur, { |i| snd.wrapAt(i) * (0.2/numChan) })  });
    "created channels".postln;
    dataArray = channelArray.lace;
    "created data".postln;
    return = FloatArray.newFrom(dataArray);

};
~sr = 96000;
~nc = 32;
~dur = 32;
~raw = ~data.value(sampleRate: ~sr, numChan: ~nc, dur: ~dur);

// this works fine:
~file = Platform.userHomeDir +/+ "tmp" +/+ "test.wav";
~soundFile = SoundFile.new.headerFormat_("wav").sampleFormat_("int16").numChannels_(~nc).sampleRate_(~sr);
~soundFile.openWrite(~file);
~soundFile.writeData(~raw);
~soundFile.close;
~soundFile.openRead(~file);
)
The function, I mean...
I want to create soundfiles quickly with arbitrary channel numbers, duration and samplerate...
Problem is at moderately large values sclang crashes, and I wonder if it's me or sclang...
The values 96kHz, 32 channels and 32 seconds still produce data for me, but if I go up higher, sclang crashes
it's in the FloatArray.newFrom line...
I am using the code in a context where it crashes at much lower parameter values, and if it crashes that surrounding code gets dirty, like variables get assigned wrong values...