Menu

#1 FLACFileWriter

pending
nobody
None
5
2011-09-24
2011-09-23
No

Proposed integration with javax sound SPI (AudioFileWriter). Somehow it is working, should be reviewed.

Discussion

  • Peter Krútel

    Peter Krútel - 2011-09-23
     
  • Preston Lacey

    Preston Lacey - 2011-09-24
    • status: open --> pending
     
  • Preston Lacey

    Preston Lacey - 2011-09-24

    Integrated FLACFileWriter SPI class into library.

     
  • Preston Lacey

    Preston Lacey - 2011-09-24

    I've looked through the file and integrated it with the library. I changed a couple IOExceptions to IllegalArgumentException(which better matches what the SPI library expects, according to the documentation). I moved some of the code that was common between FLACFileWriter and FLAC_FileEncoder into a new class, and improved the detection of format-support(testing more than just the sample-size now, as well as moving the test into the getAudioFileTypes(AudioInputStream) method ). I also finished out the implementation by adding support for OutputStream. You can check out the result so far in the attached file, which has the sources and spi-enabled jar file(there are other, unrelated changes in this file as well, but they shouldn't affect anything if you're depending only on SPI support). This release should be more stable(including fixed 24 bit encoding), but I want to do more testing and finish the documentation before I post it as a normal file-release.

     
  • Peter Krútel

    Peter Krútel - 2011-09-26

    FLACOutputStream interface -> add method
    public void close() throws IOException;

    Looks there is bug in AudioStreamEncoder.getDataFormatSupport(AudioFormat format)

    We have following stream:
    PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

    but, result is 0. WAV test file attached

    Attached is new proposal for FLACFileWriter.java

     
  • Peter Krútel

    Peter Krútel - 2011-09-26

    Comments on FLACFileWriter library integration

     
  • Peter Krútel

    Peter Krútel - 2011-09-26

    Test WAV file is not attached (tracker allows only files < 256k)

     
  • Preston Lacey

    Preston Lacey - 2011-09-26

    Based on the comments, that doesn't appear to be a bug. The Format is supported, so the method returns 0. That method sets flags for each part of the Format that is unsupported. So Let's say the Channel Count(bit zero), and sample size(bit 1) were unsupported, the return would equal 3. If you just need to know if it is supported, you test if(returnVal == 0); if you need to know specifically what failed, you can test using a bit shift and mask for each flag.

    I'm not sure I want to add the close() method to the FLACOutputStream interface. The FLACEncoder never opens or closes the destination itself. That interface simply allows a common api for writing and seeking, things that are necessary for the encoder to work right. I would like to avoid adding requirements to that interface when they won't actually be used by the FLACEncoder. Also, It is possible to implement that interface in a way that can't be truly "closed". You then have to have a "canClose()" method declared in the interface and throw a runtime exception if someone tries to close anyways(like how the canSeek() method works), or you'd have to take measures to "fake" a closed stream. However, I will consider implementing the java.io.Closable interface on FLACFileOuputStream and FLACStreamOutputStream instead, as this seems appropriate and avoids the above problems.

    As for the suggestions made in FLACFileWriter.java, I think they're good, and so might at some point move more of the common code and common tasks into AudioStreamEncoder; but I will be keeping the methods currently declared(so a new method that lacks FLACEncoder as a parameter would simply make it's own flac encoder, handle the setup, and call the existing method). I'm not in a hurry to do this though, and want to think more thoroughly about it first because I don't want to build too much around the AudioInputStream class for core encoder functionality. I use that class to read input files in the FLAC_FileEncoder, and we use it again of course in the SPI code. But that doesn't mean all sources would be an AudioInputStream. A new, simple source interface might be best, so we can target the specific requirements of flac encoding.

     
  • Preston Lacey

    Preston Lacey - 2011-09-26

    Oh, I see the bug you are talking about. It's actually in FLACFileWriter.getAudioFileTypes(AudioInputStream);
    I'm testing != 0, should be testing == 0...I'll fix it and post an updated jar file.

     
  • Peter Krútel

    Peter Krútel - 2011-09-26

    Hi,

    all comments were suggestions, it is up to you, what you do with them :-)

    As for the bug, bug is then in FLACFileWriter.java, method getAudioFileTypes(AudioInputStream stream)

    Is:
    if(AudioStreamEncoder.getDataFormatSupport(format) != 0 ) {
    return filetypes;
    }

    Shoud be:
    if(AudioStreamEncoder.getDataFormatSupport(format) == 0 ) {
    // Audio input stream supported
    return filetypes;
    }

    Can you please fix it and provide new candidate? (javaFlacEncoder-spi.tar.gz)

     
  • Preston Lacey

    Preston Lacey - 2011-09-26

    Fixed bug in FLACFileWriter.getAudioFileTypes(AudioInputStream)

     
  • Peter Krútel

    Peter Krútel - 2011-09-30

    FLAC -> WAV -> FLAC , exception in play

     
  • Preston Lacey

    Preston Lacey - 2011-10-01

    added padding to work around bug in JFlac

     

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.