Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
steward-fu committed Oct 26, 2023
1 parent 3917dd9 commit d30ea11
Show file tree
Hide file tree
Showing 1,529 changed files with 709,852 additions and 15 deletions.
64 changes: 49 additions & 15 deletions libasound/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static uint8_t *pcm_buf = NULL;
static uint8_t *pcm_dummy = NULL;
static struct json_object *jfile = NULL;

#define JSON_FILE "/appconfigs/system.json"
#define JSON_APP_FILE "/appconfigs/system.json"
#define JSON_VOL_KEY "vol"
#define PERIOD 2048
#define FREQ 44100
Expand All @@ -49,6 +49,8 @@ typedef struct {

static pthread_t thread;
static queue_t queue = {0};
static int audio_feed = 768;
static int audio_delay = 1000;

#define MAX_VOLUME 20
#define MIN_RAW_VALUE -60
Expand Down Expand Up @@ -140,6 +142,22 @@ int volume_dec(void)
return cur_volume;
}

void update_audio_settings(int feed, int delay)
{
audio_feed = feed;
audio_delay = delay;
printf("audio_feed: %d\n", audio_feed);
printf("audio_delay: %d\n", audio_delay);

if ((audio_feed < 0) || (audio_delay < 0)) {
audio_feed = pcm_buf_len;
audio_delay = ((stSetAttr.u32PtNumPerFrm * 1000) / stSetAttr.eSamplerate - 10) * 1000;
printf("Invalid audio settings !\n");
printf("Reset audio_feed as %d\n", audio_feed);
printf("Reset audio_delay as %d\n", audio_delay);
}
}

static void queue_init(queue_t *q, size_t s)
{
q->buffer = (uint8_t *)malloc(s);
Expand Down Expand Up @@ -238,10 +256,12 @@ static void *audio_handler(void *threadid)
{
MI_S32 s32RetSendStatus = 0;
MI_AUDIO_Frame_t aoTestFrame;
int r = 0, len = pcm_buf_len, use_dummy = 0;
int r = 0, len = pcm_buf_len, use_dummy = 0, feed = 0, delay = 0;

while (pcm_ready) {
use_dummy = 1;
feed = pcm_buf_len;
delay = ((stSetAttr.u32PtNumPerFrm * 1000) / stSetAttr.eSamplerate - 10) * 1000;
r = queue_get(&queue, pcm_buf, len);
if (r > 0) {
len-= r;
Expand All @@ -250,16 +270,30 @@ static void *audio_handler(void *threadid)
len = pcm_buf_len;
}
}

aoTestFrame.eBitwidth = stGetAttr.eBitwidth;
aoTestFrame.eSoundmode = stGetAttr.eSoundmode;
aoTestFrame.u32Len = pcm_buf_len;
aoTestFrame.apVirAddr[0] = use_dummy ? pcm_dummy : pcm_buf;
aoTestFrame.apVirAddr[1] = NULL;
do {
s32RetSendStatus = MI_AO_SendFrame(AoDevId, AoChn, &aoTestFrame, 1);
usleep(((stSetAttr.u32PtNumPerFrm * 1000) / stSetAttr.eSamplerate - 10) * 1000);
} while(s32RetSendStatus == MI_AO_ERR_NOBUF);

if (use_dummy) {
// stSetAttr.u32PtNumPerFrm >= 441
// (((8192 * 1000) / 44100) - 10) * 1000 = 175.759us
// usleep(((stSetAttr.u32PtNumPerFrm * 1000) / stSetAttr.eSamplerate - 10) * 1000);

feed = audio_feed;
delay = audio_delay;
}

if (feed > 0) {
aoTestFrame.eBitwidth = stGetAttr.eBitwidth;
aoTestFrame.eSoundmode = stGetAttr.eSoundmode;
aoTestFrame.u32Len = feed;
aoTestFrame.apVirAddr[0] = use_dummy ? pcm_dummy : pcm_buf;
aoTestFrame.apVirAddr[1] = NULL;
do {
s32RetSendStatus = MI_AO_SendFrame(AoDevId, AoChn, &aoTestFrame, 1);
usleep(delay);
} while(s32RetSendStatus == MI_AO_ERR_NOBUF);
}
else {
usleep(delay);
}
}
pthread_exit(NULL);
}
Expand Down Expand Up @@ -371,14 +405,14 @@ int snd_pcm_start(snd_pcm_t *pcm)
}
memset(pcm_dummy, 0, pcm_buf_len);

jfile = json_object_from_file(JSON_FILE);
jfile = json_object_from_file(JSON_APP_FILE);
if (jfile != NULL) {
struct json_object *volume = NULL;

json_object_object_get_ex(jfile, JSON_VOL_KEY, &volume);
cur_volume = json_object_get_int(volume);
//json_object_object_add(jfile, JSON_VOL_KEY, json_object_new_int(2));
//json_object_to_file(JSON_FILE, jfile);
//json_object_to_file(JSON_APP_FILE, jfile);
json_object_put(jfile);
}

Expand Down Expand Up @@ -419,7 +453,7 @@ int snd_pcm_start(snd_pcm_t *pcm)
stAoChn0OutputPort0.u32ChnId = AoChn;
stAoChn0OutputPort0.u32PortId = 0;
MI_SYS_SetChnOutputPortDepth(&stAoChn0OutputPort0, 12, 13);

pcm_ready = 1;
set_volume(cur_volume);
pthread_create(&thread, NULL, audio_handler, (void *)NULL);
Expand Down
123 changes: 123 additions & 0 deletions sdl2/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
LOCAL_PATH := $(call my-dir)

###########################
#
# SDL shared library
#
###########################

include $(CLEAR_VARS)

LOCAL_MODULE := SDL2

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)

LOCAL_SRC_FILES := \
$(subst $(LOCAL_PATH)/,, \
$(wildcard $(LOCAL_PATH)/src/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/aaudio/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/openslES/*.c) \
$(LOCAL_PATH)/src/atomic/SDL_atomic.c.arm \
$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \
$(wildcard $(LOCAL_PATH)/src/core/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
$(wildcard $(LOCAL_PATH)/src/dynapi/*.c) \
$(wildcard $(LOCAL_PATH)/src/events/*.c) \
$(wildcard $(LOCAL_PATH)/src/file/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/hidapi/*.c) \
$(wildcard $(LOCAL_PATH)/src/hidapi/android/*.cpp) \
$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/hidapi/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/virtual/*.c) \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/misc/*.c) \
$(wildcard $(LOCAL_PATH)/src/misc/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/filesystem/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/sensor/*.c) \
$(wildcard $(LOCAL_PATH)/src/sensor/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/render/*.c) \
$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \
$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
$(wildcard $(LOCAL_PATH)/src/thread/*.c) \
$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/yuv2rgb/*.c) \
$(wildcard $(LOCAL_PATH)/src/test/*.c))

LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
LOCAL_CFLAGS += \
-Wall -Wextra \
-Wdocumentation \
-Wdocumentation-unknown-command \
-Wmissing-prototypes \
-Wunreachable-code-break \
-Wunneeded-internal-declaration \
-Wmissing-variable-declarations \
-Wfloat-conversion \
-Wshorten-64-to-32 \
-Wunreachable-code-return \
-Wshift-sign-overflow \
-Wstrict-prototypes \
-Wkeyword-macro \


# Warnings we haven't fixed (yet)
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-sign-compare

LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -lOpenSLES -llog -landroid

ifeq ($(NDK_DEBUG),1)
cmd-strip :=
endif

LOCAL_STATIC_LIBRARIES := cpufeatures

include $(BUILD_SHARED_LIBRARY)

###########################
#
# SDL static library
#
###########################

LOCAL_MODULE := SDL2_static

LOCAL_MODULE_FILENAME := libSDL2

LOCAL_LDLIBS :=
LOCAL_EXPORT_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid

include $(BUILD_STATIC_LIBRARY)

###########################
#
# SDL main static library
#
###########################

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_MODULE := SDL2_main

LOCAL_MODULE_FILENAME := libSDL2main

include $(BUILD_STATIC_LIBRARY)

$(call import-module,android/cpufeatures)
16 changes: 16 additions & 0 deletions sdl2/BUGS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Bugs are now managed in the SDL issue tracker, here:

https://github.com/libsdl-org/SDL/issues

You may report bugs there, and search to see if a given issue has already
been reported, discussed, and maybe even fixed.


You may also find help at the SDL forums/mailing list:

https://discourse.libsdl.org/

Bug reports are welcome here, but we really appreciate if you use the issue
tracker, as bugs discussed on the mailing list may be forgotten or missed.

Loading

0 comments on commit d30ea11

Please sign in to comment.