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