mirror of https://github.com/adamdruppe/arsd.git
some more seek helpers
This commit is contained in:
parent
293f9ce2a8
commit
e6eac2c2cf
17
mp3.d
17
mp3.d
|
@ -53,7 +53,7 @@ class MP3Decoder {
|
||||||
alias ReadBufFn = int delegate (void[] buf);
|
alias ReadBufFn = int delegate (void[] buf);
|
||||||
|
|
||||||
private int delegate (ubyte[] buf) reader;
|
private int delegate (ubyte[] buf) reader;
|
||||||
private int delegate(size_t where) seeker;
|
private int delegate(ulong where) seeker;
|
||||||
|
|
||||||
private mp3dec_io_t io;
|
private mp3dec_io_t io;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class MP3Decoder {
|
||||||
I realize these are all breaking changes, but the fix is easy and the new functionality,
|
I realize these are all breaking changes, but the fix is easy and the new functionality,
|
||||||
the [seek] function among others, is worth it. To me anyway, and I hope for you too.
|
the [seek] function among others, is worth it. To me anyway, and I hope for you too.
|
||||||
+/
|
+/
|
||||||
this (int delegate (ubyte[] buf) reader, int delegate(size_t where) seeker) {
|
this (int delegate (ubyte[] buf) reader, int delegate(ulong where) seeker) {
|
||||||
if (reader is null)
|
if (reader is null)
|
||||||
throw new Exception("reader is null");
|
throw new Exception("reader is null");
|
||||||
if (seeker is null)
|
if (seeker is null)
|
||||||
|
@ -234,6 +234,17 @@ class MP3Decoder {
|
||||||
return (valid ? dec.info.bitrate_kbps : 0);
|
return (valid ? dec.info.bitrate_kbps : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/++
|
||||||
|
Returns the duration of the mp3, in seconds, if available, or `float.nan` if it is unknown
|
||||||
|
(unknown may happen because it is an unseekable stream without metadata).
|
||||||
|
|
||||||
|
History:
|
||||||
|
Added November 26, 2022 (dub v10.10)
|
||||||
|
+/
|
||||||
|
@property float duration() const pure nothrow @safe @nogc {
|
||||||
|
return (valid ? (cast(float) dec.samples / sampleRate / channels) : float.nan);
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Returns the number of samples in the current frame, as prepared by [decodeNextFrame].
|
Returns the number of samples in the current frame, as prepared by [decodeNextFrame].
|
||||||
|
|
||||||
|
@ -257,6 +268,8 @@ class MP3Decoder {
|
||||||
|
|
||||||
Is you want something that never allocates, see [frameSamplesFloat].
|
Is you want something that never allocates, see [frameSamplesFloat].
|
||||||
|
|
||||||
|
Please note that you MUST call [decodeNextFrame] first.
|
||||||
|
|
||||||
See_Also:
|
See_Also:
|
||||||
[frameSamplesFloat], [decodeNextFrame]
|
[frameSamplesFloat], [decodeNextFrame]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue