martincameron / micromod

Music player libraries for MOD, S3M and XM formats.
BSD 3-Clause "New" or "Revised" License
159 stars 28 forks source link

Unable to stream via OpenAL #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
WavInputStream doesn't override the default available() method, which always 
returns 0. However OpenAL (see jogamp.org) uses this method, thus is unable to 
play anything.

How to solve: add this in WavInputStream:
  public int available() {
    return getBytesRemaining();
  }

How to reproduce:
    //init openAL
    ALut.alutInit();
    al = ALFactory.getAL();
    al.alGetError();

    //open module
    Module module = <load your module here>

    try {
      ibxm = new IBXM(module, 44100);
      WavInputStream wis = new WavInputStream(ibxm);

      // Load the wav data.
      al.alGenBuffers(1, buffer, 0);
      if (al.alGetError() != ALConstants.AL_NO_ERROR) {
        throw new ALException("Error generating OpenAL buffers");
      }

      int[] format = new int[1];
      ByteBuffer[] data = new ByteBuffer[1];
      int[] size = new int[1];
      int[] freq = new int[1];
      int[] loop = new int[1];
      ALut.alutLoadWAVFile(wis, format, data, size, freq, loop);

      if (data[0] == null) {
        throw new ALException("Error loading WAV file");
      }
      al.alBufferData(buffer[0], format[0], data[0], size[0], freq[0]);

      // Bind buffer with a source.
      al.alGenSources(1, source, 0);

      if (al.alGetError() != ALConstants.AL_NO_ERROR) {
        throw new ALException("Error generating OpenAL source");
      }

      al.alSourcei(source[0], ALConstants.AL_BUFFER, buffer[0]);
      al.alSourcei(source[0], ALConstants.AL_LOOPING, loop[0]);

      // Do another error check
      if (al.alGetError() != ALConstants.AL_NO_ERROR) {
        throw new ALException("Error setting up OpenAL source");
      }
    }
    catch (ALException e) {
      e.printStackTrace();
      return false;
    }

    al.alSourcePlay(source[0]);

Original issue reported on code.google.com by fabm...@gmail.com on 3 Jun 2012 at 2:15

GoogleCodeExporter commented 9 years ago
Fix checked in, but a slightly different implementation that is closer to the 
contract for InputStream.available().

Thanks, and sorry about the late reply!

Original comment by mum...@gmail.com on 13 Dec 2012 at 6:35

GoogleCodeExporter commented 9 years ago

Original comment by mum...@gmail.com on 15 May 2013 at 8:13