#alac #apple #audio #encoder #format

alac-encoder

Rust port of Apple’s open source ALAC library

4 releases (2 breaking)

Uses new Rust 2021

0.3.0 Jan 10, 2022
0.2.0 Oct 22, 2021
0.1.1 May 15, 2019
0.1.0 May 15, 2019

#8 in Encoding

Download history 10/week @ 2022-01-28 5/week @ 2022-02-04 6/week @ 2022-02-11 11/week @ 2022-02-18 13/week @ 2022-02-25 6/week @ 2022-03-04 12/week @ 2022-03-11 19/week @ 2022-03-18 4/week @ 2022-03-25 5/week @ 2022-04-01 8/week @ 2022-04-08 4/week @ 2022-04-15 9/week @ 2022-04-22 15/week @ 2022-04-29 34/week @ 2022-05-06 71/week @ 2022-05-13

129 downloads per month

Apache-2.0 OR MIT

67KB
1K SLoC

ALAC Encoder for Rust

Rust port of Apple's open source ALAC library.

Installation

This crate works with Cargo and is on crates.io.

Usage

use alac_encoder::{AlacEncoder, FormatDescription};

// Specify the input format as signed 16-bit raw PCM, 44100 Hz & 2 channels
let input_format = FormatDescription::pcm::<i16>(44100.0, 2);

// Specify the output format as 44100 Hz ALAC with a frame size of 4096 & 2 channels
let output_format = FormatDescription::alac(44100.0, 4096, 2);

// Initialize the encoder
let mut encoder = AlacEncoder::new(&output_format);

// Allocate a buffer for the encoder to write chunks to.
let mut output = vec![0u8; output_format.max_packet_size()];

// Get a hold of the source data, e.g. from a file
let pcm = fs::read("foobar.pcm").unwrap();

// Iterate over chunks from the input
for chunk in pcm.chunks(frame_size as usize * channels as usize * 2) {
  // Feed the current chunk to the encoder
  let size = encoder.encode(&input_format, &chunk, &mut output);

  // Here you can do whatever you want with the result:
  Vec::from(&output[0..size]);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~90KB