From 7da1ab87adcd90ac7017747ccd38ef97d857c325 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 31 May 2025 11:37:32 +0200 Subject: [PATCH] optimize a bit --- io/audio.c | 29 +++++++++++------------------ io/audio.h | 6 ++---- src/vban95.c | 2 +- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/io/audio.c b/io/audio.c index dd4deec..d5b00c5 100644 --- a/io/audio.c +++ b/io/audio.c @@ -72,18 +72,18 @@ int init_PulseInputDevicef(PulseInputDevice* dev, int sample_rate, int channels, return 0; } -int read_PulseInputDevice(PulseInputDevice* dev, float* buffer, size_t size) { +int read_PulseInputDevice(PulseInputDevice* dev, void* buffer, size_t size) { if (!dev->initialized) return -1; - int error; - if (pa_simple_read(dev->dev, buffer, size, &error) < 0) return error; - return 0; + int error = 0; + pa_simple_read(dev->dev, buffer, size, &error); + return error; } int read_PulseInputDevicef(PulseInputDevice* dev, void* buffer, size_t size) { if (!dev->initialized) return -1; - int error; - if (pa_simple_read(dev->dev, buffer, size, &error) < 0) return error; - return 0; + int error = 0; + pa_simple_read(dev->dev, buffer, size, &error); + return error; } void free_PulseInputDevice(PulseInputDevice* dev) { @@ -162,18 +162,11 @@ int init_PulseOutputDevicef(PulseOutputDevice* dev, int sample_rate, int channel return 0; } -int write_PulseOutputDevice(PulseOutputDevice* dev, float* buffer, size_t size) { +int write_PulseOutputDevice(PulseOutputDevice* dev, void* buffer, size_t size) { if (!dev->initialized) return -1; - int error; - if (pa_simple_write(dev->dev, buffer, size, &error) < 0) return error; - return 0; -} - -int write_PulseOutputDevicef(PulseOutputDevice* dev, void* buffer, size_t size) { - if (!dev->initialized) return -1; - int error; - if (pa_simple_write(dev->dev, buffer, size, &error) < 0) return error; - return 0; + int error = 0; + pa_simple_write(dev->dev, buffer, size, &error); + return error; } void free_PulseOutputDevice(PulseOutputDevice* dev) { diff --git a/io/audio.h b/io/audio.h index c56b44c..4a26502 100644 --- a/io/audio.h +++ b/io/audio.h @@ -25,13 +25,11 @@ typedef struct int init_PulseInputDevice(PulseInputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr); int init_PulseInputDevicef(PulseInputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr, pa_sample_format_t format); -int read_PulseInputDevice(PulseInputDevice *dev, float *buffer, size_t size); -int read_PulseInputDevicef(PulseInputDevice *dev, void *buffer, size_t size); +int read_PulseInputDevice(PulseInputDevice *dev, void *buffer, size_t size); void free_PulseInputDevice(PulseInputDevice *dev); typedef PulseInputDevice PulseOutputDevice; int init_PulseOutputDevice(PulseOutputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr); int init_PulseOutputDevicef(PulseOutputDevice *dev, int sample_rate, int channels, char *app_name, char *stream_name, char *device, pa_buffer_attr *buffer_attr, pa_sample_format_t format); -int write_PulseOutputDevice(PulseOutputDevice *dev, float *buffer, size_t size); -int write_PulseOutputDevicef(PulseOutputDevice *dev, void *buffer, size_t size); +int write_PulseOutputDevice(PulseOutputDevice *dev, void *buffer, size_t size); void free_PulseOutputDevice(PulseOutputDevice *dev); \ No newline at end of file diff --git a/src/vban95.c b/src/vban95.c index c0d6a58..1811e2f 100644 --- a/src/vban95.c +++ b/src/vban95.c @@ -102,7 +102,7 @@ static PulseOutputDevice output = {0}; void process_audio_buffer(AudioBuffer* buffer, PulseOutputDevice* output_device) { while (buffer->count > 0) { AudioPacket* pkt = &buffer->packets[buffer->tail]; - write_PulseOutputDevicef(output_device, pkt->data, pkt->size); + write_PulseOutputDevice(output_device, pkt->data, pkt->size); buffer->tail = (buffer->tail + 1) % buffer->capacity; buffer->count--;