Skip to content

Commit

Permalink
Update to latest version of StSound from GitHub
Browse files Browse the repository at this point in the history
This sound fix the pitch issue.
  • Loading branch information
nguillaumin committed Sep 21, 2024
1 parent d06ef62 commit 6f44aa3
Show file tree
Hide file tree
Showing 42 changed files with 131 additions and 42 deletions.
2 changes: 1 addition & 1 deletion stsound/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RM = rm -f

STSOUND_SRC=StSound-1.43/StSoundLibrary
STSOUND_SRC=StSound/StSoundLibrary

LIB = digidrum.o Ymload.o Ym2149Ex.o YmMusic.o YmUserInterface.o

Expand Down
21 changes: 21 additions & 0 deletions stsound/StSound/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Arnaud Carré

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions stsound/StSound/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# StSound
Library to replay YM files ( Atari ST music file format )

written by Arnaud Carré (aka Leonard/Oxygene)

[@leonard_coder](https://twitter.com/leonard_coder)


# History
In 1995 I created the YM file format and wrote ST-Sound, a program to play ATARI-ST on your PC. I was very happy to see how ST-Sound was popular. MS-Dos player at first, I wrote a Windows player, a winamp and a netscape plugin. ( then some website use Atari tunes !).
And then time passed and I worked on other stuff. Quite often, some people asked me to release the source code, and I always answered that I should clean some code and add license stuff, so I never take time..
Now it's done ! 2005, ten years after the first ST-Sound creation, here is the ST-Sound library with sample project, all under BSD license. The code is not as clean as I hope but no time to change it. Don't forget almost all that stuff was written in 1995 :-)

2020 update: I just created this github repo, easier to use than a zip file on my website :)

# Repository details
ST-Sound library repo comes with four main directories.:

1. **StSoundLibrary**
This is the most important directory. Portable ( I hope !! :-)) C++ code to play YM files into your own production. There is a simple "C like" user API, and you just need to include "StSoundLibrary.h" to work with YM files. See tutorial projects for details. Theorically should compile under windows, linux, etc.

2. **YmToWav**
Tutorial code. Portable ( I hope !! :-)) code to render an YM file into a WAV file. Works in command line. theorically should compile under windows, linux, etc.

3. **SmallYmPlayer**
Tutorial code. Non portable (windows only) real time YM player using StSoundLibrary. Works under windows (use the waveOut sound API)

4. **YmSampleFiles**
Only contains a set of YM sample files to fastly test the library without browsing the whole world wide web ! :-)

# Compiling
The package is done to work very nicely with Microsoft Visual Studio

For Visual Studio users: Load StSound_vc2017.sln file into your lovely IDE and just build one of the tutorial sample or the main library. Everything should work without pain
For other users ( Linux, Gameboy color or any strange system), just search in your head some very, very oldschool knowledge and build a nice makefile :-) ( should be easy for StSoundLibrary)

# Legal
ST-Sound library is written by Arnaud Carré and is public domain. You can use it as you wish. If you're using it in your project, any credits in any readme file is appreciated :)
As almost all YM files on the web are packed with LZH method, ST-Sound includes LZH depacking code written by Haruhiko Okumura and modifyed/improved by Kerwin F. Medina.

# Enjoy!




Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -12,17 +12,20 @@
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{477B9C42-BE9C-47F6-B6D1-E70EC34F72AB}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand All @@ -45,6 +48,12 @@
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ExecutablePath>$(SolutionDir);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExecutablePath>$(SolutionDir);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<TypeLibraryName>.\Debug/SmallYmPlayer.tlb</TypeLibraryName>
Expand All @@ -54,7 +63,6 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\Debug/SmallYmPlayer.pch</PrecompiledHeaderOutputFile>
Expand All @@ -78,7 +86,8 @@
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<TargetMachine>NotSet</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down Expand Up @@ -118,6 +127,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extern "C"

// Create object
extern YMMUSIC * ymMusicCreate();
extern YMMUSIC * ymMusicCreateWithRate(ymint rate);
extern YMMUSIC * ymMusicCreateWithRate(ymint rate);

// Release object
extern void ymMusicDestroy(YMMUSIC *pMusic);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -12,17 +12,20 @@
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E78919ED-80E5-4BA3-A93A-0A59C9241BE4}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand All @@ -43,11 +46,16 @@
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ExecutablePath>$(SolutionDir);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExecutablePath>$(SolutionDir);$(VC_ExecutablePath_x86);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\Debug/StSoundLibrary.pch</PrecompiledHeaderOutputFile>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CDcAdjuster
{
public:
CDcAdjuster();

void AddSample(ymint sample);
ymint GetDcLevel(void) { return m_sum / DC_ADJUST_BUFFERLEN; }
void Reset(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
extern "C" {
#endif

#ifdef _MSC_VER
#define PACKED_STRUCT( __Declaration__ ) __pragma( pack(push, 1) ) struct __Declaration__ __pragma( pack(pop) )
#elif defined(__GNUC__)
#define PACKED_STRUCT( __Declaration__ ) struct __attribute__((__packed__)) __Declaration__
#endif

#pragma pack(1)
typedef struct
{
typedef PACKED_STRUCT({
ymu8 size;
ymu8 sum;
char id[5];
Expand All @@ -53,8 +56,7 @@ typedef struct
ymu8 reserved[5];
ymu8 level;
ymu8 name_lenght;
} lzhHeader_t;
#pragma pack()
} lzhHeader_t);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static const ymint mfpPrediv[8] = {0,4,10,16,50,64,100,200};



CYmMusic::CYmMusic(ymint _replayRate)
CYmMusic::CYmMusic(ymint _replayRate) :
ymChip(ATARI_CLOCK, 1, _replayRate)
{

pBigMalloc = NULL;
pSongName = NULL;
pSongAuthor = NULL;
Expand All @@ -59,7 +59,7 @@ CYmMusic::CYmMusic(ymint _replayRate)

pBigSampleBuffer = NULL;
pMixBlock = NULL;

replayRate = _replayRate;
innerSamplePos = 0;
currentPos = 0;
Expand Down Expand Up @@ -221,12 +221,12 @@ ymbool CYmMusic::isSeekable(void)
return getAttrib()&A_TIMECONTROL;
}

void CYmMusic::setLastError(char *pError)
void CYmMusic::setLastError(const char *pError)
{
pLastError = pError;
}

char *CYmMusic::getLastError(void)
const char *CYmMusic::getLastError(void)
{
return pLastError;
}
Expand Down Expand Up @@ -420,7 +420,7 @@ void CYmMusic::player(void)

if (ptr[12])
{
sampleFrq = (MFP_CLOCK / ptr[12]);
sampleFrq = ((MFP_CLOCK/4) / ptr[12]);
ymChip.drumStart( 2, // Voice C
sampleAdress[sampleNum],
sampleLen[sampleNum],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CYmMusic
int getAttrib(void);
void getMusicInfo(ymMusicInfo_t *pInfo);
void setLoopMode(ymbool bLoop);
char *getLastError(void);
const char *getLastError(void);
int readYmRegister(ymint reg) { return ymChip.readRegister(reg); }
void setLowpassFilter(ymbool bActive) { ymChip.setFilter(bActive); }

Expand All @@ -171,7 +171,7 @@ class CYmMusic

void setPlayerRate(int rate);
void setAttrib(int _attrib);
void setLastError(char *pError);
void setLastError(const char *pError);
ymu8 *depackFile(ymu32 size);
ymbool deInterleave(void);
void readYm6Effect(ymu8 *pReg,int code,int prediv,int count);
Expand All @@ -180,7 +180,7 @@ class CYmMusic


CYm2149Ex ymChip;
char *pLastError;
const char *pLastError;
ymFile_t songType;
int nbFrame;
int loopFrame;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ YMMUSIC * ymMusicCreate()

YMMUSIC * ymMusicCreateWithRate(ymint rate)
{
return (YMMUSIC*)(new CYmMusic(rate));
return (YMMUSIC*)(new CYmMusic(rate));
}

ymbool ymMusicLoad(YMMUSIC *pMus, const char *fName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
-----------------------------------------------------------------------------*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -57,9 +58,9 @@ static void signeSample(ymu8 *ptr,yms32 size)
}
}

char *mstrdup(char *in)
char *mstrdup(const char *in)
{
const int size = strlen(in)+1;
const int size = (int)strlen(in)+1;
char *out = (char*)malloc(size);
if (out)
strcpy(out,in);
Expand Down Expand Up @@ -133,14 +134,6 @@ unsigned char *CYmMusic::depackFile(ymu32 checkOriginalSize)

fileSize = (ymu32)-1;

if (pHeader->level != 0) // NOTE: Endianness works because value is 0
{ // Compression LH5, header !=0 : Error.
free(pBigMalloc);
pBigMalloc = NULL;
setLastError("LHARC Header must be 0 !");
return NULL;
}

fileSize = ReadLittleEndian32((ymu8*)&pHeader->original);
pNew = (ymu8*)malloc(fileSize);
if (!pNew)
Expand All @@ -151,12 +144,10 @@ unsigned char *CYmMusic::depackFile(ymu32 checkOriginalSize)
return NULL;
}

pSrc = pBigMalloc+sizeof(lzhHeader_t)+pHeader->name_lenght; // NOTE: Endianness works because name_lenght is a byte

pSrc += 2; // skip CRC16

pSrc = pBigMalloc + pHeader->size;
ymu32 packedSize = ReadLittleEndian32((ymu8*)&pHeader->packed);

pSrc += 2; // skip CRC16
checkOriginalSize -= ymu32(pSrc - pBigMalloc);

if (packedSize > checkOriginalSize)
Expand All @@ -166,7 +157,7 @@ unsigned char *CYmMusic::depackFile(ymu32 checkOriginalSize)
if (packedSize <= checkOriginalSize)
{
// alloc space for depacker and depack data
CLzhDepacker *pDepacker = new CLzhDepacker;
CLzhDepacker *pDepacker = new CLzhDepacker;
const bool bRet = pDepacker->LzUnpack(pSrc,packedSize,pNew,fileSize);
delete pDepacker;

Expand Down Expand Up @@ -269,7 +260,7 @@ ymbool CYmMusic::ymDecode(void)
ymu32 sampleSize;
yms32 tmp;
ymu32 id;


id = ReadBigEndian32((unsigned char*)pBigMalloc);
switch (id)
Expand Down Expand Up @@ -540,7 +531,7 @@ ymbool CYmMusic::ymDecode(void)
return YMTRUE;
}


ymbool CYmMusic::checkCompilerTypes()
{
setLastError("Basic types size are not correct (check ymTypes.h)");
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
-----------------------------------------------------------------------------*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include "../StSoundLibrary/StSoundLibrary.h"
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6f44aa3

Please sign in to comment.