add panning support

This commit is contained in:
Anthony Samms
2025-10-22 22:12:00 -04:00
parent 7e73ee24f1
commit 0f9cce50d9
7 changed files with 301 additions and 154 deletions

View File

@@ -277,6 +277,18 @@ class AudioEngine:
else:
print(f"Sound {name} not found")
def set_sound_pan(self, name: str, pan: float) -> None:
"""Set the pan of a specific sound"""
if name == 'don':
lib.set_sound_pan(self.don, pan) # type: ignore
elif name == 'kat':
lib.set_sound_pan(self.kat, pan) # type: ignore
elif name in self.sounds:
sound = self.sounds[name]
lib.set_sound_pan(sound, pan) # type: ignore
else:
print(f"Sound {name} not found")
# Music management
def load_music_stream(self, file_path: Path, name: str) -> str:
"""Load a music stream and return music ID"""

View File

@@ -18,6 +18,7 @@
#include <samplerate.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#define LOG_INFO 0
#define LOG_WARNING 1
@@ -220,13 +221,18 @@ static int port_audio_callback(const void *inputBuffer, void *outputBuffer,
if (audio_buffer->isSubBufferProcessed[currentSubBufferIndex]) {
// This part of the buffer is not ready, output silence
} else {
// Calculate pan gains (0.0 = full left, 0.5 = center, 1.0 = full right)
float left_gain = sqrtf(1.0f - audio_buffer->pan);
float right_gain = sqrtf(audio_buffer->pan);
for (unsigned long i = 0; i < framesThisPass; i++) {
unsigned long buffer_pos = ((audio_buffer->frameCursorPos + i) % audio_buffer->sizeInFrames) * AUDIO_DEVICE_CHANNELS;
unsigned long output_pos = (framesPerBuffer - framesToMix + i) * AUDIO_DEVICE_CHANNELS;
for (int ch = 0; ch < AUDIO_DEVICE_CHANNELS; ch++) {
float sample = buffer_data[buffer_pos + ch] * audio_buffer->volume;
out[output_pos + ch] += sample;
float gain = (ch == 0) ? left_gain : right_gain;
out[output_pos + ch] += sample * gain;
}
}
}

View File

@@ -97,7 +97,7 @@ class Background:
"""
self.renda.add_renda()
def update(self, current_time_ms: float, bpm: float, gauge):
def update(self, current_time_ms: float, bpm: float, gauge_1p, gauge_2p = None):
"""
Update the background.
@@ -107,24 +107,24 @@ class Background:
gauge (Gauge): The gauge object.
"""
if self.dancer is not None:
clear_threshold = gauge.clear_start[min(gauge.difficulty, 3)]
if gauge.gauge_length < clear_threshold:
current_milestone = min(self.max_dancers - 1, int(gauge.gauge_length / (clear_threshold / self.max_dancers)))
clear_threshold = gauge_1p.clear_start[min(gauge_1p.difficulty, 3)]
if gauge_1p.gauge_length < clear_threshold:
current_milestone = min(self.max_dancers - 1, int(gauge_1p.gauge_length / (clear_threshold / self.max_dancers)))
else:
current_milestone = self.max_dancers
if current_milestone > self.last_milestone and current_milestone < self.max_dancers:
self.dancer.add_dancer()
self.last_milestone = current_milestone
if self.bg_fever is not None:
if not self.is_clear and gauge.is_clear:
if not self.is_clear and gauge_1p.is_clear:
self.bg_fever.start()
if not self.is_rainbow and gauge.is_rainbow and self.fever is not None:
if not self.is_rainbow and gauge_1p.is_rainbow and self.fever is not None:
self.fever.start()
self.is_clear = gauge.is_clear
self.is_rainbow = gauge.is_rainbow
self.is_clear = gauge_1p.is_clear
self.is_rainbow = gauge_1p.is_rainbow
self.don_bg.update(current_time_ms, self.is_clear)
if self.don_bg_2 is not None:
self.don_bg_2.update(current_time_ms, self.is_clear)
self.don_bg_2.update(current_time_ms, gauge_2p.is_clear)
if self.bg_normal is not None:
self.bg_normal.update(current_time_ms)
if self.bg_fever is not None:

View File

@@ -129,7 +129,7 @@ class Chibi13(BaseChibi):
self.frame = 0
def draw(self, tex: TextureWrapper):
tex.draw_texture(self.name, 'tail', frame=self.frame, x=self.hori_move.attribute, y=-self.vert_move.attribute)
tex.draw_texture(self.name, 'tail', frame=self.frame, x=self.hori_move.attribute, y=-self.vert_move.attribute+(self.is_2p*535))
if self.scale.attribute == 0.75:
tex.draw_texture(self.name, str(self.index), frame=self.frame, x=self.hori_move.attribute, y=-self.vert_move.attribute+(self.is_2p*535))
else: