Browse Source

Add pokitto sound

merge-requests/1/head
Miloslav Číž 3 years ago
parent
commit
2d9cbe7997
  1. 7
      main.c
  2. 61
      platform_pokitto.h
  3. 3
      sounds.h

7
main.c

@ -2436,7 +2436,7 @@ void SFG_gameStepPlaying() @@ -2436,7 +2436,7 @@ void SFG_gameStepPlaying()
{
case SFG_WEAPON_KNIFE: sound = 255; break;
case SFG_WEAPON_ROCKET_LAUNCHER:
case SFG_WEAPON_SHOTGUN: sound = 2; break;
case SFG_WEAPON_SHOTGUN: sound = 2; break;
case SFG_WEAPON_PLASMAGUN:
case SFG_WEAPON_SOLUTION: sound = 4; break;
default: sound = 0; break;
@ -2445,11 +2445,6 @@ void SFG_gameStepPlaying() @@ -2445,11 +2445,6 @@ void SFG_gameStepPlaying()
if (sound != 255)
SFG_playSoundSafe(sound,255);
if (SFG_player.weapon != SFG_WEAPON_KNIFE)
SFG_playSoundSafe(
(SFG_player.weapon == SFG_WEAPON_SHOTGUN ||
SFG_player.weapon == SFG_WEAPON_MACHINE_GUN) ? 0 : 4,255);
if (ammo != SFG_AMMO_NONE)
SFG_player.ammo[ammo] -= projectileCount;

61
platform_pokitto.h

@ -1,7 +1,8 @@ @@ -1,7 +1,8 @@
/**
@file platform_pokitto.h
This is Pokitto implementation of the game front end.
This is Pokitto implementation of the game front end, using the official
PokittoLib.
by Miloslav Ciz (drummyfish), 2019
@ -44,8 +45,12 @@ @@ -44,8 +45,12 @@
#define SFG_RAYCASTING_SUBSAMPLE 2
#include "Pokitto.h"
#include "clock_11u6x.h"
#include "timer_11u6x.h"
#include "palette.h"
#include "sounds.h"
Pokitto::Core pokitto;
uint8_t *pokittoScreen;
@ -85,13 +90,66 @@ void SFG_getMouseOffset(int16_t *x, int16_t *y) @@ -85,13 +90,66 @@ void SFG_getMouseOffset(int16_t *x, int16_t *y)
*y = 0;
}
uint8_t audioBuff[SFG_SFX_SAMPLE_COUNT];
uint16_t audioPos = 0;
void onTimer() // for sound
{
if (Chip_TIMER_MatchPending(LPC_TIMER32_0, 1))
{
Chip_TIMER_ClearMatch(LPC_TIMER32_0, 1);
Pokitto::dac_write(audioBuff[audioPos]);
audioBuff[audioPos] = 127;
audioPos = (audioPos + 1) % SFG_SFX_SAMPLE_COUNT;
}
}
void timerInit(uint32_t samplingRate)
{
Chip_TIMER_Init(LPC_TIMER32_0);
Chip_TIMER_Reset(LPC_TIMER32_0);
Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 1);
Chip_TIMER_SetMatch(LPC_TIMER32_0, 1,
(Chip_Clock_GetSystemClockRate() / samplingRate));
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 1);
Chip_TIMER_Enable(LPC_TIMER32_0);
#define weirdNumber ((IRQn_Type) 18)
NVIC_ClearPendingIRQ(weirdNumber);
NVIC_SetVector(weirdNumber, (uint32_t) &onTimer);
NVIC_EnableIRQ(weirdNumber);
#undef weirdNumber
}
void SFG_playSound(uint8_t soundIndex, uint8_t volume)
{
uint8_t volumeStep = volume / 16;
uint16_t pos = audioPos;
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
{
int16_t mixedValue =
audioBuff[pos] - 127 + SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep;
mixedValue = (mixedValue > 0) ? ((mixedValue < 255) ? mixedValue : 255) : 0;
audioBuff[pos] = mixedValue;// SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep;
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0;
}
}
int main()
{
pokitto.begin();
timerInit(8000);
for (uint16_t i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
audioBuff[i] = 127;
pokitto.setFrameRate(255);
pokitto.display.setFont(fontTiny);
@ -115,3 +173,4 @@ int main() @@ -115,3 +173,4 @@ int main()
}
#endif // guard

3
sounds.h

@ -22,6 +22,9 @@ @@ -22,6 +22,9 @@
#define SFG_SFX_SAMPLE_COUNT 2048
#define SFG_SFX_SIZE (SFG_SFX_SAMPLE_COUNT / 2)
/**
Gets a 4-bit sound sample.
*/
#define SFG_GET_SFX_SAMPLE(soundIndex,sampleIndex) \
((sampleIndex % 2 == 0) ? \
(SFG_sounds[soundIndex][sampleIndex / 2] >> 4) : \

Loading…
Cancel
Save