Live audio recording and playback via PortAudio.
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <portaudio.h>
Go to the source code of this file.
|
| typedef int | LaError_t |
| | Return type for live audio functions.
|
| |
|
| LaError_t | LA_init (void) |
| | Initialise the PortAudio system.
|
| |
| LaError_t | LA_terminate (void) |
| | Shut down the PortAudio system.
|
| |
| void | LA_print_last_error (FILE *stream) |
| | Print the last PortAudio error message to the given stream.
|
| |
| int | LA_is_recording (void) |
| | Check if the recording stream is active.
|
| |
| double | LA_get_cur_record_time (void) |
| | Get the current time (in seconds) of the recording stream.
|
| |
| void | LA_stop_recording (void) |
| | Stop the current recording.
|
| |
| LaError_t | LA_record (void *buffer, unsigned long bufsize, unsigned samprate, int rectype) |
| | Record audio from the default input device into a buffer.
|
| |
| LaError_t | LA_record_callback (unsigned samprate, PaStreamCallback *cb, void *cb_data) |
| | Record using a user-supplied PortAudio callback function.
|
| |
| int | LA_is_playing (void) |
| | Check if the playback stream is active.
|
| |
| double | LA_get_cur_play_time (void) |
| | Get the current time (in seconds) of the playback stream.
|
| |
| void | LA_stop_playing (void) |
| | Stop the current playback.
|
| |
| LaError_t | LA_play (const void *buffer, unsigned long bufsize, unsigned samprate) |
| | Play audio from a buffer to the default output device.
|
| |
| LaError_t | LA_play_callback (unsigned samprate, PaStreamCallback *cb, void *cb_data) |
| | Play using a user-supplied PortAudio callback function.
|
| |
Live audio recording and playback via PortAudio.
This module wraps the PortAudio library to provide simple functions for recording from a microphone and playing back to speakers. All functions are non-blocking – they return immediately while audio I/O happens in the background via callbacks.
Typical usage:
- Call LA_init() to initialise the audio system.
- Call LA_record() to start recording into a buffer.
- Poll LA_is_recording() until recording finishes.
- Call LA_play() to play back the recorded audio.
- Call LA_terminate() when done.
Definition in file liveio.h.
◆ LaError_t
Return type for live audio functions.
Definition at line 27 of file liveio.h.
◆ LA_ERRORCODE
Error codes returned by live audio functions.
| Enumerator |
|---|
| LA_OK | Operation succeeded.
|
| LA_ERROR | Something went wrong.
|
Definition at line 30 of file liveio.h.
◆ LA_RECORDTYPE
Recording modes for LA_record().
| Enumerator |
|---|
| LA_REC_ONCE | Record until the buffer is full, then stop.
|
| LA_REC_CONT | Record continuously in a circular buffer.
|
Definition at line 36 of file liveio.h.
◆ LA_get_cur_play_time()
| double LA_get_cur_play_time |
( |
void |
| ) |
|
Get the current time (in seconds) of the playback stream.
Returns -1.0 if inactive.
Definition at line 57 of file liveio.c.
◆ LA_get_cur_record_time()
| double LA_get_cur_record_time |
( |
void |
| ) |
|
Get the current time (in seconds) of the recording stream.
Returns -1.0 if inactive.
Definition at line 49 of file liveio.c.
◆ LA_init()
Initialise the PortAudio system.
Must be called before any other LA_ function.
If already initialised, terminates first and re-initialises.
- Returns
- LA_OK on success, LA_ERROR on failure.
Definition at line 420 of file liveio.c.
◆ LA_is_playing()
| int LA_is_playing |
( |
void |
| ) |
|
Check if the playback stream is active.
Returns 1 if playing, 0 if not, -1 on error.
Check if the playback stream is active.
- Returns
- 1 if playing, 0 if not, -1 on error.
Definition at line 94 of file liveio.c.
◆ LA_is_recording()
| int LA_is_recording |
( |
void |
| ) |
|
Check if the recording stream is active.
Returns 1 if recording, 0 if not, -1 on error.
Check if the recording stream is active.
- Returns
- 1 if recording, 0 if not, -1 on error.
Definition at line 83 of file liveio.c.
◆ LA_play()
| LaError_t LA_play |
( |
const void * |
buffer, |
|
|
unsigned long |
bufsize, |
|
|
unsigned |
samprate |
|
) |
| |
Play audio from a buffer to the default output device.
- Parameters
-
| buffer | Buffer of 16-bit signed integers. |
| bufsize | Number of samples in the buffer. |
| samprate | Sampling rate in Hz. |
- Returns
- LA_OK on success, LA_ERROR on failure.
- Note
- Non-blocking: returns immediately while playback continues in the background. Mono input is duplicated to both stereo channels.
Definition at line 378 of file liveio.c.
◆ LA_play_callback()
| LaError_t LA_play_callback |
( |
unsigned |
samprate, |
|
|
PaStreamCallback * |
cb, |
|
|
void * |
cb_data |
|
) |
| |
Play using a user-supplied PortAudio callback function.
- Parameters
-
| samprate | Sampling rate in Hz. |
| cb | Your PortAudio callback function. |
| cb_data | Data pointer passed to your callback. |
- Returns
- LA_OK on success, LA_ERROR on failure.
Definition at line 358 of file liveio.c.
◆ LA_print_last_error()
| void LA_print_last_error |
( |
FILE * |
stream | ) |
|
Print the last PortAudio error message to the given stream.
Definition at line 409 of file liveio.c.
◆ LA_record()
| LaError_t LA_record |
( |
void * |
buffer, |
|
|
unsigned long |
bufsize, |
|
|
unsigned |
samprate, |
|
|
int |
rectype |
|
) |
| |
Record audio from the default input device into a buffer.
- Parameters
-
| buffer | Pre-allocated buffer of 16-bit signed integers. |
| bufsize | Number of samples the buffer can hold. |
| samprate | Desired sampling rate in Hz (e.g. 16000, 44100). |
| rectype | LA_REC_ONCE (fill buffer then stop) or LA_REC_CONT (circular). |
- Returns
- LA_OK on success, LA_ERROR on failure.
- Note
- Non-blocking: returns immediately while recording continues in the background.
Definition at line 314 of file liveio.c.
◆ LA_record_callback()
| LaError_t LA_record_callback |
( |
unsigned |
samprate, |
|
|
PaStreamCallback * |
cb, |
|
|
void * |
cb_data |
|
) |
| |
Record using a user-supplied PortAudio callback function.
- Parameters
-
| samprate | Sampling rate in Hz. |
| cb | Your PortAudio callback function. |
| cb_data | Data pointer passed to your callback. |
- Returns
- LA_OK on success, LA_ERROR on failure.
Definition at line 294 of file liveio.c.
◆ LA_stop_playing()
| void LA_stop_playing |
( |
void |
| ) |
|
Stop the current playback.
Definition at line 72 of file liveio.c.
◆ LA_stop_recording()
| void LA_stop_recording |
( |
void |
| ) |
|
Stop the current recording.
Definition at line 65 of file liveio.c.
◆ LA_terminate()
Shut down the PortAudio system.
Call when you are finished with audio.
Shut down the PortAudio system.
- Returns
- LA_OK on success, LA_ERROR on failure.
Definition at line 441 of file liveio.c.