Apologies for spam; we've changed our policy by requiring approval for accounts, and deleted all existing spam and user - thanks for your help flagging content. We continue to test our forums and Vanilla software, aiming for release early in 2013. If you need to give us feedback outside the forum, contact us via http://createdigitalmusic.com/contact/ or on Facebook
how to load samples into a patch from the sd card?
  • Im building a simple drumcomputer with libpd for android. i want to load a short wav file into an array in my patch. do i only have to send a message to the patch with the filepath?? for example sd/snare.wav?
  • That sounds about right. If your patch also resides on the SD card, then you'll probably be better off using relative paths. If it doesn't, then you need to use an absolute path that starts with /sdcard.
  • hello
    im trying to do the same and cant get it to work. using the looping sampler example in the browser, i changed this bit to load the sound
    [r filename]
    |
    [soundfiler]

    then from java i get the file path from a list and send it like this
    String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    String filename = musiccursor.getString(music_column_index);
    // File f = new File(baseDir + File.separator + filename);

    PdBase.sendMessage("filename", "read "+baseDir + File.separator + filename+" table17");

    ive tried just sending just the filename but nothing happens
    thanks
  • It's hard to say for sure given the information you provided, but at first sight it looks like you're missing a space before the array name.
  • Also, I would uncomment the File object f and check f.exists().
  • Please disregard my first response. I just realized what the problem is. You can't send the arguments in a single string. Instead, you need to say
    PdBase.sendMessage("filename", "read", baseDir + File.separator + filename, "table17").
  • thanks
    it still doesnt seem to work, the absolute address i get looks like this, do i need to format it somehow?
    /mnt/sdcar/Sounds/beep.wav

    also tried it with spaces after read and before table.
    how would i send the pd log to java to whats going on?
    tried with a few different file types and samplerates ect.
  • You don't want any spaces around your table name (or anywhere else).  The path to the SD card looks wrong.  I think you want /sdcard/Sounds/beep.wav.
  • right o,
    so its this line needs changing probably
    String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();

    wonder if i get /mnt because my phone is routed.
    ill do some experiments and find out.
  • Have you tried exploring the file system with "adb shell"?
  • adb shell? whats your idea there?

    looks like mnt/ stands for mount which is the root of the phone, a place one would not normaly have access to, sdcard is just a folder in there, i can see it with root explorer.
  • actually info is pretty random about /mnt/ and rooted phones.
  • "adb shell" will give you a shell on your Android device.  Then you can look around with cd and ls and pwd and find your SD card and files.
  • im trying to do this within the app, i already know where the files are located.
    i make a list of every sound file on the device, then on click it sends the selected path to a soundfiler in pd, i know the path because it changes the list item text to the file path.
    perhaps converting the file to an array in java and sending that would be better?

    are there any examples of this kind of thing around i can take a look at?
  • It seems like you're trying to do two things at the same time. One is listing file names, the other opening files with soundfiler. Let's focus on soundfiler. I would suggest that you pick one file that you know exists, hard-code its path in the message to Pd, and see whether you can access it. Also, make sure to register an instance of PdUiDispatcher with PdBase before you do anything else, then watch Pd's status messages in logcat. If soundfiler is unhappy, it should log an error message.
  • @Sporsmaal I notice you don't reference a Pd array or have a -resize switch in with the read message. Try this patch setup:

    [r openfilemsg]
    |
    [read -resize $1 your_array_name(    // <-- a message<br />|
    [soundfiler]

    You will need an array defined in the patch to catch the data. Then on the java side you send this:

    PdBase.sendMessage("openfilemsg", "open", fileName);

    where fileName is your absolute path string. Also make sure you have set any needed External Storage permissions in your manifest file. Hope that helps

      
  • Actually, there is a reference to an array, table17. In this setup, you only need to send in the file name, not the command, so the Java line should be PdBase.sendSymbol("openfilemsg", fileName).
  • will i cant seem to get it to work at all, maybe something in my patch is wrong? heres a link http://dl.dropbox.com/u/42310381/test.pd

    @choons, i dont understand what this is in pd [read -resize $1 your_array_name( // <-- a message<br />|

  • I think the formatting of @choons's message didn't work out. Here's how I think it was supposed to look:

    [r openfilemsg] | [read -resize $1 array_name( | [soundfiler]

    The middle part is a message object.

  • Ha! Now my formatting didn't work out. I should have previewed. Here's another attempt:

    [r openfilemsg]
    |
    [read -resize $1 array_name(
    |
    [soundfiler]

  • nope, it totally doesnt work. i have even tried putting the file path directly in the pd patch. it will not load a sample from the sdcard whatever i try.

    has anyone actually got this working on android?

    im currently using the opensl brach of pdlib if that makes a difference

  • the only thing left to try now is turning the sound file into an array in java and sending that to pd. now where did i save that bit of code lol...

  • It's hard to say what's going wrong without seeing your code. What's the path to your file? Also, are you logging messages from Pd? You should always do that, and with a bit of luck a look at logcat will tell you what's going wrong.

  • I just looked at your test patch, and the message object isn't wired up correctly. The vertical bars in my message from August 14 are meant to be connections in Pd, i.e., you connect the outlet of the receive object to the inlet of the read message, and then you connect the outlet of the read message to the soundfiler object. That should take care of it.

  • i have no idea why it doesnt work. yes i know the vertical bars are connections, i tried everything with that patch, thats just the state it was in when i posted it, sorry for any confusion. the sound file is just on sdcard/test.wav. yes i have logs going on. the code i used to test is basically a copy of PdTest because i know that works. ive spent weeks and even months on and off trying to make this work. im almost ready to give up.

  • ha! i got a click, at last yay. only certain wav files will work, must be something to do with format there, but the main problem was in the patch, frequency and chunk size were throwing me. time to sort a one shot sampler patch i reckon. so... i send this to pd PdBase.sendSymbol("filename", file.getAbsolutePath()); in pd its like you said on the 14th, thank you for all the help and sorry for posting so many times on here.