Loading...
Logo
Processing Forum
hudsonm4000's Profile
11 Posts
22 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi

    In Java Mode, the following code (based on Dan Shiffman's PShape tutorial) runs at about 50-54fps on my PC, but on an Android tablet (a good one), only at 7fps. I have tried a few display modes and the best seems to be P2D. Any help/thoughts as to why there is this huge performance difference?

    Many thanks
    Mark

    1. int number=500;
    2. Polygon[] polygons = new Polygon[number];    
    3. PShape rectangle; 


    4. void setup() {
    5.   size(640, 360, P2D);  // 6 to 7 fps
    6.   // size(640, 360, OPENGL);  //2 to 3 fps and it looks wierd
    7.   // size(640, 360); // PShape doesn't work 

    8.   rectangle = createShape(RECT, 10, 10, 60, 40);

    9.  //create array of rectangles
    10.   for (int i = 0; i < number; i++) {
    11.     polygons[i] = new Polygon(rectangle, random(0, width), random(10, height));
    12.   }
    13.  }

    14. void draw() {
    15.   background(51);
    16.   for (int i = 0; i < number; i++) {
    17.     polygons[i].display();
    18.   }
    19.   text(frameRate, 10, 10);
    20. }


    21. class Polygon {
    22.   PShape s;
    23.   float x, y;

    24.   Polygon(PShape s_, float _x, float _y) {
    25.     s = s_;
    26.     x=_x;
    27.     y=_y;
    28.   }
    29.   void display() {
    30.     shape(s, x, y);
    31.   }
    32. }
    Hi

    I have been using the AudioTrack class (android) to playback audio on an app I am developing and it has been great... very easy to use...I  create an array of shorts (wav data) on the fly and simply write it in a loop to an AudioTrack instance that is set to 'play'.

    I now want to do similar in Java (for PC/Mac version) but the Java SDK doesn't seen to have anything as easy to use. I know that Java uses lines etc and I have examples (complicated!) of getting a wav file (from disk), and then sending to a line for playback, but I am struggling to see how to send to my array of shorts. I know I need to send bytes and that's OK... but it's the actual raw data I am struggling to send instead of a file on disk... 

    Does anybody have a neat way to do this... maybe something that replicates the android AudioTrack class in some way, or skeleton Java code that does this that I can adapt?


    OR... can Minim do this... all I can get it to do is to play snippets or files that are pre-loaded, nothing that allows me to generate raw 16-bit audio data on the fly and use an output buffer to stream it to an output.

    Perhaps someone has done this...?

    Many thanks
    Mark

    ps an AudioTrack clone as a Processing core feature would be a great addition, even just with play/stop/close methods... dreaming...
    How can I make use of more of my available memory? I have a tablet with 1G RAM, of which in idle state, about 500MB is free/available, but I have been getting "out of memory errors" in my processing app as I exceed the device's heapSize of 48MB. I have read that this is a limit set by phones/tablets, so what do programmers do if 48MB (or whatever size is set for the phone) isn't enough? Can the heapSize be changed from within an app - my reading so far seems to suggest not, so I'm hoping someone here on this forum might know.

    I am reaching this limit as I incrementally expand an array holding 16-bit audio samples (building up drum loops). I can monitor the heap allocation  and my app crashes out when I reach the heapSize. I would like to go to ~300MB,

    Also... expand()  may be creating a memory leak.. or I may just be using it incorrectly?

    audioArray = (short[ ])  expand(audioArray, audioArray.length+offSet);


    increases the heapSize each time I call it to increase the array size, but if I reduce the array size (using a negative number for the offset variable) the array length changes correctly but there is no release of memory from the heap... it just stays where it is. Is this a memory leak?

    Hope someone can help!

    Mark

    Hi

    EDIT: Solved... also needed to create an ActivityManager. The code now shows me memory info although totalMem is still a problem... but one I can live with. 

    Anyone done any fiddling with memory management for android? I have just started but have hit a problem straight off!

    In the code below, I am simply printing the MemoryInfo fields 

    The first 3 work, but the myMemInfo.totalMem field generates an error.

    Also, any explanations as to why myMemInfo.availMem has the value zero?

    Any ideas/thoughts?
    1. import android.app.ActivityManager.MemoryInfo ;
    2. import android.app.ActivityManager;

    3. MemoryInfo myMemInfo ;
    4. ActivityManager myActivityManager ;

    5. void setup(){
    6.  myMemInfo = new MemoryInfo();
    7.  myActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    8.  myActivityManager.getMemoryInfo(myMemInfo);
    9.  println("availMem = " + myMemInfo.availMem);

    10.  println("lowMemory = " + myMemInfo.lowMemory);
    11.  println("threshold = " + myMemInfo.threshold);
    12.  println("totalMemory = " + myMemInfo.totalMem);
    13. }

    14. void draw(){
    15. }

    Cheers
    Mark


    Hi

    Can anyone tell me what a Frame is in the android audioTrack class? I want be able to set loop points & playback head position for a wav file, which I thought would have been done by by setting a sample position in a buffer/array, but the sdk says to use frames... 

    e.g.   public int setPlaybackHeadPosition (int positionInFrames)

    What is  a Frame & how do they relate to samples?

    Cheers

    Mark

    EDIT: samples IS frames... but I was accessing a byte array so my indexing was wrong. All OK now :)

    Have read lot now about Java threading but have a question about a method that seems to work that I haven't seen as an example anywhere, so is what I am doing here OK? I basically want to have a thread run just once whenever a button is clicked, and the code below does this, but is my approach of re-instantiating the thread every time the mouse is clicked OK? I assume that when run() completes the thread ends and system resources are automatically released, so re-instantiating isn't a problem? 

    |Thanks
    Mark

    1. SimpleThread thread1;
    2. Button startThread1Button, stopThread1Button ;

    3. void setup() {
    4.   size(600,400);  
    5.   startThread1Button = new Button(10,10, 60, 40, "thread1");
    6.   stopThread1Button = new Button(100,10, 60, 40, "stop1");
    7.   thread1 = new SimpleThread("thread1");
    8.  }
    9.  
    10. void draw() {  
    11.   background(255);
    12.   startThread1Button.display();
    13.   stopThread1Button.display();
    14.  }
    15.  
    16. class SimpleThread extends Thread {

    17.   boolean running;
    18.   int counter;
    19.   String threadName;

    20.   // Constructor
    21.   SimpleThread (String _threadName) {
    22.     running = false;
    23.     counter = 0;
    24.     threadName=_threadName;
    25.   }

    26.   void start () {
    27.     running = true;
    28.     println("Starting thread...");
    29.     super.start();
    30.   }

    31.   void run () {
    32.     running = true ;
    33.     while (running) {
    34.       println("Thread " + threadName + " has run " + counter + " times");
    35.       counter++;
    36.       delay(1000);
    37.     }
    38.     println("Thread is done...");  // The thread is done when we get to the end of run()
    39.     quit();
    40.   } // end run()

    41.   void quit() {
    42.     println("Quitting...");
    43.     running = false;  // ends the loop in run()
    44.   }
    45. }

    46. class Button {

    47.   //Variables

    48.   int x, y, w, h;
    49.   String label;
    50.   int colour;
    51.   boolean activeState;

    52.   //Constructor
    53.   
    54.   Button (int _x, int _y, int _w, int _h, String _l) {
    55.     x=_x;
    56.     y=_y;
    57.     w=_w;
    58.     h=_h;
    59.     label =_l;
    60.   }

    61.   //Methods

    62.   void display() {
    63.     fill(255);
    64.     rect(x, y, w, h);
    65.     fill(125);
    66.     rect(x+2, y+2, w-4, h-4);
    67.     fill(0);
    68.     textAlign(CENTER, CENTER);
    69.     text(label, x, y, w, h);
    70.   }

    71.   boolean over() {
    72.     if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    73.       return true;
    74.     }
    75.     else {
    76.       return false;
    77.     }
    78.   } //end of over() method
    79.   
    80. } //end of class Button

    81. void mousePressed() {

    82.   if (startThread1Button.over()) {
    83.      if (thread1.running == false) {
    84.        thread1 = new SimpleThread("thread1");
    85.        thread1.start();
    86.     }
    87.   }

    88.   if (stopThread1Button.over()) {
    89.     thread1.quit();
    90.   }
    91. } // end mousePressed()
    Hi all 

    A bit of help needed if possible, please. 

    I have some code where I want to be able to either overwrite a file, or first delete it and then re-write it using saveBytes. 
    I am using  (I think) standard java File code as f.exists() & f.canWrite() both work, but f.delete() doesn't.


    Any help or ideas?

    1. import java.io.*;

    2. byte[] kickFile ;  // to store a loaded wav file

    3. void setup() {

    4. // load the wav file
    5.   kickFile = loadBytes("/data/kick.wav"); 

    6. // do something to the wav file and then try to re-save  

    7. saveBytes("/data/kick.wav", kickFile ); 

    8. // this doesn't work and generates a console error... cannot write the file...


    9. // ...so try a test... and see if it can be written to and if it will delete

    10.   String fileName = dataPath("/data/kick.wav");
    11.   File f = new File(fileName);
    12.     
    13.   if (f.exists() && f.canWrite()) {     // this works, returning true for both  f.exists()  and f.canWrite()
    14.     f.delete();   // but this doesn't work... why?
    15.   }
    16. }

    17. void draw(){
    18. }
    Quick code to test mouse handling:
    1. void draw()
    2. {
    3. }
    4. void mousePressed ()
    5. {
    6. println("PRESSED x:" + mouseX + " y: " + mouseY);
    7. }
    8. void mouseReleased ()
    9. {
    10. println("RELEASED x:" + mouseX + " y: " + mouseY);
    11. }
    12. void mouseDragged ()
    13. {
    14. println("DRAGGED x:" + mouseX + " y: " + mouseY);
    15. }
    In Java Mode it works fine (using a mouse), but in Android Mode (touching screen), mouseDragged() continually updates and prints to the console if finger is held in same position... i.e not dragged anywhere. Is this a bug ... if so I will report it but if anyone can confirm first?... 

    mousePressed() and mouseReleased() seem to be OK though.

    Mark


    After some experimenting with APWidgets.....

    1. I can hide an APWidgetContainer using the hide() method, but can't see/find a way to hide just one widget.  I guess I could just have separate containers for each widget... but is there away to hide individual widgets in a container?
    2. Rotating my tablet from landscape to portrait causes the APWidgetContainer.hide() function to 'undo'.  Is there a way to prevent this so the so the widgets stay hidden?
    Has anybody else found this and have ideas/solutions?

    Many thanks
    Mark
    Hi
    Been making good use of this forum for  a few months now and have found loads of useful info on all sorts, and also to some extent to help me with saving files on android... but now I'm stuck.

    On a PC it seemed very easy to use createOutput() to get a file path string and then use this with saveString() to write a txt file any where I want to, but on Android createOutput() doesn't work so I am assuming I need to specify a path.


    After reading here and elsewhere I hoped the solution(s) would be:


    String[] myarray = {"one", "two", "three","four"}; //  the array to be saved

    saveStrings("\\sdcard\\myarray.txt", myarray);  // save to SD card

    OR

    saveStrings("\\sdcard\\documents\myarray.txt", myarray);  // to save to the 'documents' folder already on the SD card

    OR

    saveStrings("\\sdcard\\newfolder\myarray.txt", myarray); // to create 'newfolder' and put 'myarray' in it


    But it doesn't work, so I'm after help from someone who knows :)

    hopefully()
    Mark



    Hi

    Just trying to get a working development setup for Android, and have some success using an emulator (after reading various help topics here first.. many thanks, as without this forum I would have given up by now!), but with my HTC Wildfire I am getting errors. Processing is seeing it as a device but the console is reporting errors...

    Received unfamiliar output from “adb devices”.
    The device list may have errors.
    Output was “adb server is out of date.  killing...
    * daemon started successfully *
    List of devices attached 
    HT09APY08572 device

    error:
    nope: adb devices
        status: 1
        2175ms
        stdout:
    adb server is out of date.  killing...
        stderr:
    ADB server didn't ACK
    * failed to start daemon *


    Anybody else use an HTC Wildfire, or any other device with similar errors.... and who knows a fix  :)

    Mark