Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PCM5102 pomoc....
#2
#include <driver/i2s.h>
#include <math.h>

#define SAMPLE_RATE 44100
#define I2S_NUM I2S_NUM_0
#define PI 3.14159265

const int amplitude = 3000; // U rasponu -32768 do 32767 (int16_t)
const int frequency = 1000; // 1 kHz
const int samples_per_cycle = SAMPLE_RATE / frequency;

int16_t buffer[samples_per_cycle];

void setupSinusBuffer() {
for (int i = 0; i < samples_per_cycle; i++) {
float theta = ((float)i / samples_per_cycle) * 2.0 * PI;
buffer[i] = (int16_t)(amplitude * sin(theta));
}
}

void setup() {
Serial.begin(115200);
setupSinusBuffer();

const i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false,
.tx_desc_auto_clear = true
};

const i2s_pin_config_t pin_config = {
.bck_io_num = 26,
.ws_io_num = 25,
.data_out_num = 22,
.data_in_num = I2S_PIN_NO_CHANGE
};

i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM, &pin_config);
i2s_zero_dma_buffer(I2S_NUM);
}

void loop() {
size_t bytes_written;
i2s_write(I2S_NUM, buffer, sizeof(buffer), &bytes_written, portMAX_DELAY);
}
Reply


Messages In This Thread
PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:47 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:52 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:57 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:31 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:45 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:36 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:49 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:01 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)