2016年7月16日土曜日

NucleoシーケンサーとPSoC4 DCOとVCVS DCFの結合テスト(UIなし)

VCVS LPFシールドがなかなかうまく動いてくれなくて手こずったが音が出たのでメモ。

配線図


出音をYoutubeに上げた。(発振させているので音量に注意)


cutoffをスイープ→resonanceを上げて(127->170)再びcutoffをスイープ。

mbed repository
https://developer.mbed.org/users/ryood/code/SpiSequenceSender_Test/

main.cpp

#include "mbed.h"
#include "rtos.h"

#define UART_TRACE  (0)
#include "SpiSequenceSender.h"
#include "EnvelopeGenerator.h"
#include "SpiAmpController.h"
#include "SpiFilterController.h"

#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);
AnalogIn cutoffIn(PC_0);
AnalogIn resonanceIn(PC_2);

SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK);

Sequence sequence[SEQUENCE_N];
SpiSequenceSender sequenceSender(&spiMaster, D9, sequence, SEQUENCE_N, samplingPeriod, bpm);

Envelope envelope(4095, envelopeLength, envelopeLength*3/4, envelopeLength/2, 2047);
EnvelopeGenerator envelopeGenerator;
SpiAmpController ampController(&spiMaster, D8, D7);

SpiFilterController filterController(&spiMaster, D10);

void callbackFunction(int ticks)
{
    if (ticks == 0) {
        envelopeGenerator.init(envelope);
    }
    uint16_t level = envelopeGenerator.getModLevel();
    //printf("g,%d\r\n", level);
    ampController.outDca(level);
    envelopeGenerator.update();
   
    filterController.outDCF();
}

int main()
{
    spiMaster.format(8, 0);
    spiMaster.frequency(SPI_RATE);
   
    // Test SequencerSender Run
    //
    sequenceSender.setBpm(bpm);
    for (int i = 0; i < SEQUENCE_N; i++) {
        Sequence& seq = sequenceSender.getSequences()[i];
        seq.setPitch(i);
        seq.setOctave(-1);
        seq.tie = true;
    }

    sequence[3].setOctave(0);
    sequence[7].setOctave(0);
    sequence[11].setOctave(0);
    sequence[15].setOctave(0);
   
    envelopeGenerator.init(envelope);

    sequenceSender.attachUpdate(&callbackFunction);
    sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SAW);
    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);
       
        filterController.setCutoff(cutoffIn * 255);
        filterController.setResonance(resonanceIn * 255);
       
        printf("%d\t%d\t%d\t%d\t%d\t%d\r\n",
            filterController.getCutoff(),
            filterController.getResonance(),
            envelope.getLevel(),
            envelope.getDuration(),
            envelope.getDecay(),
            envelope.getSustain()
        );
    }
}

メモ:

VCVS DCFシールドが動かない条件は不明。Arduinoでテストしなおしているうちに動作した。

DCAと結合テストして、シーケンス入力系をテスト。

あともう少し(^q^/

0 件のコメント:

コメントを投稿