annotate src/audio/android/SDL_androidaudio.c @ 4865:fff50e86c891

Update VS2010 project to add new files; update new files so code builds on Win32/Win64
author Andreas Schiffler <aschiffler@ferzkopp.net>
date Mon, 23 Aug 2010 23:44:28 -0700
parents d86332c0fb9b
children 58b6bb4a45e9
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"
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
31
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
32 extern void Android_UpdateAudioBuffer(unsigned char *buf, int len);
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
33
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
34 #include <android/log.h>
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
35
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
36 static int
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
37 AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
38 {
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
39 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
40 int valid_datatype = 0;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
41
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
42 //TODO: Sample rates etc
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
43 __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
44
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
45 this->hidden = SDL_malloc(sizeof(*(this->hidden)));
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
46 if (!this->hidden) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
47 SDL_OutOfMemory();
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
48 return 0;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
49 }
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
50 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
51
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
52 while ((!valid_datatype) && (test_format)) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
53 this->spec.format = test_format;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
54 switch (test_format) {
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
55 case AUDIO_S8:
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
56 /*case AUDIO_S16LSB: */
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
57 valid_datatype = 1;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
58 break;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
59 default:
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
60 test_format = SDL_NextAudioFormat();
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
61 break;
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
62 }
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
63 }
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
64
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
65 return 1;
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
68 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
69 AndroidAUD_PlayDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
70 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
71 __android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Play\n");
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
74 //playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
75
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
76 #if 0
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
77
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
78 // sound->rate = 22050; /* sample rate = 22050Hz */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
79 // sound->vol = 127; /* volume [0..127] for [min..max] */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
80 // sound->pan = 64; /* balance [0..127] for [left..right] */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
81 // 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
82 // playSound(sound);
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
83 #endif
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
87 static Uint8 *
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
88 AndroidAUD_GetDeviceBuf(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
89 {
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
90 //__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
91
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
92
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
93 // 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
94 // 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
95
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
96
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
97 Android_UpdateAudioBuffer(this->hidden->mixbuf, this->hidden->mixlen);
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
98
4718
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
99 return this->hidden->mixbuf; /* is this right? */
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
102 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
103 AndroidAUD_WaitDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
104 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
105 /* stub */
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
106 __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
107 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
108
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
109 static void
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
110 AndroidAUD_CloseDevice(_THIS)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
111 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
112 /* stub */
4724
d86332c0fb9b Working on the sound system
Paul Hunkin <paul@bieh.net>
parents: 4718
diff changeset
113 __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
114 }
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
115
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
116 static int
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
117 AndroidAUD_Init(SDL_AudioDriverImpl * impl)
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
118 {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
119 /* Set the function pointers */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
120 impl->OpenDevice = AndroidAUD_OpenDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
121 impl->PlayDevice = AndroidAUD_PlayDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
122 impl->WaitDevice = AndroidAUD_WaitDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
123 impl->GetDeviceBuf = AndroidAUD_GetDeviceBuf;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
124 impl->CloseDevice = AndroidAUD_CloseDevice;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
125
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
126 /* and the capabilities */
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
127 impl->HasCaptureSupport = 0; //TODO
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
128 impl->OnlyHasDefaultOutputDevice = 1;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
129 impl->OnlyHasDefaultInputDevice = 1;
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
130
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
131 __android_log_print(ANDROID_LOG_INFO, "SDL","Audio init\n");
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
132
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
133 return 1; /* this audio target is available. */
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
136 AudioBootStrap ANDROIDAUD_bootstrap = {
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
137 "android", "SDL Android audio driver", AndroidAUD_Init, 0 /*1? */
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
79aa6c61f33b Added stub android sound system
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
140 /* vi: set ts=4 sw=4 expandtab: */