Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Audiotool/Converters/WavConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.IO;
using Audiotool.model;
using FFMpegCore;
Expand All @@ -8,12 +8,13 @@ namespace Audiotool.Converters;
public static class WavConverter
{
public static void ConvertToWav(List<Audio> audioFiles, string outputFolder)
{
{
foreach (Audio audio in audioFiles)
{
string outputPath = Path.Combine(outputFolder, $"{audio.FileName}.wav");

if (audio.FileExtension != "wav")
{
string outputPath = Path.Combine(outputFolder, $"{audio.FileName}.wav");
FFMpegArguments ff = FFMpegArguments
.FromFileInput(audio.FilePath);
_ = ff.OutputToFile(outputPath, true, opt =>
Expand All @@ -27,9 +28,13 @@ public static void ConvertToWav(List<Audio> audioFiles, string outputFolder)
if (audio.Channels != 1)
opt.WithCustomArgument("-ac 1");
}).ProcessSynchronously();

audio.FileSize = (ulong)new FileInfo(outputPath).Length; //; (long)(info.PrimaryAudioStream.BitRate * info.Duration.TotalSeconds * info.PrimaryAudioStream.Channels);
}
else
{
File.Copy(audio.FilePath, outputPath, true);
}

audio.FileSize = (ulong)new FileInfo(outputPath).Length;
}
}
}
}
6 changes: 3 additions & 3 deletions Audiotool/model/Audio.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml;
using System.Xml;

namespace Audiotool.model;

Expand All @@ -12,14 +12,14 @@
public class Audio
{
// Audio information
public string FilePath { get; set; }

Check warning on line 15 in Audiotool/model/Audio.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FilePath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public ulong FileSize { get; set; }
public string FileName { get; set; }

Check warning on line 17 in Audiotool/model/Audio.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FileName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public TimeSpan Duration { get; set; }
public int Samples { get; set; }
public int SampleRate { get; set; }
public string FileExtension { get; set; }

Check warning on line 21 in Audiotool/model/Audio.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'FileExtension' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Codec { get; set; }

Check warning on line 22 in Audiotool/model/Audio.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Codec' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int Channels { get; set; }

// Audio settings
Expand All @@ -42,7 +42,7 @@

public List<XmlNode> GenerateXML(XmlDocument doc)
{
if (FileSize >= 1.5 * 1024 * 1024)
if (FileSize > (1.5 * 8 * 1024 * 1024))
{
streamFormat = true;
}
Expand Down Expand Up @@ -238,4 +238,4 @@
element.SetAttribute(attributeName, attributeValue);
parent.AppendChild(element);
}
}
}
6 changes: 3 additions & 3 deletions Audiotool/repository/NativeAudioRepo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Audiotool.model;
using Audiotool.model;
using FFMpegCore;
using System.Collections.ObjectModel;
using System.IO;
Expand Down Expand Up @@ -38,11 +38,11 @@ public async Task AddAudioFile(string path)
SampleRate = info.PrimaryAudioStream.SampleRateHz,
Duration = info.Duration,
Channels = info.PrimaryAudioStream.Channels,
FileSize = (ulong)(info.PrimaryAudioStream.BitRate * info.Duration.TotalSeconds * info.PrimaryAudioStream.Channels)
FileSize = (ulong)new FileInfo(path).Length
};


AudioFiles.Add(audioFile);
AudioFiles.Add(audioFile);
}

public ObservableCollection<Audio> GetAudioFiles() => new(AudioFiles);
Expand Down
Loading