comparison data/fileio/OggVorbisFileReader.cpp @ 297:c022976d18e8

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 92e8dbde73cd
children 3a6725f285d6
comparison
equal deleted inserted replaced
296:2b6c99b607f1 297:c022976d18e8
32 32
33 static int instances = 0; 33 static int instances = 0;
34 34
35 OggVorbisFileReader::OggVorbisFileReader(QString path, 35 OggVorbisFileReader::OggVorbisFileReader(QString path,
36 DecodeMode decodeMode, 36 DecodeMode decodeMode,
37 CacheMode mode) : 37 CacheMode mode,
38 CodedAudioFileReader(mode), 38 size_t targetRate) :
39 CodedAudioFileReader(mode, targetRate),
39 m_path(path), 40 m_path(path),
40 m_progress(0), 41 m_progress(0),
41 m_fileSize(0), 42 m_fileSize(0),
42 m_bytesRead(0), 43 m_bytesRead(0),
43 m_commentsRead(false), 44 m_commentsRead(false),
44 m_cancelled(false), 45 m_cancelled(false),
45 m_completion(0), 46 m_completion(0),
46 m_decodeThread(0) 47 m_decodeThread(0)
47 { 48 {
48 m_frameCount = 0;
49 m_channelCount = 0; 49 m_channelCount = 0;
50 m_sampleRate = 0; 50 m_fileRate = 0;
51 51
52 std::cerr << "OggVorbisFileReader::OggVorbisFileReader(" << path.toLocal8Bit().data() << "): now have " << (++instances) << " instances" << std::endl; 52 std::cerr << "OggVorbisFileReader::OggVorbisFileReader(" << path.toLocal8Bit().data() << "): now have " << (++instances) << " instances" << std::endl;
53 53
54 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader", true); 54 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader", true);
55 55
109 } 109 }
110 110
111 void 111 void
112 OggVorbisFileReader::DecodeThread::run() 112 OggVorbisFileReader::DecodeThread::run()
113 { 113 {
114 if (m_reader->m_cacheMode == CacheInTemporaryFile) {
115 m_reader->m_completion = 1;
116 m_reader->startSerialised("OggVorbisFileReader::Decode");
117 }
118
114 while (oggz_read(m_reader->m_oggz, 1024) > 0); 119 while (oggz_read(m_reader->m_oggz, 1024) > 0);
115 120
116 fish_sound_delete(m_reader->m_fishSound); 121 fish_sound_delete(m_reader->m_fishSound);
117 m_reader->m_fishSound = 0; 122 m_reader->m_fishSound = 0;
118 oggz_close(m_reader->m_oggz); 123 oggz_close(m_reader->m_oggz);
119 m_reader->m_oggz = 0; 124 m_reader->m_oggz = 0;
120 125
121 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); 126 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache();
122 m_reader->m_completion = 100; 127 m_reader->m_completion = 100;
128
129 m_reader->endSerialised();
123 } 130 }
124 131
125 int 132 int
126 OggVorbisFileReader::readPacket(OGGZ *, ogg_packet *packet, long, void *data) 133 OggVorbisFileReader::readPacket(OGGZ *, ogg_packet *packet, long, void *data)
127 { 134 {
173 180
174 if (reader->m_channelCount == 0) { 181 if (reader->m_channelCount == 0) {
175 FishSoundInfo fsinfo; 182 FishSoundInfo fsinfo;
176 fish_sound_command(fs, FISH_SOUND_GET_INFO, 183 fish_sound_command(fs, FISH_SOUND_GET_INFO,
177 &fsinfo, sizeof(FishSoundInfo)); 184 &fsinfo, sizeof(FishSoundInfo));
185 reader->m_fileRate = fsinfo.samplerate;
178 reader->m_channelCount = fsinfo.channels; 186 reader->m_channelCount = fsinfo.channels;
179 reader->m_sampleRate = fsinfo.samplerate;
180 reader->initialiseDecodeCache(); 187 reader->initialiseDecodeCache();
181 } 188 }
182 189
183 if (nframes > 0) { 190 if (nframes > 0) {
184 191 reader->addSamplesToDecodeCache(frames, nframes);
185 reader->m_frameCount += nframes;
186
187 for (long i = 0; i < nframes; ++i) {
188 for (size_t c = 0; c < reader->m_channelCount; ++c) {
189 reader->addSampleToDecodeCache(frames[c][i]);
190 }
191 }
192
193 MUNLOCK_SAMPLEBLOCK(reader->m_data);
194 } 192 }
195 193
196 if (reader->m_cancelled) return 1; 194 if (reader->m_cancelled) return 1;
197 return 0; 195 return 0;
198 } 196 }