annotate src/portaudio/pablio/test_rw.c @ 25:7c42c2fc4173

Add Vamp SDK for OS/X
author Chris Cannam
date Thu, 09 Jan 2014 09:17:21 +0000
parents e13257ea84a4
children
rev   line source
Chris@4 1 /*
Chris@4 2 * $Id: test_rw.c 1083 2006-08-23 07:30:49Z rossb $
Chris@4 3 * test_rw.c
Chris@4 4 * Read input from one stream and write it to another.
Chris@4 5 *
Chris@4 6 * Author: Phil Burk, http://www.softsynth.com/portaudio/
Chris@4 7 *
Chris@4 8 * This program uses PABLIO, the Portable Audio Blocking I/O Library.
Chris@4 9 * PABLIO is built on top of PortAudio, the Portable Audio Library.
Chris@4 10 * For more information see: http://www.portaudio.com
Chris@4 11 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
Chris@4 12 *
Chris@4 13 * Permission is hereby granted, free of charge, to any person obtaining
Chris@4 14 * a copy of this software and associated documentation files
Chris@4 15 * (the "Software"), to deal in the Software without restriction,
Chris@4 16 * including without limitation the rights to use, copy, modify, merge,
Chris@4 17 * publish, distribute, sublicense, and/or sell copies of the Software,
Chris@4 18 * and to permit persons to whom the Software is furnished to do so,
Chris@4 19 * subject to the following conditions:
Chris@4 20 *
Chris@4 21 * The above copyright notice and this permission notice shall be
Chris@4 22 * included in all copies or substantial portions of the Software.
Chris@4 23 *
Chris@4 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@4 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@4 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chris@4 27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
Chris@4 28 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@4 29 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@4 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@4 31 */
Chris@4 32
Chris@4 33 /*
Chris@4 34 * The text above constitutes the entire PortAudio license; however,
Chris@4 35 * the PortAudio community also makes the following non-binding requests:
Chris@4 36 *
Chris@4 37 * Any person wishing to distribute modifications to the Software is
Chris@4 38 * requested to send the modifications to the original developer so that
Chris@4 39 * they can be incorporated into the canonical version. It is also
Chris@4 40 * requested that these non-binding requests be included along with the
Chris@4 41 * license above.
Chris@4 42 */
Chris@4 43
Chris@4 44 #include <stdio.h>
Chris@4 45 #include <stdlib.h>
Chris@4 46 #include "pablio.h"
Chris@4 47
Chris@4 48 /*
Chris@4 49 ** Note that many of the older ISA sound cards on PCs do NOT support
Chris@4 50 ** full duplex audio (simultaneous record and playback).
Chris@4 51 ** And some only support full duplex at lower sample rates.
Chris@4 52 */
Chris@4 53 #define SAMPLE_RATE (44100)
Chris@4 54 #define NUM_SECONDS (5)
Chris@4 55 #define SAMPLES_PER_FRAME (2)
Chris@4 56 #define FRAMES_PER_BLOCK (64)
Chris@4 57
Chris@4 58 /* Select whether we will use floats or shorts. */
Chris@4 59 #if 1
Chris@4 60 #define SAMPLE_TYPE paFloat32
Chris@4 61 typedef float SAMPLE;
Chris@4 62 #else
Chris@4 63 #define SAMPLE_TYPE paInt16
Chris@4 64 typedef short SAMPLE;
Chris@4 65 #endif
Chris@4 66
Chris@4 67 /*******************************************************************/
Chris@4 68 int main(void);
Chris@4 69 int main(void)
Chris@4 70 {
Chris@4 71 int i;
Chris@4 72 SAMPLE samples[SAMPLES_PER_FRAME * FRAMES_PER_BLOCK];
Chris@4 73 PaError err;
Chris@4 74 PABLIO_Stream *aStream;
Chris@4 75
Chris@4 76 printf("Full duplex sound test using PortAudio and RingBuffers\n");
Chris@4 77 fflush(stdout);
Chris@4 78
Chris@4 79 /* Open simplified blocking I/O layer on top of PortAudio. */
Chris@4 80 err = OpenAudioStream( &aStream, SAMPLE_RATE, SAMPLE_TYPE,
Chris@4 81 (PABLIO_READ_WRITE | PABLIO_STEREO) );
Chris@4 82 if( err != paNoError ) goto error;
Chris@4 83
Chris@4 84 /* Process samples in the foreground. */
Chris@4 85 for( i=0; i<(NUM_SECONDS * SAMPLE_RATE); i += FRAMES_PER_BLOCK )
Chris@4 86 {
Chris@4 87 /* Read one block of data into sample array from audio input. */
Chris@4 88 ReadAudioStream( aStream, samples, FRAMES_PER_BLOCK );
Chris@4 89 /* Write that same block of data to output. */
Chris@4 90 WriteAudioStream( aStream, samples, FRAMES_PER_BLOCK );
Chris@4 91 }
Chris@4 92
Chris@4 93 CloseAudioStream( aStream );
Chris@4 94
Chris@4 95 printf("Full duplex sound test complete.\n" );
Chris@4 96 fflush(stdout);
Chris@4 97 return 0;
Chris@4 98
Chris@4 99 error:
Chris@4 100 Pa_Terminate();
Chris@4 101 fprintf( stderr, "An error occured while using the portaudio stream\n" );
Chris@4 102 fprintf( stderr, "Error number: %d\n", err );
Chris@4 103 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
Chris@4 104 return -1;
Chris@4 105 }