~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to misc/samples/ddksample/ddksample_misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ddksample_audio.c -  OSS DDK sample driver - misc routines
 
3
 *
 
4
 * Description:
 
5
 * This file contains routines that are not related with the
 
6
 * OSS DDK interface. To understand how OSS DDK works you don't need to
 
7
 * pay any attention on these routines. They are here just to produce
 
8
 * some data for the mixer routines (ddksample_mixer.c).
 
9
 *
 
10
 * ddksample_misc.c emulates some arbitrary audio device. It does
 
11
 * volume scaling to the output data and computes the peak meters from the
 
12
 * result of the scaling.
 
13
 */
 
14
/*
 
15
 *
 
16
 * This file is part of Open Sound System.
 
17
 *
 
18
 * Copyright (C) 4Front Technologies 1996-2008.
 
19
 *
 
20
 * This this source file is released under GPL v2 license (no other versions).
 
21
 * See the COPYING file included in the main directory of this source
 
22
 * distribution for the license terms and conditions.
 
23
 *
 
24
 */
 
25
 
 
26
 
 
27
/*
 
28
 * Solaris DDI includes
 
29
 */
 
30
#include <sys/types.h>
 
31
#include <sys/modctl.h>
 
32
#include <sys/kmem.h>
 
33
#include <sys/conf.h>
 
34
#include <sys/ddi.h>
 
35
#include <sys/sunddi.h>
 
36
 
 
37
/*
 
38
 * OSS specific includes
 
39
 */
 
40
#include <sys/soundcard.h>
 
41
#include <sys/ossddk/ossddk.h>
 
42
 
 
43
#include "ddksample.h"
 
44
 
 
45
/**************************************************/
 
46
void
 
47
ddksample_do_math (ddksample_portc * portc, void *buf, int len)
 
48
{
 
49
  int i;
 
50
  ddksample_devc *devc = ossddk_adev_get_devc (portc->dev);
 
51
 
 
52
  switch (portc->bits + portc->channels)
 
53
    {
 
54
    case 16 + 1:                /* 16 bits / mono */
 
55
      {
 
56
        int val;
 
57
        int peak = 0;
 
58
        short *p = buf;
 
59
 
 
60
        len /= sizeof (*p);
 
61
 
 
62
        for (i = 0; i < len; i++)
 
63
          {
 
64
            /* Do volume computations */
 
65
 
 
66
            val = *p++ << 8;    /* Scale up to 24 bits */
 
67
 
 
68
            val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
 
69
 
 
70
            /*
 
71
             * Note that legacy mixer volume max is always
 
72
             * 100.
 
73
             */
 
74
            val = (val * devc->mainvol_left) / 100;
 
75
 
 
76
            /*
 
77
             * Now we have the sample value after volume control.
 
78
             * This driver doesn't store this value anywhere but
 
79
             * if necessary this functionality can be added here.
 
80
 
 
81
             /*
 
82
             * Next compute the peak value
 
83
             */
 
84
 
 
85
            if (val < 0)
 
86
              val = -val;       /* Absolute value */
 
87
 
 
88
            if (val > peak)
 
89
              peak = val;
 
90
          }
 
91
 
 
92
        if (peak > portc->left_peak)
 
93
          portc->left_peak = peak;
 
94
        if (peak > portc->right_peak)
 
95
          portc->right_peak = peak;
 
96
      }
 
97
      break;
 
98
 
 
99
    case 16 + 2:                /* 16 bits / stereo */
 
100
      {
 
101
        int val;
 
102
        int left_peak = 0, right_peak = 0;
 
103
        short *p = buf;
 
104
 
 
105
        len /= sizeof (*p);
 
106
 
 
107
        for (i = 0; i < len; i += 2)    /* Each stereo sa,ple pair */
 
108
          {
 
109
            /*
 
110
             * Left channel
 
111
             */
 
112
 
 
113
            /* Do volume computations */
 
114
 
 
115
            val = (*p++) << 8;  /* Scale up to 24 bits */
 
116
 
 
117
            val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
 
118
 
 
119
            /*
 
120
             * Note that legacy mixer volume max is always
 
121
             * 100.
 
122
             */
 
123
            val = (val * devc->mainvol_left) / 100;
 
124
 
 
125
            /*
 
126
             * Now we have the sample value after volume control.
 
127
             * This driver doesn't store this value anywhere but
 
128
             * if necessary this functionality can be added here.
 
129
 
 
130
             /*
 
131
             * Next compute the peak value
 
132
             */
 
133
 
 
134
            if (val < 0)
 
135
              val = -val;       /* Absolute value */
 
136
 
 
137
            if (val > left_peak)
 
138
              left_peak = val;
 
139
 
 
140
            /*
 
141
             * Right channel
 
142
             */
 
143
 
 
144
            /* Do volume computations */
 
145
 
 
146
            val = (*p++) << 8;  /* Scale up to 24 bits */
 
147
 
 
148
            val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
 
149
 
 
150
            /*
 
151
             * Note that legacy mixer volume max is always
 
152
             * 100.
 
153
             */
 
154
            val = (val * devc->mainvol_left) / 100;
 
155
 
 
156
            /*
 
157
             * Now we have the sample value after volume control.
 
158
             * This driver doesn't store this value anywhere but
 
159
             * if necessary this functionality can be added here.
 
160
 
 
161
             /*
 
162
             * Next compute the peak value
 
163
             */
 
164
 
 
165
            if (val < 0)
 
166
              val = -val;       /* Absolute value */
 
167
 
 
168
            if (val > right_peak)
 
169
              right_peak = val;
 
170
          }
 
171
 
 
172
        if (left_peak > portc->left_peak)
 
173
          portc->left_peak = left_peak;
 
174
        if (right_peak > portc->right_peak)
 
175
          portc->right_peak = right_peak;
 
176
      }
 
177
      break;
 
178
    }
 
179
}