Skip to content

Commit

Permalink
Merge pull request #565 from a740g/the-big-audio-library-update
Browse files Browse the repository at this point in the history
The big audio library update
  • Loading branch information
a740g authored Nov 8, 2024
2 parents f818d43 + 3142589 commit b479c60
Show file tree
Hide file tree
Showing 21 changed files with 4,194 additions and 3,116 deletions.
4 changes: 1 addition & 3 deletions internal/c/libqb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,6 @@ int32 convert_unicode(int32 src_fmt, void *src_buf, int32 src_size, int32 dest_f
#ifdef QB64_WINDOWS
void showvalue(__int64);
#endif
void sub_beep();

int32 lastfont = 48;
int32 *font = (int32 *)calloc(4 * (48 + 1), 1); // NULL=unused index
Expand Down Expand Up @@ -11782,8 +11781,7 @@ void qbs_print(qbs *str, int32 finish_on_new_line) {
} // 9

if (character == 7) {
// qb64_generatesound(783.99,0.2,0);
Sleep(250);
sub_beep();
goto skip;
}

Expand Down
23 changes: 15 additions & 8 deletions internal/c/libqb/include/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@
struct qbs;
struct mem_block;

void sub_sound(double frequency, double lengthInClockTicks, double volume, double panning, int32_t waveform, int32_t passed);
void sub_beep();
void sub_play(const qbs *str);
int32_t func_play(int32_t ignore);
double func_play(uint32_t voice, int32_t passed);
void sub_play(const qbs *str1, const qbs *str2, const qbs *str3, const qbs *str4, int32_t passed);
void sub_sound(float frequency, float lengthInClockTicks, float volume, float panPosition, int32_t waveform, float waveformParam, uint32_t voice,
int32_t option, int32_t passed);
void sub__wave(uint32_t voice, void *waveDefinition, uint32_t frameCount, int32_t passed);

int32_t func__sndrate();
int32_t func__sndopen(qbs *qbsFileName, qbs *qbsRequirements, int32_t passed);
void sub__sndclose(int32_t handle);
int32_t func__sndcopy(int32_t src_handle);
void sub__sndplay(int32_t handle);
void sub__sndplaycopy(int32_t src_handle, double volume, double x, double y, double z, int32_t passed);
void sub__sndplayfile(qbs *fileName, int32_t sync, double volume, int32_t passed);
void sub__sndplaycopy(int32_t src_handle, float volume, float x, float y, float z, int32_t passed);
void sub__sndplayfile(qbs *fileName, int32_t sync, float volume, int32_t passed);
void sub__sndpause(int32_t handle);
int32_t func__sndplaying(int32_t handle);
int32_t func__sndpaused(int32_t handle);
void sub__sndvol(int32_t handle, float volume);
void sub__sndloop(int32_t handle);
void sub__sndbal(int32_t handle, double x, double y, double z, int32_t channel, int32_t passed);
void sub__sndbal(int32_t handle, float x, float y, float z, int32_t channel, int32_t passed);
double func__sndlen(int32_t handle);
double func__sndgetpos(int32_t handle);
void sub__sndsetpos(int32_t handle, double seconds);
Expand All @@ -54,11 +56,16 @@ void sub__sndstop(int32_t handle);

int32_t func__sndopenraw();
void sub__sndraw(float left, float right, int32_t handle, int32_t passed);
void sub__sndrawdone(int32_t handle, int32_t passed);
void sub__sndrawbatch(void *sampleFrameArray, int32_t channels, int32_t handle, uint32_t frameCount, int32_t passed);
static inline void sub__sndrawdone(int32_t handle, int32_t passed) {
// Dummy function that does nothing
(void)handle;
(void)passed;
}
double func__sndrawlen(int32_t handle, int32_t passed);

mem_block func__memsound(int32_t handle, int32_t targetChannel, int32_t passed);
int32_t func__sndnew(int32_t frames, int32_t channels, int32_t bits);
int32_t func__sndnew(uint32_t frames, int32_t channels, int32_t bits);
void sub__midisoundbank(qbs *qbsFileName, qbs *qbsRequirements, int32_t passed);

void snd_init();
Expand Down
38 changes: 18 additions & 20 deletions internal/c/libqb/include/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <algorithm>
#include <cmath>
#include <stdint.h>
#include <stdio.h>
Expand All @@ -41,45 +42,42 @@ struct qbs;
int32_t func__loadimage(qbs *qbsFileName, int32_t bpp, qbs *qbsRequirements, int32_t passed);
void sub__saveimage(qbs *qbsFileName, int32_t imageHandle, qbs *qbsRequirements, int32_t passed);

static inline constexpr uint8_t image_get_bgra_red(const uint32_t c) { return (uint8_t)((c >> 16) & 0xFFu); }
static inline constexpr uint8_t image_get_bgra_red(uint32_t c) { return uint8_t((c >> 16) & 0xFFu); }

static inline constexpr uint8_t image_get_bgra_green(const uint32_t c) { return (uint8_t)((c >> 8) & 0xFFu); }
static inline constexpr uint8_t image_get_bgra_green(uint32_t c) { return uint8_t((c >> 8) & 0xFFu); }

static inline constexpr uint8_t image_get_bgra_blue(const uint32_t c) { return (uint8_t)(c & 0xFFu); }
static inline constexpr uint8_t image_get_bgra_blue(uint32_t c) { return uint8_t(c & 0xFFu); }

static inline constexpr uint8_t image_get_bgra_alpha(const uint32_t c) { return (uint8_t)(c >> 24); }
static inline constexpr uint8_t image_get_bgra_alpha(uint32_t c) { return uint8_t(c >> 24); }

static inline constexpr uint32_t image_get_bgra_bgr(const uint32_t c) { return (uint32_t)(c & 0xFFFFFFu); }
static inline constexpr uint32_t image_get_bgra_bgr(uint32_t c) { return c & 0xFFFFFFu; }

static inline constexpr uint32_t image_set_bgra_alpha(const uint32_t c, const uint8_t a = 0xFFu) { return uint32_t(c & 0xFFFFFFu) | (uint32_t(a) << 24); }
static inline constexpr uint32_t image_set_bgra_alpha(uint32_t c, uint8_t a = 0xFFu) { return (c & 0xFFFFFFu) | (uint32_t(a) << 24); }

static inline constexpr uint32_t image_make_bgra(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a = 0xFFu) {
return (uint32_t)(b) | ((uint32_t)(g) << 8) | ((uint32_t)(r) << 16) | ((uint32_t)(a) << 24);
static inline constexpr uint32_t image_make_bgra(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFFu) {
return uint32_t(b) | (uint32_t(g) << 8) | (uint32_t(r) << 16) | (uint32_t(a) << 24);
}

static inline constexpr int image_scale_5bits_to_8bits(const int v) { return (v << 3) | (v >> 2); }
static inline constexpr int image_scale_5bits_to_8bits(int v) { return (v << 3) | (v >> 2); }

static inline constexpr int image_scale_6bits_to_8bits(const int v) { return (v << 2) | (v >> 4); }
static inline constexpr int image_scale_6bits_to_8bits(int v) { return (v << 2) | (v >> 4); }

static inline constexpr uint32_t image_swap_red_blue(const uint32_t clr) {
return ((clr & 0xFF00FF00u) | ((clr & 0x00FF0000u) >> 16) | ((clr & 0x000000FFu) << 16));
}
static inline constexpr uint32_t image_swap_red_blue(uint32_t clr) { return ((clr & 0xFF00FF00u) | ((clr & 0x00FF0000u) >> 16) | ((clr & 0x000000FFu) << 16)); }

static inline constexpr uint8_t image_clamp_color_component(const int n) { return n < 0 ? 0 : n > 255 ? 255 : n; }
static inline constexpr uint8_t image_clamp_color_component(int n) { return uint8_t(std::clamp(n, 0, 255)); }

static inline float image_calculate_rgb_distance(const uint8_t r1, const uint8_t g1, const uint8_t b1, const uint8_t r2, const uint8_t g2, const uint8_t b2) {
auto delta_r = (float)r2 - (float)r1;
auto delta_g = (float)g2 - (float)g1;
auto delta_b = (float)b2 - (float)b1;
static inline float image_calculate_rgb_distance(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2) {
auto delta_r = float(r2) - float(r1);
auto delta_g = float(g2) - float(g1);
auto delta_b = float(b2) - float(b1);

return sqrtf(delta_r * delta_r + delta_g * delta_g + delta_b * delta_b);
}

static inline uint32_t image_get_color_delta(const uint8_t r1, const uint8_t g1, const uint8_t b1, const uint8_t r2, const uint8_t g2, const uint8_t b2) {
static inline uint32_t image_get_color_delta(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2) {
return uint32_t(::abs(long(r1) - long(r2)) + ::abs(long(g1) - long(g2)) + ::abs(long(b1) - long(b2)));
}

// Working with 32bit colors:
static inline constexpr uint32_t func__rgb32(int32_t r, int32_t g, int32_t b, int32_t a) {
return (image_clamp_color_component(a) << 24) | (image_clamp_color_component(r) << 16) | (image_clamp_color_component(g) << 8) |
image_clamp_color_component(b);
Expand Down
Loading

0 comments on commit b479c60

Please sign in to comment.