| 1 |
/* |
| 2 |
* Copyright 2008-2011 Various Authors |
| 3 |
* Copyright 2004 Timo Hirvonen |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License as |
| 7 |
* published by the Free Software Foundation; either version 2 of the |
| 8 |
* License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef _NOMAD_H |
| 20 |
#define _NOMAD_H |
| 21 |
|
| 22 |
#include <sys/types.h> |
| 23 |
|
| 24 |
#ifndef __GNUC__ |
| 25 |
#include <unistd.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
/* default callbacks use read, lseek, close */ |
| 29 |
struct nomad_callbacks { |
| 30 |
ssize_t (*read)(void *datasource, void *buffer, size_t count); |
| 31 |
off_t (*lseek)(void *datasource, off_t offset, int whence); |
| 32 |
int (*close)(void *datasource); |
| 33 |
}; |
| 34 |
|
| 35 |
enum { |
| 36 |
XING_FRAMES = 0x00000001L, |
| 37 |
XING_BYTES = 0x00000002L, |
| 38 |
XING_TOC = 0x00000004L, |
| 39 |
XING_SCALE = 0x00000008L |
| 40 |
}; |
| 41 |
|
| 42 |
struct nomad_xing { |
| 43 |
unsigned int is_info : 1; |
| 44 |
unsigned int flags; |
| 45 |
unsigned int nr_frames; |
| 46 |
unsigned int bytes; |
| 47 |
unsigned int scale; |
| 48 |
unsigned char toc[100]; |
| 49 |
}; |
| 50 |
|
| 51 |
struct nomad_lame { |
| 52 |
char encoder[10]; /* 9 byte encoder name/version ("LAME3.97b") */ |
| 53 |
int vbr_method; /* VBR method */ |
| 54 |
float peak; /* replaygain peak */ |
| 55 |
float trackGain; /* replaygain track gain */ |
| 56 |
float albumGain; /* replaygain album gain */ |
| 57 |
int encoderDelay; /* # of added samples at start of mp3 */ |
| 58 |
int encoderPadding; /* # of added samples at end of mp3 */ |
| 59 |
}; |
| 60 |
|
| 61 |
/* always 16-bit signed little-endian */ |
| 62 |
struct nomad_info { |
| 63 |
double duration; |
| 64 |
int sample_rate; |
| 65 |
int channels; |
| 66 |
int nr_frames; |
| 67 |
int layer; |
| 68 |
/* guessed */ |
| 69 |
int vbr; |
| 70 |
/* guessed */ |
| 71 |
int avg_bitrate; |
| 72 |
/* -1 if file not seekable */ |
| 73 |
off_t filesize; |
| 74 |
unsigned int joint_stereo : 1; |
| 75 |
unsigned int dual_channel : 1; |
| 76 |
}; |
| 77 |
|
| 78 |
enum { |
| 79 |
NOMAD_ERROR_SUCCESS, |
| 80 |
NOMAD_ERROR_ERRNO, |
| 81 |
NOMAD_ERROR_FILE_FORMAT |
| 82 |
}; |
| 83 |
|
| 84 |
struct nomad; |
| 85 |
|
| 86 |
/* -NOMAD_ERROR_ERRNO -NOMAD_ERROR_FILE_FORMAT */ |
| 87 |
int nomad_open_callbacks(struct nomad **nomadp, void *datasource, |
| 88 |
struct nomad_callbacks *cbs); |
| 89 |
|
| 90 |
void nomad_close(struct nomad *nomad); |
| 91 |
|
| 92 |
/* -NOMAD_ERROR_ERRNO */ |
| 93 |
int nomad_read(struct nomad *nomad, char *buffer, int count); |
| 94 |
|
| 95 |
/* -NOMAD_ERROR_ERRNO */ |
| 96 |
int nomad_time_seek(struct nomad *nomad, double pos); |
| 97 |
|
| 98 |
const struct nomad_xing *nomad_xing(struct nomad *nomad); |
| 99 |
const struct nomad_lame *nomad_lame(struct nomad *nomad); |
| 100 |
const struct nomad_info *nomad_info(struct nomad *nomad); |
| 101 |
long nomad_current_bitrate(struct nomad *nomad); |
| 102 |
|
| 103 |
#endif |