| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
#include <assert.h> |
| 76 |
#include <string.h> |
| 77 |
|
| 78 |
#include "pa_process.h" |
| 79 |
#include "pa_util.h" |
| 80 |
|
| 81 |
|
| 82 |
#define PA_FRAMES_PER_TEMP_BUFFER_WHEN_HOST_BUFFER_SIZE_IS_UNKNOWN_ 1024 |
| 83 |
|
| 84 |
#define PA_MIN_( a, b ) ( ((a)<(b)) ? (a) : (b) ) |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static unsigned long GCD( unsigned long a, unsigned long b ) |
| 89 |
{ |
| 90 |
return (b==0) ? a : GCD( b, a%b); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
static unsigned long LCM( unsigned long a, unsigned long b ) |
| 95 |
{ |
| 96 |
return (a*b) / GCD(a,b); |
| 97 |
} |
| 98 |
|
| 99 |
#define PA_MAX_( a, b ) (((a) > (b)) ? (a) : (b)) |
| 100 |
|
| 101 |
static unsigned long CalculateFrameShift( unsigned long M, unsigned long N ) |
| 102 |
{ |
| 103 |
unsigned long result = 0; |
| 104 |
unsigned long i; |
| 105 |
unsigned long lcm; |
| 106 |
|
| 107 |
assert( M > 0 ); |
| 108 |
assert( N > 0 ); |
| 109 |
|
| 110 |
lcm = LCM( M, N ); |
| 111 |
for( i = M; i < lcm; i += M ) |
| 112 |
result = PA_MAX_( result, i % N ); |
| 113 |
|
| 114 |
return result; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, |
| 119 |
int inputChannelCount, PaSampleFormat userInputSampleFormat, |
| 120 |
PaSampleFormat hostInputSampleFormat, |
| 121 |
int outputChannelCount, PaSampleFormat userOutputSampleFormat, |
| 122 |
PaSampleFormat hostOutputSampleFormat, |
| 123 |
double sampleRate, |
| 124 |
PaStreamFlags streamFlags, |
| 125 |
unsigned long framesPerUserBuffer, |
| 126 |
unsigned long framesPerHostBuffer, |
| 127 |
PaUtilHostBufferSizeMode hostBufferSizeMode, |
| 128 |
PaStreamCallback *streamCallback, void *userData ) |
| 129 |
{ |
| 130 |
PaError result = paNoError; |
| 131 |
PaError bytesPerSample; |
| 132 |
unsigned long tempInputBufferSize, tempOutputBufferSize; |
| 133 |
|
| 134 |
if( streamFlags & paNeverDropInput ) |
| 135 |
{ |
| 136 |
|
| 137 |
if( !streamCallback || !(inputChannelCount > 0 && outputChannelCount > 0) || |
| 138 |
framesPerUserBuffer != paFramesPerBufferUnspecified ) |
| 139 |
return paInvalidFlag; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
bp->tempInputBuffer = 0; |
| 144 |
bp->tempInputBufferPtrs = 0; |
| 145 |
bp->tempOutputBuffer = 0; |
| 146 |
bp->tempOutputBufferPtrs = 0; |
| 147 |
|
| 148 |
bp->framesPerUserBuffer = framesPerUserBuffer; |
| 149 |
bp->framesPerHostBuffer = framesPerHostBuffer; |
| 150 |
|
| 151 |
bp->inputChannelCount = inputChannelCount; |
| 152 |
bp->outputChannelCount = outputChannelCount; |
| 153 |
|
| 154 |
bp->hostBufferSizeMode = hostBufferSizeMode; |
| 155 |
|
| 156 |
bp->hostInputChannels[0] = bp->hostInputChannels[1] = 0; |
| 157 |
bp->hostOutputChannels[0] = bp->hostOutputChannels[1] = 0; |
| 158 |
|
| 159 |
if( framesPerUserBuffer == 0 ) |
| 160 |
{ |
| 161 |
bp->useNonAdaptingProcess = 1; |
| 162 |
bp->initialFramesInTempInputBuffer = 0; |
| 163 |
bp->initialFramesInTempOutputBuffer = 0; |
| 164 |
|
| 165 |
if( hostBufferSizeMode == paUtilFixedHostBufferSize |
| 166 |
|| hostBufferSizeMode == paUtilBoundedHostBufferSize ) |
| 167 |
{ |
| 168 |
bp->framesPerTempBuffer = framesPerHostBuffer; |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
bp->framesPerTempBuffer = PA_FRAMES_PER_TEMP_BUFFER_WHEN_HOST_BUFFER_SIZE_IS_UNKNOWN_; |
| 173 |
} |
| 174 |
} |
| 175 |
else |
| 176 |
{ |
| 177 |
bp->framesPerTempBuffer = framesPerUserBuffer; |
| 178 |
|
| 179 |
if( hostBufferSizeMode == paUtilFixedHostBufferSize |
| 180 |
&& framesPerHostBuffer % framesPerUserBuffer == 0 ) |
| 181 |
{ |
| 182 |
bp->useNonAdaptingProcess = 1; |
| 183 |
bp->initialFramesInTempInputBuffer = 0; |
| 184 |
bp->initialFramesInTempOutputBuffer = 0; |
| 185 |
} |
| 186 |
else |
| 187 |
{ |
| 188 |
bp->useNonAdaptingProcess = 0; |
| 189 |
|
| 190 |
if( inputChannelCount > 0 && outputChannelCount > 0 ) |
| 191 |
{ |
| 192 |
|
| 193 |
if( hostBufferSizeMode == paUtilFixedHostBufferSize ) |
| 194 |
{ |
| 195 |
unsigned long frameShift = |
| 196 |
CalculateFrameShift( framesPerHostBuffer, framesPerUserBuffer ); |
| 197 |
|
| 198 |
if( framesPerUserBuffer > framesPerHostBuffer ) |
| 199 |
{ |
| 200 |
bp->initialFramesInTempInputBuffer = frameShift; |
| 201 |
bp->initialFramesInTempOutputBuffer = 0; |
| 202 |
} |
| 203 |
else |
| 204 |
{ |
| 205 |
bp->initialFramesInTempInputBuffer = 0; |
| 206 |
bp->initialFramesInTempOutputBuffer = frameShift; |
| 207 |
} |
| 208 |
} |
| 209 |
else |
| 210 |
{ |
| 211 |
bp->initialFramesInTempInputBuffer = 0; |
| 212 |
bp->initialFramesInTempOutputBuffer = framesPerUserBuffer; |
| 213 |
} |
| 214 |
} |
| 215 |
else |
| 216 |
{ |
| 217 |
|
| 218 |
bp->initialFramesInTempInputBuffer = 0; |
| 219 |
bp->initialFramesInTempOutputBuffer = 0; |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
bp->framesInTempInputBuffer = bp->initialFramesInTempInputBuffer; |
| 226 |
bp->framesInTempOutputBuffer = bp->initialFramesInTempOutputBuffer; |
| 227 |
|
| 228 |
|
| 229 |
if( inputChannelCount > 0 ) |
| 230 |
{ |
| 231 |
bytesPerSample = Pa_GetSampleSize( hostInputSampleFormat ); |
| 232 |
if( bytesPerSample > 0 ) |
| 233 |
{ |
| 234 |
bp->bytesPerHostInputSample = bytesPerSample; |
| 235 |
} |
| 236 |
else |
| 237 |
{ |
| 238 |
result = bytesPerSample; |
| 239 |
goto error; |
| 240 |
} |
| 241 |
|
| 242 |
bytesPerSample = Pa_GetSampleSize( userInputSampleFormat ); |
| 243 |
if( bytesPerSample > 0 ) |
| 244 |
{ |
| 245 |
bp->bytesPerUserInputSample = bytesPerSample; |
| 246 |
} |
| 247 |
else |
| 248 |
{ |
| 249 |
result = bytesPerSample; |
| 250 |
goto error; |
| 251 |
} |
| 252 |
|
| 253 |
bp->inputConverter = |
| 254 |
PaUtil_SelectConverter( hostInputSampleFormat, userInputSampleFormat, streamFlags ); |
| 255 |
|
| 256 |
bp->inputZeroer = PaUtil_SelectZeroer( hostInputSampleFormat ); |
| 257 |
|
| 258 |
bp->userInputIsInterleaved = (userInputSampleFormat & paNonInterleaved)?0:1; |
| 259 |
|
| 260 |
|
| 261 |
tempInputBufferSize = |
| 262 |
bp->framesPerTempBuffer * bp->bytesPerUserInputSample * inputChannelCount; |
| 263 |
|
| 264 |
bp->tempInputBuffer = PaUtil_AllocateMemory( tempInputBufferSize ); |
| 265 |
if( bp->tempInputBuffer == 0 ) |
| 266 |
{ |
| 267 |
result = paInsufficientMemory; |
| 268 |
goto error; |
| 269 |
} |
| 270 |
|
| 271 |
if( bp->framesInTempInputBuffer > 0 ) |
| 272 |
memset( bp->tempInputBuffer, 0, tempInputBufferSize ); |
| 273 |
|
| 274 |
if( userInputSampleFormat & paNonInterleaved ) |
| 275 |
{ |
| 276 |
bp->tempInputBufferPtrs = |
| 277 |
(void **)PaUtil_AllocateMemory( sizeof(void*)*inputChannelCount ); |
| 278 |
if( bp->tempInputBufferPtrs == 0 ) |
| 279 |
{ |
| 280 |
result = paInsufficientMemory; |
| 281 |
goto error; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
bp->hostInputChannels[0] = (PaUtilChannelDescriptor*) |
| 286 |
PaUtil_AllocateMemory( sizeof(PaUtilChannelDescriptor) * inputChannelCount * 2); |
| 287 |
if( bp->hostInputChannels[0] == 0 ) |
| 288 |
{ |
| 289 |
result = paInsufficientMemory; |
| 290 |
goto error; |
| 291 |
} |
| 292 |
|
| 293 |
bp->hostInputChannels[1] = &bp->hostInputChannels[0][inputChannelCount]; |
| 294 |
} |
| 295 |
|
| 296 |
if( outputChannelCount > 0 ) |
| 297 |
{ |
| 298 |
bytesPerSample = Pa_GetSampleSize( hostOutputSampleFormat ); |
| 299 |
if( bytesPerSample > 0 ) |
| 300 |
{ |
| 301 |
bp->bytesPerHostOutputSample = bytesPerSample; |
| 302 |
} |
| 303 |
else |
| 304 |
{ |
| 305 |
result = bytesPerSample; |
| 306 |
goto error; |
| 307 |
} |
| 308 |
|
| 309 |
bytesPerSample = Pa_GetSampleSize( userOutputSampleFormat ); |
| 310 |
if( bytesPerSample > 0 ) |
| 311 |
{ |
| 312 |
bp->bytesPerUserOutputSample = bytesPerSample; |
| 313 |
} |
| 314 |
else |
| 315 |
{ |
| 316 |
result = bytesPerSample; |
| 317 |
goto error; |
| 318 |
} |
| 319 |
|
| 320 |
bp->outputConverter = |
| 321 |
PaUtil_SelectConverter( userOutputSampleFormat, hostOutputSampleFormat, streamFlags ); |
| 322 |
|
| 323 |
bp->outputZeroer = PaUtil_SelectZeroer( hostOutputSampleFormat ); |
| 324 |
|
| 325 |
bp->userOutputIsInterleaved = (userOutputSampleFormat & paNonInterleaved)?0:1; |
| 326 |
|
| 327 |
tempOutputBufferSize = |
| 328 |
bp->framesPerTempBuffer * bp->bytesPerUserOutputSample * outputChannelCount; |
| 329 |
|
| 330 |
bp->tempOutputBuffer = PaUtil_AllocateMemory( tempOutputBufferSize ); |
| 331 |
if( bp->tempOutputBuffer == 0 ) |
| 332 |
{ |
| 333 |
result = paInsufficientMemory; |
| 334 |
goto error; |
| 335 |
} |
| 336 |
|
| 337 |
if( bp->framesInTempOutputBuffer > 0 ) |
| 338 |
memset( bp->tempOutputBuffer, 0, tempOutputBufferSize ); |
| 339 |
|
| 340 |
if( userOutputSampleFormat & paNonInterleaved ) |
| 341 |
{ |
| 342 |
bp->tempOutputBufferPtrs = |
| 343 |
(void **)PaUtil_AllocateMemory( sizeof(void*)*outputChannelCount ); |
| 344 |
if( bp->tempOutputBufferPtrs == 0 ) |
| 345 |
{ |
| 346 |
result = paInsufficientMemory; |
| 347 |
goto error; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
bp->hostOutputChannels[0] = (PaUtilChannelDescriptor*) |
| 352 |
PaUtil_AllocateMemory( sizeof(PaUtilChannelDescriptor)*outputChannelCount * 2 ); |
| 353 |
if( bp->hostOutputChannels[0] == 0 ) |
| 354 |
{ |
| 355 |
result = paInsufficientMemory; |
| 356 |
goto error; |
| 357 |
} |
| 358 |
|
| 359 |
bp->hostOutputChannels[1] = &bp->hostOutputChannels[0][outputChannelCount]; |
| 360 |
} |
| 361 |
|
| 362 |
PaUtil_InitializeTriangularDitherState( &bp->ditherGenerator ); |
| 363 |
|
| 364 |
bp->samplePeriod = 1. / sampleRate; |
| 365 |
|
| 366 |
bp->streamCallback = streamCallback; |
| 367 |
bp->userData = userData; |
| 368 |
|
| 369 |
return result; |
| 370 |
|
| 371 |
error: |
| 372 |
if( bp->tempInputBuffer ) |
| 373 |
PaUtil_FreeMemory( bp->tempInputBuffer ); |
| 374 |
|
| 375 |
if( bp->tempInputBufferPtrs ) |
| 376 |
PaUtil_FreeMemory( bp->tempInputBufferPtrs ); |
| 377 |
|
| 378 |
if( bp->hostInputChannels[0] ) |
| 379 |
PaUtil_FreeMemory( bp->hostInputChannels[0] ); |
| 380 |
|
| 381 |
if( bp->tempOutputBuffer ) |
| 382 |
PaUtil_FreeMemory( bp->tempOutputBuffer ); |
| 383 |
|
| 384 |
if( bp->tempOutputBufferPtrs ) |
| 385 |
PaUtil_FreeMemory( bp->tempOutputBufferPtrs ); |
| 386 |
|
| 387 |
if( bp->hostOutputChannels[0] ) |
| 388 |
PaUtil_FreeMemory( bp->hostOutputChannels[0] ); |
| 389 |
|
| 390 |
return result; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
void PaUtil_TerminateBufferProcessor( PaUtilBufferProcessor* bp ) |
| 395 |
{ |
| 396 |
if( bp->tempInputBuffer ) |
| 397 |
PaUtil_FreeMemory( bp->tempInputBuffer ); |
| 398 |
|
| 399 |
if( bp->tempInputBufferPtrs ) |
| 400 |
PaUtil_FreeMemory( bp->tempInputBufferPtrs ); |
| 401 |
|
| 402 |
if( bp->hostInputChannels[0] ) |
| 403 |
PaUtil_FreeMemory( bp->hostInputChannels[0] ); |
| 404 |
|
| 405 |
if( bp->tempOutputBuffer ) |
| 406 |
PaUtil_FreeMemory( bp->tempOutputBuffer ); |
| 407 |
|
| 408 |
if( bp->tempOutputBufferPtrs ) |
| 409 |
PaUtil_FreeMemory( bp->tempOutputBufferPtrs ); |
| 410 |
|
| 411 |
if( bp->hostOutputChannels[0] ) |
| 412 |
PaUtil_FreeMemory( bp->hostOutputChannels[0] ); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bp ) |
| 417 |
{ |
| 418 |
unsigned long tempInputBufferSize, tempOutputBufferSize; |
| 419 |
|
| 420 |
bp->framesInTempInputBuffer = bp->initialFramesInTempInputBuffer; |
| 421 |
bp->framesInTempOutputBuffer = bp->initialFramesInTempOutputBuffer; |
| 422 |
|
| 423 |
if( bp->framesInTempInputBuffer > 0 ) |
| 424 |
{ |
| 425 |
tempInputBufferSize = |
| 426 |
bp->framesPerTempBuffer * bp->bytesPerUserInputSample * bp->inputChannelCount; |
| 427 |
memset( bp->tempInputBuffer, 0, tempInputBufferSize ); |
| 428 |
} |
| 429 |
|
| 430 |
if( bp->framesInTempOutputBuffer > 0 ) |
| 431 |
{ |
| 432 |
tempOutputBufferSize = |
| 433 |
bp->framesPerTempBuffer * bp->bytesPerUserOutputSample * bp->outputChannelCount; |
| 434 |
memset( bp->tempOutputBuffer, 0, tempOutputBufferSize ); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
unsigned long PaUtil_GetBufferProcessorInputLatency( PaUtilBufferProcessor* bp ) |
| 440 |
{ |
| 441 |
return bp->initialFramesInTempInputBuffer; |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
unsigned long PaUtil_GetBufferProcessorOutputLatency( PaUtilBufferProcessor* bp ) |
| 446 |
{ |
| 447 |
return bp->initialFramesInTempOutputBuffer; |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bp, |
| 452 |
unsigned long frameCount ) |
| 453 |
{ |
| 454 |
if( frameCount == 0 ) |
| 455 |
bp->hostInputFrameCount[0] = bp->framesPerHostBuffer; |
| 456 |
else |
| 457 |
bp->hostInputFrameCount[0] = frameCount; |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
void PaUtil_SetNoInput( PaUtilBufferProcessor* bp ) |
| 462 |
{ |
| 463 |
assert( bp->inputChannelCount > 0 ); |
| 464 |
|
| 465 |
bp->hostInputChannels[0][0].data = 0; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
void PaUtil_SetInputChannel( PaUtilBufferProcessor* bp, |
| 470 |
unsigned int channel, void *data, unsigned int stride ) |
| 471 |
{ |
| 472 |
assert( channel < bp->inputChannelCount ); |
| 473 |
|
| 474 |
bp->hostInputChannels[0][channel].data = data; |
| 475 |
bp->hostInputChannels[0][channel].stride = stride; |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
void PaUtil_SetInterleavedInputChannels( PaUtilBufferProcessor* bp, |
| 480 |
unsigned int firstChannel, void *data, unsigned int channelCount ) |
| 481 |
{ |
| 482 |
unsigned int i; |
| 483 |
unsigned int channel = firstChannel; |
| 484 |
unsigned char *p = (unsigned char*)data; |
| 485 |
|
| 486 |
if( channelCount == 0 ) |
| 487 |
channelCount = bp->inputChannelCount; |
| 488 |
|
| 489 |
assert( firstChannel < bp->inputChannelCount ); |
| 490 |
assert( firstChannel + channelCount <= bp->inputChannelCount ); |
| 491 |
|
| 492 |
for( i=0; i< channelCount; ++i ) |
| 493 |
{ |
| 494 |
bp->hostInputChannels[0][channel+i].data = p; |
| 495 |
p += bp->bytesPerHostInputSample; |
| 496 |
bp->hostInputChannels[0][channel+i].stride = channelCount; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
void PaUtil_SetNonInterleavedInputChannel( PaUtilBufferProcessor* bp, |
| 502 |
unsigned int channel, void *data ) |
| 503 |
{ |
| 504 |
assert( channel < bp->inputChannelCount ); |
| 505 |
|
| 506 |
bp->hostInputChannels[0][channel].data = data; |
| 507 |
bp->hostInputChannels[0][channel].stride = 1; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
void PaUtil_Set2ndInputFrameCount( PaUtilBufferProcessor* bp, |
| 512 |
unsigned long frameCount ) |
| 513 |
{ |
| 514 |
bp->hostInputFrameCount[1] = frameCount; |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
void PaUtil_Set2ndInputChannel( PaUtilBufferProcessor* bp, |
| 519 |
unsigned int channel, void *data, unsigned int stride ) |
| 520 |
{ |
| 521 |
assert( channel < bp->inputChannelCount ); |
| 522 |
|
| 523 |
bp->hostInputChannels[1][channel].data = data; |
| 524 |
bp->hostInputChannels[1][channel].stride = stride; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bp, |
| 529 |
unsigned int firstChannel, void *data, unsigned int channelCount ) |
| 530 |
{ |
| 531 |
unsigned int i; |
| 532 |
unsigned int channel = firstChannel; |
| 533 |
unsigned char *p = (unsigned char*)data; |
| 534 |
|
| 535 |
if( channelCount == 0 ) |
| 536 |
channelCount = bp->inputChannelCount; |
| 537 |
|
| 538 |
assert( firstChannel < bp->inputChannelCount ); |
| 539 |
assert( firstChannel + channelCount <= bp->inputChannelCount ); |
| 540 |
|
| 541 |
for( i=0; i< channelCount; ++i ) |
| 542 |
{ |
| 543 |
bp->hostInputChannels[1][channel+i].data = p; |
| 544 |
p += bp->bytesPerHostInputSample; |
| 545 |
bp->hostInputChannels[1][channel+i].stride = channelCount; |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
void PaUtil_Set2ndNonInterleavedInputChannel( PaUtilBufferProcessor* bp, |
| 551 |
unsigned int channel, void *data ) |
| 552 |
{ |
| 553 |
assert( channel < bp->inputChannelCount ); |
| 554 |
|
| 555 |
bp->hostInputChannels[1][channel].data = data; |
| 556 |
bp->hostInputChannels[1][channel].stride = 1; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
void PaUtil_SetOutputFrameCount( PaUtilBufferProcessor* bp, |
| 561 |
unsigned long frameCount ) |
| 562 |
{ |
| 563 |
if( frameCount == 0 ) |
| 564 |
bp->hostOutputFrameCount[0] = bp->framesPerHostBuffer; |
| 565 |
else |
| 566 |
bp->hostOutputFrameCount[0] = frameCount; |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
void PaUtil_SetNoOutput( PaUtilBufferProcessor* bp ) |
| 571 |
{ |
| 572 |
assert( bp->outputChannelCount > 0 ); |
| 573 |
|
| 574 |
bp->hostOutputChannels[0][0].data = 0; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
void PaUtil_SetOutputChannel( PaUtilBufferProcessor* bp, |
| 579 |
unsigned int channel, void *data, unsigned int stride ) |
| 580 |
{ |
| 581 |
assert( channel < bp->outputChannelCount ); |
| 582 |
assert( data != NULL ); |
| 583 |
|
| 584 |
bp->hostOutputChannels[0][channel].data = data; |
| 585 |
bp->hostOutputChannels[0][channel].stride = stride; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
void PaUtil_SetInterleavedOutputChannels( PaUtilBufferProcessor* bp, |
| 590 |
unsigned int firstChannel, void *data, unsigned int channelCount ) |
| 591 |
{ |
| 592 |
unsigned int i; |
| 593 |
unsigned int channel = firstChannel; |
| 594 |
unsigned char *p = (unsigned char*)data; |
| 595 |
|
| 596 |
if( channelCount == 0 ) |
| 597 |
channelCount = bp->outputChannelCount; |
| 598 |
|
| 599 |
assert( firstChannel < bp->outputChannelCount ); |
| 600 |
assert( firstChannel + channelCount <= bp->outputChannelCount ); |
| 601 |
|
| 602 |
for( i=0; i< channelCount; ++i ) |
| 603 |
{ |
| 604 |
PaUtil_SetOutputChannel( bp, channel + i, p, channelCount ); |
| 605 |
p += bp->bytesPerHostOutputSample; |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
void PaUtil_SetNonInterleavedOutputChannel( PaUtilBufferProcessor* bp, |
| 611 |
unsigned int channel, void *data ) |
| 612 |
{ |
| 613 |
assert( channel < bp->outputChannelCount ); |
| 614 |
|
| 615 |
PaUtil_SetOutputChannel( bp, channel, data, 1 ); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
void PaUtil_Set2ndOutputFrameCount( PaUtilBufferProcessor* bp, |
| 620 |
unsigned long frameCount ) |
| 621 |
{ |
| 622 |
bp->hostOutputFrameCount[1] = frameCount; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
void PaUtil_Set2ndOutputChannel( PaUtilBufferProcessor* bp, |
| 627 |
unsigned int channel, void *data, unsigned int stride ) |
| 628 |
{ |
| 629 |
assert( channel < bp->outputChannelCount ); |
| 630 |
assert( data != NULL ); |
| 631 |
|
| 632 |
bp->hostOutputChannels[1][channel].data = data; |
| 633 |
bp->hostOutputChannels[1][channel].stride = stride; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bp, |
| 638 |
unsigned int firstChannel, void *data, unsigned int channelCount ) |
| 639 |
{ |
| 640 |
unsigned int i; |
| 641 |
unsigned int channel = firstChannel; |
| 642 |
unsigned char *p = (unsigned char*)data; |
| 643 |
|
| 644 |
if( channelCount == 0 ) |
| 645 |
channelCount = bp->outputChannelCount; |
| 646 |
|
| 647 |
assert( firstChannel < bp->outputChannelCount ); |
| 648 |
assert( firstChannel + channelCount <= bp->outputChannelCount ); |
| 649 |
|
| 650 |
for( i=0; i< channelCount; ++i ) |
| 651 |
{ |
| 652 |
PaUtil_Set2ndOutputChannel( bp, channel + i, p, channelCount ); |
| 653 |
p += bp->bytesPerHostOutputSample; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
void PaUtil_Set2ndNonInterleavedOutputChannel( PaUtilBufferProcessor* bp, |
| 659 |
unsigned int channel, void *data ) |
| 660 |
{ |
| 661 |
assert( channel < bp->outputChannelCount ); |
| 662 |
|
| 663 |
PaUtil_Set2ndOutputChannel( bp, channel, data, 1 ); |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
void PaUtil_BeginBufferProcessing( PaUtilBufferProcessor* bp, |
| 668 |
PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags callbackStatusFlags ) |
| 669 |
{ |
| 670 |
bp->timeInfo = timeInfo; |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
bp->timeInfo->inputBufferAdcTime -= bp->framesInTempInputBuffer * bp->samplePeriod; |
| 676 |
|
| 677 |
bp->timeInfo->currentTime = 0; |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
bp->timeInfo->outputBufferDacTime += bp->framesInTempOutputBuffer * bp->samplePeriod; |
| 683 |
|
| 684 |
bp->callbackStatusFlags = callbackStatusFlags; |
| 685 |
|
| 686 |
bp->hostInputFrameCount[1] = 0; |
| 687 |
bp->hostOutputFrameCount[1] = 0; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, |
| 701 |
int *streamCallbackResult, |
| 702 |
PaUtilChannelDescriptor *hostInputChannels, |
| 703 |
PaUtilChannelDescriptor *hostOutputChannels, |
| 704 |
unsigned long framesToProcess ) |
| 705 |
{ |
| 706 |
void *userInput, *userOutput; |
| 707 |
unsigned char *srcBytePtr, *destBytePtr; |
| 708 |
unsigned int srcSampleStrideSamples; |
| 709 |
unsigned int srcChannelStrideBytes; |
| 710 |
unsigned int destSampleStrideSamples; |
| 711 |
unsigned int destChannelStrideBytes; |
| 712 |
unsigned int i; |
| 713 |
unsigned long frameCount; |
| 714 |
unsigned long framesToGo = framesToProcess; |
| 715 |
unsigned long framesProcessed = 0; |
| 716 |
|
| 717 |
|
| 718 |
if( *streamCallbackResult == paContinue ) |
| 719 |
{ |
| 720 |
do |
| 721 |
{ |
| 722 |
frameCount = PA_MIN_( bp->framesPerTempBuffer, framesToGo ); |
| 723 |
|
| 724 |
|
| 725 |
if( bp->inputChannelCount == 0 ) |
| 726 |
{ |
| 727 |
|
| 728 |
userInput = 0; |
| 729 |
} |
| 730 |
else |
| 731 |
{ |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
destBytePtr = (unsigned char *)bp->tempInputBuffer; |
| 738 |
|
| 739 |
if( bp->userInputIsInterleaved ) |
| 740 |
{ |
| 741 |
destSampleStrideSamples = bp->inputChannelCount; |
| 742 |
destChannelStrideBytes = bp->bytesPerUserInputSample; |
| 743 |
userInput = bp->tempInputBuffer; |
| 744 |
} |
| 745 |
else |
| 746 |
{ |
| 747 |
destSampleStrideSamples = 1; |
| 748 |
destChannelStrideBytes = frameCount * bp->bytesPerUserInputSample; |
| 749 |
|
| 750 |
|
| 751 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 752 |
{ |
| 753 |
bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) + |
| 754 |
i * bp->bytesPerUserInputSample * frameCount; |
| 755 |
} |
| 756 |
|
| 757 |
userInput = bp->tempInputBufferPtrs; |
| 758 |
} |
| 759 |
|
| 760 |
if( !bp->hostInputChannels[0][0].data ) |
| 761 |
{ |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 766 |
{ |
| 767 |
bp->inputZeroer( destBytePtr, destSampleStrideSamples, frameCount ); |
| 768 |
destBytePtr += destChannelStrideBytes; |
| 769 |
} |
| 770 |
} |
| 771 |
else |
| 772 |
{ |
| 773 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 774 |
{ |
| 775 |
bp->inputConverter( destBytePtr, destSampleStrideSamples, |
| 776 |
hostInputChannels[i].data, |
| 777 |
hostInputChannels[i].stride, |
| 778 |
frameCount, &bp->ditherGenerator ); |
| 779 |
|
| 780 |
destBytePtr += destChannelStrideBytes; |
| 781 |
|
| 782 |
|
| 783 |
hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + |
| 784 |
frameCount * hostInputChannels[i].stride * bp->bytesPerHostInputSample; |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
if( bp->outputChannelCount == 0 ) |
| 791 |
{ |
| 792 |
|
| 793 |
userOutput = 0; |
| 794 |
} |
| 795 |
else |
| 796 |
{ |
| 797 |
if( bp->userOutputIsInterleaved ) |
| 798 |
{ |
| 799 |
userOutput = bp->tempOutputBuffer; |
| 800 |
} |
| 801 |
else |
| 802 |
{ |
| 803 |
for( i = 0; i < bp->outputChannelCount; ++i ) |
| 804 |
{ |
| 805 |
bp->tempOutputBufferPtrs[i] = ((unsigned char*)bp->tempOutputBuffer) + |
| 806 |
i * bp->bytesPerUserOutputSample * frameCount; |
| 807 |
} |
| 808 |
|
| 809 |
userOutput = bp->tempOutputBufferPtrs; |
| 810 |
} |
| 811 |
} |
| 812 |
|
| 813 |
*streamCallbackResult = bp->streamCallback( userInput, userOutput, |
| 814 |
frameCount, bp->timeInfo, bp->callbackStatusFlags, bp->userData ); |
| 815 |
|
| 816 |
if( *streamCallbackResult == paAbort ) |
| 817 |
{ |
| 818 |
|
| 819 |
|
| 820 |
} |
| 821 |
else |
| 822 |
{ |
| 823 |
bp->timeInfo->inputBufferAdcTime += frameCount * bp->samplePeriod; |
| 824 |
bp->timeInfo->outputBufferDacTime += frameCount * bp->samplePeriod; |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
if( bp->outputChannelCount != 0 && bp->hostOutputChannels[0][0].data ) |
| 829 |
{ |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
srcBytePtr = (unsigned char *)bp->tempOutputBuffer; |
| 836 |
|
| 837 |
if( bp->userOutputIsInterleaved ) |
| 838 |
{ |
| 839 |
srcSampleStrideSamples = bp->outputChannelCount; |
| 840 |
srcChannelStrideBytes = bp->bytesPerUserOutputSample; |
| 841 |
} |
| 842 |
else |
| 843 |
{ |
| 844 |
srcSampleStrideSamples = 1; |
| 845 |
srcChannelStrideBytes = frameCount * bp->bytesPerUserOutputSample; |
| 846 |
} |
| 847 |
|
| 848 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 849 |
{ |
| 850 |
bp->outputConverter( hostOutputChannels[i].data, |
| 851 |
hostOutputChannels[i].stride, |
| 852 |
srcBytePtr, srcSampleStrideSamples, |
| 853 |
frameCount, &bp->ditherGenerator ); |
| 854 |
|
| 855 |
srcBytePtr += srcChannelStrideBytes; |
| 856 |
|
| 857 |
|
| 858 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 859 |
frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
framesProcessed += frameCount; |
| 864 |
|
| 865 |
framesToGo -= frameCount; |
| 866 |
} |
| 867 |
} |
| 868 |
while( framesToGo > 0 && *streamCallbackResult == paContinue ); |
| 869 |
} |
| 870 |
|
| 871 |
if( framesToGo > 0 ) |
| 872 |
{ |
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
frameCount = framesToGo; |
| 877 |
|
| 878 |
if( bp->outputChannelCount != 0 && bp->hostOutputChannels[0][0].data ) |
| 879 |
{ |
| 880 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 881 |
{ |
| 882 |
bp->outputZeroer( hostOutputChannels[i].data, |
| 883 |
hostOutputChannels[i].stride, |
| 884 |
frameCount ); |
| 885 |
|
| 886 |
|
| 887 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 888 |
frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
framesProcessed += frameCount; |
| 893 |
} |
| 894 |
|
| 895 |
return framesProcessed; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp, |
| 905 |
int *streamCallbackResult, |
| 906 |
PaUtilChannelDescriptor *hostInputChannels, |
| 907 |
unsigned long framesToProcess ) |
| 908 |
{ |
| 909 |
void *userInput, *userOutput; |
| 910 |
unsigned char *destBytePtr; |
| 911 |
unsigned int destSampleStrideSamples; |
| 912 |
unsigned int destChannelStrideBytes; |
| 913 |
unsigned int i; |
| 914 |
unsigned long frameCount; |
| 915 |
unsigned long framesToGo = framesToProcess; |
| 916 |
unsigned long framesProcessed = 0; |
| 917 |
|
| 918 |
userOutput = 0; |
| 919 |
|
| 920 |
do |
| 921 |
{ |
| 922 |
frameCount = ( bp->framesInTempInputBuffer + framesToGo > bp->framesPerUserBuffer ) |
| 923 |
? ( bp->framesPerUserBuffer - bp->framesInTempInputBuffer ) |
| 924 |
: framesToGo; |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
if( bp->userInputIsInterleaved ) |
| 929 |
{ |
| 930 |
destBytePtr = ((unsigned char*)bp->tempInputBuffer) + |
| 931 |
bp->bytesPerUserInputSample * bp->inputChannelCount * |
| 932 |
bp->framesInTempInputBuffer; |
| 933 |
|
| 934 |
destSampleStrideSamples = bp->inputChannelCount; |
| 935 |
destChannelStrideBytes = bp->bytesPerUserInputSample; |
| 936 |
|
| 937 |
userInput = bp->tempInputBuffer; |
| 938 |
} |
| 939 |
else |
| 940 |
{ |
| 941 |
destBytePtr = ((unsigned char*)bp->tempInputBuffer) + |
| 942 |
bp->bytesPerUserInputSample * bp->framesInTempInputBuffer; |
| 943 |
|
| 944 |
destSampleStrideSamples = 1; |
| 945 |
destChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserInputSample; |
| 946 |
|
| 947 |
|
| 948 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 949 |
{ |
| 950 |
bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) + |
| 951 |
i * bp->bytesPerUserInputSample * bp->framesPerUserBuffer; |
| 952 |
} |
| 953 |
|
| 954 |
userInput = bp->tempInputBufferPtrs; |
| 955 |
} |
| 956 |
|
| 957 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 958 |
{ |
| 959 |
bp->inputConverter( destBytePtr, destSampleStrideSamples, |
| 960 |
hostInputChannels[i].data, |
| 961 |
hostInputChannels[i].stride, |
| 962 |
frameCount, &bp->ditherGenerator ); |
| 963 |
|
| 964 |
destBytePtr += destChannelStrideBytes; |
| 965 |
|
| 966 |
|
| 967 |
hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + |
| 968 |
frameCount * hostInputChannels[i].stride * bp->bytesPerHostInputSample; |
| 969 |
} |
| 970 |
|
| 971 |
bp->framesInTempInputBuffer += frameCount; |
| 972 |
|
| 973 |
if( bp->framesInTempInputBuffer == bp->framesPerUserBuffer ) |
| 974 |
{ |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
if( *streamCallbackResult == paContinue ) |
| 984 |
{ |
| 985 |
bp->timeInfo->outputBufferDacTime = 0; |
| 986 |
|
| 987 |
*streamCallbackResult = bp->streamCallback( userInput, userOutput, |
| 988 |
bp->framesPerUserBuffer, bp->timeInfo, |
| 989 |
bp->callbackStatusFlags, bp->userData ); |
| 990 |
|
| 991 |
bp->timeInfo->inputBufferAdcTime += frameCount * bp->samplePeriod; |
| 992 |
} |
| 993 |
|
| 994 |
bp->framesInTempInputBuffer = 0; |
| 995 |
} |
| 996 |
|
| 997 |
framesProcessed += frameCount; |
| 998 |
|
| 999 |
framesToGo -= frameCount; |
| 1000 |
}while( framesToGo > 0 ); |
| 1001 |
|
| 1002 |
return framesProcessed; |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp, |
| 1012 |
int *streamCallbackResult, |
| 1013 |
PaUtilChannelDescriptor *hostOutputChannels, |
| 1014 |
unsigned long framesToProcess ) |
| 1015 |
{ |
| 1016 |
void *userInput, *userOutput; |
| 1017 |
unsigned char *srcBytePtr; |
| 1018 |
unsigned int srcSampleStrideSamples; |
| 1019 |
unsigned int srcChannelStrideBytes; |
| 1020 |
unsigned int i; |
| 1021 |
unsigned long frameCount; |
| 1022 |
unsigned long framesToGo = framesToProcess; |
| 1023 |
unsigned long framesProcessed = 0; |
| 1024 |
|
| 1025 |
do |
| 1026 |
{ |
| 1027 |
if( bp->framesInTempOutputBuffer == 0 && *streamCallbackResult == paContinue ) |
| 1028 |
{ |
| 1029 |
userInput = 0; |
| 1030 |
|
| 1031 |
|
| 1032 |
if( bp->userOutputIsInterleaved ) |
| 1033 |
{ |
| 1034 |
userOutput = bp->tempOutputBuffer; |
| 1035 |
} |
| 1036 |
else |
| 1037 |
{ |
| 1038 |
for( i = 0; i < bp->outputChannelCount; ++i ) |
| 1039 |
{ |
| 1040 |
bp->tempOutputBufferPtrs[i] = ((unsigned char*)bp->tempOutputBuffer) + |
| 1041 |
i * bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; |
| 1042 |
} |
| 1043 |
|
| 1044 |
userOutput = bp->tempOutputBufferPtrs; |
| 1045 |
} |
| 1046 |
|
| 1047 |
bp->timeInfo->inputBufferAdcTime = 0; |
| 1048 |
|
| 1049 |
*streamCallbackResult = bp->streamCallback( userInput, userOutput, |
| 1050 |
bp->framesPerUserBuffer, bp->timeInfo, |
| 1051 |
bp->callbackStatusFlags, bp->userData ); |
| 1052 |
|
| 1053 |
if( *streamCallbackResult == paAbort ) |
| 1054 |
{ |
| 1055 |
|
| 1056 |
} |
| 1057 |
else |
| 1058 |
{ |
| 1059 |
bp->timeInfo->outputBufferDacTime += bp->framesPerUserBuffer * bp->samplePeriod; |
| 1060 |
|
| 1061 |
bp->framesInTempOutputBuffer = bp->framesPerUserBuffer; |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
if( bp->framesInTempOutputBuffer > 0 ) |
| 1066 |
{ |
| 1067 |
|
| 1068 |
|
| 1069 |
frameCount = PA_MIN_( bp->framesInTempOutputBuffer, framesToGo ); |
| 1070 |
|
| 1071 |
if( bp->userOutputIsInterleaved ) |
| 1072 |
{ |
| 1073 |
srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + |
| 1074 |
bp->bytesPerUserOutputSample * bp->outputChannelCount * |
| 1075 |
(bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); |
| 1076 |
|
| 1077 |
srcSampleStrideSamples = bp->outputChannelCount; |
| 1078 |
srcChannelStrideBytes = bp->bytesPerUserOutputSample; |
| 1079 |
} |
| 1080 |
else |
| 1081 |
{ |
| 1082 |
srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + |
| 1083 |
bp->bytesPerUserOutputSample * |
| 1084 |
(bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); |
| 1085 |
|
| 1086 |
srcSampleStrideSamples = 1; |
| 1087 |
srcChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; |
| 1088 |
} |
| 1089 |
|
| 1090 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1091 |
{ |
| 1092 |
bp->outputConverter( hostOutputChannels[i].data, |
| 1093 |
hostOutputChannels[i].stride, |
| 1094 |
srcBytePtr, srcSampleStrideSamples, |
| 1095 |
frameCount, &bp->ditherGenerator ); |
| 1096 |
|
| 1097 |
srcBytePtr += srcChannelStrideBytes; |
| 1098 |
|
| 1099 |
|
| 1100 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1101 |
frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1102 |
} |
| 1103 |
|
| 1104 |
bp->framesInTempOutputBuffer -= frameCount; |
| 1105 |
} |
| 1106 |
else |
| 1107 |
{ |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
frameCount = framesToGo; |
| 1114 |
|
| 1115 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1116 |
{ |
| 1117 |
bp->outputZeroer( hostOutputChannels[i].data, |
| 1118 |
hostOutputChannels[i].stride, |
| 1119 |
frameCount ); |
| 1120 |
|
| 1121 |
|
| 1122 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1123 |
frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1124 |
} |
| 1125 |
} |
| 1126 |
|
| 1127 |
framesProcessed += frameCount; |
| 1128 |
|
| 1129 |
framesToGo -= frameCount; |
| 1130 |
|
| 1131 |
}while( framesToGo > 0 ); |
| 1132 |
|
| 1133 |
return framesProcessed; |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
static void CopyTempOutputBuffersToHostOutputBuffers( PaUtilBufferProcessor *bp) |
| 1141 |
{ |
| 1142 |
unsigned long maxFramesToCopy; |
| 1143 |
PaUtilChannelDescriptor *hostOutputChannels; |
| 1144 |
unsigned int frameCount; |
| 1145 |
unsigned char *srcBytePtr; |
| 1146 |
unsigned int srcSampleStrideSamples; |
| 1147 |
unsigned int srcChannelStrideBytes; |
| 1148 |
unsigned int i; |
| 1149 |
|
| 1150 |
|
| 1151 |
while( bp->framesInTempOutputBuffer > 0 && |
| 1152 |
((bp->hostOutputFrameCount[0] + bp->hostOutputFrameCount[1]) > 0) ) |
| 1153 |
{ |
| 1154 |
maxFramesToCopy = bp->framesInTempOutputBuffer; |
| 1155 |
|
| 1156 |
|
| 1157 |
if( bp->hostOutputFrameCount[0] > 0 ) |
| 1158 |
{ |
| 1159 |
hostOutputChannels = bp->hostOutputChannels[0]; |
| 1160 |
frameCount = PA_MIN_( bp->hostOutputFrameCount[0], maxFramesToCopy ); |
| 1161 |
} |
| 1162 |
else |
| 1163 |
{ |
| 1164 |
hostOutputChannels = bp->hostOutputChannels[1]; |
| 1165 |
frameCount = PA_MIN_( bp->hostOutputFrameCount[1], maxFramesToCopy ); |
| 1166 |
} |
| 1167 |
|
| 1168 |
if( bp->userOutputIsInterleaved ) |
| 1169 |
{ |
| 1170 |
srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + |
| 1171 |
bp->bytesPerUserOutputSample * bp->outputChannelCount * |
| 1172 |
(bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); |
| 1173 |
|
| 1174 |
srcSampleStrideSamples = bp->outputChannelCount; |
| 1175 |
srcChannelStrideBytes = bp->bytesPerUserOutputSample; |
| 1176 |
} |
| 1177 |
else |
| 1178 |
{ |
| 1179 |
srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + |
| 1180 |
bp->bytesPerUserOutputSample * |
| 1181 |
(bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); |
| 1182 |
|
| 1183 |
srcSampleStrideSamples = 1; |
| 1184 |
srcChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; |
| 1185 |
} |
| 1186 |
|
| 1187 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1188 |
{ |
| 1189 |
assert( hostOutputChannels[i].data != NULL ); |
| 1190 |
bp->outputConverter( hostOutputChannels[i].data, |
| 1191 |
hostOutputChannels[i].stride, |
| 1192 |
srcBytePtr, srcSampleStrideSamples, |
| 1193 |
frameCount, &bp->ditherGenerator ); |
| 1194 |
|
| 1195 |
srcBytePtr += srcChannelStrideBytes; |
| 1196 |
|
| 1197 |
|
| 1198 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1199 |
frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1200 |
} |
| 1201 |
|
| 1202 |
if( bp->hostOutputFrameCount[0] > 0 ) |
| 1203 |
bp->hostOutputFrameCount[0] -= frameCount; |
| 1204 |
else |
| 1205 |
bp->hostOutputFrameCount[1] -= frameCount; |
| 1206 |
|
| 1207 |
bp->framesInTempOutputBuffer -= frameCount; |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, |
| 1222 |
int *streamCallbackResult, int processPartialUserBuffers ) |
| 1223 |
{ |
| 1224 |
void *userInput, *userOutput; |
| 1225 |
unsigned long framesProcessed = 0; |
| 1226 |
unsigned long framesAvailable; |
| 1227 |
unsigned long endProcessingMinFrameCount; |
| 1228 |
unsigned long maxFramesToCopy; |
| 1229 |
PaUtilChannelDescriptor *hostInputChannels, *hostOutputChannels; |
| 1230 |
unsigned int frameCount; |
| 1231 |
unsigned char *destBytePtr; |
| 1232 |
unsigned int destSampleStrideSamples; |
| 1233 |
unsigned int destChannelStrideBytes; |
| 1234 |
unsigned int i, j; |
| 1235 |
|
| 1236 |
|
| 1237 |
framesAvailable = bp->hostInputFrameCount[0] + bp->hostInputFrameCount[1]; |
| 1238 |
|
| 1239 |
if( processPartialUserBuffers ) |
| 1240 |
endProcessingMinFrameCount = 0; |
| 1241 |
else |
| 1242 |
endProcessingMinFrameCount = (bp->framesPerUserBuffer - 1); |
| 1243 |
|
| 1244 |
|
| 1245 |
CopyTempOutputBuffersToHostOutputBuffers( bp ); |
| 1246 |
|
| 1247 |
while( framesAvailable > endProcessingMinFrameCount ) |
| 1248 |
{ |
| 1249 |
|
| 1250 |
if( bp->framesInTempOutputBuffer == 0 && *streamCallbackResult != paContinue ) |
| 1251 |
{ |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
for( i=0; i<2; ++i ) |
| 1256 |
{ |
| 1257 |
frameCount = bp->hostOutputFrameCount[i]; |
| 1258 |
if( frameCount > 0 ) |
| 1259 |
{ |
| 1260 |
hostOutputChannels = bp->hostOutputChannels[i]; |
| 1261 |
|
| 1262 |
for( j=0; j<bp->outputChannelCount; ++j ) |
| 1263 |
{ |
| 1264 |
bp->outputZeroer( hostOutputChannels[j].data, |
| 1265 |
hostOutputChannels[j].stride, |
| 1266 |
frameCount ); |
| 1267 |
|
| 1268 |
|
| 1269 |
hostOutputChannels[j].data = ((unsigned char*)hostOutputChannels[j].data) + |
| 1270 |
frameCount * hostOutputChannels[j].stride * bp->bytesPerHostOutputSample; |
| 1271 |
} |
| 1272 |
bp->hostOutputFrameCount[i] = 0; |
| 1273 |
} |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
while( bp->framesInTempInputBuffer < bp->framesPerUserBuffer && |
| 1280 |
((bp->hostInputFrameCount[0] + bp->hostInputFrameCount[1]) > 0) ) |
| 1281 |
{ |
| 1282 |
maxFramesToCopy = bp->framesPerUserBuffer - bp->framesInTempInputBuffer; |
| 1283 |
|
| 1284 |
|
| 1285 |
if( bp->hostInputFrameCount[0] > 0 ) |
| 1286 |
{ |
| 1287 |
hostInputChannels = bp->hostInputChannels[0]; |
| 1288 |
frameCount = PA_MIN_( bp->hostInputFrameCount[0], maxFramesToCopy ); |
| 1289 |
} |
| 1290 |
else |
| 1291 |
{ |
| 1292 |
hostInputChannels = bp->hostInputChannels[1]; |
| 1293 |
frameCount = PA_MIN_( bp->hostInputFrameCount[1], maxFramesToCopy ); |
| 1294 |
} |
| 1295 |
|
| 1296 |
|
| 1297 |
if( bp->userInputIsInterleaved ) |
| 1298 |
{ |
| 1299 |
destBytePtr = ((unsigned char*)bp->tempInputBuffer) + |
| 1300 |
bp->bytesPerUserInputSample * bp->inputChannelCount * |
| 1301 |
bp->framesInTempInputBuffer; |
| 1302 |
|
| 1303 |
destSampleStrideSamples = bp->inputChannelCount; |
| 1304 |
destChannelStrideBytes = bp->bytesPerUserInputSample; |
| 1305 |
} |
| 1306 |
else |
| 1307 |
{ |
| 1308 |
destBytePtr = ((unsigned char*)bp->tempInputBuffer) + |
| 1309 |
bp->bytesPerUserInputSample * bp->framesInTempInputBuffer; |
| 1310 |
|
| 1311 |
destSampleStrideSamples = 1; |
| 1312 |
destChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserInputSample; |
| 1313 |
} |
| 1314 |
|
| 1315 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 1316 |
{ |
| 1317 |
bp->inputConverter( destBytePtr, destSampleStrideSamples, |
| 1318 |
hostInputChannels[i].data, |
| 1319 |
hostInputChannels[i].stride, |
| 1320 |
frameCount, &bp->ditherGenerator ); |
| 1321 |
|
| 1322 |
destBytePtr += destChannelStrideBytes; |
| 1323 |
|
| 1324 |
|
| 1325 |
hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + |
| 1326 |
frameCount * hostInputChannels[i].stride * bp->bytesPerHostInputSample; |
| 1327 |
} |
| 1328 |
|
| 1329 |
if( bp->hostInputFrameCount[0] > 0 ) |
| 1330 |
bp->hostInputFrameCount[0] -= frameCount; |
| 1331 |
else |
| 1332 |
bp->hostInputFrameCount[1] -= frameCount; |
| 1333 |
|
| 1334 |
bp->framesInTempInputBuffer += frameCount; |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
framesAvailable -= frameCount; |
| 1340 |
framesProcessed += frameCount; |
| 1341 |
} |
| 1342 |
|
| 1343 |
|
| 1344 |
if( bp->framesInTempInputBuffer == bp->framesPerUserBuffer && |
| 1345 |
bp->framesInTempOutputBuffer == 0 ) |
| 1346 |
{ |
| 1347 |
if( *streamCallbackResult == paContinue ) |
| 1348 |
{ |
| 1349 |
|
| 1350 |
if( bp->userInputIsInterleaved ) |
| 1351 |
{ |
| 1352 |
userInput = bp->tempInputBuffer; |
| 1353 |
} |
| 1354 |
else |
| 1355 |
{ |
| 1356 |
for( i = 0; i < bp->inputChannelCount; ++i ) |
| 1357 |
{ |
| 1358 |
bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) + |
| 1359 |
i * bp->framesPerUserBuffer * bp->bytesPerUserInputSample; |
| 1360 |
} |
| 1361 |
|
| 1362 |
userInput = bp->tempInputBufferPtrs; |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
if( bp->userOutputIsInterleaved ) |
| 1367 |
{ |
| 1368 |
userOutput = bp->tempOutputBuffer; |
| 1369 |
} |
| 1370 |
else |
| 1371 |
{ |
| 1372 |
for( i = 0; i < bp->outputChannelCount; ++i ) |
| 1373 |
{ |
| 1374 |
bp->tempOutputBufferPtrs[i] = ((unsigned char*)bp->tempOutputBuffer) + |
| 1375 |
i * bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; |
| 1376 |
} |
| 1377 |
|
| 1378 |
userOutput = bp->tempOutputBufferPtrs; |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
*streamCallbackResult = bp->streamCallback( userInput, userOutput, |
| 1384 |
bp->framesPerUserBuffer, bp->timeInfo, |
| 1385 |
bp->callbackStatusFlags, bp->userData ); |
| 1386 |
|
| 1387 |
bp->timeInfo->inputBufferAdcTime += bp->framesPerUserBuffer * bp->samplePeriod; |
| 1388 |
bp->timeInfo->outputBufferDacTime += bp->framesPerUserBuffer * bp->samplePeriod; |
| 1389 |
|
| 1390 |
bp->framesInTempInputBuffer = 0; |
| 1391 |
|
| 1392 |
if( *streamCallbackResult == paAbort ) |
| 1393 |
bp->framesInTempOutputBuffer = 0; |
| 1394 |
else |
| 1395 |
bp->framesInTempOutputBuffer = bp->framesPerUserBuffer; |
| 1396 |
} |
| 1397 |
else |
| 1398 |
{ |
| 1399 |
|
| 1400 |
|
| 1401 |
bp->framesInTempInputBuffer = 0; |
| 1402 |
} |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
CopyTempOutputBuffersToHostOutputBuffers( bp ); |
| 1409 |
|
| 1410 |
} |
| 1411 |
|
| 1412 |
return framesProcessed; |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *streamCallbackResult ) |
| 1417 |
{ |
| 1418 |
unsigned long framesToProcess, framesToGo; |
| 1419 |
unsigned long framesProcessed = 0; |
| 1420 |
|
| 1421 |
if( bp->inputChannelCount != 0 && bp->outputChannelCount != 0 |
| 1422 |
&& bp->hostInputChannels[0][0].data |
| 1423 |
&& bp->hostOutputChannels[0][0].data ) |
| 1424 |
{ |
| 1425 |
assert( (bp->hostInputFrameCount[0] + bp->hostInputFrameCount[1]) == |
| 1426 |
(bp->hostOutputFrameCount[0] + bp->hostOutputFrameCount[1]) ); |
| 1427 |
} |
| 1428 |
|
| 1429 |
assert( *streamCallbackResult == paContinue |
| 1430 |
|| *streamCallbackResult == paComplete |
| 1431 |
|| *streamCallbackResult == paAbort ); |
| 1432 |
|
| 1433 |
if( bp->useNonAdaptingProcess ) |
| 1434 |
{ |
| 1435 |
if( bp->inputChannelCount != 0 && bp->outputChannelCount != 0 ) |
| 1436 |
{ |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
framesToGo = bp->hostOutputFrameCount[0] + bp->hostOutputFrameCount[1]; |
| 1441 |
|
| 1442 |
do{ |
| 1443 |
unsigned long noInputInputFrameCount; |
| 1444 |
unsigned long *hostInputFrameCount; |
| 1445 |
PaUtilChannelDescriptor *hostInputChannels; |
| 1446 |
unsigned long noOutputOutputFrameCount; |
| 1447 |
unsigned long *hostOutputFrameCount; |
| 1448 |
PaUtilChannelDescriptor *hostOutputChannels; |
| 1449 |
unsigned long framesProcessedThisIteration; |
| 1450 |
|
| 1451 |
if( !bp->hostInputChannels[0][0].data ) |
| 1452 |
{ |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
noInputInputFrameCount = framesToGo; |
| 1457 |
hostInputFrameCount = &noInputInputFrameCount; |
| 1458 |
hostInputChannels = 0; |
| 1459 |
} |
| 1460 |
else if( bp->hostInputFrameCount[0] != 0 ) |
| 1461 |
{ |
| 1462 |
hostInputFrameCount = &bp->hostInputFrameCount[0]; |
| 1463 |
hostInputChannels = bp->hostInputChannels[0]; |
| 1464 |
} |
| 1465 |
else |
| 1466 |
{ |
| 1467 |
hostInputFrameCount = &bp->hostInputFrameCount[1]; |
| 1468 |
hostInputChannels = bp->hostInputChannels[1]; |
| 1469 |
} |
| 1470 |
|
| 1471 |
if( !bp->hostOutputChannels[0][0].data ) |
| 1472 |
{ |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
noOutputOutputFrameCount = framesToGo; |
| 1477 |
hostOutputFrameCount = &noOutputOutputFrameCount; |
| 1478 |
hostOutputChannels = 0; |
| 1479 |
} |
| 1480 |
if( bp->hostOutputFrameCount[0] != 0 ) |
| 1481 |
{ |
| 1482 |
hostOutputFrameCount = &bp->hostOutputFrameCount[0]; |
| 1483 |
hostOutputChannels = bp->hostOutputChannels[0]; |
| 1484 |
} |
| 1485 |
else |
| 1486 |
{ |
| 1487 |
hostOutputFrameCount = &bp->hostOutputFrameCount[1]; |
| 1488 |
hostOutputChannels = bp->hostOutputChannels[1]; |
| 1489 |
} |
| 1490 |
|
| 1491 |
framesToProcess = PA_MIN_( *hostInputFrameCount, |
| 1492 |
*hostOutputFrameCount ); |
| 1493 |
|
| 1494 |
assert( framesToProcess != 0 ); |
| 1495 |
|
| 1496 |
framesProcessedThisIteration = NonAdaptingProcess( bp, streamCallbackResult, |
| 1497 |
hostInputChannels, hostOutputChannels, |
| 1498 |
framesToProcess ); |
| 1499 |
|
| 1500 |
*hostInputFrameCount -= framesProcessedThisIteration; |
| 1501 |
*hostOutputFrameCount -= framesProcessedThisIteration; |
| 1502 |
|
| 1503 |
framesProcessed += framesProcessedThisIteration; |
| 1504 |
framesToGo -= framesProcessedThisIteration; |
| 1505 |
|
| 1506 |
}while( framesToGo > 0 ); |
| 1507 |
} |
| 1508 |
else |
| 1509 |
{ |
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
framesToProcess = (bp->inputChannelCount != 0) |
| 1514 |
? bp->hostInputFrameCount[0] |
| 1515 |
: bp->hostOutputFrameCount[0]; |
| 1516 |
|
| 1517 |
framesProcessed = NonAdaptingProcess( bp, streamCallbackResult, |
| 1518 |
bp->hostInputChannels[0], bp->hostOutputChannels[0], |
| 1519 |
framesToProcess ); |
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
framesToProcess = (bp->inputChannelCount != 0) |
| 1524 |
? bp->hostInputFrameCount[1] |
| 1525 |
: bp->hostOutputFrameCount[1]; |
| 1526 |
if( framesToProcess > 0 ) |
| 1527 |
{ |
| 1528 |
framesProcessed += NonAdaptingProcess( bp, streamCallbackResult, |
| 1529 |
bp->hostInputChannels[1], bp->hostOutputChannels[1], |
| 1530 |
framesToProcess ); |
| 1531 |
} |
| 1532 |
} |
| 1533 |
} |
| 1534 |
else |
| 1535 |
{ |
| 1536 |
|
| 1537 |
if( bp->inputChannelCount != 0 && bp->outputChannelCount != 0 ) |
| 1538 |
{ |
| 1539 |
|
| 1540 |
|
| 1541 |
if( bp->hostBufferSizeMode == paUtilVariableHostBufferSizePartialUsageAllowed ) |
| 1542 |
{ |
| 1543 |
framesProcessed = AdaptingProcess( bp, streamCallbackResult, |
| 1544 |
0 ); |
| 1545 |
} |
| 1546 |
else |
| 1547 |
{ |
| 1548 |
framesProcessed = AdaptingProcess( bp, streamCallbackResult, |
| 1549 |
1 ); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
else if( bp->inputChannelCount != 0 ) |
| 1553 |
{ |
| 1554 |
|
| 1555 |
framesToProcess = bp->hostInputFrameCount[0]; |
| 1556 |
|
| 1557 |
framesProcessed = AdaptingInputOnlyProcess( bp, streamCallbackResult, |
| 1558 |
bp->hostInputChannels[0], framesToProcess ); |
| 1559 |
|
| 1560 |
framesToProcess = bp->hostInputFrameCount[1]; |
| 1561 |
if( framesToProcess > 0 ) |
| 1562 |
{ |
| 1563 |
framesProcessed += AdaptingInputOnlyProcess( bp, streamCallbackResult, |
| 1564 |
bp->hostInputChannels[1], framesToProcess ); |
| 1565 |
} |
| 1566 |
} |
| 1567 |
else |
| 1568 |
{ |
| 1569 |
|
| 1570 |
framesToProcess = bp->hostOutputFrameCount[0]; |
| 1571 |
|
| 1572 |
framesProcessed = AdaptingOutputOnlyProcess( bp, streamCallbackResult, |
| 1573 |
bp->hostOutputChannels[0], framesToProcess ); |
| 1574 |
|
| 1575 |
framesToProcess = bp->hostOutputFrameCount[1]; |
| 1576 |
if( framesToProcess > 0 ) |
| 1577 |
{ |
| 1578 |
framesProcessed += AdaptingOutputOnlyProcess( bp, streamCallbackResult, |
| 1579 |
bp->hostOutputChannels[1], framesToProcess ); |
| 1580 |
} |
| 1581 |
} |
| 1582 |
} |
| 1583 |
|
| 1584 |
return framesProcessed; |
| 1585 |
} |
| 1586 |
|
| 1587 |
|
| 1588 |
int PaUtil_IsBufferProcessorOutputEmpty( PaUtilBufferProcessor* bp ) |
| 1589 |
{ |
| 1590 |
return (bp->framesInTempOutputBuffer) ? 0 : 1; |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, |
| 1595 |
void **buffer, unsigned long frameCount ) |
| 1596 |
{ |
| 1597 |
PaUtilChannelDescriptor *hostInputChannels; |
| 1598 |
unsigned int framesToCopy; |
| 1599 |
unsigned char *destBytePtr; |
| 1600 |
void **nonInterleavedDestPtrs; |
| 1601 |
unsigned int destSampleStrideSamples; |
| 1602 |
unsigned int destChannelStrideBytes; |
| 1603 |
unsigned int i; |
| 1604 |
|
| 1605 |
hostInputChannels = bp->hostInputChannels[0]; |
| 1606 |
framesToCopy = PA_MIN_( bp->hostInputFrameCount[0], frameCount ); |
| 1607 |
|
| 1608 |
if( bp->userInputIsInterleaved ) |
| 1609 |
{ |
| 1610 |
destBytePtr = (unsigned char*)*buffer; |
| 1611 |
|
| 1612 |
destSampleStrideSamples = bp->inputChannelCount; |
| 1613 |
destChannelStrideBytes = bp->bytesPerUserInputSample; |
| 1614 |
|
| 1615 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 1616 |
{ |
| 1617 |
bp->inputConverter( destBytePtr, destSampleStrideSamples, |
| 1618 |
hostInputChannels[i].data, |
| 1619 |
hostInputChannels[i].stride, |
| 1620 |
framesToCopy, &bp->ditherGenerator ); |
| 1621 |
|
| 1622 |
destBytePtr += destChannelStrideBytes; |
| 1623 |
|
| 1624 |
|
| 1625 |
hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + |
| 1626 |
framesToCopy * hostInputChannels[i].stride * bp->bytesPerHostInputSample; |
| 1627 |
} |
| 1628 |
|
| 1629 |
|
| 1630 |
*buffer = ((unsigned char *)*buffer) + |
| 1631 |
framesToCopy * bp->inputChannelCount * bp->bytesPerUserInputSample; |
| 1632 |
} |
| 1633 |
else |
| 1634 |
{ |
| 1635 |
|
| 1636 |
|
| 1637 |
nonInterleavedDestPtrs = (void**)*buffer; |
| 1638 |
|
| 1639 |
destSampleStrideSamples = 1; |
| 1640 |
|
| 1641 |
for( i=0; i<bp->inputChannelCount; ++i ) |
| 1642 |
{ |
| 1643 |
destBytePtr = (unsigned char*)nonInterleavedDestPtrs[i]; |
| 1644 |
|
| 1645 |
bp->inputConverter( destBytePtr, destSampleStrideSamples, |
| 1646 |
hostInputChannels[i].data, |
| 1647 |
hostInputChannels[i].stride, |
| 1648 |
framesToCopy, &bp->ditherGenerator ); |
| 1649 |
|
| 1650 |
|
| 1651 |
destBytePtr += bp->bytesPerUserInputSample * framesToCopy; |
| 1652 |
nonInterleavedDestPtrs[i] = destBytePtr; |
| 1653 |
|
| 1654 |
|
| 1655 |
hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + |
| 1656 |
framesToCopy * hostInputChannels[i].stride * bp->bytesPerHostInputSample; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
|
| 1660 |
bp->hostInputFrameCount[0] -= framesToCopy; |
| 1661 |
|
| 1662 |
return framesToCopy; |
| 1663 |
} |
| 1664 |
|
| 1665 |
unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bp, |
| 1666 |
const void ** buffer, unsigned long frameCount ) |
| 1667 |
{ |
| 1668 |
PaUtilChannelDescriptor *hostOutputChannels; |
| 1669 |
unsigned int framesToCopy; |
| 1670 |
unsigned char *srcBytePtr; |
| 1671 |
void **nonInterleavedSrcPtrs; |
| 1672 |
unsigned int srcSampleStrideSamples; |
| 1673 |
unsigned int srcChannelStrideBytes; |
| 1674 |
unsigned int i; |
| 1675 |
|
| 1676 |
hostOutputChannels = bp->hostOutputChannels[0]; |
| 1677 |
framesToCopy = PA_MIN_( bp->hostOutputFrameCount[0], frameCount ); |
| 1678 |
|
| 1679 |
if( bp->userOutputIsInterleaved ) |
| 1680 |
{ |
| 1681 |
srcBytePtr = (unsigned char*)*buffer; |
| 1682 |
|
| 1683 |
srcSampleStrideSamples = bp->outputChannelCount; |
| 1684 |
srcChannelStrideBytes = bp->bytesPerUserOutputSample; |
| 1685 |
|
| 1686 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1687 |
{ |
| 1688 |
bp->outputConverter( hostOutputChannels[i].data, |
| 1689 |
hostOutputChannels[i].stride, |
| 1690 |
srcBytePtr, srcSampleStrideSamples, |
| 1691 |
framesToCopy, &bp->ditherGenerator ); |
| 1692 |
|
| 1693 |
srcBytePtr += srcChannelStrideBytes; |
| 1694 |
|
| 1695 |
|
| 1696 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1697 |
framesToCopy * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1698 |
} |
| 1699 |
|
| 1700 |
|
| 1701 |
*buffer = ((unsigned char *)*buffer) + |
| 1702 |
framesToCopy * bp->outputChannelCount * bp->bytesPerUserOutputSample; |
| 1703 |
|
| 1704 |
} |
| 1705 |
else |
| 1706 |
{ |
| 1707 |
|
| 1708 |
|
| 1709 |
nonInterleavedSrcPtrs = (void**)*buffer; |
| 1710 |
|
| 1711 |
srcSampleStrideSamples = 1; |
| 1712 |
|
| 1713 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1714 |
{ |
| 1715 |
srcBytePtr = (unsigned char*)nonInterleavedSrcPtrs[i]; |
| 1716 |
|
| 1717 |
bp->outputConverter( hostOutputChannels[i].data, |
| 1718 |
hostOutputChannels[i].stride, |
| 1719 |
srcBytePtr, srcSampleStrideSamples, |
| 1720 |
framesToCopy, &bp->ditherGenerator ); |
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
srcBytePtr += bp->bytesPerUserOutputSample * framesToCopy; |
| 1725 |
nonInterleavedSrcPtrs[i] = srcBytePtr; |
| 1726 |
|
| 1727 |
|
| 1728 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1729 |
framesToCopy * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1730 |
} |
| 1731 |
} |
| 1732 |
|
| 1733 |
bp->hostOutputFrameCount[0] += framesToCopy; |
| 1734 |
|
| 1735 |
return framesToCopy; |
| 1736 |
} |
| 1737 |
|
| 1738 |
|
| 1739 |
unsigned long PaUtil_ZeroOutput( PaUtilBufferProcessor* bp, unsigned long frameCount ) |
| 1740 |
{ |
| 1741 |
PaUtilChannelDescriptor *hostOutputChannels; |
| 1742 |
unsigned int framesToZero; |
| 1743 |
unsigned int i; |
| 1744 |
|
| 1745 |
hostOutputChannels = bp->hostOutputChannels[0]; |
| 1746 |
framesToZero = PA_MIN_( bp->hostOutputFrameCount[0], frameCount ); |
| 1747 |
|
| 1748 |
for( i=0; i<bp->outputChannelCount; ++i ) |
| 1749 |
{ |
| 1750 |
bp->outputZeroer( hostOutputChannels[i].data, |
| 1751 |
hostOutputChannels[i].stride, |
| 1752 |
framesToZero ); |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + |
| 1757 |
framesToZero * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; |
| 1758 |
} |
| 1759 |
|
| 1760 |
bp->hostOutputFrameCount[0] += framesToZero; |
| 1761 |
|
| 1762 |
return framesToZero; |
| 1763 |
} |