ReactOS 0.4.16-dev-92-g0c2cdca
gapless.h File Reference
#include "debug.h"
Include dependency graph for gapless.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SAMPLE_ADJUST(mh, x)   sample_adjust(mh,x)
 
#define SAMPLE_UNADJUST(mh, x)   sample_unadjust(mh,x)
 
#define FRAME_BUFFERCHECK(mh)   frame_buffercheck(mh)
 

Functions

static off_t sample_adjust (mpg123_handle *mh, off_t x)
 
static off_t sample_unadjust (mpg123_handle *mh, off_t x)
 
static void frame_buffercheck (mpg123_handle *fr)
 

Macro Definition Documentation

◆ FRAME_BUFFERCHECK

#define FRAME_BUFFERCHECK (   mh)    frame_buffercheck(mh)

Definition at line 111 of file gapless.h.

◆ SAMPLE_ADJUST

#define SAMPLE_ADJUST (   mh,
  x 
)    sample_adjust(mh,x)

Definition at line 109 of file gapless.h.

◆ SAMPLE_UNADJUST

#define SAMPLE_UNADJUST (   mh,
  x 
)    sample_unadjust(mh,x)

Definition at line 110 of file gapless.h.

Function Documentation

◆ frame_buffercheck()

static void frame_buffercheck ( mpg123_handle fr)
static

Definition at line 58 of file gapless.h.

59{
60 /* When we have no accurate position, gapless code does not make sense. */
61 if(!(fr->state_flags & FRAME_ACCURATE)) return;
62
63 /* Get a grip on dirty streams that start with a gapless header.
64 Simply accept all data from frames that are too much,
65 they are supposedly attached to the stream after the fact. */
66 if(fr->gapless_frames > 0 && fr->num >= fr->gapless_frames) return;
67
68 /* Important: We first cut samples from the end, then cut from beginning (including left-shift of the buffer).
69 This order works also for the case where firstframe == lastframe. */
70
71 /* The last interesting (planned) frame: Only use some leading samples.
72 Note a difference from the below: The last frame and offset are unchanges by seeks.
73 The lastoff keeps being valid. */
74 if(fr->lastframe > -1 && fr->num >= fr->lastframe)
75 {
76 /* There can be more than one frame of padding at the end, so we ignore the whole frame if we are beyond lastframe. */
77 off_t byteoff = (fr->num == fr->lastframe) ? samples_to_bytes(fr, fr->lastoff) : 0;
78 if((off_t)fr->buffer.fill > byteoff)
79 {
80 fr->buffer.fill = byteoff;
81 }
82 if(VERBOSE3) fprintf(stderr, "\nNote: Cut frame %"OFF_P" buffer on end of stream to %"OFF_P" samples, fill now %"SIZE_P" bytes.\n", (off_p)fr->num, (off_p)(fr->num == fr->lastframe ? fr->lastoff : 0), (size_p)fr->buffer.fill);
83 }
84
85 /* The first interesting frame: Skip some leading samples. */
86 if(fr->firstoff && fr->num == fr->firstframe)
87 {
88 off_t byteoff = samples_to_bytes(fr, fr->firstoff);
89 if((off_t)fr->buffer.fill > byteoff)
90 {
91 fr->buffer.fill -= byteoff;
92 /* buffer.p != buffer.data only for own buffer */
93 debug6("cutting %li samples/%li bytes on begin, own_buffer=%i at %p=%p, buf[1]=%i",
94 (long)fr->firstoff, (long)byteoff, fr->own_buffer, (void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
95 if(fr->own_buffer) fr->buffer.p = fr->buffer.data + byteoff;
96 else memmove(fr->buffer.data, fr->buffer.data + byteoff, fr->buffer.fill);
97 debug3("done cutting, buffer at %p =? %p, buf[1]=%i",
98 (void*)fr->buffer.p, (void*)fr->buffer.data, ((short*)fr->buffer.p)[2]);
99 }
100 else fr->buffer.fill = 0;
101
102 if(VERBOSE3) fprintf(stderr, "\nNote: Cut frame %"OFF_P" buffer on beginning of stream by %"OFF_P" samples, fill now %"SIZE_P" bytes.\n", (off_p)fr->num, (off_p)fr->firstoff, (size_p)fr->buffer.fill);
103 /* We can only reach this frame again by seeking. And on seeking, firstoff will be recomputed.
104 So it is safe to null it here (and it makes the if() decision abort earlier). */
105 fr->firstoff = 0;
106 }
107}
__kernel_off_t off_t
Definition: linux.h:201
@ FRAME_ACCURATE
Definition: frame.h:92
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define samples_to_bytes
Definition: intsym.h:225
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define VERBOSE3
#define SIZE_P
Definition: compat.h:139
#define OFF_P
Definition: compat.h:131
unsigned long size_p
Definition: compat.h:140
long off_p
Definition: compat.h:132
#define debug6(s, a, b, c, d, e, f)
Definition: debug.h:66
#define debug3(s, a, b, c)
Definition: debug.h:63
struct outbuffer buffer
Definition: frame.h:267
off_t gapless_frames
Definition: frame.h:277

◆ sample_adjust()

static off_t sample_adjust ( mpg123_handle mh,
off_t  x 
)
static

Definition at line 14 of file gapless.h.

15{
16 off_t s;
17 if(mh->p.flags & MPG123_GAPLESS)
18 {
19 /* It's a bit tricky to do this computation for the padding samples.
20 They are not there on the outside. */
21 if(x > mh->end_os)
22 {
23 if(x < mh->fullend_os)
24 s = mh->end_os - mh->begin_os;
25 else
26 s = x - (mh->fullend_os - mh->end_os + mh->begin_os);
27 }
28 else
29 s = x - mh->begin_os;
30 }
31 else
32 s = x;
33
34 return s;
35}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
@ MPG123_GAPLESS
Definition: mpg123.h:220
struct mpg123_pars_struct p
Definition: frame.h:289

◆ sample_unadjust()

static off_t sample_unadjust ( mpg123_handle mh,
off_t  x 
)
static

Definition at line 38 of file gapless.h.

39{
40 off_t s;
41 if(mh->p.flags & MPG123_GAPLESS)
42 {
43 s = x + mh->begin_os;
44 /* There is a hole; we don't create sample positions in there.
45 Jump from the end of the gapless track directly to after the padding. */
46 if(s >= mh->end_os)
47 s += mh->fullend_os - mh->end_os;
48 }
49 else s = x;
50
51 return s;
52}