Convert Figma logo to code with AI

PortAudio logoportaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.

1,429
295
1,429
327

Top Related Projects

C library for cross-platform real-time audio input and output

OpenAL Soft is a software implementation of the OpenAL 3D audio API.

Audio playback and capture library written in C, in a single source file.

10,620

Audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

Quick Overview

PortAudio is a free, cross-platform, open-source audio I/O library. It provides a simple API for recording and/or playing sound using a callback function or blocking read/write interface. PortAudio is designed to simplify writing cross-platform audio programs in C, C++, and other languages.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux, and more)
  • Simple and intuitive API for audio input and output
  • Supports a wide range of audio APIs (ASIO, WASAPI, CoreAudio, ALSA, etc.)
  • Low latency performance suitable for real-time audio applications

Cons

  • Limited built-in audio processing capabilities
  • Documentation could be more comprehensive
  • Some users report occasional stability issues on certain platforms
  • Learning curve can be steep for beginners in audio programming

Code Examples

  1. Initialize PortAudio and open a stream:
#include <portaudio.h>

PaStream *stream;
PaError err;

err = Pa_Initialize();
if (err != paNoError) goto error;

err = Pa_OpenDefaultStream(&stream,
                           2,          // input channels
                           2,          // output channels
                           paFloat32,  // sample format
                           44100,      // sample rate
                           256,        // frames per buffer
                           NULL,       // no callback, use blocking API
                           NULL);      // no user data
if (err != paNoError) goto error;
  1. Write audio data to the stream:
float buffer[256 * 2];  // 256 frames, 2 channels
// Fill buffer with audio data...

err = Pa_WriteStream(stream, buffer, 256);
if (err != paNoError) goto error;
  1. Close the stream and terminate PortAudio:
err = Pa_CloseStream(stream);
if (err != paNoError) goto error;

Pa_Terminate();
return 0;

error:
    Pa_Terminate();
    fprintf(stderr, "An error occurred: %s\n", Pa_GetErrorText(err));
    return 1;

Getting Started

  1. Download and install PortAudio from the official repository.
  2. Include the PortAudio header in your project:
    #include <portaudio.h>
    
  3. Link against the PortAudio library when compiling:
    gcc -o myprogram myprogram.c -lportaudio
    
  4. Initialize PortAudio, open a stream, process audio, and clean up as shown in the code examples above.

Competitor Comparisons

C library for cross-platform real-time audio input and output

Pros of libsoundio

  • Simpler API design, making it easier to use for developers
  • Better support for modern audio APIs like WASAPI and JACK
  • More actively maintained with regular updates and bug fixes

Cons of libsoundio

  • Less mature and less widely adopted compared to PortAudio
  • Fewer supported platforms and audio backends
  • Limited documentation and community resources

Code Comparison

PortAudio:

PaError err;
PaStream *stream;
err = Pa_Initialize();
err = Pa_OpenDefaultStream(&stream, 2, 2, paFloat32, 44100, 256, NULL, NULL);
err = Pa_StartStream(stream);

libsoundio:

struct SoundIo *soundio = soundio_create();
soundio_connect(soundio);
struct SoundIoDevice *device = soundio_get_output_device(soundio, soundio_default_output_device_index(soundio));
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
soundio_outstream_open(outstream);

Both libraries provide cross-platform audio I/O capabilities, but libsoundio offers a more modern approach with a simpler API. PortAudio has the advantage of being more established and widely used, with broader platform support. The code comparison shows that libsoundio's API is slightly more verbose but potentially more intuitive for some developers. Ultimately, the choice between the two depends on specific project requirements and developer preferences.

OpenAL Soft is a software implementation of the OpenAL 3D audio API.

Pros of OpenAL Soft

  • More focused on 3D audio and spatial sound processing
  • Supports a wider range of audio effects and features
  • Better suited for game development and immersive audio applications

Cons of OpenAL Soft

  • Less cross-platform compatibility compared to PortAudio
  • Steeper learning curve for beginners
  • More complex API, which may be overkill for simple audio tasks

Code Comparison

PortAudio:

PaError err;
err = Pa_Initialize();
if (err != paNoError) {
    // Handle error
}

OpenAL Soft:

ALCdevice *device = alcOpenDevice(NULL);
ALCcontext *context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

Both libraries provide low-level audio functionality, but OpenAL Soft is more focused on 3D audio processing and game development. PortAudio offers a simpler API and better cross-platform support, making it more suitable for general-purpose audio applications. OpenAL Soft provides more advanced features for spatial audio and effects, while PortAudio excels in simplicity and ease of use for basic audio input/output tasks.

Audio playback and capture library written in C, in a single source file.

Pros of miniaudio

  • Single-file header-only library, easier to integrate
  • More modern API design with simpler usage
  • Supports more platforms, including web and game consoles

Cons of miniaudio

  • Less mature and battle-tested compared to PortAudio
  • Fewer high-level abstractions for complex audio processing
  • Limited documentation and community resources

Code Comparison

miniaudio:

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

ma_engine engine;
ma_engine_init(NULL, &engine);
ma_engine_play_sound(&engine, "sound.wav", NULL);

PortAudio:

#include "portaudio.h"

PaStream *stream;
Pa_Initialize();
Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, 44100, 256, NULL, NULL);
Pa_StartStream(stream);

Summary

miniaudio offers a more modern and user-friendly approach to audio programming, with easier integration and broader platform support. However, PortAudio has a longer history, more extensive documentation, and may be better suited for complex audio applications. The choice between the two depends on project requirements, target platforms, and developer preferences.

10,620

Audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

Pros of AudioKit

  • Higher-level API with more built-in audio processing capabilities
  • Extensive documentation and tutorials for easier learning curve
  • Swift-based, offering better integration with iOS and macOS development

Cons of AudioKit

  • Limited cross-platform support (primarily focused on Apple platforms)
  • Larger framework size, which may impact app size
  • Potentially overkill for simple audio tasks

Code Comparison

AudioKit:

import AudioKit

let oscillator = AKOscillator()
AudioKit.output = oscillator
try! AudioKit.start()
oscillator.start()

PortAudio:

#include <portaudio.h>

Pa_Initialize();
Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, SAMPLE_RATE, FRAMES_PER_BUFFER, NULL, NULL);
Pa_StartStream(stream);

AudioKit provides a more abstracted and Swift-friendly API, while PortAudio offers a lower-level C interface with greater cross-platform compatibility. AudioKit is better suited for iOS/macOS audio development with advanced features, whereas PortAudio is ideal for cross-platform projects requiring fine-grained control over audio streams.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PortAudio - portable audio I/O library

PortAudio is a portable audio I/O library designed for cross-platform support of audio. It uses either a callback mechanism to request audio processing, or blocking read/write calls to buffer data between the native audio subsystem and the client. Audio can be processed in various formats, including 32 bit floating point, and will be converted to the native format internally.

Documentation:

  • Documentation is available at http://www.portaudio.com/docs/
  • Or at /doc/html/index.html after running Doxygen.
  • Also see src/common/portaudio.h for the API spec.
  • And see the examples/ and test/ directories for many examples of usage. (We suggest examples/paex_saw.c for an example.)

For information on compiling programs with PortAudio, please see the tutorial at:

http://portaudio.com/docs/v19-doxydocs/tutorial_start.html

We have an active mailing list for user and developer discussions. Please feel free to join. See http://www.portaudio.com for details.

Important Files and Folders:

include/portaudio.h     = header file for PortAudio API. Specifies API.	
src/common/             = platform independent code, host independent 
                          code for all implementations.
src/os                  = os specific (but host api neutral) code
src/hostapi             = implementations for different host apis

Host API Implementations:

src/hostapi/alsa        = Advanced Linux Sound Architecture (ALSA)
src/hostapi/asihpi      = AudioScience HPI
src/hostapi/asio        = ASIO for Windows and Macintosh
src/hostapi/audioio     = /dev/audio (Solaris/NetBSD Audio)
src/hostapi/coreaudio   = Macintosh Core Audio for OS X
src/hostapi/dsound      = Windows Direct Sound
src/hostapi/jack        = JACK Audio Connection Kit
src/hostapi/oss         = Unix Open Sound System (OSS)
src/hostapi/pulseaudio  = Sound system for POSIX OSes
src/hostapi/sndio       = Small audio and MIDI framework (sndio)
src/hostapi/wasapi      = Windows Vista WASAPI
src/hostapi/wdmks       = Windows WDM Kernel Streaming
src/hostapi/wmme        = Windows MultiMedia Extensions (MME)

Test Programs:

test/pa_fuzz.c         = guitar fuzz box
test/pa_devs.c         = print a list of available devices
test/pa_minlat.c       = determine minimum latency for your machine
test/paqa_devs.c       = self test that opens all devices
test/paqa_errs.c       = test error detection and reporting
test/patest_clip.c     = hear a sine wave clipped and unclipped
test/patest_dither.c   = hear effects of dithering (extremely subtle)
test/patest_pink.c     = fun with pink noise
test/patest_record.c   = record and playback some audio
test/patest_maxsines.c = how many sine waves can we play? Tests Pa_GetCPULoad().
test/patest_sine.c     = output a sine wave in a simple PA app
test/patest_sync.c     = test synchronization of audio and video
test/patest_wire.c     = pass input to output, wire simulator