PortAudio  2.0
pa_process.h
Go to the documentation of this file.
1 #ifndef PA_PROCESS_H
2 #define PA_PROCESS_H
3 /*
4  * $Id$
5  * Portable Audio I/O Library callback buffer processing adapters
6  *
7  * Based on the Open Source API proposed by Ross Bencina
8  * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files
12  * (the "Software"), to deal in the Software without restriction,
13  * including without limitation the rights to use, copy, modify, merge,
14  * publish, distribute, sublicense, and/or sell copies of the Software,
15  * and to permit persons to whom the Software is furnished to do so,
16  * subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
25  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 /*
31  * The text above constitutes the entire PortAudio license; however,
32  * the PortAudio community also makes the following non-binding requests:
33  *
34  * Any person wishing to distribute modifications to the Software is
35  * requested to send the modifications to the original developer so that
36  * they can be incorporated into the canonical version. It is also
37  * requested that these non-binding requests be included along with the
38  * license above.
39  */
40 
203 #include "portaudio.h"
204 #include "pa_converters.h"
205 #include "pa_dither.h"
206 
207 #ifdef __cplusplus
208 extern "C"
209 {
210 #endif /* __cplusplus */
211 
212 
219 typedef enum {
222 
225 
228 
238 
239 
242 typedef struct PaUtilChannelDescriptor{
243  void *data;
244  unsigned int stride;
246 
247 
253 typedef struct {
254  unsigned long framesPerUserBuffer;
255  unsigned long framesPerHostBuffer;
256 
261  unsigned long framesPerTempBuffer;
262 
263  unsigned int inputChannelCount;
269 
270  unsigned int outputChannelCount;
276 
279 
282  unsigned long framesInTempInputBuffer;
286  unsigned long framesInTempOutputBuffer;
289 
291 
293  unsigned long hostInputFrameCount[2];
294  PaUtilChannelDescriptor *hostInputChannels[2];
300  unsigned long hostOutputFrameCount[2];
301  PaUtilChannelDescriptor *hostOutputChannels[2];
308 
309  double samplePeriod;
310 
312  void *userData;
314 
315 
318 
378  int inputChannelCount, PaSampleFormat userInputSampleFormat,
379  PaSampleFormat hostInputSampleFormat,
380  int outputChannelCount, PaSampleFormat userOutputSampleFormat,
381  PaSampleFormat hostOutputSampleFormat,
382  double sampleRate,
383  PaStreamFlags streamFlags,
384  unsigned long framesPerUserBuffer, /* 0 indicates don't care */
385  unsigned long framesPerHostBuffer,
386  PaUtilHostBufferSizeMode hostBufferSizeMode,
387  PaStreamCallback *streamCallback, void *userData );
388 
389 
398 
399 
406 void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bufferProcessor );
407 
408 
418 
428 
438 
439 
451 void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bufferProcessor,
452  unsigned long frameCount );
453 
454 
462 void PaUtil_SetNoInput( PaUtilBufferProcessor* bufferProcessor );
463 
464 
474 void PaUtil_SetInputChannel( PaUtilBufferProcessor* bufferProcessor,
475  unsigned int channel, void *data, unsigned int stride );
476 
477 
489  unsigned int firstChannel, void *data, unsigned int channelCount );
490 
491 
500  unsigned int channel, void *data );
501 
502 
507  unsigned long frameCount );
508 
512 void PaUtil_Set2ndInputChannel( PaUtilBufferProcessor* bufferProcessor,
513  unsigned int channel, void *data, unsigned int stride );
514 
519  unsigned int firstChannel, void *data, unsigned int channelCount );
520 
525  unsigned int channel, void *data );
526 
527 
540  unsigned long frameCount );
541 
542 
548 void PaUtil_SetNoOutput( PaUtilBufferProcessor* bufferProcessor );
549 
550 
560 void PaUtil_SetOutputChannel( PaUtilBufferProcessor* bufferProcessor,
561  unsigned int channel, void *data, unsigned int stride );
562 
563 
575  unsigned int firstChannel, void *data, unsigned int channelCount );
576 
577 
586  unsigned int channel, void *data );
587 
588 
593  unsigned long frameCount );
594 
599  unsigned int channel, void *data, unsigned int stride );
600 
605  unsigned int firstChannel, void *data, unsigned int channelCount );
606 
611  unsigned int channel, void *data );
612 
619 
633  PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags callbackStatusFlags );
634 
635 
659 unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bufferProcessor,
660  int *callbackResult );
661 
662 
675 
682 
704 unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bufferProcessor,
705  void **buffer, unsigned long frameCount );
706 
707 
708 /* Copy samples from a user supplied buffer to host output channels set up by
709  the PaUtil_Set*OutputChannels functions. This function is intended for use with
710  blocking read/write streams. Copies the minimum of the number of
711  user frames (specified by the frameCount parameter) and the number of
712  host frames (specified in a previous call to SetOutputFrameCount()).
713 
714  @param bufferProcessor The buffer processor.
715 
716  @param buffer A pointer to the user buffer pointer, or a pointer to a pointer
717  to an array of user buffer pointers for a non-interleaved stream. It is
718  important that this parameter points to a copy of the user buffer pointers,
719  not to the actual user buffer pointers, because this function updates the
720  pointers before returning.
721 
722  @param frameCount The number of frames of data in the buffer(s) pointed to by
723  the buffer parameter.
724 
725  @return The number of frames copied. The buffer pointer(s) pointed to by the
726  buffer parameter are advanced to point to the frame(s) following the last one
727  copied.
728 */
729 unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bufferProcessor,
730  const void ** buffer, unsigned long frameCount );
731 
732 
733 /* Zero samples in host output channels set up by the PaUtil_Set*OutputChannels
734  functions. This function is useful for flushing streams.
735  Zeros the minimum of frameCount and the number of host frames specified in a
736  previous call to SetOutputFrameCount().
737 
738  @param bufferProcessor The buffer processor.
739 
740  @param frameCount The maximum number of frames to zero.
741 
742  @return The number of frames zeroed.
743 */
744 unsigned long PaUtil_ZeroOutput( PaUtilBufferProcessor* bufferProcessor,
745  unsigned long frameCount );
746 
747 
751 #ifdef __cplusplus
752 }
753 #endif /* __cplusplus */
754 #endif /* PA_PROCESS_H */
Conversion functions used to convert buffers of samples from one format to another.
unsigned long initialFramesInTempOutputBuffer
Definition: pa_process.h:278
unsigned int bytesPerHostOutputSample
Definition: pa_process.h:271
PaUtilZeroer * outputZeroer
Definition: pa_process.h:275
void PaUtil_SetNonInterleavedOutputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data)
Definition: pa_process.c:609
unsigned long PaUtil_EndBufferProcessing(PaUtilBufferProcessor *bp, int *streamCallbackResult)
Definition: pa_process.c:1484
void * tempInputBuffer
Definition: pa_process.h:280
unsigned int inputChannelCount
Definition: pa_process.h:263
unsigned int bytesPerUserInputSample
Definition: pa_process.h:265
unsigned long PaUtil_ZeroOutput(PaUtilBufferProcessor *bp, unsigned long frameCount)
Definition: pa_process.c:1807
void PaUtil_SetOutputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data, unsigned int stride)
Definition: pa_process.c:576
void PaUtil_Set2ndInterleavedOutputChannels(PaUtilBufferProcessor *bp, unsigned int firstChannel, void *data, unsigned int channelCount)
Definition: pa_process.c:637
void PaUtil_SetNoInput(PaUtilBufferProcessor *bp)
Definition: pa_process.c:453
unsigned long framesInTempOutputBuffer
Definition: pa_process.h:286
void ** tempInputBufferPtrs
Definition: pa_process.h:281
unsigned long framesPerHostBuffer
Definition: pa_process.h:255
int PaUtil_IsBufferProcessorOutputEmpty(PaUtilBufferProcessor *bp)
Definition: pa_process.c:1656
An auxilliary data structure used internally by the buffer processor to represent host input and outp...
Definition: pa_process.h:242
PaUtilConverter * inputConverter
Definition: pa_process.h:267
Definition: pa_process.h:221
PaStreamCallback * streamCallback
Definition: pa_process.h:311
void PaUtil_Set2ndInputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data, unsigned int stride)
Definition: pa_process.c:512
void PaUtil_Set2ndNonInterleavedInputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data)
Definition: pa_process.c:545
unsigned long framesInTempInputBuffer
Definition: pa_process.h:282
struct PaUtilChannelDescriptor PaUtilChannelDescriptor
An auxilliary data structure used internally by the buffer processor to represent host input and outp...
int userOutputSampleFormatIsEqualToHost
Definition: pa_process.h:259
PaStreamCallbackFlags callbackStatusFlags
Definition: pa_process.h:290
int PaStreamCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
Definition: portaudio.h:830
void PaUtil_SetInputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data, unsigned int stride)
Definition: pa_process.c:461
PaUtilTriangularDitherGenerator ditherGenerator
Definition: pa_process.h:307
unsigned int bytesPerHostInputSample
Definition: pa_process.h:264
void PaUtil_SetInterleavedInputChannels(PaUtilBufferProcessor *bp, unsigned int firstChannel, void *data, unsigned int channelCount)
Definition: pa_process.c:471
void PaUtil_ResetBufferProcessor(PaUtilBufferProcessor *bp)
Definition: pa_process.c:408
int hostOutputIsInterleaved
Definition: pa_process.h:299
void PaUtil_Set2ndNonInterleavedOutputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data)
Definition: pa_process.c:659
unsigned int outputChannelCount
Definition: pa_process.h:270
The portable PortAudio API.
PaUtilZeroer * inputZeroer
Definition: pa_process.h:268
void ** tempOutputBufferPtrs
Definition: pa_process.h:285
void PaUtilConverter(void *destinationBuffer, signed int destinationStride, void *sourceBuffer, signed int sourceStride, unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator)
Definition: pa_converters.h:90
void * data
Definition: pa_process.h:243
unsigned int bytesPerUserOutputSample
Definition: pa_process.h:272
unsigned long PaUtil_CopyInput(PaUtilBufferProcessor *bp, void **buffer, unsigned long frameCount)
Definition: pa_process.c:1662
void PaUtil_Set2ndOutputFrameCount(PaUtilBufferProcessor *bp, unsigned long frameCount)
Definition: pa_process.c:619
void PaUtil_Set2ndInputFrameCount(PaUtilBufferProcessor *bp, unsigned long frameCount)
Definition: pa_process.c:505
void PaUtil_SetOutputFrameCount(PaUtilBufferProcessor *bp, unsigned long frameCount)
Definition: pa_process.c:556
unsigned long PaStreamFlags
Definition: portaudio.h:653
PaUtilHostBufferSizeMode hostBufferSizeMode
Definition: pa_process.h:257
int PaError
Definition: portaudio.h:121
void PaUtil_SetInterleavedOutputChannels(PaUtilBufferProcessor *bp, unsigned int firstChannel, void *data, unsigned int channelCount)
Definition: pa_process.c:587
unsigned long PaStreamCallbackFlags
Definition: portaudio.h:712
void PaUtil_SetNoOutput(PaUtilBufferProcessor *bp)
Definition: pa_process.c:566
void PaUtil_BeginBufferProcessing(PaUtilBufferProcessor *bp, PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags callbackStatusFlags)
Definition: pa_process.c:669
PaError PaUtil_InitializeBufferProcessor(PaUtilBufferProcessor *bp, int inputChannelCount, PaSampleFormat userInputSampleFormat, PaSampleFormat hostInputSampleFormat, int outputChannelCount, PaSampleFormat userOutputSampleFormat, PaSampleFormat hostOutputSampleFormat, double sampleRate, PaStreamFlags streamFlags, unsigned long framesPerUserBuffer, unsigned long framesPerHostBuffer, PaUtilHostBufferSizeMode hostBufferSizeMode, PaStreamCallback *streamCallback, void *userData)
Definition: pa_process.c:90
unsigned long framesPerUserBuffer
Definition: pa_process.h:254
unsigned long initialFramesInTempInputBuffer
Definition: pa_process.h:277
unsigned long PaSampleFormat
Definition: portaudio.h:484
Definition: pa_process.h:224
PaUtilHostBufferSizeMode
Mode flag passed to PaUtil_InitializeBufferProcessor indicating the type of buffering that the host A...
Definition: pa_process.h:219
void PaUtil_Set2ndOutputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data, unsigned int stride)
Definition: pa_process.c:626
unsigned long PaUtil_CopyOutput(PaUtilBufferProcessor *bp, const void **buffer, unsigned long frameCount)
Definition: pa_process.c:1733
unsigned long framesPerTempBuffer
Definition: pa_process.h:261
Functions for generating dither noise.
char buffer[NUM_BYTES]
Definition: recplay.c:26
int userInputIsInterleaved
Definition: pa_process.h:266
unsigned long PaUtil_GetBufferProcessorOutputLatencyFrames(PaUtilBufferProcessor *bp)
Definition: pa_process.c:437
void * tempOutputBuffer
Definition: pa_process.h:284
int userInputSampleFormatIsEqualToHost
Definition: pa_process.h:260
void PaUtil_Set2ndInterleavedInputChannels(PaUtilBufferProcessor *bp, unsigned int firstChannel, void *data, unsigned int channelCount)
Definition: pa_process.c:522
The main buffer processor data structure.
Definition: pa_process.h:253
double samplePeriod
Definition: pa_process.h:309
int useNonAdaptingProcess
Definition: pa_process.h:258
unsigned int stride
Definition: pa_process.h:244
State needed to generate a dither signal.
Definition: pa_dither.h:61
PaStreamCallbackTimeInfo * timeInfo
Definition: pa_process.h:288
unsigned long PaUtil_GetBufferProcessorInputLatencyFrames(PaUtilBufferProcessor *bp)
Definition: pa_process.c:431
void PaUtil_SetNonInterleavedInputChannel(PaUtilBufferProcessor *bp, unsigned int channel, void *data)
Definition: pa_process.c:494
void PaUtilZeroer(void *destinationBuffer, signed int destinationStride, unsigned int count)
Definition: pa_converters.h:119
void PaUtil_SetInputFrameCount(PaUtilBufferProcessor *bp, unsigned long frameCount)
Definition: pa_process.c:443
int userOutputIsInterleaved
Definition: pa_process.h:273
PaUtilConverter * outputConverter
Definition: pa_process.h:274
void PaUtil_TerminateBufferProcessor(PaUtilBufferProcessor *bp)
Definition: pa_process.c:386
Definition: pa_process.h:227
int hostInputIsInterleaved
Definition: pa_process.h:292
void * userData
Definition: pa_process.h:312
Definition: portaudio.h:699