Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/zaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ void* zaudioDeviceGetUserData(ma_device* handle) {
assert(handle != NULL);
return handle->pUserData;
}

ma_uint32 zaudioDeviceGetSampleRate(ma_device* handle) {
assert(handle != NULL);
return handle->sampleRate;
}

ma_format zaudioDeviceGetPlaybackFormat(ma_device* handle) {
assert(handle != NULL);
return handle->playback.format;
}

ma_uint32 zaudioDeviceGetPlaybackChannels(ma_device* handle) {
assert(handle != NULL);
return handle->playback.channels;
}
//--------------------------------------------------------------------------------------------------
void zaudioEngineConfigInit(ma_engine_config* out_config) {
assert(out_config != NULL);
Expand Down
23 changes: 21 additions & 2 deletions src/zaudio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,15 @@ pub const Device = opaque {
}
extern fn ma_device_get_master_volume(device: *const Device, volume: *f32) Result;

pub const getSampleRate = zaudioDeviceGetSampleRate;
extern fn zaudioDeviceGetSampleRate(device: *const Device) u32;

pub const getPlaybackFormat = zaudioDeviceGetPlaybackFormat;
extern fn zaudioDeviceGetPlaybackFormat(device: *const Device) Format;

pub const getPlaybackChannels = zaudioDeviceGetPlaybackChannels;
extern fn zaudioDeviceGetPlaybackChannels(device: *const Device) u32;

pub const Type = enum(c_int) {
playback = 1,
capture = 2,
Expand Down Expand Up @@ -3082,9 +3091,16 @@ fn zaudioMalloc(size: usize, _: ?*anyopaque) callconv(.c) ?*anyopaque {
mem_mutex.lock();
defer mem_mutex.unlock();

const zig_version = @import("builtin").zig_version;

const alignment = comptime if (zig_version.minor == 14)
mem_alignment
else
std.mem.Alignment.fromByteUnits(mem_alignment);

const mem = mem_allocator.?.alignedAlloc(
u8,
.fromByteUnits(mem_alignment),
alignment,
size,
) catch @panic("zaudio: out of memory");

Expand Down Expand Up @@ -3328,7 +3344,10 @@ test "zaudio.audio_buffer" {
init(std.testing.allocator);
defer deinit();

var samples = try std.ArrayList(f32).initCapacity(std.testing.allocator, 1000);
const zig_version = @import("builtin").zig_version;
const ArrayList = if (zig_version.minor == 15) std.ArrayList else std.ArrayListUnmanaged;

var samples = try ArrayList(f32).initCapacity(std.testing.allocator, 1000);
defer samples.deinit(std.testing.allocator);

var prng = std.Random.DefaultPrng.init(0);
Expand Down
Loading