Exemple #1
0
        public string GetParamString(Out123.Params aParam)
        {
            long   null_value  = 0; // not interested in int value because want the string value.
            double null_fvalue = 0; // not interested in double value because want the string value.
            IntPtr strPtr      = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref null_value, ref null_fvalue, strPtr);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }

            IntPtr subPtr = Marshal.ReadIntPtr(strPtr);

            if (subPtr == IntPtr.Zero)
            {
                Marshal.FreeHGlobal(strPtr);
                throw new Out123.ErrorException("unknow error");
            }
            else
            {
                string result = Marshal.PtrToStringAnsi(subPtr);
                Marshal.FreeHGlobal(strPtr);
                return(result);
            }
        }
Exemple #2
0
        public void Open(string driver = null, string device = null)
        {
            IntPtr driverPtr = IntPtr.Zero;
            IntPtr devicePtr = IntPtr.Zero;

            if (driver != null)
            {
                driverPtr = Marshal.StringToHGlobalAnsi(driver);
            }
            if (device != null)
            {
                devicePtr = Marshal.StringToHGlobalAnsi(device);
            }

            Out123.Errors error = Out123NativeMethods.Open(handle, driverPtr, devicePtr);
            if (driverPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(driverPtr);
            }
            if (devicePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(devicePtr);
            }

            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(this);
            }
        }
Exemple #3
0
        public IEnumerable <Out123.Driver> Drivers()
        {
            IntPtr namesPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr descsPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.Drivers(handle, namesPtr, descsPtr);
            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(namesPtr);
                Marshal.FreeHGlobal(descsPtr);
                throw new Out123.ErrorException(this);
            }

            IntPtr namesPtrDeref = Marshal.ReadIntPtr(namesPtr);
            IntPtr descsPtrDeref = Marshal.ReadIntPtr(descsPtr);
            int    offset        = 0;

            while (true)
            {
                IntPtr namePtr = Marshal.ReadIntPtr(namesPtrDeref, offset);
                IntPtr descPtr = Marshal.ReadIntPtr(descsPtrDeref, offset);
                if (namePtr == IntPtr.Zero)
                {
                    yield break;
                }

                String        name   = Marshal.PtrToStringAnsi(namePtr);
                String        desc   = Marshal.PtrToStringAnsi(descPtr);
                Out123.Driver driver = new Out123.Driver(name, desc);

                yield return(driver);

                offset += Marshal.SizeOf <IntPtr>();
            }
        }
Exemple #4
0
        public string LastErrorString()
        {
            IntPtr errorPtr = Out123NativeMethods.StrError(handle);

            Console.WriteLine("2: " + handle.ToInt64());
            return(Marshal.PtrToStringAnsi(errorPtr));
        }
Exemple #5
0
 public void SetParamInt(Out123.Params aParam, long value)
 {
     Out123.Errors error = Out123NativeMethods.Param(handle, aParam, new IntPtr(value), 0, IntPtr.Zero);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Exemple #6
0
 public void SetParamFloat(Out123.Params aParam, double value)
 {
     Out123.Errors error = Out123NativeMethods.Param(handle, aParam, IntPtr.Zero, value, IntPtr.Zero);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Exemple #7
0
 public void CopyParamFrom(Out123 other)
 {
     Out123.Errors error = Out123NativeMethods.ParamFrom(handle, other.handle);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Exemple #8
0
 public void Start(long rate, int channels, int encoding)
 {
     Out123.Errors error = Out123NativeMethods.Start(handle, new IntPtr(rate), channels, encoding);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(this);
     }
 }
Exemple #9
0
 public void SetBufferSize(ulong bufferSize)
 {
     Out123.Errors error = Out123NativeMethods.SetBuffer(handle, new UIntPtr(bufferSize));
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Exemple #10
0
        public int EncodingsFor(long rate, int channels)
        {
            int result = Out123NativeMethods.Encodings(handle, new IntPtr(rate), channels);

            if (result == -1)
            {
                throw new Out123.ErrorException(this);
            }
            return(result);
        }
Exemple #11
0
 public Out123(string pluginFolder = "./plugins")
 {
     System.Environment.SetEnvironmentVariable("MPG123_MODDIR", pluginFolder);
     handle = Out123NativeMethods.New();
     if (handle == IntPtr.Zero)
     {
         System.Environment.SetEnvironmentVariable("MPG123_BINDIR", ""); //remove env variable
         throw new Out123.ErrorException("Unable to initialize lib Out123");
     }
 }
Exemple #12
0
        public ulong Play(byte[] buffer)
        {
            IntPtr bufferPtr = Marshal.AllocHGlobal(Marshal.SizeOf <byte>() * buffer.Length);

            Marshal.Copy(buffer, 0, bufferPtr, buffer.Length);
            UIntPtr size = Out123NativeMethods.Play(handle, bufferPtr, new UIntPtr((ulong)buffer.Length));

            Marshal.FreeHGlobal(bufferPtr);
            return(size.ToUInt64());
        }
Exemple #13
0
 public void Drain(ulong nummberOfBytesToDrain = 0)
 {
     if (nummberOfBytesToDrain == 0)
     {
         Out123NativeMethods.Drain(handle);
     }
     else
     {
         Out123NativeMethods.NDrain(handle, new UIntPtr(nummberOfBytesToDrain));
     }
 }
Exemple #14
0
        public static string PlainStrError(Errors error)
        {
            IntPtr errorPtr = Out123NativeMethods.PlainStrError(error);

            if (errorPtr == IntPtr.Zero)
            {
                return("unknown error");
            }
            string errorMessage = Marshal.PtrToStringAnsi(errorPtr);

            return(errorMessage);
        }
Exemple #15
0
        public double GetParamFloat(Out123.Params aParam)
        {
            long   null_value  = 0;           // not interested in int value because want the doule value.
            double result      = 0;
            IntPtr null_sValue = IntPtr.Zero; // not interested in sValue because want the doule value.

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref null_value, ref result, null_sValue);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(this);
            }
            return(result);
        }
Exemple #16
0
        public long GetParamInt(Out123.Params aParam)
        {
            long   result      = 0;
            double null_fValue = 0; // not interested in float value because want the int value.
            IntPtr null_sValue = IntPtr.Zero;

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref result, ref null_fValue, null_sValue);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }
            return(result);
        }
Exemple #17
0
        public void SetParamString(Out123.Params aParam, string value)
        {
            IntPtr sValuePtr = IntPtr.Zero;

            if (sValuePtr != null)
            {
                sValuePtr = Marshal.StringToHGlobalAnsi(value);
            }
            Out123.Errors result = Out123NativeMethods.Param(handle, aParam, IntPtr.Zero, 0, sValuePtr);
            if (sValuePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(sValuePtr);
            }
        }
Exemple #18
0
        protected void Dispose(bool isDisposingManually)
        {
            if (isDisposed)
            {
                return;
            }

            if (handle != IntPtr.Zero)
            {
                Out123NativeMethods.Del(handle);
                handle = IntPtr.Zero;
            }

            if (isDisposingManually)
            {
                // cleanup dependancies
            }

            isDisposed = true;
        }
Exemple #19
0
        public Out123.DriverInfo GetDriverInfo()
        {
            IntPtr driverPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr devicePtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.DriverInfo(handle, driverPtr, devicePtr);

            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(driverPtr);
                Marshal.FreeHGlobal(devicePtr);
                throw new Out123.ErrorException(error);
            }

            IntPtr driver = Marshal.ReadIntPtr(driverPtr);
            IntPtr device = Marshal.ReadIntPtr(devicePtr);

            Out123.DriverInfo result = new Out123.DriverInfo(Marshal.PtrToStringAnsi(driver), Marshal.PtrToStringAnsi(device));
            Marshal.FreeHGlobal(driverPtr);
            Marshal.FreeHGlobal(devicePtr);

            return(result);
        }
Exemple #20
0
        public void DriverInfo()
        {
            IntPtr driverPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr devicePtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.DriverInfo(handle, driverPtr, devicePtr);
            Console.WriteLine(error);
            Console.WriteLine(LastErrorCode());
            Console.WriteLine(LastErrorString());

            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }

            /*
             * IntPtr driver = Marshal.ReadIntPtr(driverPtr);
             * IntPtr device = Marshal.ReadIntPtr(devicePtr);
             *
             * Console.WriteLine(driver.ToString());
             * Console.WriteLine(device.ToString());
             */
        }
Exemple #21
0
        public Out123.Format GetFormat()
        {
            IntPtr rate      = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr channels  = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr encoding  = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr framesize = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.GetFormat(handle, rate, channels, encoding, framesize);
            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(rate);
                Marshal.FreeHGlobal(channels);
                Marshal.FreeHGlobal(encoding);
                Marshal.FreeHGlobal(framesize);
                throw new Out123.ErrorException(this);
            }

            Out123.Format result = new Out123.Format(rate.ToInt64(), channels.ToInt32(), encoding.ToInt32(), framesize.ToInt32());
            Marshal.FreeHGlobal(rate);
            Marshal.FreeHGlobal(channels);
            Marshal.FreeHGlobal(encoding);
            Marshal.FreeHGlobal(framesize);
            return(result);
        }
Exemple #22
0
        public string LastErrorString()
        {
            IntPtr errorPtr = Out123NativeMethods.StrError(handle);

            return(Marshal.PtrToStringAnsi(errorPtr));
        }
Exemple #23
0
 public void Close()
 {
     Out123NativeMethods.Close(handle);
 }
Exemple #24
0
 public void Pause()
 {
     Out123NativeMethods.Pause(handle);
 }
Exemple #25
0
 public int EncodingSize(int encoding)
 {
     return(Out123NativeMethods.Encsize(encoding));
 }
Exemple #26
0
 public Out123.Errors LastErrorCode()
 {
     return(Out123NativeMethods.ErrCode(handle));
 }
Exemple #27
0
 public ulong Buffered()
 {
     return(Out123NativeMethods.Buffered(handle).ToUInt64());
 }
Exemple #28
0
 public void Continue()
 {
     Out123NativeMethods.Continue(handle);
 }
Exemple #29
0
 public void Stop()
 {
     Out123NativeMethods.Stop(handle);
 }
Exemple #30
0
 public void Drop()
 {
     Out123NativeMethods.Drop(handle);
 }