Skip to content

Commit

Permalink
FLAC metadata retrieval will no longer crash program on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Nov 29, 2017
1 parent 6d23d60 commit 56164df
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 176 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "jmc/Delegate:Main Window Controller/MainWindowController.swift"
timestampString = "533607510.239328"
timestampString = "533609174.849465"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "335"
Expand Down
6 changes: 3 additions & 3 deletions jmc/Backend/Audio/FlacDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class FlacDecoder: NSObject, FileBufferer {

var decoder: FLAC__StreamDecoder?
var blockBuffer = [[Float32]]()
var sampleRate: UInt32?
var channels: UInt32?
var bitsPerSample: UInt32?
var sampleRate: UInt32!
var channels: UInt32!
var bitsPerSample: UInt32!
var totalFrames: UInt32 = 0
var file: URL
var currentBufferSampleIndex: UInt32?
Expand Down
12 changes: 6 additions & 6 deletions jmc/Backend/Database:Filesystem Management/DatabaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,17 +556,17 @@ class DatabaseManager: NSObject {

if url.pathExtension.lowercased() == "flac" {

let flacReader = FlacDecoder(file: url, audioModule: nil)
flacReader!.initForMetadata()

metadataDictionary[kSampleRateKey] = flacReader?.sampleRate
let duration_seconds = Double(flacReader!.totalFrames) / Double(flacReader!.sampleRate!)
guard let flacReader = FlacDecoder(file: url, audioModule: nil) else { return nil }
flacReader.initForMetadata()
guard flacReader.sampleRate != nil && flacReader.bitsPerSample != nil && flacReader.channels != nil else { return nil }
metadataDictionary[kSampleRateKey] = flacReader.sampleRate
let duration_seconds = Double(flacReader.totalFrames) / Double(flacReader.sampleRate!)
let bitRate = ((Double(metadataDictionary[kSizeKey] as! Int) * 8) / 1000) / duration_seconds
metadataDictionary[kBitRateKey] = bitRate
metadataDictionary[kTimeKey] = duration_seconds * 1000

//format-sensitive metadata
for item in flacReader!.metadataDictionary {
for item in flacReader.metadataDictionary {
switch item.key.lowercased() {
case "artist":
metadataDictionary[kArtistKey] = item.value
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

171 changes: 81 additions & 90 deletions jmc/Other Windows/EqualizerWindowController.xib

Large diffs are not rendered by default.

0 comments on commit 56164df

Please sign in to comment.