我有这个查克代码:
"examples/vento.txt" => string filename;
FileIO fio;
// open a file
fio.open(filename, FileIO.READ);
// ensure it's ok
if(!fio.good()) {
cherr <= "can't open file: " <= filename <= " for reading..." <= IO.newline();
me.exit();
}
fio.readLine() => string velocity;
fio.readLine() => string direction;
文本文件包含:
10
12
(每分钟更新一次python)
我想将速度和方向转换为 int (或更好的浮点数)。
我怎样才能做到这一点?
最佳答案
使用 atoi
和 atof
在 Std
图书馆。假设您想将 0-127(MIDI 力度)转换为 0 到 1.0 之间的浮点数(对于单位生成器来说更方便):
Std.atoi(fio.readLine()) => int midi_velocity;
midi_velocity/127.0 => float velocity;
<<< velocity >>>;
应该打印
0.078740 :(float)
对于 10 的输入。或者,如果您只想直接 float :
Std.atof(fio.readLine()) => float velocity;
<<< velocity >>>;
打印
10.000000 :(float)
.
关于audio - 从 Chuck 中的文件读取整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258837/