17 enum FileName
= "/tmp/03/linda_karandashi_i_spichki.opus";
18 //enum FileName = "/tmp/03/melodie_128.opus";
21 // ////////////////////////////////////////////////////////////////////////// //
22 void main (string
[] args
) {
23 if (args
.length
== 1) args
~= FileName
;
29 ogg
.setup(VFile(args
[1]));
31 ogg
.PageInfo lastpage
;
32 if (!ogg
.findLastPage(lastpage
)) assert(0, "can't find last ogg page");
33 lastpage
.granule
-= ctx
.preskip
;
34 conwriteln("last page seqnum: ", lastpage
.seqnum
);
35 conwriteln("last page granule: ", lastpage
.granule
);
36 conwriteln("last page filepos: ", lastpage
.pgfpos
);
39 auto r
= opus_header(&ctx
, ogg
);
41 if (!ogg
.loadPacket()) assert(0);
45 if (opus_decode_init(&ctx
, &c
) < 0) assert(0, "fuuuuu");
46 scope(exit
) opus_decode_close(&c
);
47 assert(c
.nb_streams
== 1);
48 assert(c
.streams
[0].output_channels
>= 1 && c
.streams
[0].output_channels
<= 2);
49 //assert(c.streams[0].output_channels == 2);
52 foreach (immutable chn; 0..c.streams[0].output_channels) {
53 conwriteln("output buf for chan #", chn);
54 //c.streams.out_[chn] = av_mallocz!float(Rate);
59 foreach (ref obb
; obuf
[]) obb
.length
= Rate
;
61 ulong packets
, frames
;
63 version(noplay
) {} else alsaOpen(c
.streams
[0].output_channels
);
64 version(noplay
) {} else scope(exit
) alsaClose();
66 //ogg.seekPCM(lastpage.granule/4+ctx.preskip);
67 //ogg.seekPCM(lastpage.granule/6+ctx.preskip);
71 auto r
= opus_packet(&ctx
, ogg
);
74 //conwriteln("packet #", packets, "; frame #", frames);
77 frame
.linesize
[0] = obuf
[0].length
*obuf
[0].sizeof
;
78 pkt
.data
= ogg
.packetData
.ptr
;
79 pkt
.size
= cast(uint)ogg
.packetLength
;
80 foreach (immutable idx
, ref obb
; obuf
[]) eptr
[idx
] = cast(ubyte*)(obb
.ptr
);
81 frame
.extended_data
= eptr
.ptr
;
82 //c.streams.out_size = outsize;
84 r
= opus_decode_packet(/*&ctx,*/ &c
, &frame
, &gotfrptr
, &pkt
);
86 conwriteln("can't process packet #", packets
);
89 if (gotfrptr
) ++frames
;
90 //conwriteln(" ", c.streams.out_size);
91 //conwriteln("dc=", r);
92 if (ogg
.packetGranule
&& ogg
.packetGranule
!= -1) lastgran
= ogg
.packetGranule
-ctx
.preskip
;
93 conwritef
!"\r%s:%02s / %s:%02s"((lastgran
/48000)/60, (lastgran
/48000)%60, (lastpage
.granule
/48000)/60, (lastpage
.granule
/48000)%60);
94 version(noplay
) {} else alsaWrite2B(eptr
.ptr
, r
);
97 if (!ogg
.loadPacket()) break;
99 conwriteln(packets
, " opus packets, ", frames
, " frames found");