Beispiel #1
0
        //<SnippetCreateFileInputNode>
        private async Task CreateFileInputNode()
        {
            if (audioGraph == null)
            {
                return;
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }
            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                ShowErrorMessage(result.Status.ToString());
            }

            fileInputNode = result.FileInputNode;
        }
Beispiel #2
0
        /// <summary>
        /// Ask user to pick a file and use the chosen file to create an AudioFileInputNode
        /// </summary>
        private async Task CreateFileInputNode()
        {
            FileOpenPicker filePicker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.MusicLibrary,
                FileTypeFilter         = { ".mp3", ".wav" }
            };

            StorageFile file = await filePicker.PickSingleFileAsync();

            // file null check code omitted

            CreateAudioFileInputNodeResult result = await _graph.CreateFileInputNodeAsync(file);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                throw new Exception(result.Status.ToString());
            }

            _fileInputNode = result.FileInputNode;

            // Set infinite loop
            _fileInputNode.LoopCount = null;
            // When file finishes playing the first time,
            // turn it's output gain down to zero.
            _fileInputNode.FileCompleted += _fileInputNode_FileCompleted;
        }
Beispiel #3
0
        public static async Task PlayAudio(StorageFile file)
        {
            await AudioDevices();

            _isAudioPlaying = true;
            CreateAudioFileInputNodeResult fileInputResult = await audioflow.CreateFileInputNodeAsync(file);

            if (AudioFileNodeCreationStatus.Success != fileInputResult.Status)
            {
                // Cannot read input file
                Debug.WriteLine(String.Format("Cannot read input file because {0}", fileInputResult.Status.ToString()));
                _isAudioPlaying = false;
                return;
            }

            if (!_isAudioPlaying)
            {
                Debug.WriteLine("Error detected!");
                return;
            }

            fileInput = fileInputResult.FileInputNode;
            fileInput.FileCompleted += FileInput_FileCompleted;
            try
            {
                fileInput.AddOutgoingConnection(deviceOuput);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
            fileInput.StartTime = TimeSpan.FromSeconds(0);
            audioflow.Start();
            _isAudioPlaying = false;
        }
Beispiel #4
0
        private async Task <AudioFileInputNode> CreateFileInputNodeAsync(IStorageFile file)
        {
            if (audioGraph == null)
            {
                return(null);
            }

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return(null);
            }
            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                throw new InvalidOperationException("Can't load file");
            }

            //prepareNextTimer?.Cancel();
            //prepareNextTimer = null;
            //prepareNextTimer = ThreadPoolTimer.CreateTimer(FileAlmostComplete, result.FileInputNode.Duration - TimeSpan.FromSeconds(3));

            return(result.FileInputNode);
        }
Beispiel #5
0
        private async Task SelectInputFile()
        {
            StorageFile file = await GetPackagedFile(null, "audio.mp3");

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot read file
                return;
            }

            fileInputNode = fileInputNodeResult.FileInputNode;
            fileInputNode.AddOutgoingConnection(deviceOutputNode);

            // Event Handler for file completion
            fileInputNode.FileCompleted += FileInput_FileCompleted;

            // Enable the button to start the graph

            // Create the custom effect and apply to the FileInput node
            AddCustomEffect();
        }
Beispiel #6
0
        private async void initGraph()
        {
            AudioGraphSettings     settings = new AudioGraphSettings(AudioRenderCategory.Media);
            CreateAudioGraphResult result   = await AudioGraph.CreateAsync(settings);

            graph = result.Graph;
            // Create a device output node
            CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await graph.CreateDeviceOutputNodeAsync();

            deviceOutput = deviceOutputNodeResult.DeviceOutputNode;


            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            StorageFile file = await GetPackagedFile(null, "audio.mp3");

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            fileInput = fileInputResult.FileInputNode;
            fileInput.AddOutgoingConnection(deviceOutput);
            graph.Start();
        }
Beispiel #7
0
        private async void File_Click(object sender, RoutedEventArgs e)
        {
            // If another file is already loaded into the FileInput node
            if (fileInput != null)
            {
                // Release the file and dispose the contents of the node
                fileInput.Dispose();
                // Stop playback since a new file is being loaded. Also reset the button UI
                if (graphButton.Content.Equals("Stop Graph"))
                {
                    TogglePlay();
                }
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (AudioFileNodeCreationStatus.Success != fileInputResult.Status)
            {
                // Cannot read input file
                rootPage.NotifyUser(String.Format("Cannot read input file because {0}", fileInputResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInput = fileInputResult.FileInputNode;
            fileInput.AddOutgoingConnection(deviceOutput);
            fileButton.Background = new SolidColorBrush(Colors.Green);

            if (fileInput.Duration.TotalSeconds < 3)
            {
                // Imported file is too short
                rootPage.NotifyUser(String.Format("This scenario requires a sound file which is longer than 3 seconds"), NotifyType.ErrorMessage);
                return;
            }

            // Trim the file: set the start time to 3 seconds from the beginning
            // fileInput.EndTime can be used to trim from the end of file
            fileInput.StartTime = TimeSpan.FromSeconds(3);

            // Enable buttons in UI to start graph, loop and change playback speed factor
            graphButton.IsEnabled     = true;
            loopToggle.IsEnabled      = true;
            playSpeedSlider.IsEnabled = true;
        }
Beispiel #8
0
        private async void File_Click(object sender, RoutedEventArgs e)
        {
            // If another file is already loaded into the FileInput node
            if (fileInputNode != null)
            {
                // Release the file and dispose the contents of the node
                fileInputNode.Dispose();
                // Stop playback since a new file is being loaded. Also reset the button UI
                if (graphButton.Content.Equals("Stop Graph"))
                {
                    TogglePlay();
                }
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Error reading the input file
                rootPage.NotifyUser(String.Format("Can't read input file because {0}", fileInputResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            // File loaded successfully. Enable these buttons in the UI
            graphButton.IsEnabled         = true;
            echoEffectToggle.IsEnabled    = true;
            reverbEffectToggle.IsEnabled  = true;
            limiterEffectToggle.IsEnabled = true;
            eqToggle.IsEnabled            = true;

            fileInputNode = fileInputResult.FileInputNode;
            fileInputNode.AddOutgoingConnection(deviceOutputNode);

            rootPage.NotifyUser("Successfully loaded input file", NotifyType.StatusMessage);
            fileButton.Background = new SolidColorBrush(Colors.Green);

            // Create the four inbox effects
            CreateEchoEffect();
            CreateReverbEffect();
            CreateLimiterEffect();
            CreateEqEffect();
        }
Beispiel #9
0
        public async Task <FileSample> ScanSampleAsync(FileSample sample, IProgress <double> progress = null)
        {
            if (sample is null)
            {
                throw new ArgumentNullException(nameof(sample));
            }
            if (!(sample is AudioSample audio))
            {
                throw new ArgumentException("Must be an audio sample");
            }

            try {
                StorageFile file;
                try {
                    file = await StorageFile.GetFileFromPathAsync(sample.SourceUrl).ConfigureAwait(false);
                } catch (AccessViolationException) {
                    if (sample.Token != null)
                    {
                        file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(sample.Token).ConfigureAwait(false);
                    }
                    else
                    {
                        throw;
                    }
                }

                CreateAudioFileInputNodeResult result = await this.graph.CreateFileInputNodeAsync(file);

                if (result.Status != AudioFileNodeCreationStatus.Success)
                {
                    Trace.TraceWarning($"Failed to scan file sample: {result.Status}");
                    return(null);
                }

                using (var node = result.FileInputNode) {
                    progress?.Report(.5);

                    var hashTask = GetContentHashAsync(await file.OpenStreamForReadAsync());

                    audio = audio with {
                        Duration    = node.Duration,
                        Channels    = (AudioChannels)node.EncodingProperties.ChannelCount,
                        Frequency   = node.EncodingProperties.SampleRate,
                        ContentHash = await hashTask
                    };
                }

                return(audio);
            } catch (Exception ex) {
                Trace.TraceWarning("Failed to scan file sample: " + ex);
                return(null);
            } finally {
                progress?.Report(1);
            }
        }
        private async void File1_Click(object sender, RoutedEventArgs e)
        {
            // If another file is already loaded into the FileInput node
            if (fileInputNode1 != null)
            {
                // Release the file and dispose the contents of the node
                fileInputNode1.Dispose();
                // Stop playback since a new file is being loaded. Also reset the button UI
                if (graphButton.Content.Equals("Stop Graph"))
                {
                    TogglePlay();
                }
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file1 = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file1 == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(file1);

            if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot read input file
                rootPage.NotifyUser(String.Format("Can't read input file1 because {0}", fileInputNodeResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInputNode1 = fileInputNodeResult.FileInputNode;
            // Since we are going to play two files simultaneously, set outgoing gain to 0.5 to prevent clipping
            fileInputNode1.AddOutgoingConnection(submixNode, 0.5);

            // The graph might already be playing, so set up UI accordingly
            if (graphButton.Content.Equals("Stop Graph"))
            {
                audioPipe1.Fill = new SolidColorBrush(Colors.Blue);
            }

            // UI tasks: enable buttons, show status message and change color of the input node box
            graphButton.IsEnabled      = true;
            echoEffectToggle.IsEnabled = true;
            rootPage.NotifyUser("Loaded File 1", NotifyType.StatusMessage);
            fileButton1.Background = new SolidColorBrush(Colors.Green);
        }
        public async Task <AudioGraph> CreateAudioGraph(string filePath)
        {
            AudioGraph            audioGraph;
            AudioDeviceOutputNode deviceOutputNode;

            // Create an AudioGraph with default setting
            AudioGraphSettings     settings = new AudioGraphSettings(AudioRenderCategory.GameEffects);
            CreateAudioGraphResult result   = await AudioGraph.CreateAsync(settings);

            if (result.Status != AudioGraphCreationStatus.Success)
            {
                Debug.WriteLine("Could not create an audio graph");
                return(null);
            }

            audioGraph = result.Graph;

            // Create a device output node
            CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await audioGraph.CreateDeviceOutputNodeAsync();

            if (deviceOutputNodeResult.Status != AudioDeviceNodeCreationStatus.Success)
            {
                Debug.WriteLine("Could not create an output node");
                return(null);
            }

            deviceOutputNode = deviceOutputNodeResult.DeviceOutputNode;

            AudioFileInputNode fileInput;

            // @"Audio\correctAnswerPlayer2.wav"
            var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(filePath);

            if (file == null)
            {
                return(null);
            }

            CreateAudioFileInputNodeResult fileInputResult = await audioGraph.CreateFileInputNodeAsync(file);

            if (AudioFileNodeCreationStatus.Success != fileInputResult.Status)
            {
                // Cannot read input file
                Debug.WriteLine($"Cannot read input file because {fileInputResult.Status.ToString()}");
                return(null);
            }

            fileInput = fileInputResult.FileInputNode;

            fileInput.AddOutgoingConnection(deviceOutputNode);

            return(audioGraph);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            destination = await ApplicationData.Current.LocalFolder.CreateFileAsync("myfile1", CreationCollisionOption.ReplaceExisting);

            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".flv");
            openPicker.FileTypeFilter.Add(".3gp");
            openPicker.FileTypeFilter.Add(".avi");
            openPicker.FileTypeFilter.Add(".mkv");
            source = await openPicker.PickSingleFileAsync();

            //获取视频信息
            if (source != null)
            {
                var clip = await MediaClip.CreateFromFileAsync(source);

                property = clip.GetVideoEncodingProperties();
                string encodeInfo = property.Subtype;
                Source_height = property.Height;
                Source_width  = property.Width;

                Source_frameRate = property.FrameRate.Numerator;
                dataRate         = property.Bitrate;
            }
            //获取声频信息
            if (source != null)
            {
                AudioGraphSettings     settings     = new AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media);
                CreateAudioGraphResult createResult = await AudioGraph.CreateAsync(settings);

                if (createResult.Status != AudioGraphCreationStatus.Success)
                {
                    return;
                }
                AudioGraph audioGraph = createResult.Graph;
                CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(source);

                if (result.Status != AudioFileNodeCreationStatus.Success)
                {
                    return;
                }
                AudioFileInputNode      fileInputNode = result.FileInputNode;
                AudioEncodingProperties property      = fileInputNode.EncodingProperties;
                //Get encode property
                string subTitles = property.Subtype;
                SampleRate = property.SampleRate;
            }
        }
        private async void PlayAudioGraph_Click(object sender, RoutedEventArgs e)
        {
            // If another file is already loaded into the FileInput node
            if (fileInput != null)
            {
                // Release the file and dispose the contents of the node
                fileInput.Dispose();
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (AudioFileNodeCreationStatus.Success != fileInputResult.Status)
            {
                // Cannot read input file
                Logging.SingleInstance.LogMessage("Cannot read input file because  " + fileInputResult.Status);
                return;
            }

            fileInput = fileInputResult.FileInputNode;

            if (fileInput.Duration <= TimeSpan.FromSeconds(3))
            {
                // Imported file is too short
                Logging.SingleInstance.LogMessage("Please pick an audio file which is longer than 3 seconds " + fileInputResult.Status);
                fileInput.Dispose();
                fileInput = null;
                return;
            }

            fileInput.AddOutgoingConnection(deviceOutput);


            // Trim the file: set the start time to 3 seconds from the beginning
            // fileInput.EndTime can be used to trim from the end of file
            fileInput.StartTime = TimeSpan.FromSeconds(3);
        }
        private async Task AddFileToSoundDictionary(string uri)
        {
            StorageFile soundFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(soundFile);

            if (AudioFileNodeCreationStatus.Success == fileInputResult.Status)
            {
                fileInputs.TryAdd(soundFile.Name, fileInputResult.FileInputNode);
                fileInputResult.FileInputNode.Stop();
                fileInputResult.FileInputNode.AddOutgoingConnection(deviceOutput);
            }
        }
        // Create a file input node
        private async Task <AudioFileInputNode> CreateInputNodeAsync(string fileName)
        {
            StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile   file   = await folder.GetFileAsync(fileName);

            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                return(null);
            }
            return(result.FileInputNode);
        }
Beispiel #16
0
        public async Task LoadFileIntoGraph(StorageFile audioFile)
        {
            CreateAudioFileInputNodeResult audioFileInputResult = await this._audioGraph.CreateFileInputNodeAsync(audioFile);

            if (audioFileInputResult.Status != AudioFileNodeCreationStatus.Success)
            {
                throw new Exception("File failed to load into graph.");
            }

            _fileInputNode = audioFileInputResult.FileInputNode;
            _fileInputNode.AddOutgoingConnection(_deviceOutputNode);

            CreateAndAddEchoEffect();
        }
        private async Task SelectInputFile()
        {
            // If another file is already loaded into the FileInput node
            if (fileInputNode != null)
            {
                // Release the file and dispose the contents of the node
                fileInputNode.Dispose();
                // Stop playback since a new file is being loaded. Also reset the button UI
                if (graphButton.Content.Equals("Stop Graph"))
                {
                    TogglePlay();
                }
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot read file
                rootPage.NotifyUser(String.Format("Cannot read input file because {0}", fileInputNodeResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInputNode = fileInputNodeResult.FileInputNode;
            fileInputNode.AddOutgoingConnection(deviceOutputNode);
            fileButton.Background = new SolidColorBrush(Colors.Green);

            // Event Handler for file completion
            fileInputNode.FileCompleted += FileInput_FileCompleted;

            // Enable the button to start the graph
            graphButton.IsEnabled = true;

            // Create the custom effect and apply to the FileInput node
            AddCustomEffect();
        }
Beispiel #18
0
 private async Task LoadAudioFromFile(StorageFile file)
 {
     // We initialize an instance of AudioGraph
     AudioGraphSettings settings = 
         new AudioGraphSettings(
             Windows.Media.Render.AudioRenderCategory.Media
             );
     CreateAudioGraphResult result1 = await AudioGraph.CreateAsync(settings);
     if (result1.Status != AudioGraphCreationStatus.Success)
     {
         ShowMessage("AudioGraph creation error: " + result1.Status.ToString());
     }
     audioGraph = result1.Graph;
     
     if (audioGraph == null)
         return;
     // We initialize FileInputNode
     CreateAudioFileInputNodeResult result2 = 
         await audioGraph.CreateFileInputNodeAsync(file);
     if (result2.Status != AudioFileNodeCreationStatus.Success)
     {
         ShowMessage("FileInputNode creation error: " + result2.Status.ToString());
     }
     fileInputNode = result2.FileInputNode;
     if (fileInputNode == null)
         return;
     // We read audio file encoding properties to pass them to FrameOutputNode creator
     AudioEncodingProperties audioEncodingProperties = fileInputNode.EncodingProperties;
     // We initialize FrameOutputNode and connect it to fileInputNode
     frameOutputNode = audioGraph.CreateFrameOutputNode(audioEncodingProperties);
     fileInputNode.AddOutgoingConnection(frameOutputNode);
     // We add a handler achiving the end of a file
     fileInputNode.FileCompleted += FileInput_FileCompleted;
     // We add a handler which will transfer every audio frame into audioData 
     audioGraph.QuantumStarted += AudioGraph_QuantumStarted;
     // We initialize audioData
     int numOfSamples = (int)Math.Ceiling(
         (decimal)0.0000001
         * fileInputNode.Duration.Ticks
         * fileInputNode.EncodingProperties.SampleRate
         );
     audioData = new float[numOfSamples];
     
     audioDataCurrentPosition = 0;
     // We start process which will read audio file frame by frame
     // and will generated events QuantumStarted when a frame is in memory
     audioGraph.Start();
 }
Beispiel #19
0
        private async Task CreateInputNodeFromFile(string uri)
        {
            StorageFile soundFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(soundFile);

            if (AudioFileNodeCreationStatus.Success == fileInputNodeResult.Status)
            {
                // FileInputNodesDictionary.Add(soundFile.Name, fileInputNodeResult.FileInputNode);
                fileInputNodeResult.FileInputNode.Stop();
                fileInputNodeResult.FileInputNode.AddOutgoingConnection(outputNode);
                fileInputNodeResult.FileInputNode.LoopCount = 0;
                //FileInputNodesDictionary.Add(soundFile.Name, fileInputNodeResult.FileInputNode);
                InputNodes.Add(fileInputNodeResult.FileInputNode);
            }
        }
Beispiel #20
0
        async Task <AudioFileInputNode> createFileInputNode(string path, double gain = 1)
        {
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Audio/" + path));

            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file);

            if (result.Status == AudioFileNodeCreationStatus.Success)
            {
                result.FileInputNode.Stop();
                result.FileInputNode.AddOutgoingConnection(deviceOutputNode, gain);
                return(result.FileInputNode);
            }
            else
            {
                return(null);
            }
        }
Beispiel #21
0
        private async Task SelectInputFile()
        {
            if (fileInputNode != null)
            {
                fileInputNode.Dispose();

                if (graphButton.Content.Equals("Stop Graph"))
                {
                    TogglePlay();
                }
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success)
            {
                NotifyUser(String.Format("Cannot read input file because {0}", fileInputNodeResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInputNode = fileInputNodeResult.FileInputNode;
            fileInputNode.AddOutgoingConnection(deviceOutputNode);
            fileButton.Background = new SolidColorBrush(Colors.Green);

            fileInputNode.FileCompleted += FileInput_FileCompleted;

            graphButton.IsEnabled = true;

            AddCustomEffect();
        }
Beispiel #22
0
        private async void openFile()
        {
            // If another file is already loaded into the FileInput node
            if (fileInput != null)
            {
                // Release the file and dispose the contents of the node
                fileInput.Dispose();
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            // StorageFile file = await filePicker.PickSingleFileAsync();
            StorageFile file = await GetPackagedFile(null, "alarm.mp3");

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (AudioFileNodeCreationStatus.Success != fileInputResult.Status)
            {
                // Cannot read input file
                return;
            }

            fileInput = fileInputResult.FileInputNode;
            fileInput.AddOutgoingConnection(deviceOutput);

            // Trim the file: set the start time to 3 seconds from the beginning
            // fileInput.EndTime can be used to trim from the end of file
            fileInput.StartTime = TimeSpan.FromSeconds(0);

            // MediaPlayer player = MediaPlayer.;
        }
Beispiel #23
0
        public async Task LoadFileAsync(StorageFile file)
        {
            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot read input file
                //rootPage.NotifyUser(String.Format("Cannot read input file because {0}", fileInputResult.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInputNode = fileInputResult.FileInputNode;

            if (fileInputNode.Duration <= TimeSpan.FromSeconds(3))
            {
                // Imported file is too short
                //rootPage.NotifyUser("Please pick an audio file which is longer than 3 seconds", NotifyType.ErrorMessage);
                fileInputNode.Dispose();
                fileInputNode = null;
                return;
            }

            fileInputNode.AddOutgoingConnection(deviceOutput);
            //fileButton.Background = new SolidColorBrush(Colors.Green);

            // Trim the file: set the start time to 3 seconds from the beginning
            // fileInput.EndTime can be used to trim from the end of file
            //fileInput.StartTime = TimeSpan.FromSeconds(3);

            // Enable buttons in UI to start graph, loop and change playback speed factor
            //graphButton.IsEnabled = true;
            //loopToggle.IsEnabled = true;
            //playSpeedSlider.IsEnabled = true;

            if (WaveformRenderer != null)
            {
                WaveformBridgeDefinition definition = new WaveformBridgeDefinition();
                definition.Renderer = WaveformRenderer;
                fileInputNode.EffectDefinitions.Add(definition);
            }

            IsPaused = true;
        }
Beispiel #24
0
        public async Task CreateFileInputNodeWithEmitter()
        {
            if (audioGraph == null)
            {
                return;
            }

            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            filePicker.FileTypeFilter.Add(".mp3");
            filePicker.FileTypeFilter.Add(".wav");
            filePicker.FileTypeFilter.Add(".wma");
            filePicker.FileTypeFilter.Add(".m4a");
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile file = await filePicker.PickSingleFileAsync();

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            //<SnippetCreateEmitter>
            var emitterShape = AudioNodeEmitterShape.CreateOmnidirectional();
            var decayModel   = AudioNodeEmitterDecayModel.CreateNatural(.1, 1, 10, 100);
            var settings     = AudioNodeEmitterSettings.None;

            var emitter = new AudioNodeEmitter(emitterShape, decayModel, settings);

            emitter.Position = new System.Numerics.Vector3(10, 0, 5);

            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file, emitter);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                ShowErrorMessage(result.Status.ToString());
            }

            fileInputNode = result.FileInputNode;
            //</SnippetCreateEmitter>
        }
Beispiel #25
0
        private async Task PlayMyMusic()
        {
            var file = await StorageFile.GetFileFromPathAsync(fil[0].Path);

            //var file = await KnownFolders.MusicLibrary.GetFileAsync("smalltest.flac");

            CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);

            if (fileInputResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot create graph
                //rootPage.NotifyUser(String.Format("AudioGraph Creation Error because {0}", result.Status.ToString()), NotifyType.ErrorMessage);
                return;
            }

            fileInput = fileInputResult.FileInputNode;
            fileInput.AddOutgoingConnection(deviceOutput);
            //fileInput.LoopCount = 10;
            graph.Start();
        }
        private async Task CreateFileInputNode(string fileName)
        {
            isInitialized.CheckIfFulfills("Speaker", "initialized", true);
            var          asd  = KnownFolders.MusicLibrary.GetFileAsync(fileName);
            IStorageFile file = await KnownFolders.MusicLibrary.GetFileAsync(fileName);

            if (file == null)
            {
                throw new Exception($"Could not find music file. {Logger.GetExceptionLocalization(this) }");
            }

            CreateAudioFileInputNodeResult result = await audioGraph.CreateFileInputNodeAsync(file);

            if (result.Status != AudioFileNodeCreationStatus.Success)
            {
                throw new Exception($"Could not create file input node. { Logger.GetExceptionLocalization(this) }");
            }

            fileInput = result.FileInputNode;
        }
Beispiel #27
0
        public static async Task LoadSound(string sound)
        {
            if (initialized)
            {
                //Stop graph for loading new sound
                graph.Stop();

                StorageFile soundFile = await StorageFile.GetFileFromPathAsync(Environment.CurrentDirectory + @"\resources\sounds\" + sound);

                CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(soundFile);

                if (fileInputResult.Status == AudioFileNodeCreationStatus.Success)
                {
                    inputs.Add(soundFile.Name, fileInputResult.FileInputNode);
                    fileInputResult.FileInputNode.Stop();
                    fileInputResult.FileInputNode.AddOutgoingConnection(output);
                    graph.Start();
                }
            }
        }
Beispiel #28
0
        public async Task InitilizeAudioGraph(StorageFile file)
        {
            AudioGraphSettings settings = new AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media);

            CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);

            if (result.Status != AudioGraphCreationStatus.Success)
            {
                return;
            }

            audioGraph = result.Graph;
            if (audioGraph == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult audioInputResult = await audioGraph.CreateFileInputNodeAsync(file);

            if (audioInputResult.Status != AudioFileNodeCreationStatus.Success)
            {
                return;
            }

            fileInputNode = audioInputResult.FileInputNode;

            CreateAudioDeviceOutputNodeResult audioOutputResult = await audioGraph.CreateDeviceOutputNodeAsync();

            if (audioOutputResult.Status != AudioDeviceNodeCreationStatus.Success)
            {
                return;
            }

            deviceOutputNode = audioOutputResult.DeviceOutputNode;

            fileInputNode.AddOutgoingConnection(deviceOutputNode);
        }
        private async Task CreateEmitter(int spatialSoundIdx)
        {
            if (_graph == null)
            {
                return;
            }

            //Create the AudioNodeEmitter
            AudioNodeEmitter emitter = new AudioNodeEmitter(
                AudioNodeEmitterShape.CreateOmnidirectional(),
                AudioNodeEmitterDecayModels.CreateNatural(),
                AudioNodeEmitterSettings.None);

            emitter.Position = _spatialSounds[spatialSoundIdx].Position;
            //Create a new AudioFileInputNode and add an emitter to it
            var audio = await GetSoundFileAsync(spatialSoundIdx);

            CreateAudioFileInputNodeResult inCreateResult = await _graph.CreateFileInputNodeAsync(audio, emitter);

            inCreateResult.FileInputNode.OutgoingGain = 5; // _spatialSounds[_spatialSoundsIdx].Gain;
                                                           //Add the new AudioFileInputNode to the AudioGraph
            inCreateResult.FileInputNode.AddOutgoingConnection(_deviceOutput);
            inCreateResult.FileInputNode.AddOutgoingConnection(_submixNode);
            //Subscribe to the FileCompleted event so that we can go to the next spatial sound
            //inCreateResult.FileInputNode.FileCompleted += CurrentAudioFileInputNode_FileCompleted;

            if (_currentAudioFileInputNode != null &&
                _currentAudioFileInputNode.OutgoingConnections.Count > 0)
            {
                //Remove the old AudioFileOutputNode from the AudioGraph
                _currentAudioFileInputNode.RemoveOutgoingConnection(_deviceOutput);
                _currentAudioFileInputNode.RemoveOutgoingConnection(_submixNode);
            }

            //Set the current node
            _currentAudioFileInputNode = inCreateResult.FileInputNode;
        }
Beispiel #30
0
        private void SelectInputFile()
        {
            StorageFile file = this.GetPackagedFile(null, "audio.mp3").Result;

            // File can be null if cancel is hit in the file picker
            if (file == null)
            {
                return;
            }

            CreateAudioFileInputNodeResult fileInputNodeResult = graph.CreateFileInputNodeAsync(file).GetResults();

            if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success)
            {
                // Cannot read file
                return;
            }

            fileInputNode = fileInputNodeResult.FileInputNode;
            fileInputNode.AddOutgoingConnection(deviceOutputNode);

            // Event Handler for file completion
            fileInputNode.FileCompleted += FileInput_FileCompleted;
        }