Fix some pulseaudio stuff

This commit is contained in:
Paul Dino Jones 2025-03-26 17:35:05 -04:00
parent 2aed9f5b51
commit 14fb81ee43
4 changed files with 17 additions and 20 deletions

View File

@ -19,8 +19,10 @@ 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);
@ -28,23 +30,22 @@ int setupsound()
pa_threaded_mainloop_lock(mainloop);
// Start the mainloop
pa_threaded_mainloop_start(mainloop);
pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
assert(pa_threaded_mainloop_start(mainloop) == 0);
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
// Wait for the context to be ready
for(;;) {
pa_context_state_t context_state = pa_context_get_state(context);
PA_CONTEXT_IS_GOOD(context_state);
assert(PA_CONTEXT_IS_GOOD(context_state));
if (context_state == PA_CONTEXT_READY) break;
pa_threaded_mainloop_wait(mainloop);
}
pa_threaded_mainloop_unlock(mainloop);
slogi("successfully connected pulseaudio...");
return 1;
return 0;
}
int freesound()
{
if (mainloop) {
@ -62,6 +63,8 @@ int freesound()
pa_threaded_mainloop_unlock(mainloop);
pa_threaded_mainloop_free(mainloop);
}
return 0;
}

View File

@ -16,9 +16,6 @@
#define M_PI (3.14159265)
#endif
static int * volatile drain_result = NULL;
static pa_context *this_context = NULL;
void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
SoundData* data = (SoundData*)userdata;
@ -108,7 +105,6 @@ 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_disconnect(sounddevice->stream);
pa_stream_unref(sounddevice->stream);
// why is this wrong
@ -123,7 +119,6 @@ int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* main
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)
{
this_context = context;
pa_threaded_mainloop_lock(mainloop);
pa_stream *stream;
@ -187,14 +182,15 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
// for now i'm only supporting playing on one specified channel which is the concept you should build your setups around
cv.values[pan] = channel_volume;
//assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL);
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
//pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL);
// Wait for the stream to be ready
for(;;) {
for(;;)
{
pa_stream_state_t stream_state = pa_stream_get_state(stream);
//assert(PA_STREAM_IS_GOOD(stream_state));
PA_STREAM_IS_GOOD(stream_state);
assert(PA_STREAM_IS_GOOD(stream_state));
//PA_STREAM_IS_GOOD(stream_state);
if (stream_state == PA_STREAM_READY) break;
pa_threaded_mainloop_wait(mainloop);
}

View File

@ -249,13 +249,10 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
ms->configcheck = 0;
}
setupsound();
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
for(int d = 0; d < 10; d++)
{
monocoque_serial_devices[d].open = false;
@ -380,7 +377,6 @@ void shmdatamapcallback(uv_timer_t* handle)
free(monocoque_serial_devices[d].portname);
}
}
freesound();
int r = simfree(simdata, simmap, f->map);
slogd("simfree returned %i", r);
f->numdevices = 0;

View File

@ -233,6 +233,7 @@ int main(int argc, char** argv)
pulseaudio = true;
//#endif
setupsound();
//error = looper(devices, numdevices, p);
error = monocoque_mainloop(ms);
if (error == MONOCOQUE_ERROR_NONE)
@ -243,6 +244,7 @@ int main(int argc, char** argv)
{
sloge("Game loop exited with error code: %i", error);
}
freesound();
}
else
{