it compiles on linux with gcc now
parent
4039d4edf8
commit
6f01e60b10
|
@ -3,3 +3,5 @@
|
|||
*.dll
|
||||
reload-trigger
|
||||
*.wav
|
||||
*.so
|
||||
core
|
||||
|
|
8
ampler.c
8
ampler.c
|
@ -6,10 +6,10 @@
|
|||
#include "draw.c"
|
||||
|
||||
Ampler_state *init() {
|
||||
Ampler_state *state = malloc(sizeof Ampler_state);
|
||||
SDL_memset(state, 0, sizeof Ampler_state);
|
||||
Ampler_state *state = malloc(sizeof (Ampler_state));
|
||||
SDL_memset(state, 0, sizeof (Ampler_state));
|
||||
|
||||
state -> size = sizeof Ampler_state;
|
||||
state -> size = sizeof (Ampler_state);
|
||||
|
||||
SDL_AudioSpec want = { 0 }, have = { 0 };
|
||||
want.freq = SAMPLE_RATE;
|
||||
|
@ -42,7 +42,7 @@ Ampler_state *init() {
|
|||
int ampler_main(SDL_Window *w, SDL_Renderer *r, Ampler_state **u_data) {
|
||||
if *u_data == NULL do *u_data = init();
|
||||
|
||||
u32 old_size = (*u_data) -> size, new_size = sizeof Ampler_state;
|
||||
u32 old_size = (*u_data) -> size, new_size = sizeof(Ampler_state);
|
||||
if old_size < new_size do {
|
||||
printf("increasing size. %i to %i\n", old_size, new_size);
|
||||
Ampler_state *nu = malloc(new_size);
|
||||
|
|
12
audio.c
12
audio.c
|
@ -62,7 +62,7 @@ void sound_src_frame(Sound_src *s, s8 *mix[]) {
|
|||
|
||||
int audio_frame(Ampler_state *state) {
|
||||
int queued = SDL_GetQueuedAudioSize(state -> playdev);
|
||||
queued /= sizeof s16; // queued is in bytes
|
||||
queued /= sizeof (s16); // queued is in bytes
|
||||
|
||||
if queued > FRAME_SAMPLES * CHANNELS * 2 do return 0;
|
||||
// else puts("queued audio.");
|
||||
|
@ -72,8 +72,8 @@ int audio_frame(Ampler_state *state) {
|
|||
// TODO: We should use CHANNELS here
|
||||
// static s8 mix_l[FRAME_SAMPLES] = { 0 }, mix_r[FRAME_SAMPLES] = { 0 };
|
||||
s8 *mix_l = state->frame_mix[0], *mix_r = state->frame_mix[1];
|
||||
SDL_memset(mix_l, 0, FRAME_SAMPLES / sizeof s8);
|
||||
SDL_memset(mix_r, 0, FRAME_SAMPLES / sizeof s8);
|
||||
SDL_memset(mix_l, 0, FRAME_SAMPLES / sizeof (s8));
|
||||
SDL_memset(mix_r, 0, FRAME_SAMPLES / sizeof (s8));
|
||||
|
||||
s8 *mix[] = { mix_l, mix_r };
|
||||
foreach_ptr(Sound_src, snd, state -> sounds)
|
||||
|
@ -85,7 +85,7 @@ int audio_frame(Ampler_state *state) {
|
|||
for int t = 0; t < CHANNELS; t += 1 do
|
||||
frame[i * CHANNELS + t] = ((s16) (mix[t][i])) * vol;
|
||||
|
||||
if SDL_QueueAudio(state -> playdev, frame, sizeof frame) do
|
||||
if SDL_QueueAudio(state -> playdev, frame, sizeof (frame)) do
|
||||
puts(SDL_GetError());
|
||||
|
||||
return 1; // audio was qued
|
||||
|
@ -115,7 +115,7 @@ void load_sample(Ampler_state *state, const char *file_name) {
|
|||
}
|
||||
|
||||
const int chans = spec.channels;
|
||||
const int length = (bytes / sizeof s16) / chans;
|
||||
const int length = (bytes / sizeof (s16)) / chans;
|
||||
|
||||
snd -> track_len = length;
|
||||
snd -> speed = 1.0f;
|
||||
|
@ -124,7 +124,7 @@ void load_sample(Ampler_state *state, const char *file_name) {
|
|||
snd -> end = snd->track_len;
|
||||
snd -> state = SND_STOPPED;
|
||||
snd -> note_speed = 1.0f; // TODO: Look up a note ?
|
||||
SDL_memset(snd->name, 0, sizeof snd->name);
|
||||
SDL_memset(snd->name, 0, sizeof (snd->name));
|
||||
for int i = 0; i < arraylen(snd->name) - 1; i += 1 do
|
||||
if file_name[i] == '\0' or file_name[i] == '.' do break;
|
||||
else snd->name[i] = file_name[i];
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
gcc ampler.c udp.c -o ampler.so -shared -lSDL2 -g --std c99 && echo > reload-trigger
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
gcc core.c -o core -lSDL2 -g
|
31
core.c
31
core.c
|
@ -6,11 +6,30 @@
|
|||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
# define SHARED_OBJECT "ampler.dll"
|
||||
# define SHARED_OBJECT_ACTIVE SHARED_OBJECT "-active.dll"
|
||||
#else
|
||||
# define SHARED_OBJECT "./ampler.so"
|
||||
# define SHARED_OBJECT_ACTIVE SHARED_OBJECT
|
||||
#endif
|
||||
|
||||
#define SHARED_MAIN "ampler_main"
|
||||
|
||||
|
||||
#define SHARED_OBJECT_ACTIVE SHARED_OBJECT "-active.dll"
|
||||
#ifdef __WIN32__
|
||||
int copy_shared_object() {
|
||||
if (system("copy " SHARED_OBJECT " " SHARED_OBJECT_ACTIVE " /Y")) {
|
||||
puts("failed copying to " SHARED_OBJECT_ACTIVE);
|
||||
// puts(SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int copy_shared_object() {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
puts("start.");
|
||||
|
@ -25,16 +44,10 @@ int main(int argc, char **argv) {
|
|||
r = SDL_CreateRenderer(w, -1,
|
||||
SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
||||
|
||||
//SDL_CreateWindowAndRenderer(
|
||||
// 1080, 480, SDL_WINDOW_RESIZABLE, &w, &r);
|
||||
|
||||
void *u_data = NULL;
|
||||
while (1) {
|
||||
if (system("copy " SHARED_OBJECT " " SHARED_OBJECT_ACTIVE " /Y")) {
|
||||
puts("failed copying to " SHARED_OBJECT_ACTIVE);
|
||||
// puts(SDL_GetError());
|
||||
if (copy_shared_object())
|
||||
break;
|
||||
}
|
||||
|
||||
void *so = SDL_LoadObject(SHARED_OBJECT_ACTIVE);
|
||||
if (so == 0) {
|
||||
|
|
2
draw.c
2
draw.c
|
@ -13,7 +13,7 @@ void draw_frame(SDL_Window *w, SDL_Renderer *r, Ampler_state *state) {
|
|||
// TODO: DRAW WITH X SCALE FACTOR
|
||||
// TODO: DRAW SMOLER
|
||||
SDL_SetRenderDrawColor(r, 0xFF, 0x00, 0x4D, 255);
|
||||
const space = (44100 * 8) / 512;
|
||||
const int space = (44100 * 8) / 512;
|
||||
const int t = 0; // TODO: DRAW L / R OVERLAPPED IN DIFF COLORS ?
|
||||
const int wav_h = 128;
|
||||
if 0 do
|
||||
|
|
35
udp.c
35
udp.c
|
@ -8,7 +8,14 @@
|
|||
* store from ip + port in message ?
|
||||
*/
|
||||
|
||||
#ifdef __WIN32__
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "ampler.h"
|
||||
|
||||
|
@ -19,8 +26,13 @@
|
|||
#undef while
|
||||
|
||||
// G l o b a L E v i L //
|
||||
#ifdef __WIN32__
|
||||
static SOCKET udp_sock;
|
||||
#else
|
||||
static int udp_sock;
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
void udp_init(Ampler_state *state) {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup
|
||||
WSADATA wsa;
|
||||
|
@ -53,12 +65,24 @@ void udp_init(Ampler_state *state) {
|
|||
if (bind_result == SOCKET_ERROR)
|
||||
printf("error: bind returned SOCKET_ERROR, WSAGetLastError() = %i\n" , WSAGetLastError());
|
||||
}
|
||||
#else
|
||||
void udp_init(Ampler_state *state) {
|
||||
//
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
void udp_quit(Ampler_state *state) {
|
||||
closesocket(udp_sock);
|
||||
WSACleanup();
|
||||
}
|
||||
#else
|
||||
void udp_quit(Ampler_state *state) {
|
||||
// close(udp_sock);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
void recv_packet(Ampler_state *state) {
|
||||
char discard_buf[32] = { 0 }; // for dropped packets
|
||||
char *buf = discard_buf;
|
||||
|
@ -98,7 +122,13 @@ void recv_packet(Ampler_state *state) {
|
|||
if (0) // FOR DEBUGGING
|
||||
printf("%s:%d\t%s\n", from_ip_str, from_port, buf);
|
||||
}
|
||||
#else
|
||||
void recv_packet(Ampler_state *state) {
|
||||
//
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
void udp_frame(Ampler_state *state) {
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
|
||||
fd_set recv_fd_set;
|
||||
|
@ -133,6 +163,11 @@ void udp_frame(Ampler_state *state) {
|
|||
recv_packet(state);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void udp_frame(Ampler_state *state) {
|
||||
//
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue