From 06b87d2aadaacfe865c3a534fabd7d0b8c48ac89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Thu, 20 Jun 2024 13:58:01 -0400 Subject: [PATCH] Audio packets are starting to come in! --- src/hal/star/i6_aud.h | 11 +++++++++-- src/hal/star/i6_hal.c | 22 +++++++++++++++------- src/hal/star/i6_sys.h | 7 +++++++ src/hal/star/i6c_hal.c | 28 +++++++++++++++++----------- src/hal/star/i6c_sys.h | 9 +++++++++ src/hal/star/i6f_aud.h | 7 +++++++ src/hal/star/i6f_hal.c | 23 +++++++++++++++-------- src/hal/star/i6f_sys.h | 10 ++++++++++ 8 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/hal/star/i6_aud.h b/src/hal/star/i6_aud.h index c591924..9d40163 100644 --- a/src/hal/star/i6_aud.h +++ b/src/hal/star/i6_aud.h @@ -66,12 +66,12 @@ typedef struct { typedef struct { int bit24On; i6_aud_snd sound; - void *addr[I6_AUD_CHN_NUM]; + int *addr[I6_AUD_CHN_NUM]; unsigned long long timestamp; unsigned int sequence; unsigned int length; unsigned int poolId[2]; - void *pcmAddr[I6_AUD_CHN_NUM]; + int *pcmAddr[I6_AUD_CHN_NUM]; unsigned int pcmLength; } i6_aud_frm; @@ -116,6 +116,7 @@ typedef struct { int (*fnSetEncodingParam)(int device, int channel, i6_aud_para *param); int (*fnSetMute)(int device, int channel, char active); + int (*fnSetVolume)(int device, int channel, int dbLevel); int (*fnFreeFrame)(int device, int channel, i6_aud_frm *frame, i6_aud_efrm *encFrame); int (*fnGetFrame)(int device, int channel, i6_aud_frm *frame, i6_aud_efrm *encFrame, int millis); @@ -181,6 +182,12 @@ static int i6_aud_load(i6_aud_impl *aud_lib) { return EXIT_FAILURE; } + if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel)) + dlsym(aud_lib->handle, "MI_AI_SetVqeVolume"))) { + fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_SetVqeVolume!\n"); + return EXIT_FAILURE; + } + if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, i6_aud_frm *frame, i6_aud_efrm *encFrame)) dlsym(aud_lib->handle, "MI_AI_ReleaseFrame"))) { fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_ReleaseFrame!\n"); diff --git a/src/hal/star/i6_hal.c b/src/hal/star/i6_hal.c index 2de9bdf..69b4021 100644 --- a/src/hal/star/i6_hal.c +++ b/src/hal/star/i6_hal.c @@ -79,17 +79,17 @@ int i6_audio_init(void) { i6_aud_cnf config; - config.rate = 48000; + config.rate = 8000; config.bit24On = 0; config.intf = I6_AUD_INTF_I2S_SLAVE; config.sound = I6_AUD_SND_MONO; config.frmNum = 0; - config.packNumPerFrm = config.rate / 16; + config.packNumPerFrm = 640; config.codecChnNum = 0; config.chnNum = 1; config.i2s.leftJustOn = 0; config.i2s.clock = I6_AUD_CLK_OFF; - config.i2s.syncRxClkOn = 1; + config.i2s.syncRxClkOn = 0; config.i2s.tdmSlotNum = 0; config.i2s.bit24On = 0; if (ret = i6_aud.fnSetDeviceConfig(_i6_aud_dev, &config)) @@ -101,6 +101,16 @@ int i6_audio_init(void) if (ret = i6_aud.fnEnableChannel(_i6_aud_dev, _i6_aud_chn)) return ret; + if (ret = i6_aud.fnSetVolume(_i6_aud_dev, _i6_aud_chn, 13)) + return ret; + + { + i6_sys_bind bind = { .module = I6_SYS_MOD_AI, + .device = _i6_aud_dev, .channel = _i6_aud_chn }; + if (ret = i6_sys.fnSetOutputDepth(&bind, 2, 4)) + return ret; + } + return EXIT_SUCCESS; } @@ -109,13 +119,11 @@ void *i6_audio_thread(void) int ret; i6_aud_frm frame; - i6_aud_efrm echoFrame; memset(&frame, 0, sizeof(frame)); - memset(&echoFrame, 0, sizeof(echoFrame)); while (keepRunning) { if (ret = i6_aud.fnGetFrame(_i6_aud_dev, _i6_aud_chn, - &frame, &echoFrame, 100)) { + &frame, NULL, 128)) { fprintf(stderr, "[i6_aud] Getting the frame failed " "with %#x!\n", ret); continue; @@ -127,7 +135,7 @@ void *i6_audio_thread(void) } if (ret = i6_aud.fnFreeFrame(_i6_aud_dev, _i6_aud_chn, - &frame, &echoFrame)) { + &frame, NULL)) { fprintf(stderr, "[i6_aud] Releasing the frame failed" " with %#x!\n", ret); } diff --git a/src/hal/star/i6_sys.h b/src/hal/star/i6_sys.h index 0ff78d8..9944386 100644 --- a/src/hal/star/i6_sys.h +++ b/src/hal/star/i6_sys.h @@ -79,6 +79,7 @@ typedef struct { unsigned int srcFps, unsigned int dstFps); int (*fnBindExt)(i6_sys_bind *source, i6_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6_sys_link link, unsigned int linkParam); + int (*fnSetOutputDepth)(i6_sys_bind *bind, unsigned int usrDepth, unsigned int bufDepth); int (*fnUnbind)(i6_sys_bind *source, i6_sys_bind *dest); } i6_sys_impl; @@ -125,6 +126,12 @@ static int i6_sys_load(i6_sys_impl *sys_lib) { return EXIT_FAILURE; } + if (!(sys_lib->fnSetOutputDepth = (int(*)(i6_sys_bind *bind, unsigned int usrDepth, unsigned int bufDepth)) + dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { + fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + return EXIT_FAILURE; + } + if (!(sys_lib->fnUnbind = (int(*)(i6_sys_bind *source, i6_sys_bind *dest)) dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n"); diff --git a/src/hal/star/i6c_hal.c b/src/hal/star/i6c_hal.c index 0b93c39..7801f97 100644 --- a/src/hal/star/i6c_hal.c +++ b/src/hal/star/i6c_hal.c @@ -83,8 +83,8 @@ int i6c_audio_init(void) i6c_aud_cnf config; config.reserved = 0; config.sound = I6C_AUD_SND_MONO; - config.rate = 48000; - config.periodSize = 0x600; + config.rate = 8000; + config.periodSize = 0x400; config.interleavedOn = 0; if (ret = i6c_aud.fnEnableDevice(_i6c_aud_dev, &config)) return ret; @@ -95,9 +95,9 @@ int i6c_audio_init(void) config.intf = I6C_AUD_INTF_I2S_SLAVE; config.bit = I6C_AUD_BIT_16; config.leftJustOn = 0; - config.rate = 48000; + config.rate = 8000; config.clock = I6C_AUD_CLK_OFF; - config.syncRxClkOn = 1; + config.syncRxClkOn = 0; config.tdmSlotNum = 0; if (ret = i6c_aud.fnSetI2SConfig(input[0], &config)) return ret; @@ -105,13 +105,20 @@ int i6c_audio_init(void) return ret; } + if (ret = i6c_aud.fnEnableGroup(_i6c_aud_dev, _i6c_aud_chn)) + return ret; { - char gain[1] = { 0xF6 }; + char gain[1] = { 13 }; if (ret = i6c_aud.fnSetGain(_i6c_aud_dev, _i6c_aud_chn, gain, 1)) return ret; } - if (ret = i6c_aud.fnEnableGroup(_i6c_aud_dev, _i6c_aud_chn)) - return ret; + + { + i6c_sys_bind bind = { .module = I6C_SYS_MOD_AI, + .device = _i6c_aud_dev, .channel = _i6c_aud_chn }; + if (ret = i6c_sys.fnSetOutputDepth(0, &bind, 2, 4)) + return ret; + } return EXIT_SUCCESS; } @@ -120,13 +127,12 @@ void *i6c_audio_thread(void) { int ret; - i6c_aud_frm frame, echoFrame; + i6c_aud_frm frame; memset(&frame, 0, sizeof(frame)); - memset(&echoFrame, 0, sizeof(echoFrame)); while (keepRunning) { if (ret = i6c_aud.fnGetFrame(_i6c_aud_dev, _i6c_aud_chn, - &frame, &echoFrame, 100)) { + &frame, NULL, 128)) { fprintf(stderr, "[i6c_aud] Getting the frame failed " "with %#x!\n", ret); continue; @@ -138,7 +144,7 @@ void *i6c_audio_thread(void) } if (ret = i6c_aud.fnFreeFrame(_i6c_aud_dev, _i6c_aud_chn, - &frame, &echoFrame)) { + &frame, NULL)) { fprintf(stderr, "[i6c_aud] Releasing the frame failed" " with %#x!\n", ret); } diff --git a/src/hal/star/i6c_sys.h b/src/hal/star/i6c_sys.h index e1527a0..dace89d 100644 --- a/src/hal/star/i6c_sys.h +++ b/src/hal/star/i6c_sys.h @@ -137,6 +137,8 @@ typedef struct { int (*fnBind)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, i6c_sys_link *link); int (*fnBindExt)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6c_sys_link link, unsigned int linkParam); + int (*fnSetOutputDepth)(unsigned short chip, i6c_sys_bind *bind, unsigned int usrDepth, + unsigned int bufDepth); int (*fnUnbind)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest); int (*fnConfigPool)(unsigned short chip, i6c_sys_pool *config); @@ -184,6 +186,13 @@ static int i6c_sys_load(i6c_sys_impl *sys_lib) { return EXIT_FAILURE; } + if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, i6c_sys_bind *bind, + unsigned int usrDepth, unsigned int bufDepth)) + dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { + fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + return EXIT_FAILURE; + } + if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest)) dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n"); diff --git a/src/hal/star/i6f_aud.h b/src/hal/star/i6f_aud.h index 8801089..00c9de8 100644 --- a/src/hal/star/i6f_aud.h +++ b/src/hal/star/i6f_aud.h @@ -123,6 +123,7 @@ typedef struct { int (*fnSetEncodingParam)(int device, int channel, i6f_aud_para *param); int (*fnSetMute)(int device, int channel, char active); + int (*fnSetVolume)(int device, int channel, int dbLevel); int (*fnFreeFrame)(int device, int channel, i6f_aud_frm *frame, i6f_aud_efrm *encFrame); int (*fnGetFrame)(int device, int channel, i6f_aud_frm *frame, i6f_aud_efrm *encFrame, int millis); @@ -188,6 +189,12 @@ static int i6f_aud_load(i6f_aud_impl *aud_lib) { return EXIT_FAILURE; } + if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel)) + dlsym(aud_lib->handle, "MI_AI_SetVqeVolume"))) { + fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_SetVqeVolume!\n"); + return EXIT_FAILURE; + } + if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, i6f_aud_frm *frame, i6f_aud_efrm *encFrame)) dlsym(aud_lib->handle, "MI_AI_ReleaseFrame"))) { fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_ReleaseFrame!\n"); diff --git a/src/hal/star/i6f_hal.c b/src/hal/star/i6f_hal.c index 3249bfe..d22e05c 100644 --- a/src/hal/star/i6f_hal.c +++ b/src/hal/star/i6f_hal.c @@ -82,19 +82,19 @@ int i6f_audio_init(void) { i6f_aud_cnf config; - config.rate = 48000; + config.rate = 8000; config.bit = I6F_AUD_BIT_16; config.intf = I6F_AUD_INTF_I2S_SLAVE; config.sound = I6F_AUD_SND_MONO; config.frmNum = 0; - config.packNumPerFrm = config.rate / 16; + config.packNumPerFrm = 640; config.codecChnNum = 0; config.chnNum = 1; config.i2s.clock = I6F_AUD_CLK_OFF; config.i2s.leftJustOn = 0; - config.i2s.syncRxClkOn = 1; + config.i2s.syncRxClkOn = 0; config.i2s.tdmSlotNum = 0; - config.i2s.bit = I6F_AUD_BIT_32; + config.i2s.bit = I6F_AUD_BIT_16; if (ret = i6f_aud.fnSetDeviceConfig(_i6f_aud_dev, &config)) return ret; } @@ -103,6 +103,15 @@ int i6f_audio_init(void) if (ret = i6f_aud.fnEnableChannel(_i6f_aud_dev, _i6f_aud_chn)) return ret; + if (ret = i6f_aud.fnSetVolume(_i6f_aud_dev, _i6f_aud_chn, 13)) + return ret; + + { + i6f_sys_bind bind = { .module = I6F_SYS_MOD_AI, + .device = _i6f_aud_dev, .channel = _i6f_aud_chn }; + if (ret = i6f_sys.fnSetOutputDepth(0, &bind, 2, 4)) + return ret; + } return EXIT_SUCCESS; } @@ -112,13 +121,11 @@ void *i6f_audio_thread(void) int ret; i6f_aud_frm frame; - i6f_aud_efrm echoFrame; memset(&frame, 0, sizeof(frame)); - memset(&echoFrame, 0, sizeof(echoFrame)); while (keepRunning) { if (ret = i6f_aud.fnGetFrame(_i6f_aud_dev, _i6f_aud_chn, - &frame, &echoFrame, 100)) { + &frame, NULL, 128)) { fprintf(stderr, "[i6f_aud] Getting the frame failed " "with %#x!\n", ret); continue; @@ -130,7 +137,7 @@ void *i6f_audio_thread(void) } if (ret = i6f_aud.fnFreeFrame(_i6f_aud_dev, _i6f_aud_chn, - &frame, &echoFrame)) { + &frame, NULL)) { fprintf(stderr, "[i6f_aud] Releasing the frame failed" " with %#x!\n", ret); } diff --git a/src/hal/star/i6f_sys.h b/src/hal/star/i6f_sys.h index 372184d..1e295db 100644 --- a/src/hal/star/i6f_sys.h +++ b/src/hal/star/i6f_sys.h @@ -121,6 +121,8 @@ typedef struct { int (*fnBind)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest, i6f_sys_link *link); int (*fnBindExt)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6f_sys_link link, unsigned int linkParam); + int (*fnSetOutputDepth)(unsigned short chip, i6f_sys_bind *bind, unsigned int usrDepth, + unsigned int bufDepth); int (*fnUnbind)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest); int (*fnConfigPool)(unsigned short chip, i6f_sys_pool *config); @@ -168,6 +170,14 @@ static int i6f_sys_load(i6f_sys_impl *sys_lib) { return EXIT_FAILURE; } + if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, i6f_sys_bind *bind, + unsigned int usrDepth, unsigned int bufDepth)) + dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { + fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + return EXIT_FAILURE; + } + + if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest)) dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n");