Code Coverage Report for src/api/read-float.c


Hit Total Coverage
Lines: 29 29 100.0%
Branches: 144 144 100.0%

1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2023 Andrew Church <achurch@achurch.org>
4 *
5 * This software may be copied and redistributed under certain conditions;
6 * see the file "COPYING" in the source code distribution for details.
7 * NO WARRANTY is provided with this software.
8 */
9
10 #include "include/nogg.h"
11 #include "src/common.h"
12 #include "src/util/decode-frame.h"
13
14 #include <string.h>
15
16
17 int32_t vorbis_read_float(
18 vorbis_t *handle, float *buf, int32_t len, vorbis_error_t *error_ret)
19 {
20 int32_t count = 0;
21 int error = VORBIS_NO_ERROR;
22
23 (36/36) if (!buf || len < 0) {
24 error = VORBIS_ERROR_INVALID_ARGUMENT;
25 goto out;
26 }
27 (18/18) if (handle->read_int16_only) {
28 error = VORBIS_ERROR_INVALID_OPERATION;
29 goto out;
30 }
31
32 const int channels = handle->channels;
33 (18/18) while (count < len) {
34 (18/18) if (handle->decode_buf_pos >= handle->decode_buf_len) {
35 (18/18) if (handle->packet_mode) {
36 error = VORBIS_ERROR_STREAM_END;
37 break;
38 } else {
39 error = decode_frame(handle, NULL, 0);
40 (18/18) if (error) {
41 break;
42 }
43 }
44 }
45 const int copy = min(
46 len - count, handle->decode_buf_len - handle->decode_buf_pos);
47 memcpy(buf, ((float *)handle->decode_buf
48 + handle->decode_buf_pos * channels),
49 copy * channels * sizeof(*buf));
50 buf += copy * channels;
51 count += copy;
52 handle->decode_buf_pos += copy;
53 }
54
55 out:
56 (18/18) if (error_ret) {
57 *error_ret = error;
58 }
59 return count;
60 }