2017年7月26日水曜日

ESP32のsigmadeltaサンプル

大変ご無沙汰しております。 Arduino ESP32のサンプルとして入っているsigmadelta、当たり前だけどちゃんと音が出ますねぇw

手持ちの16khz/16bitのwavデータで試したらちゃんと歌ってくれますww

#include "voice.h" // 16khz, 16bit, wav data block
// add 0x8000 to each original wave format data
void setup()
{
Serial.begin(115200);
Serial.println("start");
sigmaDeltaSetup(0, 16000);
sigmaDeltaSetup(1, 16000);
sigmaDeltaAttachPin(25,0);
sigmaDeltaAttachPin(26,1);
sigmaDeltaWrite(0, 0);
sigmaDeltaWrite(1, 0);
}
int count = 0;
const int length = sizeof(voice) / sizeof(uint16_t);
void loop()
{
uint8_t left = (voice[count++] >> 8) & 0xff;
uint8_t right = (voice[count++] >> 8) & 0xff;
sigmaDeltaWrite(0, left);
sigmaDeltaWrite(1, right);
if (count > length) {
count = 0;
Serial.println("loop");
}
ets_delay_us(60);
}