tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / devs / AHI / Drivers / Void / void-main.c
blob57943bc480b39c0a9c9640de71b1df12bc377460
2 /*
3 * This is a do-nothing example AHI driver that just discards the
4 * sound data that is sent to it. Recording is not supported.
5 */
7 #include <config.h>
9 #include <devices/ahi.h>
10 #include <dos/dostags.h>
11 #include <exec/memory.h>
12 #include <libraries/ahi_sub.h>
13 #include <proto/ahi_sub.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <proto/utility.h>
18 #include <stddef.h>
20 #include "library.h"
21 #include "DriverData.h"
23 #define dd ((struct VoidData*) AudioCtrl->ahiac_DriverData)
25 void
26 SlaveEntry( void );
28 PROCGW( static, void, slaveentry, SlaveEntry );
31 /* There is probably no reason to support all these frequencies. If,
32 * for example, your hardware is locked at 48 kHz, it's ok to only
33 * present one single mixing/recording frequency to the user. If your
34 * hardware has internal resamples and accept any frequency, select a
35 * few common ones.
38 static const LONG frequencies[] =
40 5513, // CD/8
41 8000, // ยต- and A-Law (telephone)
42 9600, // DAT/5
43 10000, // VHS monaural track
44 11025, // CD/4
45 12000, // DAT/4
46 14700, // CD/3
47 16000, // DAT/3, FM/2
48 17640, // CD/2.5
49 18900,
50 19200, // DAT/2.5
51 20000, // VHS Hi-Fi/Video track
52 22050, // CD/2
53 24000, // DAT/2
54 27429, // Highest Paula/OCS frequency
55 29400, // CD/1.5
56 31968, // NTSC FM 2-3 pull-down
57 32000, // DAT/1.5
58 32032, // NTSC FM 2-3 pull-up
59 33075,
60 37800,
61 44056, // NTSC CD 2-3 pull-down
62 44100, // CD
63 44144, // NTSC CD 2-3 pull-up
64 47952, // NTSC DAT 2-3 pull-down
65 48000, // DAT
66 48048, // NTSC DAT 2-3 pull-up
67 88200, // CD*2
68 96000 // DAT*2
71 #define FREQUENCIES (sizeof frequencies / sizeof frequencies[ 0 ])
73 /******************************************************************************
74 ** AHIsub_AllocAudio **********************************************************
75 ******************************************************************************/
77 ULONG
78 _AHIsub_AllocAudio( struct TagItem* taglist,
79 struct AHIAudioCtrlDrv* AudioCtrl,
80 struct DriverBase* AHIsubBase )
82 struct VoidBase* VoidBase = (struct VoidBase*) AHIsubBase;
84 // NOTE! A Real sound card driver would allocate *and lock* the
85 // audio hardware here. If this function gets called a second time,
86 // and the hardware is not capable of handling several audio streams
87 // at the same time, return AHISF_ERROR now!
89 AudioCtrl->ahiac_DriverData = AllocVec( sizeof( struct VoidData ),
90 MEMF_CLEAR | MEMF_PUBLIC );
92 if( dd != NULL )
94 dd->slavesignal = -1;
95 dd->mastersignal = AllocSignal( -1 );
96 dd->mastertask = (struct Process*) FindTask( NULL );
97 dd->ahisubbase = VoidBase;
99 else
101 return AHISF_ERROR;
104 if( dd->mastersignal == -1 )
106 return AHISF_ERROR;
109 return ( AHISF_KNOWHIFI |
110 AHISF_KNOWSTEREO |
111 AHISF_KNOWMULTICHANNEL |
112 AHISF_MIXING |
113 AHISF_TIMING );
117 /******************************************************************************
118 ** AHIsub_FreeAudio ***********************************************************
119 ******************************************************************************/
121 void
122 _AHIsub_FreeAudio( struct AHIAudioCtrlDrv* AudioCtrl,
123 struct DriverBase* AHIsubBase )
125 if( AudioCtrl->ahiac_DriverData != NULL )
127 FreeSignal( dd->mastersignal );
128 FreeVec( AudioCtrl->ahiac_DriverData );
129 AudioCtrl->ahiac_DriverData = NULL;
134 /******************************************************************************
135 ** AHIsub_Disable *************************************************************
136 ******************************************************************************/
138 void
139 _AHIsub_Disable( struct AHIAudioCtrlDrv* AudioCtrl,
140 struct DriverBase* AHIsubBase )
142 // V6 drivers do not have to preserve all registers
144 Forbid();
148 /******************************************************************************
149 ** AHIsub_Enable **************************************************************
150 ******************************************************************************/
152 void
153 _AHIsub_Enable( struct AHIAudioCtrlDrv* AudioCtrl,
154 struct DriverBase* AHIsubBase )
156 // V6 drivers do not have to preserve all registers
158 Permit();
162 /******************************************************************************
163 ** AHIsub_Start ***************************************************************
164 ******************************************************************************/
166 ULONG
167 _AHIsub_Start( ULONG flags,
168 struct AHIAudioCtrlDrv* AudioCtrl,
169 struct DriverBase* AHIsubBase )
171 struct VoidBase* VoidBase = (struct VoidBase*) AHIsubBase;
173 AHIsub_Stop( flags, AudioCtrl );
175 if(flags & AHISF_PLAY)
177 struct TagItem proctags[] =
179 { NP_Entry, (IPTR) &slaveentry },
180 { NP_Name, (IPTR) LibName },
181 { NP_Priority, -1 },
182 { TAG_DONE, 0 }
185 dd->mixbuffer = AllocVec( AudioCtrl->ahiac_BuffSize,
186 MEMF_ANY | MEMF_PUBLIC );
188 if( dd->mixbuffer == NULL ) return AHIE_NOMEM;
190 Forbid();
192 dd->slavetask = CreateNewProc( proctags );
194 if( dd->slavetask != NULL )
196 dd->slavetask->pr_Task.tc_UserData = AudioCtrl;
199 Permit();
201 if( dd->slavetask != NULL )
203 Wait( 1L << dd->mastersignal ); // Wait for slave to come alive
205 if( dd->slavetask == NULL ) // Is slave alive or dead?
207 return AHIE_UNKNOWN;
210 else
212 return AHIE_NOMEM; // Well, out of memory or whatever...
216 if( flags & AHISF_RECORD )
218 return AHIE_UNKNOWN;
221 return AHIE_OK;
225 /******************************************************************************
226 ** AHIsub_Update **************************************************************
227 ******************************************************************************/
229 void
230 _AHIsub_Update( ULONG flags,
231 struct AHIAudioCtrlDrv* AudioCtrl,
232 struct DriverBase* AHIsubBase )
234 // Empty function
238 /******************************************************************************
239 ** AHIsub_Stop ****************************************************************
240 ******************************************************************************/
242 void
243 _AHIsub_Stop( ULONG flags,
244 struct AHIAudioCtrlDrv* AudioCtrl,
245 struct DriverBase* AHIsubBase )
247 if( flags & AHISF_PLAY )
249 if( dd->slavetask != NULL )
251 if( dd->slavesignal != -1 )
253 Signal( (struct Task*) dd->slavetask,
254 1L << dd->slavesignal ); // Kill him!
257 Wait( 1L << dd->mastersignal ); // Wait for slave to die
260 FreeVec( dd->mixbuffer );
261 dd->mixbuffer = NULL;
264 if(flags & AHISF_RECORD)
266 // Do nothing
271 /******************************************************************************
272 ** AHIsub_GetAttr *************************************************************
273 ******************************************************************************/
275 IPTR
276 _AHIsub_GetAttr( ULONG attribute,
277 LONG argument,
278 IPTR def,
279 struct TagItem* taglist,
280 struct AHIAudioCtrlDrv* AudioCtrl,
281 struct DriverBase* AHIsubBase )
283 size_t i;
285 switch( attribute )
287 case AHIDB_Bits:
288 return 32;
290 case AHIDB_Frequencies:
291 return FREQUENCIES;
293 case AHIDB_Frequency: // Index->Frequency
294 return (LONG) frequencies[ argument ];
296 case AHIDB_Index: // Frequency->Index
297 if( argument <= frequencies[ 0 ] )
299 return 0;
302 if( argument >= frequencies[ FREQUENCIES - 1 ] )
304 return FREQUENCIES - 1;
307 for( i = 1; i < FREQUENCIES; i++ )
309 if( frequencies[ i ] > argument )
311 if( ( argument - frequencies[ i - 1 ] ) <
312 ( frequencies[ i ] - argument ) )
314 return i-1;
316 else
318 return i;
323 return 0; // Will not happen
325 case AHIDB_Author:
326 return (IPTR) "Martin 'Leviticus' Blom";
328 case AHIDB_Copyright:
329 return (IPTR) "Public Domain";
331 case AHIDB_Version:
332 return (IPTR) LibIDString;
334 case AHIDB_Record:
335 return FALSE;
337 case AHIDB_Realtime:
338 return TRUE; // This is not actually true
340 case AHIDB_Outputs:
341 return 1;
343 case AHIDB_Output:
344 return (IPTR) "Void"; // We have only one "output"!
346 default:
347 return def;
352 /******************************************************************************
353 ** AHIsub_HardwareControl *****************************************************
354 ******************************************************************************/
356 ULONG
357 _AHIsub_HardwareControl( ULONG attribute,
358 LONG argument,
359 struct AHIAudioCtrlDrv* AudioCtrl,
360 struct DriverBase* AHIsubBase )
362 return 0;