//<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; }
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); }
/// <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; }
private static async Task <AudioFileInputNode[, ]> LoadAudioFileInputNodesAsync(int rowsCount, int columnsCount, AudioGraph audioGraph) { var audioDeviceOutputNode = await CreateAudioDeviceOutputNodeAsync(audioGraph); var storageFiles = await LoadStorageFiles(rowsCount, columnsCount); var result = new AudioFileInputNode[rowsCount, columnsCount]; // initialize an input node for each cell for (var y = 0; y < rowsCount; y++) { for (var x = 0; x < columnsCount; x++) { var inputResult = await audioGraph.CreateFileInputNodeAsync(storageFiles[y, x]); if (inputResult.Status != AudioFileNodeCreationStatus.Success) { continue; } var audioFileInputNode = inputResult.FileInputNode; // it shouldn't start when we add it to audioGraph audioFileInputNode.Stop(); // link it to the output node audioFileInputNode.AddOutgoingConnection(audioDeviceOutputNode); // add to the array for easier access to playback result[y, x] = audioFileInputNode; } } return(result); }
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(); }
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); }
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; }
private static async Task<AudioFileInputNode[,]> LoadAudioFileInputNodesAsync(int rowsCount, int columnsCount, AudioGraph audioGraph) { var audioDeviceOutputNode = await CreateAudioDeviceOutputNodeAsync(audioGraph); var storageFiles = await LoadStorageFiles(rowsCount, columnsCount); var result = new AudioFileInputNode[rowsCount, columnsCount]; // initialize an input node for each cell for (var y = 0; y < rowsCount; y++) { for (var x = 0; x < columnsCount; x++) { var inputResult = await audioGraph.CreateFileInputNodeAsync(storageFiles[y, x]); if (inputResult.Status != AudioFileNodeCreationStatus.Success) continue; var audioFileInputNode = inputResult.FileInputNode; // it shouldn't start when we add it to audioGraph audioFileInputNode.Stop(); // link it to the output node audioFileInputNode.AddOutgoingConnection(audioDeviceOutputNode); // add to the array for easier access to playback result[y, x] = audioFileInputNode; } } return result; }
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(); }
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; }
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(); }
public async Task AddFileAsync(IStorageFile file) { var fileInputNodeResult = await _graph.CreateFileInputNodeAsync(file); var fileInputNode = fileInputNodeResult.FileInputNode; fileInputNode.Stop(); fileInputNode.AddOutgoingConnection(_deviceOutput); _fileInputs.Add(file.Name, fileInputNode); }
public async Task <AudioFileInputNode> CreateNode(AudioGraph graph) { var result = await graph.CreateFileInputNodeAsync(file); if (result.Status != AudioFileNodeCreationStatus.Success) { throw new Exception("Faild To Create InputNode"); } return(result.FileInputNode); }
} //todo: Access is denied!!! async Task NewMethod(StorageFolder sf) { try { foreach (StorageFolder item in await sf.GetFoldersAsync()) { Debug.WriteLine(item.Name); } //var dbgFoldr0 = await sf.CreateFolderAsync("Dbg"); var dbgFoldr = await sf.GetFolderAsync("Dbg"); var inpFiles = await dbgFoldr.GetFilesAsync(CommonFileQuery.OrderByName); foreach (var inpFile in inpFiles.Where(r => r.Name.StartsWith("[") && r.Name.EndsWith("3"))) //inpFiles.ForEach(inpFile =>{}); { var outFile = await dbgFoldr.CreateFileAsync($"{_PlaybackSpeedFactor:N1}-{inpFile.Name}", CreationCollisionOption.ReplaceExisting); var fileInputResult = await _graph.CreateFileInputNodeAsync(inpFile); if (AudioFileNodeCreationStatus.Success != fileInputResult.Status) { notifyUser(String.Format("Cannot read input file because {0}", fileInputResult.Status.ToString())); return; } var fileInput = fileInputResult.FileInputNode; //_fileInput.StartTime = TimeSpan.FromSeconds(10); //_fileInput.EndTime = TimeSpan.FromSeconds(20); //fileInput.PlaybackSpeedFactor = _PlaybackSpeedFactor; var fileOutNodeResult = await _graph.CreateFileOutputNodeAsync(outFile, CreateMediaEncodingProfile(outFile)); // Operate node at the graph format, but save file at the specified format if (fileOutNodeResult.Status != AudioFileNodeCreationStatus.Success) { notifyUser(string.Format("Cannot create output file because {0}", fileOutNodeResult.Status.ToString())); return; } fileInput.AddOutgoingConnection(fileOutNodeResult.FileOutputNode); //fileInput.AddOutgoingConnection(_deviceOutput); fileInput.FileCompleted += fileInput_FileCompleted; //nogo{ fileInput.EncodingProperties.Bitrate *= 2; fileInput.EncodingProperties.SampleRate *= 2; fileInput.EncodingProperties.BitsPerSample *= 2; fileOutNodeResult.FileOutputNode.EncodingProperties.Bitrate /= 2; fileOutNodeResult.FileOutputNode.EncodingProperties.SampleRate /= 2; fileOutNodeResult.FileOutputNode.EncodingProperties.BitsPerSample /= 2; //}nogo _fileInputs.Add(fileInput); } _graph.Start(); //await Task.Delay(12000); _graph.Stop(); notifyUser("Started..."); } catch (Exception ex) { Debug.WriteLine(ex); throw; } }
public async Task <bool> SetSourceAsync(StorageFile file) { Stop(); _inputNode?.Dispose(); _inputNode = null; var result = await _audioGraph.CreateFileInputNodeAsync(file); LastStatus = result.Status.ToString(); if (result.Status != AudioFileNodeCreationStatus.Success) { return(false); } lock (this) { try { _inputNode = result.FileInputNode; var invalidDuration = TimeSpan.FromMilliseconds(50); if (_inputNode.Duration < invalidDuration) { return(false); } _inputNode.AddOutgoingConnection(_outputNode); ThresoldDuration = _inputNode.Duration - invalidDuration; _inputNode.EffectDefinitions.Add(CreateEchoEffect()); _inputNode.EffectDefinitions.Add(CreateLimiterEffect()); _inputNode.EffectDefinitions.Add(CreateReverbEffect()); _inputNode.EffectDefinitions.Add(CreateEqualizerEffect()); IsEchoEffectEnabled = IsEchoEffectEnabled; IsReverbEffectEnabled = IsReverbEffectEnabled; IsLimiterEffectEnabled = IsLimiterEffectEnabled; IsEQEffectEnabled = IsEQEffectEnabled; } catch (Exception) { return(false); } } if (AutoPlay) { Play(); } return(true); }
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); }
public async Task LoadFileAsync(IStorageFile file) { if (_deviceOutput == null) { await CreateAudioGraph(); } var fileInputResult = await _graph.CreateFileInputNodeAsync(file); _fileInputs.Add(file.Name, fileInputResult.FileInputNode); fileInputResult.FileInputNode.Stop(); fileInputResult.FileInputNode.AddOutgoingConnection(_deviceOutput); }
private async Task <AudioFileInputNode> AttachFileInputNode(StorageFile file, TypedEventHandler <AudioFileInputNode, object> OnFileCompleted) { var fileInputNodeResult = await graph.CreateFileInputNodeAsync(file); if (fileInputNodeResult.Status != AudioFileNodeCreationStatus.Success) { error.Text = String.Format("FileInputNode creation failed because {0}", fileInputNodeResult.Status.ToString()); } var fileInputNode = fileInputNodeResult.FileInputNode; fileInputNode.FileCompleted += OnFileCompleted; return(fileInputNode); }
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(); }
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(); }
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); } }
/// <summary> /// Plays a sound file /// </summary> /// <param name="file">File</param> /// <param name="gain">Gain</param> /// <returns></returns> private async Task PlaySound(SfxId id, double gain) { _lastSoundId++; int thisSoundId = _lastSoundId; await Task.Delay(80); if (thisSoundId != _lastSoundId) { return; } var fileInputNodeResult = await _audioGraph.CreateFileInputNodeAsync(_loaded[id]); var fileInputNode = fileInputNodeResult.FileInputNode; fileInputNode.FileCompleted += FileInputNodeOnFileCompleted; fileInputNode.AddOutgoingConnection(_outputNode, gain); }
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); } }
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(); }
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.; }
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; }
internal async Task LoadFileAsync(StorageFile file) { if (_deviceOutput == null) { await CreateAudioGraph(); } var fileInputResult = await _graph.CreateFileInputNodeAsync(file); _fileInputs.Add(file.Name, fileInputResult.FileInputNode); fileInputResult.FileInputNode.Stop(); fileInputResult.FileInputNode.AddOutgoingConnection(_deviceOutput); MusicProperties properties = await file.Properties.GetMusicPropertiesAsync(); TimeSpan myTrackDuration = properties.Duration; length = (Convert.ToInt32(myTrackDuration.TotalSeconds) * 1000) + 1000; }
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(); } } }