@@ -32,127 +32,157 @@ static struct AHIRequest *AHIReq[2] = { NULL, NULL };
3232static int active = 0 ;
3333static signed char * AHIBuf [2 ] = { NULL , NULL };
3434
35- static void closeLibs (void ) {
36- if (AHIReq [1 ]) {
37- AHIReq [0 ]-> ahir_Link = NULL ; /* in case we are linked to req[0] */
38- if (!CheckIO ((struct IORequest * ) AHIReq [1 ])) {
39- AbortIO ((struct IORequest * ) AHIReq [1 ]);
40- WaitIO ((struct IORequest * ) AHIReq [1 ]);
41- }
42- FreeVec (AHIReq [1 ]);
43- AHIReq [1 ] = NULL ;
44- }
45- if (AHIReq [0 ]) {
46- if (!CheckIO ((struct IORequest * ) AHIReq [0 ])) {
47- AbortIO ((struct IORequest * ) AHIReq [0 ]);
48- WaitIO ((struct IORequest * ) AHIReq [0 ]);
49- }
50- if (AHIReq [0 ]-> ahir_Std .io_Device ) {
51- CloseDevice ((struct IORequest * ) AHIReq [0 ]);
52- AHIReq [0 ]-> ahir_Std .io_Device = NULL ;
53- }
54- DeleteIORequest ((struct IORequest * ) AHIReq [0 ]);
55- AHIReq [0 ] = NULL ;
56- }
57- if (AHImp ) {
58- DeleteMsgPort (AHImp );
59- AHImp = NULL ;
60- }
61- if (AHIBuf [0 ]) {
62- FreeVec (AHIBuf [0 ]);
63- AHIBuf [0 ] = NULL ;
64- }
65- if (AHIBuf [1 ]) {
66- FreeVec (AHIBuf [1 ]);
67- AHIBuf [1 ] = NULL ;
68- }
35+ static void close_libs (void )
36+ {
37+ if (AHIReq [1 ]) {
38+ /* in case req[1] is linked to req[0] */
39+ AHIReq [0 ]-> ahir_Link = NULL ;
40+
41+ if (CheckIO ((struct IORequest * ) AHIReq [1 ]) == NULL ) {
42+ AbortIO ((struct IORequest * ) AHIReq [1 ]);
43+ WaitIO ((struct IORequest * ) AHIReq [1 ]);
44+ }
45+ FreeVec (AHIReq [1 ]);
46+ AHIReq [1 ] = NULL ;
47+ }
48+ if (AHIReq [0 ]) {
49+ if (CheckIO ((struct IORequest * ) AHIReq [0 ]) == NULL ) {
50+ AbortIO ((struct IORequest * ) AHIReq [0 ]);
51+ WaitIO ((struct IORequest * ) AHIReq [0 ]);
52+ }
53+ if (AHIReq [0 ]-> ahir_Std .io_Device ) {
54+ CloseDevice ((struct IORequest * ) AHIReq [0 ]);
55+ AHIReq [0 ]-> ahir_Std .io_Device = NULL ;
56+ }
57+ DeleteIORequest ((struct IORequest * ) AHIReq [0 ]);
58+ AHIReq [0 ] = NULL ;
59+ }
60+ if (AHImp ) {
61+ DeleteMsgPort (AHImp );
62+ AHImp = NULL ;
63+ }
64+ if (AHIBuf [0 ]) {
65+ FreeVec (AHIBuf [0 ]);
66+ AHIBuf [0 ] = NULL ;
67+ }
68+ if (AHIBuf [1 ]) {
69+ FreeVec (AHIBuf [1 ]);
70+ AHIBuf [1 ] = NULL ;
71+ }
6972}
7073
71- static int init (struct options * options ) {
72- AHImp = CreateMsgPort ();
73- if (AHImp ) {
74- AHIReq [0 ] = (struct AHIRequest * )CreateIORequest (AHImp , sizeof (struct AHIRequest ));
75- if (AHIReq [0 ]) {
76- AHIReq [0 ]-> ahir_Version = 4 ;
77- AHIReq [1 ] = AllocVec (sizeof (struct AHIRequest ), SHAREDMEMFLAG );
78- if (AHIReq [1 ]) {
79- if (!OpenDevice (AHINAME , AHI_DEFAULT_UNIT , (struct IORequest * )AHIReq [0 ], 0 )) {
80- AHIReq [0 ]-> ahir_Std .io_Command = CMD_WRITE ;
81- AHIReq [0 ]-> ahir_Std .io_Data = NULL ;
82- AHIReq [0 ]-> ahir_Std .io_Offset = 0 ;
83- AHIReq [0 ]-> ahir_Frequency = options -> rate ;
84- AHIReq [0 ]-> ahir_Type = (options -> format & XMP_FORMAT_8BIT )?
85- ((options -> format & XMP_FORMAT_MONO )? AHIST_M8S : AHIST_S8S ) :
86- ((options -> format & XMP_FORMAT_MONO )? AHIST_M16S : AHIST_S16S );
87- AHIReq [0 ]-> ahir_Volume = 0x10000 ;
88- AHIReq [0 ]-> ahir_Position = 0x8000 ;
89-
90- CopyMem (AHIReq [0 ], AHIReq [1 ], sizeof (struct AHIRequest ));
91-
92- AHIBuf [0 ] = AllocVec (BUFFERSIZE , SHAREDMEMFLAG | MEMF_CLEAR );
93- if (AHIBuf [0 ]) {
94- AHIBuf [1 ] = AllocVec (BUFFERSIZE , SHAREDMEMFLAG | MEMF_CLEAR );
95- if (AHIBuf [1 ]) {
96- /* driver is initialized before calling libxmp, so this is OK : */
97- options -> format &= ~XMP_FORMAT_UNSIGNED ;/* no unsigned with AHI */
98- options -> format &= ~XMP_FORMAT_32BIT ;
99- return 0 ;
100- }
101- }
102- }
103- }
104- }
105- }
106-
107- closeLibs ();
108- return -1 ;
74+ static int init (struct options * options )
75+ {
76+ unsigned long fmt ;
77+
78+ AHImp = CreateMsgPort ();
79+ if (AHImp == NULL ) {
80+ return -1 ;
81+ }
82+
83+ AHIReq [0 ] = (struct AHIRequest * )
84+ CreateIORequest (AHImp , sizeof (struct AHIRequest ));
85+ if (AHIReq [0 ] == NULL ) {
86+ goto err ;
87+ }
88+ AHIReq [0 ]-> ahir_Version = 4 ;
89+
90+ AHIReq [1 ] = AllocVec (sizeof (struct AHIRequest ), SHAREDMEMFLAG );
91+ if (AHIReq [1 ] == NULL ) {
92+ goto err ;
93+ }
94+
95+ if (OpenDevice ((CONST_STRPTR )AHINAME , AHI_DEFAULT_UNIT ,
96+ (struct IORequest * )AHIReq [0 ], 0 ) != 0 ) {
97+ goto err ;
98+ }
99+
100+ if (options -> format & XMP_FORMAT_8BIT ) {
101+ fmt = options -> format & XMP_FORMAT_MONO ? AHIST_M8S : AHIST_S8S ;
102+ } else {
103+ fmt = options -> format & XMP_FORMAT_MONO ? AHIST_M16S : AHIST_S16S ;
104+ }
105+
106+ AHIReq [0 ]-> ahir_Std .io_Command = CMD_WRITE ;
107+ AHIReq [0 ]-> ahir_Std .io_Data = NULL ;
108+ AHIReq [0 ]-> ahir_Std .io_Offset = 0 ;
109+ AHIReq [0 ]-> ahir_Frequency = options -> rate ;
110+ AHIReq [0 ]-> ahir_Type = fmt ;
111+ AHIReq [0 ]-> ahir_Volume = 0x10000 ;
112+ AHIReq [0 ]-> ahir_Position = 0x8000 ;
113+
114+ CopyMem (AHIReq [0 ], AHIReq [1 ], sizeof (struct AHIRequest ));
115+
116+ AHIBuf [0 ] = AllocVec (BUFFERSIZE , SHAREDMEMFLAG | MEMF_CLEAR );
117+ AHIBuf [1 ] = AllocVec (BUFFERSIZE , SHAREDMEMFLAG | MEMF_CLEAR );
118+ if (AHIBuf [0 ] == NULL || AHIBuf [1 ] == NULL ) {
119+ goto err ;
120+ }
121+
122+ options -> format &= ~XMP_FORMAT_UNSIGNED ;
123+ options -> format &= ~XMP_FORMAT_32BIT ;
124+ active = 0 ;
125+ return 0 ;
126+
127+ err :
128+ close_libs ();
129+ return -1 ;
109130}
110131
111- static void deinit (void ) {
112- closeLibs ();
132+ static void deinit (void )
133+ {
134+ close_libs ();
113135}
114136
115- static void play (void * b , int len ) {
116- signed char * in = (signed char * )b ;
117- int chunk ;
118- while (len > 0 ) {
119- if (AHIReq [active ]-> ahir_Std .io_Data ) {
120- WaitIO ((struct IORequest * ) AHIReq [active ]);
121- }
122- chunk = (len < BUFFERSIZE )? len : BUFFERSIZE ;
123- memcpy (AHIBuf [active ], in , chunk );
124- len -= chunk ;
125- in += chunk ;
126-
127- AHIReq [active ]-> ahir_Std .io_Data = AHIBuf [active ];
128- AHIReq [active ]-> ahir_Std .io_Length = chunk ;
129- AHIReq [active ]-> ahir_Link = !CheckIO ((struct IORequest * ) AHIReq [active ^ 1 ]) ? AHIReq [active ^ 1 ] : NULL ;
130- SendIO ((struct IORequest * )AHIReq [active ]);
131- active ^= 1 ;
132- }
137+ static void play (void * b , int len )
138+ {
139+ signed char * in = (signed char * )b ;
140+ int chunk ;
141+
142+ while (len > 0 ) {
143+ if (AHIReq [active ]-> ahir_Std .io_Data ) {
144+ WaitIO ((struct IORequest * ) AHIReq [active ]);
145+ }
146+ chunk = (len < BUFFERSIZE ) ? len : BUFFERSIZE ;
147+ memcpy (AHIBuf [active ], in , chunk );
148+ len -= chunk ;
149+ in += chunk ;
150+
151+ AHIReq [active ]-> ahir_Std .io_Data = AHIBuf [active ];
152+ AHIReq [active ]-> ahir_Std .io_Length = chunk ;
153+ AHIReq [active ]-> ahir_Link =
154+ CheckIO ((struct IORequest * ) AHIReq [active ^ 1 ]) == NULL ?
155+ AHIReq [active ^ 1 ] : NULL ;
156+ SendIO ((struct IORequest * ) AHIReq [active ]);
157+ active ^= 1 ;
158+ }
133159}
134160
135- static void flush (void ) {
161+ static void flush (void )
162+ {
136163}
137164
138- static void onpause (void ) {
165+ static void onpause (void )
166+ {
139167}
140168
141- static void onresume (void ) {
169+ static void onresume (void )
170+ {
142171}
143172
144- static const char * description (void ) {
145- return "Amiga AHI audio" ;
173+ static const char * description (void )
174+ {
175+ return "Amiga AHI audio" ;
146176}
147177
148178const struct sound_driver sound_ahi = {
149- "ahi" ,
150- NULL ,
151- description ,
152- init ,
153- deinit ,
154- play ,
155- flush ,
156- onpause ,
157- onresume
179+ "ahi" ,
180+ NULL ,
181+ description ,
182+ init ,
183+ deinit ,
184+ play ,
185+ flush ,
186+ onpause ,
187+ onresume
158188};
0 commit comments