Make the simulator use alsa instead of esound.
diff --git a/simulator/wrapsim/Android.mk b/simulator/wrapsim/Android.mk
index f9a2414..7c2cbf2 100644
--- a/simulator/wrapsim/Android.mk
+++ b/simulator/wrapsim/Android.mk
@@ -25,8 +25,6 @@
SysPower.c \
Util.c
-LOCAL_C_INCLUDES += prebuilt/common/esd
-
LOCAL_MODULE := libwrapsim
# Relying on other Android libraries is probably a bad idea, since any
@@ -36,7 +34,7 @@
ifeq ($(BUILD_SIM_WITHOUT_AUDIO),true)
LOCAL_CFLAGS += -DBUILD_SIM_WITHOUT_AUDIO=1
else
-LOCAL_LDLIBS += -lesd
+LOCAL_LDLIBS += -lasound
endif
include $(BUILD_SHARED_LIBRARY)
diff --git a/simulator/wrapsim/DevAudio.c b/simulator/wrapsim/DevAudio.c
index af7a950..a8f5c16 100644
--- a/simulator/wrapsim/DevAudio.c
+++ b/simulator/wrapsim/DevAudio.c
@@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <esd.h>
+#include <alsa/asoundlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -19,10 +19,7 @@
* Input event device state.
*/
typedef struct AudioState {
- int fd;
- int sourceId;
- int esdVol;
- int streamType;
+ snd_pcm_t *handle;
} AudioState;
/*
@@ -33,45 +30,31 @@
#if BUILD_SIM_WITHOUT_AUDIO
return 0;
#else
- esd_player_info_t *pi;
- audioState->fd = -1;
- audioState->sourceId = -1;
- audioState->esdVol = -1;
- audioState->streamType = 0;
+ audioState->handle = NULL;
- int format = ESD_BITS16 | ESD_STEREO | ESD_STREAM | ESD_PLAY;
- char namestring[] = "Android Audio XXXXXXXX";
- sprintf(namestring,"Android Audio %08x", (unsigned int)audioState);
- int esd_fd = esd_play_stream_fallback(format, 44100, NULL, namestring);
- if (esd_fd > 0) {
- // find the source_id for this stream
- int mix = esd_open_sound(NULL);
- if (mix > 0) {
- esd_info_t *info = esd_get_all_info(mix);
+ snd_pcm_open(&audioState->handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
- if (info) {
- for(pi = info->player_list; pi; pi = pi->next) {
- if(strcmp(pi->name, namestring) == 0) {
- audioState->sourceId = pi->source_id;
- break;
- }
- }
- esd_free_all_info(info);
- }
- esd_close(mix);
- }
- audioState->fd = esd_fd;
- return 0;
+ if (audioState->handle) {
+ snd_pcm_hw_params_t *params;
+ snd_pcm_hw_params_malloc(¶ms);
+ snd_pcm_hw_params_any(audioState->handle, params);
+ snd_pcm_hw_params_set_access(audioState->handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
+ snd_pcm_hw_params_set_format(audioState->handle, params, SND_PCM_FORMAT_S16_LE);
+ unsigned int rate = 44100;
+ snd_pcm_hw_params_set_rate_near(audioState->handle, params, &rate, NULL);
+ snd_pcm_hw_params_set_channels(audioState->handle, params, 2);
+ snd_pcm_hw_params(audioState->handle, params);
+ snd_pcm_hw_params_free(params);
+ } else {
+ wsLog("Couldn't open audio hardware, faking it\n");
}
- printf("Couldn't open audio device. Faking it.\n");
+
return 0;
#endif
}
/*
- * Return the next available input event.
- *
- * We just pass this through to the real "write", since "fd" is real.
+ * Write audio data.
*/
static ssize_t writeAudio(FakeDev* dev, int fd, const void* buf, size_t count)
{
@@ -79,8 +62,10 @@
return 0;
#else
AudioState *state = (AudioState*)dev->state;
- if (state->fd >= 0)
- return _ws_write(state->fd, buf, count);
+ if (state->handle != NULL) {
+ snd_pcm_writei(state->handle, buf, count / 4);
+ return count;
+ }
// fake timing
usleep(count * 10000 / (441 * 4));
@@ -105,7 +90,7 @@
return 0;
#else
AudioState *state = (AudioState*)dev->state;
- close(state->fd);
+ snd_pcm_close(state->handle);
free(state);
dev->state = NULL;
return 0;
diff --git a/simulator/wrapsim/README.txt b/simulator/wrapsim/README.txt
index 358c06c..364d96d 100644
--- a/simulator/wrapsim/README.txt
+++ b/simulator/wrapsim/README.txt
@@ -19,3 +19,6 @@
For more verbose logging, you can enable the verbose forms of CALLTRACE
and CALLTRACEV in Intercept.c.
+To build, you will need to have the 32-bit libaudio2 development package
+installed. On Ubuntu Hardy, do something like:
+% sudo apt-get install lib32asound2-dev