~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/driver/alsatimer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Eric Hedekar, Eric Hedekar, Fabrice Coutadeur
  • Date: 2010-01-26 02:32:14 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100126023214-8ez2g5d26d9p584j
Tags: 1.0.1-0ubuntu1
[ Eric Hedekar ]
* New upstream version (LP: #479688)
* Removed patches that were fixed in upstream source
  -[10_64bit_memcorruption_fix]
  -[10_gcc43_build_fixes]
  -[10_lash_private_api_fix]
  -[10_log2f_aliasing_fix]
  -[10_vamgui_init_fix]
  -[20_fix_const]

[ Fabrice Coutadeur ]
* debian/watch: added watch file
* debian/muse.desktop: deleted deprecated Encoding key, Application category
  and icon extension. This fix several warning with lintian and
  desktop-file-validate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
  //=========================================================
2
2
  //  MusE
3
3
  //  Linux Music Editor
4
 
  //  $Id: alsatimer.cpp,v 1.1.2.6 2005/08/21 18:11:27 spamatica Exp $
 
4
  //  $Id: alsatimer.cpp,v 1.1.2.9 2009/03/28 01:46:10 terminator356 Exp $
5
5
  //
6
6
  //  Plenty of code borrowed from timer.c example in 
7
7
  //  alsalib 1.0.7
10
10
  //=========================================================
11
11
        
12
12
  #include "alsatimer.h"
 
13
  #include <climits>
13
14
 
14
15
#define TIMER_DEBUG 0
15
16
  
21
22
     id = NULL;
22
23
     info = NULL;
23
24
     params = NULL;
 
25
     findBest = true;
24
26
     }
25
27
     
26
28
  AlsaTimer::~AlsaTimer()
29
31
       fprintf(stderr,"AlsaTimer::~AlsaTimer(this=%p) called\n",this);
30
32
    if (handle)
31
33
      snd_timer_close(handle);
32
 
    if (id) free(id);
33
 
    if (info) free(info);
34
 
    if (params) free(params);
 
34
    if (id) snd_timer_id_free(id);
 
35
    if (info) snd_timer_info_free(info);
 
36
    if (params) snd_timer_params_free(params);
35
37
    }
36
38
  
37
39
  signed int AlsaTimer::initTimer()
45
47
    int card = 0;
46
48
    int device = SND_TIMER_GLOBAL_SYSTEM;
47
49
    int subdevice = 0;
 
50
    int test_ids[] = { SND_TIMER_GLOBAL_SYSTEM
 
51
                     , SND_TIMER_GLOBAL_RTC
 
52
#ifdef SND_TIMER_GLOBAL_HPET
 
53
                     , SND_TIMER_GLOBAL_HPET
 
54
#endif
 
55
                     };
 
56
    int max_ids = sizeof(test_ids) / sizeof(int);
 
57
    long best_res = LONG_MAX;
 
58
    int best_dev = SND_TIMER_GLOBAL_SYSTEM;
 
59
    int i;
48
60
 
49
61
    if (id || info || params) {
50
62
      fprintf(stderr,"AlsaTimer::initTimer(): called on initialised timer!\n");
54
66
    snd_timer_info_malloc(&info);
55
67
    snd_timer_params_malloc(&params);
56
68
 
 
69
    if (findBest) {
 
70
      for (i = 0; i < max_ids; ++i) {
 
71
        device = test_ids[i];
 
72
        sprintf(timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i", devclass, sclass, card, device, subdevice);
 
73
        if ((err = snd_timer_open(&handle, timername, SND_TIMER_OPEN_NONBLOCK)) < 0) {
 
74
          continue;
 
75
          }
 
76
        if ((err = snd_timer_info(handle, info)) < 0) {
 
77
          snd_timer_close(handle);
 
78
          continue;
 
79
          }
 
80
        // select a non slave timer with the lowest resolution value
 
81
        int is_slave = snd_timer_info_is_slave(info);
 
82
        long res = snd_timer_info_get_resolution(info);
 
83
        if ((is_slave == 0) && (best_res > res)) {
 
84
          best_res = res;
 
85
          best_dev = device;
 
86
          }
 
87
        snd_timer_close(handle);
 
88
        }
 
89
      device = best_dev;
 
90
      }
 
91
 
57
92
    sprintf(timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i", devclass, sclass, card, device, subdevice);
58
93
    if ((err = snd_timer_open(&handle, timername, SND_TIMER_OPEN_NONBLOCK))<0) {
59
94
      fprintf(stderr, "AlsaTimer::initTimer(): timer open %i (%s)\n", err, snd_strerror(err));
64
99
      return -1;
65
100
      }
66
101
 
 
102
    //if(debugMsg)
 
103
      fprintf(stderr, "AlsaTimer::initTimer(): best available ALSA timer: %s\n", snd_timer_info_get_name(info));
 
104
 
67
105
    snd_timer_params_set_auto_start(params, 1);
68
106
    snd_timer_params_set_ticks(params, 1);
69
107
      
106
144
    if (setTick == 0) {
107
145
      fprintf(stderr,"AlsaTimer::setTimerTicks(): requested freq %u Hz too high for timer (max is %g)\n",
108
146
        freq, 1000000000.0 / snd_timer_info_get_resolution(info));
109
 
      fprintf(stderr,"  freq stays at %d Hz\n",
110
 
        (1000000000 / snd_timer_info_get_resolution(info)) / snd_timer_params_get_ticks(params));
 
147
      fprintf(stderr,"  freq stays at %ld Hz\n",
 
148
        (long int)((1000000000.0 / snd_timer_info_get_resolution(info)) / snd_timer_params_get_ticks(params)) 
 
149
      );
111
150
 
112
151
      return 0;
113
152
    }