Menu

encodeSamples() raises null exception

Help
Chan Lee
2012-05-08
2013-05-30
  • Chan Lee

    Chan Lee - 2012-05-08

    Wonder if anyone encountered 'null' exception out of 'encodeSamples()' method.
    I think I must miss something in rush - will appreciate if someone can review this:

      public void encode2FLAC (int rawAudio, File flacFile) {
        FLACEncoder flacEncoder = new FLACEncoder();
        EncodingConfiguration eConf = new EncodingConfiguration();
        StreamConfiguration sConf = new StreamConfiguration(1, 100, 1000, 16000, 16);
        FLACFileOutputStream flacOutput = new FLACFileOutputStream(flacFile);

        flacEncoder.setStreamConfiguration(sConf);
        flacEncoder.setEncodingConfiguration(eConf);
        flacEncoder.setOutputStream(flacOutput);

        try {
          flacEncoder.openFLACStream();
        } catch (Exception e) {
          Log.e(getClass().getName(), ".encode2Flac(): can't open FLAC output:" + e.getMessage());
        }

        int bufSize = 500;
        int offset, encoded, blkIndex = 0;
        int buf =  new int;
        int toEncode = rawAudio.length;
        Log.d(getClass().getName(), ".encode2Flac():Encode raw data=" + toEncode);

        while (toEncode >= bufSize) {
          offset = blkIndex * bufSize;
          Log.d(getClass().getName(), ".encode2Flac():blkIndex=" + blkIndex +", offset=" + offset);
          for (int i=0; i<bufSize; i++) {
            buf_ = rawAudio;
          }
          blkIndex++;
          toEncode -= bufSize;
          if (!flacEncoder.addSamples(buf, bufSize)) {
            Log.d(getClass().getName(), ".encode2Flac():Can't add samples");
          }
          encoded = 0;
          try {
            if (toEncode > 0) {
              encoded = flacEncoder.encodeSamples(bufSize, false);
            }
            else {
              encoded = flacEncoder.encodeSamples(bufSize, true);
            }
          } catch (Exception e) {
            Log.e(getClass().getName(), ".encode2Flac(): can't encode 500. Err:" + e.getMessage());
          }
          Log.d(getClass().getName(), ".encode2Flac(): encoded(500 expected)=" + encoded);
        }

    The null exception was reported from the above Log message._

     
  • Preston Lacey

    Preston Lacey - 2012-05-08

    greetings clsf,
       Could you post more of the message, as well as tell me which version you're using? That might help me figure out what's going on. I don't see anything in your code that should be causing that, and haven't seen that issue myself yet.
    On a side note, it does appear that your loop may leave samples unencoded, if the original toEncode is not a multiple of bufSize(unless of course you're handling this case in code not posted).

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.