Nucleo Sequencer of my Base Machine
Dependencies: Amp AverageAnalogIn Envelope FilterController Sequence BaseMachineComon mbed-rtos mbed
Fork of SpiSequenceSender_Test by
Diff: main.cpp
- Revision:
- 10:fb04f9959fd9
- Parent:
- 9:3e4e08578e1c
- Child:
- 11:42ba71e533ba
--- a/main.cpp Sun Jun 26 09:51:40 2016 +0000 +++ b/main.cpp Sun Jun 26 10:18:23 2016 +0000 @@ -9,16 +9,25 @@ #define SEQUENCE_N (16) #define SPI_RATE (8000000) +const int samplingPeriod = 1; // ms +const int bpm = 120; +const int envelopeLength = (60 * 1000 / (bpm * 4)) / samplingPeriod; + +AnalogIn levelIn(A0); +AnalogIn durationIn(A1); +AnalogIn decayIn(A2); +AnalogIn sustainIn(A3); + SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK); Sequence sequence[SEQUENCE_N]; -SpiSequenceSender sequenceSender(&spiMaster, D9, sequence, SEQUENCE_N, 10); +SpiSequenceSender sequenceSender(&spiMaster, D9, sequence, SEQUENCE_N, samplingPeriod, bpm); -Envelope envelope(4095, 10, 8, 5, 2047); +Envelope envelope(4095, envelopeLength, envelopeLength*3/4, envelopeLength/2, 2047); EnvelopeGenerator envelopeGenerator; SpiAmpController ampController(&spiMaster, D8, D7); -/* + class TestClass { public: void callbackFunction(int ticks) @@ -26,11 +35,12 @@ if (ticks == 0) { envelopeGenerator.init(envelope); } - uint16_t level = envelopeGenerator.update(); - printf("m,%d\r\n", level); - } + uint16_t level = envelopeGenerator.getModLevel(); + //printf("g,%d\r\n", level); + ampController.outDca(level); + envelopeGenerator.update(); + } } testClass; -*/ void callbackFunction(int ticks) { @@ -50,7 +60,7 @@ // Test SequencerSender Run // - sequenceSender.setBpm(120); + sequenceSender.setBpm(bpm); for (int i = 0; i < SEQUENCE_N; i++) { Sequence& seq = sequenceSender.getSequences()[i]; seq.setPitch(i); @@ -65,15 +75,21 @@ envelopeGenerator.init(envelope); - //sequenceSender.attachUpdate(&testClass, &TestClass::callbackFunction); - sequenceSender.attachUpdate(&callbackFunction); + sequenceSender.attachUpdate(&testClass, &TestClass::callbackFunction); + //sequenceSender.attachUpdate(&callbackFunction); sequenceSender.run(0); for (;;) { + /* sequenceSender.setPulseWidth(sequenceSender.getPulseWidth() + 4); Thread::wait(500); sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SAW); Thread::wait(500); sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SQUARE); + */ + envelope.setLevel(levelIn * 4095); + envelope.setDuration(durationIn * envelopeLength); + envelope.setDecay(decayIn * envelopeLength); + envelope.setSustain(sustainIn * 4095); } }