gpt4 book ai didi

audio - 使用SuperCollider记录WAV文件

转载 作者:行者123 更新时间:2023-12-02 22:45:55 25 4
gpt4 key购买 nike

我编写了以下代码,以定义一个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文档,但似乎没有任何效果!任何指针,不胜感激。

最佳答案

根据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)

关于audio - 使用SuperCollider记录WAV文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com