-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c3d562
Showing
15 changed files
with
2,566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.33529.622 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyboardHook", "KeyboardHook\KeyboardHook.vcxproj", "{D6C195A5-B306-45CD-9E5A-044C90290F82}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Debug|x64.ActiveCfg = Debug|x64 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Debug|x64.Build.0 = Debug|x64 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Debug|x86.Build.0 = Debug|Win32 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Release|x64.ActiveCfg = Release|x64 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Release|x64.Build.0 = Release|x64 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Release|x86.ActiveCfg = Release|Win32 | ||
{D6C195A5-B306-45CD-9E5A-044C90290F82}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {E9A48BD7-FC27-4951-9118-B6920000C18D} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#define _CRT_SECURE_NO_WARNINGS | ||
|
||
#include "Audio.h" | ||
|
||
static int patestCallback( const void *inputBuffer, void *outputBuffer, | ||
unsigned long framesPerBuffer, | ||
const PaStreamCallbackTimeInfo* timeInfo, | ||
PaStreamCallbackFlags statusFlags, | ||
void *userData ) | ||
{ | ||
paTestData *data = (paTestData*)userData; | ||
float* rptr = &data->bufferOfSndfile[data->frameIndex * data->sfinfo.channels]; // read buffer continuely | ||
float *wptr = (float*)outputBuffer; | ||
unsigned long i; | ||
int finished; | ||
unsigned int framesLeft = data->sfinfo.frames - data->frameIndex; | ||
|
||
(void) timeInfo; /* Prevent unused variable warnings. */ | ||
(void) statusFlags; | ||
(void) inputBuffer; | ||
|
||
if (framesLeft < framesPerBuffer) /* final buffer... */ | ||
{ | ||
for (i = 0; i < framesLeft; i++) | ||
{ | ||
*wptr++ = *rptr++; /* left */ | ||
if (data->sfinfo.channels == 2) *wptr++ = *rptr++; /* right */ | ||
} | ||
for (; i < framesPerBuffer; i++) | ||
{ | ||
*wptr++ = 0; /* left */ | ||
if (data->sfinfo.channels == 2) *wptr++ = 0; /* right */ | ||
} | ||
data->frameIndex += framesLeft; | ||
finished = paComplete; | ||
} | ||
else | ||
{ | ||
for (i = 0; i < framesPerBuffer; i++) | ||
{ | ||
*wptr++ = *rptr++; /* left */ | ||
if (data->sfinfo.channels == 2) *wptr++ = *rptr++; /* right */ | ||
} | ||
data->frameIndex += framesPerBuffer; | ||
finished = paContinue; | ||
} | ||
|
||
return finished; | ||
} | ||
|
||
/*******************************************************************/ | ||
Audio::Audio(const char* audioFile) | ||
{ | ||
audioPath = audioFile; | ||
Setup(audioFile); | ||
} | ||
|
||
int Audio::Setup(const char* audioFile) | ||
{ | ||
PaStreamParameters outputParameters; | ||
int i; | ||
|
||
SNDFILE* infile = NULL; | ||
memset(&data.sfinfo, 0, sizeof(data.sfinfo)); | ||
infile = sf_open(audioFile, SFM_READ, &data.sfinfo); | ||
|
||
/* read sound file */ | ||
data.bufferOfSndfile = (float*)malloc(data.sfinfo.frames * data.sfinfo.channels * sizeof(float)); | ||
sf_read_float(infile, data.bufferOfSndfile, data.sfinfo.frames * data.sfinfo.channels); | ||
sf_close(infile); | ||
|
||
data.frameIndex = 0; | ||
numsSec = data.sfinfo.frames / data.sfinfo.samplerate; // get file's seconds | ||
|
||
err = Pa_Initialize(); | ||
if( err != paNoError ) goto error; | ||
|
||
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ | ||
if (outputParameters.device == paNoDevice) goto error; | ||
|
||
outputParameters.channelCount = data.sfinfo.channels; /* stereo output */ | ||
outputParameters.sampleFormat = paFloat32; | ||
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; | ||
outputParameters.hostApiSpecificStreamInfo = NULL; | ||
|
||
err = Pa_OpenStream( | ||
&stream, | ||
NULL, /* no input */ | ||
&outputParameters, | ||
data.sfinfo.samplerate, | ||
FRAMES_PER_BUFFER, | ||
paClipOff, /* we won't output out of range samples so don't bother clipping them */ | ||
patestCallback, | ||
&data ); | ||
if( err != paNoError ) goto error; | ||
|
||
return err; | ||
error: | ||
Pa_Terminate(); | ||
return err; | ||
} | ||
|
||
int Audio::Play() | ||
{ | ||
err = Pa_StartStream(stream); | ||
if (err != paNoError) goto error; | ||
|
||
Pa_Sleep(numsSec * 1000); | ||
|
||
return err; | ||
error: | ||
Pa_Terminate(); | ||
return err; | ||
} | ||
|
||
int Audio::End() | ||
{ | ||
err = Pa_StopStream(stream); | ||
if (err != paNoError) goto error; | ||
|
||
err = Pa_CloseStream(stream); | ||
if (err != paNoError) goto error; | ||
|
||
Pa_Terminate(); | ||
|
||
free(data.bufferOfSndfile); | ||
return err; | ||
error: | ||
Pa_Terminate(); | ||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef IS_DEFINED_AUDIO | ||
#define IS_DEFINED_AUDIO | ||
|
||
#include "portaudio.h" | ||
#include "sndfile.h" | ||
#include <iostream> | ||
#include <math.h> | ||
|
||
#define NUM_SECONDS (5) | ||
#define SAMPLE_RATE (44100) | ||
#define FRAMES_PER_BUFFER (64) | ||
|
||
typedef struct | ||
{ | ||
float* bufferOfSndfile; | ||
SF_INFO sfinfo; | ||
int frameIndex; | ||
} | ||
paTestData; | ||
|
||
class Audio | ||
{ | ||
public: | ||
Audio(const char* audioFile); | ||
|
||
private: | ||
PaStream* stream; | ||
paTestData data; | ||
PaError err; | ||
|
||
int numsSec; | ||
const char* audioPath; | ||
|
||
public: | ||
int Setup(const char* audioFile); | ||
int Play(); | ||
int End(); | ||
}; | ||
|
||
#endif // !IS_DEFINED_AUDIO |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{d6c195a5-b306-45cd-9e5a-044c90290f82}</ProjectGuid> | ||
<RootNamespace>KeyboardHook</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>../include/PortAudio/;../include/Sndfile/</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>../lib/PortAudio/portaudio_x86.lib;../lib/Sndfile/sndfile.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>../include/PortAudio/;../include/Sndfile/</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>../lib/PortAudio/portaudio_x86.lib;../lib/Sndfile/sndfile.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>../include/PortAudio/;../include/Sndfile/</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>../lib/PortAudio/portaudio_x86.lib;../lib/Sndfile/sndfile.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>../include/PortAudio/;../include/Sndfile/</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>../lib/PortAudio/portaudio_x86.lib;../lib/Sndfile/sndfile.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="Audio.cpp" /> | ||
<ClCompile Include="main.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="..\include\PortAudio\portaudio.h" /> | ||
<ClInclude Include="..\include\Sndfile\sndfile.h" /> | ||
<ClInclude Include="Audio.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
Oops, something went wrong.