flac_bound/
lib.rs

1//! FLAC encoding via libFLAC FFI
2//!
3//! # Building <!-- also update README -->
4//!
5//! There are two supported libFLAC back-ends:
6//!   * [`flac-sys`](https://crates.io/crates/flac-sys), under the `"flac"` feature, the default, and
7//!   * [`libflac-sys`](https://crates.io/crates/libflac-sys), under the `"libflac"` feature group
8//!     (better-maintained, [`FlacEncoderConfig::set_limit_min_bitrate()`] is only available here).
9//!
10//! `flac-sys` tries to link to a libFLAC already present on your system, but it doesn't do a very good job, and might need some help by copying
11//! `/usr/lib/x86_64-linux-gnu/libFLAC.so` (Debian), `$MSYSROOT\mingw64\lib\libflac.dll.a` (msys2), or equivalent
12//! to `target/{debug,release}/deps` as `libflac.so`/`libflac.dll.a`/&c. (note the lowercase).
13//!
14//! `libflac-sys` tries to build libFLAC; this is a problem because it (a) doesn't work all that well (at all) under GNU/NT,
15//! and (b) requires the host system to have both CMake and a C toolchain funxional.
16//!
17//! The `"libflac-noogg"` feature will build libFLAC without OGG support.
18//!
19//! The `"libflac-nobuild"` feature will still use `libflac-sys` but instruct it to link to the system libFLAC (≥ 1.4.0).
20//!
21//! Downstreams are encouraged to expose these features to the user.
22//!
23//! # Examples
24//!
25//! ```
26//! # use flac_bound::{WriteWrapper, FlacEncoder};
27//! # use std::fs::File;
28//! let mut outf = File::create("ЦшЦ.flac").unwrap();
29//! let mut outw = WriteWrapper(&mut outf);
30//! let mut enc = FlacEncoder::new().unwrap().compression_level(8).init_write(&mut outw).unwrap();
31//!
32//! // The following two calls are equivalent for a two-channel encoder
33//! enc.process(&[&[0xA1], &[0xF3]]).unwrap();
34//! enc.process_interleaved(&[0xA1, 0xF3], 1).unwrap();
35//!
36//! // If you don't care about errors that may arise when writing the final frames,
37//! // you can just drop the encoder; or you can inspect them:
38//! match enc.finish() {
39//!     Ok(mut conf) => {
40//!         // Encoding succeeded, a new encoder can be initialised in the same place and memory
41//! #       #[cfg(not(feature="libflac-noogg"))] {
42//!         enc = conf.compression_level(0).channels(1).init_stdout_ogg().unwrap();
43//! #       }
44//! #       #[cfg(feature="libflac-noogg")] {
45//! #       enc = conf.compression_level(0).channels(1).init_stdout().unwrap();
46//! #       }
47//!         // &c.
48//!     }
49//!     Err(enc) => {
50//!         eprintln!("Encoding failed: {:?}", enc.state());
51//!     }
52//! };
53//! ```
54//!
55//! # Special thanks
56//!
57//! To all who support further development on [Patreon](https://patreon.com/nabijaczleweli), in particular:
58//!
59//!   * ThePhD
60//!   * Embark Studios
61//!   * Jasper Bekkers
62
63
64#[cfg(feature="flac")]
65extern crate flac_sys;
66#[cfg(feature="libflac-nobuild")]
67extern crate libflac_sys;
68
69mod encoder;
70
71pub use encoder::{FlacEncoderInitError, FlacEncoderConfig, FlacEncoderState, WriteWrapper, FlacEncoder};