mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Robust.Client.Graphics.Audio
|
|
{
|
|
internal partial class ClydeAudio
|
|
{
|
|
private OggVorbisData _readOggVorbis(Stream stream)
|
|
{
|
|
using (var vorbis = new NVorbis.VorbisReader(stream, false))
|
|
{
|
|
var sampleRate = vorbis.SampleRate;
|
|
var channels = vorbis.Channels;
|
|
var totalSamples = vorbis.TotalSamples;
|
|
|
|
var readSamples = 0;
|
|
var buffer = new float[totalSamples * channels];
|
|
|
|
while (readSamples < totalSamples)
|
|
{
|
|
var read = vorbis.ReadSamples(buffer, readSamples * channels, buffer.Length - readSamples);
|
|
if (read == 0)
|
|
{
|
|
break;
|
|
}
|
|
|
|
readSamples += read;
|
|
}
|
|
|
|
return new OggVorbisData(totalSamples, sampleRate, channels, buffer, vorbis.Tags.Title, vorbis.Tags.Artist);
|
|
}
|
|
}
|
|
|
|
private readonly struct OggVorbisData
|
|
{
|
|
public readonly long TotalSamples;
|
|
public readonly long SampleRate;
|
|
public readonly long Channels;
|
|
public readonly ReadOnlyMemory<float> Data;
|
|
public readonly string Title;
|
|
public readonly string Artist;
|
|
|
|
public OggVorbisData(long totalSamples, long sampleRate, long channels, ReadOnlyMemory<float> data, string title, string artist)
|
|
{
|
|
TotalSamples = totalSamples;
|
|
SampleRate = sampleRate;
|
|
Channels = channels;
|
|
Data = data;
|
|
Title = title;
|
|
Artist = artist;
|
|
}
|
|
}
|
|
}
|
|
}
|