0.1.2 WaveMix

This commit is contained in:
rob tillaart 2022-03-27 10:26:59 +02:00
parent e8cfa49171
commit 16918bada3
8 changed files with 98 additions and 27 deletions

View File

@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.2] - 2022-03-26
### Added
- add **setOffset(offset)** and **getOffset()**
- add example
### Changed
- updated **mix()** code
### Fixed
- set gain explicit in constructor.
## [0.1.1] - 2022-03-26
### Added

View File

@ -41,6 +41,9 @@ Channel B will have 100 - percentage.
An important use of gain is to amplify weak signals but one can also use it as a modulator of a signal.
See examples.
- **float getGain()** return the gain set.
- **void setOffset(float offset)** sets the offset for the output signal.
Typical used to align the zero level.
- **float getOffset()** return the current offset used.
- **float mix(float s1, float s2 = 0)** returns the weighted average of signal1 and signal2.
Signal2 is made optional to allow single signal processes e.g. modulation by **setGain()**.
@ -71,32 +74,28 @@ When the gain is negative, the output is effectively inverted.
## Future ideas
#### 0.2.0
#### N channel variant.
- make a N channel variant.
- add **setValue(uint8_t channel, float value)** allow update of channels at a different frequency.
- add **getValue()**, read the current output given the value of the channels. OR
- add **getValue(uint8_t mask = 0xFF)**, read the current output given the value of selected channels.
- add **setMask(uint8_t mask = 0xFF)**, select channels. ease of use? **getValue(mask)** still needed?
- add **getMask()**, read back \_mask;
- note that **mix()** can be implemented with the above functions.
- add **setWeight(uint8_t channel, float weight)** need internal array of weights and \_sum
- add **float getWeight(uint8_t channel)**
- add constructor **WaveMix(uint8_t channels = 8)** with parameter to set the nr of channels?
- or do we need **WaveMix2()**, **WaveMix4()**, **WaveMix8()**, or even **WaveMix16()**, **WaveMix24()**, **WaveMix32()** class?
- add **setValue(uint8_t channel, float value)** allow update of channels at a different frequency.
- add **getValue()**, read the current output given the value of the channels. OR
- add **getValue(uint8_t mask = 0xFF)**, read the current output given the value of selected channels.
- add **setMask(uint8_t mask = 0xFF)**, select channels. ease of use? **getValue(mask)** still needed?
- add **getMask()**, read back \_mask;
- note that **mix()** can be implemented with the above functions.
- add **setWeight(uint8_t channel, float weight)** need internal array of weights and \_sum
- add **float getWeight(uint8_t channel)** Normalized or not?
Not normalized allows easier increment per channel. Needs a **float getTotalWeight()**.
- add constructor **WaveMix(uint8_t channels = 8)** with parameter to set the number of channels? \[NO\]
- or do we need **WaveMix2()**, **WaveMix4()**, **WaveMix8()**, or even **WaveMix16()**, **WaveMix24()**, **WaveMix32()** class?
**WaveMix4()** and **WaveMix8()** seems to be realistic in terms of performance.
**WaveMix8()** can be used for 2-8 channels, using a uint8_t mask.
More channels will be much slower, so upon request the 16 and 32 variant?
More channels will be much slower, so upon request the 16 and 32 variant? other variants can be obtained by masking.
#### Medium
- add **void setOffset(float)**
- add **float getOffset()**
- add top clipping
- add **setMaximum(float)**
- add **setMinimum(float)**
- performance test.
@ -113,5 +112,16 @@ More channels will be much slower, so upon request the 16 and 32 variant?
- add **increment(float)**
- add **decrement(float)**
- percentages? hard for multichannel?
- default parameters
- gain = 1.0
- percentage 50%
- offset = 0.0
- **reset()** needed?
#### wont
- add top clipping
- add **setMaximum(float)**
- add **setMinimum(float)**
- needs an enable/disable per limit.
becomes more complex than let the user constrain the output.

View File

@ -1,7 +1,7 @@
//
// FILE: WaveMix.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library to mix two signals (A and B) with an adaptive weight.
// URL: https://github.com/RobTillaart/WaveMix
//
@ -14,6 +14,8 @@ WaveMix::WaveMix()
{
_weight[0] = 0.5;
_weight[1] = 0.5;
_gain = 1.0;
_offset = 0.0;
}
@ -34,10 +36,13 @@ void WaveMix::setPercentage(float percentage)
float WaveMix::mix(float s1, float s2)
{
float total = 0;
if (_gain == 0) return 0;
if (_weight[0] == 0) return s2 * _gain;
if (_weight[1] == 0) return s1 * _gain;
return ((_weight[0] * s1) + (_weight[1] * s2)) * _gain;
if (_weight[0] != 0) total += (_weight[0] * s1);
if (_weight[1] != 0) total += (_weight[1] * s2);
total *= _gain;
if (_offset != 0) total += _offset;
return total;
}

View File

@ -2,7 +2,7 @@
//
// FILE: WaveMix.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library to mix two signals (A and B) with an adaptive weight.
// URL: https://github.com/RobTillaart/WaveMix
//
@ -10,7 +10,7 @@
#include "Arduino.h"
#define WAVEMIX_LIB_VERSION (F("0.1.1"))
#define WAVEMIX_LIB_VERSION (F("0.1.2"))
class WaveMix
@ -28,12 +28,16 @@ public:
void setGain(float gain) { _gain = gain; };
float getGain() { return _gain; };
void setOffset(float offset) { _offset = offset; };
float getOffset() { return _offset; };
float mix(float s1, float s2 = 0);
private:
float _weight[2] = { 0.5, 0.5 };
float _gain = 1.0;
float _offset = 0.0;
};

View File

@ -0,0 +1,36 @@
//
// FILE: waveMix_demo_noise_offset.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/WaveMix
//
#include "WaveMix.h"
WaveMix wm;
float n = 0;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("WAVEMIX_LIB_VERSION: ");
Serial.println(WAVEMIX_LIB_VERSION);
wm.setPercentage(95);
}
void loop()
{
Serial.println(wm.mix(sin(n), random(1000) * 0.001) * 100);
n = n + 0.05;
delay(10);
wm.setOffset(int(n/20)); // just a demo
}
// -- END OF FILE --

View File

@ -13,6 +13,9 @@ setPercentage KEYWORD2
setGain KEYWORD2
getGain KEYWORD2
setOffset KEYWORD2
getOffset KEYWORD2
mix KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/WaveMix.git"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=WaveMix
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to mix two signals (A and B) with an adaptive weight.