moutend / go-wca

Pure golang bindings for Windows Core Audio API. The `cgo` is not required.
MIT License
108 stars 28 forks source link

WASAPI IAudioSessionNotification, IAudioSessionEvents example #21

Open arkadijs opened 2 months ago

arkadijs commented 2 months ago

First of all, thank you for making WCA with Go possible and introducing some needed sanity to Win32 programming. :)

I'm sending a working example of IAudioSessionNotification, IAudioSessionEvents WASAPI usage, together with opinionated but required build system rework. I'm open to take the restructure out but it's a meaningful change for modern Go.

  1. Made Makefile more Makefile-ish by removing ad-hoc shell invocations.
  2. Examples moved to example/ so that Go tools are not confused by underscore symbol.
  3. Removed go.mod from examples. Try go build github.com/moutend/go-wca/example/DeviceEvents or make bin/DeviceEvents.exe
  4. Fixed some obvious typos and Go type mismatches.
  5. Fixed (some?) zero pointer dereferences after failed IAudioSessionControl interface method invocation.
  6. Finally, added an example program AudioSessionNotification to watch for audio session creation and follow-up events on the default playback device.

In case you're curious to try this PR in a standalone program, add to go.mod:

replace github.com/moutend/go-wca v0.3.0 => github.com/arkadijs/go-wca v0.0.0-20240709192616-1ae852f105b4