sysaudio: fix compile for web
This commit is contained in:
parent
b72c2c978f
commit
70f4514c66
5 changed files with 59 additions and 52 deletions
|
|
@ -27,38 +27,6 @@ pub const Format = enum {
|
|||
F32,
|
||||
};
|
||||
|
||||
pub const DeviceOptions = struct {
|
||||
mode: Mode = .output,
|
||||
format: ?Format = null,
|
||||
is_raw: ?bool = null,
|
||||
channels: ?u8 = null,
|
||||
sample_rate: ?u32 = null,
|
||||
id: ?[:0]const u8 = null,
|
||||
name: ?[]const u8 = null,
|
||||
};
|
||||
|
||||
pub const DeviceProperties = struct {
|
||||
mode: Mode,
|
||||
format: Format,
|
||||
is_raw: bool,
|
||||
channels: u8,
|
||||
sample_rate: u32,
|
||||
id: [:0]const u8,
|
||||
name: []const u8,
|
||||
|
||||
pub fn intoConfig(properties: DeviceProperties) DeviceOptions {
|
||||
return .{
|
||||
.mode = properties.mode,
|
||||
.format = properties.format,
|
||||
.is_raw = properties.is_raw,
|
||||
.channels = properties.channels,
|
||||
.sample_rate = properties.sample_rate,
|
||||
.id = properties.id,
|
||||
.name = properties.name,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const Audio = @This();
|
||||
|
||||
backend: Backend,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
const std = @import("std");
|
||||
const Mode = @import("main.zig").Mode;
|
||||
const DeviceOptions = @import("main.zig").DeviceOptions;
|
||||
const DeviceProperties = @import("main.zig").DeviceProperties;
|
||||
const Format = @import("main.zig").Format;
|
||||
const c = @import("soundio").c;
|
||||
const Aim = @import("soundio").Aim;
|
||||
|
|
@ -35,8 +33,25 @@ pub const Device = struct {
|
|||
planar_buffer: [512000]u8 = undefined,
|
||||
started: bool = false,
|
||||
|
||||
pub const Options = DeviceOptions;
|
||||
pub const Properties = DeviceProperties;
|
||||
pub const Options = struct {
|
||||
mode: Mode = .output,
|
||||
format: ?Format = null,
|
||||
is_raw: ?bool = null,
|
||||
channels: ?u8 = null,
|
||||
sample_rate: ?u32 = null,
|
||||
id: ?[:0]const u8 = null,
|
||||
name: ?[]const u8 = null,
|
||||
};
|
||||
|
||||
pub const Properties = struct {
|
||||
mode: Mode,
|
||||
format: Format,
|
||||
is_raw: bool,
|
||||
channels: u8,
|
||||
sample_rate: u32,
|
||||
id: [:0]const u8,
|
||||
name: []const u8,
|
||||
};
|
||||
|
||||
pub fn deinit(self: *Device, allocator: std.mem.Allocator) void {
|
||||
switch (self.handle) {
|
||||
|
|
@ -176,14 +191,14 @@ pub const DeviceIterator = struct {
|
|||
device_len: u16,
|
||||
index: u16,
|
||||
|
||||
pub fn next(self: *DeviceIterator) IteratorError!?DeviceOptions {
|
||||
pub fn next(self: *DeviceIterator) IteratorError!?Device.Options {
|
||||
if (self.index < self.device_len) {
|
||||
const device_desc = switch (self.mode) {
|
||||
.input => self.ctx.handle.getInputDevice(self.index) orelse return null,
|
||||
.output => self.ctx.handle.getOutputDevice(self.index) orelse return null,
|
||||
};
|
||||
self.index += 1;
|
||||
return DeviceOptions{
|
||||
return Device.Options{
|
||||
.mode = switch (@intToEnum(Aim, device_desc.handle.aim)) {
|
||||
.input => .input,
|
||||
.output => .output,
|
||||
|
|
@ -251,7 +266,7 @@ pub fn waitEvents(self: Audio) void {
|
|||
self.handle.waitEvents();
|
||||
}
|
||||
|
||||
pub fn requestDevice(self: Audio, allocator: std.mem.Allocator, options: DeviceOptions) Error!*Device {
|
||||
pub fn requestDevice(self: Audio, allocator: std.mem.Allocator, options: Device.Options) Error!*Device {
|
||||
var sio_device: SoundIoDevice = undefined;
|
||||
|
||||
if (options.id) |id| {
|
||||
|
|
@ -324,7 +339,7 @@ pub fn requestDevice(self: Audio, allocator: std.mem.Allocator, options: DeviceO
|
|||
// };
|
||||
// const name = std.mem.sliceTo(name_ptr, 0);
|
||||
|
||||
var properties = DeviceProperties{
|
||||
var properties = Device.Properties{
|
||||
.is_raw = options.is_raw orelse false,
|
||||
.format = format,
|
||||
.mode = options.mode,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
const std = @import("std");
|
||||
const Mode = @import("main.zig").Mode;
|
||||
const DeviceOptions = @import("main.zig").DeviceOptions;
|
||||
const DeviceProperties = @import("main.zig").DeviceProperties;
|
||||
const Format = @import("main.zig").Format;
|
||||
const js = @import("sysjs");
|
||||
|
||||
const Audio = @This();
|
||||
|
|
@ -12,13 +11,30 @@ else
|
|||
*const fn (device: *Device, user_data: ?*anyopaque, buffer: []u8) void;
|
||||
|
||||
pub const Device = struct {
|
||||
properties: DeviceProperties,
|
||||
properties: Properties,
|
||||
|
||||
// Internal fields.
|
||||
context: js.Object,
|
||||
|
||||
pub const Options = DeviceOptions;
|
||||
pub const Properties = DeviceProperties;
|
||||
pub const Options = struct {
|
||||
mode: Mode = .output,
|
||||
format: ?Format = null,
|
||||
is_raw: ?bool = null,
|
||||
channels: ?u8 = null,
|
||||
sample_rate: ?u32 = null,
|
||||
id: ?[:0]const u8 = null,
|
||||
name: ?[]const u8 = null,
|
||||
};
|
||||
|
||||
pub const Properties = struct {
|
||||
mode: Mode,
|
||||
format: Format,
|
||||
is_raw: bool,
|
||||
channels: u8,
|
||||
sample_rate: u32,
|
||||
id: [:0]const u8,
|
||||
name: []const u8,
|
||||
};
|
||||
|
||||
pub fn deinit(device: *Device, allocator: std.mem.Allocator) void {
|
||||
device.context.deinit();
|
||||
|
|
@ -45,7 +61,7 @@ pub const DeviceIterator = struct {
|
|||
ctx: *Audio,
|
||||
mode: Mode,
|
||||
|
||||
pub fn next(_: DeviceIterator) IteratorError!?DeviceProperties {
|
||||
pub fn next(_: DeviceIterator) IteratorError!?Device.Properties {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
@ -78,7 +94,7 @@ const default_channel_count = 2;
|
|||
const default_sample_rate = 48000;
|
||||
const default_buffer_size_per_channel = 1024; // 21.33ms
|
||||
|
||||
pub fn requestDevice(audio: Audio, allocator: std.mem.Allocator, options: DeviceOptions) Error!*Device {
|
||||
pub fn requestDevice(audio: Audio, allocator: std.mem.Allocator, options: Device.Options) Error!*Device {
|
||||
// NOTE: WebAudio only supports F32 audio format, so options.format is unused
|
||||
const mode = options.mode;
|
||||
const channels = options.channels orelse default_channel_count;
|
||||
|
|
@ -117,9 +133,13 @@ pub fn requestDevice(audio: Audio, allocator: std.mem.Allocator, options: Device
|
|||
_ = node.call("connect", &.{destination.toValue()});
|
||||
}
|
||||
|
||||
var properties = DeviceProperties{
|
||||
// TODO(sysaudio): Figure out ID/name or make optional again
|
||||
var properties = Device.Properties{
|
||||
.id = "0",
|
||||
.name = "WebAudio",
|
||||
.format = .F32,
|
||||
.mode = options.mode orelse .output,
|
||||
.mode = options.mode,
|
||||
.is_raw = false,
|
||||
.channels = options.channels orelse default_channel_count,
|
||||
.sample_rate = options.sample_rate orelse default_sample_rate,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue