Example #1
0
 public static MusicModAudioCuePoints FromAudioCuePoints(AudioCuePoints audioCuePoints)
 {
     return(new MusicModAudioCuePoints()
     {
         TotalSample = audioCuePoints.TotalSamples,
         LoopStartSample = audioCuePoints.LoopStartSample,
         LoopEndSample = audioCuePoints.LoopEndSample,
         TotalTimeMs = audioCuePoints.Frequency > 0 ? audioCuePoints.TotalSamples * 1000 / audioCuePoints.Frequency : 0,
         LoopStartMs = audioCuePoints.Frequency > 0 ? audioCuePoints.LoopStartSample * 1000 / audioCuePoints.Frequency : 0,
         LoopEndMs = audioCuePoints.Frequency > 0 ? audioCuePoints.LoopEndSample * 1000 / audioCuePoints.Frequency : 0
     });
 }
Example #2
0
        public AudioCuePoints GetCuePoints(string filePath)
        {
            _logger.LogDebug("Retrieving audio metadata for {FilePath}...", filePath);

            var builder = new StringBuilder();

            var oldValue = Console.Out;

            using (var writer = new StringWriter(builder))
            {
                Console.SetOut(writer);
                Converter.RunConverterCli(new string[] { "-m", "-i", filePath });
            }
            Console.SetOut(oldValue);

            var output = builder.ToString();

            var audioCuePoints = new AudioCuePoints()
            {
                TotalSamples    = ReadValueUInt64Safe(output, "Sample count: "),
                LoopStartSample = ReadValueUInt64Safe(output, "Loop start: "),
                LoopEndSample   = ReadValueUInt64Safe(output, "Loop end: "),
                Frequency       = ReadValueUInt32Safe(output, "Sample rate: "),
            };

            if (audioCuePoints.TotalSamples == 0)
            {
                _logger.LogWarning("{FilePath}: Total Samples was 0! Use song_cue_points_override property in the payload to override these values.");
            }

            if (audioCuePoints.Frequency == 0)
            {
                _logger.LogWarning("{FilePath}: Frequency was 0! Use song_cue_points_override property in the payload to override these values.");
            }

            if (audioCuePoints.LoopEndSample == 0)
            {
                _logger.LogWarning("{FilePath}: Loop end sample was 0! Use song_cue_points_override property in the payload to override these values.");
            }

            return(audioCuePoints);
        }