What is the difference between AudioFileOpenURL and ExtAudioFileOpenURL? - ios

If I use ExtAudioFile in conjunction with a remoteIO audio unit, I can use ExtAudioFileSetProperty with kExtAudioFileProperty_ClientDataFormat to convert the audio format read from disk into a device native format (with canonical au tags).
It seems when I use AudioFileOpenURL and related methods I can't use AudioFileSetProperty with kAudioFilePropertyDataFormat in the same way.
Why can't I convert any audio file to the client data format through this slightly higher level api?

The AudioFile API came first, and is the lower-level of the two. ExtAudioFile is essentially a wrapper around an AudioFile and an associated AudioConverter. It is ExtAudioFile's internal AudioConverter that provides the functionality to convert to a specific client format.

Related

Using the Media Streams API to stop a stream by name

In the Twilio documentation for the REST API for Media Streams, it says the Media Stream can be stopped with a name, but I can't quite figure out how or am I reading to much into the documentation.
Is it possible that the documentation is only relevant when using TwiML to stop the Media Stream and not the API and thus you have have use the Media Stream SID for the API?
<Stop>
<Stream name="my_first_stream" />
</Stop>
The example code in the docs is using the Media Steam SID only:
Stop Media Stream - Example in docs:
client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.streams('MZXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.update({status: 'stopped'})
.then(stream => console.log(stream.name));
Works the same for interacting with Conference resource friendly names; use the resource URL; e.g.
https://api.twilio.com/2010-04-01/Accounts/{{account_sid}}/Calls/{{call_sid}}/Streams/{{stream_name}}.json
Where {{stream_name}} is the, well, stream name.
I am sure I have seen other APIs that allow you to specify a name or a SID when referring to the resource but I cannot find an example (so maybe I'm wrong).
This is a bit ambiguous here though. But, comments in the Node library suggest you can use a name or sid when constructing a stream:
#param {sid_like} sid - The SID of the Stream resource, or the `name`
And since those comments are derived from the API definitions, I believe that you can use the name in a REST API call too.

Is it possible to pass a String to an AUAudioUnit as a parameter

I am currently working on a AUAudioUnit (AUv3) which requires to load a file located in the Host app's bundle.
This would need to pass the file path (ie: string value) to the Audio Unit as parameter, but I couldn't see how to do this with AUParameter since it seems to only supports Float values (AUValue).
Does anyone know if it's possible ? and how ?
Thanks a lot !
For basic of working with audio engine start with WWDC videos like wwdc 502
For sample code, you can find it here at shlab
An AUParameterGroups allows one to pass multiple parameters. And one can encode pretty much anything in a large enough array of values. A C string is just an array of bits.

charachter encoding in PHP Extension

I'm currently writing a PHP extension in C++ with the Zend API. Basically I make PHP_METHOD{..} wrappers around my native C++ interface methods and using "zend_parse_parameters(..)" to fetch the corresponding input arguments.
This extension contains methods which can take strings as arguments, such as a filename.
I know from http://php.net/manual/en/language.types.string.php#language.types.string.details that strings have no encoding in PHP, but still can I expect from the PHP programmer that he will use a function like "utf8_decode(..)" such that the input strings can be read by the extension correctly?
Or does the PHP Programmer expect that the extension detects the encoding from the php-script and handles strings accordingly?
Every help is highly appreciated! Thanks!
You are correct. Strings are just binary blobs in PHP. As the author of an extension. Your options:
Have the user hand your extension UTF-8: By far the best option. The user has to make the decision. Assert that the string is UTF-8 encodable and fail early.
Encode yourself: You cannot know the meaning of the string. As PHP strings are just binary blobs and have no encoding information you do not know what the intended string content is. It might as well just come from a Windows file with weird encoding and was concatenated with a complete different encoding. Worse, it might be UTF-8 encodable, but actually not UTF-8, in which way you interpret it wrongly, without the user knowing. Hence, solution 1, have the user pass UTF-8.
Alternative: Force the user to pass an input encoding.
Here is an example of the alterantive 3:
$obj = MyExtensionClass('UTF-8'); // force encoding
$obj->someMethod($inputStr); // try to convert now
The standard library uses approach 1. See json_encode as an example:

libvlc: Is there a method to get data buffer before decoding?

I want to parse mpeg user data and use it for specific purpose.
I've successufully have been able to get decoded frames from libvlc,
using libvlc_video_set_callbacks(). But it is pixel data after "decoding".
I want to get data before decoding, i.e., an encoded data buffer.
Is there an API in libvlc?
Thanks.
No, there is no API in libvlc to get access to the raw buffers it reads from input media. Patch welcome!

How to read binary QR Code with AVFoundation?

Is it possible to read a binary encoded QR Code with AVFoundation?
I can get a AVMetadataMachineReadableCodeObject object of .type AVMetadataObjectTypeQRCode, however this only has a stringValue property, which won't work, because the data contained in the QR Code can't be converted to a string friendly representation.
Should I use ZXing instead?
Thanks.
The raw data does exist in your AVMetadataMachineReadableCodeObject, but it's not available through a public getter.
However, you can use KVO to extract it, but Apple might reject your app. Also, future iOS versions might change their private APIs and your code could become invalid (because of the hardcoded private keys).
Swift:
readableCodeObject.valueForKeyPath("_internal.basicDescriptor")!["BarcodeRawData"]
Objective-C
[readableCodeObject valueForKeyPath:#"_internal.basicDescriptor"][#"BarcodeRawData"];
I tested this for iOS 8 and 9.
I was able to solve this issue by Base64 encoding the data in the QR code.
This obviously won't work if you're not also generating the QR codes but could be option for people that are.
We were running into the upper limit of data that can be stored in a QR code but by compressing the data (we used zlib) and then Base64 encoding the compressed data, so long as your data compresses to less than 75% of its original size you get some additional capacity and can use the stringValue property to get your data back out, you just have to Base64 decode and then decompress to get the original data back.
Even if you're starting with binary data that isn't very compressible, so long as you can handle the overhead of Base64 and still be within the limitations of QR codes this may be a viable option that avoids working around the fact that AVMetadataMachineReadableCodeObject seems to want to work with string values.
You can use a CIDetector to get to a CIQRCodeFeature which has a symbolDescriptor which has a errorCorrectedPayload which contains the data.
Only problem is that this data still includes QR code headers, like ECI etc... so you still need to interpret the bits.
I summed it up in a post here.
Inspired by previous answers and other sites, I have created a gist that allows to extract binary from QR code or Aztec code, without using private APIs nor other library. It is a AVMetadataMachineReadableCodeObject extension presenting a binaryValue.
However, it only runs on iOS 11 and later, because of the CIQRCodeDescriptor use.
It is available here : https://gist.github.com/PetrusM/267e2ee8c1d8b5dca17eac085afa7d7c
For QR codes, it works only with 100% binary ones. But if they contain further parts, you can easily adapt it.

Resources