mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
fix sample preview crashes
This commit is contained in:
parent
bdd3e31403
commit
e1eaa51d26
3 changed files with 13 additions and 8 deletions
|
|
@ -75,7 +75,7 @@ pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
|
|||
state.cursor.0 = (state.cursor.0 + 1) % (state.mapped.len() + state.unmapped.len());
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('t'), NONE, "/sampler/play", "play current sample", |state: &mut Sampler| {
|
||||
[Char('p'), NONE, "/sampler/play", "play current sample", |state: &mut Sampler| {
|
||||
if let Some(sample) = state.sample() {
|
||||
state.voices.write().unwrap().push(Sample::play(sample, 0, &100.into()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,11 +255,17 @@ impl Sample {
|
|||
while sample.channels.len() < spec.channels.count() {
|
||||
sample.channels.push(vec![]);
|
||||
}
|
||||
let mut samples = SampleBuffer::new(decoded.frames() as u64, spec);
|
||||
samples.copy_interleaved_ref(decoded);
|
||||
for frame in samples.samples().chunks(spec.channels.count()) {
|
||||
for (chan, frame) in frame.iter().enumerate() {
|
||||
sample.channels[chan].push(*frame)
|
||||
// Load sample
|
||||
let mut samples = SampleBuffer::new(
|
||||
decoded.frames() as u64,
|
||||
spec
|
||||
);
|
||||
if samples.capacity() > 0 {
|
||||
samples.copy_interleaved_ref(decoded);
|
||||
for frame in samples.samples().chunks(spec.channels.count()) {
|
||||
for (chan, frame) in frame.iter().enumerate() {
|
||||
sample.channels[chan].push(*frame)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ impl Iterator for Voice {
|
|||
if self.position < sample.end {
|
||||
let position = self.position;
|
||||
self.position = self.position + 1;
|
||||
return Some([
|
||||
return sample.channels[0].get(position).map(|amplitude|[
|
||||
sample.channels[0][position] * self.velocity,
|
||||
sample.channels[0][position] * self.velocity,
|
||||
])
|
||||
|
|
@ -28,4 +28,3 @@ impl Iterator for Voice {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue