1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 12:40:36 +00:00

Revert changes to miniaudio.h, move changes elsewhere

Changing midiaudio.h will make it harder to incorporate new versions
into QB64-PE as they come out. To fix that I have reverted all the
changes to midiaudio.h and moved the few private parts we were using
into a separate 'filepath' API that's part of libqb.
This commit is contained in:
Matthew Kilgore 2022-09-08 23:59:19 -04:00
parent dcc181244c
commit cd5e312f5a
8 changed files with 186 additions and 88 deletions

View file

@ -1,6 +1,7 @@
libqb-objs-y += $(PATH_LIBQB)/src/threading.o
libqb-objs-y += $(PATH_LIBQB)/src/buffer.o
libqb-objs-y += $(PATH_LIBQB)/src/filepath.o
libqb-objs-y += $(PATH_LIBQB)/src/threading-$(PLATFORM).o

View file

@ -41,6 +41,9 @@
# endif
# define AUDIO_DEBUG_CHECK(_exp_) // Don't do anything in release builds
#endif
// We always use 48000
#define MA_DEFAULT_SAMPLE_RATE 48000
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,15 @@
#ifndef INCLUDE_LIBQB_FILEPATH_H
#define INCLUDE_LIBQB_FILEPATH_H
// Takes a path + filename, and returns just the filename portion
// Returns either NULL or empty string if it has none.
const char *filepath_get_filename(const char *path);
// Takes a filename and returns just the extension at the end
// Returns either NULL or empty string if it has none.
const char *filepath_get_extension(const char *fliename);
// Returns true if the path is to a file that matches the provided extension
bool filepath_has_extension(const char *path, const char *extension);
#endif

View file

@ -0,0 +1,77 @@
// Implementation of these functions was pulled from miniaudio.h (MIT)
#include "libqb-common.h"
#include <string.h>
const char *filepath_get_filename(const char *path)
{
const char *fileName;
if (path == NULL) {
return NULL;
}
fileName = path;
/* We just loop through the path until we find the last slash. */
while (path[0] != '\0') {
if (path[0] == '/' || path[0] == '\\') {
fileName = path;
}
path += 1;
}
/* At this point the file name is sitting on a slash, so just move forward. */
while (fileName[0] != '\0' && (fileName[0] == '/' || fileName[0] == '\\')) {
fileName += 1;
}
return fileName;
}
const char *filepath_get_extension(const char *path)
{
const char *extension;
const char *lastOccurance;
if (path == NULL) {
path = "";
}
extension = filepath_get_filename(path);
lastOccurance = NULL;
/* Just find the last '.' and return. */
while (extension[0] != '\0') {
if (extension[0] == '.') {
extension += 1;
lastOccurance = extension;
}
extension += 1;
}
return (lastOccurance != NULL) ? lastOccurance : extension;
}
bool filepath_has_extension(const char *path, const char *extension)
{
const char *ext1;
const char *ext2;
if (path == NULL || extension == NULL) {
return false;
}
ext1 = extension;
ext2 = filepath_get_extension(path);
#if defined(_MSC_VER) || defined(__DMC__)
return _stricmp(ext1, ext2) == 0;
#else
return strcasecmp(ext1, ext2) == 0;
#endif
}

View file

@ -22,6 +22,9 @@
// HEADER FILES
//-----------------------------------------------------------------------------------------------------
#include "libqb-common.h"
#include "audio.h"
#include "filepath.h"
#include <string.h>
#include "../miniaudio.h"
@ -458,7 +461,7 @@ static ma_result ma_tsf_init_file(const char *pFilePath, const ma_decoding_backe
}
// Check the file extension
if (!ma_path_extension_equal(pFilePath, "mid") && !ma_path_extension_equal(pFilePath, "midi")) {
if (!filepath_has_extension(pFilePath, "mid") && !filepath_has_extension(pFilePath, "midi")) {
return MA_INVALID_FILE;
}

View file

@ -18,6 +18,10 @@
//-----------------------------------------------------------------------------------------------------
// HEADER FILES
//-----------------------------------------------------------------------------------------------------
#include "libqb-common.h"
#include "audio.h"
#include "filepath.h"
#include <stdio.h>
#include <string.h>
@ -385,8 +389,8 @@ static ma_result ma_modplay_init_file(const char *pFilePath, const ma_decoding_b
}
// Check the file extension
if (!ma_path_extension_equal(pFilePath, "it") && !ma_path_extension_equal(pFilePath, "xm") && !ma_path_extension_equal(pFilePath, "s3m") &&
!ma_path_extension_equal(pFilePath, "mod")) {
if (!filepath_has_extension(pFilePath, "it") && !filepath_has_extension(pFilePath, "xm") && !filepath_has_extension(pFilePath, "s3m") &&
!filepath_has_extension(pFilePath, "mod")) {
return MA_INVALID_FILE;
}

View file

@ -42,6 +42,10 @@
//-----------------------------------------------------------------------------------------------------
// HEADER FILES
//-----------------------------------------------------------------------------------------------------
#include "libqb-common.h"
#include "audio.h"
#include "filepath.h"
#include <string.h>
#include <stdio.h>
@ -428,7 +432,7 @@ static ma_result ma_radv2_init_file(const char *pFilePath, const ma_decoding_bac
}
// Check the file extension
if (!ma_path_extension_equal(pFilePath, "rad")) {
if (!filepath_has_extension(pFilePath, "rad")) {
return MA_INVALID_FILE;
}

View file

@ -4234,7 +4234,6 @@ Retrieves the version of miniaudio as a string which can be useful for logging p
MA_API const char* ma_version_string(void);
/**************************************************************************************************************************************************************
Logging
@ -11018,89 +11017,6 @@ MA_API ma_bool32 ma_sound_group_is_playing(const ma_sound_group* pGroup);
MA_API ma_uint64 ma_sound_group_get_time_in_pcm_frames(const ma_sound_group* pGroup);
#endif /* MA_NO_ENGINE */
/*
* The below functions used to be private to miniaudio. They were moved out of
* the implementation section to allow us to make use of them in our decoders.
*/
#if !defined(_MSC_VER) && !defined(__DMC__)
#include <strings.h> /* For strcasecmp(). */
#endif
static const char* ma_path_file_name(const char* path)
{
const char* fileName;
if (path == NULL) {
return NULL;
}
fileName = path;
/* We just loop through the path until we find the last slash. */
while (path[0] != '\0') {
if (path[0] == '/' || path[0] == '\\') {
fileName = path;
}
path += 1;
}
/* At this point the file name is sitting on a slash, so just move forward. */
while (fileName[0] != '\0' && (fileName[0] == '/' || fileName[0] == '\\')) {
fileName += 1;
}
return fileName;
}
static const char* ma_path_extension(const char* path)
{
const char* extension;
const char* lastOccurance;
if (path == NULL) {
path = "";
}
extension = ma_path_file_name(path);
lastOccurance = NULL;
/* Just find the last '.' and return. */
while (extension[0] != '\0') {
if (extension[0] == '.') {
extension += 1;
lastOccurance = extension;
}
extension += 1;
}
return (lastOccurance != NULL) ? lastOccurance : extension;
}
static ma_bool32 ma_path_extension_equal(const char* path, const char* extension)
{
const char* ext1;
const char* ext2;
if (path == NULL || extension == NULL) {
return MA_FALSE;
}
ext1 = extension;
ext2 = ma_path_extension(path);
#if defined(_MSC_VER) || defined(__DMC__)
return _stricmp(ext1, ext2) == 0;
#else
return strcasecmp(ext1, ext2) == 0;
#endif
}
#ifndef MA_DEFAULT_SAMPLE_RATE
#define MA_DEFAULT_SAMPLE_RATE 48000
#endif
#ifdef __cplusplus
}
#endif
@ -61823,6 +61739,34 @@ MA_API ma_result ma_decoder_init_memory(const void* pData, size_t dataSize, cons
#define MA_HAS_PATH_API
#endif
#if defined(MA_HAS_PATH_API)
static const char* ma_path_file_name(const char* path)
{
const char* fileName;
if (path == NULL) {
return NULL;
}
fileName = path;
/* We just loop through the path until we find the last slash. */
while (path[0] != '\0') {
if (path[0] == '/' || path[0] == '\\') {
fileName = path;
}
path += 1;
}
/* At this point the file name is sitting on a slash, so just move forward. */
while (fileName[0] != '\0' && (fileName[0] == '/' || fileName[0] == '\\')) {
fileName += 1;
}
return fileName;
}
static const wchar_t* ma_path_file_name_w(const wchar_t* path)
{
const wchar_t* fileName;
@ -61850,6 +61794,32 @@ static const wchar_t* ma_path_file_name_w(const wchar_t* path)
return fileName;
}
static const char* ma_path_extension(const char* path)
{
const char* extension;
const char* lastOccurance;
if (path == NULL) {
path = "";
}
extension = ma_path_file_name(path);
lastOccurance = NULL;
/* Just find the last '.' and return. */
while (extension[0] != '\0') {
if (extension[0] == '.') {
extension += 1;
lastOccurance = extension;
}
extension += 1;
}
return (lastOccurance != NULL) ? lastOccurance : extension;
}
static const wchar_t* ma_path_extension_w(const wchar_t* path)
{
const wchar_t* extension;
@ -61875,6 +61845,26 @@ static const wchar_t* ma_path_extension_w(const wchar_t* path)
return (lastOccurance != NULL) ? lastOccurance : extension;
}
static ma_bool32 ma_path_extension_equal(const char* path, const char* extension)
{
const char* ext1;
const char* ext2;
if (path == NULL || extension == NULL) {
return MA_FALSE;
}
ext1 = extension;
ext2 = ma_path_extension(path);
#if defined(_MSC_VER) || defined(__DMC__)
return _stricmp(ext1, ext2) == 0;
#else
return strcasecmp(ext1, ext2) == 0;
#endif
}
static ma_bool32 ma_path_extension_equal_w(const wchar_t* path, const wchar_t* extension)
{
const wchar_t* ext1;
@ -61916,6 +61906,7 @@ static ma_bool32 ma_path_extension_equal_w(const wchar_t* path, const wchar_t* e
}
#endif
}
#endif /* MA_HAS_PATH_API */