puredata - Play wave file in Android with libpd -


how play wave file in android using libpd? can soundpool.play, i'd try libpd. followed this tutorial implement libpd, it's not working. can wrong? code or pd patch?

this activity code:

public class mainactivity extends actionbaractivity implements ontouchlistener {      private pduidispatcher dispatcher;      private void initpd() throws ioexception {         int samplerate = audioparameters.suggestsamplerate();         pdaudio.initaudio(samplerate, 0, 2, 8, true);          dispatcher = new pduidispatcher();         pdbase.setreceiver(dispatcher);     }      private void loadpdpatch() throws ioexception {         file dir = getfilesdir();         ioutils.extractzipresource(getresources().openrawresource(r.raw.playaudio), dir, true);         file pdpatch = new file(dir, "playaudio.pd");         pdbase.openpatch(pdpatch.getabsolutepath());     }      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button bangbutton = (button) findviewbyid(r.id.bangbutton);         bangbutton.setontouchlistener(this);          try {             initpd();             loadpdpatch();             pdaudio.startaudio(this);          } catch (ioexception e) {             finish();         }     }      @override     protected void onresume() {         super.onresume();         pdaudio.startaudio(this);     }      @override     protected void onpause() {         super.onpause();         pdaudio.stopaudio();     }      @override     public boolean ontouch(view v, motionevent event) {         if (event.getaction() == motionevent.action_down)             if(v.getid() == r.id.bangbutton) {                 pdbase.sendbang("mybang");             }          return false;     } } 

this pd patch:

puredata patch

#n canvas 0 22 902 577 24; #x obj 46 24 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 ; #x obj 47 248 dac~; #x obj 48 193 readsf~; #x obj 49 118 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #x msg 42 61 \; pd dsp \$1; #x msg 50 155 open myfile.wav \, 1; #x connect 0 0 4 0; #x connect 2 0 1 0; #x connect 3 0 5 0; #x connect 5 0 2 0; 

the error in pd-patch:

you sending bang mybang symbol within pd-patch.

however, there doesn't seem receiver attached name in patch, never triggers within pd.

  • you have [send mybang] triggered bng object (but send void).

  • the [bng] object might have receive-label set, but

    • according screenshot has no receive-label set @ (the inlet vanish if so; it's bit hard read).

    • if did have receive-label mybang, clicking on [bng] trigger infinite recursion ([bng] => [s mybang] -> [bng] ...)

general errors

output of [bng]: should never have fan-out of messages (where connect single outlet multiple message inlets) results in undefined order of execution; use [trigger] in these cases.

last outlet of [readsf~]: [readsf~] mono player default; last outlet of object gives bang whenever soundfile has finished playing; sending bang 2nd inlet of [dac~] (expecting signal) error. if want stereo soundfile player, use [readsf~ 2]

solution

so patch should instead like:

[bng] | [s mybang]  [r mybang] | [open myfile.wav, 1( | [readsf~ 2] |     | [dac~ ] 

Comments