Compare commits

..

4 commits

Author SHA1 Message Date
b8dcb84294 image: fix typo 2019-08-06 23:35:02 -03:00
981b52c05b lang: add hack while AutoHashMap is broken
- image: add timer for runPlugin
2019-08-06 23:34:11 -03:00
fc3972d65c remove unecessary allocation in RunContext 2019-08-06 19:25:47 -03:00
75eeea14f3 add check for n_audio_out>2 2019-08-06 19:25:31 -03:00
5 changed files with 84 additions and 14 deletions

View file

@ -38,13 +38,17 @@ Run the eg-amp plugin over the given slice of the file.
Run the Retro Flanger script from the SWH plugins. Run the Retro Flanger script from the SWH plugins.
- `delay_depth_avg` is for the `Average stall (ms)` parameter of the plugin. Parameters:
- `law_freq` is for the `Flange frequency` parameter of the plugin. - `delay_depth_avg`: Average stall (ms), 0..10, default 2.5
- `law_freq`: Flange frequency (Hz), 0.5..8, default 1
## `eq split index lo mid hi` ## `eq split index lo mid hi`
Run the DJ EQ plugin from the SWH plugins. Run the DJ EQ plugin from the SWH plugins.
Parameters:
- `lo`: Low range
`lo`, `mid`, and `hi` are the respective dB gains for each frequency range. `lo`, `mid`, and `hi` are the respective dB gains for each frequency range.
All three ranges accept gains from -70dB to +6dB. All three ranges accept gains from -70dB to +6dB.

View file

@ -95,6 +95,10 @@ pub const WildNoise = struct {
} }
}; };
/// Write any float to the image.
/// Keep in mind that the bit representation of the float will clash with
/// the format of BMP pixel data, which means writing 0 everywhere won't give
/// you the black color.
pub const Write = struct { pub const Write = struct {
data: f32, data: f32,

View file

@ -243,17 +243,22 @@ pub const Image = struct {
position: plugins.Position, position: plugins.Position,
params: plugins.ParamList, params: plugins.ParamList,
) !void { ) !void {
var timer = try std.time.Timer.start();
var ctx = try plugins.makeContext(self.allocator, plugin_uri); var ctx = try plugins.makeContext(self.allocator, plugin_uri);
defer ctx.deinit(); defer ctx.deinit();
var ports = try lv2.setupPorts(&ctx); var ports = try lv2.setupPorts(&ctx);
if (ctx.n_audio_in > 2) { if (ctx.n_audio_in > 2) {
std.debug.warn("plugin <{}> accepts more than two channels.\n", plugin_uri); std.debug.warn("plugin <{}> has more than two inputs.\n", plugin_uri);
return ImageError.InvalidPlugin; return ImageError.InvalidPlugin;
} }
// TODO check n_audio_out > 2 if (ctx.n_audio_out > 2) {
std.debug.warn("plugin <{}> has more than two outputs.\n", plugin_uri);
return ImageError.InvalidPlugin;
}
// now, for each param for the plugin, we find its port, and set // now, for each param for the plugin, we find its port, and set
// the value for the port there. // the value for the port there.
@ -347,6 +352,9 @@ pub const Image = struct {
_ = c.sf_close(self.sndfile); _ = c.sf_close(self.sndfile);
try self.reopen(tmpnam); try self.reopen(tmpnam);
var time_taken = timer.read();
std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken / std.time.millisecond);
} }
pub fn saveTo(self: *Image, out_path: []const u8) !void { pub fn saveTo(self: *Image, out_path: []const u8) !void {

View file

@ -169,6 +169,66 @@ pub const Lang = struct {
_ = try self.keywords.put("rotate", .Rotate); _ = try self.keywords.put("rotate", .Rotate);
} }
// TODO remove this once AutoHashMap is fixed.
pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType {
const commands = [_][]const u8{
"noop",
"load",
"quicksave",
"runqs",
"amp",
"rflanger",
"eq",
"phaser",
"mbeq",
"chorus",
"pitchscaler",
"reverb",
"highpass",
"delay",
"vinyl",
"revdelay",
"noise",
"wildnoise",
"write",
"rotate",
};
const command_types = [_]CommandType{
.Noop,
.Load,
.Quicksave,
.RunQS,
.Amp,
.RFlanger,
.Eq,
.Phaser,
.Mbeq,
.Chorus,
.PitchScaler,
.Reverb,
.Highpass,
.Delay,
.Vinyl,
.RevDelay,
.Noise,
.WildNoise,
.Write,
.Rotate,
};
std.debug.assert(commands.len == command_types.len);
for (commands) |command, idx| {
if (std.mem.eql(u8, stmt, command)) return command_types[idx];
}
return null;
}
pub fn parse(self: *Lang, data: []const u8) !CommandList { pub fn parse(self: *Lang, data: []const u8) !CommandList {
var splitted_it = std.mem.separate(data, ";"); var splitted_it = std.mem.separate(data, ";");
try self.fillKeywords(); try self.fillKeywords();
@ -188,12 +248,12 @@ pub const Lang = struct {
if (cmd_opt == null) return ParseError.NoCommandGiven; if (cmd_opt == null) return ParseError.NoCommandGiven;
var command = cmd_opt.?; var command = cmd_opt.?;
var kv_opt = self.keywords.get(command); var ctype_opt = self.getCommand(command);
var ctype: CommandType = undefined; var ctype: CommandType = undefined;
if (kv_opt) |kv| { if (ctype_opt) |ctype_val| {
ctype = kv.value; ctype = ctype_val;
} else { } else {
std.debug.warn("Unknown command: '{}'\n", command); std.debug.warn("Unknown command: '{}' ({})\n", command, command.len);
return ParseError.UnknownCommand; return ParseError.UnknownCommand;
} }

View file

@ -99,12 +99,6 @@ pub const RunContext = struct {
return ImageError.InstantiateFail; return ImageError.InstantiateFail;
} }
// we allocate []f32 with size 2 to account for stereo plugins, however
// we only use &in_buf[0] and &out_buf[0], and don't use the
// (supposedly) right side of neither input or output.
var in_buf = try allocator.alloc(f32, 2);
std.mem.secureZero(f32, in_buf);
return RunContext{ return RunContext{
.buffers = try RunBuffers.init(allocator), .buffers = try RunBuffers.init(allocator),
.instance = instance.?, .instance = instance.?,