Mercurial > hg > svcore
comparison data/fileio/AudioFileSizeEstimator.cpp @ 1342:c0fece5e7755 3.0-integration
Improved debug output for file open troubleshooting
author | Chris Cannam |
---|---|
date | Fri, 06 Jan 2017 09:43:40 +0000 |
parents | 513e4d67d8df |
children | aadfb395e933 |
comparison
equal
deleted
inserted
replaced
1341:513e4d67d8df | 1342:c0fece5e7755 |
---|---|
16 | 16 |
17 #include "WavFileReader.h" | 17 #include "WavFileReader.h" |
18 | 18 |
19 #include <QFile> | 19 #include <QFile> |
20 | 20 |
21 //#define DEBUG_AUDIO_FILE_SIZE_ESTIMATOR 1 | 21 #include "base/Debug.h" |
22 | 22 |
23 sv_frame_t | 23 sv_frame_t |
24 AudioFileSizeEstimator::estimate(FileSource source, | 24 AudioFileSizeEstimator::estimate(FileSource source, |
25 sv_samplerate_t targetRate) | 25 sv_samplerate_t targetRate) |
26 { | 26 { |
27 sv_frame_t estimate = 0; | 27 sv_frame_t estimate = 0; |
28 | 28 |
29 SVDEBUG << "AudioFileSizeEstimator: Sample count estimate requested for file \"" | |
30 << source.getLocalFilename() << "\"" << endl; | |
31 | |
29 // Most of our file readers don't know the sample count until | 32 // Most of our file readers don't know the sample count until |
30 // after they've finished decoding. This is an exception: | 33 // after they've finished decoding. This is an exception: |
31 | 34 |
32 WavFileReader *reader = new WavFileReader(source); | 35 WavFileReader *reader = new WavFileReader(source); |
33 if (reader->isOK() && | 36 if (reader->isOK() && |
38 sv_samplerate_t rate = reader->getSampleRate(); | 41 sv_samplerate_t rate = reader->getSampleRate(); |
39 if (targetRate != 0.0 && targetRate != rate) { | 42 if (targetRate != 0.0 && targetRate != rate) { |
40 samples = sv_frame_t(double(samples) * targetRate / rate); | 43 samples = sv_frame_t(double(samples) * targetRate / rate); |
41 } | 44 } |
42 delete reader; | 45 delete reader; |
46 SVDEBUG << "AudioFileSizeEstimator: WAV file reader accepts this file, reports " | |
47 << samples << " samples" << endl; | |
43 estimate = samples; | 48 estimate = samples; |
49 } else { | |
50 SVDEBUG << "AudioFileSizeEstimator: WAV file reader doesn't like this file, " | |
51 << "estimating from file size and extension instead" << endl; | |
44 } | 52 } |
45 | 53 |
46 if (estimate == 0) { | 54 if (estimate == 0) { |
47 | 55 |
48 // The remainder just makes an estimate based on the file size | 56 // The remainder just makes an estimate based on the file size |
58 | 66 |
59 source.waitForData(); | 67 source.waitForData(); |
60 if (!source.isOK()) return 0; | 68 if (!source.isOK()) return 0; |
61 | 69 |
62 sv_frame_t sz = 0; | 70 sv_frame_t sz = 0; |
71 | |
63 { | 72 { |
64 QFile f(source.getLocalFilename()); | 73 QFile f(source.getLocalFilename()); |
65 if (f.open(QFile::ReadOnly)) { | 74 if (f.open(QFile::ReadOnly)) { |
66 #ifdef DEBUG_AUDIO_FILE_SIZE_ESTIMATOR | 75 SVDEBUG << "AudioFileSizeEstimator: opened file, size is " |
67 cerr << "opened file, size is " << f.size() << endl; | 76 << f.size() << endl; |
68 #endif | |
69 sz = f.size(); | 77 sz = f.size(); |
70 f.close(); | 78 f.close(); |
71 } | 79 } |
72 } | 80 } |
73 | 81 |
92 // conservative. | 100 // conservative. |
93 | 101 |
94 estimate = sv_frame_t(double(sz) * 1.2 * rateRatio); | 102 estimate = sv_frame_t(double(sz) * 1.2 * rateRatio); |
95 } | 103 } |
96 | 104 |
97 #ifdef DEBUG_AUDIO_FILE_SIZE_ESTIMATOR | 105 SVDEBUG << "AudioFileSizeEstimator: for extension \"" |
98 cerr << "AudioFileSizeEstimator: for extension " << extension << ", estimate = " << estimate << endl; | 106 << extension << "\", estimate = " << estimate << " samples" << endl; |
99 #endif | |
100 } | 107 } |
101 | |
102 #ifdef DEBUG_AUDIO_FILE_SIZE_ESTIMATOR | |
103 cerr << "estimate = " << estimate << endl; | |
104 #endif | |
105 | 108 |
106 return estimate; | 109 return estimate; |
107 } | 110 } |
108 | 111 |