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