Note:
This API doc is automatically generated from the current development version that you can get via Subversion or as a daily snapshot from
http://mpg123.org/snapshot.
There may be differences (additions) compared to the latest stable release. See
NEWS.libmpg123 and the overall
NEWS file on libmpg123 versions and important changes between them.
Let me emphasize that the policy for libmpg123 is to always stay backwards compatible -- only
additions are planned (and it's not yet planned to change the plans;-).
00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "mpg123.h"
00010 #include <unistd.h>
00011 #include <stdio.h>
00012
00013 #define INBUFF 16384
00014 #define OUTBUFF 32768
00015
00016 int main(int argc, char **argv)
00017 {
00018 size_t size;
00019 unsigned char buf[INBUFF];
00020 unsigned char out[OUTBUFF];
00021 ssize_t len;
00022 int ret;
00023 size_t in = 0, outc = 0;
00024 mpg123_handle *m;
00025
00026 mpg123_init();
00027 m = mpg123_new(argc > 1 ? argv[1] : NULL, &ret);
00028 if(m == NULL)
00029 {
00030 fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret));
00031 return -1;
00032 }
00033 mpg123_param(m, MPG123_VERBOSE, 2, 0);
00034
00035
00036
00037 mpg123_open_feed(m);
00038 if(m == NULL) return -1;
00039
00040 fprintf(stderr, "Feed me some MPEG audio to stdin, I will decode to stdout.\n");
00041 while(1)
00042 {
00043 len = read(0,buf,INBUFF);
00044 if(len <= 0)
00045 {
00046 fprintf(stderr, "input data end\n");
00047 break;
00048 }
00049 in += len;
00050
00051 ret = mpg123_decode(m,buf,len,out,OUTBUFF,&size);
00052 if(ret == MPG123_NEW_FORMAT)
00053 {
00054 long rate;
00055 int channels, enc;
00056 mpg123_getformat(m, &rate, &channels, &enc);
00057 fprintf(stderr, "New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc);
00058 }
00059 write(1,out,size);
00060 outc += size;
00061 while(ret != MPG123_ERR && ret != MPG123_NEED_MORE)
00062 {
00063 ret = mpg123_decode(m,NULL,0,out,OUTBUFF,&size);
00064 write(1,out,size);
00065 outc += size;
00066 }
00067 if(ret == MPG123_ERR){ fprintf(stderr, "some error: %s", mpg123_strerror(m)); break; }
00068 }
00069 fprintf(stderr, "%lu bytes in, %lu bytes out\n", (unsigned long)in, (unsigned long)outc);
00070
00071
00072 mpg123_delete(m);
00073 mpg123_exit();
00074 return 0;
00075 }
00076