本帖最后由 猪百岁 于 2021-3-31 21:09 编辑
I2S(集成电路内置音频总线)的使用
关于 I2S 音频总线详细介绍请参考I2S-API 文档.
1. 使用方法
from Maix import I2S
i2s_dev = I2S(device_num)
i2s_dev.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode = I2S.STANDARD_MODE)
i2s_dev.set_sample_rate(sample_rate)
i2s_dev.record(256)#sampling points number must be smaller than 256
2. 例程
采集数据并直接播放
from Maix import I2S
import time
from fpioa_manager import *
fm.register(20,fm.fpioa.I2S0_IN_D0)#GO
fm.register(19,fm.fpioa.I2S0_WS)
fm.register(18,fm.fpioa.I2S0_SCLK)
fm.register(34,fm.fpioa.I2S2_OUT_D1)
fm.register(35,fm.fpioa.I2S2_SCLK)
fm.register(33,fm.fpioa.I2S2_WS)
sample_rate = 44*1000
rx = I2S(I2S.DEVICE_0)
rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode = I2S.STANDARD_MODE)
rx.set_sample_rate(sample_rate)
tx = I2S(I2S.DEVICE_2)
tx.channel_config(tx.CHANNEL_1, tx.TRANSMITTER, align_mode = I2S.RIGHT_JUSTIFYING_MODE)
tx.set_sample_rate(sample_rate)
while True:
audio = rx.record(256)#sampling points number must be smaller than 256
tx.play(audio)
|