~ubuntu-branches/debian/sid/flightgear/sid

« back to all changes in this revision

Viewing changes to 3rdparty/iaxclient/lib/portaudio/test/patest_underflow.c

  • Committer: Package Import Robot
  • Author(s): Markus Wanner, Markus Wanner, Rebecca Palmer
  • Date: 2014-01-21 22:31:02 UTC
  • mfrom: (1.3.1) (15.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140121223102-cjw7g9le25acd119
Tags: 3.0.0~git20140204+c99ea4-1
[ Markus Wanner ]
* Upload to unstable.
* Adjust B-D to allow building on kfreebsd-*. Closes: #724686.
* Add a lintian-overrides on autotools; we use cmake.
* Upstream corrected the fgfs manpage. Closes: #556362.
* Drop unnecessary man page for gl-info. Closes: #698308.
* Drop README.Linux: it's outdated to the point of uselessness.
  Closes: #574173.
* Add an upper limit of libsimgear-dev versions that flightgear can be
  built with. Closes: #738436.
* Drop the libsvn-dev dependency, neither flightgear nor simgear depend
  on libsvn, anymore. Closes: #682947.
* List icons in debian/install rather than copying around from rules.
* Update menu entry for flightgear, add one for fgcom; add .xpm icons.
  Closes: #713924.
* flightgear.desktop: add German translation
* Bump Standards-Version to 3.9.5; no changes needed.

[ Rebecca Palmer ]
* New upstream release.
* Install the icons (based on code by Saikrishna Arcot).  (Not a
  complete fix for LP908153 as it only sets the menu/Dash icon, not the
  running window's icon, but better than nothing).
* Disable screensaver while running. Closes: LP#793599. Add required
  libdbus-1-dev dependency.
* Remove outdated README.Debian.
* Terrasync now works after just ticking the box. Closes: #252899.
* Always set Terrasync directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file patest_underflow.c
 
2
        @brief Simulate an output buffer underflow condition.
 
3
        Tests whether the stream can be stopped when underflowing buffers.
 
4
        @author Ross Bencina <rossb@audiomulch.com>
 
5
        @author Phil Burk <philburk@softsynth.com>
 
6
*/
 
7
/*
 
8
 * $Id: patest_underflow.c,v 1.1 2006/06/10 21:30:57 dmazzoni Exp $
 
9
 *
 
10
 * This program uses the PortAudio Portable Audio Library.
 
11
 * For more information see: http://www.audiomulch.com/portaudio/
 
12
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
 
13
 *
 
14
 * Permission is hereby granted, free of charge, to any person obtaining
 
15
 * a copy of this software and associated documentation files
 
16
 * (the "Software"), to deal in the Software without restriction,
 
17
 * including without limitation the rights to use, copy, modify, merge,
 
18
 * publish, distribute, sublicense, and/or sell copies of the Software,
 
19
 * and to permit persons to whom the Software is furnished to do so,
 
20
 * subject to the following conditions:
 
21
 *
 
22
 * The above copyright notice and this permission notice shall be
 
23
 * included in all copies or substantial portions of the Software.
 
24
 *
 
25
 * Any person wishing to distribute modifications to the Software is
 
26
 * requested to send the modifications to the original developer so that
 
27
 * they can be incorporated into the canonical version.
 
28
 *
 
29
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
30
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
31
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
32
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 
33
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 
34
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
35
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
36
 *
 
37
 */
 
38
#include <stdio.h>
 
39
#include <math.h>
 
40
#include "portaudio.h"
 
41
 
 
42
#define NUM_SECONDS   (20)
 
43
#define SAMPLE_RATE   (44100)
 
44
#define FRAMES_PER_BUFFER  (2048)
 
45
#define MSEC_PER_BUFFER  ( (FRAMES_PER_BUFFER * 1000) / SAMPLE_RATE )
 
46
 
 
47
#ifndef M_PI
 
48
#define M_PI  (3.14159265)
 
49
#endif
 
50
 
 
51
#define TABLE_SIZE   (200)
 
52
typedef struct
 
53
{
 
54
    float sine[TABLE_SIZE];
 
55
    int left_phase;
 
56
    int right_phase;
 
57
    int sleepTime;
 
58
}
 
59
paTestData;
 
60
 
 
61
/* This routine will be called by the PortAudio engine when audio is needed.
 
62
** It may called at interrupt level on some machines so don't do anything
 
63
** that could mess up the system like calling malloc() or free().
 
64
*/
 
65
static int patestCallback( const void *inputBuffer, void *outputBuffer,
 
66
                           unsigned long framesPerBuffer,
 
67
                           const PaStreamCallbackTimeInfo* timeInfo,
 
68
                           PaStreamCallbackFlags statusFlags,
 
69
                           void *userData )
 
70
{
 
71
    paTestData *data = (paTestData*)userData;
 
72
    float *out = (float*)outputBuffer;
 
73
    unsigned long i;
 
74
    int finished = 0;
 
75
    (void) inputBuffer; /* Prevent unused variable warnings. */
 
76
    for( i=0; i<framesPerBuffer; i++ )
 
77
    {
 
78
        *out++ = data->sine[data->left_phase];  /* left */
 
79
        *out++ = data->sine[data->right_phase];  /* right */
 
80
        data->left_phase += 1;
 
81
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
 
82
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
 
83
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
 
84
    }
 
85
 
 
86
    /* Cause underflow to occur. */
 
87
    if( data->sleepTime > 0 ) Pa_Sleep( data->sleepTime );
 
88
    data->sleepTime += 1;
 
89
 
 
90
    return finished;
 
91
}
 
92
 
 
93
/*******************************************************************/
 
94
int main(void);
 
95
int main(void)
 
96
{
 
97
    PaStreamParameters outputParameters;
 
98
    PaStream *stream;
 
99
    PaError err;
 
100
    paTestData data;
 
101
    int i;
 
102
    printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
 
103
    /* initialise sinusoidal wavetable */
 
104
    for( i=0; i<TABLE_SIZE; i++ )
 
105
    {
 
106
        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
 
107
    }
 
108
    data.left_phase = data.right_phase = data.sleepTime = 0;
 
109
    err = Pa_Initialize();
 
110
    if( err != paNoError ) goto error;
 
111
    
 
112
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
 
113
    outputParameters.channelCount = 2;       /* stereo output */
 
114
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
 
115
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
 
116
    outputParameters.hostApiSpecificStreamInfo = NULL;
 
117
    err = Pa_OpenStream(
 
118
              &stream,
 
119
              NULL, /* no input */
 
120
              &outputParameters,
 
121
              SAMPLE_RATE,
 
122
              FRAMES_PER_BUFFER,
 
123
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
 
124
              patestCallback,
 
125
              &data );
 
126
    if( err != paNoError ) goto error;
 
127
    err = Pa_StartStream( stream );
 
128
    if( err != paNoError ) goto error;
 
129
 
 
130
    while( data.sleepTime < (2 * MSEC_PER_BUFFER) )
 
131
    {
 
132
        printf("SleepTime = %d\n", data.sleepTime );
 
133
        Pa_Sleep( data.sleepTime );
 
134
    }
 
135
 
 
136
    printf("Try to stop stream.\n");
 
137
    err = Pa_StopStream( stream );
 
138
    if( err != paNoError ) goto error;
 
139
    err = Pa_CloseStream( stream );
 
140
    if( err != paNoError ) goto error;
 
141
    Pa_Terminate();
 
142
    printf("Test finished.\n");
 
143
    return err;
 
144
error:
 
145
    Pa_Terminate();
 
146
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
 
147
    fprintf( stderr, "Error number: %d\n", err );
 
148
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
 
149
    return err;
 
150
}