Using an Audio API

Mar 6, 2011 at 8:02pm
Hi all
I'm trying to write an audio program that uses the PortAudio library. I'm having trouble getting a sample program to run in Visual studio express 08. The program will not compile. The error message says that I haven't declared functions that I'm using, but the code is a sample written by PortAudio's designers.
I think my problem is in how Im setting up the compiler, how I'm implementing PortAudio, or I'm missing an include file.

Has anyone who's used PortAudio give me an easy to read explanation of how to set it up for my compiler? I've read and tried to follow the instructions on PortAudios website, but it's very cryptic to me. I'm not a programmer by trade, I just know enough about this stuff to get me into trouble.

Thanks, Mark
Mar 6, 2011 at 11:53pm
closed account (zb0S216C)
The error message says that I haven't declared functions that I'm using

Would these errors be something along the lines of: undefined reference to 'method( )'? If so, you may not have linked the associated library that the header( s ) require.
Last edited on Mar 6, 2011 at 11:54pm
Mar 7, 2011 at 12:01am
Hi Framework

This is the error I'm getting:
1>patest_saw.obj : error LNK2019: unresolved external symbol _Pa_GetErrorText referenced in function _main

I get 9 total errors, one for each function that looks like Pa_<xxxxx>, these seem to be the PortAudio functions.

I can paste the whole sample code if that would help

Mark
Mar 7, 2011 at 12:28am
closed account (zb0S216C)
All of my sources are pointing towards these two potential causes:
1) The associated library hasn't been properly linked.
2) All the required header( s ) haven't been included.

I can paste the whole sample code if that would help

Yes please.

Here are a few question I need to ask you:
1) What is the compiler vendor you are using?
2) Is the library a Dynamic Linked Library or a Static/Shared library?
3) Is the code written in C or C++?
Mar 7, 2011 at 4:04am
Here is my source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <math.h>
#include "portaudio.h"
#define NUM_SECONDS   (4)
#define SAMPLE_RATE   (44100)

typedef struct
{
    float left_phase;
    float right_phase;
}
paTestData;

/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
*/
static int patestCallback( const void *inputBuffer, void *outputBuffer,
                           unsigned long framesPerBuffer,
                           const PaStreamCallbackTimeInfo* timeInfo,
                           PaStreamCallbackFlags statusFlags,
                           void *userData )
{
    /* Cast data passed through stream to our structure. */
    paTestData *data = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    unsigned int i;
    (void) inputBuffer; /* Prevent unused variable warning. */

    for( i=0; i<framesPerBuffer; i++ )
    {
        *out++ = data->left_phase;  /* left */
        *out++ = data->right_phase;  /* right */
        /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */
        data->left_phase += 0.01f;
        /* When signal reaches top, drop back down. */
        if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f;
        /* higher pitch so we can distinguish left and right. */
        data->right_phase += 0.03f;
        if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f;
    }
    return 0;
}

/*******************************************************************/
static paTestData data;
int main(void);
int main(void)
{
    PaStream *stream;
    PaError err;
    
    printf("PortAudio Test: output sawtooth wave.\n");
    /* Initialize our data for use by callback. */
    data.left_phase = data.right_phase = 0.0;
    /* Initialize library before making any other calls. */
    err = Pa_Initialize();
    if( err != paNoError ) goto error;
    
    /* Open an audio I/O stream. */
    err = Pa_OpenDefaultStream( &stream,
                                0,          /* no input channels */
                                2,          /* stereo output */
                                paFloat32,  /* 32 bit floating point output */
                                SAMPLE_RATE,
                                256,        /* frames per buffer */
                                patestCallback,
                                &data );
    if( err != paNoError ) goto error;

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

    /* Sleep for several seconds. */
    Pa_Sleep(NUM_SECONDS*1000);

    err = Pa_StopStream( stream );
    if( err != paNoError ) goto error;
    err = Pa_CloseStream( stream );
    if( err != paNoError ) goto error;
    Pa_Terminate();
    printf("Test finished.\n");
    return err;
error:
    Pa_Terminate();
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
    fprintf( stderr, "Error number: %d\n", err );
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
    return err;
}


The header file "portaudio.h" is both in the visual studio project directory and in the same folder in the file system next to the file with the above code.

I think the issue may be the library as you said...

With regard to your questions:
1) I'm using the compiler that comes with Windows Visual C++2008 Express Edition.
2) Not sure on this, if you know VC++ 2008, can you tell me how I could check this? BTW there is a routine to compile PortAudio into a DLL. I can follow the instructions from PortAudio's tutorial but I'm not sure what to do with it after I'm done compiling. Not sure if this is a separate issue, or related to the compiler.
3) Code seems to be written in C. The attached code is sample code that comes with PortAudio to demonstrate its features. The extension on the file is .c, not .cpp, so I assume the code is C.

Thanks
Mark
Mar 7, 2011 at 7:46am
Hi Framework

I figured it out. Theres a really good step by step tutorial that talks about compiling and testing the API here http://wyonghao.blogspot.com

I've gotten the sample code above to work.

Thanks for your help

Mark

Topic archived. No new replies allowed.