1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: format most examples and tutorials, add them to v test-cleancode (#9826)

This commit is contained in:
Lukas Neubert
2021-04-20 16:16:35 +02:00
committed by GitHub
parent dff50686d6
commit 16e79bc3ca
38 changed files with 471 additions and 433 deletions

View File

@ -117,13 +117,12 @@ struct RIFFFormat {
}
fn read_wav_file_samples(fpath string) ?[]f32 {
mut res := []f32{}
// eprintln('> read_wav_file_samples: $fpath -------------------------------------------------')
mut bytes := os.read_bytes(fpath) ?
mut pbytes := &byte(bytes.data)
mut offset := u32(0)
rh := unsafe{ &RIFFHeader(pbytes) }
rh := unsafe { &RIFFHeader(pbytes) }
// eprintln('rh: $rh')
if rh.riff != [byte(`R`), `I`, `F`, `F`]! {
return error('WAV should start with `RIFF`')
@ -141,7 +140,7 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
break
}
//
ch := unsafe{ &RIFFChunkHeader(pbytes + offset) }
ch := unsafe { &RIFFChunkHeader(pbytes + offset) }
offset += 8 + ch.chunk_size
// eprintln('ch: $ch')
// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
@ -176,20 +175,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
}
// eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch')
mut doffset := 0
mut dp := unsafe{ &byte(&ch.chunk_data) }
mut dp := unsafe { &byte(&ch.chunk_data) }
for doffset < ch.chunk_size {
for c := 0; c < rf.nchannels; c++ {
mut x := f32(0.0)
mut step := 0
ppos := unsafe { dp + doffset }
if rf.bits_per_sample == 8 {
d8 := unsafe{ &byte(ppos) }
d8 := unsafe { &byte(ppos) }
x = (f32(*d8) - 128) / 128.0
step = 1
doffset++
}
if rf.bits_per_sample == 16 {
d16 := unsafe{ &i16(ppos) }
d16 := unsafe { &i16(ppos) }
x = f32(*d16) / 32768.0
step = 2
}
@ -207,5 +206,4 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
}
}
return res
}