Code Coverage Report for src/api/read-int16.c
|
Hit |
Total |
Coverage |
Lines: |
30 |
30 |
100.0% |
Branches: |
144 |
144 |
100.0% |
1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2024 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 #include "src/util/float-to-int16.h"
14
15 #include <string.h>
16
17
18 int32_t vorbis_read_int16(
19 vorbis_t *handle, int16_t *buf, int32_t len, vorbis_error_t *error_ret)
20 {
21 int32_t count = 0;
22 int error = VORBIS_NO_ERROR;
23
24 (36/36) if (!buf || len < 0) {
25 error = VORBIS_ERROR_INVALID_ARGUMENT;
26 goto out;
27 }
28
29 const int channels = handle->channels;
30 (18/18) while (count < len) {
31 (18/18) if (handle->decode_buf_pos >= handle->decode_buf_len) {
32 (18/18) if (handle->packet_mode) {
33 error = VORBIS_ERROR_STREAM_END;
34 break;
35 } else {
36 error = decode_frame(handle, NULL, 0);
37 (18/18) if (error) {
38 break;
39 }
40 }
41 }
42 const int copy = min(
43 len - count, handle->decode_buf_len - handle->decode_buf_pos);
44 (18/18) if (handle->read_int16_only) {
45 memcpy(buf, ((int16_t *)handle->decode_buf
46 + handle->decode_buf_pos * channels),
47 copy * channels * sizeof(*buf));
48 } else {
49 const float *src =
50 (float *)handle->decode_buf + handle->decode_buf_pos * channels;
51 float_to_int16(buf, src, copy * channels);
52 }
53 buf += copy * channels;
54 count += copy;
55 handle->decode_buf_pos += copy;
56 }
57
58 out:
59 (18/18) if (error_ret) {
60 *error_ret = error;
61 }
62 return count;
63 }