2 * Emuxki BeOS Driver for Creative Labs SBLive!/Audigy series
4 * Copyright (c) 2002, Jerome Duval (jerome.duval@free.fr)
7 * Alexander Coers Alexander.Coers@gmx.de
8 * Fredrik Modéen fredrik@modeen.se
10 * Copyright (c) 2001 The NetBSD Foundation, Inc.
11 * All rights reserved.
13 * This code is derived from software contributed to The NetBSD Foundation
14 * by Yannick Montulet.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the NetBSD
27 * Foundation, Inc. and its contributors.
28 * 4. Neither the name of The NetBSD Foundation nor the names of its
29 * contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
33 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
36 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
44 #if !defined(_EMUXKI_H)
48 #include <SupportDefs.h>
50 #include "emuxkireg.h"
53 #include "hmulti_audio.h"
55 #include "joystick_driver.h"
58 #define CREATIVELABS_VENDOR_ID 0x1102 /* Creative Labs */
59 #define CREATIVELABS_SBLIVE_DEVICE_ID 0x0002 /* Creative Labs SoundBlaster Live */
60 #define CREATIVELABS_AUDIGY_DEVICE_ID 0x0004 /* Creative Labs Audigy and Audigy 2 */
61 #define CREATIVELABS_AUDIGY2_VALUE_DEVICE_ID 0x0008 /* Creative Labs Audigy 2 Value */
63 #define AUDIGY 1 // Audigy seems to work
67 #define MIDI 0 // disabled MIDI for the time being on R5
70 #define VERSION "Version alpha 7, Copyright (c) 2002,2003 Jérôme Duval, compiled on " __DATE__ " " __TIME__
71 #define DRIVER_NAME "emuxki"
72 #define FRIENDLY_NAME "Emuxki"
73 #define FRIENDLY_NAME_LIVE FRIENDLY_NAME" SB Live"
74 #define FRIENDLY_NAME_LIVE_5_1 FRIENDLY_NAME_LIVE" 5.1"
75 #define FRIENDLY_NAME_AUDIGY FRIENDLY_NAME" Audigy"
76 #define FRIENDLY_NAME_AUDIGY2 FRIENDLY_NAME_AUDIGY" 2"
77 #define FRIENDLY_NAME_AUDIGY2_VALUE FRIENDLY_NAME_AUDIGY2" Value"
78 #define AUTHOR "Jérôme Duval"
92 extern emuxki_settings current_settings
;
98 #define HCFG 0x14 /* Hardware Configuration Register of SB-Live */
99 #define HCFG_JOYENABLE 0x00000200 /* Mask for enabling Joystick */
101 extern generic_gameport_module
* gameport
;
103 typedef struct _joy_dev
108 /* End Gameport stuff*/
114 typedef struct _midi_dev
{
125 * Emu10k1 hardware limits
128 #define EMU_PTESIZE 4096
129 #define EMU_MAXPTE ((EMU_CHAN_PSST_LOOPSTARTADDR_MASK + 1) / \
131 #define EMU_NUMCHAN 64
132 #define EMU_NUMRECSRCS 3
134 #define EMU_DMA_ALIGN 4096
135 #define EMU_DMAMEM_NSEG 1
138 * Emu10k1 memory managment
141 typedef struct _emuxki_mem
{
142 LIST_ENTRY(_emuxki_mem
) next
;
148 #define EMU_RMEM 0xffff /* recording memory */
152 * Emu10k1 play channel params
155 typedef struct _emuxki_chanparms_fxsend
{
158 } a
, b
, c
, d
, e
, f
, g
, h
;
159 } emuxki_chanparms_fxsend
;
161 typedef struct _emuxki_chanparms_pitch
{
162 uint16 intial
; /* 4 bits of octave, 12 bits of fractional
164 uint16 current
;/* 0x4000 == unity pitch shift */
165 uint16 target
; /* 0x4000 == unity pitch shift */
166 uint8 envelope_amount
; /* Signed 2's complement, +/-
167 * one octave peak extremes */
168 } emuxki_chanparms_pitch
;
170 typedef struct _emuxki_chanparms_envelope
{
171 uint16 current_state
; /* 0x8000-n == 666*n usec delay */
172 uint8 hold_time
; /* 127-n == n*(volume ? 88.2 :
174 uint8 attack_time
; /* 0 = infinite, 1 = (volume ? 11 :
175 * 10.9) msec, 0x7f = 5.5msec */
176 uint8 sustain_level
; /* 127 = full, 0 = off, 0.75dB
178 uint8 decay_time
; /* 0 = 43.7msec, 1 = 21.8msec, 0x7f =
180 } emuxki_chanparms_envelope
;
182 typedef struct _emuxki_chanparms_volume
{
185 emuxki_chanparms_envelope envelope
;
186 } emuxki_chanparms_volume
;
188 typedef struct _emuxki_chanparms_filter
{
189 uint16 initial_cutoff_frequency
;
191 * 6 most significant bits are semitones, 2 least significant bits
194 uint16 current_cutoff_frequency
;
195 uint16 target_cutoff_frequency
;
196 uint8 lowpass_resonance_height
;
197 uint8 interpolation_ROM
; /* 1 = full band, 7 = low
199 uint8 envelope_amount
; /* Signed 2's complement, +/-
200 * six octaves peak extremes */
201 uint8 LFO_modulation_depth
; /* Signed 2's complement, +/-
202 * three octave extremes */
203 } emuxki_chanparms_filter
;
205 typedef struct _emuxki_chanparms_loop
{
206 uint32 start
; /* index in the PTB (in samples) */
207 uint32 end
; /* index in the PTB (in samples) */
208 } emuxki_chanparms_loop
;
210 typedef struct _emuxki_chanparms_modulation
{
211 emuxki_chanparms_envelope envelope
;
212 uint16 LFO_state
; /* 0x8000-n = 666*n usec delay */
213 } emuxki_chanparms_modulation
;
215 typedef struct _emuxki_chanparms_vibrato_LFO
{
216 uint16 state
; /* 0x8000-n == 666*n usec delay */
217 uint8 modulation_depth
; /* Signed 2's complement, +/-
218 * one octave extremes */
219 uint8 vibrato_depth
; /* Signed 2's complement, +/- one
221 uint8 frequency
; /* 0.039Hz steps, maximum of 9.85 Hz */
222 } emuxki_chanparms_vibrato_LFO
;
224 typedef struct _emuxki_channel
{
225 uint8 num
; /* voice number */
226 struct _emuxki_voice
*voice
;
227 emuxki_chanparms_fxsend fxsend
;
228 emuxki_chanparms_pitch pitch
;
229 uint16 initial_attenuation
; /* 0.375dB steps */
230 emuxki_chanparms_volume volume
;
231 emuxki_chanparms_filter filter
;
232 emuxki_chanparms_loop loop
;
233 emuxki_chanparms_modulation modulation
;
234 emuxki_chanparms_vibrato_LFO vibrato_LFO
;
238 typedef struct _emuxki_recparams
{
239 uint32 efx_voices
[2];
254 #define EMU_USE_PLAY (1 << 0)
255 #define EMU_USE_RECORD (1 << 1)
256 #define EMU_STATE_STARTED (1 << 0)
257 #define EMU_STEREO_NOTSET 0xFF
259 typedef struct _emuxki_voice
{
260 struct _emuxki_stream
*stream
;
268 emuxki_channel
*chan
[2];
269 emuxki_recsrc_t source
;
271 emuxki_recparams recparams
;
273 uint16 blksize
;/* in samples */
274 uint16 trigblk
;/* blk on which to trigger inth */
275 uint16 blkmod
; /* Modulo value to wrap trigblk */
278 LIST_ENTRY(_emuxki_voice
) next
;
286 typedef struct _emuxki_stream
{
287 struct _emuxki_dev
*card
;
297 LIST_HEAD(, _emuxki_voice
) voices
;
298 emuxki_voice
*first_voice
;
300 LIST_ENTRY(_emuxki_stream
) next
;
302 void (*inth
) (void *);
306 volatile int64 frames_count
; // for play or record
307 volatile bigtime_t real_time
; // for play or record
308 volatile int32 buffer_cycle
; // for play or record
316 #define EMU_GPR_FIRST_MIX 16
319 EMU_MIX_GAIN
= 1 << 0,
320 EMU_MIX_MONO
= 1 << 1,
321 EMU_MIX_STEREO
= 1 << 2,
322 EMU_MIX_TMP
= 1 << 3,
323 EMU_MIX_MUTE
= 1 << 4,
324 EMU_MIX_PLAYBACK
= 1 << 5,
325 EMU_MIX_RECORD
= 1 << 6
328 typedef struct _emuxki_gpr
{
330 emuxki_gpr_type type
;
341 EMU_DIGITAL_MODE
= 1 << 0,
342 EMU_AUDIO_MODE
= 1 << 1
343 } emuxki_parameter_type
;
350 typedef struct _emuxki_dev
{
351 char name
[DEVNAME
]; /* used for resources */
353 device_config config
;
358 void *silentpage_log_base
;
359 void *silentpage_phy_base
;
360 area_id silentpage_area
;
362 emuxki_channel
*channel
[EMU_NUMCHAN
];
363 emuxki_voice
*recsrc
[EMU_NUMRECSRCS
];
365 LIST_HEAD(, _emuxki_mem
) mem
;
367 LIST_HEAD(, _emuxki_stream
) streams
;
371 #define EMU_TIMER_STATE_ENABLED 1
372 uint8 play_mode
; // number of channels to be played : 2, 4, 6
373 bool digital_enabled
; // if digital is enabled and analog is disabled
375 emuxki_stream
*pstream
;
376 emuxki_stream
*pstream2
;
377 emuxki_stream
*rstream
;
378 emuxki_stream
*rstream2
;
380 sem_id buffer_ready_sem
;
393 extern int32 num_cards
;
394 extern emuxki_dev cards
[NUM_CARDS
];
396 void emuxki_mem_free(emuxki_dev
*card
, void *ptr
);
397 void * emuxki_pmem_alloc(emuxki_dev
*card
, size_t size
);
398 void * emuxki_rmem_alloc(emuxki_dev
*card
, size_t size
);
399 status_t
emuxki_voice_commit_parms(emuxki_voice
*voice
);
400 status_t
emuxki_voice_set_audioparms(emuxki_voice
*voice
, uint8 stereo
,
401 uint8 b16
, uint32 srate
);
402 status_t
emuxki_voice_set_recparms(emuxki_voice
*voice
, emuxki_recsrc_t recsrc
,
403 emuxki_recparams
*recparams
);
404 status_t
emuxki_voice_set_bufparms(emuxki_voice
*voice
, void *ptr
,
405 uint32 bufsize
, uint16 blksize
);
406 void emuxki_voice_start(emuxki_voice
*voice
);
407 void emuxki_voice_halt(emuxki_voice
*voice
);
408 emuxki_voice
*emuxki_voice_new(emuxki_stream
*stream
, uint8 use
, uint8 voicenum
);
409 void emuxki_voice_delete(emuxki_voice
*voice
);
411 status_t
emuxki_stream_set_audioparms(emuxki_stream
*stream
, bool stereo
, uint8 channels
,
412 uint8 b16
, uint32 sample_rate
);
413 status_t
emuxki_stream_set_recparms(emuxki_stream
*stream
, emuxki_recsrc_t recsrc
,
414 emuxki_recparams
*recparams
);
415 status_t
emuxki_stream_commit_parms(emuxki_stream
*stream
);
416 status_t
emuxki_stream_get_nth_buffer(emuxki_stream
*stream
, uint8 chan
, uint8 buf
,
417 char** buffer
, size_t *stride
);
418 void emuxki_stream_start(emuxki_stream
*stream
, void (*inth
) (void *), void *inthparam
);
419 void emuxki_stream_halt(emuxki_stream
*stream
);
420 emuxki_stream
*emuxki_stream_new(emuxki_dev
*card
, uint8 use
, uint32 bufframes
, uint8 bufcount
);
421 void emuxki_stream_delete(emuxki_stream
*stream
);
423 void emuxki_dump_fx(emuxki_dev
* card
);
424 void emuxki_gpr_dump(emuxki_dev
* card
, uint16 count
);
425 void emuxki_gpr_set(emuxki_dev
*card
, emuxki_gpr
*gpr
, int32 type
, float *values
);
426 void emuxki_gpr_get(emuxki_dev
*card
, emuxki_gpr
*gpr
, int32 type
, float *values
);
428 void emuxki_parameter_set(emuxki_dev
*card
, const void*, int32 type
, int32
*value
);
429 void emuxki_parameter_get(emuxki_dev
*card
, const void*, int32 type
, int32
*value
);
431 extern void midi_interrupt_op(int32 op
, void * data
);
432 extern bool midi_interrupt(emuxki_dev
*card
);