Skip to content

BPM tracking improvement#1657

Closed
MintKeyphase wants to merge 19 commits intomoeru-ai:mainfrom
MintKeyphase:bpm-tracker-mod
Closed

BPM tracking improvement#1657
MintKeyphase wants to merge 19 commits intomoeru-ai:mainfrom
MintKeyphase:bpm-tracker-mod

Conversation

@MintKeyphase
Copy link
Copy Markdown

@MintKeyphase MintKeyphase commented Apr 13, 2026

Description

An attempt in switching to a better BPM detector to improve BPM detection accuracy.

Linked Issues

N/A

Additional Context

First time commit, may make a lot of mistakes. Also I did not remove the old code to minimize changes...

I did not remove the old code to minimize changes, you can beat me up now
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates the realtime-bpm-analyzer library to enable real-time BPM detection and metronome synchronization. Key updates include modifying the audio worklet to output high-fidelity audio and implementing a metronome that adjusts its interval based on detected BPM and audio energy. Review feedback highlights the need to resolve variable shadowing, properly configure the BPM analyzer instance, and ensure the frequency buffer is updated before energy calculations. Additionally, it is suggested to remove redundant memory allocations and debug workarounds.

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
channels: options.processorOptions?.channels || 1,
converterType: options.processorOptions?.converterType || ConverterType.SRC_SINC_MEDIUM_QUALITY,
bufferSize: options.processorOptions?.bufferSize || 4096,
bufferSize: options.processorOptions?.bufferSize || 16384,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Increasing the bufferSize to 16384 increases the memory allocated for inputBuffer and outputBuffer (lines 38-39), but these buffers are not utilized in the process method. If they are indeed redundant, it is recommended to remove them and revert this change to minimize memory overhead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the increase in necessary due to the increase in sample rate, which in turn allows for a broader spectrum to be recognized by the BPM detector

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
@github-actions github-actions Bot added feature Related to feature scope/audio-output Scope related to audio output (TTS, Voice cloning, etc.) labels Apr 13, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5c7dcac88

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
MintKeyphase and others added 5 commits April 13, 2026 19:13
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
~~I blame Gemini~~
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01143cd987

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cd336d2de

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Refactor audio data analysis method and remove async.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31ff4ff0fd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6f18558bc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread pnpm-lock.yaml
'@better-auth/drizzle-adapter':
specifier: ^1.6.2
version: 1.6.2(@better-auth/core@1.6.2(@better-auth/utils@0.4.0)(@better-fetch/fetch@1.1.21)(@opentelemetry/api@1.9.1)(better-call@1.3.5(zod@4.3.6))(jose@6.2.2)(kysely@0.28.16)(nanostores@1.2.0))(@better-auth/utils@0.4.0)(drizzle-orm@0.45.2(@electric-sql/pglite@0.4.4)(@opentelemetry/api@1.9.1)(@prisma/client@5.22.0)(@types/pg@8.20.0)(better-sqlite3@12.8.0)(kysely@0.28.16)(pg@8.20.0)(postgres@3.4.9))
version: 1.6.2(@better-auth/core@1.4.21(@better-auth/utils@0.3.0)(@better-fetch/fetch@1.1.21)(better-call@1.1.8(zod@4.3.6))(jose@6.2.2)(kysely@0.28.16)(nanostores@1.2.0))(@better-auth/utils@0.3.0)(drizzle-orm@0.45.2(@electric-sql/pglite@0.4.4)(@opentelemetry/api@1.9.1)(@prisma/client@5.22.0)(@types/pg@8.20.0)(better-sqlite3@12.8.0)(kysely@0.28.16)(pg@8.20.0)(postgres@3.4.9))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep server lockfile on compatible better-auth peer set

This lockfile change rewires apps/server to @better-auth/drizzle-adapter@1.6.2 resolved with @better-auth/core@1.4.21 and @better-auth/utils@0.3.0, which is incompatible with that adapter’s declared peer range (@better-auth/core ^1.6.2, utils 0.4.0). Because pnpm-lock.yaml is authoritative for frozen installs, this can introduce peer conflicts and unstable auth behavior unrelated to the BPM feature.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not my job.
(I never touched those)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9de0bec9ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts
MintKeyphase and others added 3 commits April 13, 2026 20:38
Updated createBeatSyncDetector to be asynchronous and modified the start method to call syncMetronome.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24a88bc2c0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/stage-shared/package.json Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Comment thread packages/stage-shared/src/beat-sync/detector.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1015724f9f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

worklet: analyserWorklet,
listeners: {
onBeat: e => emit('beat', e),
onBeat: () => {},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep forwarding TempoRA beat callbacks

Changing onBeat to a no-op removes the existing beat signal path from startTemporaAnalyser, so beat listeners now depend entirely on the new realtime-BPM path producing lock messages. In scenarios where that path is delayed or fails (e.g., no compatible audioData messages, analyzer error), beat sync emits nothing and appears broken, whereas the previous implementation still delivered beat events.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback emits 40 BPM beat events

@nekomeowww
Copy link
Copy Markdown
Member

Do you have any evidence that this is better?

@MintKeyphase
Copy link
Copy Markdown
Author

Instead of trying to pick up each spike in the audio stream, this tries to get a BPM that would lock in. This should make it more reliable and pick up beats from music that does not have spikes on beat.

@nekomeowww
Copy link
Copy Markdown
Member

Would you mind switch the implementation to have them co-exist for a while and let the user to judge which one is better?

So

  1. Have for selecting two implementations We will add data analysis hooks to verify whether the new package works better.

@MintKeyphase
Copy link
Copy Markdown
Author

That would actually be a great idea, I'll try doing that. Should I close this PR and start a new one when I am ready, or should the PR be kept open to wait for the changes?

@MintKeyphase
Copy link
Copy Markdown
Author

Since there is no activity, I'll be closing this PR and open a new one when I finish implementing the choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Related to feature scope/audio-output Scope related to audio output (TTS, Voice cloning, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants