Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eb48907a0 | ||
|
|
479c77d251 | ||
|
|
e32cac5666 | ||
|
|
93a967ec15 | ||
|
|
db6b5b027c | ||
|
|
76b7d4dafc | ||
|
|
f7df9ab90e | ||
|
|
5781518f44 | ||
|
|
ce05f0d78b | ||
|
|
7415ecf85f | ||
|
|
6b84a85639 |
@@ -47,7 +47,7 @@ jobs:
|
||||
mkdir PKG_SOURCE
|
||||
mkdir -p PKG_SOURCE/DEBIAN
|
||||
mkdir -p PKG_SOURCE/usr/bin/
|
||||
cp ./tools/distro/debian/dpkg/control ./PKG_SOURCE/DEBIAN/control
|
||||
cp ./tools/distro/debian/dpkg/${{ matrix.os }}/control ./PKG_SOURCE/DEBIAN/control
|
||||
cp ./build/monocoque ./PKG_SOURCE/usr/bin/monocoque
|
||||
dpkg-deb --build PKG_SOURCE monocoque-${{ matrix.os }}.deb
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
||||
- Convincing shaker effects for noise tranducers for wheel slip, wheel lock, and abs, as well as engine rpm and gear shifts.
|
||||
- Support for many [wheels and pedals](https://spacefreak18.github.io/simapi/thirdpartydevices) including Clubsport Elite V3, [Logitech G29](https://spacefreak18.github.io/simapi/logitechg29), and Moza R5.
|
||||
|
||||
## Adding More Devices
|
||||
- If a device isn't already supported, feel free to assist in the reverse engineering process by submitting a pcap or even better working code in a pull request!
|
||||
https://santeri.pikarinen.com/pages/usb_hid_reverse_engineering/
|
||||
|
||||
## Quick Install
|
||||
|
||||
**One-Line Installation:**
|
||||
|
||||
@@ -26,6 +26,7 @@ configs = (
|
||||
modulation = "frequency";
|
||||
frequency = 17;
|
||||
frequencyMax = 37;
|
||||
noise = 10; // additive noise in Hz
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
|
||||
@@ -19,10 +19,8 @@ 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);
|
||||
|
||||
@@ -30,13 +28,12 @@ int setupsound()
|
||||
pa_threaded_mainloop_lock(mainloop);
|
||||
|
||||
// Start the mainloop
|
||||
assert(pa_threaded_mainloop_start(mainloop) == 0);
|
||||
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
|
||||
pa_threaded_mainloop_start(mainloop);
|
||||
pa_context_connect(context, NULL, 0, NULL);
|
||||
|
||||
// Wait for the context to be ready
|
||||
for(;;) {
|
||||
pa_context_state_t context_state = pa_context_get_state(context);
|
||||
assert(PA_CONTEXT_IS_GOOD(context_state));
|
||||
if (context_state == PA_CONTEXT_READY) break;
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ int patestCallbackGearShift(const void* inputBuffer,
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0;
|
||||
data->curr_frequency = 0.0;
|
||||
}
|
||||
|
||||
*out++ = sample;
|
||||
|
||||
@@ -16,6 +16,15 @@
|
||||
#define M_PI (3.14159265)
|
||||
#endif
|
||||
|
||||
static double apply_noise(double base_freq, double noise_amount) {
|
||||
if (noise_amount > 0.0) {
|
||||
double r = (double) rand() / RAND_MAX * 2.0 - 1.0;
|
||||
return base_freq + r * noise_amount;
|
||||
} else {
|
||||
return base_freq;
|
||||
}
|
||||
}
|
||||
|
||||
void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
SoundData* data = (SoundData*)userdata;
|
||||
@@ -24,59 +33,75 @@ void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
|
||||
for (size_t i = 0; i < num_samples; i++) {
|
||||
static double t = 0.0;
|
||||
double sample = 0;
|
||||
if (data->frequency>0)
|
||||
{
|
||||
sample = ((double)data->curr_amplitude/100) * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * data->curr_duration);
|
||||
}
|
||||
|
||||
double sample = 0;
|
||||
|
||||
if (data->curr_frequency>0.0)
|
||||
{
|
||||
double t = data->phase;
|
||||
double a = (double)data->curr_amplitude/100;
|
||||
|
||||
// fade-out 5ms to prevent discontinuity
|
||||
static double fade_out_duration = 0.005;
|
||||
|
||||
double remaining = data->duration - data->curr_duration;
|
||||
if (remaining < fade_out_duration) {
|
||||
a *= remaining / fade_out_duration;
|
||||
}
|
||||
|
||||
sample = a * 32767.0 * sin(2.0 * M_PI * t);
|
||||
|
||||
double f = apply_noise(data->curr_frequency, data->noise);
|
||||
|
||||
t += f / SAMPLE_RATE;
|
||||
if (t >= 1.0) {
|
||||
t -= floor(t);
|
||||
}
|
||||
|
||||
data->phase = t;
|
||||
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0.0;
|
||||
data->phase = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
buffer[i] = (int16_t)sample;
|
||||
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0;
|
||||
}
|
||||
}
|
||||
pa_stream_write(s, buffer, length, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||
}
|
||||
|
||||
double get_closest_frequency(size_t num_samples, double input_frequency) {
|
||||
|
||||
double samples_per_cycle = SAMPLE_RATE / input_frequency;
|
||||
|
||||
double adjusted_frequency = SAMPLE_RATE / (num_samples / floor(num_samples/samples_per_cycle) );
|
||||
|
||||
return adjusted_frequency;
|
||||
}
|
||||
|
||||
void engine_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
SoundData* data = (SoundData*)userdata;
|
||||
double freq = data->curr_frequency;
|
||||
|
||||
size_t num_samples = length / sizeof(int16_t);
|
||||
freq = get_closest_frequency( num_samples, freq );
|
||||
|
||||
//size_t num_samples = (size_t) (DURATION * SAMPLE_RATE);
|
||||
int16_t buffer[num_samples];
|
||||
|
||||
//double t = 0;
|
||||
for (size_t i = 0; i < num_samples; i++) {
|
||||
|
||||
double t = data->phase;
|
||||
|
||||
double sample = ((double)data->curr_amplitude/100) * 32767.0 * sin( 2.0 * M_PI * freq * t );
|
||||
double sample = ((double)data->curr_amplitude/100) * 32767.0 * sin( 2.0 * M_PI * t );
|
||||
|
||||
buffer[i] = (int16_t)sample;
|
||||
|
||||
t += 1.0 / SAMPLE_RATE;
|
||||
if (t >= SAMPLE_RATE) {
|
||||
t = 0;
|
||||
double f = apply_noise(data->curr_frequency, data->noise);
|
||||
|
||||
t += f / SAMPLE_RATE;
|
||||
if (t >= 1.0) {
|
||||
t -= floor(t);
|
||||
}
|
||||
|
||||
data->phase = t;
|
||||
}
|
||||
data->phase = round(data->phase);
|
||||
|
||||
pa_stream_write(s, buffer, length, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||
}
|
||||
@@ -166,7 +191,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||
// recommended settings, i.e. server uses sensible values
|
||||
pa_buffer_attr buffer_attr;
|
||||
buffer_attr.maxlength = (uint32_t) 32767;
|
||||
buffer_attr.tlength = (uint32_t) -1;
|
||||
buffer_attr.tlength = (uint32_t) 2048;
|
||||
buffer_attr.prebuf = (uint32_t) -1;
|
||||
buffer_attr.minreq = (uint32_t) -1;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
||||
}
|
||||
sounddevice->sounddata.last_gear = simdata->gear;
|
||||
|
||||
slogt("set gear frequency to %i", sounddevice->sounddata.curr_frequency);
|
||||
slogt("set gear frequency to %f", sounddevice->sounddata.curr_frequency);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulati
|
||||
{
|
||||
case SOUND_EFFECT_MODULATION_FREQUENCY:
|
||||
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_frequency = trunc(modulated_effect);
|
||||
sounddevice->sounddata.curr_frequency = modulated_effect;
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
slogt("set curr frequency to %i from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency);
|
||||
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency);
|
||||
break;
|
||||
case SOUND_EFFECT_MODULATION_AMPLIFY:
|
||||
modulated_effect = ((sounddevice->sounddata.amplitudeMax - sounddevice->sounddata.amplitude) * raw_effect) + sounddevice->sounddata.amplitude;
|
||||
@@ -80,7 +80,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -177,6 +177,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
|
||||
slogi("pan is: %i", sds.pan);
|
||||
slogi("channels is: %i", sds.channels);
|
||||
slogi("duration is: %f", sds.duration);
|
||||
slogi("noise is: %i", sds.noise);
|
||||
|
||||
|
||||
sounddevice->modulationType = sds.modulation;
|
||||
@@ -184,12 +185,13 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
|
||||
sounddevice->sounddata.frequencyMax = sds.frequencyMax;
|
||||
sounddevice->sounddata.amplitude = sds.amplitude;
|
||||
sounddevice->sounddata.amplitudeMax = sds.amplitudeMax;
|
||||
sounddevice->sounddata.noise = (double)sds.noise;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
|
||||
sounddevice->sounddata.phase = 0;
|
||||
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
|
||||
|
||||
const char* streamname= "Engine";
|
||||
|
||||
@@ -26,10 +26,11 @@ typedef struct
|
||||
uint32_t amplitude;
|
||||
uint32_t amplitudeMax;
|
||||
double duration;
|
||||
uint32_t curr_frequency;
|
||||
double curr_frequency;
|
||||
uint32_t curr_amplitude;
|
||||
double curr_duration;
|
||||
double phase;
|
||||
double noise;
|
||||
}
|
||||
SoundData;
|
||||
|
||||
|
||||
@@ -726,7 +726,35 @@ int tester(SimDevice* devices, int numdevices)
|
||||
simdata->Yvelocity = 100;
|
||||
simdata->Zvelocity = 0;
|
||||
|
||||
sleep(3);
|
||||
sleep(1);
|
||||
|
||||
fprintf(stdout, "Revving rpm from 1000 to 8000 and back\n");
|
||||
|
||||
for (int r = 0; r < 8000; r += 3)
|
||||
{
|
||||
simdata->rpms = 1000 + r;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
for (int r = 0; r < 8000; r += 3)
|
||||
{
|
||||
simdata->rpms = 9000 - r;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
fprintf(stdout, "Setting rpms to 1000\n");
|
||||
simdata->rpms = 1000;
|
||||
|
||||
@@ -747,6 +747,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.channels = 1;
|
||||
ds->sounddevsettings.duration = 2.0;
|
||||
ds->sounddevsettings.noise = 0;
|
||||
if (ds->effect_type == EFFECT_GEARSHIFT)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
@@ -762,6 +763,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||
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_int(device_settings, "noise", &ds->sounddevsettings.noise);
|
||||
|
||||
const char* temp = NULL;
|
||||
int found = 0;
|
||||
|
||||
@@ -185,6 +185,7 @@ typedef struct
|
||||
double duration;
|
||||
char* dev;
|
||||
SoundEffectModulationType modulation;
|
||||
int noise;
|
||||
}
|
||||
SoundDeviceSettings;
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ set(simulatorapi_source_files
|
||||
simapi/include/scs2data.h
|
||||
simapi/include/outgauge.h
|
||||
simapi/include/f12018.h
|
||||
simapi/include/rbrdata.h
|
||||
simapi/include/r3e.h
|
||||
simapi/include/wreckfest2data.h
|
||||
simapi/include/forza.h
|
||||
simapi/simmap/basicmap.h
|
||||
simapi/simmap/mapacdata.c
|
||||
simapi/simmap/mapacdata.h
|
||||
@@ -19,14 +23,22 @@ set(simulatorapi_source_files
|
||||
simapi/simapi/pcars2.h
|
||||
simapi/simapi/scs2.h
|
||||
simapi/simapi/outgauge.h
|
||||
simapi/simapi/wreckfest2.h
|
||||
simapi/simapi/f1.h
|
||||
simapi/simapi/rbr.h
|
||||
simapi/simapi/forzadef.h
|
||||
simapi/simapi/r3edef.h
|
||||
simapi/simapi/mapping/acmapper.c
|
||||
simapi/simapi/mapping/rf2mapper.c
|
||||
simapi/simapi/mapping/r3emapper.c
|
||||
simapi/simapi/mapping/pcars2mapper.c
|
||||
simapi/simapi/mapping/dirt2mapper.c
|
||||
simapi/simapi/mapping/scs2mapper.c
|
||||
simapi/simapi/mapping/outgaugemapper.c
|
||||
simapi/simapi/mapping/f12018mapper.c
|
||||
simapi/simapi/mapping/rbrmapper.c
|
||||
simapi/simapi/mapping/wreckfest2mapper.c
|
||||
simapi/simapi/mapping/forzamapper.c
|
||||
simapi/simapi/getpid.c
|
||||
simapi/simapi/getpid.h
|
||||
)
|
||||
|
||||
Submodule src/monocoque/simulatorapi/simapi updated: 4d5222dc6b...9106c64434
@@ -0,0 +1,8 @@
|
||||
Package: monocoque
|
||||
Version: 1
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: Paul Jones <paul@spacefreak18.xyz>
|
||||
Description: Racing Simulator Device Manager
|
||||
Depends: libpulse0,libconfig11,libargtable2-0,liblua5.4-0,libuv1t64,libserialport0,libxml2,libxdg-basedir1,libhidapi-hidraw0
|
||||
@@ -0,0 +1,8 @@
|
||||
Package: monocoque
|
||||
Version: 1
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: Paul Jones <paul@spacefreak18.xyz>
|
||||
Description: Racing Simulator Device Manager
|
||||
Depends: libpulse0,libconfig9,libargtable2-0,liblua5.4-0,libuv1t64,libserialport0,libxml2,libxdg-basedir1,libhidapi-hidraw0
|
||||
Reference in New Issue
Block a user