Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize core crate #42

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Please contact me on Discord (user: ixml) to check what is being worked on and w

At this stage the focus is on the following:
- Try to get the tests and benchmarks working
- Roughly follow the file structure of Steam Audio
- Write Rusty code
- Don't worry too much about performance yet (leave a 'todo' if necessary)
- Look for opportunities to make use of the Rust ecosystem
Expand Down
2 changes: 1 addition & 1 deletion crates/phonon-fmod/examples/create_dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libfmod::ffi::{
FMOD_VECTOR,
};
use libfmod::{Error, System};
use phonon::direct_simulator::DirectSoundPath;
use phonon::simulators::direct::DirectSoundPath;
use phonon_fmod::create_dsp_description;
use std::io;
use std::io::BufRead;
Expand Down
10 changes: 5 additions & 5 deletions crates/phonon-fmod/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use libfmod::ffi::{
FMOD_DSP_STATE, FMOD_ERR_DSP_DONTPROCESS, FMOD_ERR_INVALID_PARAM, FMOD_ERR_MEMORY, FMOD_OK,
FMOD_RESULT, FMOD_SPEAKERMODE_STEREO,
};
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::direct_effect::{DirectEffect, TransmissionType};
use phonon::direct_simulator::DirectSoundPath;
use phonon::panning_effect::PanningEffect;
use phonon::speaker_layout::SpeakerLayoutType;
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::dsp::speaker_layout::SpeakerLayoutType;
use phonon::effects::direct::{DirectEffect, TransmissionType};
use phonon::effects::panning::PanningEffect;
use phonon::simulators::direct::DirectSoundPath;
use std::os::raw::{c_char, c_float, c_int, c_uint, c_void};
use std::ptr::{null_mut, slice_from_raw_parts_mut};
use std::slice;
Expand Down
8 changes: 4 additions & 4 deletions crates/phonon-fmod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ use libfmod::ffi::{
FMOD_DSP_PARAMETER_ATTENUATION_RANGE, FMOD_DSP_PARAMETER_OVERALLGAIN, FMOD_PLUGIN_SDK_VERSION,
};
use libfmod::DspDescription;
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::direct_effect::{
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::effects::direct::{
DirectApplyFlags, DirectEffect, DirectEffectParameters, TransmissionType,
};
use phonon::direct_simulator::DirectSoundPath;
use phonon::panning_effect::{PanningEffect, PanningEffectParameters};
use phonon::effects::panning::{PanningEffect, PanningEffectParameters};
use phonon::simulators::direct::DirectSoundPath;
use std::ffi::CString;
use std::os::raw::{c_char, c_int};
use std::ptr::null_mut;
Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-kira/examples/direct_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use kira::manager::backend::cpal::CpalBackend;
use kira::manager::{AudioManager, AudioManagerSettings};
use kira::sound::static_sound::StaticSoundData;
use kira::track::TrackBuilder;
use phonon::direct_effect::{DirectApplyFlags, DirectEffectParameters, TransmissionType};
use phonon::direct_simulator::DirectSoundPath;
use phonon::effects::direct::{DirectApplyFlags, DirectEffectParameters, TransmissionType};
use phonon::simulators::direct::DirectSoundPath;

use phonon_kira::direct_effect::builder::DirectEffectBuilder;

Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-kira/examples/reverb_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use kira::manager::backend::cpal::CpalBackend;
use kira::manager::{AudioManager, AudioManagerSettings};
use kira::sound::static_sound::StaticSoundData;
use kira::track::TrackBuilder;
use phonon::reverb_effect::ReverbEffectParams;
use phonon::reverb_estimator::Reverb;
use phonon::dsp::reverb_estimator::Reverb;
use phonon::effects::reverb::ReverbEffectParams;

use phonon_kira::reverb_effect::builder::ReverbEffectBuilder;

Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-kira/src/direct_effect/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::command_writers_and_readers;
use super::effect::DirectEffectWrapped;
use super::handle::DirectEffectHandle;
use kira::effect::{Effect, EffectBuilder};
use phonon::direct_effect::DirectEffectParameters;
use phonon::panning_effect::PanningEffectParameters;
use phonon::effects::direct::DirectEffectParameters;
use phonon::effects::panning::PanningEffectParameters;

#[derive(Debug, Copy, Clone)]
pub struct DirectEffectBuilder {
Expand Down
8 changes: 4 additions & 4 deletions crates/phonon-kira/src/direct_effect/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use kira::clock::clock_info::ClockInfoProvider;
use kira::effect::Effect;
use kira::modulator::value_provider::ModulatorValueProvider;
use kira::Frame;
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::direct_effect::{DirectEffect, DirectEffectParameters};
use phonon::panning_effect::{PanningEffect, PanningEffectParameters};
use phonon::speaker_layout::SpeakerLayoutType;
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::dsp::speaker_layout::SpeakerLayoutType;
use phonon::effects::direct::{DirectEffect, DirectEffectParameters};
use phonon::effects::panning::{PanningEffect, PanningEffectParameters};

pub(crate) struct DirectEffectWrapped {
command_readers: CommandReaders,
Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-kira/src/direct_effect/handle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::CommandWriters;
use phonon::direct_effect::DirectEffectParameters;
use phonon::panning_effect::PanningEffectParameters;
use phonon::effects::direct::DirectEffectParameters;
use phonon::effects::panning::PanningEffectParameters;

/// Controls an EQ effect.
pub struct DirectEffectHandle {
Expand Down
4 changes: 2 additions & 2 deletions crates/phonon-kira/src/direct_effect/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use kira::command::{CommandReader, CommandWriter};
use phonon::direct_effect::DirectEffectParameters;
use phonon::panning_effect::PanningEffectParameters;
use phonon::effects::direct::DirectEffectParameters;
use phonon::effects::panning::PanningEffectParameters;

pub mod builder;
pub(crate) mod effect;
Expand Down
6 changes: 3 additions & 3 deletions crates/phonon-kira/src/eq_effect/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use kira::clock::clock_info::ClockInfoProvider;
use kira::effect::Effect;
use kira::modulator::value_provider::ModulatorValueProvider;
use kira::Frame;
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::eq_effect::{EqEffect, EqEffectParameters};
use phonon::gain_effect::{GainEffect, GainEffectParameters};
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::effects::eq::{EqEffect, EqEffectParameters};
use phonon::effects::gain::{GainEffect, GainEffectParameters};

pub(crate) struct EqEffectWrapped {
command_readers: CommandReaders,
Expand Down
6 changes: 3 additions & 3 deletions crates/phonon-kira/src/reverb_effect/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use kira::clock::clock_info::ClockInfoProvider;
use kira::effect::Effect;
use kira::modulator::value_provider::ModulatorValueProvider;
use kira::Frame;
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::reverb_effect::{ReverbEffect, ReverbEffectParams};
use phonon::reverb_estimator::Reverb;
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::dsp::reverb_estimator::Reverb;
use phonon::effects::reverb::{ReverbEffect, ReverbEffectParams};

pub(crate) struct ReverbEffectWrapped {
command_readers: CommandReaders,
Expand Down
2 changes: 1 addition & 1 deletion crates/phonon/benches/audio_buffer_bench.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use phonon::audio_buffer::AudioBuffer;
use phonon::dsp::audio_buffer::AudioBuffer;

fn mix_buffers(in1: AudioBuffer<1>) -> AudioBuffer<1> {
let mut in2: AudioBuffer<1> = AudioBuffer::new(200);
Expand Down
6 changes: 3 additions & 3 deletions crates/phonon/benches/direct_effect_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
//

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::direct_effect::{
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::effects::direct::{
DirectApplyFlags, DirectEffect, DirectEffectParameters, TransmissionType,
};
use phonon::direct_simulator::DirectSoundPath;
use phonon::simulators::direct::DirectSoundPath;
use rand::Rng;

pub fn criterion_benchmark(c: &mut Criterion) {
Expand Down
6 changes: 3 additions & 3 deletions crates/phonon/benches/panning_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use glam::Vec3;
use phonon::audio_buffer::AudioBuffer;
use phonon::panning_effect::{PanningEffect, PanningEffectParameters};
use phonon::speaker_layout::SpeakerLayoutType;
use phonon::dsp::audio_buffer::AudioBuffer;
use phonon::dsp::speaker_layout::SpeakerLayoutType;
use phonon::effects::panning::{PanningEffect, PanningEffectParameters};
use rand::Rng;

pub fn criterion_benchmark(c: &mut Criterion) {
Expand Down
6 changes: 3 additions & 3 deletions crates/phonon/benches/reverb_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use phonon::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::reverb_effect::{ReverbEffect, ReverbEffectParams};
use phonon::reverb_estimator::Reverb;
use phonon::dsp::audio_buffer::{AudioBuffer, AudioSettings};
use phonon::dsp::reverb_estimator::Reverb;
use phonon::effects::reverb::{ReverbEffect, ReverbEffectParams};

fn bench_reverb(input: f32) -> f32 {
const NUM_RUNS: i32 = 100_000; //todo this should be a Criterion argument probably
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {

#[test]
fn test_delay_buffer() {
let mut delay = Delay {
let delay = Delay {
ring_buffer: vec![1.0, 2.0, 3.0],
cursor: 0,
read_cursor: 0,
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions crates/phonon/src/dsp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Processing of audio samples.

pub mod audio_buffer;
pub mod bands;
pub mod delay;
pub mod iir;
pub mod reverb_estimator;
pub mod speaker_layout;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::bands::NUM_BANDS;
use crate::dsp::bands::NUM_BANDS;

pub struct Reverb {
pub reverb_times: [f32; NUM_BANDS],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// limitations under the License.
//

use crate::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::bands::NUM_BANDS;
use crate::dsp::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::dsp::bands::NUM_BANDS;
use bitflags::bitflags;
use std::cmp::PartialEq;

use crate::direct_simulator::DirectSoundPath;
use crate::eq_effect::{EqEffect, EqEffectParameters};
use crate::gain_effect::{GainEffect, GainEffectParameters};
use crate::effects::eq::{EqEffect, EqEffectParameters};
use crate::effects::gain::{GainEffect, GainEffectParameters};
use crate::simulators::direct::DirectSoundPath;

bitflags! {
//todo check if these are all necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// limitations under the License.
//

use crate::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::dsp::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use ndarray::{Array, Array1};

use crate::bands::{HIGH_CUTOFF_FREQUENCIES, LOW_CUTOFF_FREQUENCIES, NUM_BANDS};
use crate::iir::{IIRFilterer, IIR};
use crate::dsp::bands::{HIGH_CUTOFF_FREQUENCIES, LOW_CUTOFF_FREQUENCIES, NUM_BANDS};
use crate::dsp::iir::{IIRFilterer, IIR};

pub struct EqEffectParameters {
pub gains: [f32; NUM_BANDS],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::dsp::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};

const NUM_INTERPOLATION_FRAMES: usize = 4;

Expand Down
8 changes: 8 additions & 0 deletions crates/phonon/src/effects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Higher level audio effects which are controlled by parameters.
//! In some cases these parameters are intended to be set by the simulators.

pub mod direct;
pub mod eq;
pub mod gain;
pub mod panning;
pub mod reverb;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// limitations under the License.
//

use crate::audio_buffer::{AudioBuffer, AudioEffectState};
use crate::speaker_layout::{SpeakerLayout, SpeakerLayoutType};
use crate::dsp::audio_buffer::{AudioBuffer, AudioEffectState};
use crate::dsp::speaker_layout::{SpeakerLayout, SpeakerLayoutType};
use glam::Vec3;
use std::f32::consts::PI;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// limitations under the License.
//

use crate::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::bands::NUM_BANDS;
use crate::delay::Delay;
use crate::reverb_estimator::Reverb;
use crate::dsp::audio_buffer::{AudioBuffer, AudioEffectState, AudioSettings};
use crate::dsp::bands::NUM_BANDS;
use crate::dsp::delay::Delay;
use crate::dsp::reverb_estimator::Reverb;

use crate::iir::{IIRFilterer, IIR};
use crate::dsp::iir::{IIRFilterer, IIR};
use derive_deref::{Deref, DerefMut};
use ndarray::{s, Array, Array2, ArrayView, Axis};
use rand::Rng;
Expand Down
30 changes: 4 additions & 26 deletions crates/phonon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,9 @@
#[macro_use]
extern crate serde;

pub mod air_absorption;
pub mod audio_buffer;
pub mod bands;
pub mod context;
pub mod coordinate_space;
pub mod delay;
pub mod direct_effect;
pub mod direct_simulator;
pub mod directivity;
pub mod distance_attenuation;
pub mod eq_effect;
pub mod gain_effect;
pub mod hit;
pub mod iir;
pub mod instanced_mesh;
pub mod material;
pub mod mesh;
pub mod panning_effect;
pub mod propagation_medium;
pub mod ray;
pub mod reverb_effect;
pub mod reverb_estimator;
pub mod sampling;
pub mod dsp;
pub mod effects;
pub mod models;
pub mod scene;
pub mod speaker_layout;
mod sphere;
pub mod static_mesh;
pub mod triangle;
pub mod simulators;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::bands::NUM_BANDS;
use crate::dsp::bands::NUM_BANDS;

pub trait AirAbsorptionModel {
fn evaluate(&self, distance: f32, band: usize) -> f32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::coordinate_space::CoordinateSpace3f;
use crate::scene::coordinate_space::CoordinateSpace3f;
use glam::Vec3;

// todo: Describe what these do and what the limits are
Expand Down
7 changes: 7 additions & 0 deletions crates/phonon/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Models for audio propagation/attenuation. Each should have a good default
//! but the user should be able to use a custom model as well.

pub mod air_absorption;
pub mod directivity;
pub mod distance_attenuation;
pub mod propagation_medium;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::material::Material;
use crate::scene::material::Material;
use glam::Vec3;

#[derive(Copy, Clone, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// limitations under the License.
//

use crate::hit::Hit;
use crate::ray::Ray;
use crate::scene::hit::Hit;
use crate::scene::ray::Ray;
use crate::scene::Scene;
use glam::Mat4;
use std::sync::{Arc, Mutex};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::bands::NUM_BANDS;
use crate::dsp::bands::NUM_BANDS;

/// An acoustic material. The acoustic surface properties of an object are represented using multi-band absorption
/// and transmission loss coefficients, and a single random-incidence scattering coefficient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
//

use crate::triangle::Triangle;
use crate::scene::triangle::Triangle;
use glam::Vec3;
use ndarray::Array1;
use parry3d::math::Point;
Expand Down
Loading