Skip to content

Commit

Permalink
Merge pull request #65, Version v3.4.0-alpha from sam-astro/dev
Browse files Browse the repository at this point in the history
Begin merging dev branch with main, `v3.4.0-alpha` update
  • Loading branch information
sam-astro authored Dec 4, 2023
2 parents 200fd90 + 782462b commit e0b5f96
Show file tree
Hide file tree
Showing 78 changed files with 536,497 additions and 785 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.ipch
*.pdb
*.db
Astro8-Emulator/.vs/Astro8-Emulator/v17/Preview/ipch/AutoPCH/98c65cbb6cc9a3d3/ASTRO8-EMULATOR.ipch
Astro8-Emulator/.vs/Astro8-Emulator/v17/Preview/Browse.VC.opendb
Astro8-Emulator/.vs/Astro8-Emulator/v17/Preview/Browse.VC.db-shm
Expand Down
Binary file not shown.
Binary file modified Astro8-Emulator/.vs/Astro8-Emulator/v17/.suo
Binary file not shown.
Binary file modified Astro8-Emulator/.vs/Astro8-Emulator/v17/Preview/Browse.VC.db
Binary file not shown.
10 changes: 7 additions & 3 deletions Astro8-Emulator/Astro8-Emulator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>D:\Code\SDL2-2.0.18\include;D:\Code\SDL2_mixer-2.6.2\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(IncludePath)</IncludePath>
<LibraryPath>D:\Code\SDL2-2.0.18\lib\x64;D:\CodeSDL2_mixer-2.6.2\lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)$(LibraryPath)</LibraryPath>
<LibraryPath>D:\Code\Astro8-Computer\Astro8-Emulator\VSSynth.lib;D:\Code\SDL2-2.0.18\lib\x64;D:\CodeSDL2_mixer-2.6.2\lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)$(LibraryPath)</LibraryPath>
<TargetName>astro8</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down Expand Up @@ -137,23 +137,27 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_mixer-2.6.2\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;SDL2_mixer.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\Code\Astro8-Computer\Astro8-Emulator\VSSynth.lib;D:\Code\SDL2-2.0.18\lib\x64;D:\Code\SDL2_mixer-2.6.2\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>VSSynth.lib;SDL2.lib;SDL2main.lib;SDL2_mixer.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)astro8$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="armstrong-compiler.cpp" />
<ClCompile Include="assembler.cpp" />
<ClCompile Include="escapi.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="armstrong-compiler.h" />
<ClInclude Include="assembler.h" />
<ClInclude Include="audio.h" />
<ClInclude Include="color.hpp" />
<ClInclude Include="colorprint.h" />
<ClInclude Include="escapi.h" />
<ClInclude Include="processing.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="VSSynth\VSSynth.h" />
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="..\char_set_memtape">
Expand Down
12 changes: 12 additions & 0 deletions Astro8-Emulator/Astro8-Emulator.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<ClCompile Include="assembler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="escapi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="colorprint.h">
Expand All @@ -44,6 +47,15 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="escapi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="audio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VSSynth\VSSynth.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="..\char_set_memtape" />
Expand Down
8 changes: 4 additions & 4 deletions Astro8-Emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
project(astro8)

SET(programName astro8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeFiles/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")

add_executable (astro8 main.cpp color.hpp colorprint.h processing.h armstrong-compiler.h )

Expand All @@ -20,11 +20,11 @@ target_link_libraries(astro8 m ${SDL2_LIBRARIES} ${SDL2_MIXER_LIBRARIES})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../char_set_memtape
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/x64/Release/noise.wav
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../Releases/Astro8-Linux/high.wav
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/x64/Release/square.wav
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../Releases/Astro8-Linux/medium.wav
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/x64/Release/triangle.wav
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../Releases/Astro8-Linux/low.wav
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Binary file added Astro8-Emulator/VSSynth.lib
Binary file not shown.
72 changes: 72 additions & 0 deletions Astro8-Emulator/VSSynth/SoundGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

namespace VSSynth
{
/**
* @brief Collection of sound generators provided with VSSynth
*/
namespace Generators
{
}

/**
* @brief Sound generating device
*
* A sound generator is responsible for creating the sound output which will be eventually sent to the speaker.
* Sound generators can be simple waveforms, a modulated waveform from an ADSR envelope, or it can playback PCM audio from a file.
*/
class SoundGenerator
{
public:
SoundGenerator();
virtual ~SoundGenerator();

/**
* @brief Sample the SoundGenerator at the given time
*
* This is the main interaction between the Synthesizer and the SoundGenerator. This method will be called at the rate of the sampling rate specified by the Synthesizer's constructor.
*
* @warning Since this function is called so frequently you should make computations as fast and efficient as possible.
* Needless to say, do not block the running thread when implementing this function.
*
* @param time - in seconds
* @return double - sound sample in range [-1.0,1.0]
*
* @see Synthesizer
*/
virtual double sample(double time) = 0;

/**
* @brief Sets the volume at a certain percent
*
* @param percent - volume as a percent in range [0,100]
*/
void setVolume(double percent);

/**
* @brief Gets the current volume as a percent
*
* @return double - volume as a percent [0, 100]
*/
double getVolume();

/**
* @brief Amplitude for synthesizer
*
* Sound generators, when sampled, return a value in [-1.0, 1.0].
* This value will be multiplied by the amplitude returned by this
* function. The amplitude will be a value such that it can fit
* in a 16-bit signed integer.
*
* This function is mainly for the Synthesizer. You shouldn't
* really have a reason to call this function.
*
* @see Synthesizer
* @return double
*/
double getAmplitude();

protected:
double mAmplitude;
};
} // namespace VSSynth
32 changes: 32 additions & 0 deletions Astro8-Emulator/VSSynth/SynthMiddleware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

namespace VSSynth
{
/**
* @brief Collection of middleware for use with the synthesizer
*/
namespace Middleware
{

}

/**
* @brief Read and modify samples prior to sending them to the speaker
*
* Middleware has the ability to modify any samples prior to sending it to the speaker.
* This can allow for the creation of filters, sample analyzers or audio file writers.
*
* @see Synthesizer
*/
class SynthMiddleware
{
public:
/**
* @brief Process the current sample and output the modified sample
* @param currentSample
* @param time
* @return short
*/
virtual short processSample(short currentSample, double time) = 0;
};
} // namespace VSSynth
99 changes: 99 additions & 0 deletions Astro8-Emulator/VSSynth/Synthesizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#pragma once

#include <SDL.h>

#include <functional>
#include <vector>

#include "SoundGenerator.h"
#include "SynthMiddleware.h"

namespace VSSynth
{
struct SynthData
{
double *time;
double sampleDeltaTime;
std::vector<SoundGenerator *> soundGenerators;
std::vector<SynthMiddleware *> middleware;
};

/**
* @brief Entrypoint and interface for audio synthesis
*
* The synthesizer is the main building block of the VSSynth audio synthesizer.
* This synthesizer uses additive synthesis to create sound.
*
* SoundGenerators are responsible for creating the sounds and must be added to this synth.
*
* Middleware can be added to read and/or modify the sound output prior to reaching the speaker.
*
* @see SoundGenerator
* @see Middleware
*/
class Synthesizer
{
public:
/**
* @brief Create a new Synthesizer
*
* @param samplingRates - Sampling rate (# of samples per second).
* Higher values are computationally intensive while lower values have a limit scope of sound frequencies.
* @param numFrames - Number of sampling frames. A sampling frame is an instance where sound generators are sampled.
*/
Synthesizer(unsigned int samplingRates = 48000, unsigned int numFrames = 20);
virtual ~Synthesizer();

/**
* @brief Creates the internal audio device (SDL should be initialized prior to calling this)
*
* @warning SDL AUDIO must be initialized prior to calling open()
*/
void open();

/**
* @brief Destroys the internal audio device
*
*/
void close();

/**
* @brief Pauses the synthesizer
*
* Sound will stop if the synthesizer is currently running
*/
void pause();

/**
* @brief Unpauses the synthesizer
*
* Sound will resume if the synthesizer has been paused
*/
void unpause();

/**
* @brief Adds a sound generator to the synthesizer
*
* @param soundGenerator
*/
void addSoundGenerator(SoundGenerator *soundGenerator);

/**
* @brief Adds a middleware to the synthesizer
*
* @param middleware
*/
void addMiddleware(SynthMiddleware *middleware);

private:
SDL_AudioDeviceID mDeviceID;

double mTime;

unsigned int mSamplingRate;
unsigned int mNumFrames;

SynthData mSynthData;
};

}; // namespace VSSynth
14 changes: 14 additions & 0 deletions Astro8-Emulator/VSSynth/VSSynth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "SoundGenerator.h"
#include "SynthMiddleware.h"
#include "Synthesizer.h"
#include "generators/Instrument.h"
#include "generators/MonophonicInstrument.h"
#include "generators/PolyphonicInstrument.h"
#include "generators/Sequencer.h"
#include "generators/Tone.h"
#include "middleware/WAVWriter.h"
#include "utils/Envelope.h"
#include "utils/Notes.h"
#include "utils/Patches.h"
#include "utils/Waveforms.h"
47 changes: 47 additions & 0 deletions Astro8-Emulator/VSSynth/generators/Instrument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <functional>

#include "../utils/Envelope.h"
#include "../SoundGenerator.h"

namespace VSSynth
{
namespace Generators
{
/**
* @brief Device capable of playing multiple notes with an ADSR envelope
*/
class Instrument : public SoundGenerator
{
public:
Instrument(std::function<double(double, double)> wave);

virtual ~Instrument();

/**
* @brief Samples the instrument at the given time
*
* @param time
* @return double
*/
virtual double sample(double time) = 0;

/**
* @brief Holds the given note
*
* @param frequency - the note
*/
virtual void holdNote(double frequency) = 0;
/**
* @brief Releases the given note
*
* @param frequency - the note
*/
virtual void releaseNote(double frequency) = 0;

protected:
std::function<double(double, double)> mWave;
};
} // namespace Generators
} // namespace VSSynth
Loading

0 comments on commit e0b5f96

Please sign in to comment.