mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
examples: cleanup obsolete unsafe{} usages in examples/sokol/sounds
This commit is contained in:
parent
fdd0dab1c3
commit
da5dc8bb22
@ -12,8 +12,7 @@ mut:
|
|||||||
gg &gg.Context = unsafe { nil } // used for drawing
|
gg &gg.Context = unsafe { nil } // used for drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) {
|
fn my_audio_stream_callback(mut soundbuffer &f32, num_frames int, num_channels int, mut acontext AppState) {
|
||||||
mut soundbuffer := unsafe { buffer }
|
|
||||||
for frame := 0; frame < num_frames; frame++ {
|
for frame := 0; frame < num_frames; frame++ {
|
||||||
t := int(f32(acontext.frame_0 + frame) * 0.245)
|
t := int(f32(acontext.frame_0 + frame) * 0.245)
|
||||||
// "Techno" by Gabriel Miceli
|
// "Techno" by Gabriel Miceli
|
||||||
@ -21,13 +20,11 @@ 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)
|
(t * (((t / 640 | 0) ^ ((t / 640 | 0) - 2)) % 13) / 2 & 127)
|
||||||
for ch := 0; ch < num_channels; ch++ {
|
for ch := 0; ch < num_channels; ch++ {
|
||||||
idx := frame * num_channels + ch
|
idx := frame * num_channels + ch
|
||||||
unsafe {
|
|
||||||
a := f32(u8(y) - 127) / 255.0
|
a := f32(u8(y) - 127) / 255.0
|
||||||
soundbuffer[idx] = a
|
soundbuffer[idx] = a
|
||||||
acontext.frames[idx & 2047] = a
|
acontext.frames[idx & 2047] = a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
acontext.frame_0 += num_frames
|
acontext.frame_0 += num_frames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,10 +10,8 @@ fn sintone(periods int, frame int, num_frames int) f32 {
|
|||||||
return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames))
|
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
|
ms := sw.elapsed().milliseconds() - sw_start_ms
|
||||||
unsafe {
|
|
||||||
mut soundbuffer := buffer
|
|
||||||
for frame := 0; frame < num_frames; frame++ {
|
for frame := 0; frame < num_frames; frame++ {
|
||||||
for ch := 0; ch < num_channels; ch++ {
|
for ch := 0; ch < num_channels; ch++ {
|
||||||
idx := frame * num_channels + ch
|
idx := frame * num_channels + ch
|
||||||
@ -28,7 +26,6 @@ fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -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 {
|
if p.finished {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user