decoder/audiofile: split audiofile_get_duration()
This commit is contained in:
parent
9ddb5931fb
commit
2e1347aba4
@ -53,18 +53,25 @@ 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
|
gcc_pure
|
||||||
static int
|
static int
|
||||||
audiofile_get_duration(Path path_fs)
|
audiofile_get_duration(Path path_fs)
|
||||||
{
|
{
|
||||||
int total_time;
|
|
||||||
AFfilehandle af_fp = afOpenFile(path_fs.c_str(), "r", nullptr);
|
AFfilehandle af_fp = afOpenFile(path_fs.c_str(), "r", nullptr);
|
||||||
if (af_fp == AF_NULL_FILEHANDLE) {
|
if (af_fp == AF_NULL_FILEHANDLE) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
total_time = (int)
|
int total_time = int(audiofile_get_duration(af_fp));
|
||||||
((double)afGetFrameCount(af_fp, AF_DEFAULT_TRACK)
|
|
||||||
/ afGetRate(af_fp, AF_DEFAULT_TRACK));
|
|
||||||
afCloseFile(af_fp);
|
afCloseFile(af_fp);
|
||||||
return total_time;
|
return total_time;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user