Skip to content

Commit

Permalink
Audio packets are starting to come in!
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 20, 2024
1 parent 80ac656 commit 06b87d2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 28 deletions.
11 changes: 9 additions & 2 deletions src/hal/star/i6_aud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
22 changes: 15 additions & 7 deletions src/hal/star/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions src/hal/star/i6_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
28 changes: 17 additions & 11 deletions src/hal/star/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -95,23 +95,30 @@ 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;
if (ret = i6c_aud.fnAttachToDevice(_i6c_aud_dev, input, 1))
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;
}
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/hal/star/i6c_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions src/hal/star/i6f_aud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
23 changes: 15 additions & 8 deletions src/hal/star/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/hal/star/i6f_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 06b87d2

Please sign in to comment.