Esempio n. 1
0
int _tmain(int argc, _TCHAR* argv[])
{
	mpg123_handle *m;
	int i;
	if(argc < 2)
	{
		fprintf(stderr, "\nI will give you the estimated and exact sample lengths of MPEG audio files.\n");
		fprintf(stderr, "\nUsage: %ls <mpeg audio file list>\n\n", argv[0]);
		return -1;
	}
	mpg123_init();
	m = mpg123_new(NULL, NULL);
	mpg123_param(m, MPG123_RESYNC_LIMIT, -1, 0); /* New in library version 0.0.1 . */
	for(i = 1; i < argc; ++i)
	{
		off_t a, b;
		
		mpg123_topen(m, argv[i]);

		a = mpg123_length(m);		
		mpg123_scan(m);
		b = mpg123_length(m);

		mpg123_tclose(m);

		printf("File %i: estimated %li vs. scanned %li\n", i, (long)a, (long)b);
	}

	mpg123_delete(m);
	mpg123_exit();
	return 0;
}
Esempio n. 2
0
int _tmain(int argc, _TCHAR* argv[])
{
    mpg123_handle *m;
    int i;
    if (argc < 3)
    {
        fprintf(stderr, "\nI will give you the estimated and exact sample lengths of MPEG audio files.\n");
        fprintf(stderr, "\nUsage: %s <mpeg audio file list>\n\n", argv[0]);
        return -1;
    }
    mpg123_init();
    m = mpg123_new(NULL, NULL);
    mpg123_param(m, MPG123_RESYNC_LIMIT, -1, 0); /* New in library version 0.0.1 . */

    off_t a, b;
    if (MPG123_OK != mpg123_open_feed(m)) {
        fprintf(stderr, "open feed failed");
        return -1;
    }

    FILE* file = _tfopen(argv[1], TEXT("rb"));
    if (!file) {
        fprintf(stderr, "open file failed");
        return -1;
    }

    _stat64i32 st = { 0 };
    _tstat(argv[1], &st);
    if (st.st_size <= 0) {
        fprintf(stderr, "file size is zero");
        return -1;
    }
    char* pDataBuf = new char[st.st_size];
    memset(pDataBuf, 0, st.st_size);
    if (st.st_size != fread(pDataBuf, 1, st.st_size, file)) {
        fprintf(stderr, "read file error");
        return -1;
    }
    if (MPG123_OK != mpg123_feed(m, (const unsigned char*)pDataBuf, st.st_size)) {
        fprintf(stderr, "feed failed");
        return -1;
    }

    // channels;
    bool bSaved = false;
    size_t nDone = 0;
    int res = mpg123_decode(m, NULL, 0, NULL, 0, &nDone);
    if (res == MPG123_NEW_FORMAT) {
        long rate = 0;
        int channels = 0;
        int enc = 0;
        mpg123_getformat(m, &rate, &channels, &enc);

        if (MPG123_ENC_SIGNED_16 == enc) {
            int nSamples = mpg123_length(m);
            int nBufCount = nSamples * channels;
            int nBufSize = nBufCount * sizeof(short);
            short* pBuf = new short[nBufCount];

            res = mpg123_decode(m, NULL, 0, (unsigned char*)pBuf, nBufSize, &nDone);
            if (res == MPG123_OK) {
                KWavFile file;
                file.Init(pBuf, nDone, rate, "");
                file.Save(CT2A(argv[2]));
                bSaved = true;
            }
            if (pBuf) {
                delete[] pBuf;
                pBuf = NULL;
            }
        }
    }


    mpg123_tclose(m);
    mpg123_delete(m);
    mpg123_exit();
    return 0;
}