1 Index: test/patest_sine.c
2 ===================================================================
3 --- test/patest_sine.c (revision 1645)
4 +++ test/patest_sine.c (working copy)
9 - * The text above constitutes the entire PortAudio license; however,
10 + * The text above constitutes the entire PortAudio license; however,
11 * the PortAudio community also makes the following non-binding requests:
13 * Any person wishing to distribute modifications to the Software is
14 * requested to send the modifications to the original developer so that
15 - * they can be incorporated into the canonical version. It is also
16 - * requested that these non-binding requests be included along with the
17 + * they can be incorporated into the canonical version. It is also
18 + * requested that these non-binding requests be included along with the
23 (void) timeInfo; /* Prevent unused variable warnings. */
28 for( i=0; i<framesPerBuffer; i++ )
30 *out++ = data->sine[data->left_phase]; /* left */
32 data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
33 if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
43 /*******************************************************************/
46 +int main(int argc, char **argv)
48 PaStreamParameters outputParameters;
57 + devindex = atoi(argv[1]);
59 printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
62 /* initialise sinusoidal wavetable */
63 for( i=0; i<TABLE_SIZE; i++ )
65 data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
67 data.left_phase = data.right_phase = 0;
70 err = Pa_Initialize();
71 if( err != paNoError ) goto error;
73 - outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
75 + outputParameters.device = Pa_GetDefaultOutputDevice();
77 + outputParameters.device = devindex;
79 if (outputParameters.device == paNoDevice) {
80 fprintf(stderr,"Error: No default output device.\n");
83 outputParameters.channelCount = 2; /* stereo output */
84 outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
85 + //outputParameters.suggestedLatency = 0.25;
86 outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
87 outputParameters.hostApiSpecificStreamInfo = NULL;
92 printf("Test finished.\n");
98 Index: src/hostapi/asihpi/pa_linux_asihpi.c
99 ===================================================================
100 --- src/hostapi/asihpi/pa_linux_asihpi.c (revision 1645)
101 +++ src/hostapi/asihpi/pa_linux_asihpi.c (working copy)
103 /** Check return value of HPI function, and map it to PaError */
104 #define PA_ASIHPI_UNLESS_(expr, paError) \
106 - HW16 hpiError = (expr); \
107 + hpi_err_t hpiError = (expr); \
108 /* If HPI error occurred */ \
109 if( UNLIKELY( hpiError ) ) \
112 /* implementation specific data goes here */
114 PaHostApiIndex hostApiIndex;
115 - /** HPI subsystem pointer */
116 - HPI_HSUBSYS *subSys;
118 PaAsiHpiHostApiRepresentation;
120 @@ -280,20 +278,18 @@
122 /* implementation specific data goes here */
124 - /** HPI subsystem (required for most HPI calls) */
125 - HPI_HSUBSYS *subSys;
128 + uint16_t adapterIndex;
129 /** Adapter model number (hex) */
131 + uint16_t adapterType;
132 /** Adapter HW/SW version */
133 - HW16 adapterVersion;
134 + uint16_t adapterVersion;
135 /** Adapter serial number */
136 - HW32 adapterSerialNumber;
137 + uint32_t adapterSerialNumber;
140 + uint16_t streamIndex;
141 /** 0=Input, 1=Output (HPI streams are either input or output but not both) */
142 - HW16 streamIsOutput;
143 + uint16_t streamIsOutput;
147 @@ -328,27 +324,25 @@
149 /** Device information (HPI handles, etc) */
150 PaAsiHpiDeviceInfo *hpiDevice;
151 - /** Stream handle, as passed to HPI interface.
152 - HACK: we assume types HPI_HISTREAM and HPI_HOSTREAM are the same...
153 - (both are HW32 up to version 3.00 of ASIHPI, and hopefully they stay that way) */
154 - HPI_HISTREAM hpiStream;
155 + /** Stream handle, as passed to HPI interface. */
156 + hpi_handle_t hpiStream;
157 /** Stream format, as passed to HPI interface */
158 - HPI_FORMAT hpiFormat;
159 + struct hpi_format hpiFormat;
160 /** Number of bytes per frame, derived from hpiFormat and saved for convenience */
161 - HW32 bytesPerFrame;
162 + uint32_t bytesPerFrame;
163 /** Size of hardware (on-card) buffer of stream in bytes */
164 - HW32 hardwareBufferSize;
165 + uint32_t hardwareBufferSize;
166 /** Size of host (BBM) buffer of stream in bytes (if used) */
167 - HW32 hostBufferSize;
168 + uint32_t hostBufferSize;
169 /** Upper limit on the utilization of output stream buffer (both hardware and host).
170 This prevents large latencies in an output-only stream with a potentially huge buffer
171 and a fast data generator, which would otherwise keep the hardware buffer filled to
172 capacity. See also the "Hardware Buffering=off" option in the AudioScience WAV driver. */
173 - HW32 outputBufferCap;
174 + uint32_t outputBufferCap;
175 /** Sample buffer (halfway station between HPI and buffer processor) */
177 + uint8_t *tempBuffer;
178 /** Sample buffer size, in bytes */
179 - HW32 tempBufferSize;
180 + uint32_t tempBufferSize;
182 PaAsiHpiStreamComponent;
185 PaAsiHpiStreamComponent *input, *output;
187 /** Polling interval (in milliseconds) */
188 - HW32 pollingInterval;
189 + uint32_t pollingInterval;
190 /** Are we running in callback mode? */
192 /** Number of frames to transfer at a time to/from HPI */
193 @@ -401,23 +395,23 @@
194 typedef struct PaAsiHpiStreamInfo
196 /** HPI stream state (HPI_STATE_STOPPED, HPI_STATE_PLAYING, etc.) */
199 /** Size (in bytes) of recording/playback data buffer in HPI driver */
201 + uint32_t bufferSize;
202 /** Amount of data (in bytes) available in the buffer */
205 /** Number of frames played/recorded since last stream reset */
207 + uint32_t frameCounter;
208 /** Amount of data (in bytes) in hardware (on-card) buffer.
209 This differs from dataSize if bus mastering (BBM) is used, which introduces another
210 driver-level buffer to which dataSize/bufferSize then refers. */
212 + uint32_t auxDataSize;
213 /** Total number of data frames currently buffered by HPI driver (host + hw buffers) */
214 - HW32 totalBufferedData;
215 + uint32_t totalBufferedData;
216 /** Size of immediately available data (for input) or space (for output) in frames.
217 This only checks the first-level buffer (typically host buffer). This amount can be
218 transferred immediately. */
219 - HW32 availableFrames;
220 + uint32_t availableFrames;
221 /** Indicates that hardware buffer is getting too full */
223 /** Indicates that hardware buffer is getting too empty */
224 @@ -479,21 +473,21 @@
226 /* Functions specific to this API */
227 static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostApi );
228 -static HW16 PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat );
229 -static PaSampleFormat PaAsiHpi_HpiToPaFormat( HW16 hpiFormat );
230 +static uint16_t PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat );
231 +static PaSampleFormat PaAsiHpi_HpiToPaFormat( uint16_t hpiFormat );
232 static PaError PaAsiHpi_CreateFormat( struct PaUtilHostApiRepresentation *hostApi,
233 const PaStreamParameters *parameters, double sampleRate,
234 - PaAsiHpiDeviceInfo **hpiDevice, HPI_FORMAT *hpiFormat );
235 + PaAsiHpiDeviceInfo **hpiDevice, struct hpi_format *hpiFormat );
236 static PaError PaAsiHpi_OpenInput( struct PaUtilHostApiRepresentation *hostApi,
237 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
238 - HPI_HISTREAM *hpiStream );
239 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
240 + hpi_handle_t *hpiStream );
241 static PaError PaAsiHpi_OpenOutput( struct PaUtilHostApiRepresentation *hostApi,
242 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
243 - HPI_HOSTREAM *hpiStream );
244 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
245 + hpi_handle_t *hpiStream );
246 static PaError PaAsiHpi_GetStreamInfo( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStreamInfo *info );
247 static void PaAsiHpi_StreamComponentDump( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStream *stream );
248 static void PaAsiHpi_StreamDump( PaAsiHpiStream *stream );
249 -static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, HW32 pollingInterval,
250 +static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, uint32_t pollingInterval,
251 unsigned long framesPerPaHostBuffer, PaTime suggestedLatency );
252 static PaError PaAsiHpi_PrimeOutputWithSilence( PaAsiHpiStream *stream );
253 static PaError PaAsiHpi_StartStream( PaAsiHpiStream *stream, int outputPrimed );
254 @@ -529,42 +523,40 @@
255 PaUtilHostApiRepresentation *hostApi = &hpiHostApi->baseHostApiRep;
256 PaHostApiInfo *baseApiInfo = &hostApi->info;
257 PaAsiHpiDeviceInfo *hpiDeviceList;
258 - HW16 adapterList[ HPI_MAX_ADAPTERS ];
262 + hpi_err_t hpiError = 0;
263 int i, j, deviceCount = 0, deviceIndex = 0;
265 assert( hpiHostApi );
266 - assert( hpiHostApi->subSys );
268 /* Look for adapters (not strictly necessary, as AdapterOpen can do the same, but this */
269 /* way we have less errors since we do not try to open adapters we know aren't there) */
270 /* Errors not considered critical here (subsystem may report 0 devices), but report them */
272 - PA_ASIHPI_UNLESS_( HPI_SubSysFindAdapters( hpiHostApi->subSys, &numAdapters,
273 - adapterList, HPI_MAX_ADAPTERS ), paNoError );
274 + PA_ASIHPI_UNLESS_( HPI_SubSysGetNumAdapters( NULL, &numAdapters), paNoError );
276 /* First open and count the number of devices (= number of streams), to ease memory allocation */
277 - for( i=0; i < HPI_MAX_ADAPTERS; ++i )
278 + for( i=0; i < numAdapters; ++i )
280 - HW16 inStreams, outStreams;
284 + uint16_t inStreams, outStreams;
290 - /* If no adapter found at this index, skip it */
291 - if( adapterList[i] == 0 )
292 + hpiError = HPI_SubSysGetAdapter(NULL, i, &idx, &type);
296 /* Try to open adapter */
297 - hpiError = HPI_AdapterOpen( hpiHostApi->subSys, i );
298 + hpiError = HPI_AdapterOpen( NULL, idx );
299 /* Report error and skip to next device on failure */
302 PA_ASIHPI_REPORT_ERROR_( hpiError );
305 - hpiError = HPI_AdapterGetInfo( hpiHostApi->subSys, i,
306 + hpiError = HPI_AdapterGetInfo( NULL, idx,
307 &outStreams, &inStreams, &version, &serial, &type );
308 /* Skip to next device on failure */
310 @@ -597,19 +589,20 @@
311 paInsufficientMemory );
313 /* Now query devices again for information */
314 - for( i=0; i < HPI_MAX_ADAPTERS; ++i )
315 + for( i=0; i < numAdapters; ++i )
317 - HW16 inStreams, outStreams;
321 + uint16_t inStreams, outStreams;
327 - /* If no adapter found at this index, skip it */
328 - if( adapterList[i] == 0 )
329 + hpiError = HPI_SubSysGetAdapter(NULL, i, &idx, &type);
333 /* Assume adapter is still open from previous round */
334 - hpiError = HPI_AdapterGetInfo( hpiHostApi->subSys, i,
335 + hpiError = HPI_AdapterGetInfo( NULL, idx,
336 &outStreams, &inStreams, &version, &serial, &type );
337 /* Report error and skip to next device on failure */
342 PA_DEBUG(( "Found HPI Adapter ID=%4X Idx=%d #In=%d #Out=%d S/N=%d HWver=%c%d DSPver=%03d\n",
343 - type, i, inStreams, outStreams, serial,
344 + type, idx, inStreams, outStreams, serial,
345 ((version>>3)&0xf)+'A', /* Hw version major */
346 version&0x7, /* Hw version minor */
347 ((version>>13)*100)+((version>>7)&0x3f) /* DSP code version */
350 memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );
351 /* Set implementation-specific device details */
352 - hpiDevice->subSys = hpiHostApi->subSys;
353 - hpiDevice->adapterIndex = i;
354 + hpiDevice->adapterIndex = idx;
355 hpiDevice->adapterType = type;
356 hpiDevice->adapterVersion = version;
357 hpiDevice->adapterSerialNumber = serial;
360 memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );
361 /* Set implementation-specific device details */
362 - hpiDevice->subSys = hpiHostApi->subSys;
363 - hpiDevice->adapterIndex = i;
364 + hpiDevice->adapterIndex = idx;
365 hpiDevice->adapterType = type;
366 hpiDevice->adapterVersion = version;
367 hpiDevice->adapterSerialNumber = serial;
369 PA_UNLESS_( hpiHostApi->allocations = PaUtil_CreateAllocationGroup(), paInsufficientMemory );
371 hpiHostApi->hostApiIndex = hostApiIndex;
372 - hpiHostApi->subSys = NULL;
374 /* Try to initialize HPI subsystem */
375 - if( ( hpiHostApi->subSys = HPI_SubSysCreate() ) == NULL)
376 + if(HPI_SubSysCreate() == NULL)
378 /* the V19 development docs say that if an implementation
379 * detects that it cannot be used, it should return a NULL
380 @@ -761,10 +751,10 @@
385 - PA_ASIHPI_UNLESS_( HPI_SubSysGetVersion( hpiHostApi->subSys, &hpiVersion ), paUnanticipatedHostError );
386 - PA_DEBUG(( "HPI interface v%d.%02d\n",
387 - hpiVersion >> 8, 10*((hpiVersion & 0xF0) >> 4) + (hpiVersion & 0x0F) ));
388 + uint32_t hpiVersion;
389 + PA_ASIHPI_UNLESS_( HPI_SubSysGetVersionEx( NULL, &hpiVersion ), paUnanticipatedHostError );
390 + PA_DEBUG(( "HPI interface v%d.%02d.%02d\n",
391 + hpiVersion >> 16, (hpiVersion >> 8) & 0x0F, (hpiVersion & 0x0F) ));
394 *hostApi = &hpiHostApi->baseHostApiRep;
395 @@ -820,25 +810,22 @@
398 /* Get rid of HPI-specific structures */
399 - if( hpiHostApi->subSys )
400 + uint16_t lastAdapterIndex = HPI_MAX_ADAPTERS;
401 + /* Iterate through device list and close adapters */
402 + for( i=0; i < hostApi->info.deviceCount; ++i )
404 - HW16 lastAdapterIndex = HPI_MAX_ADAPTERS;
405 - /* Iterate through device list and close adapters */
406 - for( i=0; i < hostApi->info.deviceCount; ++i )
407 + PaAsiHpiDeviceInfo *hpiDevice = (PaAsiHpiDeviceInfo *) hostApi->deviceInfos[ i ];
408 + /* Close adapter only if it differs from previous one */
409 + if( hpiDevice->adapterIndex != lastAdapterIndex )
411 - PaAsiHpiDeviceInfo *hpiDevice = (PaAsiHpiDeviceInfo *) hostApi->deviceInfos[ i ];
412 - /* Close adapter only if it differs from previous one */
413 - if( hpiDevice->adapterIndex != lastAdapterIndex )
415 - /* Ignore errors (report only during debugging) */
416 - PA_ASIHPI_UNLESS_( HPI_AdapterClose( hpiHostApi->subSys,
417 - hpiDevice->adapterIndex ), paNoError );
418 - lastAdapterIndex = hpiDevice->adapterIndex;
420 + /* Ignore errors (report only during debugging) */
421 + PA_ASIHPI_UNLESS_( HPI_AdapterClose( NULL,
422 + hpiDevice->adapterIndex ), paNoError );
423 + lastAdapterIndex = hpiDevice->adapterIndex;
425 - /* Finally dismantle HPI subsystem */
426 - HPI_SubSysFree( hpiHostApi->subSys );
428 + /* Finally dismantle HPI subsystem */
429 + HPI_SubSysFree( NULL );
431 if( hpiHostApi->allocations )
435 @return HPI sample format
437 -static HW16 PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat )
438 +static uint16_t PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat )
440 /* Ignore interleaving flag */
441 switch( paFormat & ~paNonInterleaved )
444 @return PortAudio sample format
446 -static PaSampleFormat PaAsiHpi_HpiToPaFormat( HW16 hpiFormat )
447 +static PaSampleFormat PaAsiHpi_HpiToPaFormat( uint16_t hpiFormat )
451 @@ -938,11 +925,11 @@
453 static PaError PaAsiHpi_CreateFormat( struct PaUtilHostApiRepresentation *hostApi,
454 const PaStreamParameters *parameters, double sampleRate,
455 - PaAsiHpiDeviceInfo **hpiDevice, HPI_FORMAT *hpiFormat )
456 + PaAsiHpiDeviceInfo **hpiDevice, struct hpi_format *hpiFormat )
458 int maxChannelCount = 0;
459 PaSampleFormat hostSampleFormat = 0;
461 + hpi_err_t hpiError = 0;
463 /* Unless alternate device specification is supported, reject the use of
464 paUseHostApiSpecificDeviceSpecification */
466 hostSampleFormat = PaUtil_SelectClosestAvailableFormat(PA_ASIHPI_AVAILABLE_FORMATS_,
467 parameters->sampleFormat );
468 /* Setup format + info objects */
469 - hpiError = HPI_FormatCreate( hpiFormat, (HW16)parameters->channelCount,
470 + hpiError = HPI_FormatCreate( hpiFormat, (uint16_t)parameters->channelCount,
471 PaAsiHpi_PaToHpiFormat( hostSampleFormat ),
472 - (HW32)sampleRate, 0, 0 );
473 + (uint32_t)sampleRate, 0, 0 );
476 PA_ASIHPI_REPORT_ERROR_( hpiError );
477 @@ -1016,25 +1003,25 @@
478 @return PortAudio error code (typically indicating a problem with stream format or device)
480 static PaError PaAsiHpi_OpenInput( struct PaUtilHostApiRepresentation *hostApi,
481 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
482 - HPI_HISTREAM *hpiStream )
483 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
484 + hpi_handle_t *hpiStream )
486 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
487 PaError result = paNoError;
489 + hpi_err_t hpiError = 0;
491 /* Catch misplaced output devices, as they typically have 0 input channels */
492 PA_UNLESS_( !hpiDevice->streamIsOutput, paInvalidChannelCount );
493 /* Try to open input stream */
494 - PA_ASIHPI_UNLESS_( HPI_InStreamOpen( hpiHostApi->subSys, hpiDevice->adapterIndex,
495 + PA_ASIHPI_UNLESS_( HPI_InStreamOpen( NULL, hpiDevice->adapterIndex,
496 hpiDevice->streamIndex, hpiStream ), paDeviceUnavailable );
497 /* Set input format (checking it in the process) */
498 /* Could also use HPI_InStreamQueryFormat, but this economizes the process */
499 - hpiError = HPI_InStreamSetFormat( hpiHostApi->subSys, *hpiStream, (HPI_FORMAT*)hpiFormat );
500 + hpiError = HPI_InStreamSetFormat( NULL, *hpiStream, (struct hpi_format*)hpiFormat );
503 PA_ASIHPI_REPORT_ERROR_( hpiError );
504 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( hpiHostApi->subSys, *hpiStream ), paNoError );
505 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL, *hpiStream ), paNoError );
508 case HPI_ERROR_INVALID_FORMAT:
509 @@ -1071,25 +1058,25 @@
510 @return PortAudio error code (typically indicating a problem with stream format or device)
512 static PaError PaAsiHpi_OpenOutput( struct PaUtilHostApiRepresentation *hostApi,
513 - const PaAsiHpiDeviceInfo *hpiDevice, const HPI_FORMAT *hpiFormat,
514 - HPI_HOSTREAM *hpiStream )
515 + const PaAsiHpiDeviceInfo *hpiDevice, const struct hpi_format *hpiFormat,
516 + hpi_handle_t *hpiStream )
518 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
519 PaError result = paNoError;
521 + hpi_err_t hpiError = 0;
523 /* Catch misplaced input devices, as they typically have 0 output channels */
524 PA_UNLESS_( hpiDevice->streamIsOutput, paInvalidChannelCount );
525 /* Try to open output stream */
526 - PA_ASIHPI_UNLESS_( HPI_OutStreamOpen( hpiHostApi->subSys, hpiDevice->adapterIndex,
527 + PA_ASIHPI_UNLESS_( HPI_OutStreamOpen( NULL, hpiDevice->adapterIndex,
528 hpiDevice->streamIndex, hpiStream ), paDeviceUnavailable );
530 /* Check output format (format is set on first write to output stream) */
531 - hpiError = HPI_OutStreamQueryFormat( hpiHostApi->subSys, *hpiStream, (HPI_FORMAT*)hpiFormat );
532 + hpiError = HPI_OutStreamQueryFormat( NULL, *hpiStream, (struct hpi_format*)hpiFormat );
535 PA_ASIHPI_REPORT_ERROR_( hpiError );
536 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( hpiHostApi->subSys, *hpiStream ), paNoError );
537 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL, *hpiStream ), paNoError );
540 case HPI_ERROR_INVALID_FORMAT:
541 @@ -1135,12 +1122,12 @@
542 PaError result = paFormatIsSupported;
543 PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;
544 PaAsiHpiDeviceInfo *hpiDevice = NULL;
545 - HPI_FORMAT hpiFormat;
546 + struct hpi_format hpiFormat;
549 if( inputParameters )
551 - HPI_HISTREAM hpiStream;
552 + hpi_handle_t hpiStream;
553 PA_DEBUG(( "%s: Checking input params: dev=%d, sr=%d, chans=%d, fmt=%d\n",
554 __FUNCTION__, inputParameters->device, (int)sampleRate,
555 inputParameters->channelCount, inputParameters->sampleFormat ));
556 @@ -1150,13 +1137,13 @@
557 /* Open stream to further check format */
558 PA_ENSURE_( PaAsiHpi_OpenInput( hostApi, hpiDevice, &hpiFormat, &hpiStream ) );
559 /* Close stream again */
560 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( hpiHostApi->subSys, hpiStream ), paNoError );
561 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL, hpiStream ), paNoError );
565 if( outputParameters )
567 - HPI_HOSTREAM hpiStream;
568 + hpi_handle_t hpiStream;
569 PA_DEBUG(( "%s: Checking output params: dev=%d, sr=%d, chans=%d, fmt=%d\n",
570 __FUNCTION__, outputParameters->device, (int)sampleRate,
571 outputParameters->channelCount, outputParameters->sampleFormat ));
572 @@ -1166,7 +1153,7 @@
573 /* Open stream to further check format */
574 PA_ENSURE_( PaAsiHpi_OpenOutput( hostApi, hpiDevice, &hpiFormat, &hpiStream ) );
575 /* Close stream again */
576 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( hpiHostApi->subSys, hpiStream ), paNoError );
577 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL, hpiStream ), paNoError );
581 @@ -1188,9 +1175,9 @@
582 static PaError PaAsiHpi_GetStreamInfo( PaAsiHpiStreamComponent *streamComp, PaAsiHpiStreamInfo *info )
584 PaError result = paDeviceUnavailable;
586 - HW32 bufferSize, dataSize, frameCounter, auxDataSize, threshold;
587 - HW32 hwBufferSize, hwDataSize;
589 + uint32_t bufferSize, dataSize, frameCounter, auxDataSize, threshold;
590 + uint32_t hwBufferSize, hwDataSize;
592 assert( streamComp );
594 @@ -1212,14 +1199,14 @@
595 /* Obtain detailed stream info (either input or output) */
596 if( streamComp->hpiDevice->streamIsOutput )
598 - PA_ASIHPI_UNLESS_( HPI_OutStreamGetInfoEx( streamComp->hpiDevice->subSys,
599 + PA_ASIHPI_UNLESS_( HPI_OutStreamGetInfoEx( NULL,
600 streamComp->hpiStream,
601 &state, &bufferSize, &dataSize, &frameCounter,
602 &auxDataSize ), paUnanticipatedHostError );
606 - PA_ASIHPI_UNLESS_( HPI_InStreamGetInfoEx( streamComp->hpiDevice->subSys,
607 + PA_ASIHPI_UNLESS_( HPI_InStreamGetInfoEx( NULL,
608 streamComp->hpiStream,
609 &state, &bufferSize, &dataSize, &frameCounter,
610 &auxDataSize ), paUnanticipatedHostError );
611 @@ -1479,7 +1466,7 @@
613 @return PortAudio error code (possibly paBufferTooBig or paInsufficientMemory)
615 -static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, HW32 pollingInterval,
616 +static PaError PaAsiHpi_SetupBuffers( PaAsiHpiStreamComponent *streamComp, uint32_t pollingInterval,
617 unsigned long framesPerPaHostBuffer, PaTime suggestedLatency )
619 PaError result = paNoError;
620 @@ -1499,8 +1486,8 @@
621 /* Check if BBM (background bus mastering) is to be enabled */
622 if( PA_ASIHPI_USE_BBM_ )
624 - HW32 bbmBufferSize = 0, preLatencyBufferSize = 0;
626 + uint32_t bbmBufferSize = 0, preLatencyBufferSize = 0;
627 + hpi_err_t hpiError = 0;
628 PaTime pollingOverhead;
630 /* Check overhead of Pa_Sleep() call (minimum sleep duration in ms -> OS dependent) */
631 @@ -1510,7 +1497,7 @@
632 PA_DEBUG(( "polling overhead = %f ms (length of 0-second sleep)\n", pollingOverhead ));
633 /* Obtain minimum recommended size for host buffer (in bytes) */
634 PA_ASIHPI_UNLESS_( HPI_StreamEstimateBufferSize( &streamComp->hpiFormat,
635 - pollingInterval + (HW32)ceil( pollingOverhead ),
636 + pollingInterval + (uint32_t)ceil( pollingOverhead ),
637 &bbmBufferSize ), paUnanticipatedHostError );
638 /* BBM places more stringent requirements on buffer size (see description */
639 /* of HPI_StreamEstimateBufferSize in HPI API document) */
640 @@ -1528,27 +1515,26 @@
642 /* Save old buffer size, to be retried if new size proves too big */
643 preLatencyBufferSize = bbmBufferSize;
644 - bbmBufferSize = (HW32)ceil( suggestedLatency * streamComp->bytesPerFrame
645 + bbmBufferSize = (uint32_t)ceil( suggestedLatency * streamComp->bytesPerFrame
646 * streamComp->hpiFormat.dwSampleRate );
649 /* Choose closest memory block boundary (HPI API document states that
650 "a buffer size of Nx4096 - 20 makes the best use of memory"
651 (under the entry for HPI_StreamEstimateBufferSize)) */
652 - bbmBufferSize = ((HW32)ceil((bbmBufferSize + 20)/4096.0))*4096 - 20;
653 + bbmBufferSize = ((uint32_t)ceil((bbmBufferSize + 20)/4096.0))*4096 - 20;
654 streamComp->hostBufferSize = bbmBufferSize;
655 /* Allocate BBM host buffer (this enables bus mastering transfers in background) */
656 if( streamComp->hpiDevice->streamIsOutput )
657 - hpiError = HPI_OutStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
658 + hpiError = HPI_OutStreamHostBufferAllocate( NULL,
659 streamComp->hpiStream,
662 - hpiError = HPI_InStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
663 + hpiError = HPI_InStreamHostBufferAllocate( NULL,
664 streamComp->hpiStream,
668 - PA_ASIHPI_REPORT_ERROR_( hpiError );
669 /* Indicate that BBM is disabled */
670 streamComp->hostBufferSize = 0;
671 /* Retry with smaller buffer size (transfers will still work, but not via BBM) */
672 @@ -1561,11 +1547,11 @@
673 preLatencyBufferSize, bbmBufferSize ));
674 bbmBufferSize = preLatencyBufferSize;
675 if( streamComp->hpiDevice->streamIsOutput )
676 - hpiError = HPI_OutStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
677 + hpiError = HPI_OutStreamHostBufferAllocate( NULL,
678 streamComp->hpiStream,
681 - hpiError = HPI_InStreamHostBufferAllocate( streamComp->hpiDevice->subSys,
682 + hpiError = HPI_InStreamHostBufferAllocate( NULL,
683 streamComp->hpiStream,
685 /* Another round of error checking */
686 @@ -1598,8 +1584,10 @@
688 /* If BBM not supported, foreground transfers will be used, but not a show-stopper */
689 /* Anything else is an error */
690 - else if( hpiError != HPI_ERROR_INVALID_OPERATION )
691 + else if (( hpiError != HPI_ERROR_INVALID_OPERATION ) &&
692 + ( hpiError != HPI_ERROR_INVALID_FUNC ))
694 + PA_ASIHPI_REPORT_ERROR_( hpiError );
695 result = paUnanticipatedHostError;
698 @@ -1623,7 +1611,7 @@
699 PaTime latency = suggestedLatency > 0.0 ? suggestedLatency :
700 streamComp->hpiDevice->baseDeviceInfo.defaultHighOutputLatency;
701 streamComp->outputBufferCap =
702 - (HW32)ceil( latency * streamComp->bytesPerFrame * streamComp->hpiFormat.dwSampleRate );
703 + (uint32_t)ceil( latency * streamComp->bytesPerFrame * streamComp->hpiFormat.dwSampleRate );
704 /* The cap should not be too small, to prevent underflow */
705 if( streamComp->outputBufferCap < 4*paHostBufferSize )
706 streamComp->outputBufferCap = 4*paHostBufferSize;
707 @@ -1635,7 +1623,7 @@
708 /* Temp buffer size should be multiple of PA host buffer size (or 1x, if using fixed blocks) */
709 streamComp->tempBufferSize = paHostBufferSize;
710 /* Allocate temp buffer */
711 - PA_UNLESS_( streamComp->tempBuffer = (HW8 *)PaUtil_AllocateMemory( streamComp->tempBufferSize ),
712 + PA_UNLESS_( streamComp->tempBuffer = (uint8_t *)PaUtil_AllocateMemory( streamComp->tempBufferSize ),
713 paInsufficientMemory );
716 @@ -1725,7 +1713,7 @@
717 By keeping the frames a multiple of 4, this is ensured even for 8-bit mono sound. */
718 framesPerHostBuffer = (framesPerHostBuffer / 4) * 4;
719 /* Polling is based on time length (in milliseconds) of user-requested block size */
720 - stream->pollingInterval = (HW32)ceil( 1000.0*framesPerHostBuffer/sampleRate );
721 + stream->pollingInterval = (uint32_t)ceil( 1000.0*framesPerHostBuffer/sampleRate );
722 assert( framesPerHostBuffer > 0 );
724 /* Open underlying streams, check formats and allocate buffers */
725 @@ -1890,7 +1878,7 @@
726 /* Close HPI stream (freeing BBM host buffer in the process, if used) */
727 if( stream->input->hpiStream )
729 - PA_ASIHPI_UNLESS_( HPI_InStreamClose( stream->input->hpiDevice->subSys,
730 + PA_ASIHPI_UNLESS_( HPI_InStreamClose( NULL,
731 stream->input->hpiStream ), paUnanticipatedHostError );
733 /* Free temp buffer and stream component */
734 @@ -1902,7 +1890,7 @@
735 /* Close HPI stream (freeing BBM host buffer in the process, if used) */
736 if( stream->output->hpiStream )
738 - PA_ASIHPI_UNLESS_( HPI_OutStreamClose( stream->output->hpiDevice->subSys,
739 + PA_ASIHPI_UNLESS_( HPI_OutStreamClose( NULL,
740 stream->output->hpiStream ), paUnanticipatedHostError );
742 /* Free temp buffer and stream component */
743 @@ -1933,9 +1921,6 @@
744 PaAsiHpiStreamComponent *out;
745 PaUtilZeroer *zeroer;
746 PaSampleFormat outputFormat;
747 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
751 out = stream->output;
752 /* Only continue if stream has output channels */
753 @@ -1944,28 +1929,19 @@
754 assert( out->tempBuffer );
756 /* Clear all existing data in hardware playback buffer */
757 - PA_ASIHPI_UNLESS_( HPI_OutStreamReset( out->hpiDevice->subSys,
758 + PA_ASIHPI_UNLESS_( HPI_OutStreamReset( NULL,
759 out->hpiStream ), paUnanticipatedHostError );
760 /* Fill temp buffer with silence */
761 outputFormat = PaAsiHpi_HpiToPaFormat( out->hpiFormat.wFormat );
762 zeroer = PaUtil_SelectZeroer( outputFormat );
763 zeroer(out->tempBuffer, 1, out->tempBufferSize / Pa_GetSampleSize(outputFormat) );
764 /* Write temp buffer to hardware fifo twice, to get started */
765 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
766 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( out->hpiDevice->subSys, out->hpiStream,
767 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL, out->hpiStream,
768 out->tempBuffer, out->tempBufferSize, &out->hpiFormat),
769 paUnanticipatedHostError );
770 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( out->hpiDevice->subSys, out->hpiStream,
771 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL, out->hpiStream,
772 out->tempBuffer, out->tempBufferSize, &out->hpiFormat),
773 paUnanticipatedHostError );
775 - PA_ASIHPI_UNLESS_( HPI_DataCreate( &data, &out->hpiFormat, out->tempBuffer, out->tempBufferSize ),
776 - paUnanticipatedHostError );
777 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( out->hpiDevice->subSys,
778 - out->hpiStream, &data ), paUnanticipatedHostError );
779 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( out->hpiDevice->subSys,
780 - out->hpiStream, &data ), paUnanticipatedHostError );
785 @@ -1989,7 +1965,7 @@
789 - PA_ASIHPI_UNLESS_( HPI_InStreamStart( stream->input->hpiDevice->subSys,
790 + PA_ASIHPI_UNLESS_( HPI_InStreamStart( NULL,
791 stream->input->hpiStream ), paUnanticipatedHostError );
794 @@ -1999,7 +1975,7 @@
795 /* Buffer isn't primed, so load stream with silence */
796 PA_ENSURE_( PaAsiHpi_PrimeOutputWithSilence( stream ) );
798 - PA_ASIHPI_UNLESS_( HPI_OutStreamStart( stream->output->hpiDevice->subSys,
799 + PA_ASIHPI_UNLESS_( HPI_OutStreamStart( NULL,
800 stream->output->hpiStream ), paUnanticipatedHostError );
802 stream->state = paAsiHpiActiveState;
803 @@ -2071,7 +2047,7 @@
807 - PA_ASIHPI_UNLESS_( HPI_InStreamReset( stream->input->hpiDevice->subSys,
808 + PA_ASIHPI_UNLESS_( HPI_InStreamReset( NULL,
809 stream->input->hpiStream ), paUnanticipatedHostError );
811 /* Output channels */
812 @@ -2097,7 +2073,7 @@
813 Pa_Sleep( (long)ceil( timeLeft ) );
816 - PA_ASIHPI_UNLESS_( HPI_OutStreamReset( stream->output->hpiDevice->subSys,
817 + PA_ASIHPI_UNLESS_( HPI_OutStreamReset( NULL,
818 stream->output->hpiStream ), paUnanticipatedHostError );
821 @@ -2315,7 +2291,7 @@
822 PaError result = paNoError;
824 unsigned long framesTarget;
825 - HW32 outputData = 0, outputSpace = 0, inputData = 0, framesLeft = 0;
826 + uint32_t outputData = 0, outputSpace = 0, inputData = 0, framesLeft = 0;
829 assert( stream->input || stream->output );
830 @@ -2484,12 +2460,9 @@
833 PaAsiHpiStreamInfo info;
835 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
838 - HW32 framesToGet = *numFrames;
840 + uint32_t framesToGet = *numFrames;
842 /* Check for overflows and underflows yet again */
843 PA_ENSURE_( PaAsiHpi_GetStreamInfo( stream->input, &info ) );
845 @@ -2513,22 +2486,12 @@
846 stream->input->tempBufferSize / Pa_GetSampleSize(inputFormat) );
849 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
850 /* Read block of data into temp buffer */
851 - PA_ASIHPI_UNLESS_( HPI_InStreamReadBuf( stream->input->hpiDevice->subSys,
852 - stream->input->hpiStream,
853 + PA_ASIHPI_UNLESS_( HPI_InStreamReadBuf( NULL,
854 + stream->input->hpiStream,
855 stream->input->tempBuffer,
856 framesToGet * stream->input->bytesPerFrame),
857 paUnanticipatedHostError );
859 - /* Setup HPI data structure around temp buffer */
860 - HPI_DataCreate( &data, &stream->input->hpiFormat, stream->input->tempBuffer,
861 - framesToGet * stream->input->bytesPerFrame );
862 - /* Read block of data into temp buffer */
863 - PA_ASIHPI_UNLESS_( HPI_InStreamRead( stream->input->hpiDevice->subSys,
864 - stream->input->hpiStream, &data ),
865 - paUnanticipatedHostError );
867 /* Register temp buffer with buffer processor (always FULL buffer) */
868 PaUtil_SetInputFrameCount( &stream->bufferProcessor, *numFrames );
869 /* HPI interface only allows interleaved channels */
870 @@ -2572,9 +2535,6 @@
873 PaAsiHpiStreamInfo info;
874 -#if (HPI_VER < HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
877 /* Check for underflows after the (potentially time-consuming) callback */
878 PA_ENSURE_( PaAsiHpi_GetStreamInfo( stream->output, &info ) );
880 @@ -2582,23 +2542,13 @@
881 *cbFlags |= paOutputUnderflow;
884 -#if (HPI_VER >= HPI_VERSION_CONSTRUCTOR( 3, 5, 5 ))
885 /* Write temp buffer to HPI stream */
886 - PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( stream->output->hpiDevice->subSys,
887 - stream->output->hpiStream,
888 + PA_ASIHPI_UNLESS_( HPI_OutStreamWriteBuf( NULL,
889 + stream->output->hpiStream,
890 stream->output->tempBuffer,
891 - numFrames * stream->output->bytesPerFrame,
892 + numFrames * stream->output->bytesPerFrame,
893 &stream->output->hpiFormat),
894 paUnanticipatedHostError );
896 - /* Setup HPI data structure around temp buffer */
897 - HPI_DataCreate( &data, &stream->output->hpiFormat, stream->output->tempBuffer,
898 - numFrames * stream->output->bytesPerFrame );
899 - /* Write temp buffer to HPI stream */
900 - PA_ASIHPI_UNLESS_( HPI_OutStreamWrite( stream->output->hpiDevice->subSys,
901 - stream->output->hpiStream, &data ),
902 - paUnanticipatedHostError );