Add AMPLIFY modulation
This commit is contained in:
parent
161f311494
commit
bec6433969
|
|
@ -6,13 +6,12 @@
|
|||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
#include "usb_generic_shaker.h"
|
||||
#include "../sounddevice.h"
|
||||
|
||||
#define FORMAT PA_SAMPLE_S16LE
|
||||
#define SAMPLE_RATE (44100)
|
||||
#define AMPLITUDE .5
|
||||
#define AMPLITUDE 1
|
||||
#define DURATION 1.0
|
||||
|
||||
#ifndef M_PI
|
||||
|
|
@ -31,7 +30,7 @@ void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
|||
double sample = 0;
|
||||
if (data->frequency>0)
|
||||
{
|
||||
sample = AMPLITUDE * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * data->curr_duration);
|
||||
sample = ((double)data->curr_amplitude/100) * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * data->curr_duration);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ void engine_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
|||
for (size_t i = 0; i < num_samples; i++) {
|
||||
double t = data->phase;
|
||||
|
||||
double sample = AMPLITUDE * 32767.0 * sin( 2.0 * M_PI * freq * t );
|
||||
double sample = ((double)data->curr_amplitude/100) * 32767.0 * sin( 2.0 * M_PI * freq * t );
|
||||
|
||||
buffer[i] = (int16_t)sample;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,16 +27,6 @@ int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
|||
slogt("set gear frequency to %i", sounddevice->sounddata.curr_frequency);
|
||||
}
|
||||
|
||||
// we could make a vtable for these different effects too
|
||||
int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
sounddevice->sounddata.curr_frequency = simdata->rpms/60 + sounddevice->sounddata.frequency;
|
||||
//sounddevice->sounddata.table_size = 48000/(sounddevice->sounddata.frequency);
|
||||
|
||||
slogt("set engine frequency to %i", sounddevice->sounddata.curr_frequency);
|
||||
}
|
||||
|
||||
double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulationType modulation)
|
||||
{
|
||||
|
|
@ -44,17 +34,36 @@ double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulati
|
|||
switch (modulation)
|
||||
{
|
||||
case SOUND_EFFECT_MODULATION_FREQUENCY:
|
||||
modulated_effect = (sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect;
|
||||
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_frequency = modulated_effect;
|
||||
slogt("set frequency to %i 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;
|
||||
sounddevice->sounddata.curr_amplitude = modulated_effect;
|
||||
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, sounddevice->sounddata.amplitude);
|
||||
break;
|
||||
case SOUND_EFFECT_MODULATION_NONE:
|
||||
default:
|
||||
modulated_effect = raw_effect;
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
break;
|
||||
}
|
||||
|
||||
return modulated_effect;
|
||||
}
|
||||
|
||||
// we could make a vtable for these different effects too
|
||||
int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
|
||||
modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
|
||||
|
||||
}
|
||||
|
||||
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
|
@ -65,7 +74,6 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
|||
if (effect > 0)
|
||||
{
|
||||
effect = modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||
}
|
||||
else
|
||||
|
|
@ -153,8 +161,11 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
|
|||
|
||||
|
||||
slogi("volume is: %i", sds.volume);
|
||||
slogi("Modulation type: %i", sds.modulation);
|
||||
slogi("frequency is: %i", sds.frequency);
|
||||
slogi("frequency Max is: %i", sds.frequencyMax);
|
||||
slogi("amplitude is: %i", sds.amplitude);
|
||||
slogi("amplitude Max is: %i", sds.amplitudeMax);
|
||||
slogi("pan is: %i", sds.pan);
|
||||
slogi("channels is: %i", sds.channels);
|
||||
slogi("duration is: %f", sds.duration);
|
||||
|
|
@ -162,10 +173,16 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
|
|||
|
||||
sounddevice->modulationType = sds.modulation;
|
||||
sounddevice->sounddata.frequency = sds.frequency;
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.frequencyMax = sds.frequencyMax;
|
||||
sounddevice->sounddata.amplitude = sds.amplitude;
|
||||
sounddevice->sounddata.amplitudeMax = sds.amplitudeMax;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
|
||||
sounddevice->sounddata.phase = 0;
|
||||
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
|
||||
|
||||
const char* streamname= "Engine";
|
||||
switch (sounddevice->m.hapticeffect.effecttype) {
|
||||
|
|
|
|||
|
|
@ -19,12 +19,15 @@ SoundEffectModulationType;
|
|||
#define MAX_TABLE_SIZE (6000)
|
||||
typedef struct
|
||||
{
|
||||
int last_gear;
|
||||
uint8_t last_gear;
|
||||
int volume;
|
||||
uint32_t frequency;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t amplitude;
|
||||
uint32_t amplitudeMax;
|
||||
double duration;
|
||||
int curr_frequency;
|
||||
uint32_t curr_frequency;
|
||||
uint32_t curr_amplitude;
|
||||
double curr_duration;
|
||||
double phase;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -669,6 +669,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
slogi("reading configured sound device settings");
|
||||
ds->sounddevsettings.frequency = 0;
|
||||
ds->sounddevsettings.frequencyMax = 0;
|
||||
ds->sounddevsettings.amplitude = 50;
|
||||
ds->sounddevsettings.amplitudeMax = 50;
|
||||
ds->sounddevsettings.volume = 0;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.channels = 1;
|
||||
|
|
@ -683,6 +685,8 @@ 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, "frequencyMax", &ds->sounddevsettings.frequencyMax);
|
||||
config_setting_lookup_int(device_settings, "amplitude", &ds->sounddevsettings.amplitude);
|
||||
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->sounddevsettings.amplitudeMax);
|
||||
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);
|
||||
|
|
@ -709,7 +713,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
}
|
||||
else
|
||||
{
|
||||
if(strcicmp(temp, "FREQUENCY"))
|
||||
if(strcicmp(temp, "FREQUENCY") == 0)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_FREQUENCY;
|
||||
if(ds->sounddevsettings.frequencyMax == 0 || ds->sounddevsettings.frequencyMax < ds->sounddevsettings.frequency)
|
||||
|
|
@ -722,7 +726,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
slogi("Effect modulation found, set to FREQUENCY");
|
||||
}
|
||||
}
|
||||
else if(strcicmp(temp, "AMPLIFY"))
|
||||
else if(strcicmp(temp, "AMPLIFY") == 0)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_AMPLIFY;
|
||||
slogi("Effect modulation found, set to AMPLIFY");
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ typedef struct
|
|||
int lowbound_frequency;
|
||||
int upperbound_frequency;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t amplitudeMax;
|
||||
uint32_t amplitude;
|
||||
int pan;
|
||||
int channels;
|
||||
double duration;
|
||||
|
|
|
|||
Loading…
Reference in New Issue