Cleanup pulseaudio code

This commit is contained in:
Paul Dino Jones 2025-03-26 11:58:05 -04:00
parent 02699d3c47
commit b380d44521
5 changed files with 23 additions and 21 deletions

View File

@ -123,12 +123,12 @@ typedef struct
int configcheck;
SoundEffectModulationType modulationType;
SoundData sounddata;
#ifdef USE_PULSEAUDIO
//#ifdef USE_PULSEAUDIO
pa_stream *stream;
#else
PaStreamParameters outputParameters;
PaStream* stream;
#endif
//#else
//PaStreamParameters outputParameters;
//PaStream* stream;
//#endif
}
SoundDevice;

View File

@ -19,10 +19,8 @@ int setupsound()
slogi("connecting pulseaudio...");
// Get a mainloop and its context
mainloop = pa_threaded_mainloop_new();
assert(mainloop);
mainloop_api = pa_threaded_mainloop_get_api(mainloop);
context = pa_context_new(mainloop_api, "Monocoque");
assert(context);
pa_context_set_state_callback(context, &context_state_cb, mainloop);
@ -30,13 +28,13 @@ int setupsound()
pa_threaded_mainloop_lock(mainloop);
// Start the mainloop
assert(pa_threaded_mainloop_start(mainloop) == 0);
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
pa_threaded_mainloop_start(mainloop);
pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
// Wait for the context to be ready
for(;;) {
pa_context_state_t context_state = pa_context_get_state(context);
assert(PA_CONTEXT_IS_GOOD(context_state));
PA_CONTEXT_IS_GOOD(context_state);
if (context_state == PA_CONTEXT_READY) break;
pa_threaded_mainloop_wait(mainloop);
}
@ -52,8 +50,12 @@ int freesound()
if (mainloop) {
pa_threaded_mainloop_lock(mainloop);
}
if (context)
{
pa_context_unref(context);
slogt("freed pulseaudio context");
}
if (mainloop) {
pa_signal_done();

View File

@ -3,12 +3,12 @@
#include "../simdevice.h"
#ifdef USE_PULSEAUDIO
//#ifdef USE_PULSEAUDIO
int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, int channels, const char* streamname);
int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop);
#else
int usb_generic_shaker_init(SoundDevice* sounddevice);
int usb_generic_shaker_free(SoundDevice* sounddevice);
#endif
//#else
//int usb_generic_shaker_init(SoundDevice* sounddevice);
//int usb_generic_shaker_free(SoundDevice* sounddevice);
//#endif
#endif

View File

@ -108,11 +108,11 @@ int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* main
int err = 0;
if (sounddevice->stream)
{
//pa_stream_cork(sounddevice->stream, 1, stream_success_cb, mainloop);
pa_stream_cork(sounddevice->stream, 1, stream_success_cb, mainloop);
pa_stream_disconnect(sounddevice->stream);
pa_stream_unref(sounddevice->stream);
// why is this wrong
//pa_xfree(sounddevice->stream);
}

View File

@ -1,11 +1,11 @@
#ifndef _SOUNDDEVICE_H
#define _SOUNDDEVICE_H
#ifdef USE_PULSEAUDIO
//#ifdef USE_PULSEAUDIO
#include <pulse/pulseaudio.h>
#else
#include "portaudio.h"
#endif
//#else
//#include "portaudio.h"
//#endif
typedef enum