1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
/// Construct an audio buffer. /// /// This is useful when testing. /// /// # Examples /// /// ```rust /// let buf = rotary::dynamic![[0.0; 1024]; 2]; /// /// let mut expected = vec![0.0; 1024]; /// /// assert_eq!(&buf[0], &expected[..]); /// assert_eq!(&buf[1], &expected[..]); /// ``` #[macro_export] macro_rules! dynamic { // Branch of the macro used when we can perform a literal instantiation of // the audio buffer. // // This is typically more performant, since it doesn't require looping and // writing through the buffer. ([$sample:expr; $frames:literal]; $channels:literal) => { $crate::Dynamic::from_array([[$sample; $frames]; $channels]); }; // Branch of the macro used when we can evaluate an expression that is // built into an audio buffer. // // `$sample`, `$frames`, and `$channels` are all expected to implement // `Copy`. `$frames` and `$channels` should evaluate to `usize`. ([$sample:expr; $frames:expr]; $channels:expr) => {{ let value = $sample; let mut buffer = $crate::Dynamic::with_topology($channels, $frames); for chan in &mut buffer { for f in chan { *f = value; } } buffer }}; } /// Construct a sequential audio buffer. /// /// This is useful for testing. /// /// # Examples /// /// ```rust /// let buf = rotary::sequential![[0.0; 1024]; 2]; /// /// let mut expected = vec![0.0; 1024]; /// /// assert_eq!(&buf[0], &expected[..]); /// assert_eq!(&buf[1], &expected[..]); /// ``` #[macro_export] macro_rules! sequential { // Branch of the macro used when we can evaluate an expression that is // built into a sequential audio buffer. // // `$sample`, `$frames`, and `$channels` are all expected to implement // `Copy`. `$frames` and `$channels` should evaluate to `usize`. ([$sample:expr; $frames:expr]; $channels:expr) => { $crate::Sequential::from_vec(vec![$sample; $channels * $frames], $channels, $frames) }; } /// Construct an interleaved audio buffer. /// /// This is useful for testing. /// /// # Examples /// /// ```rust /// let buf = rotary::interleaved![[0.0; 1024]; 2]; /// /// let mut expected = vec![0.0; 1024]; /// /// assert!(buf.get(0).unwrap().iter().eq(&expected[..])); /// assert!(buf.get(1).unwrap().iter().eq(&expected[..])); /// ``` #[macro_export] macro_rules! interleaved { // Branch of the macro used when we can evaluate an expression that is // built into a interleaved audio buffer. // // `$sample`, `$frames`, and `$channels` are all expected to implement // `Copy`. `$frames` and `$channels` should evaluate to `usize`. ([$sample:expr; $frames:expr]; $channels:expr) => { $crate::Interleaved::from_vec(vec![$sample; $channels * $frames], $channels, $frames) }; }