-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgasc.c
64 lines (56 loc) · 2.46 KB
/
gasc.c
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
#include "gasc.h"
#include <assert.h>
#include <stdlib.h>
int gasc_main(input *in, output *out, flac_settings *set){
clock_t cstart;
queue q;
stats stat={0};
simple_enc *a, *ab, *b, *swap;
mode_boilerplate_init(set, &cstart, &q, &stat);
_if((set->blocks_count!=1), "gasc cannot use multiple block sizes");
_if((2*set->blocks[0]>set->blocksize_limit_upper), "gasc needs an upper blocksize limit at least twice that of the blocksize used");
a =calloc(1, sizeof(simple_enc));
b =calloc(1, sizeof(simple_enc));
ab=calloc(1, sizeof(simple_enc));
in->input_read(in, set->blocksize_limit_upper);
if(!simple_enc_eof(&q, &a, set, in, 2*set->blocks[0], &stat, out)){//if not eof, init
simple_enc_analyse(a , set, in, set->blocks[0], 0, &stat);
simple_enc_analyse(b , set, in, set->blocks[0], set->blocks[0], &stat);
simple_enc_analyse(ab, set, in, 2*set->blocks[0], 0, &stat);
}
while(in->sample_cnt){
if((a->outbuf_size+b->outbuf_size)<ab->outbuf_size){//dump a naturally
a=simple_enc_out(&q, a, set, in, &stat, out);
in->input_read(in, set->blocksize_limit_upper);
if(!simple_enc_eof(&q, &a, set, in, 2*set->blocks[0], &stat, out)){//if next !eof, iterate
swap=a;
a=b;
b=swap;
simple_enc_analyse(b, set, in, set->blocks[0], in->loc_analysis+set->blocks[0], &stat);
simple_enc_analyse(ab, set, in, 2*set->blocks[0], in->loc_analysis, &stat);
}
}
else if(ab->sample_cnt+set->blocks[0]>set->blocksize_limit_upper){//dump ab as hit upper limit
ab=simple_enc_out(&q, ab, set, in, &stat, out);
in->input_read(in, set->blocksize_limit_upper);
if(!simple_enc_eof(&q, &a, set, in, 2*set->blocks[0], &stat, out)){//if next !eof, iterate
simple_enc_analyse(a, set, in, set->blocks[0], in->loc_analysis, &stat);
simple_enc_analyse(b, set, in, set->blocks[0], in->loc_analysis+set->blocks[0], &stat);
simple_enc_analyse(ab, set, in, 2*set->blocks[0], in->loc_analysis, &stat);
}
}
else{//iterate
_if(((ab->sample_cnt+set->blocks[0]>in->sample_cnt) && !simple_enc_eof(&q, &a, set, in, in->sample_cnt+1, &stat, out)), "Failed to finalise in-progress frame");//eof mid-frame
swap=a;
a=ab;
ab=swap;
simple_enc_analyse(b, set, in, set->blocks[0], in->loc_analysis+a->sample_cnt, &stat);
simple_enc_analyse(ab, set, in, a->sample_cnt+set->blocks[0], in->loc_analysis, &stat);
}
}
mode_boilerplate_finish(set, &cstart, &q, &stat, in, out);
simple_enc_dealloc(a);
simple_enc_dealloc(b);
simple_enc_dealloc(ab);
return 0;
}