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

« back to all changes in this revision

Viewing changes to 3rdparty/iaxclient/lib/portaudio/test/patest_leftright.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_leftright.c
 
2
        @brief Play different tone sine waves that 
 
3
                alternate between left and right channel.
 
4
 
 
5
        The low tone should be on the left channel.
 
6
 
 
7
        @author Ross Bencina <rossb@audiomulch.com>
 
8
        @author Phil Burk <philburk@softsynth.com>
 
9
*/
 
10
/*
 
11
 * $Id: patest_leftright.c,v 1.1 2006/06/10 21:30:56 dmazzoni Exp $
 
12
 *
 
13
 * This program uses the PortAudio Portable Audio Library.
 
14
 * For more information see: http://www.audiomulch.com/portaudio/
 
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
 * Any person wishing to distribute modifications to the Software is
 
29
 * requested to send the modifications to the original developer so that
 
30
 * they can be incorporated into the canonical version.
 
31
 *
 
32
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
33
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
34
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
35
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 
36
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 
37
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
38
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
39
 *
 
40
 */
 
41
#include <stdio.h>
 
42
#include <math.h>
 
43
#include "portaudio.h"
 
44
 
 
45
#define NUM_SECONDS   (8)
 
46
#define SAMPLE_RATE   (44100)
 
47
#define FRAMES_PER_BUFFER  (512)
 
48
#ifndef M_PI
 
49
#define M_PI  (3.14159265)
 
50
#endif
 
51
#define TABLE_SIZE   (200)
 
52
typedef struct
 
53
{
 
54
    float sine[TABLE_SIZE];
 
55
    int left_phase;
 
56
    int right_phase;
 
57
    int toggle;
 
58
    int countDown;
 
59
}
 
60
paTestData;
 
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,
 
66
                           void *outputBuffer,
 
67
                           unsigned long framesPerBuffer,
 
68
                           const PaStreamCallbackTimeInfo* timeInfo,
 
69
                           PaStreamCallbackFlags statusFlags,
 
70
                           void *userData )
 
71
{
 
72
    paTestData *data = (paTestData*)userData;
 
73
    float *out = (float*)outputBuffer;
 
74
    unsigned long i;
 
75
    int finished = 0;
 
76
    /* Prevent unused variable warnings. */
 
77
    (void) inputBuffer;
 
78
 
 
79
    for( i=0; i<framesPerBuffer; i++ )
 
80
    {
 
81
        if( data->toggle )
 
82
        {
 
83
            *out++ = data->sine[data->left_phase];  /* left */
 
84
            *out++ = 0;  /* right */
 
85
        }
 
86
        else
 
87
        {
 
88
            *out++ = 0;  /* left */
 
89
            *out++ = data->sine[data->right_phase];  /* right */
 
90
        }
 
91
 
 
92
        data->left_phase += 1;
 
93
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
 
94
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
 
95
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
 
96
    }
 
97
 
 
98
    if( data->countDown < 0 )
 
99
    {
 
100
        data->countDown = SAMPLE_RATE;
 
101
        data->toggle = !data->toggle;
 
102
    }
 
103
    data->countDown -= framesPerBuffer;
 
104
 
 
105
    return finished;
 
106
}
 
107
 
 
108
/*******************************************************************/
 
109
int main(void);
 
110
int main(void)
 
111
{
 
112
    PaStream *stream;
 
113
    PaStreamParameters outputParameters;
 
114
    PaError err;
 
115
    paTestData data;
 
116
    int i;
 
117
    int timeout;
 
118
    
 
119
    printf("Play different tone sine waves that alternate between left and right channel.\n");
 
120
    printf("The low tone should be on the left channel.\n");
 
121
    
 
122
    /* initialise sinusoidal wavetable */
 
123
    for( i=0; i<TABLE_SIZE; i++ )
 
124
    {
 
125
        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
 
126
    }
 
127
    data.left_phase = data.right_phase = data.toggle = 0;
 
128
    data.countDown = SAMPLE_RATE;
 
129
 
 
130
    err = Pa_Initialize();
 
131
    if( err != paNoError ) goto error;
 
132
 
 
133
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
 
134
    outputParameters.channelCount = 2;       /* stereo output */
 
135
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
 
136
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
 
137
    outputParameters.hostApiSpecificStreamInfo = NULL;
 
138
 
 
139
    err = Pa_OpenStream( &stream,
 
140
                         NULL,                  /* No input. */
 
141
                         &outputParameters,     /* As above. */
 
142
                         SAMPLE_RATE,
 
143
                         FRAMES_PER_BUFFER,
 
144
                         paClipOff,      /* we won't output out of range samples so don't bother clipping them */
 
145
                         patestCallback,
 
146
                         &data );
 
147
    if( err != paNoError ) goto error;
 
148
    
 
149
    err = Pa_StartStream( stream );
 
150
    if( err != paNoError ) goto error;
 
151
    
 
152
    printf("Play for several seconds.\n");
 
153
    timeout = NUM_SECONDS * 4;
 
154
    while( timeout > 0 )
 
155
    {
 
156
        Pa_Sleep( 300 );        /*(Irix very much likes sleeps <= 1000 ms.)*/
 
157
        timeout -= 1;
 
158
    }
 
159
 
 
160
    err = Pa_StopStream( stream );
 
161
    if( err != paNoError ) goto error;
 
162
    err = Pa_CloseStream( stream );
 
163
    if( err != paNoError ) goto error;
 
164
    Pa_Terminate();
 
165
    printf("Test finished.\n");
 
166
    return err;
 
167
error:
 
168
    Pa_Terminate();
 
169
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
 
170
    fprintf( stderr, "Error number: %d\n", err );
 
171
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
 
172
    return err;
 
173
}