|
|
|
@ -1,16 +1,17 @@
@@ -1,16 +1,17 @@
|
|
|
|
|
#include "audio.h" |
|
|
|
|
#include <SDL2/SDL_keycode.h> |
|
|
|
|
|
|
|
|
|
void generate_audio(void); |
|
|
|
|
struct game_sounds game_sounds; |
|
|
|
|
|
|
|
|
|
Uint8 big_hum(unsigned int t);
|
|
|
|
|
Uint8 func0(int t);
|
|
|
|
|
Uint8 func0(unsigned int t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fill_audio(void *func, Uint8 *stream, int len) { |
|
|
|
|
Uint8 (*wavegen)(int) = func; |
|
|
|
|
Uint8 (*wavegen)(unsigned int) = func; |
|
|
|
|
|
|
|
|
|
static int t = 1; |
|
|
|
|
unsigned int t = 1; |
|
|
|
|
for(int i = 0; i < len; i++,t++) { |
|
|
|
|
stream[i] = wavegen(t); |
|
|
|
|
} |
|
|
|
@ -38,14 +39,20 @@ void start_audio(void) {
@@ -38,14 +39,20 @@ void start_audio(void) {
|
|
|
|
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Mix_AllocateChannels(20)) { |
|
|
|
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
generate_audio(); |
|
|
|
|
Mix_Resume(-1); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void play_game_sound(Mix_Chunk *chunk, int len, int channel) { |
|
|
|
|
if (Mix_Playing(channel)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mix_FadeInChannelTimed(channel, chunk, -1, 1, len); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -97,10 +104,10 @@ void callbackfn(void *unused, Uint8 *stream, int len)
@@ -97,10 +104,10 @@ void callbackfn(void *unused, Uint8 *stream, int len)
|
|
|
|
|
/* Waveform Generators */ |
|
|
|
|
|
|
|
|
|
Uint8 big_hum(unsigned int t) { |
|
|
|
|
return ( (sin(t*2*3.14159265/16000*200)+1) * 20) + ( (sin(t*2*3.14159265/16000*110)+1) * 20) + ( (sin(t*2*3.14159265/16000*230)+1) * 20) + ( (sin((t % 80)*2*3.14159265/16000 * 6)+1) * 12); |
|
|
|
|
return ( (sin(t*2*3.14159265/8000*200)+1) * 20) + ( (sin(t*2*3.14159265/8000*110)+1) * 20) + ( (sin(t*2*3.14159265/8000*230)+1) * 20) + ( (sin((t % 80)*2*3.14159265/8000 * 6)+1) * 12); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned int sine_wave_sound(int t) { |
|
|
|
|
unsigned int sine_wave_sound(unsigned int t) { |
|
|
|
|
const double R=8000; // sample rate (samples per second)
|
|
|
|
|
const double C=261.625565; // frequency of middle-C (hertz)
|
|
|
|
|
const double F=R/256; // bytebeat frequency of 1*t due to 8-bit truncation (hertz)
|
|
|
|
@ -108,17 +115,18 @@ unsigned int sine_wave_sound(int t) {
@@ -108,17 +115,18 @@ unsigned int sine_wave_sound(int t) {
|
|
|
|
|
return (sin(t*2*M_PI/R*C)+1)*V; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned int winch_sound(int t) { |
|
|
|
|
return (t % 80) | (t % 36) | (6 * (t % 6)); |
|
|
|
|
Uint8 winch_sound(unsigned t) { |
|
|
|
|
return (((t % 80) | (t % 36) | (6 * (t % 6))) + 20) * 1.6; |
|
|
|
|
return ((t % 80) | (t % 36) | (6 * (t % 6))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned int beat_2(int t) { |
|
|
|
|
Uint8 beat_2(unsigned t) { |
|
|
|
|
return ((((t % 250) / 2)) | (t % 129)) % 110; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Uint8 func0(int t) { |
|
|
|
|
Uint8 func0(unsigned t) { |
|
|
|
|
int note = 18; |
|
|
|
|
if (t % 1240) { |
|
|
|
|
if (!(t % 1240)) { |
|
|
|
|
note = (1 + rand()) % 18 + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -126,26 +134,57 @@ Uint8 func0(int t) {
@@ -126,26 +134,57 @@ Uint8 func0(int t) {
|
|
|
|
|
return (t % note); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned int func1(int t) { |
|
|
|
|
Uint8 func1(unsigned int t) { |
|
|
|
|
int note = 10; |
|
|
|
|
if (!(t % 8000)) { |
|
|
|
|
note = (1 + rand()) % 10 + 5; |
|
|
|
|
printf("%d %d\n", t, note); |
|
|
|
|
} |
|
|
|
|
return ((t & 110) % 73 | (t % 1711)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
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
|
|
|
|
|
return (t % 4) * (4000 - t % 4000) * 0.01; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void generate_audio(void) { |
|
|
|
|
|
|
|
|
|
const int sfx_len_ms = 2000; |
|
|
|
|
Uint8 boop_noise(unsigned int t) { |
|
|
|
|
return ((t >> 10) & 42) * t; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Uint8 rope_attach(unsigned int t) { |
|
|
|
|
return (((2000 - (t % 2000)))/40 * (t % 20) | (t % 44) + 20) * 1.6; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void generate_audio(void) { |
|
|
|
|
const int sfx_len_ms = 1000; |
|
|
|
|
unsigned int sfx_len = (G_AUDIO_SFREQ/1000) * G_AUDIO_BSIZE * sfx_len_ms; |
|
|
|
|
Uint8 raw_data[sfx_len]; // 10 seconds
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
fill_audio(beat_2, raw_data, sfx_len); |
|
|
|
|
game_sounds.collision = Mix_QuickLoad_RAW(raw_data, sfx_len); |
|
|
|
|
Mix_Volume(BC_ROPE_PULL, MIX_MAX_VOLUME * 0.4); |
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|