Fixed sync of spectrogram

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2260 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-12-01 06:48:43 +00:00
parent 1444e44be7
commit ca5c698e83
2 changed files with 9 additions and 10 deletions

View File

@ -82,7 +82,7 @@ namespace Nikse.SubtitleEdit.Controls
private List<Bitmap> _spectrogramBitmaps = new List<Bitmap>();
private string _spectrogramDirectory;
private double _sampleDuration;
private double _totalDuration = 0;
private double _secondsPerImage = 0;
private const int SpectrogramBitmapWidth = 1024;
public delegate void ParagraphEventHandler(object sender, ParagraphEventArgs e);
@ -1599,7 +1599,7 @@ namespace Nikse.SubtitleEdit.Controls
var doc = new XmlDocument();
doc.Load(Path.Combine(_spectrogramDirectory, "Info.xml"));
_sampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText, System.Globalization.CultureInfo.InvariantCulture);
_totalDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText, System.Globalization.CultureInfo.InvariantCulture);
_secondsPerImage = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SecondsPerImage").InnerText, System.Globalization.CultureInfo.InvariantCulture);
ShowSpectrogram = _tempShowSpectrogram;
}
@ -1628,7 +1628,7 @@ namespace Nikse.SubtitleEdit.Controls
{
doc.Load(xmlInfoFileName);
_sampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText, System.Globalization.CultureInfo.InvariantCulture);
_totalDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText, System.Globalization.CultureInfo.InvariantCulture);
_secondsPerImage = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SecondsPerImage").InnerText, System.Globalization.CultureInfo.InvariantCulture);
ShowSpectrogram = true;
}
else
@ -1645,9 +1645,9 @@ namespace Nikse.SubtitleEdit.Controls
Bitmap bmpDestination = new Bitmap(width, 128); //calculate width
Graphics gfx = Graphics.FromImage(bmpDestination);
double startRow = seconds / (_sampleDuration);
int bitmapIndex = (int)(startRow / SpectrogramBitmapWidth);
int subtractValue = (int)startRow % SpectrogramBitmapWidth;
double startRow = seconds / _secondsPerImage;
int bitmapIndex = (int)startRow;
int subtractValue = (int)Math.Round((startRow - bitmapIndex) * SpectrogramBitmapWidth);
int i = 0;
while (i * SpectrogramBitmapWidth < width && i + bitmapIndex < _spectrogramBitmaps.Count)
@ -1671,7 +1671,6 @@ namespace Nikse.SubtitleEdit.Controls
bmpDestination.Dispose();
}
private double GetAverageVolumeForNextMilliseconds(int sampleIndex, int milliseconds)
{
milliseconds = 150;

View File

@ -470,11 +470,11 @@ namespace Nikse.SubtitleEdit.Logic
}
var doc = new XmlDocument();
doc.LoadXml("<SpectrogramInfo><SampleDuration/><TotalDuration/></SpectrogramInfo>");
doc.LoadXml("<SpectrogramInfo><SampleDuration/><TotalDuration/><SecondsPerImage /></SpectrogramInfo>");
double sampleDuration = Header.LengthInSeconds / (totalSamples / Convert.ToDouble(nfft));
double totalDuration = Header.LengthInSeconds;
doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText = sampleDuration.ToString(CultureInfo.InvariantCulture);
doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText = totalDuration.ToString(CultureInfo.InvariantCulture);
doc.DocumentElement.SelectSingleNode("TotalDuration").InnerText = Header.LengthInSeconds.ToString(CultureInfo.InvariantCulture);
doc.DocumentElement.SelectSingleNode("SecondsPerImage").InnerText = ((double)(sampleSize / (double)Header.SampleRate)).ToString(CultureInfo.InvariantCulture);
doc.Save(Path.Combine(spectrogramDirectory, "Info.xml"));
return bitmaps;