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