-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.rs
More file actions
73 lines (68 loc) · 2.11 KB
/
render.rs
File metadata and controls
73 lines (68 loc) · 2.11 KB
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
use std::num::NonZero;
use torque_tracker_engine::{
PlaybackSettings,
audio_processing::{Interpolation, playback::PlaybackState},
file::impulse_format::{header::PatternOrder, sample::VibratoWave},
project::{
event_command::NoteCommand,
note_event::{Note, NoteEvent, VolumeEffect},
pattern::InPatternPosition,
song::Song,
},
sample::{Sample, SampleMetaData},
};
fn main() {
let mut reader = hound::WavReader::open("test-files/770_Hz_Tone.wav").unwrap();
let spec = reader.spec();
println!("sample specs: {spec:?}");
assert!(spec.channels == 1);
let sample_data = reader
.samples::<i16>()
.map(|result| <f32 as dasp::Sample>::from_sample(result.unwrap()));
let sample = Sample::new_mono(sample_data);
let meta = SampleMetaData {
sample_rate: NonZero::new(spec.sample_rate).unwrap(),
default_volume: 200,
global_volume: 200,
default_pan: None,
vibrato_speed: 0,
vibrato_depth: 0,
vibrato_rate: 0,
vibrato_waveform: VibratoWave::Sine,
base_note: Note::new(20).unwrap(),
};
let mut song: Song = Song::default();
song.pattern_order[0] = PatternOrder::Number(0);
song.samples[0] = Some((meta, sample));
song.patterns[0].set_event(
InPatternPosition { row: 0, channel: 0 },
NoteEvent {
note: Note::default(),
sample_instr: 0,
vol: VolumeEffect::None,
command: NoteCommand::None,
},
);
song.patterns[0].set_event(
InPatternPosition { row: 0, channel: 2 },
NoteEvent {
note: Note::default(),
sample_instr: 0,
vol: VolumeEffect::None,
command: NoteCommand::None,
},
);
let mut playback = PlaybackState::new(
&song,
NonZero::new(44100).unwrap(),
PlaybackSettings::Order {
idx: 0,
should_loop: true,
},
)
.unwrap();
let iter = playback.iter::<{ Interpolation::Nearest as u8 }>(&song);
for _ in iter.take(50) {
// dbg!(frame);
}
}