File: sqUnixSoundDebug.h

package info (click to toggle)
squeak-vm 1%3A4.10.2.2614%2B20120917~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,144 kB
  • sloc: ansic: 72,193; objc: 5,494; sh: 3,061; asm: 1,533; cpp: 449; pascal: 372; makefile: 300; awk: 103; cs: 11
file content (128 lines) | stat: -rw-r--r-- 2,244 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#if 1

# define startSpy();
# define stopSpy();

#else

#define RED	0xff0000
#define GREEN	0x00ff00
#define BLUE	0x0000ff
#define WHITE	0xffffff
#define BLACK	0x000000

#include <pthread.h>

void rect(int h, int c, float l, float r)
{
  extern long *dpyPixels;
  extern int   dpyPitch;
  int left= 250, width= 100, height= 2;
  long *base=  dpyPixels;
  int   pitch= dpyPitch / sizeof(long);
  int x, y;

  //printf("rect %d %d %g %g\n", h, c, l, r);
  assert(l >= 0.0);  assert(r >= 0.0);
  assert(l <= 1.0);  assert(r <= 1.0);

  base+= (int)left;
  base+= (int)(h * height * pitch);

  for (y= 0; y < height; ++y)
    {
      for (x= (int)(width * l); x < (int)(width * r); ++x)
	((long *)base)[x]= c;
      base+= pitch;
    }
}

void fill(int h, int c, float l, float r)
{
  if (r > 1.0)
    {
      rect(h, c, l, 1.0);
      rect(h, c, 0.0, r - 1.0);
    }
  else
    rect(h, c, l, r);
}


#if (USE_FIFO)

void update(void)
{
  if (output)
    {
      Buffer *b=   output->buffer;
      static int phase= 0;
      float size=  b->size;
      float out=   b->optr / size;
      float avail= b->avail / size;
      extern long *dpyPixels;

      fill(0,BLACK, 0.0, out);
      fill(0,GREEN, out, out+avail);
      if (out + avail < 1.0)
	fill(0,BLACK, out+avail, 1.0);
      fill(2,GREEN, 0.0, avail);
      fill(2,BLACK, avail, 1.0);

      phase= 1 - phase;
      feedback(10, phase * WHITE);

      memcpy(dpyPixels + 400, output->buffer->data, 400);
    }
}

#else

void update(void)
{
}

#endif


static int       running= 0;
static pthread_t spyThread;

static void *spy(void *ignored)
{
  struct sched_param params;
  int                policy;
  if (pthread_getschedparam(pthread_self(), &policy, &params))
    perror("getschedparam");
  params.sched_priority+= 9;
  if (pthread_setschedparam(pthread_self(), SCHED_RR, &params))
    perror("setschedparam");
  for (;;)
    {
      update();
      usleep(10000);
    }
}

void startSpy(void)
{
  if (!pthread_create(&spyThread, 0, spy, 0))
    running= 1;
  else
    perror("pthread_create(spy)");
}

void stopSpy(void)
{
  if (running)
    {
      if (!pthread_cancel(spyThread))
	running= 0;
      else
	perror("pthread_cancel(spy)");
      running= 0;
    }
}


#endif // (DEBUG)