api-impl-jni/audio/android_media_AudioTrack.c: make this stuff noop by default

this particular implementation never worked particularly great, and thanks
to hardcoding could cause more harm then good.

export `HAX_AUDIOTRACK_PCM_DEVICE=sysdefault:CARD=Generic_1` to restore
previous behavior

TODO: use libOpenSLES to implement this maybe? we have to have it anyway...
This commit is contained in:
Mis012
2023-06-23 17:24:11 +02:00
parent c25342c8d9
commit a61e44aad8

View File

@@ -9,7 +9,8 @@
#include "../generated_headers/android_media_AudioTrack.h"
#define PCM_DEVICE "sysdefault:CARD=Generic_1"
//#define PCM_DEVICE "sysdefault:CARD=Generic_1"
#define PCM_DEVICE getenv("HAX_AUDIOTRACK_PCM_DEVICE")
void helper_hw_params_init(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *params, unsigned int rate, unsigned int channels, snd_pcm_format_t format)
{
@@ -36,6 +37,8 @@ void helper_hw_params_init(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *params, u
JNIEXPORT void JNICALL Java_android_media_AudioTrack_native_1constructor(JNIEnv *env, jobject this, jint streamType, jint rate, jint channels, jint audioFormat, jint buffer_size, jint mode)
{
snd_pcm_t *pcm_handle;
snd_pcm_hw_params_t *params;
@@ -44,6 +47,9 @@ JNIEXPORT void JNICALL Java_android_media_AudioTrack_native_1constructor(JNIEnv
int ret;
if(!PCM_DEVICE)
return; // STUB
/* Open the PCM device in playback mode */
ret = snd_pcm_open(&pcm_handle, PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0);
if (ret < 0)
@@ -127,6 +133,9 @@ JNIEXPORT jint JNICALL Java_android_media_AudioTrack_getMinBufferSize(JNIEnv *en
}
// ---
if(!PCM_DEVICE)
return 256; // STUB
ret = snd_pcm_open(&pcm_handle, PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0);
if (ret < 0)
printf("Error calling snd_pcm_open: %s\n", snd_strerror(ret));
@@ -160,6 +169,9 @@ void periodic_update_callback(snd_async_handler_t *pcm_callback)
int getenv_ret;
int attach_ret = -1;
if(!PCM_DEVICE)
return; // STUB
// printf("periodic_update_callback called!\n");
JNIEnv *env;
@@ -221,6 +233,9 @@ JNIEXPORT jint JNICALL Java_android_media_AudioTrack_write(JNIEnv *env, jobject
{
int ret;
if(!PCM_DEVICE)
return 0; // STUB
jint channels = _GET_INT_FIELD(this, "channels");
snd_pcm_t *pcm_handle = _PTR(_GET_LONG_FIELD(this, "pcm_handle"));