Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
myd7349 committed Aug 11, 2024
1 parent e219ba9 commit c8724a8
Show file tree
Hide file tree
Showing 3 changed files with 598 additions and 28 deletions.
26 changes: 21 additions & 5 deletions Source/SharpLSL/Interop/Inlet.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,40 @@ public static unsafe partial class LSL
[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern double lsl_pull_sample_str(lsl_inlet @in, IntPtr[] buffer, int buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern double lsl_pull_sample_buf(lsl_inlet @in, IntPtr[] buffer, uint[] buffer_lengths, int buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern double lsl_pull_sample_v(lsl_inlet @in, byte[] buffer, int buffer_bytes, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_c(lsl_inlet @in, sbyte[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_s(lsl_inlet @in, short[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_i(lsl_inlet @in, int[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_f([NativeTypeName("lsl_inlet")] IntPtr @in, float[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
public static extern uint lsl_pull_chunk_l(lsl_inlet @in, long[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_d([NativeTypeName("lsl_inlet")] IntPtr @in, double[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
public static extern uint lsl_pull_chunk_f(lsl_inlet @in, float[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_l([NativeTypeName("lsl_inlet")] IntPtr @in, long[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
public static extern uint lsl_pull_chunk_d(lsl_inlet @in, double[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_i([NativeTypeName("lsl_inlet")] IntPtr @in, int[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
public static extern uint lsl_pull_chunk_str(lsl_inlet @in, IntPtr[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);

[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_s([NativeTypeName("lsl_inlet")] IntPtr @in, short[] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
public static extern uint lsl_pull_chunk_buf(lsl_inlet @in, IntPtr[] data_buffer, uint[] lengths_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);






[DllImport("lsl", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint lsl_pull_chunk_f([NativeTypeName("lsl_inlet")] IntPtr @in, float[,] data_buffer, double[] timestamp_buffer, uint data_buffer_elements, uint timestamp_buffer_elements, double timeout, ref int ec);
Expand Down
32 changes: 31 additions & 1 deletion Source/SharpLSL/LSL.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SharpLSL.Interop;

using static SharpLSL.Interop.LSL;

namespace SharpLSL
Expand Down Expand Up @@ -156,7 +158,7 @@ internal static string PtrToXmlString(IntPtr ptr)
{
return Marshal.PtrToStringAnsi(ptr);
}

#if !NET35
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
Expand Down Expand Up @@ -201,5 +203,33 @@ internal static void CheckSampleBuffer<T>(T[] sample, int channelCount)

CheckChannelCount(channelCount, sample.Length);
}

#if !NET35
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
internal static int CheckChunkBuffer<T>(T[] chunk, int channelCount)
{
if (chunk == null)
throw new ArgumentNullException(nameof(chunk));

if (chunk.Length == 0 || (chunk.Length % channelCount) != 0)
throw new ArgumentException(nameof(chunk));

return chunk.Length / channelCount;
}

#if !NET35
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
internal static void CheckTimestampBuffer(double[] timestamps, int samples)
{
Debug.Assert(samples > 0);

if (timestamps != null)
{
if (timestamps.Length != samples)
throw new ArgumentException($"Timestamps buffer size ({timestamps.Length}) does not match the number of samples ({samples}).");
}
}
}
}
Loading

0 comments on commit c8724a8

Please sign in to comment.