annotate src/audio/android/SDL_androidaudio.c @ 4989:58b6bb4a45e9

More Android cleanup: * Formalized the interface with Java methods in SDL_android.h * We don't need the feature system, at least right now * Fixed waiting for the SDLMain thread
author Sam Lantinga <slouken@libsdl.org>
date Wed, 12 Jan 2011 17:53:06 -0800
parents d86332c0fb9b
children 9f9bea41e88f
rev   line source
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
1 /*
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
4
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
9
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
13 Lesser General Public License for more details.
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
14
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
18
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
19 Sam Lantinga
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
20 slouken@libsdl.org
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
21
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
22 This file written by Ryan C. Gordon (icculus@icculus.org)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
23 */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
24 #include "SDL_config.h"
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
25
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
26 /* Output audio to Android */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
27
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
28 #include "SDL_audio.h"
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
29 #include "../SDL_audio_c.h"
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
30 #include "SDL_androidaudio.h"
4989
58b6bb4a45e9 More Android cleanup:
Sam Lantinga <slouken@libsdl.org>
parents: 4724
diff changeset
31 #include "../../SDL_android.h"
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
32
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
33 #include <android/log.h>
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
34
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
35 static int
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
36 AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
37 {
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
38 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
39 int valid_datatype = 0;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
40
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
41 //TODO: Sample rates etc
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
42 __android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Open\n");
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
43
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
44 this->hidden = SDL_malloc(sizeof(*(this->hidden)));
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
45 if (!this->hidden) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
46 SDL_OutOfMemory();
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
47 return 0;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
48 }
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
49 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
50
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
51 while ((!valid_datatype) && (test_format)) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
52 this->spec.format = test_format;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
53 switch (test_format) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
54 case AUDIO_S8:
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
55 /*case AUDIO_S16LSB: */
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
56 valid_datatype = 1;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
57 break;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
58 default:
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
59 test_format = SDL_NextAudioFormat();
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
60 break;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
61 }
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
62 }
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
63
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
64 return 1;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
65 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
66
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
67 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 AndroidAUD_PlayDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70 __android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Play\n");
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
72
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
73 //playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75 #if 0
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
76
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
77 // sound->rate = 22050; /* sample rate = 22050Hz */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 // sound->vol = 127; /* volume [0..127] for [min..max] */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
79 // sound->pan = 64; /* balance [0..127] for [left..right] */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80 // sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81 // playSound(sound);
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
82 #endif
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
84
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
85
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
86 static Uint8 *
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87 AndroidAUD_GetDeviceBuf(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88 {
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
89 //__android_log_print(ANDROID_LOG_INFO, "SDL", "****** get device buf\n");
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
90
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
91
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
92 // sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
93 // sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
94
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
95
4989
58b6bb4a45e9 More Android cleanup:
Sam Lantinga <slouken@libsdl.org>
parents: 4724
diff changeset
96 Android_JNI_UpdateAudioBuffer(this->hidden->mixbuf, this->hidden->mixlen);
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
97
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
98 return this->hidden->mixbuf; /* is this right? */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
100
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
101 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
102 AndroidAUD_WaitDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
103 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
104 /* stub */
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
105 __android_log_print(ANDROID_LOG_INFO, "SDL", "****** wait device buf\n");
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
106 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
107
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
108 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
109 AndroidAUD_CloseDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
110 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
111 /* stub */
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
112 __android_log_print(ANDROID_LOG_INFO, "SDL", "****** close device buf\n");
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
113 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
114
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
115 static int
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
116 AndroidAUD_Init(SDL_AudioDriverImpl * impl)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
117 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
118 /* Set the function pointers */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
119 impl->OpenDevice = AndroidAUD_OpenDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
120 impl->PlayDevice = AndroidAUD_PlayDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
121 impl->WaitDevice = AndroidAUD_WaitDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
122 impl->GetDeviceBuf = AndroidAUD_GetDeviceBuf;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
123 impl->CloseDevice = AndroidAUD_CloseDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
124
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
125 /* and the capabilities */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
126 impl->HasCaptureSupport = 0; //TODO
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
127 impl->OnlyHasDefaultOutputDevice = 1;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
128 impl->OnlyHasDefaultInputDevice = 1;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
129
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
130 __android_log_print(ANDROID_LOG_INFO, "SDL","Audio init\n");
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
131
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
132 return 1; /* this audio target is available. */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
133 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
134
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
135 AudioBootStrap ANDROIDAUD_bootstrap = {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
136 "android", "SDL Android audio driver", AndroidAUD_Init, 0 /*1? */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
137 };
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
138
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
139 /* vi: set ts=4 sw=4 expandtab: */