1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 17:49:45 +02:00

Rewrite export of data in FreqWindow.cpp

This commit is contained in:
Paul Licameli 2019-12-26 22:01:36 -05:00
parent ced6221b57
commit f932d2d550

View File

@ -68,6 +68,9 @@ and in the spectrogram spectral selection.
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/textfile.h> #include <wx/textfile.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <math.h> #include <math.h>
#include "ShuttleGui.h" #include "ShuttleGui.h"
@ -1073,31 +1076,32 @@ void FrequencyPlotDialog::OnExport(wxCommandEvent & WXUNUSED(event))
if (fName.empty()) if (fName.empty())
return; return;
wxTextFile f(fName); wxFFileOutputStream ffStream{ fName };
f.Create(); if (!ffStream.IsOk()) {
f.Open();
if (!f.IsOpened()) {
AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) ); AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
return; return;
} }
wxTextOutputStream ss(ffStream);
const int processedSize = mAnalyst->GetProcessedSize(); const int processedSize = mAnalyst->GetProcessedSize();
const float *const processed = mAnalyst->GetProcessed(); const float *const processed = mAnalyst->GetProcessed();
if (mAlgChoice->GetSelection() == 0) { if (mAlgChoice->GetSelection() == 0) {
f.AddLine(_("Frequency (Hz)\tLevel (dB)")); ss
<< XO("Frequency (Hz)\tLevel (dB)") << '\n';
for (int i = 1; i < processedSize; i++) for (int i = 1; i < processedSize; i++)
f.AddLine(wxString:: ss
Format(wxT("%f\t%f"), i * mRate / mWindowSize, << wxString::Format(wxT("%f\t%f\n"),
processed[i])); i * mRate / mWindowSize, processed[i] );
} else { }
f.AddLine(_("Lag (seconds)\tFrequency (Hz)\tLevel")); else {
for (int i = 1; i < processedSize; i++) ss
f.AddLine(wxString::Format(wxT("%f\t%f\t%f"), << XO("Lag (seconds)\tFrequency (Hz)\tLevel") << '\n';
i / mRate, mRate / i, processed[i])); for (int i = 1; i < processedSize; i++)
ss
<< wxString::Format(wxT("%f\t%f\t%f\n"),
i / mRate, mRate / i, processed[i] );
} }
f.Write();
f.Close();
} }
void FrequencyPlotDialog::OnReplot(wxCommandEvent & WXUNUSED(event)) void FrequencyPlotDialog::OnReplot(wxCommandEvent & WXUNUSED(event))