1 #include "newpacket.hpp"
2 #include "timeparse.hpp"
3 #include "timecounter.hpp"
4 #include "resampler.hpp"
15 int real_main(int argc
, char** argv
)
17 std::map
<std::string
, uint16_t> channel_assignments
;
18 std::vector
<struct channel
> chans
;
19 uint32_t converted_channel
= 0;
20 uint16_t converted_channel_out
;
22 std::cerr
<< "syntax: fmtopcm.exe <input> <channel> <rate> <output>" << std::endl
;
26 read_channel
rchan(argv
[1]);
27 write_channel
wchan(argv
[4]);
28 converted_channel
= rchan
.number_for_channel(argv
[2]);
29 timecounter
counter(argv
[3]);
30 resampler_fm
resampler(atoi(argv
[3]));
32 //Create output channel.
33 channel_assignments
[argv
[2]] = converted_channel_out
= (uint16_t)chans
.size();
35 c
.c_channel
= (uint16_t)chans
.size();
37 c
.c_channel_name
= argv
[2];
39 wchan
.start_segment(chans
);
43 while((p
= rchan
.read())) {
45 while((uint64_t)counter
<= p
->rp_timestamp
) {
46 sample_number_t out
= resampler
.nextsample();
47 p2
.rp_timestamp
= counter
;
48 p2
.rp_channel
= converted_channel_out
;
50 p2
.rp_payload
.resize(4);
51 unsigned short x
= (unsigned short)out
.get_x();
52 unsigned short y
= (unsigned short)out
.get_y();
53 p2
.rp_payload
[0] = (x
>> 8) & 0xFF;
54 p2
.rp_payload
[1] = x
& 0xFF;
55 p2
.rp_payload
[2] = (y
>> 8) & 0xFF;
56 p2
.rp_payload
[3] = y
& 0xFF;
61 if(p
->rp_channel_perm
== converted_channel
&& p
->rp_minor
> 0) {
62 resampler
.sendpacket(*p
);
67 if(!channel_assignments
.count(p
->rp_channel_name
)) {
68 //No channel yet, create.
69 channel_assignments
[p
->rp_channel_name
] = (uint16_t)chans
.size();
71 c
.c_channel
= (uint16_t)chans
.size();
72 c
.c_type
= p
->rp_major
;
73 c
.c_channel_name
= p
->rp_channel_name
;
75 wchan
.start_segment(chans
);
77 uint16_t chan
= channel_assignments
[p
->rp_channel_name
];
78 if(chans
[chan
].c_type
!= p
->rp_major
&& p
->rp_channel_perm
!= converted_channel
) {
80 chans
[chan
].c_type
= p
->rp_major
;
81 wchan
.start_segment(chans
);