o
This commit is contained in:
Julia 2024-09-21 11:00:03 -05:00
parent c77b570671
commit 4864dbc767
10 changed files with 93 additions and 34 deletions

BIN
script/meow.wav Normal file

Binary file not shown.

BIN
script/nasty.wav Normal file

Binary file not shown.

BIN
script/nightcore.wav Normal file

Binary file not shown.

12
script/wavtest.py Normal file
View file

@ -0,0 +1,12 @@
from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt
srate, data = wavfile.read("nasty.wav")
data = data.flatten()
for i in range(1, len(data)):
data[i] = data[i-1] - data[i]
plt.hist(data, range=(-2**23, 2**23), bins=128)
plt.show()

BIN
src/fuck.exe Normal file

Binary file not shown.

View file

@ -6,17 +6,17 @@ using namespace std;
int main()
{
GUID sex = __uuidof(IAudioRenderClient);
cout << "{" << endl;
std::cout << "0x" << hex << sex.Data1 << ", ";
std::cout << "0x" << hex << sex.Data2 << ", ";
std::cout << "0x"<<hex << sex.Data3 << ", ";
GUID sex = __uuidof(IAudioClient3);
cout << ".{ ";
for (int i = 0; i < 8; i++)
cout <<"0x"<< hex << (int)sex.Data4[i] << ", ";
cout << ".Data1 = 0x" << hex << sex.Data1 << ", ";
cout << ".Data2 = 0x" << hex << sex.Data2 << ", ";
cout << ".Data3 = 0x" << hex << sex.Data3 << ", ";
cout << "}";
cout << ".Data4 = .{ ";
for (int i = 0; i < 8; i++)
cout << "0x" << hex << (int)sex.Data4[i] << ", ";
cout << "}}";
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,4 +1,5 @@
const std = @import("std");
const W = std.unicode.utf8ToUtf16LeStringLiteral;
const win = @cImport({
@cInclude("windows.h");
@ -9,26 +10,45 @@ const wasapi = @cImport(@cInclude("audioclient.h"));
const CLSID_MMDeviceEnumerator: win.CLSID = .{ .Data1 = 0xbcde0395, .Data2 = 0xe52f, .Data3 = 0x467c, .Data4 = .{ 0x8e, 0x3d, 0xc4, 0x57, 0x92, 0x91, 0x69, 0x2e } };
const IID_IMMDeviceEnumerator: win.IID = .{ .Data1 = 0xa95664d2, .Data2 = 0x9614, .Data3 = 0x4f35, .Data4 = .{ 0xa7, 0x46, 0xde, 0x8d, 0xb6, 0x36, 0x17, 0xe6 } };
const IID_IAudioClient: win.IID = .{ .Data1 = 0x1cb9ad4c, .Data2 = 0xdbfa, .Data3 = 0x4c32, .Data4 = .{ 0xb1, 0x78, 0xc2, 0xf5, 0x68, 0xa7, 0x3, 0xb2 } };
const IID_IAudioClient3: win.IID = .{ .Data1 = 0x7ed4ee07, .Data2 = 0x8e67, .Data3 = 0x4cd4, .Data4 = .{ 0x8c, 0x1a, 0x2b, 0x7a, 0x59, 0x87, 0xad, 0x42 } };
const IID_IAudioRenderClient: win.IID = .{ .Data1 = 0xf294acfc, .Data2 = 0x3146, .Data3 = 0x4483, .Data4 = .{ 0xa7, 0xbf, 0xad, 0xdc, 0xa7, 0xc2, 0x60, 0xe2 } };
fn framesToHundredNanoseconds(frames: f32, sample_rate: f32) c_longlong {
return @intFromFloat(10_000_000 * (frames / sample_rate));
pub export fn WindowProc(window: win.HWND, msg: c_uint, w_param: win.WPARAM, l_param: win.LPARAM) callconv(.C) win.LRESULT {
switch (msg) {
win.WM_KEYDOWN => {
std.debug.print("keydown: {}\n", .{w_param});
},
else => {},
}
return win.DefWindowProcW(window, msg, w_param, l_param);
}
pub fn main() !void {
var rid: [1]win.RAWINPUTDEVICE = undefined;
rid[0].usUsagePage = 0x01;
rid[0].usUsage = 0x06;
rid[0].dwFlags = 0; // win.RIDEV_INPUTSINK;
rid[0].hwndTarget = null;
if (win.RegisterRawInputDevices(@ptrCast(&rid), 1, @sizeOf(win.RAWINPUTDEVICE)) == 0) {
std.debug.print("FUCK {}\n", .{win.GetLastError()});
return;
}
var message: win.MSG = undefined;
while (win.GetMessageW(&message, null, 0, 0) != 0) {
std.debug.print("meow\n", .{});
_ = win.TranslateMessage(&message);
_ = win.DispatchMessageW(&message);
}
}
pub const WindowsAudio = struct {
timer_handle: *anyopaque,
pub fn init() !void {}
pub fn init() i32 {}
fn audioWorker() i32 {
const wave_format: wasapi.WAVEFORMATEX = .{
.wFormatTag = wasapi.WAVE_FORMAT_IEEE_FLOAT,
.nChannels = 2,
.nSamplesPerSec = 48000,
.wBitsPerSample = 32,
.nBlockAlign = 2 * (32 / 8),
.nAvgBytesPerSec = 48000 * (2 * (32 / 8)),
};
if (failed(win.CoInitialize(null))) |err| return err;
const buf_event: *anyopaque = win.CreateEventW(
null,
@ -37,8 +57,6 @@ pub const WindowsAudio = struct {
null,
) orelse return hresultFromWin32(win.GetLastError());
if (failed(win.CoInitialize(null))) |err| return err;
// Get default audio device
var device_enumerator: *win.IMMDeviceEnumerator = undefined;
var audio_device: *win.IMMDevice = undefined;
@ -59,23 +77,52 @@ pub const WindowsAudio = struct {
))) |err| return err;
// Initialize audio client
var wasapi_audio_client: *wasapi.IAudioClient = undefined;
var wasapi_audio_client: *wasapi.IAudioClient3 = undefined;
var device_format: *wasapi.WAVEFORMATEX = undefined;
var default_period: u32 = undefined;
var fundamental_period: u32 = undefined;
var min_period: u32 = undefined;
var max_period: u32 = undefined;
if (failed(audio_device.lpVtbl.*.Activate.?(
audio_device,
@ptrCast(&IID_IAudioClient),
@ptrCast(&IID_IAudioClient3),
win.CLSCTX_ALL,
null,
@ptrCast(&wasapi_audio_client),
))) |err| return err;
if (failed(wasapi_audio_client.lpVtbl.*.Initialize.?(
if (failed(wasapi_audio_client.lpVtbl.*.GetMixFormat.?(
wasapi_audio_client,
@ptrCast(&device_format),
))) |err| return err;
const negotiated_format: wasapi.WAVEFORMATEX = .{
.wFormatTag = wasapi.WAVE_FORMAT_IEEE_FLOAT,
.nChannels = 2,
.nSamplesPerSec = device_format.nSamplesPerSec,
.nAvgBytesPerSec = device_format.nSamplesPerSec * 2 * @sizeOf(f32),
.nBlockAlign = 2 * @sizeOf(f32),
.wBitsPerSample = @bitSizeOf(f32),
.cbSize = 0,
};
win.CoTaskMemFree(device_format);
if (failed(wasapi_audio_client.lpVtbl.*.GetSharedModeEnginePeriod.?(
wasapi_audio_client,
&negotiated_format,
&default_period,
&fundamental_period,
&min_period,
&max_period,
))) |err| return err;
if (failed(wasapi_audio_client.lpVtbl.*.InitializeSharedAudioStream.?(
wasapi_audio_client,
wasapi.AUDCLNT_SHAREMODE_SHARED,
wasapi.AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
framesToHundredNanoseconds(128, wave_format.nSamplesPerSec),
0,
&wave_format,
default_period,
&negotiated_format,
null,
))) |err| return err;
@ -179,6 +226,6 @@ fn fastSin(x: f32) f32 {
return abs * sign;
}
pub fn main() !void {
std.debug.print("exiting with code: {}\n", .{WindowsAudio.audioWorker()});
}
// pub fn main() !void {
// std.debug.print("exiting with code: {x}\n", .{@as(u32, @bitCast(WindowsAudio.audioWorker()))});
// }