diff --git a/examples/sokol/sounds/melody.v b/examples/sokol/sounds/melody.v index 341ded9b4b..4bc645d95b 100644 --- a/examples/sokol/sounds/melody.v +++ b/examples/sokol/sounds/melody.v @@ -12,8 +12,7 @@ mut: gg &gg.Context = unsafe { nil } // used for drawing } -fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) { - mut soundbuffer := unsafe { buffer } +fn my_audio_stream_callback(mut soundbuffer &f32, num_frames int, num_channels int, mut acontext AppState) { for frame := 0; frame < num_frames; frame++ { t := int(f32(acontext.frame_0 + frame) * 0.245) // "Techno" by Gabriel Miceli @@ -21,11 +20,9 @@ fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut a (t * (((t / 640 | 0) ^ ((t / 640 | 0) - 2)) % 13) / 2 & 127) for ch := 0; ch < num_channels; ch++ { idx := frame * num_channels + ch - unsafe { - a := f32(u8(y) - 127) / 255.0 - soundbuffer[idx] = a - acontext.frames[idx & 2047] = a - } + a := f32(u8(y) - 127) / 255.0 + soundbuffer[idx] = a + acontext.frames[idx & 2047] = a } } acontext.frame_0 += num_frames diff --git a/examples/sokol/sounds/simple_sin_tones.v b/examples/sokol/sounds/simple_sin_tones.v index edb3069d30..671cb05e4b 100644 --- a/examples/sokol/sounds/simple_sin_tones.v +++ b/examples/sokol/sounds/simple_sin_tones.v @@ -10,22 +10,19 @@ 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 int, num_channels int) { +fn my_audio_stream_callback(mut soundbuffer &f32, num_frames int, num_channels int) { ms := sw.elapsed().milliseconds() - sw_start_ms - unsafe { - mut soundbuffer := buffer - for frame := 0; frame < num_frames; frame++ { - for ch := 0; ch < num_channels; ch++ { - idx := frame * num_channels + ch - if ms < 250 { - soundbuffer[idx] = 0.5 * sintone(20, frame, num_frames) - } else if ms < 300 { - soundbuffer[idx] = 0.5 * sintone(25, frame, num_frames) - } else if ms < 1500 { - soundbuffer[idx] *= sintone(22, frame, num_frames) - } else { - soundbuffer[idx] = 0.5 * sintone(25, frame, num_frames) - } + for frame := 0; frame < num_frames; frame++ { + for ch := 0; ch < num_channels; ch++ { + idx := frame * num_channels + ch + if ms < 250 { + soundbuffer[idx] = 0.5 * sintone(20, frame, num_frames) + } else if ms < 300 { + soundbuffer[idx] = 0.5 * sintone(25, frame, num_frames) + } else if ms < 1500 { + soundbuffer[idx] *= sintone(22, frame, num_frames) + } else { + soundbuffer[idx] = 0.5 * sintone(25, frame, num_frames) } } } diff --git a/examples/sokol/sounds/wav_player.v b/examples/sokol/sounds/wav_player.v index f8b35c16d3..6b8d4e42e5 100644 --- a/examples/sokol/sounds/wav_player.v +++ b/examples/sokol/sounds/wav_player.v @@ -37,7 +37,7 @@ fn play_sounds(files []string) ! { } // -fn audio_player_callback(buffer &f32, num_frames int, num_channels int, mut p Player) { +fn audio_player_callback(mut buffer &f32, num_frames int, num_channels int, mut p Player) { if p.finished { return }