예제 #1
0
 public static extern bool IsExtensionPresent([In] ALDevice device, [In] string extname);
예제 #2
0
 public static extern bool CloseDevice([In] ALDevice device);
예제 #3
0
 public static extern AlcError GetError([In] ALDevice device);
예제 #4
0
 public static extern void GetInteger(ALDevice device, AlcGetInteger param, int size, out int data);
예제 #5
0
파일: HRTF.cs 프로젝트: bclnet/DroidNet
 public static unsafe bool ResetDeviceSoft(ALDevice device, int[] attribs) => LoadDelegate <ResetDeviceSoftArrayDelegate>(device, "alcResetDeviceSOFT")(device, attribs);
예제 #6
0
 public static extern unsafe byte *GetStringPtr([In] ALDevice device, AlcGetString param);
예제 #7
0
        // ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );

        /// <summary>This function returns a List of strings related to the context.</summary>
        /// <remarks>
        ///     ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a
        ///     list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings
        ///     separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more
        ///     details.
        ///     ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will
        ///     return a list of all available devices if a NULL device pointer is supplied.
        ///     ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the
        ///     list terminated by a NULL character.
        /// </remarks>
        /// <param name="device">A pointer to the device to be queried.</param>
        /// <param name="param">
        ///     An attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER,
        ///     ALC_ALL_DEVICES_SPECIFIER.
        /// </param>
        /// <returns>A List of strings containing the names of the Devices.</returns>
        public static unsafe List <string> GetString(ALDevice device, AlcGetStringList param)
        {
            byte *result = GetStringPtr(device, (AlcGetString)param);

            return(ALStringListToList(result));
        }
예제 #8
0
 public static void GetInteger(ALDevice device, GetInteger64 param, int size, long[] values) => _GetIntegerArray(device, param, size, values);
예제 #9
0
 /// <summary>
 /// Checks whether the extension is present.
 /// </summary>
 /// <param name="device">The device to be queried.</param>
 /// <returns>Whether the extension was present or not.</returns>
 public static bool IsExtensionPresent(ALDevice device)
 {
     return(ALC.IsExtensionPresent(device, ExtensionName));
 }
예제 #10
0
#pragma warning disable SA1516 // Elements should be separated by blank line
        public static unsafe void GetInteger(ALDevice device, GetInteger64 param, int size, long *values) => _GetIntegerPtr(device, param, size, values);
예제 #11
0
 private static void GetInteger(ALDevice device, GetInteger64 param, int size, ref long values) => _GetIntegerRef(device, param, size, ref values);
예제 #12
0
 public static unsafe void GetInteger(ALDevice device, GetInteger64 param, Span <long> values)
 {
     GetInteger(device, param, values.Length, ref values[0]);
 }
예제 #13
0
#pragma warning restore SA1516 // Elements should be separated by blank line

        public static void GetInteger(ALDevice device, GetInteger64 param, long[] values)
        {
            GetInteger(device, param, values.Length, values);
        }
예제 #14
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello!");
            IEnumerable <string> devices = ALC.ALC.GetStringList(GetEnumerationStringList.DeviceSpecifier);

            Console.WriteLine($"Devices: {string.Join(", ", devices)}");

            // Get the default device, then go though all devices and select the AL soft device if it exists.
            string deviceName = ALC.ALC.GetString(ALDevice.Null, AlcGetString.DefaultDeviceSpecifier);

            foreach (string d in devices)
            {
                if (d.Contains("OpenAL Soft"))
                {
                    deviceName = d;
                }
            }

            IEnumerable <string> allDevices =
                EnumerateAll.GetStringList(GetEnumerateAllContextStringList.AllDevicesSpecifier);

            Console.WriteLine($"All Devices: {string.Join(", ", allDevices)}");

            ALDevice  device  = ALC.ALC.OpenDevice(deviceName);
            ALContext context = ALC.ALC.CreateContext(device, (int[])null);

            ALC.ALC.MakeContextCurrent(context);

            CheckALError("Start");

            ALC.ALC.GetInteger(device, AlcGetInteger.MajorVersion, 1, out int alcMajorVersion);
            ALC.ALC.GetInteger(device, AlcGetInteger.MinorVersion, 1, out int alcMinorVersion);
            string alcExts = ALC.ALC.GetString(device, AlcGetString.Extensions);

            ALContextAttributes attrs = ALC.ALC.GetContextAttributes(device);

            Console.WriteLine($"Attributes: {attrs}");

            string exts = AL.AL.Get(ALGetString.Extensions);
            string rend = AL.AL.Get(ALGetString.Renderer);
            string vend = AL.AL.Get(ALGetString.Vendor);
            string vers = AL.AL.Get(ALGetString.Version);

            Console.WriteLine(
                $"Vendor: {vend}, \nVersion: {vers}, \nRenderer: {rend}, \nExtensions: {exts}, \nALC Version: {alcMajorVersion}.{alcMinorVersion}, \nALC Extensions: {alcExts}");

            Console.WriteLine("Available devices: ");
            IEnumerable <string> list = EnumerateAll.GetStringList(GetEnumerateAllContextStringList.AllDevicesSpecifier);

            foreach (string item in list)
            {
                Console.WriteLine("  " + item);
            }

            Console.WriteLine("Available capture devices: ");
            list = ALC.ALC.GetStringList(GetEnumerationStringList.CaptureDeviceSpecifier);
            foreach (string item in list)
            {
                Console.WriteLine("  " + item);
            }

            int auxSlot = 0;

            if (EFX.IsExtensionPresent(device))
            {
                Console.WriteLine("EFX extension is present!!");
                EFX.GenEffect(out int effect);
                EFX.Effect(effect, EffectInteger.EffectType, (int)EffectType.Reverb);
                EFX.GenAuxiliaryEffectSlot(out auxSlot);
                EFX.AuxiliaryEffectSlot(auxSlot, EffectSlotInteger.Effect, effect);
            }

            // Record a second of data
            CheckALError("Before record");
            short[]         recording     = new short[44100 * 4];
            ALCaptureDevice captureDevice = ALC.ALC.CaptureOpenDevice(null, 44100, ALFormat.Mono16, 1024);

            {
                ALC.ALC.CaptureStart(captureDevice);

                int current = 0;
                while (current < recording.Length)
                {
                    int samplesAvailable = ALC.ALC.GetAvailableSamples(captureDevice);
                    if (samplesAvailable > 512)
                    {
                        int samplesToRead = Math.Min(samplesAvailable, recording.Length - current);
                        ALC.ALC.CaptureSamples(captureDevice, ref recording[current], samplesToRead);
                        current += samplesToRead;
                    }

                    Thread.Yield();
                }

                ALC.ALC.CaptureStop(captureDevice);
            }
            CheckALError("After record");

            // Playback the recorded data
            CheckALError("Before data");
            AL.AL.GenBuffer(out int alBuffer);
            // short[] sine = new short[44100 * 1];
            // FillSine(sine, 4400, 44100);
            // FillSine(recording, 440, 44100);
            AL.AL.BufferData(alBuffer, ALFormat.Mono16, ref recording[0], recording.Length * 2, 44100);
            CheckALError("After data");

            AL.AL.Listener(ALListenerf.Gain, 0.1f);

            AL.AL.GenSource(out int alSource);
            AL.AL.Source(alSource, ALSourcef.Gain, 1f);
            AL.AL.Source(alSource, ALSourcei.Buffer, alBuffer);
            if (EFX.IsExtensionPresent(device))
            {
                EFX.Source(alSource, EFXSourceInteger3.AuxiliarySendFilter, auxSlot, 0, 0);
            }

            AL.AL.SourcePlay(alSource);

            Console.WriteLine("Before Playing: " + AL.AL.GetErrorString(AL.AL.GetError()));

            if (DeviceClock.IsExtensionPresent(device))
            {
                long[] clockLatency = new long[2];
                DeviceClock.GetInteger(device, GetInteger64.DeviceClock, clockLatency);
                Console.WriteLine("Clock: " + clockLatency[0] + ", Latency: " + clockLatency[1]);
                CheckALError(" ");
            }

            if (SourceLatency.IsExtensionPresent())
            {
                SourceLatency.GetSource(alSource, SourceLatencyVector2d.SecOffsetLatency, out Vector2d values);
                SourceLatency.GetSource(alSource, SourceLatencyVector2i.SampleOffsetLatency, out int values1,
                                        out int values2, out long values3);
                Console.WriteLine("Source latency: " + values);
                Console.WriteLine($"Source latency 2: {Convert.ToString(values1, 2)}, {values2}; {values3}");
                CheckALError(" ");
            }

            while (AL.AL.GetSourceState(alSource) == ALSourceState.Playing)
            {
                if (SourceLatency.IsExtensionPresent())
                {
                    SourceLatency.GetSource(alSource, SourceLatencyVector2d.SecOffsetLatency, out Vector2d values);
                    SourceLatency.GetSource(alSource, SourceLatencyVector2i.SampleOffsetLatency, out int values1,
                                            out int values2, out long values3);
                    Console.WriteLine("Source latency: " + values);
                    Console.WriteLine($"Source latency 2: {Convert.ToString(values1, 2)}, {values2}; {values3}");
                    CheckALError(" ");
                }

                if (DeviceClock.IsExtensionPresent(device))
                {
                    long[] clockLatency = new long[2];
                    DeviceClock.GetInteger(device, GetInteger64.DeviceClock, 1, clockLatency);
                    Console.WriteLine("Clock: " + clockLatency[0] + ", Latency: " + clockLatency[1]);
                    CheckALError(" ");
                }

                Thread.Sleep(10);
            }

            AL.AL.SourceStop(alSource);

            // Test float32 format extension
            if (EXTFloat32.IsExtensionPresent())
            {
                Console.WriteLine("Testing float32 format extension with a sine wave...");

                float[] sine = new float[44100 * 2];
                for (int i = 0; i < sine.Length; i++)
                {
                    sine[i] = MathF.Sin(440 * MathF.PI * 2 * (i / (float)sine.Length));
                }

                int buffer = AL.AL.GenBuffer();
                EXTFloat32.BufferData(buffer, FloatBufferFormat.Mono, sine, 44100);

                AL.AL.Listener(ALListenerf.Gain, 0.1f);

                AL.AL.Source(alSource, ALSourcef.Gain, 1f);
                AL.AL.Source(alSource, ALSourcei.Buffer, buffer);

                AL.AL.SourcePlay(alSource);

                while (AL.AL.GetSourceState(alSource) == ALSourceState.Playing)
                {
                    Thread.Sleep(10);
                }

                AL.AL.SourceStop(alSource);
            }

            // Test double format extension
            if (EXTDouble.IsExtensionPresent())
            {
                Console.WriteLine("Testing float64 format extension with a saw wave...");

                double[] saw = new double[44100 * 2];
                for (int i = 0; i < saw.Length; i++)
                {
                    double t = i / (double)saw.Length * 440;
                    saw[i] = t - Math.Floor(t);
                }

                int buffer = AL.AL.GenBuffer();
                EXTDouble.BufferData(buffer, DoubleBufferFormat.Mono, saw, 44100);

                AL.AL.Listener(ALListenerf.Gain, 0.1f);

                AL.AL.Source(alSource, ALSourcef.Gain, 1f);
                AL.AL.Source(alSource, ALSourcei.Buffer, buffer);

                AL.AL.SourcePlay(alSource);

                while (AL.AL.GetSourceState(alSource) == ALSourceState.Playing)
                {
                    Thread.Sleep(10);
                }

                AL.AL.SourceStop(alSource);
            }


            ALC.ALC.MakeContextCurrent(ALContext.Null);
            ALC.ALC.DestroyContext(context);
            ALC.ALC.CloseDevice(device);

            Console.WriteLine("Goodbye!");

            Console.WriteLine("Playing sound...");
            ExampleSound();
            Console.WriteLine("Done!");
        }
예제 #15
0
 public static extern IntPtr GetProcAddress([In] ALDevice device, [In] string funcname);
예제 #16
0
 public static extern string GetString(ALDevice device, GetEnumerateAllContextString param);
예제 #17
0
 public static extern int GetEnumValue([In] ALDevice device, [In] string enumname);
예제 #18
0
 public static extern unsafe byte *GetStringList(ALDevice device, GetEnumerateAllContextStringList param);
예제 #19
0
 public static extern string GetString([In] ALDevice device, AlcGetString param);
예제 #20
0
 /// <summary>
 /// Checks whether the extension is present.
 /// </summary>
 /// <param name="device">The device to be queried.</param>
 /// <returns>Whether the extension was present or not.</returns>
 public static bool IsExtensionPresent(ALDevice device)
 => ALC.IsExtensionPresent(device, ExtensionName);
예제 #21
0
 public static extern unsafe void GetInteger(ALDevice device, AlcGetInteger param, int size, int *data);
예제 #22
0
 /// <summary>
 /// Gets a named property on the context.
 /// </summary>
 /// <param name="device">The device for the context.</param>
 /// <param name="param">The named property.</param>
 /// <returns>The value.</returns>
 [DllImport(ALC.Lib, EntryPoint = "alcGetString", ExactSpelling = true, CallingConvention = ALC.AlcCallingConv)] public static extern unsafe byte *GetStringList(ALDevice device, GetEnumerateAllContextStringList param);
예제 #23
0
        // ALC_API void            ALC_APIENTRY alcGetIntegerv( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *buffer );

        /// <summary>This function returns integers related to the context.</summary>
        /// <param name="device">A pointer to the device to be queried.</param>
        /// <param name="param">
        ///     An attribute to be retrieved: ALC_MAJOR_VERSION, ALC_MINOR_VERSION, ALC_ATTRIBUTES_SIZE,
        ///     ALC_ALL_ATTRIBUTES.
        /// </param>
        /// <param name="data">A pointer to the buffer to be returned.</param>
        public static void GetInteger(ALDevice device, AlcGetInteger param, out int data)
        {
            GetInteger(device, param, 1, out data);
        }
예제 #24
0
파일: HRTF.cs 프로젝트: bclnet/DroidNet
 public static unsafe bool ResetDeviceSoft(ALDevice device, ref int attribs) => LoadDelegate <ResetDeviceSoftRefDelegate>(device, "alcResetDeviceSOFT")(device, ref attribs);