Skip to content

Commit e34360f

Browse files
committed
Initial commit
0 parents  commit e34360f

File tree

12 files changed

+149
-0
lines changed

12 files changed

+149
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/target
3+
**/*.rs.bk
4+
Cargo.lock

Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "speexdsp"
3+
version = "0.1.0"
4+
authors = ["Luca Barbato <[email protected]>"]
5+
description = "Bindings for the speexdsp library"
6+
7+
[features]
8+
build = ["speexdsp-sys/build"]
9+
10+
[dependencies]
11+
speexdsp-sys = { path = "speexdsp-sys" }
12+
13+
[workspace]
14+
members = ["speexdsp-sys"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Luca Barbato
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# speexdsp bindings
2+
3+
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4+
5+
It is a simple [binding][1] and safe abstraction over [speexdsp][2].
6+
7+
## Building
8+
9+
The bindings are generated using the headers and libraries that ought to be present in the system.
10+
11+
## TODO
12+
- [ ] Simple bindings
13+
- [ ] Safe abstraction
14+
- [ ] Examples
15+
16+
[1]: https://github.com/servo/rust-bindgen
17+
[2]: https://github.com/xiph/speexdsp

speexdsp-sys/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "speexdsp-sys"
3+
version = "0.1.0"
4+
authors = ["Luca Barbato <[email protected]>"]
5+
license = "MIT"
6+
7+
[features]
8+
build = []
9+
10+
[build-dependencies]
11+
autotools = "0.1"
12+
metadeps = "1.1"
13+
bindgen = "0.33"
14+
15+
[package.metadata.pkg-config]
16+
speexdsp = "1.2"

speexdsp-sys/build.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
extern crate autotools;
2+
extern crate bindgen;
3+
extern crate metadeps;
4+
5+
use std::env;
6+
use std::fs::OpenOptions;
7+
use std::io::Write;
8+
9+
fn format_write(builder: bindgen::Builder, output: &str) {
10+
let s = builder
11+
.generate()
12+
.unwrap()
13+
.to_string()
14+
.replace("/**", "/*")
15+
.replace("/*!", "/*");
16+
17+
let mut file = OpenOptions::new()
18+
.write(true)
19+
.truncate(true)
20+
.create(true)
21+
.open(output)
22+
.unwrap();
23+
24+
let _ = file.write(s.as_bytes());
25+
}
26+
27+
fn common_builder() -> bindgen::Builder {
28+
bindgen::builder()
29+
.raw_line("#![allow(dead_code)]")
30+
.raw_line("#![allow(non_camel_case_types)]")
31+
.raw_line("#![allow(non_snake_case)]")
32+
.raw_line("#![allow(non_upper_case_globals)]")
33+
}
34+
35+
fn main() {
36+
if cfg!(feature="build") {
37+
// TODO: decide how to fetch the source
38+
let dst = autotools::build("speexdsp");
39+
40+
env::set_var("PKG_CONFIG_PATH", dst.join("lib/pkgconfig"));
41+
}
42+
43+
let libs = metadeps::probe().unwrap();
44+
45+
let headers = libs.get("speexdsp").unwrap().include_paths.clone();
46+
47+
for e in ["echo", "jitter", "preprocess", "resampler"].iter() {
48+
let mut builder = common_builder().header(format!("data/{}.h", e));
49+
50+
for header in headers.iter() {
51+
builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap());
52+
}
53+
54+
// Manually fix the comment so rustdoc won't try to pick them
55+
format_write(builder, &format!("src/{}.rs", e));
56+
}
57+
}

speexdsp-sys/data/echo.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "speex/speex_echo.h"

speexdsp-sys/data/jitter.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "speex/speex_jitter.h"

speexdsp-sys/data/preprocess.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "speex/speex_preprocess.h"

speexdsp-sys/data/resampler.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "speex/speex_resampler.h"

speexdsp-sys/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
pub mod resampler;
3+
pub mod echo;
4+
pub mod jitter;
5+
pub mod preprocess;

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern crate speexdsp_sys;
2+
3+
pub use speexdsp_sys::*;
4+
5+
#[cfg(test)]
6+
mod tests {
7+
#[test]
8+
fn it_works() {
9+
assert_eq!(2 + 2, 4);
10+
}
11+
}

0 commit comments

Comments
 (0)