diff --git a/internal/c/libqb/include/audio.h b/internal/c/libqb/include/audio.h index 8d8071935..2d81576e7 100644 --- a/internal/c/libqb/include/audio.h +++ b/internal/c/libqb/include/audio.h @@ -86,7 +86,7 @@ void sub__sndrawdone(int32_t handle, int32_t passed); double func__sndrawlen(int32_t handle, int32_t passed); mem_block func__memsound(int32_t handle, int32_t targetChannel); -int32_t func__newsound(int32_t frames, int32_t channels, int32_t bits, int32_t rate, int32_t passed); +int32_t func__sndnew(int32_t frames, int32_t channels, int32_t bits); void snd_init(); void snd_un_init(); diff --git a/internal/c/parts/audio/audio.cpp b/internal/c/parts/audio/audio.cpp index 36f6faa69..e3cafccea 100644 --- a/internal/c/parts/audio/audio.cpp +++ b/internal/c/parts/audio/audio.cpp @@ -1829,24 +1829,16 @@ double func__sndrawlen(int32_t handle, int32_t passed) { /// The number of sample frames required /// The number of sound channels. This can be 1 (mono) or 2 (stereo)/param> /// The bit depth of the sound. This can be 8 (unsigned 8-bit), 16 (signed 16-bit) or 32 (FP32) -/// The sample rate of the sound. This will default to device sample rate -/// How many parameters were passed? /// A new sound handle if successful or 0 on failure -int32_t func__newsound(int32_t frames, int32_t channels, int32_t bits, int32_t rate, int32_t passed) { +int32_t func__sndnew(int32_t frames, int32_t channels, int32_t bits) { if (!audioEngine.isInitialized || frames <= 0) { AUDIO_DEBUG_CHECK(frames > 0); return INVALID_SOUND_HANDLE; } - // Set sample rate to engine sample rate if not passed - if (!passed) { - rate = audioEngine.sampleRate; - AUDIO_DEBUG_PRINT("Defaulting sample rate to %u", rate); - } - // Validate all parameters - if (rate <= 0 || (channels != 1 && channels != 2) || (bits != 16 && bits != 32 && bits != 8)) { - AUDIO_DEBUG_PRINT("Invalid channels (%i), bits (%i) or rate (%i)", channels, bits, rate); + if ((channels != 1 && channels != 2) || (bits != 16 && bits != 32 && bits != 8)) { + AUDIO_DEBUG_PRINT("Invalid channels (%i) or bits (%i)", channels, bits); return INVALID_SOUND_HANDLE; } @@ -1862,8 +1854,10 @@ int32_t func__newsound(int32_t frames, int32_t channels, int32_t bits, int32_t r audioEngine.soundHandles[handle]->maAudioBufferConfig = ma_audio_buffer_config_init( (bits == 32 ? ma_format::ma_format_f32 : (bits == 16 ? ma_format::ma_format_s16 : ma_format::ma_format_u8)), channels, frames, NULL, NULL); - // Set the sample rate - audioEngine.soundHandles[handle]->maAudioBufferConfig.sampleRate = rate; + // This currently has no effect. Sample rate always defaults to engine sample rate + // Sample rate support for audio buffer is coming in miniaudio version 0.12 + // Once we have support, we can add sample rate as an optional 4th parameter + // audioEngine.soundHandles[handle]->maAudioBufferConfig.sampleRate = audioEngine.sampleRate; // Allocate and initialize ma_audio_buffer audioEngine.maResult = @@ -1885,7 +1879,7 @@ int32_t func__newsound(int32_t frames, int32_t channels, int32_t bits, int32_t r return INVALID_SOUND_HANDLE; } - AUDIO_DEBUG_PRINT("Frames = %i, Channels = %i, Bits = %i, Rate = %i", frames, channels, bits, rate); + AUDIO_DEBUG_PRINT("Frames = %i, Channels = %i, Bits = %i", frames, channels, bits); return handle; } diff --git a/source/subs_functions/subs_functions.bas b/source/subs_functions/subs_functions.bas index 07e9bd0ec..d8d05767e 100644 --- a/source/subs_functions/subs_functions.bas +++ b/source/subs_functions/subs_functions.bas @@ -2060,15 +2060,14 @@ regid ' a740g: Feature request #28 clearid -id.n = qb64prefix$ + "NewSound" ' Name in CaMeL case +id.n = qb64prefix$ + "SndNew" ' Name in CaMeL case id.Dependency = DEPENDENCY_AUDIO_OUT ' QB64-PE library dependency id.subfunc = 1 ' 1 = function, 2 = sub -id.callname = "func__newsound" ' C/C++ function name -id.args = 4 ' number of arguments "passed" +id.callname = "func__sndnew" ' C/C++ function name +id.args = 3 ' number of arguments "passed" id.arg = MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) + MKL$(LONGTYPE - ISPOINTER) ' arguments & types -id.specialformat = "?,?,?[,?]" ' special format (optional in []; functions can have only one optional) id.ret = LONGTYPE - ISPOINTER ' return type for functions -id.hr_syntax = "_NEWSOUND(frames&, channels&, bits&[, rate&])" ' syntax help +id.hr_syntax = "_SNDNEW(frames&, channels&, bits&)" ' syntax help regid ' a740g: Feature request #28 diff --git a/source/subs_functions/syntax_highlighter_list.bas b/source/subs_functions/syntax_highlighter_list.bas index 851e861e2..0a7754603 100644 --- a/source/subs_functions/syntax_highlighter_list.bas +++ b/source/subs_functions/syntax_highlighter_list.bas @@ -6,5 +6,5 @@ listOfKeywords$ = listOfKeywords$ + "_GLPOPATTRIB@_GLPOPCLIENTATTRIB@_GLPOPMATRI listOfKeywords$ = listOfKeywords$ + "_SOFTWARE@_SQUAREPIXELS@_STRETCH@_ALLOWFULLSCREEN@_ALL@_ECHO@_INSTRREV@_TRIM$@_ACCEPTFILEDROP@_FINISHDROP@_TOTALDROPPEDFILES@_DROPPEDFILE@_DROPPEDFILE$@_SHR@_SHL@_ROR@_ROL@" ' a740g: added ROR & ROL listOfKeywords$ = listOfKeywords$ + "_DEFLATE$@_INFLATE$@_READBIT@_RESETBIT@_SETBIT@_TOGGLEBIT@$ASSERTS@_ASSERT@_CAPSLOCK@_NUMLOCK@_SCROLLLOCK@_TOGGLE@_CONSOLEFONT@_CONSOLECURSOR@_CONSOLEINPUT@_CINP@$NOPREFIX@$COLOR@$DEBUG@_ENVIRONCOUNT@$UNSTABLE@$MIDISOUNDFONT@" listOfKeywords$ = listOfKeywords$ + "_NOTIFYPOPUP@_MESSAGEBOX@_INPUTBOX$@_SELECTFOLDERDIALOG$@_COLORCHOOSERDIALOG@_OPENFILEDIALOG$@_SAVEFILEDIALOG$@" ' a740g: added common dialog keywords -listOfKeywords$ = listOfKeywords$ + "_STATUSCODE@_NEWSOUND@" +listOfKeywords$ = listOfKeywords$ + "_STATUSCODE@_SNDNEW@" diff --git a/tests/compile_tests/audio_mem_test/newsound_test.bas b/tests/compile_tests/audio_mem_test/newsound_test.bas index 25199d823..69fbffb5d 100644 --- a/tests/compile_tests/audio_mem_test/newsound_test.bas +++ b/tests/compile_tests/audio_mem_test/newsound_test.bas @@ -2,7 +2,7 @@ $Console:Only Option _Explicit Option _ExplicitArray -Dim h As Long: h = _NewSound(1024, 2, 32) +Dim h As Long: h = _SndNew(1024, 2, 32) Print "Handle ="; h Dim m As _MEM: m = _MemSound(h, 0)