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.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 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 NDS */
    27 
    28 #include <nds.h>
    29 
    30 #include "SDL_audio.h"
    31 #include "../SDL_audio_c.h"
    32 #include "SDL_ndsaudio.h"
    33 
    34 #define TRACE printf
    35 
    36 static int
    37 NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
    38 {
    39     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
    40     int valid_datatype = 0;
    41 
    42     this->hidden = SDL_malloc(sizeof(*(this->hidden)));
    43     if(!this->hidden) {
    44         SDL_OutOfMemory();
    45         return 0;
    46     }
    47     SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    48 
    49     TRACE("+NDSAUD_OpenDevice\n");
    50     while ((!valid_datatype) && (test_format)) {
    51         this->spec.format = test_format;
    52         switch (test_format) {
    53             case AUDIO_S8:
    54             /*case AUDIO_S16LSB:*/
    55                 valid_datatype = 1;
    56                 break;
    57             default:
    58                test_format = SDL_NextAudioFormat();
    59                break;
    60         }
    61     }
    62 
    63     /* set the generic sound parameters */
    64     setGenericSound(22050,  /* sample rate */
    65                     127,    /* volume */
    66                     64,     /* panning/balance */
    67                     0);     /* sound format*/
    68 
    69     TRACE("-NDSAUD_OpenDevice\n");
    70     return 1;
    71 }
    72 
    73 static void
    74 NDSAUD_PlayDevice(_THIS)
    75 {
    76     TransferSoundData* sound = SDL_malloc(sizeof(TransferSoundData));
    77     if(!sound) {
    78         SDL_OutOfMemory();
    79     }
    80     TRACE("+NDSAUD_PlayDevice\n");
    81 
    82     playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
    83 
    84     TRACE("-NDSAUD_PlayDevice\n");
    85 //    sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
    86 //    sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
    87 //    sound->rate = 22050; /* sample rate = 22050Hz */
    88 //    sound->vol = 127;    /* volume [0..127] for [min..max] */
    89 //    sound->pan = 64;     /* balance [0..127] for [left..right] */
    90 //    sound->format = 0;   /* 0 for 16-bit, 1 for 8-bit */
    91 //    playSound(sound);
    92 }
    93 
    94 
    95 static Uint8 *
    96 NDSAUD_GetDeviceBuf(_THIS)
    97 {   /* is this right? */
    98     TRACE("!NDSAUD_GetDeviceBuf\n");
    99     return this->hidden->mixbuf;
   100 }
   101 
   102 static void
   103 NDSAUD_WaitDevice(_THIS)
   104 {
   105     /* stub */
   106     TRACE("!NDSAUD_WaitDevice\n");
   107 }
   108 
   109 static void
   110 NDSAUD_CloseDevice(_THIS)
   111 {
   112     /* stub */
   113     TRACE("!NDSAUD_CloseDevice\n");
   114 }
   115 
   116 static int
   117 NDSAUD_Init(SDL_AudioDriverImpl * impl)
   118 {
   119     TRACE("+NDSAUD_Init\n");
   120 
   121     /* Set the function pointers */
   122     impl->OpenDevice = NDSAUD_OpenDevice;
   123     impl->PlayDevice = NDSAUD_PlayDevice;
   124     impl->WaitDevice = NDSAUD_WaitDevice;
   125     impl->GetDeviceBuf = NDSAUD_GetDeviceBuf;
   126     impl->CloseDevice = NDSAUD_CloseDevice;
   127 
   128     /* and the capabilities */
   129     impl->HasCaptureSupport = 1;
   130     impl->OnlyHasDefaultOutputDevice = 1;
   131     impl->OnlyHasDefaultInputDevice = 1;
   132 
   133     TRACE("-NDSAUD_Init\n");
   134     return 1;
   135 }
   136 
   137 AudioBootStrap NDSAUD_bootstrap = {
   138     "nds", "SDL NDS audio driver", NDSAUD_Init, 0 /*1?*/
   139 };
   140 
   141 /* vi: set ts=4 sw=4 expandtab: */