diff options
author | Max Kellermann <max@duempel.org> | 2014-07-10 08:31:41 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-10 08:31:41 +0200 |
commit | 2e1347aba4c51060b937751c2a76a5254e89a702 (patch) | |
tree | 8d175e4200e8bd068ceffab8b100a401566ec650 /src/decoder/plugins/AudiofileDecoderPlugin.cxx | |
parent | 9ddb5931fbcbde1cde36dcc698db5fbd718e3dc7 (diff) | |
download | mpd-2e1347aba4c51060b937751c2a76a5254e89a702.tar.gz mpd-2e1347aba4c51060b937751c2a76a5254e89a702.tar.xz mpd-2e1347aba4c51060b937751c2a76a5254e89a702.zip |
decoder/audiofile: split audiofile_get_duration()
Diffstat (limited to 'src/decoder/plugins/AudiofileDecoderPlugin.cxx')
-rw-r--r-- | src/decoder/plugins/AudiofileDecoderPlugin.cxx | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/decoder/plugins/AudiofileDecoderPlugin.cxx b/src/decoder/plugins/AudiofileDecoderPlugin.cxx index cd7021631..e78c156f9 100644 --- a/src/decoder/plugins/AudiofileDecoderPlugin.cxx +++ b/src/decoder/plugins/AudiofileDecoderPlugin.cxx @@ -54,17 +54,24 @@ struct AudioFileInputStream { }; gcc_pure +static double +audiofile_get_duration(AFfilehandle fh) +{ + double frame_count = afGetFrameCount(fh, AF_DEFAULT_TRACK); + double rate = afGetRate(fh, AF_DEFAULT_TRACK); + + return frame_count / rate; +} + +gcc_pure static int audiofile_get_duration(Path path_fs) { - int total_time; AFfilehandle af_fp = afOpenFile(path_fs.c_str(), "r", nullptr); if (af_fp == AF_NULL_FILEHANDLE) { return -1; } - total_time = (int) - ((double)afGetFrameCount(af_fp, AF_DEFAULT_TRACK) - / afGetRate(af_fp, AF_DEFAULT_TRACK)); + int total_time = int(audiofile_get_duration(af_fp)); afCloseFile(af_fp); return total_time; } |