dsp.c (45248baa3cf36c20d02c57816735b247c4e62eaf) dsp.c (bd18f3340844b7bf72499464ee51572b9a48c7e5)
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 43 unchanged lines hidden (view full) ---

52getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch)
53{
54 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
55 ("getchns: read and write both prioritised"));
56
57 if ((d->flags & SD_F_SIMPLEX) && (d->flags & SD_F_PRIO_SET)) {
58 *rdch = (d->flags & SD_F_PRIO_RD)? d->arec[chan] : &d->fakechan;
59 *wrch = (d->flags & SD_F_PRIO_WR)? d->aplay[chan] : &d->fakechan;
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 43 unchanged lines hidden (view full) ---

52getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch)
53{
54 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
55 ("getchns: read and write both prioritised"));
56
57 if ((d->flags & SD_F_SIMPLEX) && (d->flags & SD_F_PRIO_SET)) {
58 *rdch = (d->flags & SD_F_PRIO_RD)? d->arec[chan] : &d->fakechan;
59 *wrch = (d->flags & SD_F_PRIO_WR)? d->aplay[chan] : &d->fakechan;
60 d->fakechan.flags |= CHN_F_BUSY;
60 } else {
61 *rdch = d->arec[chan];
62 *wrch = d->aplay[chan];
63 }
64 return 0;
65}
66
67static void
68setchns(snddev_info *d, int chan)
69{
70 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
71 ("getchns: read and write both prioritised"));
72 d->flags |= SD_F_DIR_SET;
73 if (d->swap) d->swap(d->devinfo, (d->flags & SD_F_PRIO_WR)? PCMDIR_PLAY : PCMDIR_REC);
74}
75
76int
77dsp_open(snddev_info *d, int chan, int oflags, int devtype)
78{
61 } else {
62 *rdch = d->arec[chan];
63 *wrch = d->aplay[chan];
64 }
65 return 0;
66}
67
68static void
69setchns(snddev_info *d, int chan)
70{
71 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
72 ("getchns: read and write both prioritised"));
73 d->flags |= SD_F_DIR_SET;
74 if (d->swap) d->swap(d->devinfo, (d->flags & SD_F_PRIO_WR)? PCMDIR_PLAY : PCMDIR_REC);
75}
76
77int
78dsp_open(snddev_info *d, int chan, int oflags, int devtype)
79{
79 pcm_channel *rdch = NULL, *wrch = NULL;
80 pcm_channel *rdch, *wrch;
80 u_int32_t fmt;
81
82 if (chan >= d->chancount) return ENODEV;
81 u_int32_t fmt;
82
83 if (chan >= d->chancount) return ENODEV;
83 if (d->aplay[chan] || d->arec[chan]) return EBUSY;
84 if ((d->flags & SD_F_SIMPLEX) && (d->ref[chan] > 0)) return EBUSY;
85 rdch = d->arec[chan];
86 wrch = d->aplay[chan];
84 if (oflags & FREAD) {
87 if (oflags & FREAD) {
85 rdch = allocchn(d, PCMDIR_REC);
86 if (!rdch) return EBUSY;
88 if (rdch == NULL) {
89 rdch = allocchn(d, PCMDIR_REC);
90 if (!rdch) return EBUSY;
91 } else return EBUSY;
87 }
88 if (oflags & FWRITE) {
92 }
93 if (oflags & FWRITE) {
89 wrch = allocchn(d, PCMDIR_PLAY);
90 if (!wrch) {
91 if (rdch) rdch->flags &= ~CHN_F_BUSY;
92 return EBUSY;
93 }
94 if (wrch == NULL) {
95 wrch = allocchn(d, PCMDIR_PLAY);
96 if (!wrch && (oflags & FREAD)) {
97 rdch->flags &= ~CHN_F_BUSY;
98 return EBUSY;
99 }
100 } else return EBUSY;
94 }
95 d->aplay[chan] = wrch;
96 d->arec[chan] = rdch;
101 }
102 d->aplay[chan] = wrch;
103 d->arec[chan] = rdch;
104 d->ref[chan]++;
97 switch (devtype) {
98 case SND_DEV_DSP16:
99 fmt = AFMT_S16_LE;
100 break;
101
102 case SND_DEV_DSP:
103 fmt = AFMT_U8;
104 break;

--- 5 unchanged lines hidden (view full) ---

110 case SND_DEV_NORESET:
111 fmt = 0;
112 break;
113
114 default:
115 return ENXIO;
116 }
117
105 switch (devtype) {
106 case SND_DEV_DSP16:
107 fmt = AFMT_S16_LE;
108 break;
109
110 case SND_DEV_DSP:
111 fmt = AFMT_U8;
112 break;

--- 5 unchanged lines hidden (view full) ---

118 case SND_DEV_NORESET:
119 fmt = 0;
120 break;
121
122 default:
123 return ENXIO;
124 }
125
118 if (rdch) {
126 if (rdch && (oflags & FREAD)) {
119 chn_reset(rdch);
120 if (oflags & O_NONBLOCK) rdch->flags |= CHN_F_NBIO;
121 if (fmt) {
122 rdch->volume = (100 << 8) | 100;
123 rdch->format = fmt;
124 rdch->speed = DSP_DEFAULT_SPEED;
125 rdch->blocksize = 2048;
126 }
127 }
127 chn_reset(rdch);
128 if (oflags & O_NONBLOCK) rdch->flags |= CHN_F_NBIO;
129 if (fmt) {
130 rdch->volume = (100 << 8) | 100;
131 rdch->format = fmt;
132 rdch->speed = DSP_DEFAULT_SPEED;
133 rdch->blocksize = 2048;
134 }
135 }
128 if (wrch) {
136 if (wrch && (oflags & FWRITE)) {
129 chn_reset(wrch);
130 if (oflags & O_NONBLOCK) wrch->flags |= CHN_F_NBIO;
131 if (fmt) {
132 wrch->volume = (100 << 8) | 100;
133 wrch->format = fmt;
134 wrch->speed = DSP_DEFAULT_SPEED;
135 wrch->blocksize = 2048;
136 }
137 }
138 return 0;
139}
140
141int
142dsp_close(snddev_info *d, int chan, int devtype)
143{
144 pcm_channel *rdch, *wrch;
145
137 chn_reset(wrch);
138 if (oflags & O_NONBLOCK) wrch->flags |= CHN_F_NBIO;
139 if (fmt) {
140 wrch->volume = (100 << 8) | 100;
141 wrch->format = fmt;
142 wrch->speed = DSP_DEFAULT_SPEED;
143 wrch->blocksize = 2048;
144 }
145 }
146 return 0;
147}
148
149int
150dsp_close(snddev_info *d, int chan, int devtype)
151{
152 pcm_channel *rdch, *wrch;
153
154 d->ref[chan]--;
155 if (d->ref[chan]) return 0;
146 d->flags &= ~SD_F_TRANSIENT;
147 rdch = d->arec[chan];
148 wrch = d->aplay[chan];
149
150 if (rdch) {
151 chn_abort(rdch);
152 rdch->flags &= ~(CHN_F_BUSY | CHN_F_RUNNING | CHN_F_MAPPED);
153 }

--- 459 unchanged lines hidden ---
156 d->flags &= ~SD_F_TRANSIENT;
157 rdch = d->arec[chan];
158 wrch = d->aplay[chan];
159
160 if (rdch) {
161 chn_abort(rdch);
162 rdch->flags &= ~(CHN_F_BUSY | CHN_F_RUNNING | CHN_F_MAPPED);
163 }

--- 459 unchanged lines hidden ---