Skip to content

Commit

Permalink
allow setting samplerate and blocksize for Daisy using meta info (#133)
Browse files Browse the repository at this point in the history
* allow setting samplerate and blocksize for Daisy using meta info

* add sr/bs to Daisy docs

* mention max blocksize; clamp blocksize between 1 and 256

* reword Daisy docs
  • Loading branch information
dromer authored Nov 13, 2023
1 parent 9b2c80e commit 4f81017
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Next Release

* Objects: `[bang~]`
* Documentation fixes/additions
* Daisy: ability to set samplerate and blocksize
* DPF: enum for UI parameter IDs
* DPF bugfixes: correct input PortGroup names

Expand Down
17 changes: 16 additions & 1 deletion docs/03.gen.daisy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Daisy is an embedded platform for music. It features everything you need for cre

Currently daisy platform is supported for:

* `field`
* `seed`
* `pod`
* `petal`
* `patch`
* `patch_init`
* `patch_sm`
* `field`

Which can be configured using the `-m` metadata.json `daisy.board` setting:

Expand Down Expand Up @@ -65,3 +65,18 @@ Printing to serial console can be enabled using the `debug_printing` flag in the
```

This will increase the program size with a few kb and will disable `usb_midi` as we currently do not have composite USB device yet.

## Custom samplerate and blocksize

This can be done by adding either to the meta.json:

```json
{
"daisy": {
"samplerate": 96000,
"blocksize": 128
}
}
```

Do note that the samplerate will be automatically set to either 16k, 32k, 48k, or 96k. Blocksize will need to be 256 or less and is automatically capped.
10 changes: 9 additions & 1 deletion hvcc/generators/c2daisy/c2daisy.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,17 @@ def compile(
component_glue['header'] = f"HeavyDaisy_{patch_name}.hpp"
component_glue['max_channels'] = board_info['channels']
component_glue['num_output_channels'] = num_output_channels
component_glue['has_midi'] = board_info['has_midi']
component_glue['debug_printing'] = daisy_meta.get('debug_printing', False)
component_glue['usb_midi'] = daisy_meta.get('usb_midi', False)
component_glue['has_midi'] = board_info['has_midi']
component_glue['samplerate'] = daisy_meta.get('samplerate')

blocksize = daisy_meta.get('blocksize')

if blocksize:
component_glue['blocksize'] = max(min(256, blocksize), 1)
else:
component_glue['blocksize'] = None

component_glue['copyright'] = copyright_c

Expand Down
6 changes: 6 additions & 0 deletions hvcc/generators/c2daisy/templates/HeavyDaisy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ void HandleMidiMessage(MidiEvent m)
int main(void)
{
hardware.Init(true);
{% if samplerate is not none %}
hardware.SetAudioSampleRate({{samplerate}});
{% endif %}
{% if blocksize is not none %}
hardware.SetAudioBlockSize({{blocksize}});
{% endif %}
{% if has_midi %}
MidiUartHandler::Config midi_config;
hardware.midi.Init(midi_config);
Expand Down

0 comments on commit 4f81017

Please sign in to comment.