audio change
This commit is contained in:
parent
a170d88ccc
commit
5ca3629406
6
Makefile
6
Makefile
|
@ -73,18 +73,18 @@ SEM = 0.0.1
|
|||
COM != git rev-parse --short HEAD
|
||||
VER = $(SEM)-$(COM)
|
||||
|
||||
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DDUK_USE_SYMBOL_BUILTIN -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@
|
||||
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DDUK_USE_SYMBOL_BUILTIN -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -march=native -std=c99 -c $< -o $@
|
||||
|
||||
LIBPATH = -L$(BIN)
|
||||
|
||||
ifeq ($(OS), WIN32)
|
||||
LINKER_FLAGS = $(QFLAGS) -static
|
||||
ELIBS = engine ucrt yughc portaudio glfw3 opengl32 gdi32 ws2_32 ole32 winmm setupapi m
|
||||
ELIBS = engine ucrt yughc glfw3 opengl32 gdi32 ws2_32 ole32 winmm setupapi m
|
||||
CLIBS =
|
||||
EXT = .exe
|
||||
else
|
||||
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib -rdynamic
|
||||
ELIBS = engine pthread yughc portaudio asound glfw3 c m dl
|
||||
ELIBS = engine pthread yughc glfw3 c m dl
|
||||
CLIBS =
|
||||
endif
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ cpVect inflatepoint(cpVect a, cpVect b, cpVect c, float d)
|
|||
}
|
||||
|
||||
void inflatepoints(cpVect *r, cpVect *p, float d, int n)
|
||||
{ if (d == 0) {
|
||||
{
|
||||
if (d == 0) {
|
||||
for (int i = 0; i < n; i++)
|
||||
r[i] = p[i];
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#define LOG_ERROR 2
|
||||
#define LOG_CRITICAL 3
|
||||
|
||||
#define M_PI 3.14
|
||||
|
||||
extern char lastlog[];
|
||||
extern char consolelog[];
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "script.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "debug.h"
|
||||
#include "window.h"
|
||||
#include "editor.h"
|
||||
#include "engine.h"
|
||||
|
@ -26,6 +27,8 @@
|
|||
#include "stb_ds.h"
|
||||
#include <ftw.h>
|
||||
|
||||
#include "miniaudio.h"
|
||||
|
||||
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
|
||||
#define BYTE_TO_BINARY(byte) \
|
||||
(byte & 0x80 ? '1' : '0'), \
|
||||
|
@ -163,7 +166,7 @@ duk_idx_t vecarr2duk(duk_context *duk, cpVect *points, int n)
|
|||
{
|
||||
duk_idx_t arr = duk_push_array(duk);
|
||||
for (int i = 0; i < n; i++) {
|
||||
duk_idx_t varr = vect2duk(points[i]);
|
||||
vect2duk(points[i]);
|
||||
duk_put_prop_index(duk, arr, i);
|
||||
}
|
||||
|
||||
|
@ -373,18 +376,17 @@ duk_ret_t duk_spline_cmd(duk_context *duk)
|
|||
|
||||
for (int i = 0; i < n; i++) {
|
||||
duk_get_prop_index(duk, 4, i);
|
||||
|
||||
points[i] = duk2vec2(duk, -1);
|
||||
|
||||
duk_pop(duk);
|
||||
}
|
||||
|
||||
ts_bspline_set_control_points(&spline, points, NULL);
|
||||
|
||||
|
||||
int nsamples = duk_to_int(duk, 5);
|
||||
size_t nsamples = duk_to_int(duk, 5);
|
||||
cpVect samples[nsamples];
|
||||
int rsamples;
|
||||
static_assert(sizeof(tsReal)*2 == sizeof(cpVect));
|
||||
size_t rsamples;
|
||||
ts_bspline_sample(&spline, nsamples, &samples, &rsamples, NULL);
|
||||
|
||||
int arridx = duk_push_array(duk);
|
||||
|
@ -587,7 +589,7 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
break;
|
||||
|
||||
case 14:
|
||||
play_oneshot(make_sound(duk_to_string(duk, 1)));
|
||||
mini_sound(duk_to_string(duk,1));
|
||||
break;
|
||||
|
||||
case 15:
|
||||
|
@ -607,7 +609,7 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
break;
|
||||
|
||||
case 19:
|
||||
mix_master_vol(duk_to_number(duk, 1));
|
||||
mini_master(duk_to_number(duk,1));
|
||||
break;
|
||||
|
||||
case 20:
|
||||
|
@ -882,6 +884,22 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
case 86:
|
||||
ints2duk(phys2d_query_box_points(duk2vec2(duk, 1), duk2vec2(duk, 2), duk2cpvec2arr(duk,3), duk_to_int(duk,4)));
|
||||
return 1;
|
||||
|
||||
case 87:
|
||||
mini_music_play(duk_to_string(duk,1));
|
||||
return 0;
|
||||
|
||||
case 88:
|
||||
mini_music_pause();
|
||||
return 0;
|
||||
|
||||
case 89:
|
||||
mini_music_stop();
|
||||
return 0;
|
||||
|
||||
case 90:
|
||||
window_set_icon(duk_to_string(duk,1));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1353,7 +1371,7 @@ duk_ret_t duk_inflate_cpv(duk_context *duk)
|
|||
{
|
||||
cpVect *points = duk2cpvec2arr(duk,0);
|
||||
int n = duk_to_int(duk,1);
|
||||
float d = duk_to_number(duk,2);
|
||||
double d = duk_to_number(duk,2);
|
||||
|
||||
cpVect inflate_out[n];
|
||||
cpVect inflate_in[n];
|
||||
|
@ -1361,14 +1379,11 @@ duk_ret_t duk_inflate_cpv(duk_context *duk)
|
|||
inflatepoints(inflate_out, points, d, n);
|
||||
inflatepoints(inflate_in, points, -d, n);
|
||||
|
||||
vecarr2duk(duk,inflate_out,n);
|
||||
return 1;
|
||||
|
||||
duk_idx_t arr = duk_push_array(duk);
|
||||
duk_idx_t out = vecarr2duk(duk, inflate_out, n);
|
||||
duk_put_prop_index(duk,arr, out);
|
||||
duk_put_prop_index(duk,arr, 0);
|
||||
duk_idx_t in = vecarr2duk(duk, inflate_in, n);
|
||||
duk_put_prop_index(duk,arr,in);
|
||||
duk_put_prop_index(duk,arr,1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1450,7 +1465,7 @@ void ffi_load()
|
|||
DUK_FUNC(cursor_text,5);
|
||||
DUK_FUNC(gui_img, 2);
|
||||
|
||||
DUK_FUNC(inflate_cpv, 2);
|
||||
DUK_FUNC(inflate_cpv, 3);
|
||||
|
||||
DUK_FUNC(anim, 2);
|
||||
}
|
||||
|
|
92927
source/engine/miniaudio.h
Normal file
92927
source/engine/miniaudio.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -16,15 +16,7 @@
|
|||
#include "mix.h"
|
||||
#include "dsp.h"
|
||||
|
||||
#define DR_WAV_IMPLEMENTATION
|
||||
#include "dr_wav.h"
|
||||
|
||||
#define DR_MP3_IMPLEMENTATION
|
||||
#include "dr_mp3.h"
|
||||
|
||||
#include "portaudio.h"
|
||||
|
||||
#include "circbuf.h"
|
||||
#include "miniaudio.h"
|
||||
|
||||
#define TSF_IMPLEMENTATION
|
||||
#include "tsf.h"
|
||||
|
@ -88,23 +80,6 @@ static struct wav change_samplerate(struct wav w, int rate)
|
|||
return w;
|
||||
}
|
||||
|
||||
static int patestCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
|
||||
{
|
||||
bus_fill_buffers(outputBuffer, framesPerBuffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void check_pa_err(PaError e)
|
||||
{
|
||||
if (e != paNoError) {
|
||||
YughError("PA Error: %s", Pa_GetErrorText(e));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static PaStream *stream_def;
|
||||
|
||||
void wav_norm_gain(struct wav *w, double lv)
|
||||
{
|
||||
short tarmax = db2short(lv);
|
||||
|
@ -125,29 +100,19 @@ void wav_norm_gain(struct wav *w, double lv)
|
|||
}
|
||||
}
|
||||
|
||||
void print_devices()
|
||||
{
|
||||
int numDevices = Pa_GetDeviceCount();
|
||||
const PaDeviceInfo *deviceInfo;
|
||||
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
deviceInfo = Pa_GetDeviceInfo(i);
|
||||
|
||||
YughInfo("Device %i: channels %i, sample rate %f, name %s\n", i, deviceInfo->maxOutputChannels, deviceInfo->defaultSampleRate, deviceInfo->name);
|
||||
}
|
||||
}
|
||||
static ma_engine *engine;
|
||||
|
||||
void sound_init()
|
||||
{
|
||||
ma_result result;
|
||||
engine = malloc(sizeof(*engine));
|
||||
result = ma_engine_init(NULL, engine);
|
||||
if (result != MA_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
mixer_init();
|
||||
PaError err = Pa_Initialize();
|
||||
check_pa_err(err);
|
||||
|
||||
err = Pa_OpenDefaultStream(&stream_def, 0, CHANNELS, paInt16, SAMPLERATE, BUF_FRAMES, patestCallback, NULL);
|
||||
check_pa_err(err);
|
||||
|
||||
err = Pa_StartStream(stream_def);
|
||||
check_pa_err(err);
|
||||
}
|
||||
|
||||
struct wav *make_sound(const char *wav)
|
||||
|
@ -197,6 +162,37 @@ struct soundstream *soundstream_make()
|
|||
return new;
|
||||
}
|
||||
|
||||
void mini_sound(char *path)
|
||||
{
|
||||
ma_engine_play_sound(engine, path, NULL);
|
||||
}
|
||||
|
||||
static ma_sound music_sound;
|
||||
|
||||
void mini_music_play(char *path)
|
||||
{
|
||||
int result = ma_sound_init_from_file(engine, path, MA_SOUND_FLAG_NO_SPATIALIZATION, NULL, NULL, &music_sound);
|
||||
if (result != MA_SUCCESS) {
|
||||
YughInfo("DID NOT LOAD SOUND!");
|
||||
}
|
||||
ma_sound_start(&music_sound);
|
||||
}
|
||||
|
||||
void mini_music_pause()
|
||||
{
|
||||
ma_sound_stop(&music_sound);
|
||||
}
|
||||
|
||||
void mini_music_stop()
|
||||
{
|
||||
ma_sound_stop(&music_sound);
|
||||
}
|
||||
|
||||
void mini_master(float v)
|
||||
{
|
||||
ma_engine_set_volume(engine, v);
|
||||
}
|
||||
|
||||
void kill_oneshot(struct sound *s)
|
||||
{
|
||||
free(s);
|
||||
|
@ -210,6 +206,7 @@ void play_oneshot(struct wav *wav) {
|
|||
new->loop=0;
|
||||
new->frame = 0;
|
||||
new->endcb = kill_oneshot;
|
||||
|
||||
}
|
||||
|
||||
struct sound *play_sound(struct wav *wav)
|
||||
|
@ -263,10 +260,10 @@ int sound_stopped(const struct sound *s)
|
|||
|
||||
struct mp3 make_music(const char *mp3)
|
||||
{
|
||||
drmp3 new;
|
||||
if (!drmp3_init_file(&new, mp3, NULL)) {
|
||||
YughError("Could not open mp3 file %s.", mp3);
|
||||
}
|
||||
// drmp3 new;
|
||||
// if (!drmp3_init_file(&new, mp3, NULL)) {
|
||||
// YughError("Could not open mp3 file %s.", mp3);
|
||||
// }
|
||||
|
||||
struct mp3 newmp3 = {};
|
||||
return newmp3;
|
||||
|
|
|
@ -56,6 +56,12 @@ void audio_close();
|
|||
|
||||
void sound_fillbuf(struct sound *s, short *buf, int n);
|
||||
|
||||
void mini_sound(char *path);
|
||||
void mini_master(float v);
|
||||
void mini_music_play(char *path);
|
||||
void mini_music_pause();
|
||||
void mini_music_stop();
|
||||
|
||||
struct wav *make_sound(const char *wav);
|
||||
void free_sound(const char *wav);
|
||||
void wav_norm_gain(struct wav *w, double lv);
|
||||
|
|
|
@ -37,7 +37,7 @@ void mixer_init() {
|
|||
}
|
||||
|
||||
struct bus *first_free_bus(struct dsp_filter in) {
|
||||
assert(initted);
|
||||
// assert(initted);
|
||||
|
||||
for (int i = 0; i < 255; i++)
|
||||
if (!bus[i].on) {
|
||||
|
|
|
@ -52,6 +52,7 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
YughError("STBI failed to load file %s with message: %s", path, stbi_failure_reason());
|
||||
return NULL;
|
||||
}
|
||||
tex->data = data;
|
||||
|
||||
glGenTextures(1, &tex->id);
|
||||
|
||||
|
@ -96,7 +97,7 @@ struct Texture *texture_pullfromfile(const char *path)
|
|||
|
||||
|
||||
|
||||
stbi_image_free(data);
|
||||
// stbi_image_free(data);
|
||||
|
||||
if (shlen(texhash) == 0)
|
||||
sh_new_arena(texhash);
|
||||
|
|
|
@ -61,7 +61,7 @@ struct Texture {
|
|||
unsigned int id; /* ID reference for the GPU memory location of the texture */
|
||||
int width;
|
||||
int height;
|
||||
|
||||
unsigned char *data;
|
||||
struct TextureOptions opts;
|
||||
struct TexAnim anim;
|
||||
};
|
||||
|
|
|
@ -119,6 +119,7 @@ struct window *MakeSDLWindow(const char *name, int width, int height, uint32_t f
|
|||
void window_set_icon(const char *png)
|
||||
{
|
||||
icon = texture_pullfromfile(png);
|
||||
window_seticon(mainwin, icon);
|
||||
}
|
||||
|
||||
void window_destroy(struct window *w)
|
||||
|
@ -263,7 +264,7 @@ void window_seticon(struct window *w, struct Texture *icon)
|
|||
static GLFWimage images[1];
|
||||
images[0].width = icon->width;
|
||||
images[0].height = icon->height;
|
||||
//images[0].pixels = icon->data;
|
||||
images[0].pixels = icon->data;
|
||||
glfwSetWindowIcon(w->window, 1, images);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
#include "openglrender.h"
|
||||
#include "gameobject.h"
|
||||
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "miniaudio.h"
|
||||
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
#include "script.h"
|
||||
|
@ -162,8 +166,6 @@ int main(int argc, char **args) {
|
|||
|
||||
renderMS = 1.0/vidmode->refreshRate;
|
||||
|
||||
window_set_icon("icon.png");
|
||||
|
||||
if (ed)
|
||||
script_dofile("editor.js");
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue