0

我正在为我的音乐学位做最后的项目(这个想法是探索与电子乐器交互的替代输入方法),我正在使用 Teensy 3.2 和 Adafruit STMPE610 组合一个基于触摸屏的合成器。我最初计划使用基于硬件的设置,但在与不同的电路进行斗争之后,我决定使用我更熟悉的软件。

我遇到的问题是,我似乎无法通过板载 DAC 或通过传递到计算机的数字 USB 接口播放任何音频。我可以看到程序正在播放音频,但似乎没有任何效果。

添加 dac1.begin() 后,程序挂起,只打印出初始项目标题。我不认为这个函数是必需的,但是在查看了库的源代码之后,我发现了它,所以我想我会试一试。

我不确定我是否在我的设置功能中遗漏了某些东西,或者我是否特别需要在循环功能中输出音频。

这是没有 dac1.begin() 的串行监视器的输出副本,我随机按下触摸屏(源代码在下面):

=======================
Touch Synth
<name> - 2017
Music Major Project
=======================
Note on 
Touch location (x,y,z) -> 1884 2371 49 
Touch location (x,y,z) -> 1896 2365 37 
Touch location (x,y,z) -> 1892 2365 34  
Touch location (x,y,z) -> 1428 2152 37 
Note off 
Note on 
Touch location (x,y,z) -> 1985 2440 55 
Touch location (x,y,z) -> 1987 2420 39 
Touch location (x,y,z) -> 2010 2381 36 
Touch location (x,y,z) -> 2023 2327 34 
Touch location (x,y,z) -> 2277 2552 34 
Touch location (x,y,z) -> 2074 2648 40 
Note off 
Note on 
Touch location (x,y,z) -> 2006 2575 35 
Touch location (x,y,z) -> 2024 2568 35 
Note off 
Note on 
Touch location (x,y,z) -> 1992 2522 34 
Touch location (x,y,z) -> 2005 2525 31 
Touch location (x,y,z) -> 2004 2523 31 
Touch location (x,y,z) -> 2007 2514 33 
Note off 
Note on 
Touch location (x,y,z) -> 2047 2409 36 
Touch location (x,y,z) -> 2036 2410 32 
Touch location (x,y,z) -> 2039 2405 31 
Touch location (x,y,z) -> 2066 2399 37 
Note off 
Note on 
Touch location (x,y,z) -> 2058 2367 36 
Touch location (x,y,z) -> 2062 2372 34 
Note off 
Note on 
Touch location (x,y,z) -> 2013 2398 34 
Touch location (x,y,z) -> 2029 2399 32 
Note off 

和代码:

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#include "Adafruit_STMPE610.h"

// ===== Audio GUI Tool code =====
// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=97,100
AudioSynthWaveform       waveform2;      //xy=97,137
AudioMixer4              mixer1;         //xy=349,119
AudioEffectEnvelope      envelope1;      //xy=514,104
AudioMixer4              mixer2;         //xy=676,123
AudioOutputAnalog        dac1;           //xy=841,110
AudioConnection          patchCord1(waveform1, 0, mixer1, 0);
AudioConnection          patchCord2(waveform2, 0, mixer1, 1);
AudioConnection          patchCord3(mixer1, envelope1);
AudioConnection          patchCord4(envelope1, 0, mixer2, 0);
AudioConnection          patchCord5(mixer2, 0, dac1, 0);
// GUItool: end automatically generated code

// ===== Pinout setup =====
const byte PWR_LED = 13;
const byte GATE_OUT = 6;
const byte SPI_SCK = 14;
const byte SPI_MOSI = 11;
const byte SPI_MISO = 12;
const byte STMPE_CS = 15; // Touch Screen Controller Chip Select
const byte aPot = 16;
const byte rPot = 17;

// ===== Touch Screen Object Declaration =====
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, SPI_MOSI, SPI_MISO, SPI_SCK);

// ===== Function Declarations =====
void error(int);

// ===== Global variables =====
int gTouchOn = 0;
int gNoteOn = 0;

void setup() {
  Serial.begin(9600);                         // Setup serial
  Serial.println("=======================");  // ============================
  Serial.println("Touch Synth");              // 
  Serial.println("Callum Blackmore - 2017");  // Print faux splash screen to
  Serial.println("Music Major Project");      // serial output
  Serial.println("=======================");  //
  //Serial.flush();                             // ============================

  pinMode(PWR_LED, OUTPUT); //Setup power LED
  digitalWrite(PWR_LED, HIGH);

  if (! touch.begin()) {
    Serial.println("STMPE not found!");
    error(1000);
  }


  AudioMemory(50);
  //dac1.begin(); // <--- Code will hang here if uncommented
  dac1.analogReference(INTERNAL);
  waveform1.begin(WAVEFORM_SINE);
  waveform2.begin(WAVEFORM_TRIANGLE);
  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer2.gain(0, 0.75);
  envelope1.delay(0);
  envelope1.attack(100);
  envelope1.hold(0);
  envelope1.decay(15);
  envelope1.sustain(0.7);
  envelope1.release(200);
}

void loop() {
  // put your main code here, to run repeatedly:
  uint16_t analogVal; // temp value for analog reads
  uint16_t x, y;  // Touch coordinates
  uint8_t z;      // ''

  analogVal = analogRead(aPot);      // =====
  //Serial.print(analogVal); Serial.print(' ');
  envelope1.attack(analogVal/10);   // Read pots and update attack and release values
  analogVal = analogRead(rPot);      //
  //Serial.print(analogVal); Serial.println(' ');
  envelope1.release(analogVal/10);  // =====

  if(touch.touched())
  {
    gTouchOn = 1; 
    while (! touch.bufferEmpty())
    {
      touch.readData(&x, &y, &z);
      waveform1.frequency((y*2)+100);
      waveform2.frequency((y*2)+100);
      Serial.print("Touch location (x,y,z) -> ");
      Serial.print(x); Serial.print(' ');
      Serial.print(y); Serial.print(' ');
      Serial.print(z); Serial.println(' ');
    }
    touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
    if(gNoteOn == 0)
    {
      Serial.print("Note on"); Serial.println(' ');
      gNoteOn = 1;
      envelope1.noteOn();
    }
  }
  else if(!touch.touched() && gNoteOn == 1)
  {
    Serial.print("Note off"); Serial.println(' ');
    envelope1.noteOff();
    gNoteOn = 0;
    gTouchOn = 0;
  }
}

void error(int len){
  while(1) {
      digitalWrite(PWR_LED, HIGH);
      delay(len);
      digitalWrite(PWR_LED, LOW);
      delay(len);
    }
}
4

1 回答 1

0

所以事实证明,teensy 是有问题的。我已经把它换成了另一个单元,它工作得很好。

我需要修改几行代码,但它们纯粹是语义上的,而不是更改波形.begin() 语句以包括起始幅度和起始频率,如下所示:

waveform1.begin(1.0, 440, WAVEFORM_SINE);
waveform2.begin(1.0, 440, WAVEFORM_TRIANGLE);

我还没有数字音频工作,所以我使用板载 DAC 将音频输出到我拥有的小型混音器,但大部分功能都在工作。

于 2017-10-01T07:45:08.517 回答