X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afh_common.c;h=c5a25e36bfe889d22318fa28e5cf23088c2cbb67;hp=cad972d94026eb1f1587fdf7201b752786b801b7;hb=9c1aa53f0cda586aa13a022452d16a2704055578;hpb=c341594d9788fd7e52a76f6430d91fce41cbf0ec diff --git a/afh_common.c b/afh_common.c index cad972d9..c5a25e36 100644 --- a/afh_common.c +++ b/afh_common.c @@ -264,6 +264,12 @@ const char *audio_format_name(int i) return afl[i].name; } +static inline size_t get_chunk_len(long unsigned chunk_num, + const struct afh_info *afhi) +{ + return afhi->chunk_table[chunk_num + 1] - afhi->chunk_table[chunk_num]; +} + /** * Get one chunk of audio data. * @@ -281,7 +287,28 @@ void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi, { size_t pos = afhi->chunk_table[chunk_num]; *buf = map + pos; - *len = afhi->chunk_table[chunk_num + 1] - pos; + *len = get_chunk_len(chunk_num, afhi); +} + +/** + * Find a suitable start chunk. + * + * \param approx_chunk_num Upper bound for the chunk number to return. + * \param afhi Needed for the chunk table. + * + * \return The first non-empty chunk <= \a approx_chunk_num. + * + * \sa \ref afh_get_chunk(). + */ +int32_t afh_get_start_chunk(int32_t approx_chunk_num, + const struct afh_info *afhi) +{ + int32_t k; + + for (k = PARA_MAX(0, approx_chunk_num); k >= 0; k--) + if (get_chunk_len(k, afhi) > 0) + break; + return k; } /**