Exemplo n.º 1
0
        public IAsyncOperation <AudioFrameReader> OpenAudioFrameReaderAsync()
        {
            return(Task.Run(async() =>
            {
                if (AudioReader == null)
                {
                    var microphones = await DeviceInformation.FindAllAsync(DeviceInformation.GetAqsFilterFromDeviceClass(DeviceClass.AudioCapture));
                    var kinectMicArray = microphones.FirstOrDefault(mic => mic.Name.ToLowerInvariant().Contains("xbox nui sensor"));

                    if (kinectMicArray != null)
                    {
                        //TODO: review parameters
                        var settings = new AudioGraphSettings(AudioRenderCategory.Speech);
                        settings.EncodingProperties = AudioEncodingProperties.CreatePcm(16000, 4, 32);
                        settings.EncodingProperties.Subtype = MediaEncodingSubtypes.Float;
                        settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency;
                        settings.DesiredRenderDeviceAudioProcessing = Windows.Media.AudioProcessing.Raw;

                        var audioGraphResult = await AudioGraph.CreateAsync(settings);
                        if (audioGraphResult.Status == AudioGraphCreationStatus.Success)
                        {
                            var inputNodeResult = await audioGraphResult.Graph.CreateDeviceInputNodeAsync(MediaCategory.Speech, audioGraphResult.Graph.EncodingProperties, kinectMicArray);

                            if (inputNodeResult.Status == AudioDeviceNodeCreationStatus.Success)
                            {
                                var output = audioGraphResult.Graph.CreateFrameOutputNode(audioGraphResult.Graph.EncodingProperties);
                                AudioReader = new AudioFrameReader(audioGraphResult.Graph, output);
                            }
                        }
                    }
                }
                AudioReader?.Open();
                return AudioReader;
            }).AsAsyncOperation());
        }
Exemplo n.º 2
0
 AudioReader Import(string fileName)
 {
     browser.FileName = fileName;
     if (browser.ShowDialog().Value)
     {
         return(AudioReader.Open(browser.FileName));
     }
     return(null);
 }
Exemplo n.º 3
0
        void ProcessImpulse(object sender, RoutedEventArgs e)
        {
            if (browser.ShowDialog().Value)
            {
                AudioReader reader  = AudioReader.Open(browser.FileName);
                float[]     impulse = reader.Read();
                float       gain    = 1;
                if (keepGain.IsChecked.Value)
                {
                    gain = WaveformUtils.GetPeak(impulse);
                }

                if (commonEQ.IsChecked.Value)
                {
                    ProcessCommon(reader, ref impulse);
                }
                else
                {
                    ProcessPerChannel(reader, ref impulse);
                }

                if (keepGain.IsChecked.Value)
                {
                    WaveformUtils.Gain(impulse, gain / WaveformUtils.GetPeak(impulse));
                }

                BitDepth bits = reader.Bits;
                if (forceFloat.IsChecked.Value)
                {
                    bits = BitDepth.Float32;
                }

                int targetLen = QMath.Base2Ceil((int)reader.Length);
                if (separateExport.IsChecked.Value)
                {
                    ReferenceChannel[] channels = ChannelPrototype.GetStandardMatrix(reader.ChannelCount);
                    for (int ch = 0; ch < reader.ChannelCount; ++ch)
                    {
                        string exportName  = Path.GetFileName(browser.FileName);
                        int    idx         = exportName.LastIndexOf('.');
                        string channelName = ChannelPrototype.Mapping[(int)channels[ch]].Name;
                        exporter.FileName = $"{exportName[..idx]} - {channelName}{exportName[idx..]}";
Exemplo n.º 4
0
        static Dictionary <int, Dictionary <int, float[][]> > ImportImpulses(string path, Regex pattern)
        {
            Settings.Default.LastFolder = path;
            string[] folders = Directory.GetFiles(path);
            Dictionary <int, Dictionary <int, float[][]> > data = new Dictionary <int, Dictionary <int, float[][]> >();

            for (int file = 0; file < folders.Length; ++file)
            {
                string fileName = Path.GetFileName(folders[file]);
                Match  match    = pattern.Match(fileName);
                if (match.Success &&
                    int.TryParse(match.Groups["param1"].Value, out int angle) &&
                    int.TryParse(match.Groups["param2"].Value, out int distance))
                {
                    if (!data.ContainsKey(angle))
                    {
                        data.Add(angle, new Dictionary <int, float[][]>());
                    }
                    data[angle][distance] = AudioReader.Open(folders[file]).ReadMultichannel();
                }
            }
            return(data);
        }