{"id":16866310,"url":"https://github.com/jprjr/miniflac","last_synced_at":"2025-07-19T01:04:18.102Z","repository":{"id":37481923,"uuid":"382429820","full_name":"jprjr/miniflac","owner":"jprjr","description":"Single-file FLAC decoder with a push-style API","archived":false,"fork":false,"pushed_at":"2025-02-16T16:22:33.000Z","size":313,"stargazers_count":34,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T09:06:07.210Z","etag":null,"topics":["audio","c","codec","decoder","flac","minimal","music","single-header","single-header-lib","single-header-library","sound","tiny"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jprjr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-02T18:19:46.000Z","updated_at":"2025-03-29T03:12:04.000Z","dependencies_parsed_at":"2024-10-28T21:50:03.484Z","dependency_job_id":null,"html_url":"https://github.com/jprjr/miniflac","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jprjr/miniflac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Fminiflac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Fminiflac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Fminiflac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Fminiflac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jprjr","download_url":"https://codeload.github.com/jprjr/miniflac/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprjr%2Fminiflac/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265866268,"owners_count":23840937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","c","codec","decoder","flac","minimal","music","single-header","single-header-lib","single-header-library","sound","tiny"],"created_at":"2024-10-13T14:50:06.553Z","updated_at":"2025-07-19T01:04:18.077Z","avatar_url":"https://github.com/jprjr.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# miniflac\n\nA single-file C library for decoding FLAC streams. Does not use any C library\nfunctions, does not allocate any memory.\n\n## Features\n\n* push-style API or pull-style API\n* does not allocate memory or use any c library functions\n* handles native FLAC as well as Ogg FLAC\n* supports Ogg files with multiple bitstreams (only decodes the first FLAC bitstream)\n* supports chained ogg files, including chained multi-bitstream files\n* single C file\n* metadata decoding for:\n  * [`STREAMINFO`](https://xiph.org/flac/format.html#metadata_block_streaminfo)\n  * [`VORBIS_COMMENT`](https://xiph.org/flac/format.html#metadata_block_vorbis_comment)\n  * [`PICTURE`](https://xiph.org/flac/format.html#metadata_block_picture)\n  * [`CUESHEET`](https://xiph.org/flac/format.html#metadata_block_cuesheet)\n  * [`SEEKTABLE`](https://xiph.org/flac/format.html#metadata_block_seektable)\n  * [`APPLICATION`](https://xiph.org/flac/format.html#metadata_block_application)\n\n## Future Improvements\n\n* Speed optimizations\n* Memory reduction\n\n## Usage\n\nIn one C file define `MINIFLAC_IMPLEMENTATION` before including `miniflac.h`.\n\n```c\n#define MINIFLAC_IMPLEMENTATION\n#include \"miniflac.h\"\n```\n\n### Push-style API\n\nTo use the push-style API, allocate a `miniflac_t` struct, call\n`miniflac_init` to initialize the struct, and use functions prefixed\nwith `miniflac_`.\n\nAll functions follow a similar paradigm - you provide a buffer of data,\nthe length of the buffer, and an out-variable to record the amount of data\nconsumed. If more bytes are needed, functions return `MINIFLAC_CONTINUE`. You can\nloop around these functions until they return something other than\n`MINIFLAC_CONTINUE`.\n\n`miniflac_sync` will read data until it parses a metadata header or audio\nframe header. You can inspect the struct to determine if you're in a\nmetadata block or audio frame, and respond accordingly.\n\n`miniflac_decode` will read data until it's decoded an audio frame. You can\ncheck the size of the audio frame by inspecting the `frame.header` struct.\n\nSee the example programs under the `examples` directory.\n\n### Pull-style API\n\nTo use the pull-style API, allocate a `mflac_t` struct, call `mflac_init`\nwith your data-reading callback and userdata, then use functions\nprefixed with `mflac_t`\n\nAll the pull-style functions follow a similar style - you call the\nfunction with any needed out-variables. If you're out of data, the\nfunctions will return `MFLAC_EOF`, otherwise they should return\n`MFLAC_OK` or `MFLAC_METADATA_END` (in the case of an iterator-type\nfunction). Any other result can be cast into a `MINIFLAC_RESULT`\nenum.\n\nUsing the pull-style API is similar to the push - you call\n`mflac_sync`, which will read data using your callback until\nit parses a metadata header or audio frame header. You inspect\nthe struct to determine the kind of block, or use the convenience\nstatus functions (`mflac_is_metadata`, `mflac_is_frame`, etc).\n\nSee the example program `basic-decoder-mflac` in the `examples` directory.\n\n## Tips\n\nIt's possible to build the library using the individual sources\nand headers under the `/src` directory. Essentially, `flac.h` functions\nsimilarly as `miniflac.h`.\n\nBecause of this, some functions aren't inlined, you can get a\nconsiderable speed improvement by overriding the `MINIFLAC_API` and `MINIFLAC_PRIVATE` defines, and set `MINIFLAC_PRIVATE` to `static inline`:\n\n```c\n#define MINIFLAC_IMPLEMENTATION\n#define MINIFLAC_API\n#define MINIFLAC_PRIVATE static inline\n#include \"miniflac.h\"\n```\n\nOn my tests, this results in about a 4x speed improvement.\n\n\n## Details\n\n`miniflac` offers a \"push-style\" interface. After initializing the decoder,\nyou give it a chunk of data. It will consume some amount of data (not\nnecessarily all) and decode audio. You'll need to keep track of how\nmuch data was consumed, and hold on to any un-consumed bytes for\nthe next function call.\n\nThere's no callbacks involved, and you can provide as little as one byte\nat a time.\n\nThis library does not perform any data allocations, everything can be\nstatically allocated if you like. A library user will need to provide\na buffer for writing decoded audio samples. FLAC supports up to 8 channels\nof audio, and up to 65535 samples per frame of audio, so the maximum\nrequired audio buffer is:\n\n` (8 channels) * (65535 samples) * (4 bytes/sample) = 2097120 bytes`\n\nIn practice you often need less, most FLAC files are in the \"streamable\"\nsubset, which limits the frame size to 16384 samples, or 4608 samples if the\nsample rate is \u003c= 48kHz, and probably only 2 channels.\n\n## LICENSE\n\nBSD Zero Clause (see the `LICENSE` file).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprjr%2Fminiflac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjprjr%2Fminiflac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprjr%2Fminiflac/lists"}