Swift EXC_BREAKPOINT upon receipt of CMAudioFormatDescription

I am trying to restore the sampling rate and the number of channels from an audio file. I received at runtime "EXC_BREAKPOINT (code = EXC_ARM_BREAKPOINT)" error on this line:

let audioFormstDesc = descriptions[0] as CMAudioFormatDescription

This is the simplest version of the code used:

import AVFoundation
import CoreMedia
import MediaPlayer

class ViewController: UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()

        let query = MPMediaQuery.songsQuery()
        let song = query.items[0] as MPMediaItem
        let url = song.valueForProperty(MPMediaItemPropertyAssetURL) as NSURL
        let songAsset = AVURLAsset.URLAssetWithURL(url, options: nil)
        let trackAsset = songAsset.tracks[0] as AVAssetTrack
        if let descriptions = trackAsset.formatDescriptions
        {
            let audioFormstDesc = descriptions[0] as CMAudioFormatDescription
            let streamBasicDescription = CMAudioFormatDescriptionGetStreamBasicDescription(audioFormstDesc)
        }
    }
}

In Objective-C, this code works correctly:

MPMediaQuery *query = [MPMediaQuery songsQuery];
MPMediaItem *song = [[query items] objectAtIndex:0];
NSURL *url = [song valueForProperty: MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetTrack *trackAsset = songAsset.tracks[0];

UInt32 sampleRate = 0, channelCount = 0;
NSArray* descriptions = trackAsset.formatDescriptions;
CMAudioFormatDescriptionRef audioFormstDesc = (__bridge CMAudioFormatDescriptionRef)descriptions[0];
const AudioStreamBasicDescription* audioStreamDesc = CMAudioFormatDescriptionGetStreamBasicDescription(audioFormstDesc);
if(audioStreamDesc)
{
    sampleRate = audioStreamDesc->mSampleRate;
    channelCount = audioStreamDesc->mChannelsPerFrame;
}

println(descriptions[0]) displayed on the console:

<CMAudioFormatDescription 0x15d3b690 [0x387e5ad0]>

How to deal with this error?

+4
source share
1 answer

In Swift and xcode 6 beta, this error appears sometimes if you compile the "fast optimization level" -O (Fastest). Try setting the optimization level to -One in "Build Settings".

-1
source

All Articles