aboutsummaryrefslogtreecommitdiffstats
path: root/android/audio-test.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2011-01-02 13:17:22 +0100
committerDavid 'Digit' Turner <digit@android.com>2011-01-02 13:18:16 +0100
commitca29fbbb188a1aab9b69776d5dc6bc3e7f812a0a (patch)
tree49975f4c226c17a22f824f1763a4ad7eeeadf9a7 /android/audio-test.c
parent5164d3c53f57dfb468ab11136358b6e3b6cf0513 (diff)
downloadexternal_qemu-ca29fbbb188a1aab9b69776d5dc6bc3e7f812a0a.zip
external_qemu-ca29fbbb188a1aab9b69776d5dc6bc3e7f812a0a.tar.gz
external_qemu-ca29fbbb188a1aab9b69776d5dc6bc3e7f812a0a.tar.bz2
Add -audio-test-out option to the core.
This option can be used to quickly check audio output (without having to boot a full AVD and launch a sound-playing application). Usage: emulator <other-options> -qemu -audio-test-out qemu-android <other-options> -audio-test-out This simply generates an ugly saw signal, but that's enough for us. Change-Id: I060300b4000b9705d181c6262de8d4d13c749e69
Diffstat (limited to 'android/audio-test.c')
-rw-r--r--android/audio-test.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/android/audio-test.c b/android/audio-test.c
new file mode 100644
index 0000000..e10b987
--- /dev/null
+++ b/android/audio-test.c
@@ -0,0 +1,103 @@
+/* Copyright (C) 2010 The Android Open Source Project
+**
+** This software is licensed under the terms of the GNU General Public
+** License version 2, as published by the Free Software Foundation, and
+** may be copied, distributed, and modified under those terms.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+*/
+#include "audio/audio.h"
+#include "android/utils/debug.h"
+
+/* This source file contains a small test audio virtual device that
+ * can be used to check that the emulator properly plays sound on
+ * the host system without having to boot a full system.
+ */
+
+#define SAMPLE_SIZE 16384
+
+typedef struct {
+ QEMUSoundCard card;
+ SWVoiceOut *voice;
+ int pos;
+ short sample[SAMPLE_SIZE];
+} TestAudio;
+
+static void
+testAudio_audio_callback(void* opaque, int free)
+{
+ TestAudio* ta = opaque;
+
+ //printf("%s: pos=%d free=%d\n", __FUNCTION__, ta->pos, free);
+
+ while (free > 0) {
+ int avail = SAMPLE_SIZE - ta->pos;
+ if (avail > free)
+ avail = free;
+
+ AUD_write(ta->voice, ta->sample + ta->pos, avail);
+ ta->pos += avail;
+ if (ta->pos >= SAMPLE_SIZE)
+ ta->pos = 0;
+
+ free -= avail;
+ }
+}
+
+static int
+testAudio_init( TestAudio* ta )
+{
+ struct audsettings as;
+
+ AUD_register_card("test_audio", &ta->card);
+
+ as.freq = 16000;
+ as.nchannels = 1;
+ as.fmt = AUD_FMT_S16;
+ as.endianness = AUDIO_HOST_ENDIANNESS;
+
+ ta->voice = AUD_open_out(
+ &ta->card,
+ ta->voice,
+ "test_audio",
+ ta,
+ testAudio_audio_callback,
+ &as);
+
+ if (!ta->voice) {
+ dprint("Cannot open test audio!");
+ return -1;
+ }
+ ta->pos = 0;
+
+ /* Initialize samples */
+ int nn;
+ for (nn = 0; nn < SAMPLE_SIZE; nn++) {
+ ta->sample[nn] = (short)(((nn % (SAMPLE_SIZE/4))*65536/(SAMPLE_SIZE/4)) & 0xffff);
+ }
+
+ AUD_set_active_out(ta->voice, 1);
+ return 0;
+}
+
+static TestAudio* testAudio;
+
+int
+android_audio_test_start_out(void)
+{
+ if (!testAudio) {
+ testAudio = malloc(sizeof(*testAudio));
+ if (testAudio_init(testAudio) < 0) {
+ free(testAudio);
+ testAudio = NULL;
+ fprintf(stderr, "Could not start audio test!\n");
+ return -1;
+ } else {
+ printf("Audio test started!\n");
+ }
+ }
+ return 0;
+}