aboutsummaryrefslogtreecommitdiffstats
path: root/src/faadalyse.cpp
blob: 9c7fbf9b5a4c306607c725c8180e2dd5742b0214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
    Copyright (C) 2017 Matthias P. Braendli (http://www.opendigitalradio.org)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    faadalyse.cpp
        Use FAAD to analyse some AAC file internals

    Authors:
         Matthias P. Braendli <matthias@mpb.li>
*/


#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <getopt.h>

extern "C" {
#include "lib_crc.h"
}
#include "dabplussnoop.hpp"

using namespace std;

static void usage(void)
{
    cerr << "\nUsage:\n"
        "faadalyse <file.dabp> <bitrate>\n"
        "  The bitrate of the file must be given separately\n";
}

int main(int argc, char **argv)
{
    cerr << "Faadalyse -- A .dabp file analyser\n  www.opendigitalradio.org\n" <<
            " compiled at " << __DATE__ << " " << __TIME__ << "\n";

    if (argc != 3) {
        usage();
        return 1;
    }
    const string fname = argv[1];
    const int bitrate = stoi(argv[2]);
    if (bitrate % 8 != 0) {
        cerr << "Bitrate not a multiple of 8\n";
        return 1;
    }
    const int subchannel_index = bitrate / 8;

    cerr << "Analysing " << fname << " " << bitrate << "kbps\n";

    DabPlusSnoop snoop;
    snoop.set_subchannel_index(subchannel_index);

    FILE* fd = fopen(fname.c_str(), "r");
    if (!fd) {
        cerr << "Failed to open file\n";
        return 1;
    }

    while (!feof(fd) and !ferror(fd)) {
        vector<uint8_t> buf(1024);
        size_t read_bytes = fread(buf.data(), 1, 1024, fd);

        if (read_bytes) {
            snoop.push(buf.data(), read_bytes);
        }
    }

    snoop.close();

    cerr << "Write file stream-0.wav\n";

    return 0;
}