changeset 523:d00096b6bf17

added sound introspection abilities.
author Robert McIntyre <rlm@mit.edu>
date Sat, 23 Jun 2012 20:34:14 -0500
parents 5596cd4a3fc6
children 7ef5c73ea8fa
files clojure/com/aurellem/gb/gb_driver.clj clojure/com/aurellem/run/sound.clj java/src/com/aurellem/gb/Gb.java src/VisualBoyAdvance.cfg src/clojure/clojure.cpp src/gb/GB.h
diffstat 6 files changed, 77 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj	Sat Jun 23 19:12:26 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj	Sat Jun 23 20:34:14 2012 -0500
     1.3 @@ -193,6 +193,12 @@
     1.4      ([new-data]
     1.5         (store-data @current-state new-data))))
     1.6  
     1.7 +(def sound-data
     1.8 +  (cpu-data Gb/SOUND_SIZE
     1.9 +            (fn [arr]
    1.10 +              (Gb/getFrameSound arr)
    1.11 +              (Gb/setSoundFrameWritten 0))))
    1.12 +
    1.13  (def memory
    1.14    (cpu-data Gb/GB_MEMORY #(Gb/getMemory %)))
    1.15  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/clojure/com/aurellem/run/sound.clj	Sat Jun 23 20:34:14 2012 -0500
     2.3 @@ -0,0 +1,20 @@
     2.4 +(ns com.aurellem.run.sound
     2.5 +  (:use (com.aurellem.gb saves gb-driver util constants
     2.6 +                         items vbm characters money
     2.7 +                         rlm-assembly))
     2.8 +  (:use (com.aurellem.run util music title save-corruption
     2.9 +                          bootstrap-0 bootstrap-1))
    2.10 +  (:require clojure.string)
    2.11 +  (:import [com.aurellem.gb.gb_driver SaveState])
    2.12 +  (:import java.awt.image.BufferedImage)
    2.13 +  (:import java.io.File))
    2.14 +
    2.15 +
    2.16 +(defn sound-test []
    2.17 +  (step (mid-game))
    2.18 +  (println (frequencies (sound-data)))
    2.19 +  (run-moves @current-state (repeat 10 []))
    2.20 +  (println (frequencies (sound-data))))
    2.21 +
    2.22 +
    2.23 +        
    2.24 \ No newline at end of file
     3.1 --- a/java/src/com/aurellem/gb/Gb.java	Sat Jun 23 19:12:26 2012 -0500
     3.2 +++ b/java/src/com/aurellem/gb/Gb.java	Sat Jun 23 20:34:14 2012 -0500
     3.3 @@ -101,6 +101,8 @@
     3.4  
     3.5      public static final int GB_MEMORY = 0x10000;
     3.6  
     3.7 +    public static final int SOUND_SIZE = 735 * 30 * 2;
     3.8 +
     3.9      public static native void getMemory(int[] store);
    3.10  
    3.11      public static native void writeMemory(int[] newMemory);
    3.12 @@ -127,7 +129,14 @@
    3.13  
    3.14      public static native void getPixels(int[] store);
    3.15  
    3.16 +    public static native void getFrameSound(int[] store);
    3.17 +
    3.18      public static native void nwritePNG(String filename);
    3.19  
    3.20      public static native int readMemory(int address);
    3.21 +    
    3.22 +    public static native int getSoundFrameWritten();
    3.23 +
    3.24 +    public static native void setSoundFrameWritten(int frames);
    3.25 +
    3.26  }
     4.1 --- a/src/VisualBoyAdvance.cfg	Sat Jun 23 19:12:26 2012 -0500
     4.2 +++ b/src/VisualBoyAdvance.cfg	Sat Jun 23 20:34:14 2012 -0500
     4.3 @@ -182,7 +182,7 @@
     4.4  
     4.5  # Sound OFF flag
     4.6  # 0=sound on, anything else turns off sound
     4.7 -soundOff=1
     4.8 +soundOff=0
     4.9  
    4.10  # Sound Enable
    4.11  # Controls which channels are enabled: (add values)
     5.1 --- a/src/clojure/clojure.cpp	Sat Jun 23 19:12:26 2012 -0500
     5.2 +++ b/src/clojure/clojure.cpp	Sat Jun 23 20:34:14 2012 -0500
     5.3 @@ -347,3 +347,41 @@
     5.4  (JNIEnv *env, jclass clazz, jint address){
     5.5    return (jint) gbReadMemory((u16) address); 
     5.6  }
     5.7 +
     5.8 +
     5.9 +/*
    5.10 + * Class:     com_aurellem_gb_Gb
    5.11 + * Method:    getFrameSound
    5.12 + * Signature: ([I)V
    5.13 + */
    5.14 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_getFrameSound
    5.15 +(JNIEnv *env, jclass clazz, jintArray arr){
    5.16 +  jint *sound_store = env->GetIntArrayElements(arr, 0);
    5.17 +  int i;
    5.18 +  for (i = 0; i < 44100; i++){
    5.19 +    sound_store[i] = (jint) soundFrameSound[i];
    5.20 +  }
    5.21 +  env->ReleaseIntArrayElements(arr, sound_store, 0);
    5.22 +}
    5.23 +
    5.24 +
    5.25 +/*
    5.26 + * Class:     com_aurellem_gb_Gb
    5.27 + * Method:    getSoundFrameWritten
    5.28 + * Signature: ()I
    5.29 + */
    5.30 +JNIEXPORT jint JNICALL Java_com_aurellem_gb_Gb_getSoundFrameWritten
    5.31 +  (JNIEnv *env, jclass clazz){
    5.32 +  return soundFrameSoundWritten;
    5.33 +}
    5.34 +
    5.35 +/*
    5.36 + * Class:     com_aurellem_gb_Gb
    5.37 + * Method:    setSoundFrameWritten
    5.38 + * Signature: (I)V
    5.39 + */
    5.40 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_setSoundFrameWritten
    5.41 +(JNIEnv *env, jclass clazz , jint newSoundFrameWritten){
    5.42 +  soundFrameSoundWritten = newSoundFrameWritten;
    5.43 +}
    5.44 +
     6.1 --- a/src/gb/GB.h	Sat Jun 23 19:12:26 2012 -0500
     6.2 +++ b/src/gb/GB.h	Sat Jun 23 20:34:14 2012 -0500
     6.3 @@ -65,6 +65,9 @@
     6.4  
     6.5  extern u8 gbReadMemory(u16 address);
     6.6  
     6.7 +extern u16	 soundFrameSound[735 * 30 * 2];
     6.8 +extern int32 soundFrameSoundWritten;
     6.9 +
    6.10  extern struct EmulatedSystem GBSystem;
    6.11  extern struct EmulatedSystemCounters &GBSystemCounters;
    6.12