~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to muse/audioconvert.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-11-17 21:43:38 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101117214338-1hvfl7oo2dsqnvrb
Tags: 1.1-0ubuntu1
* New upstream release (LP: #668631)
* Switch to dpkg-source 3.0 (quilt) format
* Switch to dh7 short form
* debian/rules:
  - added --enable-dssi and --enable-osc to conf flags for dssi support
  - added -ljackserver to LDFLAGS to fix a FTBFS because of --as-needed
* debian/control:
  - added build build dependency on liblo-dev and dssi-dev for dssi support
  - bump Standards-version to 3.9.1. No changes required.
* debian/muse.desktop, debian/muse.xpm: dropped as desktop file and icon is
  now shipped upstream.
* fix-desktop-categories.patch: fix Categories tag in upstream desktop file
* 10_es_locale_fix.dpatch: refreshed and converted to quilt as
  fix_es_locale.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include "wave.h"
14
14
#include "globals.h"
15
15
#include "audioconvert.h"
 
16
#include "eventbase.h"
16
17
 
17
18
//#define AUDIOCONVERT_DEBUG
18
19
//#define AUDIOCONVERT_DEBUG_PRC
19
20
 
20
21
//---------------------------------------------------------
 
22
//   AudioConvertMap
 
23
//---------------------------------------------------------
 
24
 
 
25
void AudioConvertMap::remapEvents(const EventList* el)  
 
26
{
 
27
 
 
28
}
 
29
 
 
30
iAudioConvertMap AudioConvertMap::addEvent(EventBase* eb)
 
31
{
 
32
  iAudioConvertMap iacm = getConverter(eb);
 
33
  if(iacm == end())
 
34
  {
 
35
    AudioConverter* cv = 0;
 
36
    if(!eb->sndFile().isNull())
 
37
      cv = new SRCAudioConverter(eb->sndFile().channels(), SRC_SINC_MEDIUM_QUALITY);
 
38
    
 
39
    // Use insert with hint for speed.
 
40
    return insert(iacm, std::pair<EventBase*, AudioConverter*> (eb, cv));
 
41
  }
 
42
  else
 
43
    // Adopt a policy of returning an already existing item to enforce no-duplicates.
 
44
    return iacm;
 
45
}
 
46
 
 
47
void AudioConvertMap::removeEvent(EventBase* eb)
 
48
{
 
49
  iAudioConvertMap iacm = find(eb);
 
50
  if(iacm != end())
 
51
  {
 
52
    AudioConverter* cv = iacm->second;
 
53
    if(cv)
 
54
      delete cv;
 
55
    erase(iacm);  
 
56
  }    
 
57
}
 
58
 
 
59
iAudioConvertMap AudioConvertMap::getConverter(EventBase* eb)
 
60
{
 
61
  return find(eb);
 
62
}
 
63
 
 
64
//---------------------------------------------------------
21
65
//   AudioConverter
22
66
//---------------------------------------------------------
23
67
 
28
72
  #endif
29
73
 
30
74
  _refCount = 1;
 
75
  _sfCurFrame = 0;
31
76
}
32
77
 
33
78
AudioConverter::~AudioConverter()
50
95
{
51
96
  if(!cv)
52
97
    return 0;
53
 
  #ifdef AUDIOCONVERT_DEBUG
54
 
  printf("AudioConverter::release converter:%p\n", cv);
55
 
  #endif
56
98
  //if(cv->incRefCount(-1) <= 0)
57
 
  if((cv->_refCount -= 1) <= 0)
 
99
  cv->_refCount -= 1;
 
100
  #ifdef AUDIOCONVERT_DEBUG
 
101
  printf("AudioConverter::release converter:%p current refcount:%d\n", cv, cv->_refCount);
 
102
  #endif
 
103
  if(cv->_refCount <= 0)
58
104
  {
59
105
    #ifdef AUDIOCONVERT_DEBUG
60
106
    printf("AudioConverter::release deleting converter:%p\n", cv);
65
111
  return cv;  
66
112
}
67
113
 
68
 
off_t AudioConverter::readAudio(SndFileR& f, off_t sfCurFrame, unsigned offset, float** buffer, int channel, int n, bool doSeek, bool overwrite)
 
114
//off_t AudioConverter::readAudio(SndFileR& f, off_t sfCurFrame, unsigned offset, float** buffer, int channel, int n, bool doSeek, bool overwrite)
 
115
off_t AudioConverter::readAudio(SndFileR& f, unsigned offset, float** buffer, int channel, int n, bool doSeek, bool overwrite)
69
116
{
70
117
  if(f.isNull())
71
 
    return sfCurFrame;
 
118
    return _sfCurFrame;
72
119
  
73
120
  // Added by Tim. p3.3.17
74
121
  //#ifdef AUDIOCONVERT_DEBUG_PRC
84
131
  if(!resample)
85
132
  {
86
133
    // Sample rates are the same. Just a regular seek + read, no conversion.
87
 
    sfCurFrame = f.seek(frame, 0);
88
 
    return sfCurFrame + f.read(channel, buffer, n, overwrite);
 
134
    _sfCurFrame = f.seek(frame, 0);
 
135
    return _sfCurFrame + f.read(channel, buffer, n, overwrite);
89
136
  }
90
137
  
91
138
  // Is a 'transport' seek requested? (Not to be requested with every read! Should only be for 'first read' seeks, or positional 'transport' seeks.)
99
146
    //long inSize = long((double)frames * _src_ratio) + 1     // From MusE-2 file converter.
100
147
    off_t newfr = (off_t)floor(((double)frame * srcratio));    // From simplesynth.
101
148
  
102
 
    sfCurFrame = f.seek(newfr, 0);
 
149
    _sfCurFrame = f.seek(newfr, 0);
103
150
    
104
151
    // Added by Tim. p3.3.17
105
152
    //#ifdef AUDIOCONVERT_DEBUG_PRC
120
167
    // Sample rates are different. We can't just tell seek to go to an absolute calculated position, 
121
168
    //  since the last position can vary - it might not be what the calculated position is. 
122
169
    // We must use the last position left by SRC conversion, ie. let the file position progress on its own.
123
 
    sfCurFrame = f.seek(sfCurFrame, 0);
 
170
    _sfCurFrame = f.seek(_sfCurFrame, 0);
124
171
  }
125
172
  
126
173
  /*
132
179
  
133
180
  //sfCurFrame = process(f, sfCurFrame, offset, &outbuffer[0], channel, n);
134
181
//  sfCurFrame = process(f, sfCurFrame, outbuffer, channel, n);
135
 
  sfCurFrame = process(f, sfCurFrame, buffer, channel, n, overwrite);
 
182
  //sfCurFrame = process(f, sfCurFrame, buffer, channel, n, overwrite);
 
183
  _sfCurFrame = process(f, buffer, channel, n, overwrite);
136
184
  
137
185
  /*
138
186
  float*  poutbuf = &outbuffer[0];
193
241
  }
194
242
  */
195
243
  
196
 
  return sfCurFrame;
 
244
  return _sfCurFrame;
197
245
}
198
246
 
199
247
//---------------------------------------------------------
261
309
  return;  
262
310
}
263
311
 
264
 
off_t SRCAudioConverter::process(SndFileR& f, off_t sfCurFrame, float** buffer, int channel, int n, bool overwrite)
 
312
//off_t SRCAudioConverter::process(SndFileR& f, off_t sfCurFrame, float** buffer, int channel, int n, bool overwrite)
 
313
off_t SRCAudioConverter::process(SndFileR& f, float** buffer, int channel, int n, bool overwrite)
265
314
{
266
315
  //return src_process(_src_state, sd);
267
316
  
268
317
  if(f.isNull())
269
318
    //return;
270
 
    return sfCurFrame;
 
319
    return _sfCurFrame;
271
320
  
272
321
  // Added by Tim. p3.3.17
273
322
  //#ifdef AUDIOCONVERT_DEBUG_PRC
285
334
    #ifdef AUDIOCONVERT_DEBUG
286
335
    printf("SRCAudioConverter::process Error: sampleRate or file samplerate is zero!\n");
287
336
    #endif
288
 
    return sfCurFrame;
 
337
    return _sfCurFrame;
289
338
  }  
290
339
  
291
340
  SRC_DATA srcdata;
347
396
    if(srcerr != 0)      
348
397
    {
349
398
      printf("\nSRCAudioConverter::process SampleRate converter process failed: %s\n", src_strerror(srcerr));
350
 
      return sfCurFrame += rn;
 
399
      return _sfCurFrame += rn;
351
400
    }
352
401
    
353
402
    totalOutFrames += srcdata.output_frames_gen;
374
423
        #ifdef AUDIOCONVERT_DEBUG_PRC
375
424
        printf("SRCAudioConverter::process Seek-back by:%d\n", seekn);
376
425
        #endif
377
 
        sfCurFrame = f.seek(-seekn, SEEK_CUR);
 
426
        _sfCurFrame = f.seek(-seekn, SEEK_CUR);
378
427
      }
379
428
      else  
380
 
        sfCurFrame += rn;
 
429
        _sfCurFrame += rn;
381
430
      
382
431
      if(totalOutFrames == n)
383
432
      {
409
458
    }
410
459
    else
411
460
    {
412
 
      sfCurFrame += rn;
 
461
      _sfCurFrame += rn;
413
462
      #ifdef AUDIOCONVERT_DEBUG
414
463
      printf("SRCAudioConverter::process %s rn:%zd != inFrames:%ld output_frames_gen:%ld outFrames:%ld srcdata.input_frames_used:%ld\n", 
415
464
        f.name().latin1(), rn, inFrames, srcdata.output_frames_gen, outFrames, srcdata.input_frames_used);
498
547
    #endif
499
548
  }
500
549
  
501
 
  return sfCurFrame;
 
550
  return _sfCurFrame;
502
551
}
503
552
 
504
553
#ifdef RUBBERBAND_SUPPORT
556
605
/////////////////////////////////
557
606
// TODO: Not finished yet..
558
607
////////////////////////////////
559
 
off_t RubberBandAudioConverter::process(SndFileR& f, off_t sfCurFrame, float** buffer, int channel, int n, bool overwrite)
 
608
//off_t RubberBandAudioConverter::process(SndFileR& f, off_t sfCurFrame, float** buffer, int channel, int n, bool overwrite)
 
609
off_t RubberBandAudioConverter::process(SndFileR& f, float** buffer, int channel, int n, bool overwrite)
560
610
{
561
611
  //return src_process(_src_state, sd);
562
612
  
563
613
  if(f.isNull())
564
614
    //return;
565
 
    return sfCurFrame;
 
615
    return _sfCurFrame;
566
616
  
567
617
  // Added by Tim. p3.3.17
568
618
  //#ifdef AUDIOCONVERT_DEBUG_PRC
580
630
    #ifdef AUDIOCONVERT_DEBUG
581
631
    printf("RubberBandAudioConverter::process Error: sampleRate or file samplerate is zero!\n");
582
632
    #endif
583
 
    return sfCurFrame;
 
633
    return _sfCurFrame;
584
634
  }  
585
635
  
586
636
//  SRC_DATA srcdata;
679
729
    if(srcerr != 0)      
680
730
    {
681
731
      printf("\RubberBandAudioConverter::process SampleRate converter process failed: %s\n", src_strerror(srcerr));
682
 
      return sfCurFrame += rn;
 
732
      return _sfCurFrame += rn;
683
733
    }
684
734
    
685
735
    totalOutFrames += srcdata.output_frames_gen;
706
756
        #ifdef AUDIOCONVERT_DEBUG_PRC
707
757
        printf("RubberBandAudioConverter::process Seek-back by:%d\n", seekn);
708
758
        #endif
709
 
        sfCurFrame = f.seek(-seekn, SEEK_CUR);
 
759
        _sfCurFrame = f.seek(-seekn, SEEK_CUR);
710
760
      }
711
761
      else  
712
 
        sfCurFrame += rn;
 
762
        _sfCurFrame += rn;
713
763
      
714
764
      if(totalOutFrames == n)
715
765
      {
741
791
    }
742
792
    else
743
793
    {
744
 
      sfCurFrame += rn;
 
794
      _sfCurFrame += rn;
745
795
      #ifdef AUDIOCONVERT_DEBUG
746
796
      printf("RubberBandAudioConverter::process %s rn:%zd != inFrames:%ld output_frames_gen:%ld outFrames:%ld srcdata.input_frames_used:%ld\n", 
747
797
        f.name().latin1(), rn, inFrames, srcdata.output_frames_gen, outFrames, srcdata.input_frames_used);
830
880
    #endif
831
881
  }
832
882
  
833
 
  return sfCurFrame;
 
883
  return _sfCurFrame;
834
884
}
835
885
 
836
886
#endif // RUBBERBAND_SUPPORT