Skip to content

Commit

Permalink
🔨 Fix erronious audio channel pitches being wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
SeedyROM committed Dec 1, 2024
1 parent ce65fa8 commit 7de0b31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/engine/audio/audio_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ void AudioChannel::stop() {
m_active = false;
m_currentFile = nullptr;
m_position = 0;
m_currentSpeed = 1.0f;
m_targetSpeed = 1.0f;
}

void AudioChannel::setVolume(float vol) {
Expand Down Expand Up @@ -379,10 +381,12 @@ void AudioEngine::audioCallback(float *buffer, size_t frames) {
}
}

int AudioEngine::findFreeChannel() const {
int AudioEngine::findFreeChannel() {
// Skip channel 0 (reserved for music)
for (size_t i = 1; i < MAX_CHANNELS; ++i) {
if (!m_channels[i].isActive()) {
// Optionally force a stop to ensure clean state
m_channels[i].stop();
return static_cast<int>(i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/audio/audio_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AudioEngine {

void processCommands();
void mixAudio(float *buffer, size_t frames);
[[nodiscard]] int findFreeChannel() const;
[[nodiscard]] int findFreeChannel();
};

}; // namespace ste

0 comments on commit 7de0b31

Please sign in to comment.