parent
d1c3d26710
commit
c45606c290
5 changed files with 51 additions and 29 deletions
|
|
@ -779,7 +779,8 @@ pub fn toAlsaFormat(format: main.Format) c.snd_pcm_format_t {
|
|||
return switch (format) {
|
||||
.u8 => c.SND_PCM_FORMAT_U8,
|
||||
.i16 => if (is_little) c.SND_PCM_FORMAT_S16_LE else c.SND_PCM_FORMAT_S16_BE,
|
||||
.i24 => if (is_little) c.SND_PCM_FORMAT_S24_3LE else c.SND_PCM_FORMAT_S24_3BE,
|
||||
// TODO(i24)
|
||||
// .i24 => if (is_little) c.SND_PCM_FORMAT_S24_3LE else c.SND_PCM_FORMAT_S24_3BE,
|
||||
.i32 => if (is_little) c.SND_PCM_FORMAT_S32_LE else c.SND_PCM_FORMAT_S32_BE,
|
||||
.f32 => if (is_little) c.SND_PCM_FORMAT_FLOAT_LE else c.SND_PCM_FORMAT_FLOAT_BE,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -742,7 +742,8 @@ fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.A
|
|||
.mFormatID = c.kAudioFormatLinearPCM,
|
||||
.mFormatFlags = switch (format) {
|
||||
.i16 => c.kAudioFormatFlagIsSignedInteger,
|
||||
.i24 => c.kAudioFormatFlagIsSignedInteger,
|
||||
// TODO(i24)
|
||||
// .i24 => c.kAudioFormatFlagIsSignedInteger,
|
||||
.i32 => c.kAudioFormatFlagIsSignedInteger,
|
||||
.f32 => c.kAudioFormatFlagIsFloat,
|
||||
.u8 => return error.IncompatibleDevice,
|
||||
|
|
@ -753,7 +754,8 @@ fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.A
|
|||
.mChannelsPerFrame = @intCast(ch_count),
|
||||
.mBitsPerChannel = switch (format) {
|
||||
.i16 => 16,
|
||||
.i24 => 24,
|
||||
// TODO(i24)
|
||||
// .i24 => 24,
|
||||
.i32 => 32,
|
||||
.f32 => 32,
|
||||
.u8 => return error.IncompatibleDevice,
|
||||
|
|
|
|||
|
|
@ -339,13 +339,14 @@ pub fn convertTo(comptime SrcType: type, src: []const SrcType, dst_format: Forma
|
|||
f32 => conv.floatToSigned(SrcType, src, i16, @as([*]i16, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
else => unreachable,
|
||||
},
|
||||
.i24 => switch (SrcType) {
|
||||
i24 => @memcpy(@as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len], src),
|
||||
u8 => conv.unsignedToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
i8, i16, i32 => conv.signedToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
f32 => conv.floatToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
else => unreachable,
|
||||
},
|
||||
// TODO(i24)
|
||||
// .i24 => switch (SrcType) {
|
||||
// i24 => @memcpy(@as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len], src),
|
||||
// u8 => conv.unsignedToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
// i8, i16, i32 => conv.signedToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
// f32 => conv.floatToSigned(SrcType, src, i24, @as([*]i24, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
// else => unreachable,
|
||||
// },
|
||||
.i32 => switch (SrcType) {
|
||||
i32 => @memcpy(@as([*]i32, @ptrCast(@alignCast(dst)))[0..dst_len], src),
|
||||
u8 => conv.unsignedToSigned(SrcType, src, i32, @as([*]i32, @ptrCast(@alignCast(dst)))[0..dst_len]),
|
||||
|
|
@ -380,13 +381,14 @@ pub fn convertFrom(comptime DestType: type, dst: []DestType, src_format: Format,
|
|||
f32 => conv.signedToFloat(i16, @as([*]const i16, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
else => unreachable,
|
||||
},
|
||||
.i24 => switch (DestType) {
|
||||
i24 => @memcpy(dst, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len]),
|
||||
u8 => conv.signedToUnsigned(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
i8, i16, i32 => conv.signedToSigned(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
f32 => conv.signedToFloat(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
else => unreachable,
|
||||
},
|
||||
// TODO(i24)
|
||||
// .i24 => switch (DestType) {
|
||||
// i24 => @memcpy(dst, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len]),
|
||||
// u8 => conv.signedToUnsigned(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
// i8, i16, i32 => conv.signedToSigned(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
// f32 => conv.signedToFloat(i24, @as([*]const i24, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
// else => unreachable,
|
||||
// },
|
||||
.i32 => switch (DestType) {
|
||||
i32 => @memcpy(dst, @as([*]const i32, @ptrCast(@alignCast(src)))[0..src_len]),
|
||||
u8 => conv.signedToUnsigned(i32, @as([*]const i32, @ptrCast(@alignCast(src)))[0..src_len], DestType, dst),
|
||||
|
|
@ -450,18 +452,20 @@ pub const ChannelPosition = enum {
|
|||
lfe,
|
||||
};
|
||||
|
||||
pub const Format = enum(u3) {
|
||||
u8 = 0,
|
||||
i16 = 1,
|
||||
i24 = 2,
|
||||
i32 = 3,
|
||||
f32 = 4,
|
||||
pub const Format = enum {
|
||||
u8,
|
||||
i16,
|
||||
// TODO(i24): Uncomment when https://github.com/hexops/mach/issues/1152 is fixed
|
||||
// i24 = 2,
|
||||
i32,
|
||||
f32,
|
||||
|
||||
pub inline fn size(format: Format) u8 {
|
||||
return switch (format) {
|
||||
.u8 => 1,
|
||||
.i16 => 2,
|
||||
.i24 => 3,
|
||||
// TODO(i24)
|
||||
// .i24 => 3,
|
||||
.i32, .f32 => 4,
|
||||
};
|
||||
}
|
||||
|
|
@ -470,7 +474,8 @@ pub const Format = enum(u3) {
|
|||
return switch (format) {
|
||||
.u8 => 1,
|
||||
.i16 => 2,
|
||||
.i24 => 3,
|
||||
// TODO(i24)
|
||||
// .i24 => 3,
|
||||
.i32, .f32 => 4,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -740,7 +740,14 @@ fn performOperation(main_loop: *c.pa_threaded_mainloop, op: ?*c.pa_operation) vo
|
|||
}
|
||||
}
|
||||
|
||||
pub const available_formats = &[_]main.Format{ .u8, .i16, .i24, .i32, .f32 };
|
||||
pub const available_formats = &[_]main.Format{
|
||||
.u8,
|
||||
.i16,
|
||||
// TODO(i24)
|
||||
// .i24,
|
||||
.i32,
|
||||
.f32,
|
||||
};
|
||||
|
||||
pub fn fromPAChannelPos(pos: c.pa_channel_position_t) !main.ChannelPosition {
|
||||
return switch (pos) {
|
||||
|
|
@ -773,7 +780,8 @@ pub fn toPAFormat(format: main.Format) c.pa_sample_format_t {
|
|||
return switch (format) {
|
||||
.u8 => c.PA_SAMPLE_U8,
|
||||
.i16 => if (is_little) c.PA_SAMPLE_S16LE else c.PA_SAMPLE_S16BE,
|
||||
.i24 => if (is_little) c.PA_SAMPLE_S24LE else c.PA_SAMPLE_S24LE,
|
||||
// TODO(i24)
|
||||
// .i24 => if (is_little) c.PA_SAMPLE_S24LE else c.PA_SAMPLE_S24LE,
|
||||
.i32 => if (is_little) c.PA_SAMPLE_S32LE else c.PA_SAMPLE_S32BE,
|
||||
.f32 => if (is_little) c.PA_SAMPLE_FLOAT32LE else c.PA_SAMPLE_FLOAT32BE,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -383,7 +383,12 @@ pub const Context = struct {
|
|||
|
||||
fn setWaveFormatFormat(wf: *win32.WAVEFORMATEXTENSIBLE, format: main.Format) void {
|
||||
switch (format) {
|
||||
.u8, .i16, .i24, .i32 => {
|
||||
.u8,
|
||||
.i16,
|
||||
// TODO(i24)
|
||||
// .i24,
|
||||
.i32,
|
||||
=> {
|
||||
wf.SubFormat = win32.CLSID_KSDATAFORMAT_SUBTYPE_PCM.*;
|
||||
},
|
||||
.f32 => {
|
||||
|
|
@ -685,7 +690,8 @@ pub const Context = struct {
|
|||
return switch (format) {
|
||||
.u8,
|
||||
.i16,
|
||||
.i24,
|
||||
// TODO(i24)
|
||||
// .i24,
|
||||
.i32,
|
||||
=> win32.CLSID_KSDATAFORMAT_SUBTYPE_PCM.*,
|
||||
.f32 => win32.CLSID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT.*,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue