Skip to content

Commit 96dedbd

Browse files
authored
Test long recording for stalls (#1075)
You may want to use an explicit device instead of the default. This will print the number of seconds every 10 seconds. If it stalls it will probably print an error. For #930 and #1074
1 parent d1493dc commit 96dedbd

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ TESTS = \
104104
bin/patest_latency \
105105
bin/patest_leftright \
106106
bin/patest_longsine \
107+
bin/patest_long_record \
107108
bin/patest_many \
108109
bin/patest_maxsines \
109110
bin/patest_mono \

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if(PA_USE_WASAPI)
2626
endif()
2727
add_test(patest_latency)
2828
add_test(patest_leftright)
29+
add_test(patest_long_record)
2930
add_test(patest_longsine)
3031
add_test(patest_many)
3132
add_test(patest_maxsines)

test/patest_long_record.c

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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

Comments
 (0)