Skip to content

Per-request MP3 bitrate control#63

Closed
ibarron9216 wants to merge 3 commits intoServeurpersoCom:masterfrom
ibarron9216:feature/mp3-bitrate-control-v2
Closed

Per-request MP3 bitrate control#63
ibarron9216 wants to merge 3 commits intoServeurpersoCom:masterfrom
ibarron9216:feature/mp3-bitrate-control-v2

Conversation

@ibarron9216
Copy link
Copy Markdown

Summary

Adds per-request MP3 bitrate selection, allowing callers to specify encoding quality on every /synth request instead of relying solely on the server-wide --mp3-bitrate flag.

Changes

C++ server (tools/ace-server.cpp)

  • Added int mp3_bitrate to ServerFields (0 = use server default g_mp3_kbps)
  • Validated mp3_bitrate in parse_server_fields against the full 14-value allowlist {32,40,48,56,64,80,96,112,128,160,192,224,256,320}; invalid values trigger HTTP 400 at all 6 call sites
  • Replaced hardcoded g_mp3_kbps in synth_worker with (sf.mp3_bitrate > 0) ? sf.mp3_bitrate : g_mp3_kbps
  • Added startup validation of --mp3-bitrate; invalid value exits with code 1

WebUI (tools/webui/)

  • config.ts: exported VALID_MP3_BITRATES with all 14 values
  • state.svelte.ts: added mp3Bitrate to app state and localStorage with validation on load
  • api.ts: added mp3Bitrate=0 param to both submit functions; injects mp3_bitrate into JSON only when format is mp3 and bitrate > 0
  • RequestForm.svelte: bitrate <select> in the format row, visible only for MP3, seeded from app.props.cli.mp3_bitrate on first load

Config

  • server.sh: added commented #--mp3-bitrate 128 example with all valid values listed inline
  • tools/public/index.html.gz: rebuilt from updated sources

API Usage

# 32 kbps MP3
curl -X POST http://localhost:8085/synth \
  -H 'Content-Type: application/json' \
  -d '{"caption": "calm piano", "mp3_bitrate": 32}'

# Invalid bitrate → HTTP 400
curl -X POST http://localhost:8085/synth \
  -H 'Content-Type: application/json' \
  -d '{"caption": "calm piano", "mp3_bitrate": 999}'
# {"error":"mp3_bitrate must be one of: 32,40,48,56,64,80,96,112,128,160,192,224,256,320"}

Verification

  • Server boots cleanly with and without --mp3-bitrate
  • WebUI bitrate selector appears for MP3, hidden for other formats
  • Selector seeded from server prop on first load; persists to localStorage
  • HTTP 400 on invalid bitrate; valid requests accepted
  • ffprobe confirms per-request bitrate in output file

Irving Barron added 3 commits April 22, 2026 06:14
Add int mp3_bitrate to ServerFields (0 = use server default g_mp3_kbps).
Validate against the full 14-value allowlist {32,40,48,56,64,80,96,112,
128,160,192,224,256,320} in parse_server_fields; invalid values set a -1
sentinel so all 6 call sites return HTTP 400.

Replace the hardcoded g_mp3_kbps in synth_worker with:
  (sf.mp3_bitrate > 0) ? sf.mp3_bitrate : g_mp3_kbps

Add post-atoi startup validation of --mp3-bitrate; exits with code 1 and
an error message on an invalid value.
config.ts: export VALID_MP3_BITRATES with all 14 server-accepted values
  [32,40,48,56,64,80,96,112,128,160,192,224,256,320]

state.svelte.ts: add mp3Bitrate to app state and localStorage; validate
  stored value against VALID_MP3_BITRATES on load (default 0)

api.ts: add optional mp3Bitrate=0 param to synthSubmit and
  synthSubmitWithAudio; inject mp3_bitrate into JSON only when format
  is mp3 and bitrate > 0 — never touches AceRequest type

RequestForm.svelte: bitrate <select> in the format row, visible only
  when app.format === 'mp3', bound to app.mp3Bitrate, seeded from
  app.props.cli.mp3_bitrate on first load (fallback 128), with a
  conditional extra option for non-preset server-configured values
server.sh: add commented #--mp3-bitrate 128 example after --max-batch
  with inline comment listing all 14 valid kbps values

tools/public/index.html.gz: rebuild from updated Svelte sources;
  includes full 14-value bitrate selector
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@ibarron9216 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 46 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 48 minutes and 46 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16f42507-6a8c-4692-ae36-9a3d41c95efa

📥 Commits

Reviewing files that changed from the base of the PR and between afb9f14 and 8fe9274.

⛔ Files ignored due to path filters (2)
  • tools/public/index.html.gz is excluded by !**/*.gz
  • tools/webui/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • server.sh
  • tools/ace-server.cpp
  • tools/webui/src/components/RequestForm.svelte
  • tools/webui/src/lib/api.ts
  • tools/webui/src/lib/config.ts
  • tools/webui/src/lib/state.svelte.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ibarron9216 ibarron9216 changed the title feat: per-request MP3 bitrate control Per-request MP3 bitrate control Apr 22, 2026
@ServeurpersoCom
Copy link
Copy Markdown
Owner

Hi! Thanks for your contribution! I've already planned to move this field from the dedicated bitrate to the rest of the request JSON, along with adding a new "Advanced Flow Matching and Post-Processing" section to standardize the API (and work same on CLIs), as more advanced parameters will be added very soon! The commit only adds 14 lines.

e1ed114

@ibarron9216
Copy link
Copy Markdown
Author

Hi! Thanks for your contribution! I've already planned to move this field from the dedicated bitrate to the rest of the request JSON, along with adding a new "Advanced Flow Matching and Post-Processing" section to standardize the API (and work same on CLIs), as more advanced parameters will be added very soon! The commit only adds 14 lines.

e1ed114

Great news! One quick question, any plan to add using an existing song (audio file) for the cover/lego/complete features? Or is it already there, and I just have not understood how to use it? I am talking about the WebUI, I know the functionality is there in acestep.cpp

Thank you for your amazing repo!

@ServeurpersoCom
Copy link
Copy Markdown
Owner

Anything is possible. It's a "playground," so everything is "folded in on itself" to be compact and work on mobile.

If you check "Src audio" + "Ref timbre" on a song, the "Cover" task lets you make remixes, and you also have Cover (nofsq) to condition the DiT and force it to reproduce variations very close to the original, and even modify the lyrics. It takes a little time to find the right "Cover strength" The "Repaint" function even lets you edit the lyrics, and it works better than Suno! ("Src" switch to Region selection)

@ibarron9216
Copy link
Copy Markdown
Author

Anything is possible. It's a "playground," so everything is "folded in on itself" to be compact and work on mobile.

If you check "Src audio" + "Ref timbre" on a song, the "Cover" task lets you make remixes, and you also have Cover (nofsq) to condition the DiT and force it to reproduce variations very close to the original, and even modify the lyrics. It takes a little time to find the right "Cover strength" The "Repaint" function even lets you edit the lyrics, and it works better than Suno! ("Src" switch to Region selection)

Thank you for the quick response! Based on your explanation, I can confirm the user error was entirely mine. I haven't been using the correct workflow for the WebUI. Specifically, I didn't realize you could check the 'Src audio' box for the 'Cover' function, as it always shows up red and uninteractable for me.

I was expecting a standard file explorer window to pop up so I could select my reference song, but that clearly isn't how it works! I know you aren't here to troubleshoot everything, but clarifying these UI interactions is really useful, may be once I get the hang of it, I could contribute to the documentation!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants