/// <summary> /// Load an audio file. Unfortunately, Linux can't load from the file system YET. /// </summary> /// <param name="name">The audio name.</param> /// <param name="filePath">Path to the file.</param> /// <param name="loop">Loop. Will try and find one with the same name and in the same location if null.</param> public void LoadAudioFile(string name, string filePath, Loop loop = null) { if (loop == null && FileSystem.FileExists(Path.GetFileNameWithoutExtension(filePath) + ".dbli")) { loop = (Loop)FileSystem.OpenFile <Loop>(Path.GetFileNameWithoutExtension(filePath) + ".dbli"); } if (IsLinux) { var c = CSCore.Linux.Codecs.CodecFactory.Instance.GetCodec(filePath); var src = new AudioSource(c, loop); ALSoundOut o = new ALSoundOut(); o.Initialize(src); if (!LinuxBuffer.ContainsKey(name)) { LinuxBuffer.Add(name, o); } else { LinuxBuffer[name] = o; } } else { IWaveSource c = null; if (WindowsCodecs.ContainsKey(Path.GetExtension(filePath))) { c = WindowsCodecs[Path.GetExtension(filePath)](FileSystem.OpenFileStream(filePath)); } if (c == null) { c = new CSCore.MediaFoundation.MediaFoundationDecoder(FileSystem.OpenFileStream(filePath)); } var src = new AudioSource(c, loop); WasapiOut o = new WasapiOut(); o.Initialize(src); if (!WindowsBuffer.ContainsKey(name)) { WindowsBuffer.Add(name, o); } else { WindowsBuffer[name] = o; } } }
public async void Init(AaruFormat image, bool autoPlay = false) { this.Image = image; if (await Task.Run(() => image.Info.ReadableMediaTags?.Contains(MediaTagType.CD_FullTOC)) != true) { Console.WriteLine("Full TOC not found"); return; } byte[] tocBytes = await Task.Run(() => image.ReadDiskTag(MediaTagType.CD_FullTOC)); if ((tocBytes?.Length ?? 0) == 0) { Console.WriteLine("Error reading TOC from disc image"); return; } if (Swapping.Swap(BitConverter.ToUInt16(tocBytes, 0)) + 2 != tocBytes.Length) { byte[] tmp = new byte[tocBytes.Length + 2]; Array.Copy(tocBytes, 0, tmp, 2, tocBytes.Length); tmp[0] = (byte)((tocBytes.Length & 0xFF00) >> 8); tmp[1] = (byte)(tocBytes.Length & 0xFF); tocBytes = tmp; } FullTOC.CDFullTOC?nullableToc = await Task.Run(() => FullTOC.Decode(tocBytes)); if (nullableToc == null) { Console.WriteLine("Error decoding TOC"); return; } toc = nullableToc.Value; Console.WriteLine(FullTOC.Prettify(toc)); if (deEmphasisFilterLeft == null) { deEmphasisFilterLeft = new DeEmphasisFilter(); deEmphasisFilterRight = new DeEmphasisFilter(); } else { deEmphasisFilterLeft.Reset(); deEmphasisFilterRight.Reset(); } if (source == null) { source = new PlayerSource(ProviderRead); soundOut = new ALSoundOut(100); soundOut.Initialize(source); } else { soundOut.Stop(); } CurrentTrack = 0; LoadTrack(0); if (autoPlay) { soundOut.Play(); } else { TotalIndexes = 0; } TotalTracks = image.Tracks.Count; TrackDataDescriptor firstTrack = toc.TrackDescriptors.First(d => d.ADR == 1 && d.POINT == 1); TimeOffset = (ulong)(firstTrack.PMIN * 60 * 75 + firstTrack.PSEC * 75 + firstTrack.PFRAME); TotalTime = TimeOffset + image.Tracks.Last().TrackEndSector; Volume = App.Settings.Volume; Initialized = true; source.Start(); }