i am studying "Audio File Stream Services Reference" in iOS

934 views Asked by At

i can't understand this sentence "To use a parser, you pass data from a streamed audio file, as you acquire it, to the parser. When the parser has a complete packet of audio data or a complete property, it invokes a callback function. Your callbacks then process the parsed data—such as by playing it or writing it to disk." I don't know what is "Complete packet" and "complete property". I need your help, thanks.

1

There are 1 answers

1
justin On BEST ANSWER

The audio file's data is coming in incrementally. You feed the data to the parser. Once 'enough' data exists, you are returned data via your user provided callback.

Analogy: You want to read a text file line by line, and you feed your parser data bytes as you read. How many bytes are in a line? It varies depending on a number of factors (e.g. what are the contents of the text file? what encoding is it in? is there any way to predict line length?). In this case, you are informed when enough data is present to return the next line.

So the Audio File Stream APIs are an abstraction which are capable of dealing with many audio file formats. Some formats store their sample data (or other data/properties) in byte counts of varying sizes. PCM formats (for example) are typically contiguous, interleaved values of widths specified by the file's header -- but compressed formats tend to have lager packet sizes. Also, some properties/packets are variable length, so you cannot reasonably know when to ask the convertor for data based on the amount of data you put in -- parsing, decoding, and converting is the API's job, and I assure you that implementing parsers/decoders/convertors for all these file formats will take a long time if you were required to decode and pull based on binary input.

So you push the data as you receive/read it, and it pushes to you when there is a 'usable' amount for you.