4 #include <exec/memory.h>
5 #include <exec/execbase.h>
6 #include <datatypes/soundclass.h>
7 #include <devices/ahi.h>
8 #include <libraries/ahi_sub.h>
9 #include <libraries/asl.h>
11 #include <proto/datatypes.h>
12 #include <proto/dos.h>
13 #include <proto/exec.h>
15 #include "DriverData.h"
18 #define dd ((struct FilesaveData*) AudioCtrl->ahiac_DriverData)
21 /******************************************************************************
22 ** The record slave process ***************************************************
23 ******************************************************************************/
27 static void RecSlave( struct ExecBase
* SysBase
);
29 #if defined( __AROS__ )
31 #include <aros/asmcall.h>
33 AROS_UFH3(void, RecSlaveEntry
,
34 AROS_UFHA(STRPTR
, argPtr
, A0
),
35 AROS_UFHA(ULONG
, argSize
, D0
),
36 AROS_UFHA(struct ExecBase
*, SysBase
, A6
))
45 void RecSlaveEntry(void)
47 struct ExecBase
* SysBase
= *((struct ExecBase
**) 4);
53 static void RecSlave( struct ExecBase
* SysBase
)
55 struct AHIAudioCtrlDrv
* AudioCtrl
;
56 struct DriverBase
* AHIsubBase
;
57 struct FilesaveBase
* FilesaveBase
;
60 BPTR lock
= 0,cd
=0,file
= 0;
64 ULONG count
= 0,offs
= 0,i
;
66 struct AHIRecordMessage RecordMessage
=
73 /* Note that in OS4, we cannot call FindTask(NULL) here, since IExec
74 * is inside AHIsubBase! */
75 AudioCtrl
= (struct AHIAudioCtrlDrv
*) FindTask(NULL
)->tc_UserData
;
76 AHIsubBase
= (struct DriverBase
*) dd
->fs_AHIsubBase
;
77 FilesaveBase
= (struct FilesaveBase
*) AHIsubBase
;
79 RecordMessage
.ahirm_Buffer
= dd
->fs_RecBuffer
;
81 if(!(lock
= Lock(dd
->fs_RecFileReq
->fr_Drawer
,ACCESS_READ
)))
83 cd
= CurrentDir(lock
);
87 struct TagItem newtags
[] =
89 { DTA_GroupID
, GID_SOUND
},
93 struct TagItem attrtags
[] =
95 { SDTA_Sample
, (IPTR
)&samples
},
96 { SDTA_SampleLength
, (IPTR
)&length
},
100 if (!(o
= NewDTObjectA (dd
->fs_RecFileReq
->fr_File
, newtags
)))
103 GetDTAttrsA(o
, attrtags
);
105 else // datatypes.library not open. Open the selected file as raw 8 bit signed instead.
107 if(!(file
= Open(dd
->fs_RecFileReq
->fr_File
,MODE_OLDFILE
)))
109 Seek(file
,0,OFFSET_END
);
110 length
= Seek(file
,0,OFFSET_BEGINNING
);
111 if(!(samples
= AllocVec(length
,MEMF_ANY
)))
113 if(length
!= (ULONG
) Read(file
,samples
,length
))
117 if(!samples
|| !length
)
120 if((dd
->fs_RecSlaveSignal
= AllocSignal(-1)) == -1)
123 // Everything set up. Tell Master we're alive and healthy.
124 Signal((struct Task
*)dd
->fs_MasterTask
,1L<<dd
->fs_RecMasterSignal
);
128 signals
= SetSignal(0L,0L);
129 if(signals
& (SIGBREAKF_CTRL_C
| 1L<<dd
->fs_RecSlaveSignal
))
134 if(count
+RECBUFFERSIZE
-offs
< length
)
136 // End of sample will not be reached; just fill to the end of dd->fs_RecBuffer.
137 for(i
= RECBUFFERSIZE
-offs
;i
>0;i
--)
139 dd
->fs_RecBuffer
[(offs
)<<1] =
140 dd
->fs_RecBuffer
[((offs
)<<1)+1] =
149 // End of sample will be reached. Fill part of buffer, and iterate (== don't break).
150 for(i
= length
-count
;i
>0;i
--)
152 dd
->fs_RecBuffer
[(offs
)<<1] =
153 dd
->fs_RecBuffer
[((offs
)<<1)+1] =
162 CallHookPkt(AudioCtrl
->ahiac_SamplerFunc
,AudioCtrl
,&RecordMessage
);
163 Delay(50*RECBUFFERSIZE
/AudioCtrl
->ahiac_MixFreq
);
173 else // datatypes.library not open.
185 dd
->fs_RecSlaveTask
= NULL
;
186 FreeSignal(dd
->fs_RecSlaveSignal
);
187 dd
->fs_RecSlaveSignal
= -1;
188 // Tell the Master we're dying
189 Signal((struct Task
*)dd
->fs_MasterTask
,1L<<dd
->fs_RecMasterSignal
);
190 // Multitaking will resume when we are dead.