summaryrefslogtreecommitdiff
path: root/player.h
blob: 1f0e999dbe2580dc2f530b2cd4e0b62501e1792c (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * madplay - MPEG audio decoder and player
 * Copyright (C) 2000-2004 Robert Leslie
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: player.h,v 1.24 2004/02/23 21:34:53 rob Exp $
 */

# ifndef PLAYER_H
# define PLAYER_H

# include <stdio.h>
# include <mad.h>

# include "audio.h"
# include "resample.h"
# include "filter.h"
# include "tag.h"

enum {
  PLAYER_OPTION_SHUFFLE      = 0x0001,
  PLAYER_OPTION_DOWNSAMPLE   = 0x0002,
  PLAYER_OPTION_IGNORECRC    = 0x0004,
  PLAYER_OPTION_IGNOREVOLADJ = 0x0008,

  PLAYER_OPTION_SKIP         = 0x0010,
  PLAYER_OPTION_TIMED        = 0x0020,
  PLAYER_OPTION_TTYCONTROL   = 0x0040,
  PLAYER_OPTION_STREAMID3    = 0x0080,

  PLAYER_OPTION_FADEIN       = 0x0100,
  PLAYER_OPTION_FADEOUT      = 0x0200,
  PLAYER_OPTION_GAP          = 0x0400,
  PLAYER_OPTION_CROSSFADE    = 0x0800,

# if defined(EXPERIMENTAL)
  PLAYER_OPTION_EXTERNALMIX  = 0x1000,
  PLAYER_OPTION_EXPERIMENTAL = 0x2000,
# endif

  PLAYER_OPTION_SHOWTAGSONLY = 0x4000
};

enum player_control {
  PLAYER_CONTROL_DEFAULT,
  PLAYER_CONTROL_NEXT,
  PLAYER_CONTROL_PREVIOUS,
  PLAYER_CONTROL_REPLAY,
  PLAYER_CONTROL_STOP
};

enum player_channel {
  PLAYER_CHANNEL_DEFAULT = 0,
  PLAYER_CHANNEL_LEFT    = 1,
  PLAYER_CHANNEL_RIGHT   = 2,
  PLAYER_CHANNEL_MONO    = 3,
  PLAYER_CHANNEL_STEREO  = 4
};

enum stats_show {
  STATS_SHOW_OVERALL,
  STATS_SHOW_CURRENT,
  STATS_SHOW_REMAINING
};

enum {
  DB_MIN = -175,	/* minimum representable mad_fixed_t factor */
  DB_MAX =  +18		/* maximum representable mad_fixed_t factor */
};

enum {
  PLAYER_RGAIN_ENABLED    = 0x0001,
  PLAYER_RGAIN_SET        = 0x0002,
  PLAYER_RGAIN_AUDIOPHILE = 0x0010,
  PLAYER_RGAIN_HARDLIMIT  = 0x0020
};

struct player {
  int verbosity;

  int options;
  int repeat;

  enum player_control control;

  struct playlist {
    char const **entries;
    int length;
    int current;
  } playlist;

  mad_timer_t global_start;
  mad_timer_t global_stop;

  mad_timer_t fade_in;
  mad_timer_t fade_out;
  mad_timer_t gap;

  struct input {
    char const *path;

    int fd;
# if defined(HAVE_MMAP)
    unsigned char *fdm;
# endif

    unsigned char *data;
    unsigned long length;

    int eof;

    struct tag tag;
  } input;

  struct output {
    enum audio_mode mode;

    double voladj_db;
    double attamp_db;
    mad_fixed_t gain;

    int replay_gain;

    struct filter *filters;

    unsigned int channels_in;
    unsigned int channels_out;
    enum player_channel select;

    unsigned int speed_in;
    unsigned int speed_out;
    unsigned int speed_request;

    unsigned int precision_in;
    unsigned int precision_out;

    char const *path;
    audio_ctlfunc_t *command;

    struct resample_state resample[2];
    mad_fixed_t (*resampled)[2][MAX_NSAMPLES];
  } output;

  struct ancillary {
    char const *path;
    FILE *file;

    unsigned short buffer;
    unsigned short length;
  } ancillary;

  struct stats {
    enum stats_show show;
    char const *label;

    unsigned long total_bytes;
    mad_timer_t total_time;

    mad_timer_t global_timer;
    mad_timer_t absolute_timer;
    mad_timer_t play_timer;

    unsigned long global_framecount;
    unsigned long absolute_framecount;
    unsigned long play_framecount;

    unsigned long error_frame;
    unsigned long mute_frame;

    int vbr;
    unsigned int bitrate;
    unsigned long vbr_frames;
    unsigned long vbr_rate;

    signed long nsecs;

    struct audio_stats audio;
  } stats;
};

void player_init(struct player *);
void player_finish(struct player *);

int player_run(struct player *, int, char const *[]);

# endif