Crates.io | hodaun |
lib.rs | hodaun |
version | 0.4.1 |
source | src |
created_at | 2023-04-19 16:42:04.856717 |
updated_at | 2023-08-07 01:16:33.370172 |
description | Audio IO and synthesis |
homepage | https://github.com/kaikalii/hodaun |
repository | |
max_upload_size | |
id | 843731 |
size | 110,125 |
An audio IO and synthesis library for Rust.
Built on top of cpal.
Source
traitWhile this library was inspired by Rodio, it was designed to address some of the pain-points of using Rodio in a real application.
Like Rodio, Hodaun has a Source
trait that abstracts audio streams.
The main thing that makes Hodaun different from Rodio is that Hodaun's Source
s process audio at the frame level rather than the sample level.
In Rodio, Source
processes one sample at a time, even if consecutive samples correspond to different channels of the same sample frame.
This makes writing custom Source
s that are channel-aware difficult.
By contrast, Hodaun's Source
trait groups samples in the same frame into a statically-sized array (or just a number for mono audio) with a value for each channel.
In Rodio, the sample rate is a property of a Source
. This can be weird when working with synthesized audio. What is the sample rate of a sine wave? Who cares? It's a mathematical function with inifinite resolution.
In Hodaun, the sample rate is passed to Source
, and it is up to the Source
to decide what to do with it. In practice, this means that the sample rate of Source
s adapts to the sample rate of the audio output device.
Sources that can have various possible sample rates, like audio input devices or audio files, implement UnrolledSource
instead of Source
. This trait corresponds more closely to Rodio's Source
trait. An UnrolledSource
can be converted to a Source
using UnrolledSource::resample
.
Rodio's Source
trait lets you do many basic transformations on audio streams, but once the sound is playing, the parameters used for these transformations cannot be changed.
For example rodio::Source::amplify
takes an f32
that changes the volume of the Source
.
But what if you want to change the volume of the Source
while it's playing? This is common in basically any application that plays audio.
Hodaun also has Source::amplify
, but it takes a value implementing the Automation
trait.
This can be a static number just like Rodio
, but it can also be an externally-controlled value modified elsewhere in your code, or it can even be another Source
that changes the value over time.