Adding more CSound models

This commit is contained in:
2025-10-13 13:45:33 +02:00
parent 580aa4b96f
commit 38479f0253
31 changed files with 1458 additions and 23 deletions

View File

@ -55,6 +55,69 @@ Opens on http://localhost:8080
4. Keep all DSP code, helpers, and types in the same file
5. Register in `src/lib/audio/engines/registry.ts`
### Adding CSound-Based Synthesis Engines
For complex DSP algorithms, you can leverage CSound's powerful audio language:
1. Create a single file in `src/lib/audio/engines/` extending the `CsoundEngine<ParamsType>` abstract class
2. Define a TypeScript interface for your parameters
3. Implement required methods:
- `getName()`: Engine display name
- `getDescription()`: Brief description
- `getType()`: Return `'generative'`, `'sample'`, or `'input'`
- `getOrchestra()`: Return CSound orchestra code as a string
- `getParametersForCsound(params)`: Map TypeScript params to CSound channel parameters
- `randomParams(pitchLock?)`: Generate random parameter values
- `mutateParams(params, mutationAmount?, pitchLock?)`: Mutate existing parameters
4. Keep all enums, interfaces, and helper logic in the same file
5. Register in `src/lib/audio/engines/registry.ts`
**CSound Orchestra Guidelines:**
- Use `instr 1` as your main instrument
- Read parameters via `chnget "paramName"`
- Duration is available as `p3`
- Time-based parameters (attack, decay, release) should be ratios (0-1) scaled by `p3`
- Output stereo audio with `outs aLeft, aRight`
- The base class handles WAV parsing, normalization, and fade-in
**Example:**
```typescript
import { CsoundEngine, type CsoundParameter } from './base/CsoundEngine';
interface MyParams {
frequency: number;
resonance: number;
}
export class MyEngine extends CsoundEngine<MyParams> {
getName() { return 'My Engine'; }
getDescription() { return 'Description'; }
getType() { return 'generative' as const; }
protected getOrchestra(): string {
return `
instr 1
iFreq chnget "frequency"
iRes chnget "resonance"
aNoise noise 1, 0
aOut butterbp aNoise, iFreq, iRes
outs aOut, aOut
endin
`;
}
protected getParametersForCsound(params: MyParams): CsoundParameter[] {
return [
{ channelName: 'frequency', value: params.frequency },
{ channelName: 'resonance', value: params.resonance }
];
}
randomParams() { /* ... */ }
mutateParams(params, amount = 0.15) { /* ... */ }
}
```
### Adding Audio Processors
1. Create a single file in `src/lib/audio/processors/` implementing the `AudioProcessor` interface