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

examples: fix warnings when doing ./v -W -progress -check-syntax build-examples

This commit is contained in:
Delyan Angelov
2020-10-26 13:14:21 +02:00
parent a7e3092165
commit 9772eb7c96
14 changed files with 203 additions and 157 deletions

View File

@ -55,7 +55,7 @@ fn draw() {
// line(0, 0, 500, 500)
}
fn draw_hollow_rect(x, y, w, h f32) {
fn draw_hollow_rect(x f32, y f32, w f32, h f32) {
sgl.begin_line_strip()
sgl.v2f(x, y)
sgl.v2f(x + w, y)
@ -65,7 +65,7 @@ fn draw_hollow_rect(x, y, w, h f32) {
sgl.end()
}
fn draw_filled_rect(x, y, w, h f32) {
fn draw_filled_rect(x f32, y f32, w f32, h f32) {
sgl.begin_quads()
sgl.v2f(x, y)
sgl.v2f(x + w, y)

View File

@ -10,7 +10,7 @@ mut:
gg &gg.Context // used for drawing
}
fn my_audio_stream_callback(buffer &f32, num_frames, num_channels int, mut acontext AppState) {
fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) {
mut soundbuffer := buffer
for frame := 0; frame < num_frames; frame++ {
t := int(f32(acontext.frame_0 + frame) * 0.245)
@ -68,7 +68,7 @@ fn (mut state AppState) bsample(idx int) byte {
fn (mut state AppState) draw() {
// first, reset and setup ortho projection
for x in 0 .. 1024 {
mut y := 100 * (state.frames[2*x] + state.frames[2*x+1])
mut y := 100 * (state.frames[2 * x] + state.frames[2 * x + 1])
state.gg.draw_line(x, 200, x, 200 + y, gx.rgba(state.bsample(x), state.bsample(x + 300),
state.bsample(x + 700), 255))
}

View File

@ -8,11 +8,11 @@ const (
)
[inline]
fn sintone(periods, frame, num_frames int) f32 {
fn sintone(periods int, frame int, num_frames int) f32 {
return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames))
}
fn my_audio_stream_callback(buffer &f32, num_frames, num_channels int) {
fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int) {
ms := sw.elapsed().milliseconds() - sw_start_ms
unsafe {
mut soundbuffer := buffer

View File

@ -12,10 +12,10 @@ mut:
fn main() {
if os.args.len < 2 {
eprintln('Usage: play_wav file1.wav file2.wav ...')
play_sounds([os.resource_abs_path('uhoh.wav')])?
play_sounds([os.resource_abs_path('uhoh.wav')]) ?
exit(1)
}
play_sounds(os.args[1..])?
play_sounds(os.args[1..]) ?
}
fn play_sounds(files []string) ? {
@ -31,13 +31,13 @@ fn play_sounds(files []string) ? {
eprintln('skipping "$f" (not a .wav file)')
continue
}
player.play_wav_file(f)?
player.play_wav_file(f) ?
}
player.stop()
}
//
fn audio_player_callback(buffer &f32, num_frames, num_channels int, mut p Player) {
fn audio_player_callback(buffer &f32, num_frames int, num_channels int, mut p Player) {
if p.finished {
return
}
@ -48,9 +48,7 @@ fn audio_player_callback(buffer &f32, num_frames, num_channels int, mut p Player
p.finished = true
return
}
unsafe {
C.memcpy(buffer, &p.samples[p.pos], nsamples * int(sizeof(f32)))
}
unsafe {C.memcpy(buffer, &p.samples[p.pos], nsamples * int(sizeof(f32)))}
p.pos += nsamples
}
@ -69,7 +67,7 @@ fn (mut p Player) stop() {
fn (mut p Player) play_wav_file(fpath string) ? {
println('> play_wav_file: $fpath')
samples := read_wav_file_samples(fpath)?
samples := read_wav_file_samples(fpath) ?
p.finished = true
p.samples << samples
p.finished = false
@ -121,7 +119,7 @@ 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 bytes := os.read_bytes(fpath) ?
mut pbytes := byteptr(bytes.data)
mut offset := u32(0)
rh := &RIFFHeader(pbytes)