0.1.3 WaveMix

This commit is contained in:
rob tillaart 2022-11-27 10:36:01 +01:00
parent 7fd4dabcc8
commit 2c210ed8d8
8 changed files with 81 additions and 39 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -9,5 +24,6 @@ compile:
- esp32
- esp8266
# - mega2560
- rpipico
libraries:
- "DHTNEW"

View File

@ -6,38 +6,28 @@ 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
## [0.1.3] - 2022-11-27
- add RP2040 to build-CI
- add test for 0 in setWeight()
- add test for percentage in setPercentage()
- update unit test
- move code from .h to .cpp
- simplified changelog
### Added
## [0.1.2] - 2022-03-26
- add **setOffset(offset)** and **getOffset()**
- add example
### Changed
- updated **mix()** code
### Fixed
- set gain explicit in constructor.
## [0.1.1] - 2022-03-26
### Added
- add **setGain()** and **getGain()**
- add examples
### Changed
- updated readme.md
- removed constraints on weight and percentage
### Fixed
- minor edits and clean up
## [0.1.0] - 2022-03-24
### Added
- add initial version
### Changed
### Fixed

View File

@ -31,12 +31,14 @@ Differences
The main functions of the WaveMix:
- **explicit WaveMix()** Constructor
- **void setWeight(float weight1, float weight2)** set the weight of the channels A and B.
- **bool setWeight(float weight1, float weight2)** set the weight of the channels A and B.
The weights do not need to be normalized, so one can use e.g **setWeight(7, 13)** See below.
The function returns false if the weights sum up to 0. (no changes will be made)
- **float getW1()** return the normalized weight for channel A.
- **float getW2()** return the normalized weight for channel B.
- **void setPercentage(float percentage)** sets the weight for channel A preferably to 0 <= percentage <= 100.
- **bool setPercentage(float percentage)** sets the weight for channel A to percentage.
Channel B will have 100 - percentage.
Returns false if percentage < 0 or percentage > 100. (no changes will be made)
- **void setGain(float gain)** sets the gain factor.
An important use of gain is to amplify weak signals but one can also use it as a modulator of a signal.
See examples.
@ -95,7 +97,6 @@ More channels will be much slower, so upon request the 16 and 32 variant? other
#### Medium
- performance test.

View File

@ -1,10 +1,9 @@
//
// FILE: WaveMix.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library to mix two signals (A and B) with an adaptive weight.
// URL: https://github.com/RobTillaart/WaveMix
//
#include "WaveMix.h"
@ -19,21 +18,51 @@ WaveMix::WaveMix()
}
void WaveMix::setWeight(float weight1, float weight2)
bool WaveMix::setWeight(float weight1, float weight2)
{
if ((weight1 + weight2) == 0) return false; // test for <= 0 ?
float factor = 1.0 / (weight1 + weight2);
_weight[0] = weight1 * factor;
_weight[1] = weight2 * factor;
return true;
}
void WaveMix::setPercentage(float percentage)
bool WaveMix::setPercentage(float percentage)
{
if ((percentage < 0) || (percentage > 100)) return false;
_weight[0] = percentage * 0.01;
_weight[1] = 1.0 - _weight[0];
return true;
}
// do we need a value check here
void WaveMix::setGain(float gain)
{
_gain = gain;
};
float WaveMix::getGain()
{
return _gain;
};
// do we need a value check here
void WaveMix::setOffset(float offset)
{
_offset = offset;
};
float WaveMix::getOffset()
{
return _offset;
};
float WaveMix::mix(float s1, float s2)
{
float total = 0;
@ -46,5 +75,5 @@ float WaveMix::mix(float s1, float s2)
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,15 +2,14 @@
//
// FILE: WaveMix.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library to mix two signals (A and B) with an adaptive weight.
// URL: https://github.com/RobTillaart/WaveMix
//
#include "Arduino.h"
#define WAVEMIX_LIB_VERSION (F("0.1.2"))
#define WAVEMIX_LIB_VERSION (F("0.1.3"))
class WaveMix
@ -19,17 +18,17 @@ public:
explicit WaveMix();
// weight1 + weight2 != 0
void setWeight(float weight1, float weight2);
bool setWeight(float weight1, float weight2);
float getW1() { return _weight[0]; };
float getW2() { return _weight[1]; };
// preferably 0 <= percentage <= 100
void setPercentage(float percentage);
bool setPercentage(float percentage);
void setGain(float gain) { _gain = gain; };
float getGain() { return _gain; };
void setGain(float gain);
float getGain();
void setOffset(float offset) { _offset = offset; };
float getOffset() { return _offset; };
void setOffset(float offset);
float getOffset();
float mix(float s1, float s2 = 0);

View File

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

View File

@ -1,5 +1,5 @@
name=WaveMix
version=0.1.2
version=0.1.3
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.

View File

@ -63,6 +63,8 @@ unittest(test_setWeight)
assertEqualFloat(1.00, wm.getW1(), 0.001);
assertEqualFloat(0.00, wm.getW2(), 0.001);
assertTrue(wm.setWeight(0.0, 3.0));
assertFalse(wm.setWeight(-3.0, 3.0));
}
@ -83,7 +85,12 @@ unittest(test_setPercentage)
assertEqualFloat(0.27, wm.getW2(), 0.001);
wm.setPercentage(100);
assertEqualFloat(1.00, wm.getW1(), 0.001);
assertEqualFloat(0.00, wm.getW2(), 0.001);
assertEqualFloat(0.00, wm.getW2(), 0.001);
assertTrue(wm.setPercentage(0));
assertTrue(wm.setPercentage(100));
assertFalse(wm.setPercentage(-1));
assertFalse(wm.setPercentage(101));
}