Skip to content

Commit

Permalink
Merge pull request #76 from solaoi/main
Browse files Browse the repository at this point in the history
update to v0.9.2
  • Loading branch information
solaoi authored Jul 18, 2023
2 parents 876a1c0 + a973e5c commit 3eb82fc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
35 changes: 18 additions & 17 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.4", features = ["api-all"] }
tauri = { version = "1.2.5", features = ["api-all"] }
vosk = "0.1.0"
cpal = "0.14.0"
dasp = "0.11"
Expand Down
25 changes: 24 additions & 1 deletion src-tauri/src/module/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,37 @@ impl Writer {
{
if let Ok(mut guard) = writer.try_lock() {
if let Some(writer) = guard.as_mut() {
let mut silence_passed = false;
for &sample in input.iter() {
let sample: U = cpal::Sample::from(&sample);
writer.0.write_sample(sample).ok();
if Self::to_float(&sample).abs() > 0.01 {
silence_passed = true;
}
if silence_passed {
writer.0.write_sample(sample).ok();
}
}
}
}
}

fn to_float<S: cpal::Sample>(sample: &S) -> f32 {
let sample_f32 = sample.to_f32();
let sample_i16 = sample.to_i16();
let sample_u16 = sample.to_u16();
let max_abs = sample_f32
.abs()
.max(sample_i16.abs() as f32)
.max(sample_u16 as f32);
if max_abs == sample_f32.abs() {
sample_f32
} else if max_abs == sample_i16.abs() as f32 {
sample_i16 as f32 / i16::MAX as f32
} else {
(sample_u16 as f32 - u16::MAX as f32 / 2.0) / (u16::MAX as f32 / 2.0)
}
}

fn sample_format(format: cpal::SampleFormat) -> hound::SampleFormat {
match format {
cpal::SampleFormat::U16 => hound::SampleFormat::Int,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Lycoris",
"version": "0.9.1"
"version": "0.9.2"
},
"tauri": {
"allowlist": {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1450,9 +1450,9 @@ scheduler@^0.23.0:
loose-envify "^1.1.0"

semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

simple-swizzle@^0.2.2:
version "0.2.2"
Expand Down

0 comments on commit 3eb82fc

Please sign in to comment.