|
|
|
@ -1,5 +1,7 @@
@@ -1,5 +1,7 @@
|
|
|
|
|
#include "audio.h" |
|
|
|
|
#include <SDL2/SDL_keycode.h> |
|
|
|
|
#include <SDL2/SDL_mixer.h> |
|
|
|
|
#include <SDL2/SDL_mutex.h> |
|
|
|
|
|
|
|
|
|
void generate_audio(void); |
|
|
|
|
struct game_sounds game_sounds; |
|
|
|
@ -40,7 +42,7 @@ void start_audio(void) {
@@ -40,7 +42,7 @@ void start_audio(void) {
|
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Mix_AllocateChannels(20)) { |
|
|
|
|
if (Mix_AllocateChannels(20) < 0) { |
|
|
|
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -48,15 +50,43 @@ void start_audio(void) {
@@ -48,15 +50,43 @@ void start_audio(void) {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void play_game_sound(Mix_Chunk *chunk, int len, int channel) { |
|
|
|
|
void
|
|
|
|
|
play_game_sound(Mix_Chunk *chunk, int len, int channel)
|
|
|
|
|
{ |
|
|
|
|
if (Mix_Playing(channel)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mix_FadeInChannelTimed(channel, chunk, -1, 1, len); |
|
|
|
|
if(Mix_PlayChannelTimed(channel, chunk, -1, len) < 0) |
|
|
|
|
fprintf(stderr, "Unable to play audio: %s\n", SDL_GetError()); |
|
|
|
|
//Mix_FadeInChannelTimed(channel, chunk, -1, 1, len);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Uint8
|
|
|
|
|
pitchshift_hit(unsigned int t, void *arg)
|
|
|
|
|
{ |
|
|
|
|
double *hitt = arg; |
|
|
|
|
double hit = *hitt; |
|
|
|
|
hit = 6 - hit; |
|
|
|
|
int lower = 10 + 2 * (hit > 6 ? 6 : hit); |
|
|
|
|
int higher = 1 + (hit > 6 ? 6 : hit); |
|
|
|
|
// printf("mag %f higher %d lower %d\n", hit, higher, lower);
|
|
|
|
|
|
|
|
|
|
const double R=8000; // sample rate (samples per second)
|
|
|
|
|
const double C=125; // frequency of middle-C (hertz)
|
|
|
|
|
const double F=R/256; // bytebeat frequency of 1*t due to 8-bit truncation (hertz)
|
|
|
|
|
const double V=127; // a volume constant
|
|
|
|
|
double volume = (((t / 3000) > 2) ? 2 : t / 3000); |
|
|
|
|
|
|
|
|
|
return ((sin(t*2*M_PI/R*(125 + hit))+1)*10 + (sin(t*2*M_PI/R*(250 + hit))+1)*(50 + hit) + (sin(t*2*M_PI/R*(900 + hit))+1)*100 + (sin(t*2*M_PI/R*(150+ hit))+1)*5) ; |
|
|
|
|
|
|
|
|
|
return ((t < 3000) * ((t % higher) * (3000 - t % 3000) * 0.00351)); |
|
|
|
|
//+ ((t < 3500) * ((3500 - t % 3500)) * 0.0002 * (t % lower));
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void synthplay_now(Uint8 (*bbgen)(unsigned int t), int len) { |
|
|
|
|
void
|
|
|
|
|
synthplay_now(Uint8 (*bbgen)(unsigned int t, void *), void *arg, int len)
|
|
|
|
|
{ |
|
|
|
|
static Mix_Chunk *new_chunk = NULL; |
|
|
|
|
|
|
|
|
|
if (Mix_Playing(1)) { |
|
|
|
@ -66,13 +96,17 @@ void synthplay_now(Uint8 (*bbgen)(unsigned int t), int len) {
@@ -66,13 +96,17 @@ void synthplay_now(Uint8 (*bbgen)(unsigned int t), int len) {
|
|
|
|
|
if (new_chunk) |
|
|
|
|
Mix_FreeChunk(new_chunk); |
|
|
|
|
|
|
|
|
|
int generate_len = len * (512) * 8; |
|
|
|
|
int generate_len = len * (512); |
|
|
|
|
|
|
|
|
|
Uint8 raw_data[generate_len]; |
|
|
|
|
fill_audio(bbgen, raw_data, generate_len); |
|
|
|
|
|
|
|
|
|
unsigned int t = 1; |
|
|
|
|
for(int i = 0; i < generate_len; i++,t++) { |
|
|
|
|
raw_data[i] = bbgen(t, arg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
new_chunk = Mix_QuickLoad_RAW(raw_data, generate_len); |
|
|
|
|
Mix_PlayChannelTimed(1, new_chunk, -1, -1); |
|
|
|
|
Mix_PlayChannelTimed(1, new_chunk, -1, len); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -145,7 +179,7 @@ Uint8 func1(unsigned int t) {
@@ -145,7 +179,7 @@ Uint8 func1(unsigned int t) {
|
|
|
|
|
Uint8 collision_test(unsigned int t) { |
|
|
|
|
// try not to loop
|
|
|
|
|
return ((t < 3000) * ((t % 5) * (3000 - t % 3000) * 0.00351))
|
|
|
|
|
+ ((t < 3500) * ((3500 - t % 3500)) * 0.0002 * (t % 11)); |
|
|
|
|
+ ((t < 3500) * ((3500 - t % 3500)) * 0.0002 * (t % 14)); |
|
|
|
|
return ((t < 3000) * ((t % 5) * (3000 - t % 3000) * 0.00351))
|
|
|
|
|
+ ((4000 - t % 4000) * 0.0003 * (t % 128))
|
|
|
|
|
+ ((t < 3500) * ((3500 - t % 3500)) * 0.0002 * (t % 64)); // has a big low sound
|
|
|
|
@ -164,26 +198,27 @@ Uint8 rope_attach(unsigned int t) {
@@ -164,26 +198,27 @@ Uint8 rope_attach(unsigned int t) {
|
|
|
|
|
void generate_audio(void) { |
|
|
|
|
const int sfx_len_ms = 1000; |
|
|
|
|
unsigned int sfx_len = (G_AUDIO_SFREQ/1000) * G_AUDIO_BSIZE * sfx_len_ms; |
|
|
|
|
sfx_len = G_AUDIO_BSIZE; |
|
|
|
|
|
|
|
|
|
Uint8 *raw_data = malloc(sfx_len);
|
|
|
|
|
fill_audio(winch_sound, raw_data, sfx_len); |
|
|
|
|
game_sounds.rope_pull = Mix_QuickLoad_RAW(raw_data, sfx_len); |
|
|
|
|
Mix_Volume(BC_ROPE_PULL, MIX_MAX_VOLUME * 0.4); |
|
|
|
|
Mix_Volume(BC_ROPE_PULL, MIX_MAX_VOLUME * 0.3); |
|
|
|
|
|
|
|
|
|
Uint8 *raw_data2 = malloc(sfx_len);
|
|
|
|
|
fill_audio(collision_test, raw_data2, sfx_len); |
|
|
|
|
game_sounds.collision = Mix_QuickLoad_RAW(raw_data2, sfx_len); |
|
|
|
|
//Mix_Volume(BC_COLLISION, MIX_MAX_VOLUME);
|
|
|
|
|
Mix_Volume(BC_COLLISION, MIX_MAX_VOLUME * 1.2); |
|
|
|
|
|
|
|
|
|
Uint8 *raw_data3 = malloc(sfx_len);
|
|
|
|
|
fill_audio(big_hum, raw_data3, sfx_len); |
|
|
|
|
game_sounds.background = Mix_QuickLoad_RAW(raw_data3, sfx_len); |
|
|
|
|
Mix_Volume(BC_MUSIC, MIX_MAX_VOLUME * 0.2); |
|
|
|
|
Mix_Volume(BC_MUSIC, MIX_MAX_VOLUME * 0.1); |
|
|
|
|
|
|
|
|
|
Uint8 *raw_data4 = malloc(sfx_len);
|
|
|
|
|
fill_audio(rope_attach, raw_data4, sfx_len); |
|
|
|
|
game_sounds.rope_attach = Mix_QuickLoad_RAW(raw_data4, sfx_len); |
|
|
|
|
//Mix_Volume(BC_ROPE_ATTACH, MIX_MAX_VOLUME);
|
|
|
|
|
Mix_Volume(BC_ROPE_ATTACH, MIX_MAX_VOLUME * 0.1); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|