Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        public static Dictionary <double, double> SegmentAudioFile(string audioFile,
                                                                   int silenceThreshold, float clusterDuration, int clusterThreshold,
                                                                   float[] onsetDetectionValues)
        {
            var rubyScript =
                FileLocator.GetFileDistributedWithApplication("AutoSegmenter", "rubyscripts", "segmenter.rb");

            var libAubioFolder = Path.GetDirectoryName(
                FileLocator.GetFileDistributedWithApplication("AutoSegmenter", "libaudio", "aubioonset.exe"));

            if (!libAubioFolder.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)))
            {
                libAubioFolder += Path.DirectorySeparatorChar;
            }

            var runtime = Ruby.CreateRuntime();
            var engine  = runtime.GetEngine("rb");
            var paths   = engine.GetSearchPaths().ToList();

            paths.Add(Path.GetDirectoryName(rubyScript));
            engine.SetSearchPaths(paths);

            engine.Runtime.ExecuteFile(rubyScript);
            var segmenterObj  = engine.Runtime.Globals.GetVariable("Segmenter");
            var segmenterInst = engine.Operations.CreateInstance(segmenterObj);

            engine.Operations.InvokeMember(segmenterInst, "initFromCSharp",
                                           silenceThreshold, clusterDuration, clusterThreshold, onsetDetectionValues);

            IronRuby.Builtins.Hash returnValues = engine.Operations.InvokeMember(segmenterInst,
                                                                                 "processFromCSharp", libAubioFolder, audioFile);

            return(returnValues.ToDictionary(kvp => (double)kvp.Key, kvp => (double)kvp.Value));
        }
Esempio n. 2
0
        protected static IronRuby.Builtins.Hash ParseObject(char[] json, ref int index, ref bool success)
        {
            IronRuby.Builtins.Hash table = RhoRuby.createHash();
            int token;

            // {
            NextToken(json, ref index);

            bool done = false;

            while (!done)
            {
                token = LookAhead(json, index);
                if (token == TOKEN_NONE)
                {
                    success = false;
                    return(null);
                }
                else if (token == TOKEN_COMMA)
                {
                    NextToken(json, ref index);
                }
                else if (token == TOKEN_CURLY_CLOSE)
                {
                    NextToken(json, ref index);
                    return(table);
                }
                else
                {
                    // name
                    object name = ParseString(json, ref index, ref success);
                    if (!success)
                    {
                        success = false;
                        return(null);
                    }

                    // :
                    token = NextToken(json, ref index);
                    if (token != TOKEN_COLON)
                    {
                        success = false;
                        return(null);
                    }

                    // value
                    object value = ParseValue(json, ref index, ref success);
                    if (!success)
                    {
                        success = false;
                        return(null);
                    }

                    table[name] = value;
                }
            }

            return(table);
        }