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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#[allow(unused_imports)]
use rumu::{
instruments::{Instrument, PianoStackoverflow, PianoVideo, PianoWOver, Sinus, Tangent, Violin},
output::{Output, PlainOutput},
sheet::Sheet,
Hertz, Samples, Semitones, Wave, BPM,
};
#[cfg(feature = "ffmpeg")]
#[allow(unused_imports)]
use rumu::output::ffmpeg_output::{AACOutput, MP3Output, OpusOutput};
#[test]
fn test_sine() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut sine_instrument: Sinus = Default::default();
let rate: Samples = Default::default();
let wave: Vec<_> = tones
.into_iter()
.map(|tone| {
sine_instrument
.play(tone as f64, rate, 100f64, 1f64, 1f64)
.to_vec()
})
.collect();
let wave = Wave::new(wave.into_iter().flatten().collect());
let plain_output = PlainOutput::default();
plain_output.save(wave, rate, "test.bin")?;
Ok(())
}
#[test]
fn test_tangent() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut tangent_instrument: Tangent = Default::default();
let rate: Samples = Default::default();
let wave: Vec<_> = tones
.into_iter()
.map(|tone| {
tangent_instrument
.play(tone as f64, rate, 100f64, 1f64, 1f64)
.to_vec()
})
.collect();
let wave = Wave::new(wave.into_iter().flatten().collect());
let plain_output = PlainOutput::default();
plain_output.save(wave, rate, "test.bin")?;
Ok(())
}
#[test]
fn test_piano_wover() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut tangent_instrument: PianoWOver = Default::default();
let rate: Samples = Default::default();
let wave: Vec<_> = tones
.into_iter()
.map(|tone| {
tangent_instrument
.play(tone as f64, rate, 100f64, 1f64, 2f64)
.to_vec()
})
.collect();
let wave = Wave::new(wave.into_iter().flatten().collect());
let plain_output = PlainOutput::default();
plain_output.save(wave, rate, "test.bin")?;
Ok(())
}
#[test]
#[cfg(feature = "ffmpeg")]
fn test_ffmpeg_piano_video() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut piano_wover_instrument: PianoVideo = Default::default();
let rate: Samples = 48000f64.into();
let wave = tones.into_iter().map(|tone| {
piano_wover_instrument
.play(tone as f64, rate, 120f64, 1f64, 2f64)
.to_vec()
});
let wave = Wave::new(wave.flatten().collect());
let opus_output = OpusOutput::default();
opus_output.save(wave, rate, "test.opus")?;
Ok(())
}
#[test]
#[cfg(feature = "ffmpeg")]
fn test_ffmpeg_piano_stackoverflow() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut piano_wover_instrument: PianoStackoverflow = Default::default();
let rate: Samples = 48000f64.into();
let wave = tones.into_iter().map(|tone| {
piano_wover_instrument
.play(tone as f64, rate, 120f64, 1f64, 1f64)
.to_vec()
});
let wave = Wave::new(wave.flatten().collect());
let opus_output = OpusOutput::default();
opus_output.save(wave, rate, "test.opus")?;
Ok(())
}
#[test]
#[cfg(feature = "ffmpeg")]
fn test_ffmpeg_violin() -> Result<(), Box<dyn std::error::Error>> {
let tones = [-9, -7, -5, -4, -2, 0, 2, 3, 2, 0, -2, -4, -5, -7, -9];
let mut piano_wover_instrument: Violin = Default::default();
let rate: Samples = 48000f64.into();
let wave = tones.into_iter().map(|tone| {
piano_wover_instrument
.play(tone as f64, rate, 180f64, 1f64, 0.5f64)
.to_vec()
});
let wave = Wave::new(wave.flatten().collect());
let opus_output = OpusOutput::default();
opus_output.save(wave, rate, "test.opus")?;
Ok(())
}
#[test]
#[cfg(feature = "ffmpeg")]
fn test_ffmpeg_piano_from_sheet() -> Result<(), Box<dyn std::error::Error>> {
let source = std::fs::read_to_string("songs/Ievan Polkka.rumu")?;
let mut sheet: Sheet = source.parse()?;
println!("sheet = {sheet:?}");
let wave: Wave = (&mut sheet).into();
let rate = Samples::default();
let opus_output = OpusOutput::default();
opus_output.save(wave, rate, "test.opus")?;
Ok(())
}
|