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
00011
00012
00013 #ifndef _MSC_VER
00014 #include <unistd.h>
00015 #else
00016 #include <io.h>
00017 #endif
00018
00019 #include <stdio.h>
00020
00021 #define INBUFF 16384
00022 #define OUTBUFF 32768
00023
00024 int main(int argc, char **argv)
00025 {
00026 size_t size;
00027 unsigned char buf[INBUFF];
00028 unsigned char out[OUTBUFF];
00029 ssize_t len;
00030 int ret;
00031 size_t in = 0, outc = 0;
00032 mpg123_handle *m;
00033
00034 mpg123_init();
00035 m = mpg123_new(argc > 1 ? argv[1] : NULL, &ret);
00036 if(m == NULL)
00037 {
00038 fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret));
00039 return -1;
00040 }
00041 mpg123_param(m, MPG123_VERBOSE, 2, 0);
00042
00043
00044
00045 mpg123_open_feed(m);
00046 if(m == NULL) return -1;
00047
00048 fprintf(stderr, "Feed me some MPEG audio to stdin, I will decode to stdout.\n");
00049 while(1)
00050 {
00051 len = read(0,buf,INBUFF);
00052 if(len <= 0)
00053 {
00054 fprintf(stderr, "input data end\n");
00055 break;
00056 }
00057 in += len;
00058
00059 ret = mpg123_decode(m,buf,len,out,OUTBUFF,&size);
00060 if(ret == MPG123_NEW_FORMAT)
00061 {
00062 long rate;
00063 int channels, enc;
00064 mpg123_getformat(m, &rate, &channels, &enc);
00065 fprintf(stderr, "New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc);
00066 }
00067 write(1,out,size);
00068 outc += size;
00069 while(ret != MPG123_ERR && ret != MPG123_NEED_MORE)
00070 {
00071 ret = mpg123_decode(m,NULL,0,out,OUTBUFF,&size);
00072 write(1,out,size);
00073 outc += size;
00074 }
00075 if(ret == MPG123_ERR){ fprintf(stderr, "some error: %s", mpg123_strerror(m)); break; }
00076 }
00077 fprintf(stderr, "%lu bytes in, %lu bytes out\n", (unsigned long)in, (unsigned long)outc);
00078
00079
00080 mpg123_delete(m);
00081 mpg123_exit();
00082 return 0;
00083 }