Audio: implement NOTE->PITCH + control pitch -- the AL_PITCH was never applied (task #50)
The whole pitch system existed but was discarded: NoteAudioHandler captured the
MIDI note, ExecuteModel computed relativePitch from the control-chain cents --
and NOTHING ever called alSourcef(AL_PITCH). Every sample played at root.
Consequences fixed:
- The load-time 'chirping' ambience: an authored looped sequence (div=120
tempo=160, note 51 events on bank1:83) plays a rhythmic tick pitched ~9
semitones DOWN; at root it was a high click ('chirp'). Identified live via
the new BT_AUDIO_DUMP playing-source tape + user ear-match at cadence.
- Engine now revs: EngineMotor pitch rides the throttle (measured 1.0 -> 1.12).
- All sequence-authored patterns (alarms/klaxons/ambience) regain their pitch.
Implementation: BTNotePitchFactor(note) = 2^((note-60)/12); applied at all 3
patch-source StartImplementations (fresh attach) and all 3 ExecuteModels
(combined with the control-chain relativePitch, clamped 0.5..2.0 as before).
Uses the existing AudioSource::GetCurrentNoteValue().
Also: [seqcfg] sequence-config dump, g_bufferNames + BT_AUDIO_DUMP live tape
(1/s: every playing AL source with sample name/gain/pitch/loop),
tools/soundboard.py updated mapping.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e017f257a5
commit
37d4554440
@@ -1,3 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include "mungal4.h"
|
||||
#pragma hdrstop
|
||||
@@ -10,6 +11,18 @@
|
||||
#include "..\munga\player.h"
|
||||
#include "..\rp\vtv.h"
|
||||
|
||||
|
||||
// NOTE -> PITCH (task #50): the AWE32 played every patch at the requested MIDI
|
||||
// note relative to the sample root (60); sequences author notes (klaxon/ambience
|
||||
// rhythms are PITCHED patterns). The port captured noteValue but never applied
|
||||
// any pitch to the AL sources -- everything played at root (the "chirping"
|
||||
// ambience: an authored deep tick at note 51 sounded as a high click). Apply
|
||||
// pitch = 2^((note-60)/12) x the control-chain cents offset at start + per frame.
|
||||
static inline float BTNotePitchFactor(int note_value)
|
||||
{
|
||||
return (float)pow(2.0, ((double)note_value - 60.0) / 12.0);
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
//####################### L4AudioSpatialization #########################
|
||||
//#############################################################################
|
||||
@@ -924,6 +937,12 @@ void
|
||||
patch_resource->SetDistance(GetDistanceToSource());
|
||||
patch_resource->SetupPatch(channelSet);
|
||||
|
||||
{ // apply the requested note's pitch to the freshly attached sources
|
||||
float note_pitch = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, note_pitch);
|
||||
}
|
||||
|
||||
//
|
||||
// Set the channel to default control values
|
||||
//
|
||||
@@ -1034,6 +1053,11 @@ void
|
||||
pitch_offset = CalculateSourcePitchOffset();
|
||||
double relativePitch = pow(2.0,pitch_offset/1200.0);
|
||||
Clamp(relativePitch,0.5,2.0);
|
||||
{ // apply the combined control-chain + note pitch per frame
|
||||
float _np = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, (float)relativePitch * _np);
|
||||
}
|
||||
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -1210,6 +1234,12 @@ void
|
||||
patch_resource->SetDistance(GetDistanceToSource());
|
||||
patch_resource->SetupPatch(channelSet);
|
||||
|
||||
{ // apply the requested note's pitch to the freshly attached sources
|
||||
float note_pitch = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, note_pitch);
|
||||
}
|
||||
|
||||
/*patch_resource->SetDistance(GetDistanceToSource());
|
||||
for (i = 0; i < AudioChannelSetSize; i++)
|
||||
{
|
||||
@@ -1411,6 +1441,11 @@ void
|
||||
|
||||
double relativePitch = pow(2.0,pitch_offset/1200.0);
|
||||
Clamp(relativePitch,0.5,2.0);
|
||||
{ // apply the combined control-chain + note pitch per frame
|
||||
float _np = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, (float)relativePitch * _np);
|
||||
}
|
||||
|
||||
if (getenv("BT_AUDIO_SPATIAL")) { static int s_sp=0; if ((s_sp++ % 120) == 0)
|
||||
DEBUG_STREAM << "[spatial] dyn src=" << (channelSet.count>0?channelSet.sources[0]:0)
|
||||
@@ -1704,6 +1739,12 @@ void
|
||||
Check(patch_resource);
|
||||
patch_resource->SetDistance(GetDistanceToSource());
|
||||
patch_resource->SetupPatch(channelSet);
|
||||
|
||||
{ // apply the requested note's pitch to the freshly attached sources
|
||||
float note_pitch = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, note_pitch);
|
||||
}
|
||||
/*for (i = 0; i < AudioChannelSetSize; i++)
|
||||
{
|
||||
if ((channel = channelSet.GetNth(i)) != NULL)
|
||||
@@ -1931,6 +1972,11 @@ void
|
||||
pitch_offset = CalculateSourcePitchOffset();
|
||||
double relativePitch = pow(2.0,pitch_offset/1200.0);
|
||||
Clamp(relativePitch,0.5,2.0);
|
||||
{ // apply the combined control-chain + note pitch per frame
|
||||
float _np = BTNotePitchFactor((int)GetCurrentNoteValue());
|
||||
for (int _i = 0; _i < channelSet.count; ++_i)
|
||||
alSourcef(channelSet.sources[_i], AL_PITCH, (float)relativePitch * _np);
|
||||
}
|
||||
|
||||
Vector3D relative_position;
|
||||
Vector3D relative_velocity;
|
||||
|
||||
Reference in New Issue
Block a user