1 Index: src/hostapi/asihpi/pa_linux_asihpi.c
2 ===================================================================
3 --- src/hostapi/asihpi/pa_linux_asihpi.c (revision 1645)
4 +++ src/hostapi/asihpi/pa_linux_asihpi.c (working copy)
6 /** Check return value of HPI function, and map it to PaError */
7 #define PA_ASIHPI_UNLESS_(expr, paError) \
9 - HW16 hpiError = (expr); \
10 + hpi_err_t hpiError = (expr); \
11 /* If HPI error occurred */ \
12 if( UNLIKELY( hpiError ) ) \
15 /* implementation specific data goes here */
17 PaHostApiIndex hostApiIndex;
18 - /** HPI subsystem pointer */
19 - HPI_HSUBSYS *subSys;
21 PaAsiHpiHostApiRepresentation;
25 /* implementation specific data goes here */
27 - /** HPI subsystem (required for most HPI calls) */
28 - HPI_HSUBSYS *subSys;
31 + uint16_t adapterIndex;
32 /** Adapter model number (hex) */
34 + uint16_t adapterType;
35 /** Adapter HW/SW version */
36 - HW16 adapterVersion;
37 + uint16_t adapterVersion;
38 /** Adapter serial number */
39 - HW32 adapterSerialNumber;
40 + uint32_t adapterSerialNumber;
43 + uint16_t streamIndex;
44 /** 0=Input, 1=Output (HPI streams are either input or output but not both) */
45 - HW16 streamIsOutput;
46 + uint16_t streamIsOutput;
52 /** Device information (HPI handles, etc) */
53 PaAsiHpiDeviceInfo *hpiDevice;
54 - /** Stream handle, as passed to HPI interface.
55 - HACK: we assume types HPI_HISTREAM and HPI_HOSTREAM are the same...
56 - (both are HW32 up to version 3.00 of ASIHPI, and hopefully they stay that way) */
57 - HPI_HISTREAM hpiStream;
58 + /** Stream handle, as passed to HPI interface. */
59 + hpi_handle_t hpiStream;
60 /** Stream format, as passed to HPI interface */
61 - HPI_FORMAT hpiFormat;
62 + struct hpi_format hpiFormat;
63 /** Number of bytes per frame, derived from hpiFormat and saved for convenience */
65 + uint32_t bytesPerFrame;
66 /** Size of hardware (on-card) buffer of stream in bytes */
67 - HW32 hardwareBufferSize;
68 + uint32_t hardwareBufferSize;
69 /** Size of host (BBM) buffer of stream in bytes (if used) */
70 - HW32 hostBufferSize;
71 + uint32_t hostBufferSize;
72 /** Upper limit on the utilization of output stream buffer (both hardware and host).
73 This prevents large latencies in an output-only stream with a potentially huge buffer
74 and a fast data generator, which would otherwise keep the hardware buffer filled to
75 capacity. See also the "Hardware Buffering=off" option in the AudioScience WAV driver. */
76 - HW32 outputBufferCap;
77 + uint32_t outputBufferCap;
78 /** Sample buffer (halfway station between HPI and buffer processor) */
80 + uint8_t *tempBuffer;
81 /** Sample buffer size, in bytes */
82 - HW32 tempBufferSize;
83 + uint32_t tempBufferSize;
85 PaAsiHpiStreamComponent;
88 PaAsiHpiStreamComponent *input, *output;
90 /** Polling interval (in milliseconds) */
91 - HW32 pollingInterval;
92 + uint32_t pollingInterval;
93 /** Are we running in callback mode? */
95 /** Number of frames to transfer at a time to/from HPI */
97 typedef struct PaAsiHpiStreamInfo
99 /** HPI stream state (HPI_STATE_STOPPED, HPI_STATE_PLAYING, etc.) */
102 /** Size (in bytes) of recording/playback data buffer in HPI driver */
104 + uint32_t bufferSize;
105 /** Amount of data (in bytes) available in the buffer */
108 /** Number of frames played/recorded since last stream reset */
110 + uint32_t frameCounter;
111 /** Amount of data (in bytes) in hardware (on-card) buffer.
112 This differs from dataSize if bus mastering (BBM) is used, which introduces another
113 driver-level buffer to which dataSize/bufferSize then refers. */
115 + uint32_t auxDataSize;
116 /** Total number of data frames currently buffered by HPI driver (host + hw buffers) */
117 - HW32 totalBufferedData;
118 + uint32_t totalBufferedData;
119 /** Size of immediately available data (for input) or space (for output) in frames.
120 This only checks the first-level buffer (typically host buffer). This amount can be
121 transferred immediately. */
122 - HW32 availableFrames;
123 + uint32_t availableFrames;
124 /** Indicates that hardware buffer is getting too full */
126 /** Indicates that hardware buffer is getting too empty */
127 @@ -479,21 +473,21 @@
129 /* Functions specific to this API */
130 static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostApi );
131 -static HW16 PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat );
132 -static PaSampleFormat PaAsiHpi_HpiToPaFormat( HW16 hpiFormat );
133 +static uint16_t PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat );
134 +static PaSampleFormat PaAsiHpi_HpiToPaFormat( uint16_t hpiFormat );
135 static PaError PaAsiHpi_CreateFormat( struct PaUtilHostApiRepresentation *hostApi,
136 const PaStreamParameters *parameters, double sampleRate,
137 - PaAsiHpiDeviceInfo **hpiDevice, HPI_FORMAT *hpiFormat );
138 + PaAsiHpiDeviceInfo **hpiDevice, struct hpi_format *hpiFormat );
139 static PaError PaAsiHpi_OpenInput( struct PaUtilHostApiRepresentation *hostApi,
140 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
141 - HPI_HISTREAM *hpiStream );
142 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
143 + hpi_handle_t *hpiStream );
144 static PaError PaAsiHpi_OpenOutput( struct PaUtilHostApiRepresentation *hostApi,
145 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
146 - HPI_HOSTREAM *hpiStream );
147 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
148 + hpi_handle_t *hpiStream );
149 static PaError PaAsiHpi_GetStreamInfo( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStreamInfo *info );
150 static void PaAsiHpi_StreamComponentDump( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStream *stream );
151 static void PaAsiHpi_StreamDump( PaAsiHpiStream *stream );
152 -static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, HW32 pollingInterval,
153 +static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, uint32_t pollingInterval,
154 unsigned long framesPerPaHostBuffer, PaTime suggestedLatency );
155 static PaError PaAsiHpi_PrimeOutputWithSilence( PaAsiHpiStream *stream );
156 static PaError PaAsiHpi_StartStream( PaAsiHpiStream *stream, int outputPrimed );
157 @@ -529,42 +523,40 @@
158 PaUtilHostApiRepresentation *hostApi = &hpiHostApi->baseHostApiRep;
159 PaHostApiInfo *baseApiInfo = &hostApi->info;
160 PaAsiHpiDeviceInfo *hpiDeviceList;
161 - HW16 adapterList[ HPI_MAX_ADAPTERS ];
165 + hpi_err_t hpiError = 0;
166 int i, j, deviceCount = 0, deviceIndex = 0;
168 assert( hpiHostApi );
169 - assert( hpiHostApi->subSys );
171 /* Look for adapters (not strictly necessary, as AdapterOpen can do the same, but this */
172 /* way we have less errors since we do not try to open adapters we know aren't there) */
173 /* Errors not considered critical here (subsystem may report 0 devices), but report them */
175 - PA_ASIHPI_UNLESS_( HPI_SubSysFindAdapters( hpiHostApi->subSys, &numAdapters,
176 - adapterList, HPI_MAX_ADAPTERS ), paNoError );
177 + PA_ASIHPI_UNLESS_( HPI_SubSysGetNumAdapters( NULL, &numAdapters), paNoError );
179 /* First open and count the number of devices (= number of streams), to ease memory allocation */
180 - for( i=0; i < HPI_MAX_ADAPTERS; ++i )
181 + for( i=0; i < numAdapters; ++i )
183 - HW16 inStreams, outStreams;
187 + uint16_t inStreams, outStreams;
193 - /* If no adapter found at this index, skip it */
194 - if( adapterList[i] == 0 )
195 + hpiError = HPI_SubSysGetAdapter(NULL, i, &idx, &type);
199 /* Try to open adapter */
200 - hpiError = HPI_AdapterOpen( hpiHostApi->subSys, i );
201 + hpiError = HPI_AdapterOpen( NULL, idx );
202 /* Report error and skip to next device on failure */
205 PA_ASIHPI_REPORT_ERROR_( hpiError );
208 - hpiError = HPI_AdapterGetInfo( hpiHostApi->subSys, i,
209 + hpiError = HPI_AdapterGetInfo( NULL, idx,
210 &outStreams, &inStreams, &version, &serial, &type );
211 /* Skip to next device on failure */
213 @@ -597,19 +589,20 @@
214 paInsufficientMemory );
216 /* Now query devices again for information */
217 - for( i=0; i < HPI_MAX_ADAPTERS; ++i )
218 + for( i=0; i < numAdapters; ++i )
220 - HW16 inStreams, outStreams;
224 + uint16_t inStreams, outStreams;
230 - /* If no adapter found at this index, skip it */
231 - if( adapterList[i] == 0 )
232 + hpiError = HPI_SubSysGetAdapter(NULL, i, &idx, &type);
236 /* Assume adapter is still open from previous round */
237 - hpiError = HPI_AdapterGetInfo( hpiHostApi->subSys, i,
238 + hpiError = HPI_AdapterGetInfo( NULL, idx,
239 &outStreams, &inStreams, &version, &serial, &type );
240 /* Report error and skip to next device on failure */
245 PA_DEBUG(( "Found HPI Adapter ID=%4X Idx=%d #In=%d #Out=%d S/N=%d HWver=%c%d DSPver=%03d\n",
246 - type, i, inStreams, outStreams, serial,
247 + type, idx, inStreams, outStreams, serial,
248 ((version>>3)&0xf)+'A', /* Hw version major */
249 version&0x7, /* Hw version minor */
250 ((version>>13)*100)+((version>>7)&0x3f) /* DSP code version */
253 memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );
254 /* Set implementation-specific device details */
255 - hpiDevice->subSys = hpiHostApi->subSys;
256 - hpiDevice->adapterIndex = i;
257 + hpiDevice->adapterIndex = idx;
258 hpiDevice->adapterType = type;
259 hpiDevice->adapterVersion = version;
260 hpiDevice->adapterSerialNumber = serial;
263 memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );
264 /* Set implementation-specific device details */
265 - hpiDevice->subSys = hpiHostApi->subSys;
266 - hpiDevice->adapterIndex = i;
267 + hpiDevice->adapterIndex = idx;
268 hpiDevice->adapterType = type;
269 hpiDevice->adapterVersion = version;
270 hpiDevice->adapterSerialNumber = serial;
272 PA_UNLESS_( hpiHostApi->allocations = PaUtil_CreateAllocationGroup(), paInsufficientMemory );
274 hpiHostApi->hostApiIndex = hostApiIndex;
275 - hpiHostApi->subSys = NULL;
277 /* Try to initialize HPI subsystem */
278 - if( ( hpiHostApi->subSys = HPI_SubSysCreate() ) == NULL)
279 + if(HPI_SubSysCreate() == NULL)
281 /* the V19 development docs say that if an implementation
282 * detects that it cannot be used, it should return a NULL
283 @@ -761,10 +751,10 @@
288 - PA_ASIHPI_UNLESS_( HPI_SubSysGetVersion( hpiHostApi->subSys, &hpiVersion ), paUnanticipatedHostError );
289 - PA_DEBUG(( "HPI interface v%d.%02d\n",
290 - hpiVersion >> 8, 10*((hpiVersion & 0xF0) >> 4) + (hpiVersion & 0x0F) ));
291 + uint32_t hpiVersion;
292 + PA_ASIHPI_UNLESS_( HPI_SubSysGetVersionEx( NULL, &hpiVersion ), paUnanticipatedHostError );
293 + PA_DEBUG(( "HPI interface v%d.%02d.%02d\n",
294 + hpiVersion >> 16, (hpiVersion >> 8) & 0x0F, (hpiVersion & 0x0F) ));
297 *hostApi = &hpiHostApi->baseHostApiRep;
298 @@ -820,25 +810,22 @@
301 /* Get rid of HPI-specific structures */
302 - if( hpiHostApi->subSys )
303 + uint16_t lastAdapterIndex = HPI_MAX_ADAPTERS;
304 + /* Iterate through device list and close adapters */
305 + for( i=0; i < hostApi->info.deviceCount; ++i )
307 - HW16 lastAdapterIndex = HPI_MAX_ADAPTERS;
308 - /* Iterate through device list and close adapters */
309 - for( i=0; i < hostApi->info.deviceCount; ++i )
310 + PaAsiHpiDeviceInfo *hpiDevice = (PaAsiHpiDeviceInfo *) hostApi->deviceInfos[ i ];
311 + /* Close adapter only if it differs from previous one */
312 + if( hpiDevice->adapterIndex != lastAdapterIndex )
314 - PaAsiHpiDeviceInfo *hpiDevice = (PaAsiHpiDeviceInfo *) hostApi->deviceInfos[ i ];
315 - /* Close adapter only if it differs from previous one */
316 - if( hpiDevice->adapterIndex != lastAdapterIndex )
318 - /* Ignore errors (report only during debugging) */
319 - PA_ASIHPI_UNLESS_( HPI_AdapterClose( hpiHostApi->subSys,
320 - hpiDevice->adapterIndex ), paNoError );
321 - lastAdapterIndex = hpiDevice->adapterIndex;
323 + /* Ignore errors (report only during debugging) */
324 + PA_ASIHPI_UNLESS_( HPI_AdapterClose( NULL,
325 + hpiDevice->adapterIndex ), paNoError );
326 + lastAdapterIndex = hpiDevice->adapterIndex;
328 - /* Finally dismantle HPI subsystem */
329 - HPI_SubSysFree( hpiHostApi->subSys );
331 + /* Finally dismantle HPI subsystem */
332 + HPI_SubSysFree( NULL );
334 if( hpiHostApi->allocations )
338 @return HPI sample format
340 -static HW16 PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat )
341 +static uint16_t PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat )
343 /* Ignore interleaving flag */
344 switch( paFormat & ~paNonInterleaved )
347 @return PortAudio sample format
349 -static PaSampleFormat PaAsiHpi_HpiToPaFormat( HW16 hpiFormat )
350 +static PaSampleFormat PaAsiHpi_HpiToPaFormat( uint16_t hpiFormat )
354 @@ -938,11 +925,11 @@
356 static PaError PaAsiHpi_CreateFormat( struct PaUtilHostApiRepresentation *hostApi,
357 const PaStreamParameters *parameters, double sampleRate,
358 - PaAsiHpiDeviceInfo **hpiDevice, HPI_FORMAT *hpiFormat )
359 + PaAsiHpiDeviceInfo **hpiDevice, struct hpi_format *hpiFormat )
361 int maxChannelCount = 0;
362 PaSampleFormat hostSampleFormat = 0;
364 + hpi_err_t hpiError = 0;
366 /* Unless alternate device specification is supported, reject the use of
367 paUseHostApiSpecificDeviceSpecification */
369 hostSampleFormat = PaUtil_SelectClosestAvailableFormat(PA_ASIHPI_AVAILABLE_FORMATS_,
370 parameters->sampleFormat );
371 /* Setup format + info objects */
372 - hpiError = HPI_FormatCreate( hpiFormat, (HW16)parameters->channelCount,
373 + hpiError = HPI_FormatCreate( hpiFormat, (uint16_t)parameters->channelCount,
374 PaAsiHpi_PaToHpiFormat( hostSampleFormat ),
375 - (HW32)sampleRate, 0, 0 );
376 + (uint32_t)sampleRate, 0, 0 );
379 PA_ASIHPI_REPORT_ERROR_( hpiError );
380 @@ -1016,25 +1003,25 @@
381 @return PortAudio error code (typically indicating a problem with stream format or device)
383 static PaError PaAsiHpi_OpenInput( struct PaUtilHostApiRepresentation *hostApi,
384 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
385 - HPI_HISTREAM *hpiStream )
386 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
387 + hpi_handle_t *hpiStream )
389 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
390 PaError result = paNoError;
392 + hpi_err_t hpiError = 0;
394 /* Catch misplaced output devices, as they typically have 0 input channels */
395 PA_UNLESS_( !hpiDevice->streamIsOutput, paInvalidChannelCount );
396 /* Try to open input stream */
397 - PA_ASIHPI_UNLESS_( HPI_InStreamOpen( hpiHostApi->subSys, hpiDevice->adapterIndex,
398 + PA_ASIHPI_UNLESS_( HPI_InStreamOpen( NULL, hpiDevice->adapterIndex,
399 hpiDevice->streamIndex, hpiStream ), paDeviceUnavailable );
400 /* Set input format (checking it in the process) */
401 /* Could also use HPI_InStreamQueryFormat, but this economizes the process */
402 - hpiError = HPI_InStreamSetFormat( hpiHostApi->subSys, *hpiStream, (HPI_FORMAT*)hpiFormat );
403 + hpiError = HPI_InStreamSetFormat( NULL, *hpiStream, (struct hpi_format*)hpiFormat );
406 PA_ASIHPI_REPORT_ERROR_( hpiError );
407 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( hpiHostApi->subSys, *hpiStream ), paNoError );
408 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL, *hpiStream ), paNoError );
411 case HPI_ERROR_INVALID_FORMAT:
412 @@ -1071,25 +1058,25 @@
413 @return PortAudio error code (typically indicating a problem with stream format or device)
415 static PaError PaAsiHpi_OpenOutput( struct PaUtilHostApiRepresentation *hostApi,
416 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
417 - HPI_HOSTREAM *hpiStream )
418 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
419 + hpi_handle_t *hpiStream )
421 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
422 PaError result = paNoError;
424 + hpi_err_t hpiError = 0;
426 /* Catch misplaced input devices, as they typically have 0 output channels */
427 PA_UNLESS_( hpiDevice->streamIsOutput, paInvalidChannelCount );
428 /* Try to open output stream */
429 - PA_ASIHPI_UNLESS_( HPI_OutStreamOpen( hpiHostApi->subSys, hpiDevice->adapterIndex,
430 + PA_ASIHPI_UNLESS_( HPI_OutStreamOpen( NULL, hpiDevice->adapterIndex,
431 hpiDevice->streamIndex, hpiStream ), paDeviceUnavailable );
433 /* Check output format (format is set on first write to output stream) */
434 - hpiError = HPI_OutStreamQueryFormat( hpiHostApi->subSys, *hpiStream, (HPI_FORMAT*)hpiFormat );
435 + hpiError = HPI_OutStreamQueryFormat( NULL, *hpiStream, (struct hpi_format*)hpiFormat );
438 PA_ASIHPI_REPORT_ERROR_( hpiError );
439 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( hpiHostApi->subSys, *hpiStream ), paNoError );
440 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL, *hpiStream ), paNoError );
443 case HPI_ERROR_INVALID_FORMAT:
444 @@ -1135,12 +1122,12 @@
445 PaError result = paFormatIsSupported;
446 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
447 PaAsiHpiDeviceInfo *hpiDevice = NULL;
448 - HPI_FORMAT hpiFormat;
449 + struct hpi_format hpiFormat;
452 if( inputParameters )
454 - HPI_HISTREAM hpiStream;
455 + hpi_handle_t hpiStream;
456 PA_DEBUG(( "%s: Checking input params: dev=%d, sr=%d, chans=%d, fmt=%d\n",
457 __FUNCTION__, inputParameters->device, (int)sampleRate,
458 inputParameters->channelCount, inputParameters->sampleFormat ));
459 @@ -1150,13 +1137,13 @@
460 /* Open stream to further check format */
461 PA_ENSURE_( PaAsiHpi_OpenInput( hostApi, hpiDevice, &hpiFormat, &hpiStream ) );
462 /* Close stream again */
463 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( hpiHostApi->subSys, hpiStream ), paNoError );
464 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL, hpiStream ), paNoError );
468 if( outputParameters )
470 - HPI_HOSTREAM hpiStream;
471 + hpi_handle_t hpiStream;
472 PA_DEBUG(( "%s: Checking output params: dev=%d, sr=%d, chans=%d, fmt=%d\n",
473 __FUNCTION__, outputParameters->device, (int)sampleRate,
474 outputParameters->channelCount, outputParameters->sampleFormat ));
475 @@ -1166,7 +1153,7 @@
476 /* Open stream to further check format */
477 PA_ENSURE_( PaAsiHpi_OpenOutput( hostApi, hpiDevice, &hpiFormat, &hpiStream ) );
478 /* Close stream again */
479 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( hpiHostApi->subSys, hpiStream ), paNoError );
480 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL, hpiStream ), paNoError );
484 @@ -1188,9 +1175,9 @@
485 static PaError PaAsiHpi_GetStreamInfo( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStreamInfo *info )
487 PaError result = paDeviceUnavailable;
489 - HW32 bufferSize, dataSize, frameCounter, auxDataSize, threshold;
490 - HW32 hwBufferSize, hwDataSize;
492 + uint32_t bufferSize, dataSize, frameCounter, auxDataSize, threshold;
493 + uint32_t hwBufferSize, hwDataSize;
495 assert( streamComp );
497 @@ -1212,14 +1199,14 @@
498 /* Obtain detailed stream info (either input or output) */
499 if( streamComp->hpiDevice->streamIsOutput )
501 - PA_ASIHPI_UNLESS_( HPI_OutStreamGetInfoEx( streamComp->hpiDevice->subSys,
502 + PA_ASIHPI_UNLESS_( HPI_OutStreamGetInfoEx( NULL,
503 streamComp->hpiStream,
504 &state, &bufferSize, &dataSize, &frameCounter,
505 &auxDataSize ), paUnanticipatedHostError );
509 - PA_ASIHPI_UNLESS_( HPI_InStreamGetInfoEx( streamComp->hpiDevice->subSys,
510 + PA_ASIHPI_UNLESS_( HPI_InStreamGetInfoEx( NULL,
511 streamComp->hpiStream,
512 &state, &bufferSize, &dataSize, &frameCounter,
513 &auxDataSize ), paUnanticipatedHostError );
514 @@ -1479,7 +1466,7 @@
516 @return PortAudio error code (possibly paBufferTooBig or paInsufficientMemory)
518 -static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, HW32 pollingInterval,
519 +static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, uint32_t pollingInterval,
520 unsigned long framesPerPaHostBuffer, PaTime suggestedLatency )
522 PaError result = paNoError;
523 @@ -1499,8 +1486,8 @@
524 /* Check if BBM (background bus mastering) is to be enabled */
525 if( PA_ASIHPI_USE_BBM_ )
527 - HW32 bbmBufferSize = 0, preLatencyBufferSize = 0;
529 + uint32_t bbmBufferSize = 0, preLatencyBufferSize = 0;
530 + hpi_err_t hpiError = 0;
531 PaTime pollingOverhead;
533 /* Check overhead of Pa_Sleep() call (minimum sleep duration in ms -> OS dependent) */
534 @@ -1510,7 +1497,7 @@
535 PA_DEBUG(( "polling overhead = %f ms (length of 0-second sleep)\n", pollingOverhead ));
536 /* Obtain minimum recommended size for host buffer (in bytes) */
537 PA_ASIHPI_UNLESS_( HPI_StreamEstimateBufferSize( &streamComp->hpiFormat,
538 - pollingInterval + (HW32)ceil( pollingOverhead ),
539 + pollingInterval + (uint32_t)ceil( pollingOverhead ),
540 &bbmBufferSize ), paUnanticipatedHostError );
541 /* BBM places more stringent requirements on buffer size (see description */
542 /* of HPI_StreamEstimateBufferSize in HPI API document) */
543 @@ -1528,27 +1515,26 @@
545 /* Save old buffer size, to be retried if new size proves too big */
546 preLatencyBufferSize = bbmBufferSize;
547 - bbmBufferSize = (HW32)ceil( suggestedLatency * streamComp->bytesPerFrame
548 + bbmBufferSize = (uint32_t)ceil( suggestedLatency * streamComp->bytesPerFrame
549 * streamComp->hpiFormat.dwSampleRate );
552 /* Choose closest memory block boundary (HPI API document states that
553 "a buffer size of Nx4096 - 20 makes the best use of memory"
554 (under the entry for HPI_StreamEstimateBufferSize)) */
555 - bbmBufferSize = ((HW32)ceil((bbmBufferSize + 20)/4096.0))*4096 - 20;
556 + bbmBufferSize = ((uint32_t)ceil((bbmBufferSize + 20)/4096.0))*4096 - 20;
557 streamComp->hostBufferSize = bbmBufferSize;
558 /* Allocate BBM host buffer (this enables bus mastering transfers in background) */
559 if( streamComp->hpiDevice->streamIsOutput )
560 - hpiError = HPI_OutStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
561 + hpiError = HPI_OutStreamHostBufferAllocate( NULL,
562 streamComp->hpiStream,
565 - hpiError = HPI_InStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
566 + hpiError = HPI_InStreamHostBufferAllocate( NULL,
567 streamComp->hpiStream,
571 - PA_ASIHPI_REPORT_ERROR_( hpiError );
572 /* Indicate that BBM is disabled */
573 streamComp->hostBufferSize = 0;
574 /* Retry with smaller buffer size (transfers will still work, but not via BBM) */
575 @@ -1561,11 +1547,11 @@
576 preLatencyBufferSize, bbmBufferSize ));
577 bbmBufferSize = preLatencyBufferSize;
578 if( streamComp->hpiDevice->streamIsOutput )
579 - hpiError = HPI_OutStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
580 + hpiError = HPI_OutStreamHostBufferAllocate( NULL,
581 streamComp->hpiStream,
584 - hpiError = HPI_InStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
585 + hpiError = HPI_InStreamHostBufferAllocate( NULL,
586 streamComp->hpiStream,
588 /* Another round of error checking */
589 @@ -1598,8 +1584,10 @@
591 /* If BBM not supported, foreground transfers will be used, but not a show-stopper */
592 /* Anything else is an error */
593 - else if( hpiError != HPI_ERROR_INVALID_OPERATION )
594 + else if (( hpiError != HPI_ERROR_INVALID_OPERATION ) &&
595 + ( hpiError != HPI_ERROR_INVALID_FUNC ))
597 + PA_ASIHPI_REPORT_ERROR_( hpiError );
598 result = paUnanticipatedHostError;
601 @@ -1623,7 +1611,7 @@
602 PaTime latency = suggestedLatency > 0.0 ? suggestedLatency :
603 streamComp->hpiDevice->baseDeviceInfo.defaultHighOutputLatency;
604 streamComp->outputBufferCap =
605 - (HW32)ceil( latency * streamComp->bytesPerFrame * streamComp->hpiFormat.dwSampleRate );
606 + (uint32_t)ceil( latency * streamComp->bytesPerFrame * streamComp->hpiFormat.dwSampleRate );
607 /* The cap should not be too small, to prevent underflow */
608 if( streamComp->outputBufferCap < 4*paHostBufferSize )
609 streamComp->outputBufferCap = 4*paHostBufferSize;
610 @@ -1635,7 +1623,7 @@
611 /* Temp buffer size should be multiple of PA host buffer size (or 1x, if using fixed blocks) */
612 streamComp->tempBufferSize = paHostBufferSize;
613 /* Allocate temp buffer */
614 - PA_UNLESS_( streamComp->tempBuffer = (HW8 *)PaUtil_AllocateMemory( streamComp->tempBufferSize ),
615 + PA_UNLESS_( streamComp->tempBuffer = (uint8_t *)PaUtil_AllocateMemory( streamComp->tempBufferSize ),
616 paInsufficientMemory );
619 @@ -1725,7 +1713,7 @@
620 By keeping the frames a multiple of 4, this is ensured even for 8-bit mono sound. */
621 framesPerHostBuffer = (framesPerHostBuffer / 4) * 4;
622 /* Polling is based on time length (in milliseconds) of user-requested block size */
623 - stream->pollingInterval = (HW32)ceil( 1000.0*framesPerHostBuffer/sampleRate );
624 + stream->pollingInterval = (uint32_t)ceil( 1000.0*framesPerHostBuffer/sampleRate );
625 assert( framesPerHostBuffer > 0 );
627 /* Open underlying streams, check formats and allocate buffers */
628 @@ -1890,7 +1878,7 @@
629 /* Close HPI stream (freeing BBM host buffer in the process, if used) */
630 if( stream->input->hpiStream )
632 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( stream->input->hpiDevice->subSys,
633 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL,
634 stream->input->hpiStream ), paUnanticipatedHostError );
636 /* Free temp buffer and stream component */
637 @@ -1902,7 +1890,7 @@
638 /* Close HPI stream (freeing BBM host buffer in the process, if used) */
639 if( stream->output->hpiStream )
641 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( stream->output->hpiDevice->subSys,
642 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL,
643 stream->output->hpiStream ), paUnanticipatedHostError );
645 /* Free temp buffer and stream component */
646 @@ -1933,9 +1921,6 @@
647 PaAsiHpiStreamComponent *out;
648 PaUtilZeroer *zeroer;
649 PaSampleFormat outputFormat;
650 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
654 out = stream->output;
655 /* Only continue if stream has output channels */
656 @@ -1944,28 +1929,19 @@
657 assert( out->tempBuffer );
659 /* Clear all existing data in hardware playback buffer */
660 - PA_ASIHPI_UNLESS_( HPI_OutStreamReset( out->hpiDevice->subSys,
661 + PA_ASIHPI_UNLESS_( HPI_OutStreamReset( NULL,
662 out->hpiStream ), paUnanticipatedHostError );
663 /* Fill temp buffer with silence */
664 outputFormat = PaAsiHpi_HpiToPaFormat( out->hpiFormat.wFormat );
665 zeroer = PaUtil_SelectZeroer( outputFormat );
666 zeroer(out->tempBuffer, 1, out->tempBufferSize / Pa_GetSampleSize(outputFormat) );
667 /* Write temp buffer to hardware fifo twice, to get started */
668 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
669 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( out->hpiDevice->subSys, out->hpiStream,
670 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL, out->hpiStream,
671 out->tempBuffer, out->tempBufferSize, &out->hpiFormat),
672 paUnanticipatedHostError );
673 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( out->hpiDevice->subSys, out->hpiStream,
674 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL, out->hpiStream,
675 out->tempBuffer, out->tempBufferSize, &out->hpiFormat),
676 paUnanticipatedHostError );
678 - PA_ASIHPI_UNLESS_( HPI_DataCreate( &data, &out->hpiFormat, out->tempBuffer, out->tempBufferSize ),
679 - paUnanticipatedHostError );
680 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( out->hpiDevice->subSys,
681 - out->hpiStream, &data ), paUnanticipatedHostError );
682 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( out->hpiDevice->subSys,
683 - out->hpiStream, &data ), paUnanticipatedHostError );
688 @@ -1989,7 +1965,7 @@
692 - PA_ASIHPI_UNLESS_( HPI_InStreamStart( stream->input->hpiDevice->subSys,
693 + PA_ASIHPI_UNLESS_( HPI_InStreamStart( NULL,
694 stream->input->hpiStream ), paUnanticipatedHostError );
697 @@ -1999,7 +1975,7 @@
698 /* Buffer isn't primed, so load stream with silence */
699 PA_ENSURE_( PaAsiHpi_PrimeOutputWithSilence( stream ) );
701 - PA_ASIHPI_UNLESS_( HPI_OutStreamStart( stream->output->hpiDevice->subSys,
702 + PA_ASIHPI_UNLESS_( HPI_OutStreamStart( NULL,
703 stream->output->hpiStream ), paUnanticipatedHostError );
705 stream->state = paAsiHpiActiveState;
706 @@ -2071,7 +2047,7 @@
710 - PA_ASIHPI_UNLESS_( HPI_InStreamReset( stream->input->hpiDevice->subSys,
711 + PA_ASIHPI_UNLESS_( HPI_InStreamReset( NULL,
712 stream->input->hpiStream ), paUnanticipatedHostError );
714 /* Output channels */
715 @@ -2097,7 +2073,7 @@
716 Pa_Sleep( (long)ceil( timeLeft ) );
719 - PA_ASIHPI_UNLESS_( HPI_OutStreamReset( stream->output->hpiDevice->subSys,
720 + PA_ASIHPI_UNLESS_( HPI_OutStreamReset( NULL,
721 stream->output->hpiStream ), paUnanticipatedHostError );
724 @@ -2315,7 +2291,7 @@
725 PaError result = paNoError;
727 unsigned long framesTarget;
728 - HW32 outputData = 0, outputSpace = 0, inputData = 0, framesLeft = 0;
729 + uint32_t outputData = 0, outputSpace = 0, inputData = 0, framesLeft = 0;
732 assert( stream->input || stream->output );
733 @@ -2484,12 +2460,9 @@
736 PaAsiHpiStreamInfo info;
738 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
741 - HW32 framesToGet = *numFrames;
743 + uint32_t framesToGet = *numFrames;
745 /* Check for overflows and underflows yet again */
746 PA_ENSURE_( PaAsiHpi_GetStreamInfo( stream->input, &info ) );
748 @@ -2513,22 +2486,12 @@
749 stream->input->tempBufferSize / Pa_GetSampleSize(inputFormat) );
752 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
753 /* Read block of data into temp buffer */
754 - PA_ASIHPI_UNLESS_( HPI_InStreamReadBuf( stream->input->hpiDevice->subSys,
755 - stream->input->hpiStream,
756 + PA_ASIHPI_UNLESS_( HPI_InStreamReadBuf( NULL,
757 + stream->input->hpiStream,
758 stream->input->tempBuffer,
759 framesToGet * stream->input->bytesPerFrame),
760 paUnanticipatedHostError );
762 - /* Setup HPI data structure around temp buffer */
763 - HPI_DataCreate( &data, &stream->input->hpiFormat, stream->input->tempBuffer,
764 - framesToGet * stream->input->bytesPerFrame );
765 - /* Read block of data into temp buffer */
766 - PA_ASIHPI_UNLESS_( HPI_InStreamRead( stream->input->hpiDevice->subSys,
767 - stream->input->hpiStream, &data ),
768 - paUnanticipatedHostError );
770 /* Register temp buffer with buffer processor (always FULL buffer) */
771 PaUtil_SetInputFrameCount( &stream->bufferProcessor, *numFrames );
772 /* HPI interface only allows interleaved channels */
773 @@ -2572,9 +2535,6 @@
776 PaAsiHpiStreamInfo info;
777 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
780 /* Check for underflows after the (potentially time-consuming) callback */
781 PA_ENSURE_( PaAsiHpi_GetStreamInfo( stream->output, &info ) );
783 @@ -2582,23 +2542,13 @@
784 *cbFlags |= paOutputUnderflow;
787 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
788 /* Write temp buffer to HPI stream */
789 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( stream->output->hpiDevice->subSys,
790 - stream->output->hpiStream,
791 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL,
792 + stream->output->hpiStream,
793 stream->output->tempBuffer,
794 - numFrames * stream->output->bytesPerFrame,
795 + numFrames * stream->output->bytesPerFrame,
796 &stream->output->hpiFormat),
797 paUnanticipatedHostError );
799 - /* Setup HPI data structure around temp buffer */
800 - HPI_DataCreate( &data, &stream->output->hpiFormat, stream->output->tempBuffer,
801 - numFrames * stream->output->bytesPerFrame );
802 - /* Write temp buffer to HPI stream */
803 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( stream->output->hpiDevice->subSys,
804 - stream->output->hpiStream, &data ),
805 - paUnanticipatedHostError );