Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mpg123 #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ optional(HAVE_SNDIO sndio.h sndio sio_open sndio)
optional(HAVE_AO ao/ao.h ao ao_play ao)
optional(HAVE_FLAC FLAC/all.h FLAC FLAC__stream_encoder_new flac)
optional(HAVE_MAD_H mad.h mad mad_stream_buffer mp3)
optional(HAVE_MPG123_H mpg123.h mpg123 mpg123_init mp3)
optional(HAVE_LAME_LAME_H lame/lame.h mp3lame lame_get_lametag_frame mp3)
if (NOT HAVE_LAME_LAME_H)
optional(HAVE_LAME_LAME_H lame.h mp3lame lame_get_lametag_frame mp3)
Expand Down Expand Up @@ -162,9 +163,9 @@ optional4(HAVE_OGG_VORBIS vorbis/codec.h ogg ogg_stream_flush vorbis vorbis_anal
optional3(HAVE_OPUS opusfile.h ogg ogg_stream_flush opus opus_encoder_create opusfile op_open_callbacks opus)
optional(HAVE_WAVPACK wavpack/wavpack.h wavpack WavpackGetSampleRate wavpack)

if (HAVE_LAME_LAME_H OR HAVE_MAD_H)
if (HAVE_LAME_LAME_H OR HAVE_MAD_H OR HAVE_MPG123_H)
set(HAVE_MP3 1)
endif (HAVE_LAME_LAME_H OR HAVE_MAD_H)
endif (HAVE_LAME_LAME_H OR HAVE_MAD_H OR HAVE_MPG123_H)

set(CMAKE_REQUIRED_LIBRARIES mp3lame m)
check_function_exists("lame_set_VBR_quality" HAVE_LAME_SET_VBR_QUALITY)
Expand Down
34 changes: 32 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,32 @@ AM_CONDITIONAL(HAVE_ID3TAG, test x$using_id3tag = xyes)



dnl Check for mpg123 libraries
AC_ARG_WITH(mpg123,
AS_HELP_STRING([--with-mpg123],
[Try to use mpg123 (LGPL MP3 Audio Decoder)]))
using_mpg123=no
if test "$with_mpg123" == "yes"; then
using_mpg123=yes
AC_CHECK_HEADERS(mpg123.h,, using_mpg123=no)
AC_MSG_CHECKING([whether to dlopen mpg123])
AC_ARG_ENABLE(dl_mpg123,
AS_HELP_STRING([--enable-dl-mpg123], [Dlopen mpg123 instead of linking in.]),
enable_dl_mpg123=$enableval, enable_dl_mpg123=no)
AC_MSG_RESULT($enable_dl_mpg123)
if test "x$using_libltdl" = "xyes" -a "x$enable_dl_mpg123" = "xyes"; then
AC_DEFINE(DL_MPG123, 1, [Define to dlopen() mpg123.])
else
enable_dl_mpg123="no"
AC_CHECK_LIB(mpg123, mpg123_new, MP3_LIBS="$MP3_LIBS -lmpg123",using_mpg123=no)
if test "$with_mpg123" = "yes" -a "$using_mpg123" = "no"; then
AC_MSG_FAILURE([cannot find libmpg123])
fi
fi
fi



dnl Check for LAME library.
AC_ARG_WITH(lame,
AS_HELP_STRING([--without-lame],
Expand Down Expand Up @@ -623,9 +649,9 @@ AC_OPTIONAL_FORMAT(sunaudio, SUN_AUDIO, [AC_CHECK_HEADERS(sys/audioio.h,,



# MP2/MP3 format depends on libmad || LAME || twolame
# MP2/MP3 format depends on libmad || libmpg123 || LAME || twolame
AC_OPTIONAL_FORMAT(mp3, MP3, [
if test "$using_mad" != yes -a "$using_lame" != yes -a "$using_twolame" != yes; then
if test "$using_mad" != yes -a "$using_mpg123" != yes -a "$using_lame" != yes -a "$using_twolame" != yes; then
using_mp3=no
fi])

Expand Down Expand Up @@ -740,6 +766,10 @@ echo " mad.......................$using_mad"
if test "x$using_mad" = "xyes"; then
echo " dlopen mad................$enable_dl_mad"
fi
echo " mpg123....................$using_mpg123"
if test "x$using_mpg123" = "xyes"; then
echo " dlopen mpg123.............$enable_dl_mpg123"
fi
echo " twolame...................$using_twolame"
if test "x$using_twolame" = "xyes"; then
echo " dlopen twolame............$enable_dl_twolame"
Expand Down
2 changes: 2 additions & 0 deletions src/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static char const * auto_detect_format(sox_format_t * ft, char const * ext)
CHECK(sf , 0, 0, "" , 0, 4, "\144\243\004\0")
CHECK(sox , 0, 0, "" , 0, 4, ".SoX")
CHECK(sox , 0, 0, "" , 0, 4, "XoS.")
CHECK(mp3 , 0, 0, "" , 0, 3, "ID3")
CHECK(mp3 , 0, 0, "" , 0, 2, "\xFF\xFB")

if (ext && !strcasecmp(ext, "snd"))
CHECK(sndr , 7, 1, "" , 0, 2, "\0")
Expand Down
36 changes: 36 additions & 0 deletions src/mp3-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,39 @@ static size_t mp3_duration_ms(sox_format_t * ft)
}

#endif /* HAVE_MAD_H */

#ifdef HAVE_MPG123_H

static size_t mp3_duration(sox_format_t * ft)
{
priv_t * p = (priv_t *) ft->priv;
FILE * fp = ft->fp;
if (!fp || !ft->seekable) {
lsx_fail_errno(ft, SOX_EOF, "File pointer is undefined or not seekable in mp3_duration_ms");
return SOX_UNSPEC;
}
int error;
mpg123_handle * handle = p->mpg123_new(NULL, &error);
if (!handle) {
lsx_fail_errno(ft, SOX_EOF, "Could not get mpg123 handle: %s", mpg123_plain_strerror(error));
return SOX_UNSPEC;
}

p->mpg123_open_fd(handle, fileno(fp));
p->mpg123_scan(handle);
off_t samples = p->mpg123_length(handle);
int channels = 0;
int encoding = 0;
long sample_rate = 0;
mpg123_getformat(handle, &sample_rate, &channels, &encoding);
p->mpg123_close(handle);
p->mpg123_delete(handle);

lsx_rewind(ft);

// fprintf(stderr, "File length in samples, according to mpg123 (after scan): %zu / %zu\n", samples, samples * channels);

return (size_t) (samples * channels);
}

#endif /* HAVE_MPG123_H */
Loading