Some audio work, setting default frequency, volume, etc. and calling a generic playback function that uses them. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Fri, 15 Aug 2008 10:44:31 +0000
branchgsoc2008_nds
changeset 2689 e065c9f6a393
parent 2688 71c56e900f8b
child 2690 ca01c20274c0
Some audio work, setting default frequency, volume, etc. and calling a generic playback function that uses them.
src/audio/nds/SDL_ndsaudio.c
src/audio/nds/SDL_ndsaudio.h
--- a/src/audio/nds/SDL_ndsaudio.c	Fri Aug 15 10:17:07 2008 +0000
+++ b/src/audio/nds/SDL_ndsaudio.c	Fri Aug 15 10:44:31 2008 +0000
@@ -34,7 +34,36 @@
 static int
 NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
 {
-    return 1;                   /* always succeeds. */
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+    int valid_datatype = 0;
+
+    this->hidden = SDL_malloc(sizeof(*(this->hidden)));
+    if(!this->hidden) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    while ((!valid_datatype) && (test_format)) {
+        this->spec.format = test_format;
+        switch (test_format) {
+            case AUDIO_S8:
+            /*case AUDIO_S16LSB:*/
+                valid_datatype = 1;
+                break;
+            default:
+               test_format = SDL_NextAudioFormat();
+               break;
+        }
+    }
+
+    /* set the generic sound parameters */
+    setGenericSound(22050,  /* sample rate */
+                    127,    /* volume */
+                    64,     /* panning/balance */
+                    0);     /* sound format*/
+
+    return 1;
 }
 
 static void
@@ -44,21 +73,23 @@
     if(!sound) {
         SDL_OutOfMemory();
     }
-    sound->data = NULL;  /* pointer to raw audio data */
-    sound->len = 0;      /* size of raw data pointed to above */
-    sound->rate = 22050; /* sample rate = 22050Hz */
-    sound->vol = 127;    /* volume [0..127] for [min..max] */
-    sound->pan = 64;     /* balance [0..127] for [left..right] */
-    sound->format = 0;   /* 0 for 16-bit, 1 for 8-bit */
-    /*playSound(sound);*/
-    /* stub */
+
+    playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
+
+//    sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
+//    sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
+//    sound->rate = 22050; /* sample rate = 22050Hz */
+//    sound->vol = 127;    /* volume [0..127] for [min..max] */
+//    sound->pan = 64;     /* balance [0..127] for [left..right] */
+//    sound->format = 0;   /* 0 for 16-bit, 1 for 8-bit */
+//    playSound(sound);
 }
 
 
 static Uint8 *
 NDSAUD_GetDeviceBuf(_THIS)
-{
-    /* stub */
+{   /* is this right? */
+    return this->hidden->mixbuf;
 }
 
 static void
--- a/src/audio/nds/SDL_ndsaudio.h	Fri Aug 15 10:17:07 2008 +0000
+++ b/src/audio/nds/SDL_ndsaudio.h	Fri Aug 15 10:44:31 2008 +0000
@@ -25,12 +25,14 @@
 #define _SDL_ndsaudio_h
 
 #include "../SDL_sysaudio.h"
+#include <nds/arm9/sound.h>
 
 /* Hidden "this" pointer for the audio functions */
 #define _THIS	SDL_AudioDevice *this
 
 struct SDL_PrivateAudioData
 {
+    TransferSoundData* sound;
     /* The file descriptor for the audio device */
     Uint8 *mixbuf;
     Uint32 mixlen;