using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UMP.Wrappers;
///
/// VLC sound formats
///
internal enum SoundType
{
///
/// 16 bits per sample
///
S16N
}
internal class PlayerBufferSound
{
public const int DEFAULT_CLIP_SAMPLES_SIZE = 65536;
public const int BITS_PER_SAMPLE = 16;
private readonly float[] _samplesData;
private GCHandle _gcHandle = default(GCHandle);
public static SoundType GetSoundType(string format)
{
switch (format)
{
case "S16N":
return SoundType.S16N;
default:
return SoundType.S16N;
}
}
///
/// Initializes new instance of SoundFormat class
///
///
///
public PlayerBufferSound(int rate, int channels)
{
SoundType = SoundType.S16N;
Rate = rate;
Channels = channels;
_samplesData = new float[2048];
}
public void UpdateSamplesData(IntPtr samples, uint count)
{
/*_nativeHelper.NativeHelperGetAudioSamples()
lock (_samplesData)
{
int audioFrameLength = BlockSize * (int)count;
IntPtr point = IntPtr.Zero;//_nativeHelper.NativeHelperGetAudioSamples(samples, audioFrameLength);
float[] buffer = new float[audioFrameLength / 2];
Marshal.Copy(point, buffer, 0, buffer.Length);
if (UMPSettings.SupportedPlatform == UMPSettings.Platforms.Win)
Marshal.FreeCoTaskMem(point);
_samplesData.AddRange(buffer);
buffer = null;
}*/
}
///
/// Sampling rate in Hz
///
public int Rate { get; private set; }
///
/// Number of channels used by audio sample
///
public int Channels { get; private set; }
///
/// Size of single audio sample in bytes
///
public int BitsPerSample { get; private set; }
///
/// Specifies sound sample format
///
public SoundType SoundType { get; private set; }
///
/// Size of audio block (BitsPerSample / 8 * Channels)
///
public int BlockSize { get; private set; }
///
/// Gets the decoded audio samples.
///
public float[] SamplesData
{
get { return _samplesData; }
}
internal IntPtr SamplesDataAddr
{
get
{
if (!_gcHandle.IsAllocated)
_gcHandle = GCHandle.Alloc(_samplesData, GCHandleType.Pinned);
return _gcHandle.AddrOfPinnedObject();
}
}
///
/// Playback time stamp in microseconds
///
public long Pts { get; set; }
}