An open API service indexing awesome lists of open source software.

https://github.com/1bardesign/garbage_geiger

An audio memory debugging tool for love2d
https://github.com/1bardesign/garbage_geiger

audio debugging love2d lua lua-library memory memory-management

Last synced: about 1 month ago
JSON representation

An audio memory debugging tool for love2d

Awesome Lists containing this project

README

        

# ☢️ `garbage_geiger`

> A dosimeter for garbage exposure in LÖVE

`garbage_geiger` emits a [geiger(-muller) counter](https://en.wikipedia.org/wiki/Geiger_counter) like noise when there is a lot of memory being allocated or garbage being collected. That's all!

This can give a good indication of potential "gc problem" events in your game. If you get a huge chatter after an attack, you may be allocating too much. If you get a roar right around when your game freezes for a frame or three, its a hint that garbage generation might be an issue.

It is designed for use with [LÖVE](https://love2d.org) 11.x and is intended to be easy to drop into existing projects.

Inspired by [malloc_geiger](https://github.com/laserallan/malloc_geiger).

# Features

- One source, on-demand sound generation
- No garbage generated by the module while it's operating, other than garbage generated internally by love
- Internal RNG state to avoid polluting love.math.random
- Configurable for sensitivity in garbage-heavy or garbage-light environments

# Installation

- Copy [garbage_geiger.lua](./garbage_geiger.lua) and [license.txt](./license.txt) somewhere convenient
- Wherever you put dependencies in your project
- `require` it in your code and construct a new instance
- Optionally configure the instance
- The defaults are fine for starters
- Update it each time around your update loop
- Don't forget to pass `dt`
- Optionally provide some way to deactivate it, for when you next say "hrm, maybe this is a garbage issue..."
- Maybe only have it active when some key is held, or via your console

# Example Usage

```lua
--set up our object
local geiger = require("garbage_geiger"):new()

function love.update(dt)
--audio is generated and played
--(can be done anywhere else with access to the time since last frame)
geiger:update(dt)

-- ... (rest of your game logic)
end

```

# Demo

The provided [main.lua](./main.lua) is a simple demo which allows listening the effect for different garbage generation workloads.

# Limitations

- Generates sound buffers at 30hz (configurable in the source), so there's _at least_ that much latency between something happening and it being audible (plus OS mixing, your sound card, any hardware between your machine and the speakers, etc)
- Will not generate sound if there has been garbage generated _and_ cleaned between updates; lua does not expose any way to check this, and even if it did the implication is pretty expensive.
- Does add some CPU load, though generally much less than a millisecond of work per generation.
- The clicks aren't super high fidelity - but they are audible and feel geiger-y!

# Pull Requests

Contributions will be merged "fairly optimistically"; if it adds something meaningful I'm happy to pull it in.

# License

MIT, see [`license.txt`](./license.txt)