bool nuiAudioDecoder::Seek(int64 SampleFrame) { off_t streamPosition; off_t res = mpg123_feedseek(mpPrivate->mpHandle, SampleFrame, SEEK_SET, &streamPosition); if (res < 0) return false; mrStream.SetPos(streamPosition); return true; }
bool Mpg123Decoder::rewind() { eof = false; off_t offset; if (mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0) { data_offset = offset; return true; } else return false; }
bool Mpg123Decoder::seek(float s) { off_t offset = static_cast<off_t>(s * static_cast<float>(sampleRate)); if (offset < 0) return false; if (mpg123_feedseek(handle, offset, SEEK_SET, &offset) >= 0) { data_offset = offset; eof = false; return true; } else return false; }
bool Mpg123Decoder::seek(float s) { off_t offset = mpg123_timeframe(handle, s); if(offset < 0) return false; if(mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0) { data_offset = offset; eof = false; return true; } else return false; }
static gint64 xmms_mpg123_seek (xmms_xform_t *xform, gint64 samples, xmms_xform_seek_mode_t whence, xmms_error_t *err) { xmms_mpg123_data_t *data; gint64 ret; off_t byteoff, samploff; int mwhence = -1; data = xmms_xform_private_data_get (xform); g_return_val_if_fail (data, -1); if (whence == XMMS_XFORM_SEEK_SET) { mwhence = SEEK_SET; } else if (whence == XMMS_XFORM_SEEK_CUR) { mwhence = SEEK_CUR; } else if (whence == XMMS_XFORM_SEEK_END) { mwhence = SEEK_END; } /* Get needed input position and possibly reached sample offset * from mpg123. */ samploff = mpg123_feedseek (data->decoder, samples, mwhence, &byteoff); XMMS_DBG ("seeked to %li ... input stream seek following", (long) samploff); if (samploff < 0) { xmms_error_set (err, XMMS_ERROR_GENERIC, mpg123_strerror (data->decoder)); return -1; } /* Seek in input stream. */ ret = xmms_xform_seek (xform, byteoff, XMMS_XFORM_SEEK_SET, err); if (ret < 0) { return ret; } return samploff; }
int _tmain(int argc, TCHAR **argv) { unsigned char buf[INBUFF]; unsigned char *audio; FILE *in; mpg123_handle *m; int ret, state; size_t inc, outc; off_t len, num; size_t bytes; off_t inoffset; size_t nrates; const long *rates; size_t i; inc = outc = 0; nrates = 0; rates = NULL; if(argc < 3) { fprintf(stderr,"Please supply in and out filenames\n"); return -1; } mpg123_init(); m = mpg123_new(NULL, &ret); if(m == NULL) { fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret)); return -1; } mpg123_param(m, MPG123_VERBOSE, 4, 0); ret = mpg123_param(m, MPG123_FLAGS, MPG123_FUZZY | MPG123_SEEKBUFFER | MPG123_GAPLESS, 0); if(ret != MPG123_OK) { fprintf(stderr,"Unable to set library options: %s\n", mpg123_plain_strerror(ret)); return -1; } // Let the seek index auto-grow and contain an entry for every frame ret = mpg123_param(m, MPG123_INDEX_SIZE, -1, 0); if(ret != MPG123_OK) { fprintf(stderr,"Unable to set index size: %s\n", mpg123_plain_strerror(ret)); return -1; } // Use float output formats only ret = mpg123_format_none(m); if(ret != MPG123_OK) { fprintf(stderr,"Unable to disable all output formats: %s\n", mpg123_plain_strerror(ret)); return -1; } mpg123_rates(&rates, &nrates); for(i=0; i<nrates; i++) { ret = mpg123_format(m, rates[i], MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32); if(ret != MPG123_OK) { fprintf(stderr,"Unable to set float output formats: %s\n", mpg123_plain_strerror(ret)); return -1; } } ret = mpg123_open_feed(m); if(ret != MPG123_OK) { fprintf(stderr,"Unable open feed: %s\n", mpg123_plain_strerror(ret)); return -1; } in = _tfopen(argv[1], __T("rb")); if(in == NULL) { _ftprintf(stderr,__T("Unable to open input file %s\n"), argv[1]); return -1; } out = _tfopen(argv[2], __T("wb")); if(out == NULL) { _ftprintf(stderr,__T("Unable to open output file %s\n"), argv[2]); return -1; } while(ret = mpg123_feedseek(m, 95000, SEEK_SET, &inoffset) == MPG123_NEED_MORE) { len = fread(buf, sizeof(unsigned char), INBUFF, in); if(len <= 0) break; inc += len; state = mpg123_feed(m, buf, len); if(state == MPG123_ERR) { fprintf(stderr, "Error: %s", mpg123_strerror(m)); return -1; } } fseek(in, inoffset, SEEK_SET); while(1) { len = fread(buf, sizeof(unsigned char), INBUFF, in); if(len <= 0) break; inc += len; ret = mpg123_feed(m, buf, len); while(ret != MPG123_ERR && ret != MPG123_NEED_MORE) { ret = mpg123_decode_frame(m, &num, &audio, &bytes); if(ret == MPG123_NEW_FORMAT) { mpg123_getformat(m, &rate, &channels, &enc); initwavformat(); initwav(); fprintf(stderr, "New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc); } fwrite(audio, sizeof(unsigned char), bytes, out); outc += bytes; } if(ret == MPG123_ERR) { fprintf(stderr, "Error: %s", mpg123_strerror(m)); break; } } fprintf(stderr, "Finished read %lu, decoded %lu\n", (unsigned long)inc, (unsigned long)outc); closewav(); fclose(out); fclose(in); mpg123_delete(m); mpg123_exit(); return 0; }
/*********************************************************************** * MPEG3_Reset * */ static void MPEG3_Reset(PACMDRVSTREAMINSTANCE adsi, AcmMpeg3Data* aad) { mpg123_feedseek(aad->mh, 0, SEEK_SET, NULL); mpg123_close(aad->mh); mpg123_open_feed(aad->mh); }