~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to src/import/ImportPCM.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "../Audacity.h"
22
22
#include "../AudacityApp.h"
23
23
#include "../Internat.h"
 
24
#include "../Tags.h"
24
25
#include "ImportPCM.h"
25
26
 
26
27
#include <wx/string.h>
43
44
#include "../WaveTrack.h"
44
45
#include "ImportPlugin.h"
45
46
 
 
47
#define DESC _("WAV, AIFF, and other uncompressed types")
 
48
 
46
49
class PCMImportPlugin : public ImportPlugin
47
50
{
48
51
public:
70
73
   wxString GetFileDescription();
71
74
   int GetFileUncompressedBytes();
72
75
   bool Import(TrackFactory *trackFactory, Track ***outTracks,
73
 
               int *outNumTracks);
 
76
               int *outNumTracks, Tags *tags);
74
77
private:
75
78
   wxString              mName;
76
79
   SNDFILE              *mFile;
88
91
 
89
92
wxString PCMImportPlugin::GetPluginFormatDescription()
90
93
{
91
 
    return wxT("Uncompressed PCM Audio Files");
 
94
    return DESC;
92
95
}
93
96
 
94
97
ImportFileHandle *PCMImportPlugin::Open(wxString filename)
153
156
 
154
157
bool PCMImportFileHandle::Import(TrackFactory *trackFactory,
155
158
                                 Track ***outTracks,
156
 
                                 int *outNumTracks)
 
159
                                 int *outNumTracks,
 
160
                                 Tags *tags)
157
161
{
158
162
   wxASSERT(mFile);
159
163
 
160
 
   *outNumTracks = mInfo.channels;
161
 
   WaveTrack **channels = new WaveTrack *[*outNumTracks];
 
164
   WaveTrack **channels = new WaveTrack *[mInfo.channels];
162
165
 
163
166
   int c;
164
 
   for (c = 0; c < *outNumTracks; c++) {
 
167
   for (c = 0; c < mInfo.channels; c++) {
165
168
      channels[c] = trackFactory->NewWaveTrack(mFormat, mInfo.samplerate);
166
169
 
167
 
      if (*outNumTracks > 1)
 
170
      if (mInfo.channels > 1)
168
171
         switch (c) {
169
172
         case 0:
170
173
            channels[c]->SetChannel(Track::LeftChannel);
177
180
         }
178
181
   }
179
182
 
180
 
   if (*outNumTracks == 2) {
 
183
   if (mInfo.channels == 2) {
181
184
      channels[0]->SetLinked(true);
182
185
      channels[1]->SetTeamed(true);
183
186
   }
211
214
         if (i + blockLen > fileTotalFrames)
212
215
            blockLen = fileTotalFrames - i;
213
216
 
214
 
         for(c=0; c<(*outNumTracks); c++)
 
217
         for (c = 0; c < mInfo.channels; c++)
215
218
            channels[c]->AppendAlias(mName, i, blockLen, c);
216
219
 
217
220
         if( mProgressCallback )
226
229
      // samples from the file and store our own local copy of the
227
230
      // samples in the tracks.
228
231
      
229
 
      samplePtr srcbuffer = NewSamples(maxBlockSize * (*outNumTracks),
 
232
      samplePtr srcbuffer = NewSamples(maxBlockSize * mInfo.channels,
230
233
                                       mFormat);
231
234
      samplePtr buffer = NewSamples(maxBlockSize, mFormat);
232
235
 
242
245
            block = sf_readf_float(mFile, (float *)srcbuffer, block);
243
246
         
244
247
         if (block) {
245
 
            for(c=0; c<(*outNumTracks); c++) {
 
248
            for(c=0; c<mInfo.channels; c++) {
246
249
               if (mFormat==int16Sample) {
247
250
                  for(int j=0; j<block; j++)
248
251
                     ((short *)buffer)[j] =
249
 
                        ((short *)srcbuffer)[(*outNumTracks)*j+c];
 
252
                        ((short *)srcbuffer)[mInfo.channels*j+c];
250
253
               }
251
254
               else {
252
255
                  for(int j=0; j<block; j++)
253
256
                     ((float *)buffer)[j] =
254
 
                        ((float *)srcbuffer)[(*outNumTracks)*j+c];
 
257
                        ((float *)srcbuffer)[mInfo.channels*j+c];
255
258
               }
256
259
               
257
260
               channels[c]->Append(buffer, mFormat, block);
270
273
   }
271
274
 
272
275
   if (cancelled) {
273
 
      for (c = 0; c < *outNumTracks; c++)
 
276
      for (c = 0; c < mInfo.channels; c++)
274
277
         delete channels[c];
275
278
      delete[] channels;
276
279
 
277
280
      return false;
278
281
   }
279
 
   else {
280
 
      *outTracks = new Track *[*outNumTracks];
281
 
      for(c = 0; c < *outNumTracks; c++) {
 
282
 
 
283
   *outNumTracks = mInfo.channels;
 
284
   *outTracks = new Track *[mInfo.channels];
 
285
   for(c = 0; c < mInfo.channels; c++) {
282
286
         channels[c]->Flush();
283
287
         (*outTracks)[c] = channels[c];
284
288
      }
285
289
      delete[] channels;
286
290
 
287
 
      return true;
288
 
   }
 
291
   const char *str;
 
292
 
 
293
   str = sf_get_string(mFile, SF_STR_TITLE);
 
294
   if (str) {
 
295
      tags->SetTag(TAG_TITLE, UTF8CTOWX(str));
 
296
   }
 
297
 
 
298
   str = sf_get_string(mFile, SF_STR_ARTIST);
 
299
   if (str) {
 
300
      tags->SetTag(TAG_ARTIST, UTF8CTOWX(str));
 
301
   }
 
302
 
 
303
   str = sf_get_string(mFile, SF_STR_COMMENT);
 
304
   if (str) {
 
305
      tags->SetTag(TAG_COMMENTS, UTF8CTOWX(str));
 
306
   }
 
307
 
 
308
   str = sf_get_string(mFile, SF_STR_DATE);
 
309
   if (str) {
 
310
      tags->SetTag(TAG_YEAR, UTF8CTOWX(str));
 
311
   }
 
312
 
 
313
   str = sf_get_string(mFile, SF_STR_COPYRIGHT);
 
314
   if (str) {
 
315
      tags->SetTag(wxT("Copyright"), UTF8CTOWX(str));
 
316
   }
 
317
 
 
318
   str = sf_get_string(mFile, SF_STR_SOFTWARE);
 
319
   if (str) {
 
320
      tags->SetTag(wxT("Software"), UTF8CTOWX(str));
 
321
   }
 
322
 
 
323
   return true;
289
324
}
290
325
 
291
326
PCMImportFileHandle::~PCMImportFileHandle()