mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
2fceec4d85
1. Support built-in ADC for I2S. 2. Modify code of ADC, made no change to the original APIs. 3. Add APIs in I2S: esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel); 4. Add I2S ADC/DAC example code. 5. add old-fashion definition to make it more compatible 6. replase spi_flash_ APIs with esp_partition_ APIs 7. add example of generating audio table from wav 8. change example sound
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import os
|
|
import wave
|
|
import struct
|
|
|
|
def get_wave_array_str(filename, target_bits):
|
|
wave_read = wave.open(filename, "r")
|
|
array_str = ""
|
|
nchannels, sampwidth, framerate, nframes, comptype, compname = wave_read.getparams()
|
|
sampwidth *= 8
|
|
for i in range(wave_read.getnframes()):
|
|
val, = struct.unpack("<H", wave_read.readframes(1))
|
|
scale_val = (1 << target_bits) - 1
|
|
cur_lim = (1 << sampwidth) - 1
|
|
#scale current data to 8-bit data
|
|
val = val * scale_val / cur_lim
|
|
val = (val + ((scale_val + 1) / 2)) & scale_val
|
|
array_str += "0x%x, "%(val)
|
|
if (i + 1) % 16 == 0:
|
|
array_str += "\n"
|
|
return array_str
|
|
|
|
def gen_wave_table(wav_file_list, target_file_name, scale_bits = 8):
|
|
with open(target_file_name, "w") as audio_table:
|
|
print >> audio_table, '#include <stdio.h>'
|
|
print >> audio_table, 'const unsigned char audio_table[] = {'
|
|
for wav in wav_file_list:
|
|
print("processing: {}".format(wav))
|
|
print >> audio_table, get_wave_array_str(filename = wav, target_bits = scale_bits)
|
|
print >>audio_table,'};\n'
|
|
print("Done...")
|
|
|
|
if __name__=='__main__':
|
|
print("Generating audio array...")
|
|
wav_list = []
|
|
for filename in os.listdir("./"):
|
|
if filename.endswith(".wav"):
|
|
wav_list.append(filename)
|
|
gen_wave_table(wav_file_list = wav_list, target_file_name = "audio_example_file.h")
|