Created
January 26, 2020 12:27
-
-
Save kamiyaowl/8d87cd1386e08b2ef9adb54d76a8bdb9 to your computer and use it in GitHub Desktop.
PYNQ-Z2のPython上で音声ループバック https://twitter.com/kamiya_owl/status/1221407626564534277
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// select_line_in()呼び出し時にTX Buffから音声出力できるようにレジスタ設定を書き込んでおく | |
/****************************************************************************** | |
* Function to select LINE_IN as input. | |
* @param iic_index is the i2c index in /dev list. | |
* @return none. | |
*****************************************************************************/ | |
extern "C" void select_line_in(int iic_index) { | |
int iic_fd; | |
iic_fd = setI2C(iic_index, IIC_SLAVE_ADDR); | |
if (iic_fd < 0) { | |
printf("Unable to set I2C %d.\n", iic_index); | |
} | |
// Mixer 1 (left channel) | |
write_audio_reg(R4_RECORD_MIXER_LEFT_CONTROL_0, 0x01, iic_fd); | |
// Enable LAUX (MX1AUXG) | |
write_audio_reg(R5_RECORD_MIXER_LEFT_CONTROL_1, 0x07, iic_fd); | |
// Mixer 2 | |
write_audio_reg(R6_RECORD_MIXER_RIGHT_CONTROL_0, 0x01, iic_fd); | |
// Enable RAUX (MX2AUXG) | |
write_audio_reg(R7_RECORD_MIXER_RIGHT_CONTROL_1, 0x07, iic_fd); | |
/* ついでに出力も使えるようにする */ | |
// Enable Mixer3 and Mixer4 | |
write_audio_reg(R22_PLAYBACK_MIXER_LEFT_CONTROL_0, 0x21, iic_fd); | |
write_audio_reg(R24_PLAYBACK_MIXER_RIGHT_CONTROL_0, 0x41, iic_fd); | |
// Enable Left/Right Headphone out | |
write_audio_reg(R29_PLAYBACK_HEADPHONE_LEFT_VOLUME_CONTROL, 0xE7, iic_fd); | |
write_audio_reg(R30_PLAYBACK_HEADPHONE_RIGHT_VOLUME_CONTROL, 0xE7, iic_fd); | |
if (unsetI2C(iic_fd) < 0) { | |
printf("Unable to unset I2C %d.\n", iic_index); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pynq.overlays.base import BaseOverlay | |
base = BaseOverlay("base.bit", download=False) | |
# from audio_adau1761.h | |
I2S_DATA_RX_L_REG = 0x00 | |
I2S_DATA_RX_R_REG = 0x04 | |
I2S_DATA_TX_L_REG = 0x08 | |
I2S_DATA_TX_R_REG = 0x0C | |
I2S_STATUS_REG = 0x10 | |
pAudio = base.audio | |
pAudio.select_line_in() # line入力を使う | |
while True: | |
l_raw = pAudio.mmio.read_reg(offset=I2S_DATA_RX_L_REG) | |
r_raw = pAudio.mmio.read_reg(offset=I2S_DATA_RX_R_REG) | |
pAudio.mmio.write_reg(data=l_raw, offset=I2S_DATA_TX_L_REG) | |
pAudio.mmio.write_reg(data=r_raw, offset=I2S_DATA_TX_R_REG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment