PortAudio input-to-output wire has too much delay

I'm trying to create a wire from input to output with near zero latency. The framesPerBuffer is almost definately the problem. When I call Pa_OpenStream I pass 256 for the framesPerBuffer parameter, or 128 when I'm more optimistic, but the opening stream message in the command prompt always displays 512 framesPerBuffer.

I'm running Windows 7 on a gaming computer. I'm completely sure it isn't my hardware since I've run software like GuitarRig and gotten live audio effects with ASIO4ALL.

I get the same results with or without the ASIO4ALL 2.10 audio driver and the JACK 1.9.10 Audio Server.

I've tried the example programs: paex_read_write_wire.c, and paex_mono_asio_channel_select.c. The former worked with delay and the later gave me the error message, "Incompatible host API specific stream info."

When I work without ASIO and JACK I select devices under the hostApi MME. When I work with ASIO and JACK I run Jack PortAudio and select, "JackRouter," for both input and output. I've played around with the, "Jack Control," panel but the settings seam to have no effect. Mind you, I'm unable to access the ASIO control panel when using the, "JackRouter," device, that might be critical. When I select the, "ASIO4ALL v2," device for both input and output, I can access the ASIO control panel but there is no sound at all, and yet no error messages.

I've also ran a for loop to go through all combinations of devices (each for 3 seconds) while playing my radio next to my mic and waiting for the radio music to sync up with my headphones. I should have known it would be a waste of time.

The following is a boiled down version of the program I'm working on. I removed error checking since I haven't been getting error's only delay.
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include "portaudio.h"

#define DUR_MILLIS          (5000)
#define NUM_CHANNELS        (2)
#define SAMPLE_RATE         (44100)
#define FRAMES_PER_BUFFER   (128)
#define SAMPLE_FORMAT       paFloat32
#define SAMPLE_SIZE         sizeof(float)
#define SAMPLE_SILENCE      (0.0f)

using namespace std;

PaError err;
PaStream *stream = NULL;

static int wireCallback( const void *inputBuffer,
        void *outputBuffer,
        unsigned long framesPerBuffer,
        const PaStreamCallbackTimeInfo *timeInfo,
        PaStreamCallbackFlags statusFlags,
        void *userData
        )
{
    (void) timeInfo; // Prevent unused variable warnings.
    (void) statusFlags;
    (void) userData;

    // Cast data to floats:
    float *out = (float*)outputBuffer;
    float *in = (float*)inputBuffer;
    unsigned long i;
    
    // Copy (wire) input to output:
    for( i = 0; i < framesPerBuffer*NUM_CHANNELS; i++ )
        out[i] = in[i];

    return paContinue;
}

PaStreamParameters getParam( PaDeviceIndex dev ){
    PaStreamParameters param;
    param.device = dev;
    param.channelCount = NUM_CHANNELS;
    param.sampleFormat = SAMPLE_FORMAT;
    param.suggestedLatency =
        Pa_GetDeviceInfo( dev )
        ->defaultLowInputLatency;
    param.hostApiSpecificStreamInfo = NULL;

    return param;
}

void startStream( PaDeviceIndex input, PaDeviceIndex output ){
    PaStreamParameters inParam = getParam( input );
    PaStreamParameters outParam = getParam( output );

    // Open and start stream using wireCallback:
    err = Pa_OpenStream(
            &stream,
            &inParam,
            &outParam,
            SAMPLE_RATE,
            FRAMES_PER_BUFFER,
            paClipOff,
            wireCallback,
            NULL
            );
    err = Pa_StartStream( stream );
    Pa_Sleep(DUR_MILLIS); // let stream run for 5 seconds.

    // Cleanup:
    err = Pa_StopStream( stream );
    Pa_AbortStream( stream );
    Pa_CloseStream( stream );
}

int main( int argc, char *argv[] ){
    err = Pa_Initialize();

    // List all devices (include hostApi):
    int deviceCount = (int) Pa_GetDeviceCount();
    cout << "\n\nThere are " << deviceCount << " audio devices:\n";
    for( int i = 0; i < deviceCount; i++ ){
        const PaDeviceInfo *devInfo;
        devInfo = Pa_GetDeviceInfo( (PaDeviceIndex)i );

        const PaHostApiInfo *host;
        host = Pa_GetHostApiInfo( devInfo->hostApi );

        cout << "Device Id Number " << i << ": ";
        cout << host->name << ": ";
        cout << devInfo->name << endl;
    }

    // Query user for input device:
    cout << endl << "Input Device Id Number: ";
    PaDeviceIndex inputDeviceIndex;
    cin >> inputDeviceIndex;

    // Query user for output device:
    cout << "Output Device Id Number: ";
    PaDeviceIndex outputDeviceIndex;
    cin >> outputDeviceIndex;

    startStream( inputDeviceIndex, outputDeviceIndex );

    Pa_Terminate();

    return 0;
}


I'm not deadset on using PortAudio, or even C++ for that matter, so if you are unable to help me fix PortAudio, but have an other live audio solution, I'm all ears.
Last edited on
Topic archived. No new replies allowed.