Skip to content

Unify LPC coefficient tables with architectural improvements#9

Merged
cgreening merged 2 commits intomainfrom
refactor/unified-tables
Nov 7, 2025
Merged

Unify LPC coefficient tables with architectural improvements#9
cgreening merged 2 commits intomainfrom
refactor/unified-tables

Conversation

@cgreening
Copy link
Copy Markdown
Contributor

Summary

Refactors the codebase to use tmsTables.ts as the single source of truth for TMS5220/TMS5100/TMS5200 speech synthesis coefficient tables, eliminating duplicate table definitions and improving maintainability.

Key Changes

Architecture Improvements

  • ✅ Added ChipVariant type for type-safe chip selection ('tms5220' | 'tms5100' | 'tms5200')
  • ✅ Added CodingTable.getChipConfig() for controlled table access
  • ✅ Added CodingTable.getSynthesisK() for proper coefficient quantization
  • ✅ All chip variants now fully supported (including tms5200)

Table Unification

  • ✅ Removed ~120 lines of duplicate hardcoded tables from talkieStream.ts
  • ✅ TalkieStream now uses tmsTables.ts for all coefficient data
  • ✅ Phrase definitions updated to use lowercase chip identifiers
  • ✅ Net reduction: 72 lines of code (-155/+83)

Critical Fix: Synthesis Quantization

  • ✅ Encoding uses normalized coefficient values from tmsTables
  • ✅ Synthesis requires quantized fixed-point register values
  • ✅ Added conversion logic in CodingTable.getSynthesisK():
    • K1/K2: multiply by 64 (16-bit signed Q15 format)
    • K3-K10: divide by 4 (8-bit signed Q7 format)
  • ✅ TalkieStream initializes separate synthesis lookup tables on say()

API Changes

  • TalkieStream.say() now accepts ChipVariant string instead of number
  • ✅ Removed backward compatibility constants (TalkieDevice.*)
  • ✅ LpcEncoder/LpcPlayer components use ChipVariant type throughout

Benefits

  • 🎯 Single source of truth for coefficient tables
  • 🔒 Type-safe chip variant selection
  • 🎵 Proper separation of encoding vs synthesis representations
  • 📦 Smaller bundle size (~400 bytes saved)
  • 🚀 Support for all TMS chip variants
  • 🛠️ Improved maintainability and testability

Testing

  • ✅ All 28 unit tests passing
  • ✅ Build and lint checks passing
  • ✅ Playback functionality verified for all chip variants

Files Changed

  • src/tmsTables.ts - Added ChipVariant type and CodingTable static methods
  • src/talkieStream.ts - Major refactor, removed ~120 lines of duplicate tables
  • src/lib/tools/LpcEncoder.svelte - Updated to use ChipVariant type
  • src/lib/tools/LpcPlayer.svelte - Updated to use ChipVariant type
  • src/lpc-phrases/*.ts (5 files) - Updated table identifiers to lowercase

🤖 Generated with Claude Code

Refactors the codebase to use tmsTables.ts as the single source of truth
for TMS5220/TMS5100/TMS5200 speech synthesis coefficient tables, eliminating
duplicate table definitions and improving maintainability.

## Key Changes

### Architecture Improvements
- Added `ChipVariant` type for type-safe chip selection ('tms5220' | 'tms5100' | 'tms5200')
- Added `CodingTable.getChipConfig()` for controlled table access
- Added `CodingTable.getSynthesisK()` for proper coefficient quantization
- All chip variants now fully supported (including tms5200)

### Table Unification
- Removed ~120 lines of duplicate hardcoded tables from talkieStream.ts
- TalkieStream now uses tmsTables.ts for all coefficient data
- Phrase definitions updated to use lowercase chip identifiers
- Net reduction: 72 lines of code (-155/+83)

### Critical Fix: Synthesis Quantization
- Encoding uses normalized coefficient values from tmsTables
- Synthesis requires quantized fixed-point register values
- Added conversion logic in CodingTable.getSynthesisK():
  - K1/K2: multiply by 64 (16-bit signed Q15 format)
  - K3-K10: divide by 4 (8-bit signed Q7 format)
- TalkieStream initializes separate synthesis lookup tables on say()

### API Changes
- TalkieStream.say() now accepts ChipVariant string instead of number
- Removed backward compatibility constants (TalkieDevice.*)
- LpcEncoder/LpcPlayer components use ChipVariant type throughout

## Benefits

- Single source of truth for coefficient tables
- Type-safe chip variant selection
- Proper separation of encoding vs synthesis representations
- Smaller bundle size (~400 bytes saved)
- Support for all TMS chip variants
- Improved maintainability and testability

## Testing

- All 28 unit tests passing ✓
- Build and lint checks passing ✓
- Playback functionality verified for all chip variants ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Nov 7, 2025

Deploying ch32v003-music with  Cloudflare Pages  Cloudflare Pages

Latest commit: 06685f0
Status: ✅  Deploy successful!
Preview URL: https://b2d846cd.ch32v003-music.pages.dev
Branch Preview URL: https://refactor-unified-tables.ch32v003-music.pages.dev

View logs

Run Prettier to fix formatting issues in 10 files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cgreening cgreening merged commit 5c73c71 into main Nov 7, 2025
2 checks passed
@cgreening cgreening deleted the refactor/unified-tables branch November 7, 2025 14:38
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.

1 participant