Skip to content

Instantly share code, notes, and snippets.

@TareObjects
Created March 18, 2018 23:27
Show Gist options
  • Save TareObjects/d0ba75b43305236da3767ab163d6fa28 to your computer and use it in GitHub Desktop.
Save TareObjects/d0ba75b43305236da3767ab163d6fa28 to your computer and use it in GitHub Desktop.
//
// Sound
//
#include "driver/i2s.h"
#include "driver/gpio.h"
#include "ching.h"
#include "clap.h"
#include "cymbal.h"
#include "voice.h"
const i2s_port_t I2S_NUM = (i2s_port_t)0;
const i2s_bits_per_sample_t BITS_PER_SAMPLE = (i2s_bits_per_sample_t)16;
// PDM
void set_16k_16() {
i2s_set_pin(I2S_NUM, NULL);
i2s_config_t i2s_config;
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_PDM); // Only TX
i2s_config.sample_rate = 16000;
i2s_config.bits_per_sample = BITS_PER_SAMPLE;
i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT; //right channels
// i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT; //right left
i2s_config.communication_format = I2S_COMM_FORMAT_PCM;
i2s_config.dma_buf_count = 4;
i2s_config.dma_buf_len = 1024;
i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; //Interrupt level 1
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
}
void setup()
{
Serial.begin(115200);
set_16k_16();
Serial.println("setup end");
}
int iSound = 0;
void loop()
{
Serial.println("ching");
i2s_write_bytes(I2S_NUM, (const char *)ching, sizeof(ching), portMAX_DELAY);
delay(500);
Serial.println("clap");
i2s_write_bytes(I2S_NUM, (const char *)clap, sizeof(clap), portMAX_DELAY);
delay(500);
Serial.println("cymbal");
i2s_write_bytes(I2S_NUM, (const char *)cymbal, sizeof(cymbal), portMAX_DELAY);
delay(500);
Serial.println("voice");
i2s_write_bytes(I2S_NUM, (const char *)voice, sizeof(voice), portMAX_DELAY);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment