-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding NVorbis as a submodule and adding *.ogg as a supported file fo…
…rmat
- Loading branch information
1 parent
3bd4ec1
commit 23afa30
Showing
9 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "taglib-sharp"] | ||
path = taglib-sharp | ||
url = https://github.com/tstavropoulos/taglib-sharp | ||
[submodule "NVorbis"] | ||
path = NVorbis | ||
url = https://github.com/ioctlLR/NVorbis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.IO; | ||
using CSCore; | ||
using NVorbis; | ||
|
||
namespace Musegician.Sources | ||
{ | ||
/// <summary> | ||
/// Stolen shamelessly from CSCore Examples | ||
/// </summary> | ||
public sealed class NVorbisSource : ISampleSource | ||
{ | ||
private readonly Stream _stream; | ||
private readonly VorbisReader _vorbisReader; | ||
private bool _disposed; | ||
|
||
public NVorbisSource(Stream stream) | ||
{ | ||
if (stream == null) | ||
{ | ||
throw new ArgumentNullException("stream"); | ||
} | ||
|
||
if (!stream.CanRead) | ||
{ | ||
throw new ArgumentException("Stream is not readable.", "stream"); | ||
} | ||
|
||
_stream = stream; | ||
_vorbisReader = new VorbisReader(stream, false); | ||
WaveFormat = new WaveFormat(_vorbisReader.SampleRate, 32, _vorbisReader.Channels, AudioEncoding.IeeeFloat); | ||
} | ||
|
||
public bool CanSeek => _stream.CanSeek; | ||
|
||
public WaveFormat WaveFormat { get; } | ||
|
||
public long Length => CanSeek ? | ||
(long)(_vorbisReader.TotalTime.TotalSeconds * WaveFormat.SampleRate * WaveFormat.Channels) : 0; | ||
|
||
public long Position | ||
{ | ||
get => CanSeek ? (long)(_vorbisReader.DecodedTime.TotalSeconds * _vorbisReader.SampleRate * _vorbisReader.Channels) : 0; | ||
set | ||
{ | ||
if (!CanSeek) | ||
{ | ||
throw new InvalidOperationException("NVorbisSource is not seekable."); | ||
} | ||
|
||
if (value < 0 || value > Length) | ||
{ | ||
throw new ArgumentOutOfRangeException("value"); | ||
} | ||
|
||
_vorbisReader.DecodedTime = TimeSpan.FromSeconds((double)value / _vorbisReader.SampleRate / _vorbisReader.Channels); | ||
} | ||
} | ||
|
||
public int Read(float[] buffer, int offset, int count) => | ||
_vorbisReader.ReadSamples(buffer, offset, count); | ||
|
||
public void Dispose() | ||
{ | ||
if (!_disposed) | ||
{ | ||
_vorbisReader.Dispose(); | ||
} | ||
else | ||
{ | ||
throw new ObjectDisposedException("NVorbisSource"); | ||
} | ||
|
||
_disposed = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters