core-audio

AudioUnitRender error -50 with odd length buffers

ⅰ亾dé卋堺 提交于 2020-01-05 03:29:08
问题 I have a RemoteIO unit configured with AVAudioSessionCategoryPlayAndRecord. I find some strange behavior in it. I open the app, and immediately close it before audioUnit initializes fully (it actually initializes in background as I quit the app too soon). Next I bring the app to foreground and immediately on relaunch, I see AudioUnitRender failing with error -50 continuously. I find inNumberFrames to be 1115 and it fails whenever this number is odd. func recordingCallback(inRefCon

AVAssetReader reads audio, then fails

流过昼夜 提交于 2020-01-05 00:52:29
问题 My app reads audio and plays it back in a producer / consumer setup. The consumer thread requests new samples to render to hardware. The producer thread reads audio data from disk into its buffer using AVAssetReader. The producer thread runs in a loop, checking if more samples need to be read. The producer's buffer size is equal to 4 seconds of audio. When I instruct my app to buffer audio, samples are read successfully without error. When I trigger my producer thread to begin rendering audio

Swift and Boolean

孤街浪徒 提交于 2020-01-04 15:28:41
问题 The function AUGraphIsInitialized is defined like this: func AUGraphIsInitialized(inGraph: AUGraph, outIsInitialized: CMutablePointer<Boolean>) -> OSStatus So, you call it like this: var status : OSStatus = OSStatus(noErr) var outIsInitialized:Boolean = 0 status = AUGraphIsInitialized(self.processingGraph, &outIsInitialized) That works. But how do you check it? Boolean is defined as an CUnsignedChar (in MacTypes.h) So, you cannot do this: if outIsInitialized { // whatever } And you cannot

Swift 3 - Pass struct by reference via UnsafeMutableRawPointer?

孤人 提交于 2020-01-04 07:51:49
问题 In the Core Audio -Framework user data can be passed into callbacks via an UnsafeMutableRawPointer? . I was wondering how to pass a struct by reference via this UnsafeMutableRawPointer? . Changes made inside the callback should be reflected outside the callback. I set up a playground to test this: struct TestStruct { var prop1: UInt32 var prop2: Float64 var prop3: Bool } func printTestStruct(prefix: String, data: TestStruct) { print("\(prefix): prop1: \(data.prop1), prop2: \(data.prop2),

Swift 3 - Pass struct by reference via UnsafeMutableRawPointer?

房东的猫 提交于 2020-01-04 07:51:02
问题 In the Core Audio -Framework user data can be passed into callbacks via an UnsafeMutableRawPointer? . I was wondering how to pass a struct by reference via this UnsafeMutableRawPointer? . Changes made inside the callback should be reflected outside the callback. I set up a playground to test this: struct TestStruct { var prop1: UInt32 var prop2: Float64 var prop3: Bool } func printTestStruct(prefix: String, data: TestStruct) { print("\(prefix): prop1: \(data.prop1), prop2: \(data.prop2),

Programmatically Create Aggregate Audio Devices In Swift Using CoreAudio

南楼画角 提交于 2020-01-03 18:37:19
问题 I am researching creating multi-output devices on either OS X or iOS, and I found out that CoreAudio would allow you to create aggregate devices. My first question is, does iOS allow you to do this. I know that this is certainly possible on OS X, but I've heard that iOS will not allow it. I would really appreciate an example of how you would go about detecting multiple audio output devices and creating an aggregate device, all using swift. I have checked here, but it doesn't fully answer my

Setting up audio unit iOS with mono input and stereo output

北战南征 提交于 2020-01-03 13:22:29
问题 I'm trying to set up an audio unit capable of mono input and stereo output. Intend on playing a sine wave tone through the left channel output and a different sign wave periodically through the right channel out. I am receiving the error, 'NSInternalInconsistencyException', reason: ' Error initialing unit: -50; when I attempt to initialize my audio unit here, // Initialize audio unit OSErr err = AudioUnitInitialize(self.ioUnit); NSAssert1(err == noErr, @"Error initializing unit: %hd", err); I

Which built in AudioUnit can resample audio?

守給你的承諾、 提交于 2020-01-03 04:45:08
问题 I have an application that will need to rapidly change the sample rate of audio. The pitch shift caused by doing simple linear interpolation of the samples is totally fine. Is there an audio unit that resamples in software in real time (ie: does not need to change the hardware sample rate). 回答1: Yes, Apple's AU kAudioUnitType_FormatConverter , kAudioUnitSubType_AUConverter can do this. Internally the AU contains a FormatConverter that performs the work. 来源: https://stackoverflow.com/questions

Delta calculation between MIDIPackets do not seem to be right

こ雲淡風輕ζ 提交于 2020-01-03 04:03:41
问题 I am trying to read a midi file, and play all the midi events with a synthesizer. The way the synth works is, it has a circular buffer which you write midi data to, and then call GenerateSamples() on it, and it will process that midi data, and give you back the number of samples you want. I'm using AudioToolbox's music player, and have setup a MidiReadProc where I write those midi packets to a buffer, and then have a separate thread polling that buffer, and writing the data to the ring buffer

Audio Session: Using measurement mode causes low volume / no sound in iOS 7.1

僤鯓⒐⒋嵵緔 提交于 2020-01-02 03:01:10
问题 Using AVAudioSessionModeMeasurement with AVAudioSessionCategoryPlayAndRecord used to work fine under iOS 5.x, 6.x, and 7.0, but it now results in low volume / no sound from the speaker on some (not all) devices under iOS 7.1. Here's the code: NSError* error = nil; // Set Aduio Session category [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&error]; if( error ) ... // Set Audio Session mode [audioSession setMode