Post

Replies

Boosts

Views

Activity

If not AVMIDIRecorder, then what?
For AVAudioPlayer, there is corresponding AVAudioRecorder. For AVMIDIPLayer, I found nothing for recording from the system's active MIDI input device. Can I record midi events from the system’s active input midi device, without resolving to low level CoreMidi? After configuring AVAudioUnitSampler with just a few lines of code, import AVFoundation var engine = AVAudioEngine() let unit = AVAudioUnitSampler() engine.attach(unit) engine.connect(unit, to: engine.outputNode, format: engine.outputNode.outputFormat (forBus:0)) try! unit.loadInstrument(at:sndurl) //url to .sf2 file try! engine.start() I could send midi events programmatically. // feeding AVAudioUnitMIDIInstrument with midi data let range = (0..<100) let midiStart = range.map { _ in UInt8.random(in: 70...90) } let midiStop = [0] + midiStart let times = range.map { _ in TimeInterval.random(in: 0...100) * 0.3 } for i in range {     DispatchQueue.main.asyncAfter(deadline: .now()+TimeInterval(times[i])){         unit.stopNote(midiStop[i], onChannel: 1)         unit.startNote(midiStart[i], withVelocity: 127, onChannel: 1)     } } But instead, I need to send midi events from a midi instrument, and tap to them for recording.
1
0
1.3k
Dec ’22
For OSStatus, how to get a string explaining its meaning?
SecCopyErrorMessageString returns a string explaining the meaning of a security result code and its declaration is func SecCopyErrorMessageString( _ status: OSStatus, _ reserved: UnsafeMutableRawPointer? ) -> CFString? with typealias OSStatus = Int32 Having arbitrary OSStatus (for example for kAudioFormatUnsupportedDataFormatError it is 1718449215), is there something to get the description as string? The idea would be analogous to: let x: Int32 = 1718449215 if let errMsg = SecCopyErrorMessageString(x, nil) as? String{     print(errMsg) } This is not a security result code, and the output is just OSStatus 1718449215, what I expect is a "string explaining the meaning".
1
0
4.3k
Dec ’22
Optimising initialisation of big arrays with random data
I will be filling audio and video buffers with randomly distributed data for each frame in real time. Initializing these arrays with Floats inside basic for loop somehow seems naive. Are there any optimised methods for this task in iOS libraries? I was looking for data-science oriented framework from Apple, did not found one, but maybe Accelerate, Metal, or CoreML are good candidates to research? Is my thinking correct, and if so, can you guide me?
1
0
1.4k
Dec ’22
Background uploads with short-lived authorisation tokens.
Let’s say I have a hundred of big files to upload to a server, using requests with a short-lived authorisation token. NSURLSession background upload describes a problem with adding too many requests, so the first question is: should we manage uploads manually, by which I mean queuing, postponing, retrying. Will we then fall into the same traps only in a different way? What to do if tasks picked by the system have outdated token, and so fail. How to update a token: is there a delegate method (preferable pre iOS 13 compatibile) in which I can get a fresh token and modify a request header? Is there any iOS specific design pattern or contract (Apple's list of server requirements) that would allow uploads to be resumable?
1
0
1.3k
Dec ’22
WWDC example of signal generator outputs files with 0 duration
Using the example from WWDC, with the following command ./SignalGenerator -signal square -duration 3 -output ./uncompressed.wav I can generate an audio file, which is not playable, and its Get Info is: Duration: 00:00 Audio channels: Mono Sample rate: 44,1 kHz Bits per sample: 32 Although for MacOS Preview the duration is zero, this file is playable in VLC and convertible to other formats, so its content is ok. To get more information about the format of an output file I changed the example to print outputFormatSettings: ["AVLinearPCMBitDepthKey": 32, "AVLinearPCMIsBigEndianKey": 0, "AVSampleRateKey": 44100, "AVFormatIDKey": 1819304813, "AVLinearPCMIsFloatKey": 1, "AVNumberOfChannelsKey": 1, "AVLinearPCMIsNonInterleaved": 1] I don’t know how to interpret the “number of AVFormatIDKey": 1819304813. The documentation says: let AVFormatIDKey: String - For information about the possible values for this key, see Audio Format Identifiers Having red this, I still don't know the relation of AVFormatIDKey and listed Audio Format Identifiers. If I knew which file format to expect, it might have helped to guess why the duration of the generated files is always 0? Can you help me with both questions? Thanks.
2
0
1.3k
Dec ’22
Why repeating protocol conformance in a subclass is considered redundant?
Repeating protocol conformance in a subclass of conforming class results in a redundancy error. My problem is that, because of how protocol witness tables work, repeating protocol conformance in a subclass seems not to be redundant at all . Intuitively, in the Example3 below repeating a conformance of the parent class in the child class could restore the route from protocol extension's implementation back to child's implementation . Where am I wrong? protocol Prot { func f() func g() } extension Prot { func f(){ print("protocol extension's implementation") } func g(){ f() } } class Parent: Prot { } //Directly implementing protocol would route to a child's implementation. class Example1: Prot { func f(){ print("child's implementation")} } //Indirectly implementing protocol would route to a protocol extension's implementation. class Example2: Parent { func f(){ print("child's implementation")} } //Redundant conformance of 'Child' to protocol 'Prot' error, instead of restoring route to a child's implementation. class Example3: Parent, Prot { func f(){ print("child's implementation")} } Example1().g() Example2().g()
5
0
1.9k
Dec ’22