Skip to content

Commit

Permalink
Merge pull request #837 from edge-classic/decoder-updates
Browse files Browse the repository at this point in the history
Update decoders; restore (optional) OPL MIDI support
  • Loading branch information
dashodanger authored Jan 14, 2025
2 parents 2eb977c + b3bc529 commit e8fa556
Show file tree
Hide file tree
Showing 24 changed files with 8,213 additions and 5,855 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ option(EDGE_IMF_SUPPORT "Enable support for IMF music format" ON)
option(EDGE_MP3_SUPPORT "Enable support for MP3 music format" ON)
option(EDGE_MUS_SUPPORT "Enable support for MUS MIDI format" ON)
option(EDGE_OGG_SUPPORT "Enable support for OGG music format" ON)
option(EDGE_OPL_SUPPORT "Enable support for MIDI playback via OPL emulation" ON)
option(EDGE_SID_SUPPORT "Enable support for C64 SID music" ON)
option(EDGE_TRACKER_SUPPORT "Enable support for Tracker music (MOD/XM/S3M/IT)" ON)
option(EDGE_XMI_SUPPORT "Enable support for XMI MIDI format" ON)
Expand Down Expand Up @@ -204,6 +205,10 @@ if (EDGE_OGG_SUPPORT)
add_definitions(-DEDGE_OGG_SUPPORT)
endif()

if (EDGE_OPL_SUPPORT)
add_definitions(-DEDGE_OPL_SUPPORT)
endif()

if (EDGE_SID_SUPPORT)
add_definitions(-DEDGE_SID_SUPPORT)
endif()
Expand Down
6 changes: 4 additions & 2 deletions docs/licenses/License Attribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Freedoom (various assets) - Copyright (c) 2001-2019 Contributors to the Freedoom
Mod4Play library - Copyright (c) 2024-2025 dashodanger
Copyright (c) 2022 Olav Sørensen

OpalMIDI library - Copyright (c) 2025, Dashodanger
Copyright (c) 2021-2024, Devin Acker
Opal Emulation released into Public Domain by Reality Productions

ZDoom FName implementation - Copyright (c) 2005-2007 Randy Heit

===========================================================================================
Expand Down Expand Up @@ -123,8 +127,6 @@ Public Domain

Fraction.hpp - Bisqwit

Opal library - Reality Productions

Miniaudio library - David Reid

prns.h - Marc B. Reynolds
Expand Down
4 changes: 2 additions & 2 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if (EDGE_TRACKER_SUPPORT)
add_subdirectory(m4p)
endif()
add_subdirectory(miniz)
if (EDGE_IMF_SUPPORT)
add_subdirectory(opal)
if (EDGE_IMF_SUPPORT OR EDGE_OPL_SUPPORT)
add_subdirectory(opalmidi)
endif()
add_subdirectory(pl_mpeg)
add_subdirectory(prns)
Expand Down
10 changes: 0 additions & 10 deletions libraries/opal/CMakeLists.txt

This file was deleted.

18 changes: 0 additions & 18 deletions libraries/opal/LICENSE.txt

This file was deleted.

17 changes: 17 additions & 0 deletions libraries/opalmidi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
##########################################
# opalmidi
##########################################

set(OPALMIDI_SOURCE_FILES opal.cpp)

# If only IMF is supported, we don't need the MIDI components
if(EDGE_OPL_SUPPORT)
set(OPALMIDI_SOURCE_FILES ${OPALMIDI_SOURCE_FILES} opalmidi.cpp patches.cpp)
endif()

add_library(
opalmidi
${OPALMIDI_SOURCE_FILES}
)

target_include_directories(opalmidi PUBLIC ./)
53 changes: 53 additions & 0 deletions libraries/opalmidi/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BSD 3-Clause License

Copyright (c) 2025, Dashodanger
Copyright (c) 2021-2024, Devin Acker
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Opal emulation is derived from the RAD Tracker v2 source release, and has
been put into the public domain by Reality Productions (see below)

A quote from a letter sent by Willy Reeve to Vitaly Novichkov
as a reply from a letter sent by Reality's (https://www.3eality.com/)
contact form
----------------------------------------------------------------
All source code supplied with RAD is in the public domain.
----------------------------------------------------------------

================================================================
The complete letter:
================================================================
Hi,

All source code supplied with RAD is in the public domain.
We'll clarify that in the documentation for the next release.

Later...
SHAYDE
================================================================
34 changes: 0 additions & 34 deletions libraries/opal/opal.cpp → libraries/opalmidi/opal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,40 +423,6 @@ void Opal::Sample(int16_t *left, int16_t *right) {
SampleAccum += OPL3SampleRate;
}

//==================================================================================================
// Generate sample. Every time you call this you will get two floating-point samples (one for each
// stereo channel) which will sound correct when played back at the sample rate given when the
// class was constructed.
//==================================================================================================
void Opal::SampleFloat(float *left, float *right) {

// If the destination sample rate is higher than the OPL3 sample rate, we need to skip ahead
while (SampleAccum >= SampleRate) {

LastOutput[0] = CurrOutput[0];
LastOutput[1] = CurrOutput[1];

Output(CurrOutput[0], CurrOutput[1]);

SampleAccum -= SampleRate;
}

// Mix with the partial accumulation
int32_t omblend = SampleRate - SampleAccum;

#if defined _MSC_VER || (defined __SIZEOF_FLOAT__ && __SIZEOF_FLOAT__ == 4)
*(uint32_t *)left=0x43818000^((uint16_t)((LastOutput[0] * omblend + CurrOutput[0] * SampleAccum) / SampleRate));
*left -= 259.0f;
*(uint32_t *)right=0x43818000^((uint16_t)((LastOutput[1] * omblend + CurrOutput[1] * SampleAccum) / SampleRate));
*right -= 259.0f;
#else
*left = (float)((LastOutput[0] * omblend + CurrOutput[0] * SampleAccum) / SampleRate) * 0.000030517578125f;
*right = (float)((LastOutput[1] * omblend + CurrOutput[1] * SampleAccum) / SampleRate) * 0.000030517578125f;
#endif

SampleAccum += OPL3SampleRate;
}

//==================================================================================================
// Produce final output from the chip. This is at the OPL3 sample-rate.
//==================================================================================================
Expand Down
1 change: 0 additions & 1 deletion libraries/opal/opal.h → libraries/opalmidi/opal.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ class Opal
void SetSampleRate(int sample_rate);
void Port(uint16_t reg_num, uint8_t val);
void Sample(int16_t *left, int16_t *right);
void SampleFloat(float *left, float *right);

protected:
void Init(int sample_rate);
Expand Down
Loading

0 comments on commit e8fa556

Please sign in to comment.