Add ability to use sound cards with more than 2 channels.
This commit is contained in:
parent
dd20fe3eb4
commit
30a3c3a73f
|
|
@ -4,7 +4,7 @@
|
||||||
#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, 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
|
#else
|
||||||
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ int usb_generic_shaker_free(SoundDevice* sounddevice)
|
||||||
return err;
|
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;
|
pa_stream *stream;
|
||||||
|
|
||||||
|
|
@ -100,12 +100,13 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||||
pa_sample_spec sample_specifications;
|
pa_sample_spec sample_specifications;
|
||||||
sample_specifications.format = FORMAT;
|
sample_specifications.format = FORMAT;
|
||||||
sample_specifications.rate = SAMPLE_RATE;
|
sample_specifications.rate = SAMPLE_RATE;
|
||||||
sample_specifications.channels = 2;
|
sample_specifications.channels = channels;
|
||||||
|
|
||||||
|
|
||||||
pa_channel_map channel_map;
|
pa_channel_map channel_map;
|
||||||
pa_channel_map_init_stereo(&channel_map);
|
pa_channel_map_init_auto(&channel_map, channels, PA_CHANNEL_MAP_DEFAULT);
|
||||||
pa_channel_map_parse(&channel_map, "front-left,front-right");
|
//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);
|
stream = pa_stream_new(context, streamname, &sample_specifications, &channel_map);
|
||||||
|
|
@ -128,19 +129,18 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||||
buffer_attr.prebuf = (uint32_t) -1;
|
buffer_attr.prebuf = (uint32_t) -1;
|
||||||
buffer_attr.minreq = (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);
|
uint16_t pvolume = ceil(((double) volume/100.0d)*65535);
|
||||||
// Settings copied as per the chromium browser source
|
// Settings copied as per the chromium browser source
|
||||||
|
|
||||||
pa_stream_flags_t stream_flags;
|
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;
|
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
|
// Wait for the stream to be ready
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ int sounddev_free(SimDevice* this)
|
||||||
return 0;
|
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...");
|
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("volume is: %i", volume);
|
||||||
slogi("frequency is: %i", frequency);
|
slogi("frequency is: %i", frequency);
|
||||||
slogi("pan is: %i", pan);
|
slogi("pan is: %i", pan);
|
||||||
|
slogi("channels is: %i", channels);
|
||||||
slogi("duration is: %f", duration);
|
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_threaded_mainloop* mainloop;
|
||||||
//pa_context* context;
|
//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
|
#else
|
||||||
usb_generic_shaker_init(sounddevice);
|
usb_generic_shaker_init(sounddevice);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -219,7 +220,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||||
|
|
||||||
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
|
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)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
|
|
|
||||||
|
|
@ -376,6 +376,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
ds->sounddevsettings.lowbound_frequency = -1;
|
ds->sounddevsettings.lowbound_frequency = -1;
|
||||||
ds->sounddevsettings.upperbound_frequency = -1;
|
ds->sounddevsettings.upperbound_frequency = -1;
|
||||||
ds->sounddevsettings.pan = 0;
|
ds->sounddevsettings.pan = 0;
|
||||||
|
ds->sounddevsettings.channels = 1;
|
||||||
ds->sounddevsettings.duration = 2.0;
|
ds->sounddevsettings.duration = 2.0;
|
||||||
if (ds->effect_type == EFFECT_GEARSHIFT)
|
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, "volume", &ds->sounddevsettings.volume);
|
||||||
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
|
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, "pan", &ds->sounddevsettings.pan);
|
||||||
|
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
|
||||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||||
|
|
||||||
const char* temp;
|
const char* temp;
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ typedef struct
|
||||||
int lowbound_frequency;
|
int lowbound_frequency;
|
||||||
int upperbound_frequency;
|
int upperbound_frequency;
|
||||||
int pan;
|
int pan;
|
||||||
|
int channels;
|
||||||
double duration;
|
double duration;
|
||||||
char* dev;
|
char* dev;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue