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

WIP: 64bit sound fonts #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion projects/Makefile.X64
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ OPT_FLAGS := -O3
OPT_FLAGS := -g
INCLUDES := $(ALSA_CFLAGS) $(JACK_CFLAGS) $(SDL_CFLAGS) -I$(PWD)/../sources
CFLAGS := $(OPT_FLAGS) $(DEFINES) $(INCLUDES) -Wall
CXXFLAGS := $(CFLAGS) -std=gnu++03
CXXFLAGS := $(CFLAGS) -std=gnu++11
LIBS := $(ALSA_LIBS) $(JACK_LIBS) $(SDL_LIBS)
OUTPUT := ../lgpt
EXTENSION := x64
Expand Down
10 changes: 6 additions & 4 deletions sources/Application/Instruments/SamplePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ void SamplePool::PurgeSample(int i) {

bool SamplePool::loadSoundFont(const char *path) {

sfBankID id=SoundFontManager::GetInstance()->LoadBank(path) ;
printf("SamplePool::loadSoundFont\n");
sfBankID id=SoundFontManager::GetInstance()->LoadBank(path) ;
if (id==-1) {
Trace::Debug("SamplePool", "SoundFont failed to load!");
return false ;
}

Expand All @@ -246,13 +248,13 @@ bool SamplePool::loadSoundFont(const char *path) {
if (count_<MAX_PIG_SAMPLES) {
sfPresetHdr current=pHeaders[i] ;
wav_[count_]=new SoundFontPreset(id,i) ;
const char *name=pHeaders[i].achPresetName ;
const char *name = pHeaders[i].achPresetName;
names_[count_]=(char*)SYS_MALLOC(strlen(name)+1) ;
strcpy(names_[count_],name) ;
count_++ ;
}
}
/*

// Get Sample information

WORD headerCount=0 ;
Expand All @@ -270,5 +272,5 @@ bool SamplePool::loadSoundFont(const char *path) {
count_++ ;
}
}
*/ return true ;
return true ;
} ;
7 changes: 7 additions & 0 deletions sources/Application/Instruments/SoundFontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ sfBankID SoundFontManager::LoadBank(const char *path) {

sfBankID id=sfReadSFBFile((char *)path) ;
if (id==-1) {
printf("SoundFont failed to load!\n");
Trace::Debug("SoundFontManager", "SoundFont failed to load!");
return -1 ;
}
// open the file

I_File *fin=FileSystem::GetInstance()->Open(path,"r") ;
if (!fin) {
printf("SoundFont failed open file: %s\n", path);

Trace::Debug("SoundFontManager", "SoundFont failed open file: %s", path);
return false;
}

Expand All @@ -43,7 +48,9 @@ sfBankID SoundFontManager::LoadBank(const char *path) {
SFSAMPLEHDRPTR &headers=sfGetSampHdrs(id,&headerCount );

// Loop on every sample, load them and adapt the pointers
Trace::Debug("SoundFontManager", "Header count: %d", headerCount);

printf("Header count: %d\n", headerCount);
for (int i=0;i<headerCount;i++) {

sfSampleHdr &current=headers[i] ;
Expand Down
10 changes: 8 additions & 2 deletions sources/Externals/Soundfont/DATATYPE.H
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
************/

#include <limits.h>

#ifdef _64BIT
#include <cstdint>
#endif

/************
* Defines
Expand Down Expand Up @@ -84,7 +86,11 @@
* Typedefs
*************/

typedef char CHAR; /* 8 bit signed value */
//#ifdef _64BIT
// typedef signed char CHAR; /* 8 bit signed value */
//#else
typedef char CHAR;
//#endif
typedef short SHORT; /* 16 bit signed value was: INT */

#ifdef EMU_WINDOWS
Expand Down
9 changes: 6 additions & 3 deletions sources/Externals/Soundfont/ENAB.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ PURPOSE.
#include "SFDETECT.H"
#include "ENAB.H"

#define DEBUG_ENAB 1

using namespace::std ;
using namespace::soundfont ;

Expand Down Expand Up @@ -76,7 +78,7 @@ HydraClass *GetHydraPtr(int bankID) {
return bankNodes[bankID].pHydra;
}

sfBankID sfReadSFBFile(char *bankFileName)
sfBankID sfReadSFBFile(CHAR *bankFileName)
//-****************************************************************************
//
// Implementation Notes:
Expand Down Expand Up @@ -137,9 +139,10 @@ WORD i;
{
bankNodes[i].pHydra = pHF;
}
const char *bfn = (const char *)(bankFileName);

bankNodes[i].bankFileName = new CHAR[strlen(bankFileName)+1];
strcpy(bankNodes[i].bankFileName , bankFileName);
bankNodes[i].bankFileName = new CHAR[strlen(bfn)+1];
strcpy(bankNodes[i].bankFileName , bfn);

riff.OpenRIFF(bankFileName);
riff.FindCk("SMPL");
Expand Down
2 changes: 1 addition & 1 deletion sources/Externals/Soundfont/HYDRA.H
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef union unGenAmtTag
//// Standard list used in Phdr (Preset lists) ////
typedef struct sfPresetHdrTag
{
CHAR achPresetName[PRESETNAMESIZE]; // Name of preset
const CHAR achPresetName[PRESETNAMESIZE]; // Name of preset
WORD wPresetNum; // The number of the preset
WORD wPresetBank; // The preset bank number
WORD wBagNdx; // The index to sfPresetBag
Expand Down
40 changes: 30 additions & 10 deletions sources/Externals/Soundfont/RIFF.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,18 @@ SHORT RIFFClass::initRiffTokensArray()
WORD RIFFClass::OpenRIFF(CHAR* pName)
{
byWhereIsRIFFData = RIFF_ONDISK;

SHORT ret = RIFFOpen((LONG)pName);


if ((RIFFOpen((LONG)pName) != SUCCESS ) || (pFile == NULL))
if ((ret != SUCCESS ) || (pFile == NULL))
{
printf("RIFFOpen Error %d::%d %d 0x%X\n", ret, SUCCESS, errno,pFile);
SetError(errno); // Set inside RIFFOpen
return (uiErrorNdx = RIFF_OPENFILEERROR);
}

printf("InitRIFF()\n");
return (InitRIFF());

}
Expand Down Expand Up @@ -270,10 +275,13 @@ WORD RIFFClass::OpenRIFF(FSSpec* pSpecifier)
WORD RIFFClass::InitRIFF(void)
{

if (ReadCkHdr() != SUCCESS)
if (ReadCkHdr() != SUCCESS) {
printf("check HDR\n");
return (uiErrorNdx = RIFF_OPENFILEERROR);
else if (dwLastID != MAKE_ID(RIFF))
} else if ((int)dwLastID != (int)MAKE_ID(RIFF)) {
printf("MAKE_ID %d::%d\n",dwLastID, MAKE_ID(RIFF));
return (uiErrorNdx = RIFF_IDERROR);
}

dwRIFFSize = dwLastSize;
return (uiErrorNdx = SUCCESS);
Expand Down Expand Up @@ -314,9 +322,10 @@ WORD RIFFClass::ReadCkHdr(void)
} ;
dwLastID = ckHdr.dwCkID;
dwLastSize = ckHdr.dwCkSize;
printf("dwLastSizeA %d\n", (int) ckHdr.dwCkSize);
SwapDWORD(&dwLastSize);

if ((dwLastID == MAKE_ID(RIFF)) || (dwLastID == MAKE_ID(LIST))) {
if (((int)dwLastID == (int)MAKE_ID(RIFF)) || ((int)dwLastID == (int)MAKE_ID(LIST))) {

RIFFRead(&dwLastFormID, sizeof(dwLastFormID), 1);
chIdPtr=(char *)&dwLastFormID ;
Expand All @@ -340,7 +349,7 @@ WORD RIFFClass::ReadCkHdr(void)
WORD RIFFClass::Descend(void)
{
//// We are at a RIFF or LIST ID ////
if ((dwLastID == MAKE_ID(RIFF)) || (dwLastID == MAKE_ID(LIST)))
if (((int)dwLastID == (int)MAKE_ID(RIFF)) || ((int)dwLastID == (int)MAKE_ID(LIST)))
{
return (ReadCkHdr());
}
Expand All @@ -357,13 +366,17 @@ WORD RIFFClass::Descend(void)
//************************************************************
WORD RIFFClass::Ascend(void)
{
if (((DWORD) lLastFilePtr + dwLastSize) <= dwRIFFSize)
if (((uintptr_t) lLastFilePtr + dwLastSize) <= (uintptr_t)dwRIFFSize)
{
//// Our last chunk had a RIFF or LIST ID ////
printf("Ascend %d\n", dwLastSize);

if (dwLastFormID)
dwLastSize -= sizeof(DWORD);
// SL: IsssueHereMaybe.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at dwLastSize, this line seems suspect.

dwLastSize -= sizeof(uintptr_t);
printf("Ascend 2 %d\n", dwLastSize);

if ((RIFFSeek(lLastFilePtr + (LONG) dwLastSize, SEEK_SET)) == 0)
if ((RIFFSeek(lLastFilePtr + (uintptr_t) dwLastSize, SEEK_SET)) == 0)
return (ReadCkHdr());
else
return (RIFF_READFILEERROR);
Expand All @@ -378,20 +391,25 @@ WORD RIFFClass::Ascend(void)
//**************************************
WORD RIFFClass::FindCk(CHAR* pID)
{
printf("pID: %s\n", pID);
char tmp[4] ;
for (int i=0;i<4;i++)
{
tmp[i]=toupper(*pID++) ;
}
printf("tmp:%s\n",tmp);
DWORD dwID = MAKE_ID(tmp);

Reset();
ReadCkHdr();

while (TRUE)
{
if ((dwID == dwLastID) || // We found our chunk
(dwID == dwLastFormID))
//int * tsta= (int *)(long)dwID;
//int tstb = *tsta;
printf(" %d-%u-%u\n", dwID, dwLastID, dwLastFormID);
if (((int)dwID == (int)dwLastID) || // We found our chunk
((int)dwID == (int)dwLastFormID))
{
return (SUCCESS);
}
Expand Down Expand Up @@ -467,6 +485,7 @@ SHORT RIFFClass::RIFFOpen(LONG lPointer)
{
case RIFF_ONDISK:
pFile = fopen((CHAR *)lPointer, "rb");
printf("fopen: %d\n", errno);
return (errno);

#ifdef USE_MACINTOSH
Expand All @@ -475,6 +494,7 @@ SHORT RIFFClass::RIFFOpen(LONG lPointer)
#endif

default:
printf("Default\n");
return (1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion sources/Externals/Soundfont/RIFF.H
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class RIFFClass
SHORT fRefNum;
#endif

LONG lLastFilePtr; // The chunk in the file where we visited last
uintptr_t lLastFilePtr; // The chunk in the file where we visited last
DWORD dwLastID; // The ID of the last RIFF/LIST chunk visited
DWORD dwLastSize; // The size of our last visited chunk
DWORD dwLastFormID; // The last form/list-type we visited
Expand Down
Loading
Loading