3

I need to split flac file to many pieces. I am using jFLAC library to read flac files

FLACDecoder decoder = new FLACDecoder(inputStream);

then I am trying to decode parent file between to SeekPoints

decoder.decode(seekPointFrom, seekPointTo);

I also don't quite understand how properly to get this seekpoints for seconds value. For example I need first seekpoint from 0 seconds and second to 150 seconds. How to get right seek points objects? Seekpoint cinstructor is

/**
 * The constructor.
 * @param sampleNumber  The sample number of the target frame
 * @param streamOffset  The offset, in bytes, of the target frame with respect to beginning of the first frame
 * @param frameSamples  The number of samples in the target frame
 */
public SeekPoint(long sampleNumber, long streamOffset, int frameSamples) {
    this.sampleNumber = sampleNumber;
    this.streamOffset = streamOffset;
    this.frameSamples = frameSamples;
}

also decoder have some listener that listen every read chunk action.

 @Override
    public void processPCM(ByteData pcm) {
        try {
            outputStream.write(pcm.getData(), 0, pcm.getLen());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

When writing is done I am tying to play new flac file but my player alerts that file incorrect. What I need to do that my flac files will open right? Maybe I need to write some header to this file or something else?

Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78

1 Answers1

0

In regards to the FLAC SeekPoints, there is no guarantee that there will be one that corresponds to a given second - there might only be a few SeekPoints in the entire audio file.

As such, I recently updated jFLAC with a seek function to get you to at least the closest audio frame: https://github.com/nguillaumin/jflac/commit/585940af97157eb11b60c15cc8cb13ef3fc27ce3

In regards to writing out a new file, the decoded data will be in raw PCM samples. So you will need to pipe it into a FLAC encoder if you want a valid FLAC file as the output. Alternately you could write out a Wave header and dump the raw PCM samples, then convert that resultant Wave file into a FLAC file.

alexdw
  • 68
  • 7