|
| 1 | +/** @file patest_long_record.c |
| 2 | + @ingroup test_src |
| 3 | + @brief Test whether we can record for many hours without failing. |
| 4 | + @author Phil Burk http://www.softsynth.com |
| 5 | +*/ |
| 6 | +/* |
| 7 | + * $Id$ |
| 8 | + * |
| 9 | + * Authors: |
| 10 | + * Ross Bencina <rossb@audiomulch.com> |
| 11 | + * Phil Burk <philburk@mobileer.com> |
| 12 | + * |
| 13 | + * This program uses the PortAudio Portable Audio Library. |
| 14 | + * For more information see: http://www.portaudio.com |
| 15 | + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk |
| 16 | + * |
| 17 | + * Permission is hereby granted, free of charge, to any person obtaining |
| 18 | + * a copy of this software and associated documentation files |
| 19 | + * (the "Software"), to deal in the Software without restriction, |
| 20 | + * including without limitation the rights to use, copy, modify, merge, |
| 21 | + * publish, distribute, sublicense, and/or sell copies of the Software, |
| 22 | + * and to permit persons to whom the Software is furnished to do so, |
| 23 | + * subject to the following conditions: |
| 24 | + * |
| 25 | + * The above copyright notice and this permission notice shall be |
| 26 | + * included in all copies or substantial portions of the Software. |
| 27 | + * |
| 28 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 29 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 30 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 31 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 32 | + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 33 | + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 34 | + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 35 | + */ |
| 36 | + |
| 37 | +/* |
| 38 | + * The text above constitutes the entire PortAudio license; however, |
| 39 | + * the PortAudio community also makes the following non-binding requests: |
| 40 | + * |
| 41 | + * Any person wishing to distribute modifications to the Software is |
| 42 | + * requested to send the modifications to the original developer so that |
| 43 | + * they can be incorporated into the canonical version. It is also |
| 44 | + * requested that these non-binding requests be included along with the |
| 45 | + * license above. |
| 46 | + */ |
| 47 | + |
| 48 | +#include <stdio.h> |
| 49 | +#include <math.h> |
| 50 | +#include <stdint.h> |
| 51 | +#include "portaudio.h" |
| 52 | + |
| 53 | +static int64_t sCallbackCount = 0; |
| 54 | +// This callback will never be called again after a certain period of time |
| 55 | + |
| 56 | +static int listening( const void *inputBuffer, void *outputBuffer, |
| 57 | + unsigned long framesPerBuffer, |
| 58 | + const PaStreamCallbackTimeInfo* timeInfo, |
| 59 | + PaStreamCallbackFlags statusFlags, |
| 60 | + void *userData ) { |
| 61 | + (void) inputBuffer; |
| 62 | + (void) outputBuffer; |
| 63 | + (void) framesPerBuffer; |
| 64 | + (void) timeInfo; |
| 65 | + (void) statusFlags; |
| 66 | + (void) userData; |
| 67 | + sCallbackCount++; |
| 68 | + return paContinue; |
| 69 | +} |
| 70 | + |
| 71 | +int main ( int argc, char** argv ) { |
| 72 | + PaStream* stream = NULL; |
| 73 | + PaStreamParameters inputParameters; |
| 74 | + PaError err = 0; |
| 75 | + int loopCount = 0; |
| 76 | + int64_t previousCallbackCount = sCallbackCount; |
| 77 | + (void) argc; |
| 78 | + (void) argv; |
| 79 | + |
| 80 | + Pa_Initialize (); |
| 81 | + |
| 82 | + inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ |
| 83 | + printf("Recording using device #%d\n", inputParameters.device); |
| 84 | + inputParameters.channelCount = 1; |
| 85 | + inputParameters.sampleFormat = paInt16; |
| 86 | + inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; |
| 87 | + inputParameters.hostApiSpecificStreamInfo = NULL; |
| 88 | + |
| 89 | + err = Pa_OpenStream( |
| 90 | + &stream, |
| 91 | + &inputParameters, |
| 92 | + NULL, /* &outputParameters, */ |
| 93 | + 44100, |
| 94 | + 512, |
| 95 | + paClipOff, /* we won't output out of range samples so don't bother clipping them */ |
| 96 | + listening, /* callback */ |
| 97 | + NULL ); /* no callback userData */ |
| 98 | + if( err != paNoError ) { |
| 99 | + printf("Pa_OpenDefaultStream returned %d!\n", err); |
| 100 | + goto error2; |
| 101 | + } |
| 102 | + err = Pa_StartStream ( stream ); |
| 103 | + if( err != paNoError ) { |
| 104 | + printf("Pa_StartStream returned %d!\n", err); |
| 105 | + goto error1; |
| 106 | + } |
| 107 | + |
| 108 | + while ( Pa_IsStreamActive ( stream ) == 1 ) { |
| 109 | + Pa_Sleep ( 1000 ); |
| 110 | + |
| 111 | + if (previousCallbackCount == sCallbackCount) { |
| 112 | + printf("Callbacks stopped!\n"); |
| 113 | + goto error1; |
| 114 | + } |
| 115 | + previousCallbackCount = sCallbackCount; |
| 116 | + |
| 117 | + loopCount++; |
| 118 | + if ((loopCount % 10) == 0) { |
| 119 | + printf("%d loops\n", loopCount); |
| 120 | + } |
| 121 | + } |
| 122 | + printf("Stream no longer Active!"); |
| 123 | + |
| 124 | +error1: |
| 125 | + Pa_CloseStream ( stream ); |
| 126 | +error2: |
| 127 | + Pa_Terminate (); |
| 128 | + return 0; |
| 129 | +} |
0 commit comments