Skip to content

Commit 47f59ca

Browse files
committed
Compact get_buffer impls
1 parent 1ac9415 commit 47f59ca

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

ctru-rs/examples/audio-filters.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ fn fill_buffer(audio_data: &mut Buffer, frequency: f32) {
3636
let result = (sample * amplitude) as i16;
3737

3838
// Stereo samples are interleaved: left and right channels.
39-
audio_data.0[i] = [result, result];
39+
if audio_data.0.len() <= i {
40+
audio_data.0.push([result, result]);
41+
} else {
42+
audio_data.0[i] = [result, result];
43+
}
4044
}
4145
}
4246

ctru-rs/src/services/ndsp/wave.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109

110110
/// Returns a slice to the audio data (on the LINEAR memory).
111111
pub fn get_buffer(&self) -> &[u8] {
112-
self.buffer.as_ref()
112+
self.get_raw_buffer().as_ref()
113113
}
114114

115115
/// Returns a mutable slice to the audio data (on the LINEAR memory).
@@ -122,12 +122,7 @@ where
122122
where
123123
Buffer: AsMut<[u8]>,
124124
{
125-
match self.status() {
126-
Status::Playing | Status::Queued => {
127-
Err(Error::WaveBusy(self.played_on_channel.unwrap()))
128-
}
129-
_ => Ok(self.buffer.as_mut()),
130-
}
125+
Ok(self.get_raw_buffer_mut()?.as_mut())
131126
}
132127

133128
/// Returns this wave's playback status.

0 commit comments

Comments
 (0)