sysaudio: access sample rate from field (except for jack) and add media role option
This commit is contained in:
parent
bb6a654c90
commit
7315d1ab62
6 changed files with 41 additions and 44 deletions
|
|
@ -5,6 +5,8 @@ const backends = @import("backends.zig");
|
|||
|
||||
pub const default_sample_rate = 44_100; // Hz
|
||||
pub const default_latency = 500 * std.time.us_per_ms; // μs
|
||||
pub const min_sample_rate = 8_000; // Hz
|
||||
pub const max_sample_rate = 5_644_800; // Hz
|
||||
|
||||
pub const Backend = backends.Backend;
|
||||
pub const DeviceChangeFn = *const fn (self: ?*anyopaque) void;
|
||||
|
|
@ -104,9 +106,18 @@ pub const Player = struct {
|
|||
pub const Options = struct {
|
||||
format: Format = .f32,
|
||||
sample_rate: u24 = default_sample_rate,
|
||||
media_role: MediaRole = .default,
|
||||
user_data: ?*anyopaque = null,
|
||||
};
|
||||
|
||||
pub const MediaRole = enum {
|
||||
default,
|
||||
game,
|
||||
music,
|
||||
movie,
|
||||
communication,
|
||||
};
|
||||
|
||||
data: backends.BackendPlayer,
|
||||
|
||||
pub fn deinit(self: Player) void {
|
||||
|
|
@ -185,7 +196,7 @@ pub const Player = struct {
|
|||
|
||||
pub fn write(self: Player, channel: Channel, frame: usize, sample: anytype) void {
|
||||
switch (@TypeOf(sample)) {
|
||||
f32, u8, i8, i16, i24, i32 => {},
|
||||
u8, i8, i16, i24, i32, f32 => {},
|
||||
else => @compileError(
|
||||
\\invalid sample type. supported types are:
|
||||
\\u8, i8, i16, i24, i32, f32
|
||||
|
|
@ -239,8 +250,11 @@ pub const Player = struct {
|
|||
}
|
||||
|
||||
pub fn sampleRate(self: Player) u24 {
|
||||
return switch (self.data) {
|
||||
inline else => |b| b.sampleRate(),
|
||||
return if (@hasField(Backend, "jack")) switch (self.data) {
|
||||
.jack => |b| b.sampleRate(),
|
||||
inline else => |b| b.sample_rate,
|
||||
} else switch (self.data) {
|
||||
inline else => |b| b.sample_rate,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue