Skip to content

Commit

Permalink
sokol: fix the audio examples
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Oct 6, 2023
1 parent 322ba71 commit cee2eab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
16 changes: 8 additions & 8 deletions vlib/sokol/audio/audio.v
Expand Up @@ -58,15 +58,15 @@ pub fn (x FnStreamingCBWithUserData) str() string {
[typedef]
pub struct C.saudio_allocator {
pub mut:
alloc memory.FnAllocatorAlloc
free memory.FnAllocatorFree
alloc_fn memory.FnAllocatorAlloc
free_fn memory.FnAllocatorFree
user_data voidptr
}

[typedef]
pub struct C.saudio_logger {
pub mut:
log_cb memory.FnLogCb
func memory.FnLogCb
user_data voidptr
}

Expand Down Expand Up @@ -120,16 +120,16 @@ fn C.saudio_push(frames &f32, num_frames int) int

// setup - setup sokol-audio
pub fn setup(desc &C.saudio_desc) {
if desc.allocator.alloc == unsafe { nil } && desc.allocator.free == unsafe { nil } {
if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
unsafe {
desc.allocator.alloc = memory.salloc
desc.allocator.free = memory.sfree
desc.allocator.alloc_fn = memory.salloc
desc.allocator.free_fn = memory.sfree
desc.allocator.user_data = voidptr(0x100a0d10)
}
}
if desc.logger.log_cb == unsafe { nil } {
if desc.logger.func == unsafe { nil } {
unsafe {
desc.logger.log_cb = memory.slog
desc.logger.func = memory.slog
}
}
C.saudio_setup(desc)
Expand Down
21 changes: 5 additions & 16 deletions vlib/sokol/memory/memory.v
Expand Up @@ -4,7 +4,7 @@ pub type FnAllocatorAlloc = fn (size usize, user_data voidptr) voidptr

pub type FnAllocatorFree = fn (ptr voidptr, user_data voidptr)

pub type FnLogCb = fn (const_message &char, user_data voidptr)
pub type FnLogCb = fn (const_tag &char, log_level u32, log_item_id u32, const_message_or_null &char, line_nr u32, const_filename_or_null &char, user_data voidptr)

// salloc - used in the allocator structs, that the SOKOL libraries use, for allocating new memory blocks
pub fn salloc(size usize, user_data voidptr) voidptr {
Expand All @@ -31,19 +31,8 @@ pub fn sfree(ptr voidptr, user_data voidptr) {

fn C.SOKOL_LOG(const_message &char)

pub fn slog(const_message &char, user_data voidptr) {
$if trace_sokol_memory ? {
C.fprintf(C.stderr, c'sokol.memory.slog | user_data: %p, message: %s\n', user_data,
const_message)
}
C.fprintf(C.stderr, c'%s\n', const_message)
/*
$if msvc {
C.fprintf(C.stderr, c'%s\n', const_message)
} $else {
$if !prod {
C.SOKOL_LOG(const_message)
}
}
*/
pub fn slog(const_tag &char, log_level u32, log_item_id u32, const_message_or_null &char, line_nr u32, const_filename_or_null &char, user_data voidptr) {
C.fprintf(C.stderr, c'sokol.memory.slog | user_data: %p, const_tag: %s, level: %d, item_id: %d, fname: %s, line: %d, message: %s\n',
user_data, const_tag, log_level, log_item_id, const_filename_or_null, line_nr,
const_message_or_null)
}

0 comments on commit cee2eab

Please sign in to comment.