我编写了以下代码来定义一个SynthDef,它将声音记录到作为参数之一传递的缓冲区中。
(
SynthDef(\recordTone, { |freq, bufnum, duration|
var w = SinOsc.ar(freq) * XLine.ar(101,1,duration,add: -1) / 100;
RecordBuf.ar(w!2,bufnum,loop: 0,doneAction: 2);
}).add;
)
我还有下面的代码,它为上面的SynthDef调用Synth,并尝试将缓冲区写入文件。
({
var recordfn = { |freq, duration, fileName|
var server = Server.local;
var buf = Buffer.alloc(server,server.sampleRate * duration,2);
Synth(\recordTone,[\freq, 440, \bufnum, buf.bufnum, \duration, duration]);
buf.write(
"/Users/minerva/Temp/snd/" ++ fileName ++ ".wav",
"WAVE",
"int16",
completionMessage: ["b_free", buf.bufnum]
);
};
recordfn.value(440,0.5,"test");
}.value)
正在创建输出文件,但不包含任何声音。我究竟做错了什么?我查看了所有可以找到的SuperCollider文档,但似乎没有任何效果!任何指针都非常感谢。
答案 0 :(得分:1)
你的主要问题是你的recordfn
函数你正在实例化SynthDef(即开始录制)并同时将Buffer写入磁盘。显然,在你开始录音时,缓冲区中没有声音,因此SuperCollider完全按照你的要求进行操作,并将空的无声缓冲区写为文件。
解决方案:
次要的事情:我现在不记得了,但我认为它可能是“WAV”而不是“WAVE”。
答案 1 :(得分:1)
根据Dan S的回答,我做了一些修改以使其正常工作:
(
SynthDef(\playTone, { |freq, duration|
var w = SinOsc.ar(freq) * XLine.ar(1001,1,duration,add: -1,doneAction:2) / 1000;
Out.ar(0,w!2);
}).add;
)
(
SynthDef(\recordTone, { |buffer|
RecordBuf.ar(In.ar(0,2), buffer, loop: 0, doneAction: 2);
}).add;
)
(Routine({
var recordfn = { |freq, duration|
var server = Server.local;
var buffer = Buffer.alloc(server, server.sampleRate * duration, 2);
server.sync;
server.makeBundle(func: {
var player = Synth(\playTone, [\freq, freq, \duration, duration]);
var recorder = Synth.after(player, \recordTone, [\buffer, buffer]);
});
duration.wait;
buffer.write(
"/Users/minerva/Temp/snd/test.wav",
"WAVE",
"int16",
completionMessage: ["/b_free", buffer]
);
};
recordfn.value(440,0.1);
}).next)