1. package com.eschere.usozo;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.puredata.android.io.PdAudio;
  7. import org.puredata.core.PdBase;
  8. import org.puredata.core.utils.IoUtils;
  9.  
  10. import android.util.Log;
  11.  
  12. public class Sound {
  13.    
  14.     final Usozo u;
  15.     public static final String TAG = "eschere usozo";
  16.    
  17.     public Sound(Usozo u) {
  18.         this.u = u;
  19.         initPd();
  20.     }
  21.    
  22.     public void sendData(float centerX, float centerY) {
  23.         PdBase.sendFloat("xCoor", centerX);
  24.         PdBase.sendFloat("yCoor", centerY);
  25.     }
  26.    
  27.     public void cleanup() {
  28.         PdAudio.stopAudio();
  29.         PdBase.release();
  30.     }
  31.    
  32.     private void initPd() {
  33.         File dir = u.getFilesDir();
  34.         File patchFile = new File(dir, "usozoPatch.pd");
  35.         try {
  36.             IoUtils.extractZipResource(u.getResources().openRawResource(R.raw.patch), dir, true);
  37.             PdBase.openPatch(patchFile.getAbsolutePath());
  38.         } catch (IOException e) {
  39.             Log.e(TAG, e.toString() + "; exiting now");
  40.             u.finish();
  41.         }
  42.     }
  43.  
  44. }