mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-11-24 01:42:19 -05:00
Update csfml
This commit is contained in:
parent
2279e01ea5
commit
72712103cb
60
main_csfml.c
60
main_csfml.c
@ -28,6 +28,8 @@
|
||||
#define SFG_DIMINISH_SPRITES 1
|
||||
#define SFG_RESOLUTION_SCALEDOWN 1
|
||||
|
||||
#define MUSIC_VOLUME 16
|
||||
|
||||
#define WINDOW_SIZE (SFG_SCREEN_RESOLUTION_X * SFG_SCREEN_RESOLUTION_Y)
|
||||
|
||||
#include "game.h"
|
||||
@ -173,36 +175,63 @@ uint8_t SFG_load(uint8_t data[SFG_SAVE_SIZE])
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SFG_playSound(uint8_t soundIndex, uint8_t volume)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t soundPos = 0;
|
||||
|
||||
sfSoundStream *sound;
|
||||
|
||||
#define AUDIO_BUFFER_SIZE (SFG_SFX_SAMPLE_COUNT * 2)
|
||||
#define AUDIO_BUFFER_OFFSET 400
|
||||
|
||||
int16_t audioBuffer[AUDIO_BUFFER_SIZE];
|
||||
uint32_t audioUpdateFrame = 0; // game frame at which audio buffer fill happened
|
||||
|
||||
static inline int16_t mixSamples(int16_t sample1, int16_t sample2)
|
||||
{
|
||||
return sample1 + sample2;
|
||||
}
|
||||
|
||||
void SFG_playSound(uint8_t soundIndex, uint8_t volume)
|
||||
{
|
||||
uint16_t volumeScale = 1 << (volume / 37);
|
||||
|
||||
uint32_t pos = AUDIO_BUFFER_OFFSET +
|
||||
((SFG_game.frame - audioUpdateFrame) * SFG_MS_PER_FRAME * 8);
|
||||
|
||||
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
|
||||
{
|
||||
audioBuffer[pos] = mixSamples(audioBuffer[pos],
|
||||
(128 - SFG_GET_SFX_SAMPLE(soundIndex,i)) * volumeScale);
|
||||
|
||||
pos++;
|
||||
|
||||
if (pos >= AUDIO_BUFFER_SIZE)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sfBool soundFill(sfSoundStreamChunk *data, void *userdata)
|
||||
{
|
||||
for (uint32_t i = 0; i < AUDIO_BUFFER_SIZE - AUDIO_BUFFER_OFFSET; ++i)
|
||||
audioBuffer[i] = audioBuffer[i + AUDIO_BUFFER_OFFSET];
|
||||
|
||||
for (uint32_t i = AUDIO_BUFFER_SIZE - AUDIO_BUFFER_OFFSET; i < AUDIO_BUFFER_SIZE; ++i)
|
||||
audioBuffer[i] = 0;
|
||||
|
||||
for (uint32_t i = 0; i < AUDIO_BUFFER_OFFSET; ++i) // mix in the music
|
||||
{
|
||||
audioBuffer[i] = mixSamples((SFG_getNextMusicSample() -
|
||||
SFG_musicTrackAverages[SFG_MusicState.track]) * MUSIC_VOLUME,
|
||||
audioBuffer[i]);
|
||||
}
|
||||
|
||||
printf("sasa\n");
|
||||
data->samples = audioBuffer;
|
||||
data->sampleCount = AUDIO_BUFFER_SIZE;
|
||||
data->sampleCount = AUDIO_BUFFER_OFFSET;
|
||||
|
||||
audioUpdateFrame = SFG_game.frame;
|
||||
|
||||
return sfTrue;
|
||||
}
|
||||
|
||||
void soundSeek(sfTime t, void *userData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@ -261,6 +290,9 @@ sfSoundStream_play(sound);
|
||||
|
||||
}
|
||||
|
||||
sfSoundStream_stop(sound);
|
||||
sfSoundStream_destroy(sound);
|
||||
|
||||
sfSprite_destroy(windowSprite);
|
||||
sfTexture_destroy(windowTexture);
|
||||
sfRenderWindow_destroy(window);
|
||||
|
@ -85,7 +85,6 @@
|
||||
|
||||
#define MUSIC_VOLUME 16
|
||||
|
||||
|
||||
#if !SFG_OS_IS_MALWARE
|
||||
#include <signal.h>
|
||||
#endif
|
||||
@ -321,7 +320,7 @@ void audioFillCallback(void *userdata, uint8_t *s, int l)
|
||||
{
|
||||
s16[i] = musicOn ?
|
||||
mixSamples(audioBuff[audioPos], MUSIC_VOLUME *
|
||||
(SFG_getNextMusicSample()- SFG_musicTrackAverages[SFG_MusicState.track]))
|
||||
(SFG_getNextMusicSample() - SFG_musicTrackAverages[SFG_MusicState.track]))
|
||||
: audioBuff[audioPos];
|
||||
|
||||
audioBuff[audioPos] = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user