To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/sonic-visualiser/sv-dependency-builds .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / src / portaudio_20161030_catalina_patch / test / patest_sine_channelmaps.c @ 162:d43aab368df9

History | View | Annotate | Download (6.38 KB)

1
/*
2
 * patest_sine_channelmaps.c
3
 *
4
 * This program uses the PortAudio Portable Audio Library.
5
 * For more information see: http://www.portaudio.com/
6
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining
9
 * a copy of this software and associated documentation files
10
 * (the "Software"), to deal in the Software without restriction,
11
 * including without limitation the rights to use, copy, modify, merge,
12
 * publish, distribute, sublicense, and/or sell copies of the Software,
13
 * and to permit persons to whom the Software is furnished to do so,
14
 * subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be
17
 * included in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
23
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
 */
27

    
28
/*
29
 * The text above constitutes the entire PortAudio license; however, 
30
 * the PortAudio community also makes the following non-binding requests:
31
 *
32
 * Any person wishing to distribute modifications to the Software is
33
 * requested to send the modifications to the original developer so that
34
 * they can be incorporated into the canonical version. It is also 
35
 * requested that these non-binding requests be included along with the 
36
 * license above.
37
 */
38

    
39
/** @file patest_sine_channelmaps.c
40
        @ingroup test_src
41
        @brief Plays sine waves using sme simple channel maps.
42
          Designed for use with CoreAudio, but should made to work with other APIs
43
        @author Bjorn Roche <bjorn@xowave.com>
44
   @author Ross Bencina <rossb@audiomulch.com>
45
   @author Phil Burk <philburk@softsynth.com>
46
*/
47

    
48
#include <stdio.h>
49
#include <math.h>
50
#include "portaudio.h"
51

    
52
#ifdef __APPLE__
53
#include "pa_mac_core.h"
54
#endif
55

    
56
#define NUM_SECONDS   (5)
57
#define SAMPLE_RATE   (44100)
58
#define FRAMES_PER_BUFFER  (64)
59

    
60
#ifndef M_PI
61
#define M_PI  (3.14159265)
62
#endif
63

    
64
#define TABLE_SIZE   (200)
65
typedef struct
66
{
67
    float sine[TABLE_SIZE];
68
    int left_phase;
69
    int right_phase;
70
}
71
paTestData;
72

    
73
/* This routine will be called by the PortAudio engine when audio is needed.
74
** It may called at interrupt level on some machines so don't do anything
75
** that could mess up the system like calling malloc() or free().
76
*/
77
static int patestCallback( const void *inputBuffer, void *outputBuffer,
78
                            unsigned long framesPerBuffer,
79
                            const PaStreamCallbackTimeInfo* timeInfo,
80
                            PaStreamCallbackFlags statusFlags,
81
                            void *userData )
82
{
83
    paTestData *data = (paTestData*)userData;
84
    float *out = (float*)outputBuffer;
85
    unsigned long i;
86

    
87
    (void) timeInfo; /* Prevent unused variable warnings. */
88
    (void) statusFlags;
89
    (void) inputBuffer;
90
    
91
    for( i=0; i<framesPerBuffer; i++ )
92
    {
93
        *out++ = data->sine[data->left_phase];  /* left */
94
        *out++ = data->sine[data->right_phase];  /* right */
95
        data->left_phase += 1;
96
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
97
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
98
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
99
    }
100
    
101
    return paContinue;
102
}
103

    
104
/*******************************************************************/
105
int main(void);
106
int main(void)
107
{
108
    PaStreamParameters outputParameters;
109
    PaStream *stream;
110
    PaError err;
111
    paTestData data;
112
#ifdef __APPLE__
113
    PaMacCoreStreamInfo macInfo;
114
    const SInt32 channelMap[4] = { -1, -1, 0, 1 };
115
#endif
116
    int i;
117

    
118
    
119
    printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
120
    printf("Output will be mapped to channels 2 and 3 instead of 0 and 1.\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 = 0;
128
    
129
    err = Pa_Initialize();
130
    if( err != paNoError ) goto error;
131

    
132
    /** setup host specific info */
133
#ifdef __APPLE__
134
    PaMacCore_SetupStreamInfo( &macInfo, paMacCorePlayNice );
135
    PaMacCore_SetupChannelMap( &macInfo, channelMap, 4 );
136

    
137
    for( i=0; i<4; ++i )
138
       printf( "channel %d name: %s\n", i, PaMacCore_GetChannelName( Pa_GetDefaultOutputDevice(), i, false ) );
139
#else
140
    printf( "Channel mapping not supported on this platform. Reverting to normal sine test.\n" );
141
#endif
142

    
143
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
144
    if (outputParameters.device == paNoDevice) {
145
        fprintf(stderr,"Error: No default output device.\n");
146
        goto error;
147
    }
148
    outputParameters.channelCount = 2;       /* stereo output */
149
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
150
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
151
#ifdef __APPLE__
152
    outputParameters.hostApiSpecificStreamInfo = &macInfo;
153
#else
154
    outputParameters.hostApiSpecificStreamInfo = NULL;
155
#endif
156

    
157
    err = Pa_OpenStream(
158
              &stream,
159
              NULL, /* no input */
160
              &outputParameters,
161
              SAMPLE_RATE,
162
              FRAMES_PER_BUFFER,
163
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
164
              patestCallback,
165
              &data );
166
    if( err != paNoError ) goto error;
167

    
168
    err = Pa_StartStream( stream );
169
    if( err != paNoError ) goto error;
170

    
171
    printf("Play for %d seconds.\n", NUM_SECONDS );
172
    Pa_Sleep( NUM_SECONDS * 1000 );
173

    
174
    err = Pa_StopStream( stream );
175
    if( err != paNoError ) goto error;
176

    
177
    err = Pa_CloseStream( stream );
178
    if( err != paNoError ) goto error;
179

    
180
    Pa_Terminate();
181
    printf("Test finished.\n");
182
    
183
    return err;
184
error:
185
    Pa_Terminate();
186
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
187
    fprintf( stderr, "Error number: %d\n", err );
188
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
189
    return err;
190
}