Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmitage committed Jul 11, 2022
1 parent 90d664e commit be8c67a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

.DS_Store
/wekiLib/

# Created by https://www.gitignore.io/api/emacs
Expand Down
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# RapidLib
# RapidLibBela

## Context

### RapidLib

[![GitHub license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/mzed/RapidLib/blob/master/LICENSE)

Expand All @@ -14,4 +18,47 @@

RapidLib is a lightweight library for interactive machine learning. It currently features classification (using kNN), regression (multilayer perceptron), and series classification (using dynamic time warping).

## More at: [https://mzed.github.io/RapidLib/](https://mzed.github.io/RapidLib/)
More at: https://mzed.github.io/RapidLib/

### Bela

Bela is a platform for ultra-low latency audio and sensor processing.

http://bela.io

## Install

See Releases.

## Build

- Requires "experimental" Bela image with recent CMake: https://github.com/BelaPlatform/bela-image-builder/releases/tag/v0.5.0alpha2.
- Highly recommended to install `distcc` ([guide](https://gist.github.com/jarmitage/2a5dffbcfdd5532371f097e9bb80e4b0)).
- `git clone` RapidLib onto Bela ([connecting to network on Bela](https://learn.bela.io/using-bela/bela-techniques/connecting-to-wifi))
- Comment out DTW multi-threading test (see https://github.com/mzed/RapidLib/issues/20).
- Build commands from inside `RapidLib` dir:

```sh
mkdir build && cd build
CC="distcc-clang" CXX="distcc-clang++" cmake -DCMAKE_CXX_FLAGS="-Werror" ..
CC="distcc-clang" CXX="distcc-clang++" cmake
ctest
```
- `make` parameters for RapidLib projects (see [Bela Blog](https://blog.bela.io/using-an-external-library-with-bela/)):

```
LDFLAGS=-L/root/RapidLib/build;LDLIBS=-lrapidLib;CPPFLAGS=-I/root/RapidLib/src;
```

## Examples

Currently very simple, based on https://github.com/mzed/ofxRapidLib

## Todo

- [ ] Benchmark RapidLib performance on Bela
- [ ] Add C++ examples using `AuxiliaryTask`
- [ ] Add C++ examples using sensor inputs and audio outputs
- [ ] Add C++ examples with Bela GUIs
- [ ] Add `install` to CMake to simplify installation
- [ ] Scope out SuperCollider / Pure Data support and examples
53 changes: 53 additions & 0 deletions bela_examples/knn/render.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Based on https://github.com/mzed/ofxRapidLib/tree/main/example-objectClassification

#include <Bela.h>
#include "rapidLib.h"

std::vector<rapidLib::trainingExample> myData;
std::vector<double> trainingInput;
std::vector<double> trainingOutput;
std::vector<double> inputVec;

rapidLib::classification myKnn;
rapidLib::trainingExample tempExample;

int examples = 10;
int recordingState = 2;
int result;

bool setup(BelaContext *context, void *userData)
{
tempExample.input = { 0.5, 0.3, 0.4 };
tempExample.output = { double(1) };
myData.push_back(tempExample);

tempExample.input = { 1.6, 1.7, 1.8 };
tempExample.output = { double(2) };
myData.push_back(tempExample);

tempExample.input = { 2.3, 2.4, 2.5 };
tempExample.output = { double(3) };
myData.push_back(tempExample);

if (myData.size() > 0)
myKnn.train(myData);

inputVec = { 0.34, 0.45, 0.54 };
result = myKnn.run(inputVec)[0];
rt_printf("Input: { %2f, %2f, %2f }\n", inputVec[0], inputVec[1], inputVec[2]);
rt_printf("Output: %i\n", result);

inputVec = { 1.34, 1.45, 1.54 };
result = myKnn.run(inputVec)[0];
rt_printf("Input: { %2f, %2f, %2f }\n", inputVec[0], inputVec[1], inputVec[2]);
rt_printf("Output: %i\n", result);

inputVec = { 2.34, 2.45, 2.54 };
result = myKnn.run(inputVec)[0];
rt_printf("Input: { %2f, %2f, %2f }\n", inputVec[0], inputVec[1], inputVec[2]);
rt_printf("Output: %i\n", result);

return true;
}
void render(BelaContext *context, void *userData){}
void cleanup(BelaContext *context, void *userData){}
40 changes: 40 additions & 0 deletions bela_examples/regression/render.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Bela.h>
#include "rapidLib.h"

rapidLib::regression mtofRegression;
std::vector<rapidLib::trainingExample> myData;
rapidLib::trainingExample tempExample;
int inputMIDINote = 60;

bool setup(BelaContext *context, void *userData)
{
tempExample.input = { 48 };
tempExample.output = { 130.81 };
myData.push_back(tempExample);

tempExample.input = { 54 };
tempExample.output = { 185.00 };
myData.push_back(tempExample);

tempExample.input = { 60 };
tempExample.output = { 261.63 };
myData.push_back(tempExample);

tempExample.input = { 66 };
tempExample.output = { 369.994 };
myData.push_back(tempExample);

tempExample.input = { 72 };
tempExample.output = { 523.25 };
myData.push_back(tempExample);

mtofRegression.train(myData);

std::vector<double> inputVec = { double(inputMIDINote) };
double freqHz = mtofRegression.run(inputVec)[0];
rt_printf("MIDI Note %i is %2fHz\n", inputMIDINote, freqHz);

return true;
}
void render(BelaContext *context, void *userData){}
void cleanup(BelaContext *context, void *userData){}

0 comments on commit be8c67a

Please sign in to comment.