- - - - - - - ----
Add the following to your `Cargo.toml`:
```toml
[dependencies]
rustic_audio_tool = "0.0.1"
`RusticAudio` is a Rust library for recording, processing, and playing back audio with support for DSP effects and Opus compression. It provides a simple API for handling audio files, including recording, playback, and encoding.
Linux Debian/Ubuntu-based Dependencies Installation
Usage
Creating an Instance
use RusticAudio;
let mut audio_tool = new;
Recording Audio
if let Err = audio_tool.start_recording
// Stop recording
if let Err = audio_tool.stop_recording
Playing Audio
-
Play Original WAV:
if let Err = audio_tool.play_original_wav
-
Play Processed WAV:
if let Err = audio_tool.play_processed_wav
-
Play Unprocessed Opus:
if let Err = audio_tool.play_unprocessed_opus
-
Play Processed Opus:
if let Err = audio_tool.play_processed_opus
-
Stop Playback:
if let Err = audio_tool.stop_playback
Processing Audio
-
Apply DSP Effects:
if let Err = audio_tool.process_file
-
Encode to Opus:
if let Err = audio_tool.encode_to_opus
Managing Opus Settings
-
Set Opus Bitrate:
audio_tool.set_opus_bitrate; // Set bitrate to 64 kbps
-
Get Opus Bitrate:
let bitrate = audio_tool.get_opus_bitrate; println!;
Querying Audio Information
let info = audio_tool.get_audio_info;
println!;
println!;
println!;
Checking States
-
Check if Recording:
if audio_tool.is_recording
-
Check if Playing:
if audio_tool.is_playing
Flags
The library uses the following flags to manage state:
is_recording
: Indicates if recording is in progress.is_playing
: Indicates if processed audio playback is in progress.is_playing_original
: Indicates if original WAV playback is in progress.is_playing_unprocessed_opus
: Indicates if unprocessed Opus playback is in progress.
DSP Settings
The AudioProcessor
provides several configurable DSP settings to control audio processing. These settings can be adjusted to enable or disable specific effects or fine-tune their behavior.
Available DSP Settings
Setting | Type | Default Value | Description |
---|---|---|---|
sample_rate |
f32 |
48000.0 |
The sample rate of the audio in Hz. |
threshold_db |
f32 |
5.0 |
Threshold in dB for the spectral noise gate. |
amplitude_threshold_db |
f32 |
-20.0 |
Threshold in dB for the amplitude gate. |
amplitude_attack_ms |
f32 |
10.0 |
Attack time in milliseconds for the amplitude gate. |
amplitude_release_ms |
f32 |
100.0 |
Release time in milliseconds for the amplitude gate. |
amplitude_lookahead_ms |
f32 |
5.0 |
Lookahead time in milliseconds for the amplitude gate. |
gain_db |
f32 |
6.0 |
Gain boost in dB. |
limiter_threshold_db |
f32 |
-1.0 |
Threshold in dB for the lookahead limiter. |
limiter_release_ms |
f32 |
50.0 |
Release time in milliseconds for the limiter. |
limiter_lookahead_ms |
f32 |
5.0 |
Lookahead time in milliseconds for the limiter. |
lowpass_freq |
f32 |
20000.0 |
Low-pass filter cutoff frequency in Hz. |
highpass_freq |
f32 |
75.0 |
High-pass filter cutoff frequency in Hz. |
rms_target_db |
f32 |
-20.0 |
Target RMS level in dB for normalization. |
rms_enabled |
bool |
true |
Enables or disables RMS normalization. |
filters_enabled |
bool |
true |
Enables or disables high-pass and low-pass filters. |
spectral_gate_enabled |
bool |
true |
Enables or disables the spectral noise gate. |
amplitude_gate_enabled |
bool |
true |
Enables or disables the amplitude gate. |
gain_boost_enabled |
bool |
false |
Enables or disables gain boosting. |
limiter_enabled |
bool |
true |
Enables or disables the lookahead limiter. |
Example: Configuring DSP Settings
You can customize the DSP settings by modifying the AudioProcessor
instance:
use AudioProcessor;
let mut processor = new; // Set sample rate to 48 kHz
// Enable or disable specific effects
processor.rms_enabled = true;
processor.filters_enabled = true;
processor.spectral_gate_enabled = true;
// Adjust parameters
processor.gain_db = 10.0; // Increase gain boost to 10 dB
processor.lowpass_freq = 20000.0; // Set low-pass filter cutoff to 20 kHz
processor.highpass_freq = 75.0; // Set high-pass filter cutoff to 75 Hz
processor.limiter_threshold_db = -3.0; // Set limiter threshold to -3 dB
Processing an Audio File
Once the DSP settings are configured, you can process an audio file:
if let Err = processor.process_file
Opus Encoding Settings
The OpusEncoder
provides configurable settings for encoding audio to the Opus format. These settings allow you to control the bitrate and other encoding parameters.
Available Settings
Setting | Type | Default Value | Description |
---|---|---|---|
channels |
Channels |
Mono |
The number of audio channels (Mono or Stereo ). |
bitrate |
i32 |
12000 |
The bitrate for Opus encoding in bits per second (e.g., 12000 for 12 kbps). |
Example: Configuring Opus Encoder
You can customize the Opus encoder settings by modifying the OpusEncoder
instance:
use OpusEncoder;
let mut encoder = new;
// Set the bitrate to 12 kbps
encoder.set_bitrate;
// Get the current bitrate
let bitrate = encoder.get_bitrate;
println!;
Encoding a WAV File to Opus
To encode a WAV file to Opus format, use the encode_wav_to_opus
method:
if let Err = encoder.encode_wav_to_opus
How the Encoding Works
- Resampling: If the input WAV file is not 48 kHz, it will be resampled to 48 kHz.
- Mono Conversion: If the input WAV file is stereo, it will be converted to mono by isolating the left channel.
- Encoding: The audio is encoded to Opus format using the specified bitrate and channel configuration.
- Output: The encoded Opus file is saved to the specified output path.
Opus Header and Metadata
The encoder automatically adds the following metadata to the Opus file:
- OpusHead: Contains information about the Opus stream (e.g., version, channel count, sample rate).
- OpusTags: Contains vendor information.
License
This project is licensed under the GPLv3 License. See the LICENSE file for details.