2022-08-02 20:50:03 +00:00
|
|
|
|
using System;
|
2022-08-02 06:02:13 +00:00
|
|
|
|
using MoonWorks.Audio;
|
|
|
|
|
|
|
|
|
|
namespace MoonWorks.Video
|
|
|
|
|
{
|
|
|
|
|
public unsafe class StreamingSoundTheora : StreamingSound
|
|
|
|
|
{
|
2022-08-02 06:14:45 +00:00
|
|
|
|
private IntPtr VideoHandle;
|
2022-08-02 20:50:03 +00:00
|
|
|
|
protected override int BUFFER_SIZE => 8192;
|
2022-08-02 06:02:13 +00:00
|
|
|
|
|
|
|
|
|
internal StreamingSoundTheora(
|
|
|
|
|
AudioDevice device,
|
|
|
|
|
IntPtr videoHandle,
|
|
|
|
|
int channels,
|
|
|
|
|
uint sampleRate
|
|
|
|
|
) : base(
|
|
|
|
|
device,
|
|
|
|
|
3, /* float type */
|
|
|
|
|
32, /* size of float */
|
|
|
|
|
(ushort) (4 * channels),
|
|
|
|
|
(ushort) channels,
|
|
|
|
|
sampleRate
|
|
|
|
|
) {
|
|
|
|
|
VideoHandle = videoHandle;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 06:22:00 +00:00
|
|
|
|
protected override unsafe void FillBuffer(
|
2022-08-02 06:02:13 +00:00
|
|
|
|
void* buffer,
|
2022-08-02 20:50:03 +00:00
|
|
|
|
int bufferLengthInBytes,
|
|
|
|
|
out int filledLengthInBytes,
|
2022-08-02 06:02:13 +00:00
|
|
|
|
out bool reachedEnd
|
|
|
|
|
) {
|
2022-08-02 20:50:03 +00:00
|
|
|
|
var lengthInFloats = bufferLengthInBytes / sizeof(float);
|
|
|
|
|
|
2022-08-02 06:02:13 +00:00
|
|
|
|
int samples = Theorafile.tf_readaudio(
|
|
|
|
|
VideoHandle,
|
|
|
|
|
(IntPtr) buffer,
|
2022-08-02 20:50:03 +00:00
|
|
|
|
lengthInFloats
|
2022-08-02 06:02:13 +00:00
|
|
|
|
);
|
|
|
|
|
|
2022-08-02 20:50:03 +00:00
|
|
|
|
filledLengthInBytes = samples * sizeof(float);
|
2022-08-02 06:02:13 +00:00
|
|
|
|
reachedEnd = Theorafile.tf_eos(VideoHandle) == 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|