| 1 |
#include "../compat/compat.h" |
| 2 |
#include <mpg123.h> |
| 3 |
#include "../common/debug.h" |
| 4 |
|
| 5 |
|
| 6 |
int work(mpg123_handle *mh, int ch, int enc) |
| 7 |
{ |
| 8 |
int16_t buffer[16348]; |
| 9 |
long rate; |
| 10 |
int channels, encoding; |
| 11 |
if(mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK) |
| 12 |
return 1; |
| 13 |
if(channels != ch || encoding != enc) |
| 14 |
{ |
| 15 |
error("channel/encoding mismatch"); |
| 16 |
return 1; |
| 17 |
} |
| 18 |
fprintf(stderr, "openend fixed track with %ld %d %d\n" |
| 19 |
, rate, channels, encoding ); |
| 20 |
int ret; |
| 21 |
size_t done; |
| 22 |
while( (ret=mpg123_read(mh, buffer, sizeof(buffer), &done)) == MPG123_OK) |
| 23 |
{ |
| 24 |
if(!done) |
| 25 |
continue; |
| 26 |
fprintf(stderr, "Got first sample %d and last sample %d out of %zu\n" |
| 27 |
, buffer[0], buffer[done/sizeof(*buffer)-1], done/sizeof(*buffer) ); |
| 28 |
INT123_unintr_write(STDOUT_FILENO, buffer, done); |
| 29 |
} |
| 30 |
if(ret != MPG123_DONE) |
| 31 |
{ |
| 32 |
merror( "wrong mpg123_read() return value %d (%s, %s)" |
| 33 |
, ret, mpg123_plain_strerror(ret), mpg123_strerror(mh) ); |
| 34 |
return 1; |
| 35 |
} else |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
int main(int argc, char **argv) |
| 40 |
{ |
| 41 |
int ret = 1; |
| 42 |
int enc = MPG123_ENC_SIGNED_16; |
| 43 |
if(!mpg123_feature2(MPG123_FEATURE_OUTPUT_16BIT)) |
| 44 |
{ |
| 45 |
error("Libmpg123 doesn't do 16 bit output, cannot test."); |
| 46 |
return 1; |
| 47 |
} |
| 48 |
if(argc < 2) |
| 49 |
{ |
| 50 |
printf("Gimme a MPEG file name...\n"); |
| 51 |
return 0; |
| 52 |
} |
| 53 |
// Intentionally no error checking here. Let's see how the lib deals with it. |
| 54 |
mpg123_handle *mh = mpg123_new(NULL, NULL); |
| 55 |
// Try to set decoder to generic to avoid memory sanitizer freaking out about |
| 56 |
// asssembly synth routines. |
| 57 |
mpg123_decoder(mh, "generic"); |
| 58 |
// Let's fix it to mono. |
| 59 |
if(mpg123_open_fixed(mh, argv[1], MPG123_MONO, enc) == MPG123_OK) |
| 60 |
ret = work(mh, 1, enc); |
| 61 |
mpg123_delete(mh); |
| 62 |
return ret; |
| 63 |
} |