+/**
+ * Get one chunk of audio data.
+ *
+ * \param chunk_num The number of the chunk to get.
+ * \param afhi Describes the audio file.
+ * \param map The memory mapped audio file.
+ * \param buf Result pointer.
+ * \param len The length of the chunk in bytes.
+ *
+ * Upon return, \a buf will point so memory inside \a map. The returned buffer
+ * must therefore not be freed by the caller.
+ */
+void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
+ void *map, const char **buf, size_t *len)
+{
+ size_t pos = afhi->chunk_table[chunk_num];
+ *buf = map + pos;
+ *len = afhi->chunk_table[chunk_num + 1] - pos;
+}
+
+/**
+ * Compute the size of the largest chunk of an audio file.
+ *
+ * \param afhi The audio format handler struct containing the chunk table.
+ *
+ * \return The number of bytes of the largest chunk.
+ */
+uint32_t afh_get_largest_chunk_size(struct afh_info *afhi)
+{
+ uint32_t n, largest = 0, *ct = afhi->chunk_table;
+
+ for (n = 1; n <= afhi->chunks_total; n++)
+ largest = PARA_MAX(largest, ct[n] - ct[n - 1]);
+ return largest;
+}
+
+/**
+ * Get the header of an audio file.
+ *
+ * \param afhi The audio file handler data describing the file.
+ * \param map The data of the audio file.
+ * \param buf The length of the header is stored here.
+ * \param len Points to a buffer containing the header on return.
+ *
+ * This function sets \a buf to \p NULL and \a len to zero if \a map or \a
+ * afhi is \p NULL, or if the current audio format does not need special
+ * header treatment.
+ */
+void afh_get_header(struct afh_info *afhi, void *map, const char **buf, size_t *len)
+{
+ if (!map || !afhi || !afhi->header_len) {
+ *buf = NULL;
+ *len = 0;
+ return;
+ }
+ *len = afhi->header_len;
+ *buf = map + afhi->header_offset;
+}