v/vlib/sokol
Larpon 5cffa1a2e4
sokol: use V type for SG_SHADERSTAGE_[VS|FS] (#13086)
2022-01-07 19:52:44 +02:00
..
audio docs: add more documentation to each of the modules in vlib (#13043) 2022-01-07 13:28:50 +02:00
c sokol: add screenshot function to OpenGL based backends (#12169) 2021-10-13 21:22:58 +03:00
f tools: make `v test-cleancode` test everything by default (#10050) 2021-05-08 13:32:29 +03:00
gfx sokol: use V type for SG_SHADERSTAGE_[VS|FS] (#13086) 2022-01-07 19:52:44 +02:00
sapp sokol: rename sapp consts, remove sapp prefix (#13083) 2022-01-07 18:01:07 +02:00
sfons sokol: fix missing import in `sfons`. Fixes #13061 (#13062) 2022-01-06 18:21:41 +02:00
sgl sokol: update to floooh/sokol from 27-Dec-2021 (4ff3ed7) (#13044) 2022-01-05 18:23:14 +02:00
README.md docs: add more documentation to each of the modules in vlib (#13043) 2022-01-07 13:28:50 +02:00
sokol.v tools: make `v test-cleancode` test everything by default (#10050) 2021-05-08 13:32:29 +03:00

README.md

Description:

sokol is a thin wrapper around sokol, which in turn is a library of "Simple STB-style cross-platform libraries for C and C++, written in C.", that provide access to graphics/audio/input processing.

Each .h file in the sokol source code is well-documented as can be seen here:

sokol_audio.h

Example from @VROOTDIR/examples/sokol/sounds/simple_sin_tones.v:

import time
import math
import sokol.audio

const (
	sw          = time.new_stopwatch()
	sw_start_ms = sw.elapsed().milliseconds()
)

[inline]
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) {
	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)
				}
			}
		}
	}
}

fn main() {
	audio.setup(
		stream_cb: my_audio_stream_callback
	)
	time.sleep(2000 * time.millisecond)
	audio.shutdown()
}