Skip to content

Commit

Permalink
wasapi: Fixed Pa_ReadStream()/Pa_WriteStream() for 1-channel (Mono) I…
Browse files Browse the repository at this point in the history
…/O (#948)

Fixed Pa_ReadStream()/Pa_WriteStream() for 1-channel (Mono) stream, made some tests configurable for 1-channel operation for easier testing of Mono I/O.

Added WASAPI-specific `patest_read_write_wire_wasapi.c` and `patest_read_record_wasapi.c` tests with ability to use WASAPI Loopback devices (USE_LOOPBACK_INPUT must be 1).
  • Loading branch information
dmitrykos authored Sep 26, 2024
1 parent 3beece1 commit c121482
Show file tree
Hide file tree
Showing 5 changed files with 694 additions and 132 deletions.
21 changes: 15 additions & 6 deletions examples/paex_write_sine.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@

#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "portaudio.h"

#define NUM_SECONDS (5)
#define SAMPLE_RATE (44100)
#define CHANNELS (2) /* Set to 1 or 2. */
#define FRAMES_PER_BUFFER (1024)

#ifndef M_PI
Expand All @@ -63,7 +65,7 @@ int main(void)
PaStreamParameters outputParameters;
PaStream *stream;
PaError err;
float buffer[FRAMES_PER_BUFFER][2]; /* stereo output buffer */
float buffer[FRAMES_PER_BUFFER][CHANNELS]; /* stereo output buffer */
float sine[TABLE_SIZE]; /* sine wavetable */
int left_phase = 0;
int right_phase = 0;
Expand All @@ -72,6 +74,8 @@ int main(void)
int i, j, k;
int bufferCount;

assert(CHANNELS >= 1 && CHANNELS <= 2);

printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);

/* initialise sinusoidal wavetable */
Expand All @@ -89,7 +93,7 @@ int main(void)
fprintf(stderr,"Error: No default output device.\n");
goto error;
}
outputParameters.channelCount = 2; /* stereo output */
outputParameters.channelCount = CHANNELS;
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
outputParameters.suggestedLatency = 0.050; // Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
Expand Down Expand Up @@ -122,11 +126,15 @@ int main(void)
for( j=0; j < FRAMES_PER_BUFFER; j++ )
{
buffer[j][0] = sine[left_phase]; /* left */
buffer[j][1] = sine[right_phase]; /* right */
left_phase += left_inc;
if( left_phase >= TABLE_SIZE ) left_phase -= TABLE_SIZE;
right_phase += right_inc;
if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;

if (CHANNELS == 2)
{
buffer[j][1] = sine[right_phase]; /* right */
right_phase += right_inc;
if( right_phase >= TABLE_SIZE ) right_phase -= TABLE_SIZE;
}
}

err = Pa_WriteStream( stream, buffer, FRAMES_PER_BUFFER );
Expand All @@ -137,7 +145,8 @@ int main(void)
if( err != paNoError ) goto error;

++left_inc;
++right_inc;
if (CHANNELS == 2)
++right_inc;

Pa_Sleep( 1000 );
}
Expand Down
Loading

0 comments on commit c121482

Please sign in to comment.