Skip to content

Commit

Permalink
adding Generative Audio sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeocool committed Apr 23, 2010
1 parent b6329bc commit 5a95b0d
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 0 deletions.
54 changes: 54 additions & 0 deletions samples/AudioGenerative/src/AudioGenerativeApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "cinder/app/AppBasic.h"
#include "cinder/audio/Output.h"
#include "cinder/audio/Callback.h"
#include "cinder/CinderMath.h"

using namespace ci;
using namespace ci::app;

float gFreqTarget = 0.0f;
float gPhase = 0.0f;
float gPhaseAdjust = 0.0f;
const float gMaxFreq = 2000.0f;

void sineWave( uint64_t inSampleOffset, uint32_t *ioSampleCount, audio::Buffer *ioBuffer ) {
float * buffer = (float *)ioBuffer->mData;
gPhaseAdjust = gPhaseAdjust * 0.95f + ( gFreqTarget / 44100.0f ) * 0.05f;
for( int i = 0; i < *ioSampleCount; i++ ) {
gPhase += gPhaseAdjust;
float r = gPhase - math<float>::floor( gPhase );
float val = math<float>::sin( r * 2.0f * M_PI );

buffer[i*ioBuffer->mNumberChannels] = val;
buffer[i*ioBuffer->mNumberChannels + 1] = val;
}
}

class AudioGenerativeApp : public AppBasic {
public:
void setup();
void mouseMove( MouseEvent event );
void draw();

};

void AudioGenerativeApp::setup()
{
audio::Output::addTrack( audio::Callback( &sineWave ) );
}

void AudioGenerativeApp::mouseMove( MouseEvent event )
{
int height = getWindowHeight();
//gFreqTarget = ( height - event.getY() ) / (float)height * gMaxFreq/ 44100.0f;
gFreqTarget = math<float>::clamp( ( height - event.getY() ) / (float)height * gMaxFreq, 0.0, 2000.0 );
}

void AudioGenerativeApp::draw()
{
glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );
}

// This line tells Cinder to actually create the application
CINDER_APP_BASIC( AudioGenerativeApp, RendererGl )
19 changes: 19 additions & 0 deletions samples/AudioGenerative/vc9/AudioGenerative.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AudioGenerative", "AudioGenerative.vcproj", "{9DA00FEA-5218-413E-B762-35D91045B3B4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DA00FEA-5218-413E-B762-35D91045B3B4}.Debug|Win32.ActiveCfg = Debug|Win32
{9DA00FEA-5218-413E-B762-35D91045B3B4}.Debug|Win32.Build.0 = Debug|Win32
{9DA00FEA-5218-413E-B762-35D91045B3B4}.Release|Win32.ActiveCfg = Release|Win32
{9DA00FEA-5218-413E-B762-35D91045B3B4}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
204 changes: 204 additions & 0 deletions samples/AudioGenerative/vc9/AudioGenerative.vcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="AudioGenerative"
ProjectGUID="{9DA00FEA-5218-413E-B762-35D91045B3B4}"
RootNamespace="AudioGenerative"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\..\include;..\..\..\boost"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cinder_d.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\lib\msw"
GenerateDebugInformation="true"
SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\include;..\..\..\include;..\..\..\boost"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cinder.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\lib\msw"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\src\AudioGenerativeApp.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\..\include\cinder\Cinder.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
Loading

0 comments on commit 5a95b0d

Please sign in to comment.