mirror of
https://github.com/dwhinham/mt32-pi.git
synced 2026-10-26 22:11:05 +00:00
Initial OPNMIDI integration
This commit is contained in:
1 parent
3e7dbcd06a
commit
8d2602c76e
10 files changed
+15837
-3
No files matched your search
@@ -96,4 +96,8 @@ LIBADLMIDIHOME=$(realpath external/libadlmidi)
|
||||
LIBADLMIDIBUILDDIR=build-libadlmidi
|
||||
LIBADLMIDILIB=$(LIBADLMIDIBUILDDIR)/libADLMIDI.a
|
||||
|
||||
LIBOPNMIDIHOME=$(realpath external/libopnmidi)
|
||||
LIBOPNMIDIBUILDDIR=build-libopnmidi
|
||||
LIBOPNMIDILIB=$(LIBOPNMIDIBUILDDIR)/libOPNMIDI.a
|
||||
|
||||
INIHHOME=$(realpath external/inih)
|
||||
@@ -31,6 +31,7 @@ OBJS := src/config.o \
|
||||
src/soundfontmanager.o \
|
||||
src/synth/mt32synth.o \
|
||||
src/synth/oplsynth.o \
|
||||
src/synth/opnsynth.o \
|
||||
src/synth/soundfontsynth.o \
|
||||
src/synth/synthbase.o \
|
||||
src/zoneallocator.o
|
||||
@@ -89,6 +90,9 @@ EXTRALIBS += $(FLUIDSYNTHLIB)
|
||||
INCLUDE += -I $(LIBADLMIDIHOME)/include
|
||||
EXTRALIBS += $(LIBADLMIDILIB)
|
||||
|
||||
INCLUDE += -I $(LIBOPNMIDIHOME)/include
|
||||
EXTRALIBS += $(LIBOPNMIDILIB)
|
||||
|
||||
#
|
||||
# Generate version string from git tag
|
||||
#
|
||||
|
||||
@@ -150,10 +150,28 @@ $(LIBADLMIDIBUILDDIR)/.done: $(CIRCLESTDLIBHOME)/.done
|
||||
@cmake --build $(LIBADLMIDIBUILDDIR) --target ADLMIDI_static
|
||||
@touch $@
|
||||
|
||||
#
|
||||
# Build libOPNMIDI
|
||||
#
|
||||
libopnmidi: $(LIBOPNMIDIBUILDDIR)/.done
|
||||
|
||||
$(LIBOPNMIDIBUILDDIR)/.done: $(CIRCLESTDLIBHOME)/.done
|
||||
@CFLAGS="$(CFLAGS_EXTERNAL)" \
|
||||
CXXFLAGS="$(CFLAGS_EXTERNAL)" \
|
||||
cmake -B $(LIBOPNMIDIBUILDDIR) \
|
||||
$(CMAKE_TOOLCHAIN_FLAGS) \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DWITH_MIDI_SEQUENCER=OFF \
|
||||
-DUSE_VGM_FILE_DUMPER=OFF \
|
||||
$(LIBOPNMIDIHOME) \
|
||||
>/dev/null
|
||||
@cmake --build $(LIBOPNMIDIBUILDDIR) --target OPNMIDI_static
|
||||
@touch $@
|
||||
|
||||
#
|
||||
# Build kernel itself
|
||||
#
|
||||
all: circle-stdlib mt32emu fluidsynth libadlmidi
|
||||
all: circle-stdlib mt32emu fluidsynth libadlmidi libopnmidi
|
||||
@$(MAKE) -f Kernel.mk $(KERNEL).img $(KERNEL).hex
|
||||
|
||||
#
|
||||
@@ -183,3 +201,6 @@ mrproper: clean
|
||||
|
||||
# Clean libADLMIDI
|
||||
@$(RM) -r $(LIBADLMIDIBUILDDIR)
|
||||
|
||||
# Clean libOPNMIDI
|
||||
@$(RM) -r $(LIBOPNMIDIBUILDDIR)
|
||||
+2
-1
@@ -38,7 +38,8 @@ public:
|
||||
#define ENUM_SYSTEMDEFAULTSYNTH(ENUM) \
|
||||
ENUM(MT32, mt32) \
|
||||
ENUM(SoundFont, soundfont) \
|
||||
ENUM(OPL, opl)
|
||||
ENUM(OPL, opl) \
|
||||
ENUM(OPN, opn)
|
||||
|
||||
#define ENUM_AUDIOOUTPUTDEVICE(ENUM) \
|
||||
ENUM(PWM, pwm) \
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "synth/mt32romset.h"
|
||||
#include "synth/mt32synth.h"
|
||||
#include "synth/oplsynth.h"
|
||||
#include "synth/opnsynth.h"
|
||||
#include "synth/soundfontsynth.h"
|
||||
#include "synth/synth.h"
|
||||
|
||||
@@ -114,6 +115,7 @@ private:
|
||||
bool InitMT32Synth();
|
||||
bool InitSoundFontSynth();
|
||||
bool InitOPLSynth();
|
||||
bool InitOPNSynth();
|
||||
|
||||
// Tasks for specific CPU cores
|
||||
void MainTask();
|
||||
@@ -216,6 +218,7 @@ private:
|
||||
CMT32Synth* m_pMT32Synth;
|
||||
CSoundFontSynth* m_pSoundFontSynth;
|
||||
COPLSynth* m_pOPLSynth;
|
||||
COPNSynth* m_pOPNSynth;
|
||||
|
||||
// MIDI receive buffer
|
||||
CRingBuffer<u8, MIDIRxBufferSize> m_MIDIRxBuffer;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// opnsynth.h
|
||||
//
|
||||
// mt32-pi - A baremetal MIDI synthesizer for Raspberry Pi
|
||||
// Copyright (C) 2020-2022 Dale Whinham <daleyo@gmail.com>
|
||||
//
|
||||
// This file is part of mt32-pi.
|
||||
//
|
||||
// mt32-pi is free software: you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// mt32-pi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// mt32-pi. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#ifndef _opnsynth_h
|
||||
#define _opnsynth_h
|
||||
|
||||
#include <circle/types.h>
|
||||
|
||||
#include <opnmidi.h>
|
||||
|
||||
#include "synth/synthbase.h"
|
||||
|
||||
class COPNSynth : public CSynthBase
|
||||
{
|
||||
public:
|
||||
COPNSynth(unsigned nSampleRate);
|
||||
virtual ~COPNSynth() override;
|
||||
|
||||
// CSynthBase
|
||||
virtual bool Initialize() override;
|
||||
virtual void HandleMIDIShortMessage(u32 nMessage) override;
|
||||
virtual void HandleMIDISysExMessage(const u8* pData, size_t nSize) override;
|
||||
virtual bool IsActive() override;
|
||||
virtual void AllSoundOff() override;
|
||||
virtual void SetMasterVolume(u8 nVolume) override;
|
||||
virtual size_t Render(s16* pOutBuffer, size_t nFrames) override;
|
||||
virtual size_t Render(float* pOutBuffer, size_t nFrames) override;
|
||||
virtual void ReportStatus() const override;
|
||||
|
||||
private:
|
||||
OPN2_MIDIPlayer* m_pSynth;
|
||||
|
||||
u8 m_nVolume;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -28,6 +28,7 @@ enum class TSynth
|
||||
MT32,
|
||||
SoundFont,
|
||||
OPL,
|
||||
OPN,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -34,6 +34,7 @@ verbose = off
|
||||
# mt32: Use mt32emu (Munt) for Roland MT-32 emulation
|
||||
# soundfont: Use FluidSynth for SoundFont synthesis
|
||||
# opl: Use ADLMIDI for Yamaha OPL synthesis
|
||||
# opn: Use OPNMIDI for Yamaha OPN synthesis
|
||||
default_synth = mt32
|
||||
|
||||
# Enable or disable support for USB devices.
|
||||
|
||||
+36
-1
@@ -121,7 +121,8 @@ CMT32Pi::CMT32Pi(CI2CMaster* pI2CMaster, CSPIMaster* pSPIMaster, CInterruptSyste
|
||||
m_pCurrentSynth(nullptr),
|
||||
m_pMT32Synth(nullptr),
|
||||
m_pSoundFontSynth(nullptr),
|
||||
m_pOPLSynth(nullptr)
|
||||
m_pOPLSynth(nullptr),
|
||||
m_pOPNSynth(nullptr)
|
||||
{
|
||||
s_pThis = this;
|
||||
}
|
||||
@@ -280,6 +281,9 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
|
||||
LCDLog(TLCDLogType::Startup, "Init ADLMIDI");
|
||||
InitOPLSynth();
|
||||
|
||||
LCDLog(TLCDLogType::Startup, "Init OPNMIDI");
|
||||
InitOPNSynth();
|
||||
|
||||
// Set initial synthesizer
|
||||
if (m_pConfig->SystemDefaultSynth == CConfig::TSystemDefaultSynth::MT32)
|
||||
m_pCurrentSynth = m_pMT32Synth;
|
||||
@@ -287,6 +291,8 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
|
||||
m_pCurrentSynth = m_pSoundFontSynth;
|
||||
else if (m_pConfig->SystemDefaultSynth == CConfig::TSystemDefaultSynth::OPL)
|
||||
m_pCurrentSynth = m_pOPLSynth;
|
||||
else if (m_pConfig->SystemDefaultSynth == CConfig::TSystemDefaultSynth::OPN)
|
||||
m_pCurrentSynth = m_pOPNSynth;
|
||||
|
||||
if (!m_pCurrentSynth)
|
||||
{
|
||||
@@ -299,6 +305,8 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
|
||||
m_pCurrentSynth = m_pSoundFontSynth;
|
||||
else if (m_pOPLSynth)
|
||||
m_pCurrentSynth = m_pOPLSynth;
|
||||
else if (m_pOPNSynth)
|
||||
m_pCurrentSynth = m_pOPNSynth;
|
||||
else
|
||||
{
|
||||
m_pLogger->Write(MT32PiName, LogPanic, "No synths available; ROMs/SoundFonts not found");
|
||||
@@ -437,6 +445,24 @@ bool CMT32Pi::InitOPLSynth()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMT32Pi::InitOPNSynth()
|
||||
{
|
||||
assert(m_pOPNSynth == nullptr);
|
||||
|
||||
m_pOPNSynth = new COPNSynth(m_pConfig->AudioSampleRate);
|
||||
if (!m_pOPNSynth->Initialize())
|
||||
{
|
||||
m_pLogger->Write(MT32PiName, LogWarning, "OPNMIDI init failed; no banks present?");
|
||||
delete m_pOPNSynth;
|
||||
m_pOPNSynth = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pOPNSynth->SetUserInterface(&m_UserInterface);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMT32Pi::MainTask()
|
||||
{
|
||||
CScheduler* const pScheduler = CScheduler::Get();
|
||||
@@ -1101,6 +1127,8 @@ void CMT32Pi::ProcessButtonEvent(const TButtonEvent& Event)
|
||||
SwitchSynth(TSynth::SoundFont);
|
||||
else if (m_pCurrentSynth == m_pSoundFontSynth)
|
||||
SwitchSynth(TSynth::OPL);
|
||||
else if (m_pCurrentSynth == m_pOPLSynth)
|
||||
SwitchSynth(TSynth::OPN);
|
||||
else
|
||||
SwitchSynth(TSynth::MT32);
|
||||
}
|
||||
@@ -1165,6 +1193,11 @@ void CMT32Pi::SwitchSynth(TSynth NewSynth)
|
||||
pNewSynth = m_pOPLSynth;
|
||||
pModeString = "OPL mode";
|
||||
break;
|
||||
|
||||
case TSynth::OPN:
|
||||
pNewSynth = m_pOPNSynth;
|
||||
pModeString = "OPN mode";
|
||||
break;
|
||||
}
|
||||
|
||||
if (pNewSynth == nullptr)
|
||||
@@ -1244,6 +1277,8 @@ void CMT32Pi::SetMasterVolume(s32 nVolume)
|
||||
m_pSoundFontSynth->SetMasterVolume(m_nMasterVolume);
|
||||
if (m_pOPLSynth)
|
||||
m_pOPLSynth->SetMasterVolume(m_nMasterVolume);
|
||||
if (m_pOPNSynth)
|
||||
m_pOPNSynth->SetMasterVolume(m_nMasterVolume);
|
||||
|
||||
if (m_pCurrentSynth != m_pMT32Synth)
|
||||
LCDLog(TLCDLogType::Notice, "Volume: %d", m_nMasterVolume);
|
||||
|
||||
+15709
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user