Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio lib fixes #6

Merged
merged 34 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c349214
Fix #554
a740g Oct 15, 2024
93a9f92
Make dummy function sub__sndrawdone() inline
a740g Oct 16, 2024
7142328
Implement custom LFSR based noise generator
a740g Oct 16, 2024
fc924ec
Use C++17 std::clamp instead of custom implementations
a740g Oct 16, 2024
2746f8e
Add pink noise, brownian noise and pulse wave.
a740g Oct 16, 2024
52c21bd
Add pulse wave support to SOUND
a740g Oct 17, 2024
f10cc97
Add initial support for multiple PSG instances and pausing a RawStream
a740g Oct 18, 2024
b6b804e
Prep. for multiple PSG
a740g Oct 18, 2024
3fae3ee
Cleanup and fix argument data types in subs_functions.bas
a740g Oct 18, 2024
5679b92
Convert IS_SOUND_HANDLE_VALID macro to AudioEngine::IsValidHandle() m…
a740g Oct 19, 2024
ce99581
Refactor and move all non-top-level classes and functions inside Audi…
a740g Oct 19, 2024
a133238
Implement multichannel sound
a740g Oct 19, 2024
82faed2
Implement multi-channel PLAY
a740g Oct 19, 2024
89be8de
Cleanup multi-voice PSG logic
a740g Oct 20, 2024
dbfe653
Move PSG pausing logic from RawStream to PSG class
a740g Oct 20, 2024
d0eea22
Allow SOUND to work correctly with 0 frequency and 0 duration
a740g Oct 21, 2024
10160a7
Updated comments from VS to VSCode doxgen style.
a740g Oct 21, 2024
348a180
Increase LFSR noise cycle and move BEEP out of the audio library
a740g Oct 22, 2024
ee3deb5
Backport tinyfd_beep() changes from tinyfiledialogs v3.18.2
a740g Oct 23, 2024
e677d99
Implement SOUND WAIT | RESUME
a740g Oct 23, 2024
03bed2e
Make SOUND handle regular SOUND and WAIT/RESUME in one go
a740g Oct 23, 2024
79a492c
Implement _SNDRAW function
a740g Oct 24, 2024
949412c
Fix func__sndraw() arg validation
a740g Oct 24, 2024
03b0692
Implement initial ADSR envelope support
a740g Oct 26, 2024
a21a9f1
Implemented ADSR envelope in PLAY
a740g Oct 26, 2024
3e0aa22
Implement _WAVE & _SNDRAWBATCH
a740g Oct 28, 2024
df0b4e9
Make CHR$(7) beep when used
a740g Oct 28, 2024
de0eff6
Always query the engine sample rate from the engine rather than cachi…
a740g Oct 28, 2024
1b9a640
Merge branch 'QB64-Phoenix-Edition:main' into audio-lib-fixes
a740g Oct 31, 2024
4094c1c
Cleanup
a740g Nov 4, 2024
42e499b
Improve PSG voice synchronization
a740g Nov 4, 2024
14400f0
Move setting autoKill flag after calling sub__sndplay()
a740g Nov 5, 2024
0db63fd
Move sub_beep() declaration back into audio.h
a740g Nov 5, 2024
585d4af
Merge branch 'the-big-audio-library-update' into audio-lib-fixes
a740g Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 panning, 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