* Simple string hash function for consistent pitch variations
(str: string)
| 236 | * Simple string hash function for consistent pitch variations |
| 237 | */ |
| 238 | private hashString(str: string): number { |
| 239 | let hash = 0; |
| 240 | for (let i = 0; i < str.length; i++) { |
| 241 | const char = str.charCodeAt(i); |
| 242 | hash = ((hash << 5) - hash) + char; |
| 243 | hash = hash & hash; // Convert to 32-bit integer |
| 244 | } |
| 245 | return Math.abs(hash) / 2147483647; // Normalize to 0-1 |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Resume audio context if it's suspended (required by some browsers) |