-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: harudagondi <giogdeasis@gmail.com>
- Loading branch information
1 parent
8efed7d
commit 2e98c5f
Showing
13 changed files
with
229 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,4 +93,4 @@ jobs: | |
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: -- -D warnings | ||
args: -- -D warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
### Added | ||
- Support for mono. | ||
- Support for `oddio::Sine` and `oddio::SpatialScene`. | ||
|
||
### Changed | ||
- `Audio::play` now returns `AudioHandle` and `AudioSink`. | ||
- All public facing structs now need `F` to be specified, where `F` is either `Mono` or `Stereo`. | ||
|
||
## [0.1.0] - 2022-07-01 | ||
- Released `bevy_oddio` 0.1 🎉 | ||
|
||
[Unreleased]: https://github.com/harudagondi/bevy_oddio/compare/v0.1.0..HEAD | ||
[0.1.0]: https://github.com/harudagondi/bevy_oddio/releases/tag/v0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use bevy::{ | ||
prelude::{Deref, DerefMut}, | ||
reflect::TypeUuid, | ||
}; | ||
use oddio::{Frame, Sample}; | ||
|
||
/// Internal trait to convert frames. | ||
pub trait FromFrame<F: Frame> { | ||
/// The number of channels of the given frame. | ||
const CHANNELS: usize; | ||
/// Convert given frame to the implementing type. | ||
fn from_frame(f: F) -> Self; | ||
} | ||
|
||
impl<const N: usize> FromFrame<[Sample; N]> for [Sample; N] { | ||
const CHANNELS: usize = N; | ||
|
||
fn from_frame(f: [Sample; N]) -> Self { | ||
f | ||
} | ||
} | ||
|
||
impl FromFrame<[Sample; 1]> for Sample { | ||
const CHANNELS: usize = 1; | ||
|
||
fn from_frame(f: [Sample; 1]) -> Self { | ||
f[0] | ||
} | ||
} | ||
|
||
macro_rules! impl_frame { | ||
($(#[$meta:meta])* $name:ident, $n:literal, $uuid:expr) => { | ||
#[repr(transparent)] | ||
#[derive(TypeUuid, Deref, DerefMut, Clone, Copy)] | ||
#[uuid = $uuid] | ||
$(#[$meta])* | ||
pub struct $name([Sample; $n]); | ||
|
||
impl From<$name> for [Sample; $n] { | ||
fn from(x: $name) -> Self { | ||
x.0 | ||
} | ||
} | ||
|
||
impl From<[Sample; $n]> for $name { | ||
fn from(x: [Sample; $n]) -> Self { | ||
$name(x) | ||
} | ||
} | ||
|
||
impl FromFrame<[Sample; $n]> for $name { | ||
const CHANNELS: usize = $n; | ||
|
||
fn from_frame(f: [Sample; $n]) -> Self { | ||
f.into() | ||
} | ||
} | ||
|
||
impl Frame for $name { | ||
const ZERO: Self = $name(Frame::ZERO); | ||
|
||
fn channels(&self) -> &[Sample] { | ||
self.0.channels() | ||
} | ||
|
||
fn channels_mut(&mut self) -> &mut [Sample] { | ||
self.0.channels_mut() | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_frame!( | ||
/// A frame with a single channel. | ||
Mono, | ||
1, | ||
"43915b3a-332c-4104-81ff-3b68bdb192c3" | ||
); | ||
impl_frame!( | ||
/// A frame with two channels. | ||
Stereo, | ||
2, | ||
"94ca7739-0a77-4142-91de-b7150fecc689" | ||
); | ||
|
||
/// Convert a mutable reference of a list of samples to the corresponding newtyped frame. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function must uphold the following invariants: | ||
/// | ||
/// 1. `F` must have equivalent memory representation to `[Sample; N]`. | ||
/// 2. `N` must be a number where 64 mod `N` == 0. | ||
pub unsafe fn frame_n<F: Frame + FromFrame<[Sample; N]>, const N: usize>( | ||
input: &mut [Sample], | ||
) -> &mut [F] { | ||
let slice: &mut [[Sample; N]] = | ||
core::slice::from_raw_parts_mut(input.as_mut_ptr().cast(), input.len() / N); | ||
&mut *(slice as *mut [[Sample; N]] as *mut [F]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.