Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
# Pinned major version: formatting output can differ across releases.
- name: Check formatting
# Run the TapHouse pre-commit hook — the same pinned clang-format
# developers get from `pre-commit install` (.pre-commit-config.yaml), so
# local and CI share one version AND one file scope (all C/C++ minus
# third_party) by construction. pipx is preinstalled on the runner.
- name: Check formatting (pre-commit)
run: |
sudo apt-get update -q && sudo apt-get install -y -q clang-format-18
clang-format-18 --dry-run --Werror \
include/srt/*.h include/srt/detail/*.h \
bench/*.cpp bench/icount/*.cpp bench/compare/*.cpp \
tools/capi/*.cpp tools/qemu_insn_plugin/*.c \
tests/*.cpp tests/support/*.h examples/*.cpp platform/*.c
pipx install pre-commit
pre-commit run --all-files --show-diff-on-failure

# The book (book/) quotes library code via mdBook anchor includes; this
# gate makes a refactor that orphans an excerpt fail CI, the same
Expand Down
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Canonical Tap House pre-commit config — the single source of truth for the
# Tap family's local formatting hook. Distributed to every Tap repo by
# scripts/sync.sh (alongside .clang-format / .clang-tidy / STYLE.md) and kept
# honest by the drift-check workflow, so every repo runs the SAME hook at the
# SAME pinned clang-format version.
#
# Why the pin matters: an ad-hoc hook using each machine's own clang-format
# would format differently than CI and be worse than none. The `rev` below is
# the Tap-wide clang-format version — bump it HERE, re-sync, and every repo
# (and its CI, which runs `pre-commit run --all-files`) moves together.
#
# Adopt in a consumer repo:
# 1. taphouse/scripts/sync.sh /path/to/your-repo # copies this file in
# 2. cd your-repo && pre-commit install # once per clone
# Thereafter `git commit` formats staged C/C++ before it can be pushed, so the
# clang-format CI gate can never fail on a local commit again.
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.3 # Tap-wide clang-format version (matches CI)
hooks:
- id: clang-format
types_or: [c, c++]
exclude: '^third_party/' # vendored sources are formatted upstream, never by us
21 changes: 10 additions & 11 deletions scripts/book_figures_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@

int main(int argc, char** argv) {
if (argc < 5) {
std::fprintf(stderr, "usage: %s pullBlock pushBlock ppm seconds [dropStart dropDur]\n",
argv[0]);
std::fprintf(stderr, "usage: %s pullBlock pushBlock ppm seconds [dropStart dropDur]\n", argv[0]);
return 2;
}
const std::size_t pullBlock = static_cast<std::size_t>(std::atol(argv[1]));
const std::size_t pushBlock = static_cast<std::size_t>(std::atol(argv[2]));
const double ppm = std::atof(argv[3]);
const double seconds = std::atof(argv[4]);
const double dropStart = argc > 5 ? std::atof(argv[5]) : -1.0;
const double dropDur = argc > 6 ? std::atof(argv[6]) : 0.0;
const double ppm = std::atof(argv[3]);
const double seconds = std::atof(argv[4]);
const double dropStart = argc > 5 ? std::atof(argv[5]) : -1.0;
const double dropDur = argc > 6 ? std::atof(argv[6]) : 0.0;

srt::Config cfg;
cfg.channels = 1;
srt::AsyncSampleRateConverter conv(cfg);

const double fsOut = cfg.sampleRateHz;
const double fsIn = fsOut * (1.0 + ppm * 1e-6); // producer's crystal
const double fsOut = cfg.sampleRateHz;
const double fsIn = fsOut * (1.0 + ppm * 1e-6); // producer's crystal
std::vector<float> in(pushBlock), out(pullBlock);

double tPush = 0.0, tPull = 0.0, phase = 0.0;
double tPush = 0.0, tPull = 0.0, phase = 0.0;
const double dPhase = 2.0 * std::numbers::pi * 997.0 / fsIn;
std::puts("t,fill,state,ppm,underruns");
while (tPull < seconds) {
Expand All @@ -56,8 +55,8 @@ int main(int argc, char** argv) {
conv.pull(out.data(), pullBlock);
tPull += static_cast<double>(pullBlock) / fsOut;
const srt::Status s = conv.status();
std::printf("%.6f,%.2f,%d,%.2f,%llu\n", tPull, s.fifoFillFrames, static_cast<int>(s.state),
s.ppm, static_cast<unsigned long long>(s.underruns));
std::printf("%.6f,%.2f,%d,%.2f,%llu\n", tPull, s.fifoFillFrames, static_cast<int>(s.state), s.ppm,
static_cast<unsigned long long>(s.underruns));
}
return 0;
}
Loading