Giter Site home page Giter Site logo

Comments (5)

sbooth avatar sbooth commented on June 12, 2024

Could you show the definition of decodedBuffer?

from sfbaudioengine.

BTRLabs avatar BTRLabs commented on June 12, 2024

Sorry... both of these produce the same results and both should be big enough to hold the frames remaining:

//--- buffer is 1x the expected frames (i.e., equal in size)
let decodedBuffer = AVAudioPCMBuffer(pcmFormat: decoder.processingFormat, 
                    frameCapacity: AVAudioFrameCount(decoder.processingFormat.sampleRate * durationOfChunkToRead))!

or

//--- buffer is 2x the expected frames
let decodedBuffer = AVAudioPCMBuffer(pcmFormat: decoder.processingFormat, 
                    frameCapacity: AVAudioFrameCount(2 * decoder.processingFormat.sampleRate * durationOfChunkToRead))!

as in...

do {
  let decoder = try AudioDecoder(url: URL("file.flac"))
  try decoder.open()
  let frameCapacityForOneSecond = AVAudioFrameCount(decoder.processingFormat.sampleRate)
  let decodedBuffer = AVAudioPCMBuffer(pcmFormat: decoder.processingFormat, frameCapacity: frameCapacityForOneSecond)!
  try decoder.seek(to: decoder.length - AVAudioFramePosition(frameCapacityForOneSecond))
  try decoder.decode(into: decodedBuffer)
  if decoder.inputSource.atEOF && decoder.position < decoder.length {
    print("WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by \(decoder.length - decoder.position) frames - decodedBuffer.frameLength is \(decodedBuffer.frameLength) instead of \(frameCapacityForOneSecond) off by \(frameCapacityForOneSecond - decodedBuffer.frameLength) frames")
  }
} catch {
  print(error.localizedDescription)
}

produces the following for an album

WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 2992 frames - decodedBuffer.frameLength is 41108 instead of 44100 off by 2992 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 3968 frames - decodedBuffer.frameLength is 40132 instead of 44100 off by 3968 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 3764 frames - decodedBuffer.frameLength is 40336 instead of 44100 off by 3764 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 4096 frames - decodedBuffer.frameLength is 40004 instead of 44100 off by 4096 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 1844 frames - decodedBuffer.frameLength is 42256 instead of 44100 off by 1844 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 3012 frames - decodedBuffer.frameLength is 41088 instead of 44100 off by 3012 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 2472 frames - decodedBuffer.frameLength is 41628 instead of 44100 off by 2472 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 3080 frames - decodedBuffer.frameLength is 41020 instead of 44100 off by 3080 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 2440 frames - decodedBuffer.frameLength is 41660 instead of 44100 off by 2440 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 740 frames - decodedBuffer.frameLength is 43360 instead of 44100 off by 740 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 3100 frames - decodedBuffer.frameLength is 41000 instead of 44100 off by 3100 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 512 frames - decodedBuffer.frameLength is 43588 instead of 44100 off by 512 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 2564 frames - decodedBuffer.frameLength is 41536 instead of 44100 off by 2564 frames
WARNING - inputSource.atEOF is TRUE while decoder.position < decoder.length, off by 268 frames - decodedBuffer.frameLength is 43832 instead of 44100 off by 268 frames

from sfbaudioengine.

sbooth avatar sbooth commented on June 12, 2024

Could you check out the proposed fix in #252 and see if it works for you?

from sfbaudioengine.

BTRLabs avatar BTRLabs commented on June 12, 2024

Yes, #252 in conjunction with using libFLAC 1.4.2 fixed the issue. Amazing turnaround. Thanks!

from sfbaudioengine.

sbooth avatar sbooth commented on June 12, 2024

I'm glad it's working now. Thanks for reporting this issue!

from sfbaudioengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.