Skip to content

最终数据处理的原因是什么 #24

@tsk15535904190

Description

@tsk15535904190

你好,在最终写入I2S设备的数据中,为什么要这样处理?
我的理解是,发送方采集128个数据转换成16bit,然后再转换成8bit,通过UDP或者ESP-NOW传输到接收方,接收方将128个8位数据经过如下处理写入到I2S设备中,但是我不理解为什么要经过这样的处理,这样处理完之后,最终写入到ESP32的数据是多少个?

void Output::write(int16_t *samples, int count) { int sample_index = 0; while (sample_index < count) { int samples_to_send = 0; for (int i = 0; i < NUM_FRAMES_TO_SEND && sample_index < count; i++) { int sample = process_sample(samples[sample_index]); m_frames[i * 2] = sample; // left channel m_frames[i * 2 + 1] = sample; // right channel samples_to_send++; sample_index++; } // write data to the i2s peripheral size_t bytes_written = 0; i2s_write(m_i2s_port, m_frames, samples_to_send * sizeof(int16_t) * 2, &bytes_written, portMAX_DELAY); if (bytes_written != samples_to_send * sizeof(int16_t) * 2) { ESP_LOGE(TAG, "Did not write all bytes"); } } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions