Fix some pulseaudio stuff
This commit is contained in:
parent
2aed9f5b51
commit
14fb81ee43
|
|
@ -19,8 +19,10 @@ int setupsound()
|
||||||
slogi("connecting pulseaudio...");
|
slogi("connecting pulseaudio...");
|
||||||
// Get a mainloop and its context
|
// Get a mainloop and its context
|
||||||
mainloop = pa_threaded_mainloop_new();
|
mainloop = pa_threaded_mainloop_new();
|
||||||
|
assert(mainloop);
|
||||||
mainloop_api = pa_threaded_mainloop_get_api(mainloop);
|
mainloop_api = pa_threaded_mainloop_get_api(mainloop);
|
||||||
context = pa_context_new(mainloop_api, "Monocoque");
|
context = pa_context_new(mainloop_api, "Monocoque");
|
||||||
|
assert(context);
|
||||||
|
|
||||||
pa_context_set_state_callback(context, &context_state_cb, mainloop);
|
pa_context_set_state_callback(context, &context_state_cb, mainloop);
|
||||||
|
|
||||||
|
|
@ -28,23 +30,22 @@ int setupsound()
|
||||||
pa_threaded_mainloop_lock(mainloop);
|
pa_threaded_mainloop_lock(mainloop);
|
||||||
|
|
||||||
// Start the mainloop
|
// Start the mainloop
|
||||||
pa_threaded_mainloop_start(mainloop);
|
assert(pa_threaded_mainloop_start(mainloop) == 0);
|
||||||
pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
|
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
|
||||||
|
|
||||||
// Wait for the context to be ready
|
// Wait for the context to be ready
|
||||||
for(;;) {
|
for(;;) {
|
||||||
pa_context_state_t context_state = pa_context_get_state(context);
|
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;
|
if (context_state == PA_CONTEXT_READY) break;
|
||||||
pa_threaded_mainloop_wait(mainloop);
|
pa_threaded_mainloop_wait(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_threaded_mainloop_unlock(mainloop);
|
pa_threaded_mainloop_unlock(mainloop);
|
||||||
slogi("successfully connected pulseaudio...");
|
slogi("successfully connected pulseaudio...");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int freesound()
|
int freesound()
|
||||||
{
|
{
|
||||||
if (mainloop) {
|
if (mainloop) {
|
||||||
|
|
@ -62,6 +63,8 @@ int freesound()
|
||||||
pa_threaded_mainloop_unlock(mainloop);
|
pa_threaded_mainloop_unlock(mainloop);
|
||||||
pa_threaded_mainloop_free(mainloop);
|
pa_threaded_mainloop_free(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
#define M_PI (3.14159265)
|
#define M_PI (3.14159265)
|
||||||
#endif
|
#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) {
|
void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||||
|
|
||||||
SoundData* data = (SoundData*)userdata;
|
SoundData* data = (SoundData*)userdata;
|
||||||
|
|
@ -108,7 +105,6 @@ int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if (sounddevice->stream)
|
if (sounddevice->stream)
|
||||||
{
|
{
|
||||||
pa_stream_cork(sounddevice->stream, 1, stream_success_cb, mainloop);
|
|
||||||
pa_stream_disconnect(sounddevice->stream);
|
pa_stream_disconnect(sounddevice->stream);
|
||||||
pa_stream_unref(sounddevice->stream);
|
pa_stream_unref(sounddevice->stream);
|
||||||
// why is this wrong
|
// 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)
|
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_threaded_mainloop_lock(mainloop);
|
||||||
pa_stream *stream;
|
pa_stream *stream;
|
||||||
|
|
||||||
|
|
@ -187,15 +182,16 @@ 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
|
// 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;
|
cv.values[pan] = channel_volume;
|
||||||
|
|
||||||
//assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
|
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);
|
//pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL);
|
||||||
|
|
||||||
// Wait for the stream to be ready
|
// Wait for the stream to be ready
|
||||||
for(;;) {
|
for(;;)
|
||||||
|
{
|
||||||
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
||||||
//assert(PA_STREAM_IS_GOOD(stream_state));
|
assert(PA_STREAM_IS_GOOD(stream_state));
|
||||||
PA_STREAM_IS_GOOD(stream_state);
|
//PA_STREAM_IS_GOOD(stream_state);
|
||||||
if (stream_state == PA_STREAM_READY) break;
|
if (stream_state == PA_STREAM_READY) break;
|
||||||
pa_threaded_mainloop_wait(mainloop);
|
pa_threaded_mainloop_wait(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,13 +249,10 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||||
ms->configcheck = 0;
|
ms->configcheck = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupsound();
|
|
||||||
|
|
||||||
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
||||||
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(int d = 0; d < 10; d++)
|
for(int d = 0; d < 10; d++)
|
||||||
{
|
{
|
||||||
monocoque_serial_devices[d].open = false;
|
monocoque_serial_devices[d].open = false;
|
||||||
|
|
@ -380,7 +377,6 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||||
free(monocoque_serial_devices[d].portname);
|
free(monocoque_serial_devices[d].portname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freesound();
|
|
||||||
int r = simfree(simdata, simmap, f->map);
|
int r = simfree(simdata, simmap, f->map);
|
||||||
slogd("simfree returned %i", r);
|
slogd("simfree returned %i", r);
|
||||||
f->numdevices = 0;
|
f->numdevices = 0;
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,7 @@ int main(int argc, char** argv)
|
||||||
pulseaudio = true;
|
pulseaudio = true;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
setupsound();
|
||||||
//error = looper(devices, numdevices, p);
|
//error = looper(devices, numdevices, p);
|
||||||
error = monocoque_mainloop(ms);
|
error = monocoque_mainloop(ms);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
|
|
@ -243,6 +244,7 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
sloge("Game loop exited with error code: %i", error);
|
sloge("Game loop exited with error code: %i", error);
|
||||||
}
|
}
|
||||||
|
freesound();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue