From 70b227d4717630f399ef323eab9a115fd3c74ba9 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Tue, 12 Jul 2022 15:00:52 +0100 Subject: [PATCH] Get doctests working for mixer/mod.rs --- agb/examples/sfx/jump.wav | Bin 0 -> 2762 bytes agb/examples/sfx/my_bgm.wav | Bin 0 -> 14602 bytes agb/src/sound/mixer/mod.rs | 81 +++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 agb/examples/sfx/jump.wav create mode 100644 agb/examples/sfx/my_bgm.wav diff --git a/agb/examples/sfx/jump.wav b/agb/examples/sfx/jump.wav new file mode 100644 index 0000000000000000000000000000000000000000..e4f078cb7b835102d327829908aedbc657cfb018 GIT binary patch literal 2762 zcmZve%TJqE5XHw}^DtmY2;or(P(mo1D6LefU3O6xie?ZId`s~EiNqloj3dar{8{l`Reu5fSF}@4a}QO zJu_>w0eiam{KXj07k^p!b@BPaivs^YUHbFo_dh)T?#IX9K6zq)EWKX(i!63xZ*0#F ztz@70)M*8~Zxc3a^ESiZVY_2JmbC_}r*>rTY|B>dA6vJ5E83Y=Dc4QG5u3C*`^Kj2 zD;u(Y>#}yMS=m0=e`MdF#v9wV1FDs+ZaM3-c5RiU$~IM&n^mr; zk_XACO;KZx_c8YOfi?qzbFv=Vj=crfn(b2Ylsp+Q+{C3F1>bR%?AT?;@~s`w$(L&! zgMNqTWp+jHf$A<;ra|=x21eC07{I$W=1za71 zJ}~Wh7h*S0&QU7NQ$b8gj~sejqF50mn=rcqw}KMc^U*!N0V70k``NZ^MM@K zFw&38p`Lgh1mVqi5uNfl;{H@_^(kF%BN6LjF~i!O1ow=Mg$_9-9ICNLlSNtd(4_2~^1 zbDTfv9&AX*lO$FyQEU~KT8MAPo?9!g&S`Yl2g(OzopXN&Z&lXB#HKT`=kBQEgnmxI zRN^JE)`^3|d2w=rhhX?F6Gn4v+Bwq{lXfZEm4x4vg*0n0rmP?7X4l!>blv3U9;S$t z5C=td{imu8v^@{ZhaL`0~t4;y9hOR+K3()9dNq~^`>7jjAg zsnx2!?k-UG`6f=y49#PCpw#SW3+I$vRk5!VG3!3;^Vw3ShXbD!t9V5xQz&)Pq92_F zxx0$mn(uPpW;3HarHl{h{~k`r`Ds5+`VNL#7(@4z^-ElQfRE%nRStf{q}(5zs~4$r z=;vEH7D3o>gel|FrWLnCwlpp}N%IZEjXcz<8y%Oak!Kc8p!6f3ESf_)b8@isd+S_R z-0Q)h`W?g}(pj1WFI#Ya#?B59h00UzoUUe7P2@HA%_n!*kWb?oqHkuCzcdqcay6R< z@XCyz@ge6}*mMtWlWW^=j~b4bx|77kjL}?A=k$6Kr8}mFO5?aMqB`9xI)A$DcRW|z zM4Bv?+STvHgM;e+ROSd9Tf0njwe?zQ6lO+m`=%5r(PEs261CQ zIXgU41tcXRioBQEW9-edJ_!C^sjSHDWHQ za{&`qd^VnU(04cQSt>_NmDRFmsU|GSt69>+GA=S mRU@L2#I*Z*n`eobI+#>N5&F?rQN8qY?Jupxx<2b^^7}uY$*_?C literal 0 HcmV?d00001 diff --git a/agb/examples/sfx/my_bgm.wav b/agb/examples/sfx/my_bgm.wav new file mode 100644 index 0000000000000000000000000000000000000000..80ba543eb4a2e057e083c45c10102d2da81b756c GIT binary patch literal 14602 zcmd5-OK%)S5H7Fn#B0ZnLr5SA0V9G?BoqZCq~yo}OO_&#k_gU`5I1fSzm7kEcpgCF zf_Nwozr0Df zHsN#etl83KvxY6&rIjmJPdb0)sUE~KDf$;t45paGgYt>J)9QoG+pJiB)jZYNvFkWmp?U}_mAF%dO! z(=IHrFAt)X9eu$Y`RpRGQ{b=q;M4mvxCv6DQ)_ePrQ_PkAPB#Mz) z3q)eH9ruN4zK4ujz{0_d8~?|iwu3%r{5g>Du}{Pkd2M=iH*MXXIfBiEf)#IhTny%j z8q+_jgNVd}{M0q*3#m}4LbPU8fCm%RfluXx{2Iyowj)7Bq7FcYQy~A4ARcWZC&cA! zB@5cHCg>3(vJ#+`i@Qn#J}C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w3SH$5URg62zU0@7M!5bEZ?4tspi?hrr%In?@E6-m1 zvKD*2%NfHrYX})DCQj5(TGWv|w}Xa;w6q`oD&*z-#=(iY3D+Ok~)(XOMJ~ z)>E7DWnPTTY{07;QL8HHet1O`qu&90bBpx z)cMBQ8+E3=#M`SH?9pCYb;x@`OC3ZLg;jfTd-ue%m>i7xCCti2``*^Uth)KGE{9Ho z)@rR`a@nzN$m@~~GmCD%g+ESnP?A-zWj(~H*6oK2ALAX0-w*2gbgODO-g;C;uP@); iJ(Y2=Q{{KAscz=H{n6bJS9PzOewD1dkNsgE(E2}*?e|dt literal 0 HcmV?d00001 diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 16ca4cd8..9b72e599 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -35,9 +35,13 @@ //! To create a sound mixer, you will need to get it out of the [`Gba`](crate::Gba) struct //! as follows: //! -//! ``` +//! ```rust,no_run +//! # #![no_std] +//! # #![no_main] +//! # fn foo(gba: &mut agb::Gba) { //! let mut mixer = gba.mixer.mixer(); //! mixer.enable(); +//! # } //! ``` //! //! ## Doing the per-frame work @@ -48,22 +52,34 @@ //! //! Without interrupts: //! -//! ``` +//! ```rust,no_run +//! # #![no_std] +//! # #![no_main] +//! # fn foo(gba: &mut agb::Gba) { +//! # let mut mixer = gba.mixer.mixer(); +//! # let vblank = agb::interrupt::VBlank::get(); //! // Somewhere in your main loop: //! mixer.frame(); //! vblank.wait_for_vblank(); //! mixer.after_vblank(); +//! # } //! ``` //! //! Or with interrupts: //! -//! ``` +//! ```rust,no_run +//! # #![no_std] +//! # #![no_main] +//! # fn foo(gba: &mut agb::Gba) { +//! # let mut mixer = gba.mixer.mixer(); +//! # let vblank = agb::interrupt::VBlank::get(); //! // outside your main loop, close to initialisation //! let _mixer_interrupt = mixer.setup_interrupt_handler(); //! //! // inside your main loop //! mixer.frame(); //! vblank.wait_for_vblank(); +//! # } //! ``` //! //! Despite being high performance, the mixer still takes a sizable portion of CPU time (6-10% @@ -79,14 +95,21 @@ //! Use the [`include_wav!`](crate::include_wav) macro in order to load the sound. This will produce //! an error if your wav file is of the wrong frequency. //! -//! ``` +//! ```rust,no_run +//! # #![no_std] +//! # #![no_main] +//! # fn foo(gba: &mut agb::Gba) { +//! # let mut mixer = gba.mixer.mixer(); +//! # let vblank = agb::interrupt::VBlank::get(); +//! # use agb::{*, sound::mixer::*}; //! // Outside your main function in global scope: -//! const MY_CRAZY_SOUND: &[u8] = include_wav!("sfx/my_crazy_sound.wav"); +//! const MY_CRAZY_SOUND: &[u8] = include_wav!("examples/sfx/jump.wav"); //! //! // Then to play the sound: //! let mut channel = SoundChannel::new(MY_CRAZY_SOUND); //! channel.stereo(); //! let _ = mixer.play_sound(channel); // we don't mind if this sound doesn't actually play +//! # } //! ``` //! //! See the [`SoundChannel`] struct for more details on how you can configure the sounds to play. @@ -152,25 +175,39 @@ enum SoundPriority { /// play regardless of whether you have lots of sound effects playing. You create a high /// priority sound channel using [`new_high_priority`](SoundChannel::new_high_priority). /// -/// ``` +/// ```rust,no_run +/// # #![no_std] +/// # #![no_main] +/// # use agb::sound::mixer::*; +/// # use agb::*; /// // in global scope: -/// const MY_BGM: [u8] = include_wav!("sfx/my_bgm.wav"); +/// const MY_BGM: &[u8] = include_wav!("examples/sfx/my_bgm.wav"); /// /// // somewhere in code +/// # fn foo(gba: &mut Gba) { +/// # let mut mixer = gba.mixer.mixer(); /// let mut bgm = SoundChannel::new_high_priority(MY_BGM); /// bgm.stereo().should_loop(); /// let _ = mixer.play_sound(bgm); +/// # } /// ``` /// /// ## Playing a sound effect /// -/// ``` +/// ```rust,no_run +/// # #![no_std] +/// # #![no_main] +/// # use agb::sound::mixer::*; +/// # use agb::*; /// // in global scope: -/// const JUMP_SOUND: [u8] = include_wav!("sfx/jump_sound.wav"); +/// const JUMP_SOUND: &[u8] = include_wav!("examples/sfx/jump.wav"); /// /// // somewhere in code -/// let jump_sound = SoundChannel::new(MY_JUMP_SOUND); +/// # fn foo(gba: &mut Gba) { +/// # let mut mixer = gba.mixer.mixer(); +/// let jump_sound = SoundChannel::new(JUMP_SOUND); /// let _ = mixer.play_sound(jump_sound); +/// # } /// ``` pub struct SoundChannel { data: &'static [u8], @@ -198,13 +235,20 @@ impl SoundChannel { /// /// # Example /// - /// ``` + /// ```rust,no_run + /// # #![no_std] + /// # #![no_main] + /// # use agb::sound::mixer::*; + /// # use agb::*; + /// # fn foo(gba: &mut Gba) { + /// # let mut mixer = gba.mixer.mixer(); /// // in global scope: - /// const JUMP_SOUND: [u8] = include_wav!("sfx/jump_sound.wav"); + /// const JUMP_SOUND: &[u8] = include_wav!("examples/sfx/jump.wav"); /// /// // somewhere in code - /// let jump_sound = SoundChannel::new(MY_JUMP_SOUND); + /// let jump_sound = SoundChannel::new(JUMP_SOUND); /// let _ = mixer.play_sound(jump_sound); + /// # } /// ``` #[inline(always)] #[must_use] @@ -233,14 +277,21 @@ impl SoundChannel { /// /// # Example /// - /// ``` + /// ```rust,no_run + /// # #![no_std] + /// # #![no_main] + /// # use agb::sound::mixer::*; + /// # use agb::*; + /// # fn foo(gba: &mut Gba) { + /// # let mut mixer = gba.mixer.mixer(); /// // in global scope: - /// const MY_BGM: [u8] = include_wav!("sfx/my_bgm.wav"); + /// const MY_BGM: &[u8] = include_wav!("examples/sfx/my_bgm.wav"); /// /// // somewhere in code /// let mut bgm = SoundChannel::new_high_priority(MY_BGM); /// bgm.stereo().should_loop(); /// let _ = mixer.play_sound(bgm); + /// # } /// ``` #[inline(always)] #[must_use]