Skip to content

Commit b5fdb2a

Browse files
committed
Arduino Support
1 parent 0a1635c commit b5fdb2a

File tree

15 files changed

+420
-0
lines changed

15 files changed

+420
-0
lines changed

examples/FileLoop/FileLoop.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "FileLoop.h"
2+
#include "ArdStreamOut.h"
3+
4+
using namespace stk;
5+
6+
FileLoop input;
7+
ArdStreamOut output(Serial);
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
12+
input.openFile( "rawwaves/sinewave.raw", true );
13+
14+
Stk::setSampleRate( 44100.0 );
15+
input.setFrequency( 440.0 );
16+
}
17+
18+
void loop() {
19+
output.tick( input.tick() );
20+
}

examples/HelloSine/HelloSine.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "SineWave.h"
2+
#include "ArdStreamOut.h"
3+
4+
using namespace stk;
5+
6+
SineWave input;
7+
ArdStreamOut output(Serial);
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
12+
Stk::setSampleRate( 44100.0 );
13+
input.setFrequency( 440.0 );
14+
}
15+
16+
void loop() {
17+
output.tick( input.tick() );
18+
}
19+

examples/Instrument/Instrument.ino

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "ArdStreamOut.h"
2+
#include "ArdMidiCommon.h"
3+
#include "Clarinet.h"
4+
5+
using namespace stk;
6+
7+
ArdStreamOut output(Serial);
8+
Clarinet instrument(440);
9+
int note = 90; // starting midi note
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
}
14+
15+
void loop() {
16+
note += rand() % 10 - 5; // generate some random offset
17+
float frequency = ArdMidiCommon::noteToFrequency(note);
18+
19+
instrument.noteOn( frequency, 0.5 );
20+
long endTime = millis()+1000;
21+
while (millis()<endTime){
22+
output.tick( instrument.tick() );
23+
}
24+
delay( 100 );
25+
26+
}

examples/MemoryLoop/MemoryLoop.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "ArdStreamOut.h"
2+
#include "MemoryLoop.h"
3+
#include "MemoryFS.h"
4+
5+
using namespace stk;
6+
7+
extern const unsigned char sinewave_raw[];
8+
extern const unsigned int sinewave_raw_len;
9+
10+
MemoryLoop input(new MemoryFS(sinewave_raw, sinewave_raw_len));
11+
ArdStreamOut output(Serial);
12+
13+
void setup() {
14+
Serial.begin(115200);
15+
Stk::setSampleRate( 44100.0 );
16+
input.setFrequency( 440.0 );
17+
}
18+
19+
void loop() {
20+
output.tick( input.tick() );
21+
}
22+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <Voicer.h>
2+
#include <Clarinet.h>
3+
#include <ArdMidiBleEventHandler.h>
4+
#include <ArdMidiBleServer.h>
5+
6+
using namespace stk;
7+
8+
Voicer voicer;
9+
Clarinet clarinet(440);
10+
ArdMidiBleEventHandler handler(&voicer);
11+
ArdMidiBleServer ble("MidiServer", &handler);
12+
13+
void setup() {
14+
voicer.addInstrument(&clarinet, 0);
15+
ble.start(voicer);
16+
}
17+
18+
StkFloat note = 64; // 0 to 128
19+
StkFloat amplitude = 100; // 0 to 128
20+
21+
void loop() {
22+
Serial.print("playing ");
23+
Serial.println(++note);
24+
25+
ble.noteOn( note, amplitude );
26+
delay(900);
27+
ble.noteOff( note, 20 );
28+
delay(200);
29+
if (note>=90) {
30+
note = 30;
31+
}
32+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <Voicer.h>
2+
#include <Clarinet.h>
3+
#include <ArdMidiBleEventHandler.h>
4+
#include <ArdMidiBleServer.h>
5+
6+
using namespace stk;
7+
8+
Voicer voicer;
9+
Clarinet clarinet(440);
10+
ArdMidiBleEventHandler handler(&voicer);
11+
ArdMidiBleServer ble("MidiServer", &handler);
12+
13+
using namespace stk;
14+
15+
ArdMidiBleServer ble("MidiServer");
16+
17+
StkFloat note = 64; // 0 to 128
18+
StkFloat amplitude = 100; // 0 to 128
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
voicer.addInstrument(&clarinet, 0);
23+
ble.start(voicer);
24+
}
25+
26+
void loop() {
27+
Serial.print("playing ");
28+
Serial.println(++note);
29+
30+
ble.noteOn( note, amplitude );
31+
delay(900);
32+
ble.noteOff( note, 20 );
33+
delay(200);
34+
if (note>=90) {
35+
note = 30;
36+
}
37+
}
38+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "Voicer.h"
2+
#include "Clarinet.h"
3+
#include "ArdMidiStreamIn.h"
4+
5+
using namespace stk;
6+
7+
Voicer voicer;
8+
Clarinet clarinet(440);
9+
ArdMidiEventHandler handler(&voicer);
10+
ArdMidiStreamIn in(Serial, handler);
11+
12+
void setup() {
13+
Serial.begin(115200);
14+
voicer.addInstrument(&clarinet);
15+
}
16+
17+
void loop() {
18+
in.loop();
19+
}

examples/MidiFromUDP/MidiFromUDP

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <WiFi.h>
2+
#include <WiFiClient.h>
3+
#include <WiFiUdp.h>
4+
#include <ArdMidiStreamIn.h>
5+
#include "Voicer.h"
6+
#include "Clarinet.h"
7+
8+
using namespace stk;
9+
10+
11+
WiFiUDP udp;
12+
Clarinet clarinet(440);
13+
Voicer voicer;
14+
ArdMidiEventHandler handler(&voicer);
15+
ArdMidiStreamIn in(udp, handler );
16+
int localPort = 9000;
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
WiFi.begin(SSID, PWD);
21+
while (WiFi.status() != WL_CONNECTED) {
22+
Serial.print('.');
23+
delay(1000);
24+
}
25+
26+
Serial.print("Connected to IP address: ");
27+
Serial.println(WiFi.localIP());
28+
29+
voicer.addInstrument(&clarinet,0);
30+
udp.begin(localPort);
31+
}
32+
33+
void loop() {
34+
in.loop();
35+
}```
36+
37+
## BLE Server
38+
The MIDI BLE Server functionality is provided by the __ArdMidiBleServer__ class. Above you have already seen all relevant components and how they work together.
39+
40+
### Sending of MIDI Messages over BLE
41+

examples/MidiToIP/MidiToIP.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <WiFi.h>
2+
#include <WiFiMulti.h>
3+
#include "ArdMidiStreamOut.h"
4+
5+
using namespace stk;
6+
7+
IPAddress ip(192, 168, 1, 35);
8+
int port = 9999;
9+
WiFiClient client;
10+
ArdMidiStreamOut out(client);
11+
const char *SSID = "your ssid";
12+
const char *PWD = "your password";
13+
14+
StkFloat note = 64; // 0 to 128
15+
StkFloat amplitude = 100; // 0 to 128
16+
17+
void setup() {
18+
Serial.begin(115200);
19+
WiFi.begin(SSID, PWD);
20+
while (WiFi.status() != WL_CONNECTED) {
21+
Serial.print('.');
22+
delay(1000);
23+
}
24+
25+
Serial.print("Connected to IP address: ");
26+
Serial.println(WiFi.localIP());
27+
28+
client.connect(ip, port);
29+
}
30+
31+
void loop() {
32+
Serial.print("playing ");
33+
Serial.println(++note);
34+
35+
out.noteOn( note, amplitude );
36+
delay(900);
37+
out.noteOff( note, 20 );
38+
delay(200);
39+
if (note>=90) {
40+
note = 30;
41+
}
42+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "ArdMidiStreamOut.h"
2+
3+
using namespace stk;
4+
5+
ArdMidiStreamOut out(Serial);
6+
StkFloat note = 64; // 0 to 128
7+
StkFloat amplitude = 100; // 0 to 128
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
}
12+
13+
void loop() {
14+
Serial.println();
15+
Serial.print("playing ");
16+
Serial.println(++note);
17+
18+
out.noteOn( note, amplitude );
19+
delay(900);
20+
out.noteOff( note, 20 );
21+
delay(200);
22+
if (note>=90) {
23+
note = 30;
24+
}
25+
}

examples/MidiToUDP/MidiToUDP.ino

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "WiFi.h"
2+
#include "ArdUdp.h"
3+
#include "ArdMidiStreamOut.h"
4+
5+
using namespace stk;
6+
7+
IPAddress ip(192, 168, 1, 35);
8+
ArdUdp udp(ip, 7000);
9+
ArdMidiStreamOut out(udp);
10+
const char *SSID = "your ssid";
11+
const char *PWD = "your password";
12+
13+
StkFloat note = 64; // 0 to 128
14+
StkFloat amplitude = 100; // 0 to 128
15+
16+
void setup() {
17+
Serial.begin(115200);
18+
WiFi.begin(SSID, PWD);
19+
while (WiFi.status() != WL_CONNECTED) {
20+
Serial.print('.');
21+
delay(1000);
22+
}
23+
24+
Serial.print("Connected to IP address: ");
25+
Serial.println(WiFi.localIP());
26+
}
27+
28+
void loop() {
29+
Serial.print("playing ");
30+
Serial.println(++note);
31+
32+
out.noteOn( note, amplitude );
33+
delay(900);
34+
out.noteOff( note, 20 );
35+
delay(200);
36+
if (note>=90) {
37+
note = 30;
38+
}
39+
}

examples/Noise/Noise.ino

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "Noise.h"
2+
using namespace stk;
3+
4+
void setup() {
5+
StkFloat output;
6+
Noise noise;
7+
for ( unsigned int i=0; i<20; i++ ) {
8+
output = noise.tick();
9+
Serial.println(output);
10+
}
11+
}
12+
13+
void loop() {
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Noise.h"
2+
using namespace stk;
3+
4+
Noise noise;
5+
StkFrames output(20, 1); // initialize StkFrames to 20 frames and 1 channel (default: interleaved)
6+
7+
void setup() {
8+
Serial.begin(115200);
9+
}
10+
11+
void loop() {
12+
noise.tick( output );
13+
for ( unsigned int i=0; i<output.size(); i++ ) {
14+
Serial.println(output[i]);
15+
}
16+
}

0 commit comments

Comments
 (0)