From b5ed4063e7370f2472f77d8c59d645a156698980 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 21 Mar 2017 19:47:34 +0100 Subject: Store input samplerate and use that for the output files instead of hardcoded 44k1Hz. --- src/audioextractor.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/audioextractor.cc b/src/audioextractor.cc index 71e0b2a..c249949 100644 --- a/src/audioextractor.cc +++ b/src/audioextractor.cc @@ -47,6 +47,7 @@ AudioExtractor::AudioExtractor(Selections &s, QObject *parent) void AudioExtractor::exportSelections() { + int samplerate = -1; emit setMaximumProgress(selections.ids().size() + 1/* for xml writing*/); int progress = 0; emit progressUpdate(progress++); @@ -67,6 +68,11 @@ void AudioExtractor::exportSelections() return; } + if(samplerate == -1) { + // Store the first samplerate we meet + samplerate = sf_info.samplerate; + } + audiodata[idx].data = NULL; j++; @@ -91,6 +97,11 @@ void AudioExtractor::exportSelections() } } + if(samplerate == -1) { + // For some reason we never got a samplerate. Set it to 44k1Hz + samplerate = 44100; + } + // Iterate and write audio files QVector::iterator si = sels.begin(); while(si != sels.end()) { @@ -145,7 +156,7 @@ void AudioExtractor::exportSelections() SF_INFO sf_info; sf_info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; - sf_info.samplerate = 44100; + sf_info.samplerate = samplerate; sf_info.channels = audiofiles.size(); SNDFILE *ofh = sf_open(file.toStdString().c_str(), SFM_WRITE, &sf_info); -- cgit v1.2.3