Cleanup pulseaudio code
This commit is contained in:
parent
02699d3c47
commit
b380d44521
|
|
@ -123,12 +123,12 @@ typedef struct
|
||||||
int configcheck;
|
int configcheck;
|
||||||
SoundEffectModulationType modulationType;
|
SoundEffectModulationType modulationType;
|
||||||
SoundData sounddata;
|
SoundData sounddata;
|
||||||
#ifdef USE_PULSEAUDIO
|
//#ifdef USE_PULSEAUDIO
|
||||||
pa_stream *stream;
|
pa_stream *stream;
|
||||||
#else
|
//#else
|
||||||
PaStreamParameters outputParameters;
|
//PaStreamParameters outputParameters;
|
||||||
PaStream* stream;
|
//PaStream* stream;
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
SoundDevice;
|
SoundDevice;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,8 @@ 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);
|
||||||
|
|
||||||
|
|
@ -30,13 +28,13 @@ int setupsound()
|
||||||
pa_threaded_mainloop_lock(mainloop);
|
pa_threaded_mainloop_lock(mainloop);
|
||||||
|
|
||||||
// Start the mainloop
|
// Start the mainloop
|
||||||
assert(pa_threaded_mainloop_start(mainloop) == 0);
|
pa_threaded_mainloop_start(mainloop);
|
||||||
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
|
pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
|
||||||
|
|
||||||
// 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);
|
||||||
assert(PA_CONTEXT_IS_GOOD(context_state));
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -52,8 +50,12 @@ int freesound()
|
||||||
if (mainloop) {
|
if (mainloop) {
|
||||||
pa_threaded_mainloop_lock(mainloop);
|
pa_threaded_mainloop_lock(mainloop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context)
|
if (context)
|
||||||
|
{
|
||||||
pa_context_unref(context);
|
pa_context_unref(context);
|
||||||
|
slogt("freed pulseaudio context");
|
||||||
|
}
|
||||||
|
|
||||||
if (mainloop) {
|
if (mainloop) {
|
||||||
pa_signal_done();
|
pa_signal_done();
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
#include "../simdevice.h"
|
#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_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);
|
int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop);
|
||||||
#else
|
//#else
|
||||||
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
//int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||||
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
//int usb_generic_shaker_free(SoundDevice* sounddevice);
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -108,11 +108,11 @@ 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_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
|
||||||
//pa_xfree(sounddevice->stream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef _SOUNDDEVICE_H
|
#ifndef _SOUNDDEVICE_H
|
||||||
#define _SOUNDDEVICE_H
|
#define _SOUNDDEVICE_H
|
||||||
|
|
||||||
#ifdef USE_PULSEAUDIO
|
//#ifdef USE_PULSEAUDIO
|
||||||
#include <pulse/pulseaudio.h>
|
#include <pulse/pulseaudio.h>
|
||||||
#else
|
//#else
|
||||||
#include "portaudio.h"
|
//#include "portaudio.h"
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue