mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +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());
|
state.cursor.0 = (state.cursor.0 + 1) % (state.mapped.len() + state.unmapped.len());
|
||||||
Ok(true)
|
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() {
|
if let Some(sample) = state.sample() {
|
||||||
state.voices.write().unwrap().push(Sample::play(sample, 0, &100.into()));
|
state.voices.write().unwrap().push(Sample::play(sample, 0, &100.into()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -255,11 +255,17 @@ impl Sample {
|
||||||
while sample.channels.len() < spec.channels.count() {
|
while sample.channels.len() < spec.channels.count() {
|
||||||
sample.channels.push(vec![]);
|
sample.channels.push(vec![]);
|
||||||
}
|
}
|
||||||
let mut samples = SampleBuffer::new(decoded.frames() as u64, spec);
|
// Load sample
|
||||||
samples.copy_interleaved_ref(decoded);
|
let mut samples = SampleBuffer::new(
|
||||||
for frame in samples.samples().chunks(spec.channels.count()) {
|
decoded.frames() as u64,
|
||||||
for (chan, frame) in frame.iter().enumerate() {
|
spec
|
||||||
sample.channels[chan].push(*frame)
|
);
|
||||||
|
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 {
|
if self.position < sample.end {
|
||||||
let position = self.position;
|
let position = self.position;
|
||||||
self.position = self.position + 1;
|
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,
|
||||||
sample.channels[0][position] * self.velocity,
|
sample.channels[0][position] * self.velocity,
|
||||||
])
|
])
|
||||||
|
|
@ -28,4 +28,3 @@ impl Iterator for Voice {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue