Tidy up WAV file reading and fix WAV input rate conversion defect

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6521 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-03-10 19:48:54 +00:00
parent ffcfe97f34
commit ab52a7f0ea
2 changed files with 12 additions and 9 deletions

View File

@ -23,7 +23,7 @@ subroutine wav12(d2,d1,npts,nbitsam2)
jz=min(NZ11,npts)
if(nbitsam2.eq.8) then
jz=min(NZ11,2*npts)
jz=min(NZ11,npts)
d1a(1:jz)=d1(1:jz) !d1 and d2 may be same array in calling prog
do i=1,jz !Move data from d1a into d2
i2=0

View File

@ -1606,18 +1606,21 @@ void MainWindow::read_wav_file (QString const& fname)
}
BWFFile file {QAudioFormat {}, fname};
file.open (BWFFile::ReadOnly);
auto ntps = std::min (m_TRperiod * 12000, 120 * 12000);
auto bytes_per_frame = file.format ().bytesPerFrame ();
int n = file.read (reinterpret_cast<char *> (dec_data.d2),
std::min (qint64 (bytes_per_frame * ntps), file.size ()));
int npts=n / file.format ().bytesPerFrame ();
std::memset (dec_data.d2 + n, 0, bytes_per_frame * ntps - n);
qint64 max_bytes {std::min (std::size_t (m_TRperiod * RX_SAMPLE_RATE),
sizeof (dec_data.d2) / sizeof (dec_data.d2[0]))
* bytes_per_frame};
auto n = file.read (reinterpret_cast<char *> (dec_data.d2),
std::min (max_bytes, file.size ()));
int frames_read = n / bytes_per_frame;
// zero unfilled remaining sample space
std::memset (&dec_data.d2[0] + n, 0, max_bytes - n);
if (11025 == file.format ().sampleRate ())
{
auto sample_size = static_cast<short > (file.format ().sampleSize ());
wav12_ (dec_data.d2, dec_data.d2, &npts, &sample_size);
short sample_size = file.format ().sampleSize ();
wav12_ (dec_data.d2, dec_data.d2, &frames_read, &sample_size);
}
dec_data.params.kin = npts;
dec_data.params.kin = frames_read;
dec_data.params.newdat = 1;
});
m_wav_future_watcher.setFuture(m_wav_future); // call diskDat() when done