diff --git a/script/meow.wav b/script/meow.wav new file mode 100644 index 0000000..2ca4679 Binary files /dev/null and b/script/meow.wav differ diff --git a/script/nasty.wav b/script/nasty.wav new file mode 100644 index 0000000..9d8b2c6 Binary files /dev/null and b/script/nasty.wav differ diff --git a/script/nightcore.wav b/script/nightcore.wav new file mode 100644 index 0000000..debd312 Binary files /dev/null and b/script/nightcore.wav differ diff --git a/script/wavtest.py b/script/wavtest.py new file mode 100644 index 0000000..da23a6b --- /dev/null +++ b/script/wavtest.py @@ -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() \ No newline at end of file diff --git a/src/fuck.exe b/src/fuck.exe new file mode 100644 index 0000000..27087c2 Binary files /dev/null and b/src/fuck.exe differ diff --git a/src/imsuffering.cpp b/src/imsuffering.cpp index 8bae584..63f87b9 100644 --- a/src/imsuffering.cpp +++ b/src/imsuffering.cpp @@ -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"< { + 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()))}); +// }