2 Replies Latest reply: Nov 8, 2010 1:39 PM by captfoss RSS

    Mic Sampling - Smallest Sample size?

    806103
      I presumed if I use line.read(), it will return as soon as it reads the number of bytes requested, however I'm finding that it won't return until a much larger sample has been taken.

      I initialize AudioFormat: (rate = 44100)
      return new AudioFormat(rate, 16, 1, true, false);

      I run this in a full-out loop:
      int available = line.available();
      System.out.println(line.available());
      int read = line.read(tmp, 0, 916);

      What I see is that line.available will reach some number around 10k and then actually start returning samples, here's a typical output:
      11016
      10100
      9184
      8268
      7352
      6436
      5520
      4604
      3688
      2772
      1856
      940
      24
      (notice it decreases by 916 each time, as if no new samples are coming in)

      Its apparently waiting until it has a certain number of samples and then "releasing" them to the line.read() method. Doing some testing, apparently if I wait until .available() >= 2756, I can actually obtain just that number of samples. I see that 2756 is 44.1k / 16. HOWEVER, if I put 2756 in the .read() line above, it still waits until it gets to about 10k samples before "releasing" the data, it only works if I test the .available() for having 2756 bytes.

      I'm trying to do close to real-time data analysis, but if it waits to release the samples, I have to wait too, I'd really like to get to 916 sample frame (of the most recent data of course). Is this the API, my hardware, or is there a better way/API? Funny because on Android this is not a problem at all, it notifies me at the rate I choose.

      Help!,
      J