2
* ddksample_audio.c - OSS DDK sample driver - misc routines
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).
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.
16
* This file is part of Open Sound System.
18
* Copyright (C) 4Front Technologies 1996-2008.
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.
28
* Solaris DDI includes
30
#include <sys/types.h>
31
#include <sys/modctl.h>
35
#include <sys/sunddi.h>
38
* OSS specific includes
40
#include <sys/soundcard.h>
41
#include <sys/ossddk/ossddk.h>
43
#include "ddksample.h"
45
/**************************************************/
47
ddksample_do_math (ddksample_portc * portc, void *buf, int len)
50
ddksample_devc *devc = ossddk_adev_get_devc (portc->dev);
52
switch (portc->bits + portc->channels)
54
case 16 + 1: /* 16 bits / mono */
62
for (i = 0; i < len; i++)
64
/* Do volume computations */
66
val = *p++ << 8; /* Scale up to 24 bits */
68
val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
71
* Note that legacy mixer volume max is always
74
val = (val * devc->mainvol_left) / 100;
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.
82
* Next compute the peak value
86
val = -val; /* Absolute value */
92
if (peak > portc->left_peak)
93
portc->left_peak = peak;
94
if (peak > portc->right_peak)
95
portc->right_peak = peak;
99
case 16 + 2: /* 16 bits / stereo */
102
int left_peak = 0, right_peak = 0;
107
for (i = 0; i < len; i += 2) /* Each stereo sa,ple pair */
113
/* Do volume computations */
115
val = (*p++) << 8; /* Scale up to 24 bits */
117
val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
120
* Note that legacy mixer volume max is always
123
val = (val * devc->mainvol_left) / 100;
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.
131
* Next compute the peak value
135
val = -val; /* Absolute value */
144
/* Do volume computations */
146
val = (*p++) << 8; /* Scale up to 24 bits */
148
val = (val * portc->left_volume) / DDKSAMPLE_MAX_VOL;
151
* Note that legacy mixer volume max is always
154
val = (val * devc->mainvol_left) / 100;
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.
162
* Next compute the peak value
166
val = -val; /* Absolute value */
168
if (val > right_peak)
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;