Skip to content
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
3 changes: 2 additions & 1 deletion docs/LittlePiggyTrackerConf.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ They are currenly _mostly_ used for **W32** but might extend in the future to ot
- `AUDIODRIVER`: Allows to specify which driver to open. It takes the first drvier whose name matches the beginning of the string. For example, to force using a realtek soundcard instead of the default one, you can just specify “Real”
- `AUDIOBUFFERSIZE`: Allows to tweak the default buffersize used for the audio. If the piggy glitches, increase this value.
- `AUDIOPREBUFFERCOUNT`: Even if the computer has the ability to run the piggy full screen, some sound hardware needs nearly instant reply for the couple of first buffers. If you have upped the `AUDIOBUFFERSIZE` but still get glitches, try putting it back to something decent (like 512) and define `AUDIOPREBUFFERCOUNT` to be 2,3,… that way, a set of blank buffer will be queued, ready for the soundcard to grab, before the sequencer is actually kicked in.

- `AUDIOSAMPLERATE`: SDL2 Only, Modern Linux systems running pipewire often run at 48000 rather then 44100. This setting
allows you to run at the system default. SDL may use a different sample rate if the specified one is not supported. Currently 44100 and 48000 have been tested on Linux.

```xml
<CONFIG>
Expand Down
180 changes: 88 additions & 92 deletions sources/Adapters/LINUX/System/LINUXSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "LINUXSystem.h"
#include <libgen.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include "Adapters/SDL2/GUI/GUIFactory.h"
#include "Adapters/SDL2/GUI/SDLEventManager.h"
#include "Adapters/SDL2/GUI/SDLGUIWindowImp.h"
#include "Adapters/SDL2/Timer/SDLTimer.h"
#include "Adapters/Unix/FileSystem/UnixFileSystem.h"
#include "Adapters/Unix/Process/UnixProcess.h"
#include "Application/Controllers/ControlRoom.h"
#include "Application/Commands/NodeList.h"
#include "Application/Controllers/ControlRoom.h"
#include "Application/Model/Config.h"
#include "System/Console/Logger.h"
#include <libgen.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#ifdef DUMMYMIDI
#include "Adapters/Dummy/Midi/DummyMidi.h"
Expand Down Expand Up @@ -46,97 +46,95 @@ static int secbase = 0;
* starts the main loop
*/
int LINUXSystem::MainLoop() {
eventManager_->InstallMappings();
return eventManager_->MainLoop() ;
eventManager_->InstallMappings();
return eventManager_->MainLoop();
};

/*
* initializes the application
*/
void LINUXSystem::Boot(int argc,char **argv) {
void LINUXSystem::Boot(int argc, char **argv) {

SDL_setenv((char *)"SDL_VIDEO_X11_WMCLASS",(char *)"LittleGPTracker",1) ;
SDL_setenv((char *)"SDL_VIDEO_X11_WMCLASS", (char *)"LittleGPTracker", 1);

// Install System
System::Install(new LINUXSystem());
// Install System
System::Install(new LINUXSystem());

// Install FileSystem
FileSystem::Install(new UnixFileSystem());
// Install FileSystem
FileSystem::Install(new UnixFileSystem());

// Install aliases
char buff[1024];
ssize_t len = ::readlink("/proc/self/exe",buff,sizeof(buff)-1);
if (len != -1)
{
buff[len] = 0;
}
else
{
strcpy(buff,".");
}
Path::SetAlias("bin",dirname(buff)) ;
Path::SetAlias("root",".") ;
// Install aliases
char buff[1024];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len != -1) {
buff[len] = 0;
} else {
strcpy(buff, ".");
}
Path::SetAlias("bin", dirname(buff));
Path::SetAlias("root", ".");

// always use stdout, user can capture in launch script
Trace::GetInstance()->SetLogger(*(new StdOutLogger()));
// always use stdout, user can capture in launch script
Trace::GetInstance()->SetLogger(*(new StdOutLogger()));

// Process arguments
Config::GetInstance()->ProcessArguments(argc,argv) ;
// Process arguments
Config::GetInstance()->ProcessArguments(argc, argv);

// Install GUI Factory
I_GUIWindowFactory::Install(new GUIFactory()) ;
// Install GUI Factory
I_GUIWindowFactory::Install(new GUIFactory());

// Install Timers
TimerService::GetInstance()->Install(new SDLTimerService()) ;
// Install Timers
TimerService::GetInstance()->Install(new SDLTimerService());

#ifdef JACKAUDIO
Trace::Log("System","Installing JACK audio") ;
Audio::Install(new JackAudio(AudioSettings hints));
Trace::Log("System", "Installing JACK audio");
Audio::Install(new JackAudio(AudioSettings hints));
#endif

#ifdef RTAUDIO
Trace::Log("System","Installing RT audio") ;
AudioSettings hints ;
hints.bufferSize_= 256 ;
hints.preBufferCount_=2 ;
Audio::Install(new RTAudioStub(hints)) ;
Trace::Log("System", "Installing RT audio");
AudioSettings hints;
hints.bufferSize_ = 256;
hints.preBufferCount_ = 2;
Audio::Install(new RTAudioStub(hints));
#endif

#ifdef SDLAUDIO
Trace::Log("System","Installing SDL audio") ;
AudioSettings hint;
hint.bufferSize_ = 1024;
hint.preBufferCount_ = 8;
Audio::Install(new SDLAudio(hint));
Trace::Log("System", "Installing SDL audio");
AudioSettings hint;
hint.bufferSize_ = 1024;
hint.preBufferCount_ = 8;
hint.sampleRate_ = 44100;
Audio::Install(new SDLAudio(hint));
#endif

#ifdef DUMMYMIDI
Trace::Log("System","Installing DUMMY MIDI") ;
MidiService::Install(new DummyMidi());
Trace::Log("System", "Installing DUMMY MIDI");
MidiService::Install(new DummyMidi());
#endif

#ifdef JACKMIDI
Trace::Log("System","Installing JACK MIDI") ;
MidiService::Install(new JackMidiService()) ;
Trace::Log("System", "Installing JACK MIDI");
MidiService::Install(new JackMidiService());
#endif

#ifdef RTMIDI
Trace::Log("System","Installing RT MIDI") ;
MidiService::Install(new RTMidiService()) ;
Trace::Log("System", "Installing RT MIDI");
MidiService::Install(new RTMidiService());
#endif

// Install Threads
SysProcessFactory::Install(new UnixProcessFactory());
// Install Threads
SysProcessFactory::Install(new UnixProcessFactory());

if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0 ) {
return;
}
SDL_ShowCursor(SDL_DISABLE);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
return;
}
SDL_ShowCursor(SDL_DISABLE);

atexit(SDL_Quit);
atexit(SDL_Quit);

eventManager_ = I_GUIWindowFactory::GetInstance()->GetEventManager();
eventManager_ -> Init();
eventManager_ = I_GUIWindowFactory::GetInstance()->GetEventManager();
eventManager_->Init();
};

void LINUXSystem::Shutdown() {};
Expand All @@ -145,85 +143,83 @@ void LINUXSystem::Shutdown() {};
* get current time for status display
*/
unsigned long LINUXSystem::GetClock() {
struct timeval tp;

gettimeofday(&tp, NULL);
if (!secbase) {
secbase = tp.tv_sec;
return long(tp.tv_usec/1000.0);
}
return long((tp.tv_sec - secbase)*1000 + tp.tv_usec/1000.0);
struct timeval tp;

gettimeofday(&tp, NULL);
if (!secbase) {
secbase = tp.tv_sec;
return long(tp.tv_usec / 1000.0);
}
return long((tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000.0);
}

/*
* wraps sleep, guess we never sleep!
*/
void LINUXSystem::Sleep(int millisec) {
//if (millisec>0)
//::Sleep(millisec) ;
// if (millisec>0)
//::Sleep(millisec) ;
}

/*
* wraps malloc
*/
void *LINUXSystem::Malloc(unsigned size) {
void *ptr=malloc(size) ;
//Trace::Debug("alloc:%x (%d)",ptr,size) ;
return ptr ;
void *ptr = malloc(size);
// Trace::Debug("alloc:%x (%d)",ptr,size) ;
return ptr;
}

/*
* wraps free
*/
void LINUXSystem::Free(void *ptr) {
free(ptr);
}
void LINUXSystem::Free(void *ptr) { free(ptr); }

/*
* wraps memset
*/
void LINUXSystem::Memset(void *addr,char val,int size) {
void LINUXSystem::Memset(void *addr, char val, int size) {
#ifdef _64BIT
unsigned int ad = (intptr_t)addr;
#else
unsigned int ad=(unsigned int)addr;
unsigned int ad = (unsigned int)addr;
#endif
if (((ad&0x3)==0)&&((size&0x3)==0)) { // Are we 4-byte aligned ?
unsigned int intVal=0;
for (int i=0;i<4;i++) {
intVal=(intVal<<8)+val;
if (((ad & 0x3) == 0) && ((size & 0x3) == 0)) { // Are we 4-byte aligned ?
unsigned int intVal = 0;
for (int i = 0; i < 4; i++) {
intVal = (intVal << 8) + val;
}
unsigned int *dst=(unsigned int *)addr;
size_t intSize=size>>2 ;
unsigned int *dst = (unsigned int *)addr;
size_t intSize = size >> 2;

for (unsigned int i=0;i<intSize;i++) {
*dst++=intVal ;
for (unsigned int i = 0; i < intSize; i++) {
*dst++ = intVal;
}
} else {
memset(addr,val,size) ;
memset(addr, val, size);
};
};

/*
* wraps memcpy
*/
void *LINUXSystem::Memcpy(void *s1, const void *s2, int n) {
return memcpy(s1,s2,n) ;
return memcpy(s1, s2, n);
};

/*
* logprint
*/
void LINUXSystem::AddUserLog(const char *msg) {
fprintf(stderr,"LOG: %s\n",msg) ;
fprintf(stderr, "LOG: %s\n", msg);
};

/*
* print after quit
*/
void LINUXSystem::PostQuitMessage() {
SDLEventManager::GetInstance()->PostQuitMessage() ;
};
SDLEventManager::GetInstance()->PostQuitMessage();
};

/*
* get memory usage, guess it's infinite
Expand Down
58 changes: 32 additions & 26 deletions sources/Adapters/SDL2/Audio/SDLAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@
#include "SDLAudioDriver.h"
#include "Services/Audio/AudioOutDriver.h"

SDLAudio::SDLAudio(AudioSettings &hints):Audio(hints) {
hints_=hints;
SDLAudio::SDLAudio(AudioSettings &hints) : Audio(hints) {
hints_ = hints;
drv_ = NULL;
}

SDLAudio::~SDLAudio() {
}
SDLAudio::~SDLAudio() {}

void SDLAudio::Init() {
AudioSettings settings ;
settings.audioAPI_=GetAudioAPI();

settings.bufferSize_=GetAudioBufferSize() ;
settings.preBufferCount_=GetAudioPreBufferCount() ;
AudioSettings settings;
settings.audioAPI_ = GetAudioAPI();

settings.bufferSize_ = GetAudioBufferSize();
settings.preBufferCount_ = GetAudioPreBufferCount();
settings.sampleRate_ = GetPreferredSampleRate();

SDLAudioDriver *drv=new SDLAudioDriver(settings) ;
AudioOut *out=new AudioOutDriver(*drv) ;
Insert(out) ;
} ;
drv_ = new SDLAudioDriver(settings);
AudioOut *out = new AudioOutDriver(*drv_);
Insert(out);
};

void SDLAudio::Close() {
IteratorPtr<AudioOut>it(GetIterator()) ;
for (it->Begin();!it->IsDone();it->Next()) {
AudioOut &current=it->CurrentItem() ;
current.Close() ;
}
} ;

int SDLAudio::GetMixerVolume() {
return 100 ;
} ;

void SDLAudio::SetMixerVolume(int volume) {
} ;
IteratorPtr<AudioOut> it(GetIterator());
for (it->Begin(); !it->IsDone(); it->Next()) {
AudioOut &current = it->CurrentItem();
current.Close();
}
};

int SDLAudio::GetSampleRate() {
if (!drv_) {
Trace::Error(
"AUDIO",
"Sample rate requested before audio driver is initialised!");
}
return drv_->GetSampleRate();
};

int SDLAudio::GetMixerVolume() { return 100; };

void SDLAudio::SetMixerVolume(int volume) {};
Loading
Loading