Skip to content

Commit

Permalink
Hacks to improve sound - will maybe clean up when i get over DEFCON C…
Browse files Browse the repository at this point in the history
…OVID!

But yeah, the speaker really didn't like the high frequency carrier wave, so I'm just outputting a 49716 Hz carrier which is the OPL frequency
  • Loading branch information
kilograham committed Aug 15, 2024
1 parent 320cc56 commit 1c85ec7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/doom/s_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ static channel_t *channels;
// Maximum volume of a sound effect.
// Internal default is max out of 0-15.

int sfxVolume = 6;
int sfxVolume = 11;

// Maximum volume of music.

int musicVolume = 6;
int musicVolume = 11;

// Internal volume level, ranging from 0-127

Expand Down
5 changes: 5 additions & 0 deletions src/pico/i_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ void I_GetEvent() {
#endif
#endif

#ifdef DEFCON32_BADGE
static const uint8_t bdef[] = {
DEFCON32_BADGE_SW_FN_PIN, 0, 0,
DEFCON32_BADGE_SW_START_PIN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_ESCAPE,
Expand All @@ -585,7 +586,10 @@ static const uint8_t bdef[] = {
static uint8_t buttons[count_of(bdef)/3];
static uint8_t keycodex[count_of(bdef)/3];
#include "hardware/gpio.h"
#endif

void I_GetEventTimeout(int key_timeout) {
#ifdef DEFCON32_BADGE
static int mods;
// this is a bit hacky, but just track the state
// of each of the keys we care about, and select a different function
Expand Down Expand Up @@ -618,6 +622,7 @@ void I_GetEventTimeout(int key_timeout) {
}
extern boolean show_fps;
show_fps = buttons[0];
#endif
#if PICO_ON_DEVICE && !NO_USE_UART
if (uart_is_readable(uart_default)) {
char c = uart_getc(uart_default);
Expand Down
15 changes: 13 additions & 2 deletions src/pico/i_picosound.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,19 @@ static void I_Pico_UpdateSound(void)
// let's collapse stereo to mono...
int16_t *samples = (int16_t *)buffer->buffer->bytes;
for(int i=0;i<buffer->sample_count * 2; i += 2) {
// ... and divide by 4 not 2 because the speaker is real bad
samples[i] = samples[i+1] = (samples[i] + samples[i+1])/4;
// hacky: we take 270Mhz / 5431 to be close to our sample rate of 49716 Hz which is a pain
// to change as that is the OPL2 freq
uint x = samples[i] + samples[i+1];
#ifdef DEFCON32_BADGE
// note 2x because the volume is so quiet - thus the need to saturate
pico_default_asm(
"ssat %0, #16, %0"
: "+r" (x));
x = 2715 + x * 2715 / 32768;
#else
x = 2715 + x * 2715 / 65536;
#endif
samples[i] = samples[i+1] = x;
}
give_audio_buffer(producer_pool, buffer);
}
Expand Down
6 changes: 3 additions & 3 deletions src/pico/pico_audio_pwm8/audio_pwm8.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ const audio_format_t *audio_pwm8_setup(const audio_format_t *intended_audio_form

dma_channel_config dma_config = dma_channel_get_default_config(dma_channel);

shared_state.slice_num = pwm_gpio_to_slice_num(config->pins[0]);
channel_config_set_dreq(&dma_config,
DREQ_DMA_TIMER0
PWM_DREQ_NUM(shared_state.slice_num)
);

// todo only true for stereo
channel_config_set_transfer_data_size(&dma_config, DMA_SIZE_32);
// todo only true for same pin
shared_state.slice_num = pwm_gpio_to_slice_num(config->pins[0]);
pwm_config pc = pwm_get_default_config();
pwm_config_set_wrap(&pc, 255);
pwm_config_set_wrap(&pc, 5431); // 270000000 / 49716 ish
pwm_init(shared_state.slice_num, &pc, true);
dma_channel_configure(dma_channel,
&dma_config,
Expand Down
3 changes: 2 additions & 1 deletion src/pico/pico_audio_pwm8/sample_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ audio_buffer_t *audio_pwm8_mono_to_stereo_consumer_take_s16(audio_connection_t *
}

audio_buffer_t *audio_pwm8_stereo_to_stereo_consumer_take_s16(audio_connection_t *connection, bool block) {
return consumer_pool_take<Stereo<FmtPWM8>, Stereo<FmtS16>>(connection, block);
// buffer conversion is done in i_picosound now, so just do a pass thru copy for now
return consumer_pool_take<Stereo<FmtS16>, Stereo<FmtS16>>(connection, block);
}

0 comments on commit 1c85ec7

Please sign in to comment.