2021-03-19 17:07:27 -03:00
|
|
|
using System;
|
2021-06-29 12:08:08 -07:00
|
|
|
using System.IO;
|
2021-06-05 14:21:59 -07:00
|
|
|
using System.Linq;
|
2021-03-19 17:07:27 -03:00
|
|
|
using System.Threading.Tasks;
|
2021-06-29 12:08:08 -07:00
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.DiscImages;
|
|
|
|
|
using Aaru.Filters;
|
2021-06-06 20:28:36 +01:00
|
|
|
using CSCore.SoundOut;
|
2021-03-19 17:07:27 -03:00
|
|
|
using NWaves.Audio;
|
|
|
|
|
using NWaves.Filters.BiQuad;
|
2021-06-29 12:08:08 -07:00
|
|
|
using RedBookPlayer.Discs;
|
2021-03-19 17:07:27 -03:00
|
|
|
|
|
|
|
|
namespace RedBookPlayer
|
|
|
|
|
{
|
|
|
|
|
public class Player
|
|
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
#region Public Fields
|
2021-04-14 20:36:34 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Indicate if the player is ready to be used
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Initialized { get; private set; } = false;
|
2021-06-06 20:28:36 +01:00
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if de-emphasis should be applied
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ApplyDeEmphasis { get; private set; } = false;
|
|
|
|
|
|
2021-06-28 23:11:16 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Indicate if the disc is playing
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Playing => _soundOut.PlaybackState == PlaybackState.Playing;
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private State Variables
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// OpticalDisc object
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
private OpticalDisc _opticalDisc;
|
2021-06-06 21:43:47 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// Current position in the sector
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
private int _currentSectorReadPosition = 0;
|
2021-06-06 21:43:47 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Data provider for sound output
|
|
|
|
|
/// </summary>
|
|
|
|
|
private PlayerSource _source;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sound output instance
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ALSoundOut _soundOut;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Left channel de-emphasis filter
|
|
|
|
|
/// </summary>
|
|
|
|
|
private BiQuadFilter _deEmphasisFilterLeft;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Right channel de-emphasis filter
|
|
|
|
|
/// </summary>
|
|
|
|
|
private BiQuadFilter _deEmphasisFilterRight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lock object for reading track data
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly object _readingImage = new object();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// Initialize the player with a given image path
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// <param name="path">Path to the disc image</param>
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <param name="autoPlay">True if playback should begin immediately, false otherwise</param>
|
2021-06-29 12:08:08 -07:00
|
|
|
public void Init(string path, bool autoPlay = false)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
// Reset the internal state for initialization
|
|
|
|
|
Initialized = false;
|
|
|
|
|
ApplyDeEmphasis = false;
|
|
|
|
|
_opticalDisc = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Validate the image exists
|
|
|
|
|
if(string.IsNullOrWhiteSpace(path) || !File.Exists(path))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Load the disc image to memory
|
|
|
|
|
var image = new AaruFormat();
|
|
|
|
|
var filter = new ZZZNoFilter();
|
|
|
|
|
filter.Open(path);
|
|
|
|
|
image.Open(filter);
|
|
|
|
|
|
|
|
|
|
// Generate and instantiate the disc
|
|
|
|
|
_opticalDisc = OpticalDiscFactory.GenerateFromImage(image, App.Settings.AutoPlay);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// All errors mean an invalid image in some way
|
2021-03-19 17:07:27 -03:00
|
|
|
return;
|
2021-06-29 12:08:08 -07:00
|
|
|
}
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
// If we have an unusable disc, just return
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
2021-04-08 21:41:31 -03:00
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
// Enable de-emphasis for CDs, if necessary
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
ApplyDeEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
|
|
|
|
|
// Setup de-emphasis filters
|
2021-06-06 21:43:47 -07:00
|
|
|
SetupFilters();
|
2021-04-08 21:41:31 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Setup the audio output
|
|
|
|
|
SetupAudio();
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Initialize playback, if necessary
|
2021-06-06 20:28:36 +01:00
|
|
|
if(autoPlay)
|
2021-06-06 21:43:47 -07:00
|
|
|
_soundOut.Play();
|
2021-04-15 19:16:34 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Mark the player as ready
|
2021-03-19 17:07:27 -03:00
|
|
|
Initialized = true;
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Begin loading data
|
|
|
|
|
_source.Start();
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Fill the current byte buffer with playable data
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer to load data into</param>
|
|
|
|
|
/// <param name="offset">Offset in the buffer to load at</param>
|
|
|
|
|
/// <param name="count">Number of bytes to load</param>
|
|
|
|
|
/// <returns>Number of bytes read</returns>
|
2021-03-19 17:07:27 -03:00
|
|
|
public int ProviderRead(byte[] buffer, int offset, int count)
|
|
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
// Set the current volume
|
2021-06-21 21:35:09 -07:00
|
|
|
_soundOut.Volume = (float)App.Settings.Volume / 100;
|
2021-03-30 20:25:44 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Determine how many sectors we can read
|
2021-03-19 17:07:27 -03:00
|
|
|
ulong sectorsToRead;
|
|
|
|
|
ulong zeroSectorsAmount;
|
|
|
|
|
do
|
|
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
// Attempt to read 2 more sectors than requested
|
2021-06-29 12:08:08 -07:00
|
|
|
sectorsToRead = ((ulong)(count / _opticalDisc.BytesPerSector)) + 2;
|
2021-03-19 17:07:27 -03:00
|
|
|
zeroSectorsAmount = 0;
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Avoid overreads by padding with 0-byte data at the end
|
2021-06-29 12:08:08 -07:00
|
|
|
if(_opticalDisc.CurrentSector + sectorsToRead > _opticalDisc.TotalSectors)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
|
|
|
|
ulong oldSectorsToRead = sectorsToRead;
|
2021-06-29 12:08:08 -07:00
|
|
|
sectorsToRead = _opticalDisc.TotalSectors - _opticalDisc.CurrentSector;
|
2021-06-06 21:43:47 -07:00
|
|
|
zeroSectorsAmount = oldSectorsToRead - sectorsToRead;
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// TODO: Figure out when this value could be negative
|
|
|
|
|
if(sectorsToRead <= 0)
|
|
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
_opticalDisc.LoadFirstTrack();
|
2021-06-06 21:43:47 -07:00
|
|
|
_currentSectorReadPosition = 0;
|
|
|
|
|
}
|
2021-06-06 20:28:36 +01:00
|
|
|
} while(sectorsToRead <= 0);
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Create padding data for overreads
|
2021-06-29 12:08:08 -07:00
|
|
|
byte[] zeroSectors = new byte[(int)zeroSectorsAmount * _opticalDisc.BytesPerSector];
|
2021-03-19 17:07:27 -03:00
|
|
|
byte[] audioData;
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Attempt to read the required number of sectors
|
|
|
|
|
var readSectorTask = Task.Run(() =>
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
lock(_readingImage)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-05 10:57:20 -07:00
|
|
|
try
|
|
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
return _opticalDisc.ReadSectors((uint)sectorsToRead).Concat(zeroSectors).ToArray();
|
2021-06-05 10:57:20 -07:00
|
|
|
}
|
2021-06-06 20:28:36 +01:00
|
|
|
catch(ArgumentOutOfRangeException)
|
2021-06-05 10:57:20 -07:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
_opticalDisc.LoadFirstTrack();
|
|
|
|
|
return _opticalDisc.ReadSectors((uint)sectorsToRead).Concat(zeroSectors).ToArray();
|
2021-06-05 10:57:20 -07:00
|
|
|
}
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Wait 100ms at longest for the read to occur
|
|
|
|
|
if(readSectorTask.Wait(TimeSpan.FromMilliseconds(100)))
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
audioData = readSectorTask.Result;
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Array.Clear(buffer, offset, count);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Load only the requested audio segment
|
2021-03-19 17:07:27 -03:00
|
|
|
byte[] audioDataSegment = new byte[count];
|
2021-06-06 21:43:47 -07:00
|
|
|
Array.Copy(audioData, _currentSectorReadPosition, audioDataSegment, 0, Math.Min(count, audioData.Length - _currentSectorReadPosition));
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Apply de-emphasis filtering, only if enabled
|
2021-06-29 12:08:08 -07:00
|
|
|
if(ApplyDeEmphasis)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
|
|
|
|
float[][] floatAudioData = new float[2][];
|
|
|
|
|
floatAudioData[0] = new float[audioDataSegment.Length / 4];
|
|
|
|
|
floatAudioData[1] = new float[audioDataSegment.Length / 4];
|
|
|
|
|
ByteConverter.ToFloats16Bit(audioDataSegment, floatAudioData);
|
|
|
|
|
|
2021-06-06 20:28:36 +01:00
|
|
|
for(int i = 0; i < floatAudioData[0].Length; i++)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-06 21:43:47 -07:00
|
|
|
floatAudioData[0][i] = _deEmphasisFilterLeft.Process(floatAudioData[0][i]);
|
|
|
|
|
floatAudioData[1][i] = _deEmphasisFilterRight.Process(floatAudioData[1][i]);
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ByteConverter.FromFloats16Bit(floatAudioData, audioDataSegment);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Write out the audio data to the buffer
|
2021-03-19 17:07:27 -03:00
|
|
|
Array.Copy(audioDataSegment, 0, buffer, offset, count);
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
// Set the read position in the sector for easier access
|
|
|
|
|
_currentSectorReadPosition += count;
|
2021-06-29 12:08:08 -07:00
|
|
|
if(_currentSectorReadPosition >= _opticalDisc.BytesPerSector)
|
2021-06-06 21:43:47 -07:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
_opticalDisc.CurrentSector += (ulong)(_currentSectorReadPosition / _opticalDisc.BytesPerSector);
|
|
|
|
|
_currentSectorReadPosition %= _opticalDisc.BytesPerSector;
|
2021-06-06 21:43:47 -07:00
|
|
|
}
|
2021-03-19 17:07:27 -03:00
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 21:35:09 -07:00
|
|
|
#region Playback
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// Toggle audio playback
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// <param name="start">True to start playback, false to pause</param>
|
|
|
|
|
public void TogglePlayPause(bool start)
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
2021-03-19 17:07:27 -03:00
|
|
|
return;
|
|
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
if(start)
|
|
|
|
|
{
|
|
|
|
|
_soundOut.Play();
|
|
|
|
|
_opticalDisc.SetTotalIndexes();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_soundOut.Stop();
|
|
|
|
|
}
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// Stop the current audio playback
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
public void Stop()
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
2021-03-19 17:07:27 -03:00
|
|
|
return;
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
_soundOut.Stop();
|
2021-06-29 12:08:08 -07:00
|
|
|
_opticalDisc.LoadFirstTrack();
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
/// Move to the next playable track
|
2021-06-06 21:43:47 -07:00
|
|
|
/// </summary>
|
2021-06-29 12:08:08 -07:00
|
|
|
public void NextTrack()
|
2021-03-19 17:07:27 -03:00
|
|
|
{
|
2021-06-29 12:08:08 -07:00
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
2021-03-19 17:07:27 -03:00
|
|
|
return;
|
|
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
bool wasPlaying = Playing;
|
|
|
|
|
if(wasPlaying) TogglePlayPause(false);
|
|
|
|
|
|
|
|
|
|
_opticalDisc.NextTrack();
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
ApplyDeEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
|
|
|
|
|
if(wasPlaying) TogglePlayPause(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move to the previous playable track
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void PreviousTrack()
|
|
|
|
|
{
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool wasPlaying = Playing;
|
|
|
|
|
if(wasPlaying) TogglePlayPause(false);
|
|
|
|
|
|
|
|
|
|
_opticalDisc.PreviousTrack();
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
ApplyDeEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
|
|
|
|
|
if(wasPlaying) TogglePlayPause(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move to the next index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param>
|
|
|
|
|
public void NextIndex(bool changeTrack)
|
|
|
|
|
{
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool wasPlaying = Playing;
|
|
|
|
|
if(wasPlaying) TogglePlayPause(false);
|
|
|
|
|
|
|
|
|
|
_opticalDisc.NextIndex(changeTrack);
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
ApplyDeEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
|
|
|
|
|
if(wasPlaying) TogglePlayPause(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move to the previous index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="changeTrack">True if index changes can trigger a track change, false otherwise</param>
|
|
|
|
|
public void PreviousIndex(bool changeTrack)
|
|
|
|
|
{
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool wasPlaying = Playing;
|
|
|
|
|
if(wasPlaying) TogglePlayPause(false);
|
|
|
|
|
|
|
|
|
|
_opticalDisc.PreviousIndex(changeTrack);
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
ApplyDeEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
|
|
|
|
|
if(wasPlaying) TogglePlayPause(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fast-forward playback by 75 sectors, if possible
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void FastForward()
|
|
|
|
|
{
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_opticalDisc.CurrentSector = Math.Min(_opticalDisc.TotalSectors, _opticalDisc.CurrentSector + 75);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rewind playback by 75 sectors, if possible
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Rewind()
|
|
|
|
|
{
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(_opticalDisc.CurrentSector >= 75)
|
|
|
|
|
_opticalDisc.CurrentSector -= 75;
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
#endregion
|
2021-03-19 17:07:27 -03:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
#region Helpers
|
|
|
|
|
|
2021-06-29 12:08:08 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Generate the digit string to be interpreted by the frontend
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>String representing the digits for the frontend</returns>
|
|
|
|
|
public string GenerateDigitString()
|
|
|
|
|
{
|
|
|
|
|
// If the disc isn't initialized, return all '-' characters
|
|
|
|
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
|
|
|
|
return string.Empty.PadLeft(20, '-');
|
|
|
|
|
|
|
|
|
|
// Otherwise, take the current time into account
|
|
|
|
|
ulong sectorTime = _opticalDisc.CurrentSector;
|
|
|
|
|
if(_opticalDisc.SectionStartSector != 0)
|
|
|
|
|
sectorTime -= _opticalDisc.SectionStartSector;
|
|
|
|
|
else
|
|
|
|
|
sectorTime += _opticalDisc.TimeOffset;
|
|
|
|
|
|
|
|
|
|
int[] numbers = new int[]
|
|
|
|
|
{
|
|
|
|
|
_opticalDisc.CurrentTrackNumber + 1,
|
|
|
|
|
_opticalDisc.CurrentTrackIndex,
|
|
|
|
|
|
|
|
|
|
(int)(sectorTime / (75 * 60)),
|
|
|
|
|
(int)(sectorTime / 75 % 60),
|
|
|
|
|
(int)(sectorTime % 75),
|
|
|
|
|
|
|
|
|
|
_opticalDisc.TotalTracks,
|
|
|
|
|
_opticalDisc.TotalIndexes,
|
|
|
|
|
|
|
|
|
|
(int)(_opticalDisc.TotalTime / (75 * 60)),
|
|
|
|
|
(int)(_opticalDisc.TotalTime / 75 % 60),
|
|
|
|
|
(int)(_opticalDisc.TotalTime % 75),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return string.Join("", numbers.Select(i => i.ToString().PadLeft(2, '0').Substring(0, 2)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggle de-emphasis processing
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enable">True to apply de-emphasis, false otherwise</param>
|
|
|
|
|
public void ToggleDeEmphasis(bool enable) => ApplyDeEmphasis = enable;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update the data context for the frontend
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dataContext">Data context to be updated</param>
|
|
|
|
|
public void UpdateDataContext(PlayerViewModel dataContext)
|
|
|
|
|
{
|
|
|
|
|
if(!Initialized || dataContext == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dataContext.HiddenTrack = _opticalDisc.TimeOffset > 150;
|
|
|
|
|
dataContext.ApplyDeEmphasis = ApplyDeEmphasis;
|
|
|
|
|
|
|
|
|
|
if(_opticalDisc is CompactDisc compactDisc)
|
|
|
|
|
{
|
|
|
|
|
dataContext.QuadChannel = compactDisc.QuadChannel;
|
|
|
|
|
dataContext.IsDataTrack = compactDisc.IsDataTrack;
|
|
|
|
|
dataContext.CopyAllowed = compactDisc.CopyAllowed;
|
|
|
|
|
dataContext.TrackHasEmphasis = compactDisc.TrackHasEmphasis;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dataContext.QuadChannel = false;
|
|
|
|
|
dataContext.IsDataTrack = _opticalDisc.TrackType != TrackType.Audio;
|
|
|
|
|
dataContext.CopyAllowed = false;
|
|
|
|
|
dataContext.TrackHasEmphasis = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets or resets the de-emphasis filters
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetupFilters()
|
|
|
|
|
{
|
|
|
|
|
if(_deEmphasisFilterLeft == null)
|
|
|
|
|
{
|
|
|
|
|
_deEmphasisFilterLeft = new DeEmphasisFilter();
|
|
|
|
|
_deEmphasisFilterRight = new DeEmphasisFilter();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_deEmphasisFilterLeft.Reset();
|
|
|
|
|
_deEmphasisFilterRight.Reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-06 20:28:36 +01:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets or resets the audio playback objects
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetupAudio()
|
|
|
|
|
{
|
|
|
|
|
if(_source == null)
|
|
|
|
|
{
|
|
|
|
|
_source = new PlayerSource(ProviderRead);
|
|
|
|
|
_soundOut = new ALSoundOut(100);
|
|
|
|
|
_soundOut.Initialize(_source);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_soundOut.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-06 20:28:36 +01:00
|
|
|
|
2021-06-06 21:43:47 -07:00
|
|
|
#endregion
|
2021-03-19 17:07:27 -03:00
|
|
|
}
|
2021-06-06 20:28:36 +01:00
|
|
|
}
|