sysaudio: improve backend selection; remove i8 sample support (#767)

* sysaudio: fix compilation errors
* re-order backend selection
* remove i8 samples support from backends and disable signedToSigned convertion for now
* update sine-wave example
This commit is contained in:
Ali Chraghi 2023-04-30 16:36:39 -07:00 committed by GitHub
parent 8fbc36999f
commit ed05166348
Failed to generate hash of commit
8 changed files with 64 additions and 89 deletions

View file

@ -44,14 +44,13 @@ pub fn main() !void {
const pitch = 440.0;
const radians_per_second = pitch * 2.0 * std.math.pi;
var seconds_offset: f32 = 0.0;
fn writeCallback(_: ?*anyopaque, n_frame: usize) void {
fn writeCallback(_: ?*anyopaque, frames: usize) void {
const seconds_per_frame = 1.0 / @intToFloat(f32, player.sampleRate());
var frame: usize = 0;
while (frame < n_frame) : (frame += 1) {
const sample = std.math.sin((seconds_offset + @intToFloat(f32, frame) * seconds_per_frame) * radians_per_second);
player.writeAll(frame, sample);
for (0..frames) |fi| {
const sample = std.math.sin((seconds_offset + @intToFloat(f32, fi) * seconds_per_frame) * radians_per_second);
player.writeAll(fi, sample);
}
seconds_offset = @mod(seconds_offset + seconds_per_frame * @intToFloat(f32, n_frame), 1.0);
seconds_offset = @mod(seconds_offset + seconds_per_frame * @intToFloat(f32, frames), 1.0);
}
fn deviceChange(_: ?*anyopaque) void {