mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
optimize a bit
This commit is contained in:
29
io/audio.c
29
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) {
|
||||
|
||||
@@ -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);
|
||||
@@ -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--;
|
||||
|
||||
Reference in New Issue
Block a user