4个稳定版本
3.0.0 | 2020年10月23日 |
---|---|
2.0.0 | 2020年3月27日 |
1.0.1 | 2020年2月23日 |
#16 在 #lv2
167 每月下载量
用于 7 个crate(6 直接使用)
1MB
15K SLoC
Rust-LV2的核心库。
是rust-lv2
的基础,一个用于创建LV2插件的简单、快速和便捷的框架,用于音频处理,用Rust编写。
此crate提供了Plugin
特质和一些实用工具,允许您创建一个基本的音频插件,并可选择使用宿主和插件扩展。
示例
此示例包含一个简单放大插件的代码。请注意,这并不是创建插件所必需的,更多详细信息请参阅下面的文档。
// Import everything we need.
use lv2_core::prelude::*;
// The input and output ports are defined by a struct which implements the `PortCollection` trait.
// In this case, there is an input control port for the gain of the amplification, an input audio
// port and an output audio port.
#[derive(PortCollection)]
struct Ports {
gain: InputPort<Control>,
input: InputPort<Audio>,
output: OutputPort<Audio>,
}
// The plugin struct. In this case, we don't need any data and therefore, this struct is empty.
#[uri("rn:rust-lv2-book:eg-amp-rs")]
struct Amp;
// LV2 uses URIs to identify types. This association is expressed via the `UriBound` trait, which
// tells the framework that the type `Amp` is identified by the given URI.
//
// This trait is unsafe to implement since you **need** to include the \0 character at the end of
// the string.
// The implementation of the `Plugin` trait, which turns `Amp` into a plugin.
impl Plugin for Amp {
// Tell the framework which ports this plugin has.
type Ports = Ports;
// We don't need any special host features; We can leave them out.
type InitFeatures = ();
type AudioFeatures = ();
// Create a new instance of the plugin; Trivial in this case.
fn new(_plugin_info: &PluginInfo, _features: &mut ()) -> Option<Self> {
Some(Self)
}
// Process a chunk of audio. The audio ports are dereferenced to slices, which the plugin
// iterates over.
fn run(&mut self, ports: &mut Ports, _features: &mut ()) {
let coef = if *(ports.gain) > -90.0 {
10.0_f32.powf(*(ports.gain) * 0.05)
} else {
0.0
};
for (in_frame, out_frame) in Iterator::zip(ports.input.iter(), ports.output.iter_mut()) {
*out_frame = in_frame * coef;
}
}
}
// Generate the plugin descriptor function which exports the plugin to the outside world.
lv2_descriptors!(Amp);
文档
原始LV2 API(使用C
编程语言)由"LV2书籍"进行文档记录。这本书正在被翻译成Rust,并与rust-lv2
的开发同步进行(链接),描述了如何正确使用rust-lv2
。
特性
与任何其他rust-lv2
crate一样,此crate具有可选的host
特性。一些crate定义的类型仅对测试或LV2宿主有用。由于此框架的目标是提供创建插件的一种简单方法,因此这些不是必需的,因此被置于该特性之后。
许可
许可协议为以下之一
- Apache许可证版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证(LICENSE-MIT 或 http://opensource.org/licenses/MIT)
由您自行选择。
依赖项
~1.5MB
~34K SLoC