diff --git a/src/monocoque/devices/sound/usb_generic_shaker.h b/src/monocoque/devices/sound/usb_generic_shaker.h index 83441f3..909ba9b 100644 --- a/src/monocoque/devices/sound/usb_generic_shaker.h +++ b/src/monocoque/devices/sound/usb_generic_shaker.h @@ -4,7 +4,7 @@ #include "../simdevice.h" #ifdef USE_PULSEAUDIO -int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, 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); #else int usb_generic_shaker_init(SoundDevice* sounddevice); #endif diff --git a/src/monocoque/devices/sound/usb_generic_shaker_pulse.c b/src/monocoque/devices/sound/usb_generic_shaker_pulse.c index dc37f5d..ec575c0 100644 --- a/src/monocoque/devices/sound/usb_generic_shaker_pulse.c +++ b/src/monocoque/devices/sound/usb_generic_shaker_pulse.c @@ -92,7 +92,7 @@ int usb_generic_shaker_free(SoundDevice* sounddevice) return err; } -int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, 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) { pa_stream *stream; @@ -100,12 +100,13 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main pa_sample_spec sample_specifications; sample_specifications.format = FORMAT; sample_specifications.rate = SAMPLE_RATE; - sample_specifications.channels = 2; + sample_specifications.channels = channels; pa_channel_map channel_map; - pa_channel_map_init_stereo(&channel_map); - pa_channel_map_parse(&channel_map, "front-left,front-right"); + pa_channel_map_init_auto(&channel_map, channels, PA_CHANNEL_MAP_DEFAULT); + //pa_channel_map_init_stereo(&channel_map); + //pa_channel_map_parse(&channel_map, "front-left,front-right"); stream = pa_stream_new(context, streamname, &sample_specifications, &channel_map); @@ -128,25 +129,24 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main buffer_attr.prebuf = (uint32_t) -1; buffer_attr.minreq = (uint32_t) -1; - pa_cvolume cv; + pa_cvolume* cv; + pa_cvolume_mute(cv, channels); uint16_t pvolume = ceil(((double) volume/100.0d)*65535); // Settings copied as per the chromium browser source pa_stream_flags_t stream_flags; stream_flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED; - // Connect stream to the default audio output sink - pa_cvolume_set(&cv, sample_specifications.channels, pvolume); - pa_cvolume_set_balance(&cv, &channel_map, pan); + cv->values[pan] = pvolume; - 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); // Wait for the stream to be ready for(;;) { pa_stream_state_t stream_state = pa_stream_get_state(stream); assert(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); } diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index 91b1e94..c60c3a4 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -109,7 +109,7 @@ int sounddev_free(SimDevice* this) return 0; } -int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration, double threshold) +int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, int channels, double duration, double threshold) { slogi("initializing standalone sound device..."); @@ -117,6 +117,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int slogi("volume is: %i", volume); slogi("frequency is: %i", frequency); slogi("pan is: %i", pan); + slogi("channels is: %i", channels); slogi("duration is: %f", duration); @@ -165,7 +166,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int //pa_threaded_mainloop* mainloop; //pa_context* context; - usb_generic_shaker_init(sounddevice, mainloop, context, devname, volume, pan, streamname); + usb_generic_shaker_init(sounddevice, mainloop, context, devname, volume, pan, channels, streamname); #else usb_generic_shaker_init(sounddevice); #endif @@ -219,7 +220,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) { slogt("Attempting to use device %s", ds->sounddevsettings.dev); - int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration, ds->threshold); + int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.channels, ds->sounddevsettings.duration, ds->threshold); if (error != 0) { free(this); diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index 9989b12..94e45dc 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -376,6 +376,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co ds->sounddevsettings.lowbound_frequency = -1; ds->sounddevsettings.upperbound_frequency = -1; ds->sounddevsettings.pan = 0; + ds->sounddevsettings.channels = 1; ds->sounddevsettings.duration = 2.0; if (ds->effect_type == EFFECT_GEARSHIFT) { @@ -387,6 +388,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume); config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency); config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan); + config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels); config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration); const char* temp; diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index d055d26..7f68695 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -129,6 +129,7 @@ typedef struct int lowbound_frequency; int upperbound_frequency; int pan; + int channels; double duration; char* dev; }