electro-smith / libDaisy

Hardware Library for the Daisy Audio Platform
https://www.electro-smith.com/daisy
MIT License
312 stars 131 forks source link

Feature: audio output compensation #530

Closed stephenhensley closed 2 years ago

stephenhensley commented 2 years ago

Minor feature update for the AudioHandle.

This adds the ability to set a compensation value for the output signal to match the analog input level.

This can be useful in hardware where the input and output levels differ due to the attached circuits.

It is the equivalent of doing a multiply on each output sample at the end of the callback.

This differs from the "postgain" which is an adjustment to the "1.0" point to allow for hardware with extra headroom to have its nominal analog level match a normalized -1 to 1 range in software.


Tested this on hardware using 24-bit SAI bit-depth, non-interleaving callback

github-actions[bot] commented 2 years ago

Unit Test Results

    1 files  ±0    16 suites  ±0   0s :stopwatch: ±0s 150 tests ±0  150 :heavy_check_mark: ±0  0 :zzz: ±0  0 :x: ±0 

Results for commit 666dd3a2. ± Comparison against base commit 80ab34b3.

:recycle: This comment has been updated with latest results.

TheSlowGrowth commented 2 years ago

Just saw this now. Could we maybe precompute the postgain * compensation to avoid introducing an additional multiplication step for each sample?

stephenhensley commented 2 years ago

@TheSlowGrowth yes, certainly.

That's a good idea. I didn't like having the extra multiplication for each step, either. I can do a quick patch for that. 😄

stephenhensley commented 2 years ago

opened a new PR #531