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"
+ − 31
4724
+ − 32 extern void Android_UpdateAudioBuffer(unsigned char *buf, int len);
+ − 33
4718
+ − 34 #include <android/log.h>
+ − 35
+ − 36 static int
+ − 37 AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
+ − 38 {
4724
+ − 39 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ − 40 int valid_datatype = 0;
+ − 41
4718
+ − 42 //TODO: Sample rates etc
+ − 43 __android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Open\n");
4724
+ − 44
+ − 45 this->hidden = SDL_malloc(sizeof(*(this->hidden)));
+ − 46 if (!this->hidden) {
+ − 47 SDL_OutOfMemory();
+ − 48 return 0;
+ − 49 }
+ − 50 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+ − 51
+ − 52 while ((!valid_datatype) && (test_format)) {
+ − 53 this->spec.format = test_format;
+ − 54 switch (test_format) {
+ − 55 case AUDIO_S8:
+ − 56 /*case AUDIO_S16LSB: */
+ − 57 valid_datatype = 1;
+ − 58 break;
+ − 59 default:
+ − 60 test_format = SDL_NextAudioFormat();
+ − 61 break;
+ − 62 }
+ − 63 }
4718
+ − 64
+ − 65 return 1;
+ − 66 }
+ − 67
+ − 68 static void
+ − 69 AndroidAUD_PlayDevice(_THIS)
+ − 70 {
+ − 71 __android_log_print(ANDROID_LOG_INFO, "SDL", "AndroidAudio Play\n");
+ − 72
+ − 73
+ − 74 //playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
+ − 75
+ − 76 #if 0
4724
+ − 77
4718
+ − 78 // sound->rate = 22050; /* sample rate = 22050Hz */
+ − 79 // sound->vol = 127; /* volume [0..127] for [min..max] */
+ − 80 // sound->pan = 64; /* balance [0..127] for [left..right] */
+ − 81 // sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */
+ − 82 // playSound(sound);
+ − 83 #endif
+ − 84 }
+ − 85
+ − 86
+ − 87 static Uint8 *
+ − 88 AndroidAUD_GetDeviceBuf(_THIS)
+ − 89 {
4724
+ − 90 //__android_log_print(ANDROID_LOG_INFO, "SDL", "****** get device buf\n");
+ − 91
+ − 92
+ − 93 // sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
+ − 94 // sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
+ − 95
+ − 96
+ − 97 Android_UpdateAudioBuffer(this->hidden->mixbuf, this->hidden->mixlen);
+ − 98
4718
+ − 99 return this->hidden->mixbuf; /* is this right? */
+ − 100 }
+ − 101
+ − 102 static void
+ − 103 AndroidAUD_WaitDevice(_THIS)
+ − 104 {
+ − 105 /* stub */
4724
+ − 106 __android_log_print(ANDROID_LOG_INFO, "SDL", "****** wait device buf\n");
4718
+ − 107 }
+ − 108
+ − 109 static void
+ − 110 AndroidAUD_CloseDevice(_THIS)
+ − 111 {
+ − 112 /* stub */
4724
+ − 113 __android_log_print(ANDROID_LOG_INFO, "SDL", "****** close device buf\n");
4718
+ − 114 }
+ − 115
+ − 116 static int
+ − 117 AndroidAUD_Init(SDL_AudioDriverImpl * impl)
+ − 118 {
+ − 119 /* Set the function pointers */
+ − 120 impl->OpenDevice = AndroidAUD_OpenDevice;
+ − 121 impl->PlayDevice = AndroidAUD_PlayDevice;
+ − 122 impl->WaitDevice = AndroidAUD_WaitDevice;
+ − 123 impl->GetDeviceBuf = AndroidAUD_GetDeviceBuf;
+ − 124 impl->CloseDevice = AndroidAUD_CloseDevice;
+ − 125
+ − 126 /* and the capabilities */
+ − 127 impl->HasCaptureSupport = 0; //TODO
+ − 128 impl->OnlyHasDefaultOutputDevice = 1;
+ − 129 impl->OnlyHasDefaultInputDevice = 1;
+ − 130
+ − 131 __android_log_print(ANDROID_LOG_INFO, "SDL","Audio init\n");
+ − 132
+ − 133 return 1; /* this audio target is available. */
+ − 134 }
+ − 135
+ − 136 AudioBootStrap ANDROIDAUD_bootstrap = {
+ − 137 "android", "SDL Android audio driver", AndroidAUD_Init, 0 /*1? */
+ − 138 };
+ − 139
+ − 140 /* vi: set ts=4 sw=4 expandtab: */