Code Monkey home page Code Monkey logo

Comments (12)

andymule avatar andymule commented on May 17, 2024 1

Yeah should be done and checked in next week

from mixedrealitytoolkit-unity.

jwittner avatar jwittner commented on May 17, 2024 1

@andymule Looks like maybe we've got a couple implementations here. Reasons to wait on yours or should @stbertou just make a PR?

from mixedrealitytoolkit-unity.

andymule avatar andymule commented on May 17, 2024 1

Hey guys, didn't see all this talk until now. There are official PRs out on this repo and a matching one going into the main Holotoolkit. It should all be good to go everywhere. Please use excessively and make changes as you see fit. Cheers!

from mixedrealitytoolkit-unity.

NeerajW avatar NeerajW commented on May 17, 2024

@andymule are you working on this currently?

from mixedrealitytoolkit-unity.

stbertou avatar stbertou commented on May 17, 2024

Great news !
On Friday last week I gave it a quick go, here is the c# bindings that seem to work except for MicGetFrame that I ignored.
You probably have done that already anyway but just in case here it is:

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

namespace HoloToolkit.Unity
{
    public class MicStreamSelector
    {
        #region Public APIs

        public static int MicInitialize(int category, int fftsize, int numBuffers, int samplerate)
        {
            return DLLImports.MicInitialize(category, fftsize, numBuffers, samplerate);
        }

        public static int MicStartStream(bool keepData)
        {
            return DLLImports.MicStartStream(keepData);
        }

        public static int MicStopStream()
        {
            return DLLImports.MicStopStream();
        }

        public static int MicStartRecording(String filename)
        {
            return DLLImports.MicStartRecording(filename);
        }

        public static int MicPause()
        {
            return DLLImports.MicPause();
        }

        public static int MicResume()
        {
            return DLLImports.MicResume();
        }

        public static int MicSetGain(float gain)
        {
            return DLLImports.MicSetGain(gain);
        }

        public static int MicDestroy()
        {
            return DLLImports.MicDestroy();
        }

        #endregion

        #region Internal

        /// <summary>
        /// Raw MicStreamSelector.dll imports
        /// </summary>
        private class DLLImports
        {
            [DllImport("MicStreamSelector")]
            public static extern int MicInitialize(
                [In] int category,
                [In] int fftsize,
                [In] int numBuffers,
                [In] int samplerate);

            [DllImport("MicStreamSelector")]
            public static extern int MicStartStream(
                [In] bool keepData);

            [DllImport("MicStreamSelector")]
            public static extern int MicStopStream();

            [DllImport("MicStreamSelector")]
            public static extern int MicStartRecording(
                [In] String filename);

            [DllImport("MicStreamSelector")]
            public static extern int MicStopRecording(
                [In] String path);

            /*
            [DllImport("MicStreamSelector")]
            public static extern int MicGetFrame(// float * 
                [In] int length,
                [In] int numchannels
                );
            */

            [DllImport("MicStreamSelector")]
            public static extern int MicPause();

            [DllImport("MicStreamSelector")]
            public static extern int MicResume();

            [DllImport("MicStreamSelector")]
            public static extern int MicSetGain(
                [In] float gain);

            [DllImport("MicStreamSelector")]
            public static extern int MicDestroy();
        }

        #endregion
    }
}

from mixedrealitytoolkit-unity.

stbertou avatar stbertou commented on May 17, 2024

Here is a new version kindly improved by Dave Sullivan here in London

using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

#if NETFX_CORE
using Windows.Storage;
#endif

namespace HoloToolkit.Unity
{
    public class MicStreamSelector
    {
        public enum ErrorCode
        {
            ALREADY_RUNNING = -10,
            NO_AUDIO_DEVICE,
            NO_INPUT_DEVICE,
            ALREADY_RECORDING,
            GRAPH_NOT_EXIST,
            CHANNEL_COUNT_MISMATCH,
            FILE_CREATION_PERMISSION_ERROR,
            NOT_IMPLEMENTED = -1,
            SUCCESS = 0
        }
#region Public APIs

        public static ErrorCode MicInitialize(int category, int fftsize, int numBuffers, int samplerate)
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicInitialize(category, fftsize, numBuffers, samplerate);
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicStartStream(bool keepData)
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicStartStream(keepData);
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicStopStream()
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicStopStream();
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicStartRecording(String filename)
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicStartRecording(filename);
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicStopRecording(ref String filename)
        {
#if NETFX_CORE
            string originalFilename = filename;

            IntPtr msgBuffer = Marshal.AllocHGlobal(256);

            try
            {
                Marshal.WriteByte(msgBuffer, 0);
                DLLImports.MicStopRecording(msgBuffer);
                filename = Marshal.PtrToStringAnsi(msgBuffer);
            }
            finally
            {
                Marshal.FreeHGlobal(msgBuffer);
            }

            //Debug.LogFormat("New audio filename is {0}", filename);
            //filename = System.IO.Path.Combine(KnownFolders.MusicLibrary.Path, filename);

            var fileInfo = new FileInfo(filename);
            if (fileInfo.Exists)
            {
                return ErrorCode.SUCCESS;
            }

            return ErrorCode.FILE_CREATION_PERMISSION_ERROR;
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicPause()
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicPause();
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicResume()
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicResume();
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicSetGain(float gain)
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicSetGain(gain);
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

        public static ErrorCode MicDestroy()
        {
#if NETFX_CORE
            return (ErrorCode)DLLImports.MicDestroy();
#else
            return ErrorCode.NOT_IMPLEMENTED;
#endif
        }

#endregion

#region Internal

        /// <summary>
        /// Raw MicStreamSelector.dll imports
        /// </summary>
        private class DLLImports
        {
            [DllImport("MicStreamSelector")]
            public static extern int MicInitialize(
                [In] int category,
                [In] int fftsize,
                [In] int numBuffers,
                [In] int samplerate);

            [DllImport("MicStreamSelector")]
            public static extern int MicStartStream(
                [In] bool keepData);

            [DllImport("MicStreamSelector")]
            public static extern int MicStopStream();

            [DllImport("MicStreamSelector")]
            public static extern int MicStartRecording(
                [In] String filename);

            [DllImport("MicStreamSelector")]
            public static extern void MicStopRecording(
                [In] IntPtr path);

            /*
            [DllImport("MicStreamSelector")]
            public static extern int MicGetFrame(// float * 
                [In] int length,
                [In] int numchannels
                );
            */

            [DllImport("MicStreamSelector")]
            public static extern int MicPause();

            [DllImport("MicStreamSelector")]
            public static extern int MicResume();

            [DllImport("MicStreamSelector")]
            public static extern int MicSetGain(
                [In] float gain);

            [DllImport("MicStreamSelector")]
            public static extern int MicDestroy();
        }

#endregion
    }
}

from mixedrealitytoolkit-unity.

DanHolbert avatar DanHolbert commented on May 17, 2024

Thanks for this, Dave and Stephane. The MicStream code is still under some internal development, so I’m not sure how much of the changes will make it into HoloToolkit, but we’ll look at it. In particular, I’m not sure why it’s returning NOT_IMPLEMENTED when you’re not running NETFX_CORE, as the code works fine running in the Unity editor on Windows 10, and having the code run in the Unity editor makes development much easier.

from mixedrealitytoolkit-unity.

stbertou avatar stbertou commented on May 17, 2024

I'll let @DaveSullivanAtWork comment here but he told me the DLL was somehow not working from within the editor

from mixedrealitytoolkit-unity.

jwittner avatar jwittner commented on May 17, 2024

@DanHolbert mind if I clean up your comment? It's full of the reply text from the email and is cluttering up this thread.

from mixedrealitytoolkit-unity.

DanHolbert avatar DanHolbert commented on May 17, 2024

Done. I didn't realize that email replies were generating GitHub comments.

Regarding the DLL not working in editor, I know it's been under some revision lately. It's possible some of the revision addressed this, although I'd lean toward not. @DaveSullivanAtWork, do you have any details on what wasn't working?

from mixedrealitytoolkit-unity.

jwittner avatar jwittner commented on May 17, 2024

@andymule is this done? Can we get a PR?

from mixedrealitytoolkit-unity.

jwittner avatar jwittner commented on May 17, 2024

Thanks @andymule! - #117

from mixedrealitytoolkit-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.