• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astoeckel / libfoxenflac / 12091188646

29 Nov 2024 10:25PM UTC coverage: 91.243% (-0.2%) from 91.404%
12091188646

push

github

astoeckel
Fix unnecessary copy in demo application

256 of 269 branches covered (95.17%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

786 of 873 relevant lines covered (90.03%)

21589561.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/examples/flac_decoder.c
1
/*
2
 *  libfoxenflac -- Tiny FLAC Decoder Library
3
 *  Copyright (C) 2018-2022  Andreas Stöckel
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18

19
#include <stdbool.h>
20
#include <stdio.h>
21
#include <stdlib.h>
22

23
#include <foxen/flac.h>
24

25
int main(int argc, char *argv[]) {
×
26
        if (argc != 2) {
×
27
                fprintf(stderr, "Usage: %s <FLAC FILE>\n", argv[0]);
×
28
                return 1;
×
29
        }
30
        FILE *f = *argv[1] == '-' ? stdin : fopen(argv[1], "rb");
×
31
        if (!f) {
×
32
                fprintf(stderr, "Error opening file \"%s\"", argv[1]);
×
33
                return 1;
×
34
        }
35

36
        uint8_t in_buf[128];
37
        int32_t out_buf[512];
38
        uint32_t in_buf_wr_cur = 0;
39
        fx_flac_t *flac = FX_FLAC_ALLOC_DEFAULT();
×
40
        bool done_reading = false;
41
#if 0
42
        uint64_t smpl_idx = 0;
43
        uint64_t byte_idx = 0;
44
#endif
45
        while (true) {
×
46
                /* Read data from the input file */
47
                size_t to_read = sizeof(in_buf) - in_buf_wr_cur;
×
48
                size_t n_read = 0;
49
                if ((!done_reading) && (to_read > 0)) {
×
50
                        n_read = fread(in_buf + in_buf_wr_cur, 1, to_read, f);
×
51
                        if (n_read == 0) {
×
52
                                done_reading = true;
53
                                fprintf(stderr, "%s: Reached end of file.\n", argv[1]);
×
54
                        }
55

56
                        /* Advance the write cursor */
57
                        in_buf_wr_cur += n_read;
×
58
                }
59

60
                /* Read from the buffer */
61
                uint32_t in_buf_len = in_buf_wr_cur;
×
62
                uint32_t out_buf_len = 512;
×
63
                switch (
×
64
                    fx_flac_process(flac, in_buf, &in_buf_len, out_buf, &out_buf_len)) {
×
65
                        case FLAC_END_OF_METADATA:
66
                                /* Can read metadata here */
67
                                break;
68
                        case FLAC_ERR:
×
69
                                fprintf(stderr, "FLAC decoder in error state!\n");
×
70
                                break;
71
                        default:
72
                                break;
73
                }
74

75
                        /* Write decoded samples to stdout */
76
#if 0
77
                byte_idx += in_buf_len;
78
                for (uint32_t i = 0; i < out_buf_len; i++) {
79
/*                        fprintf(stdout, "%08lX %09ld %11d\n", byte_idx, smpl_idx++, out_buf[i] >> 16);*/
80
                        fprintf(stdout, "%09ld %11d\n", smpl_idx++, out_buf[i] >> 16);
81
                }
82
#else
83
                fwrite(out_buf, 4, out_buf_len, stdout);
×
84
#endif
85

86
                /* Copy unread bytes to the beginning of the buffer and adjust the write
87
                   cursor. */
NEW
88
                for (uint32_t i = 0; in_buf_len && (i < (in_buf_wr_cur - in_buf_len));
×
NEW
89
                     i++) {
×
UNCOV
90
                        in_buf[i] = in_buf[i + in_buf_len];
×
91
                }
UNCOV
92
                in_buf_wr_cur = in_buf_wr_cur - in_buf_len;
×
93

94
                /* Check whether we are at the end of the file */
95
                if ((in_buf_len == 0U) && (out_buf_len == 0U) && (n_read < to_read)) {
×
96
                        break;
97
                }
98
        }
99
        free(flac);
×
100

101
        if (f != stdin) {
×
102
                fclose(f);
×
103
        }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc