am bd642f3e: Make the simulator use alsa instead of esound.

Merge commit 'bd642f3e94f4cb94cbb48646ae61da5f6b18a093' into eclair-mr2-plus-aosp

* commit 'bd642f3e94f4cb94cbb48646ae61da5f6b18a093':
  Make the simulator use alsa instead of esound.
This commit is contained in:
Marco Nelissen
2009-12-07 16:02:40 -08:00
committed by Android Git Automerger
3 changed files with 28 additions and 42 deletions

View File

@@ -25,8 +25,6 @@ LOCAL_SRC_FILES := \
SysPower.c \ SysPower.c \
Util.c Util.c
LOCAL_C_INCLUDES += prebuilt/common/esd
LOCAL_MODULE := libwrapsim LOCAL_MODULE := libwrapsim
# Relying on other Android libraries is probably a bad idea, since any # Relying on other Android libraries is probably a bad idea, since any
@@ -36,7 +34,7 @@ LOCAL_LDLIBS += -lpthread -ldl
ifeq ($(BUILD_SIM_WITHOUT_AUDIO),true) ifeq ($(BUILD_SIM_WITHOUT_AUDIO),true)
LOCAL_CFLAGS += -DBUILD_SIM_WITHOUT_AUDIO=1 LOCAL_CFLAGS += -DBUILD_SIM_WITHOUT_AUDIO=1
else else
LOCAL_LDLIBS += -lesd LOCAL_LDLIBS += -lasound
endif endif
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)

View File

@@ -8,7 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <esd.h> #include <alsa/asoundlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@@ -19,10 +19,7 @@
* Input event device state. * Input event device state.
*/ */
typedef struct AudioState { typedef struct AudioState {
int fd; snd_pcm_t *handle;
int sourceId;
int esdVol;
int streamType;
} AudioState; } AudioState;
/* /*
@@ -33,45 +30,31 @@ static int configureInitialState(const char* pathName, AudioState* audioState)
#if BUILD_SIM_WITHOUT_AUDIO #if BUILD_SIM_WITHOUT_AUDIO
return 0; return 0;
#else #else
esd_player_info_t *pi; audioState->handle = NULL;
audioState->fd = -1;
audioState->sourceId = -1;
audioState->esdVol = -1;
audioState->streamType = 0;
int format = ESD_BITS16 | ESD_STEREO | ESD_STREAM | ESD_PLAY; snd_pcm_open(&audioState->handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
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);
if (info) { if (audioState->handle) {
for(pi = info->player_list; pi; pi = pi->next) { snd_pcm_hw_params_t *params;
if(strcmp(pi->name, namestring) == 0) { snd_pcm_hw_params_malloc(&params);
audioState->sourceId = pi->source_id; snd_pcm_hw_params_any(audioState->handle, params);
break; 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;
esd_free_all_info(info); snd_pcm_hw_params_set_rate_near(audioState->handle, params, &rate, NULL);
} snd_pcm_hw_params_set_channels(audioState->handle, params, 2);
esd_close(mix); snd_pcm_hw_params(audioState->handle, params);
} snd_pcm_hw_params_free(params);
audioState->fd = esd_fd; } else {
return 0; wsLog("Couldn't open audio hardware, faking it\n");
} }
printf("Couldn't open audio device. Faking it.\n");
return 0; return 0;
#endif #endif
} }
/* /*
* Return the next available input event. * Write audio data.
*
* We just pass this through to the real "write", since "fd" is real.
*/ */
static ssize_t writeAudio(FakeDev* dev, int fd, const void* buf, size_t count) static ssize_t writeAudio(FakeDev* dev, int fd, const void* buf, size_t count)
{ {
@@ -79,8 +62,10 @@ static ssize_t writeAudio(FakeDev* dev, int fd, const void* buf, size_t count)
return 0; return 0;
#else #else
AudioState *state = (AudioState*)dev->state; AudioState *state = (AudioState*)dev->state;
if (state->fd >= 0) if (state->handle != NULL) {
return _ws_write(state->fd, buf, count); snd_pcm_writei(state->handle, buf, count / 4);
return count;
}
// fake timing // fake timing
usleep(count * 10000 / (441 * 4)); usleep(count * 10000 / (441 * 4));
@@ -105,7 +90,7 @@ static int closeAudio(FakeDev* dev, int fd)
return 0; return 0;
#else #else
AudioState *state = (AudioState*)dev->state; AudioState *state = (AudioState*)dev->state;
close(state->fd); snd_pcm_close(state->handle);
free(state); free(state);
dev->state = NULL; dev->state = NULL;
return 0; return 0;

View File

@@ -19,3 +19,6 @@ To debug wrapsim, set WRAPSIM_LOG to a log file before launching, e.g.
For more verbose logging, you can enable the verbose forms of CALLTRACE For more verbose logging, you can enable the verbose forms of CALLTRACE
and CALLTRACEV in Intercept.c. 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