From: wittend99 Date: Tue, 15 May 2012 13:47:57 +0000 (+0000) Subject: Fun with portaudio! X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=fa262cc3539b6ce1f3c3c494a65a49ea4589781d;p=freetel-svn-tracking.git Fun with portaudio! git-svn-id: https://svn.code.sf.net/p/freetel/code@467 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/pa_test/Debug/portaudio.dll b/fdmdv2/pa_test/Debug/portaudio.dll new file mode 100644 index 00000000..9b292864 Binary files /dev/null and b/fdmdv2/pa_test/Debug/portaudio.dll differ diff --git a/fdmdv2/pa_test/Release/portaudio.dll b/fdmdv2/pa_test/Release/portaudio.dll new file mode 100644 index 00000000..9b292864 Binary files /dev/null and b/fdmdv2/pa_test/Release/portaudio.dll differ diff --git a/fdmdv2/pa_test/pa_class.cpp b/fdmdv2/pa_test/pa_class.cpp new file mode 100644 index 00000000..14e70e40 --- /dev/null +++ b/fdmdv2/pa_test/pa_class.cpp @@ -0,0 +1,146 @@ +#include +#include +#include "portaudio.h" + +/* +** Note that many of the older ISA sound cards on PCs do NOT support +** full duplex audio (simultaneous record and playback). +** And some only support full duplex at lower sample rates. +*/ +#define SAMPLE_RATE (44100) +#define PA_SAMPLE_TYPE paFloat32 +#define FRAMES_PER_BUFFER (64) + +typedef float SAMPLE; + +float CubicAmplifier(float input); + +static int fuzzCallback(const void *inputBuffer, + void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData); + +/* Non-linear amplifier with soft distortion curve. */ +float CubicAmplifier(float input) +{ + float output, temp; + if(input < 0.0) + { + temp = input + 1.0f; + output = (temp * temp * temp) - 1.0f; + } + else + { + temp = input - 1.0f; + output = (temp * temp * temp) + 1.0f; + } + return output; +} + +#define FUZZ(x) CubicAmplifier(CubicAmplifier(CubicAmplifier(CubicAmplifier(x)))) + +static int gNumNoInputs = 0; + +static int fuzzCallback(const void *inputBuffer, + void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData) +{ + SAMPLE *out = (SAMPLE*)outputBuffer; + const SAMPLE *in = (const SAMPLE*)inputBuffer; + unsigned int i; + (void) timeInfo; /* Prevent unused variable warnings. */ + (void) statusFlags; + (void) userData; + + if(inputBuffer == NULL) + { + for(i = 0; i < framesPerBuffer; i++) + { + *out++ = 0; /* left - silent */ + *out++ = 0; /* right - silent */ + } + gNumNoInputs += 1; + } + else + { + for(i = 0; i < framesPerBuffer; i++) + { + *out++ = FUZZ(*in++); /* left - distorted */ + *out++ = *in++; /* right - clean */ + } + } + return paContinue; +} + + +#define BUILD_MAIN + +#ifdef BUILD_MAIN + +int main(void) +{ + PaStreamParameters inputParameters, outputParameters; + PaStream *stream; + PaError err; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ + if (inputParameters.device == paNoDevice) { + fprintf(stderr,"Error: No default input device.\n"); + goto error; + } + inputParameters.channelCount = 2; /* stereo input */ + inputParameters.sampleFormat = PA_SAMPLE_TYPE; + inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; + inputParameters.hostApiSpecificStreamInfo = NULL; + + outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ + if (outputParameters.device == paNoDevice) { + fprintf(stderr,"Error: No default output device.\n"); + goto error; + } + outputParameters.channelCount = 2; /* stereo output */ + outputParameters.sampleFormat = PA_SAMPLE_TYPE; + outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; + outputParameters.hostApiSpecificStreamInfo = NULL; + + err = Pa_OpenStream( + &stream, + &inputParameters, + &outputParameters, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* paClipOff, */ /* we won't output out of range samples so don't bother clipping them */ + fuzzCallback, + NULL ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Hit ENTER to stop program.\n"); + getchar(); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + + printf("Finished. gNumNoInputs = %d\n", gNumNoInputs ); + Pa_Terminate(); + return 0; + +error: + Pa_Terminate(); + fprintf( stderr, "An error occured while using the portaudio stream\n" ); + fprintf( stderr, "Error number: %d\n", err ); + fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); + return -1; + return 0; +} + +#endif diff --git a/fdmdv2/pa_test/pa_test.mk b/fdmdv2/pa_test/pa_test.mk new file mode 100644 index 00000000..d95eb471 --- /dev/null +++ b/fdmdv2/pa_test/pa_test.mk @@ -0,0 +1,103 @@ +## +## Auto Generated makefile by CodeLite IDE +## any manual changes will be erased +## +## Debug +ProjectName :=pa_test +ConfigurationName :=Debug +IntermediateDirectory :=./Debug +OutDir := $(IntermediateDirectory) +WorkspacePath := "C:\Users\wittend\Projects\audio\portaudio_test\paEcho" +ProjectPath := "C:\Users\wittend\Projects\audio\portaudio_test\paEcho\pa_test" +CurrentFileName := +CurrentFilePath := +CurrentFileFullPath := +User :=wittend +Date :=5/14/2012 +CodeLitePath :="C:\Program Files\CodeLite" +LinkerName :=g++ +ArchiveTool :=ar rcus +SharedObjectLinkerName :=g++ -shared -fPIC +ObjectSuffix :=.o +DependSuffix :=.o.d +PreprocessSuffix :=.o.i +DebugSwitch :=-gstab +IncludeSwitch :=-I +LibrarySwitch :=-l +OutputSwitch :=-o +LibraryPathSwitch :=-L +PreprocessorSwitch :=-D +SourceSwitch :=-c +CompilerName :=g++ +C_CompilerName :=gcc +OutputFile :=$(IntermediateDirectory)/$(ProjectName) +Preprocessors := +ObjectSwitch :=-o +ArchiveOutputSwitch := +PreprocessOnlySwitch :=-E +ObjectsFileList :="C:\Users\wittend\Projects\audio\portaudio_test\paEcho\pa_test\pa_test.txt" +PCHCompileFlags := +MakeDirCommand :=makedir +CmpOptions := -g -O0 -Wall $(Preprocessors) +C_CmpOptions := -g -O0 -Wall $(Preprocessors) +LinkOptions := +IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)../../../portaudio/include +IncludePCH := +RcIncludePath := +Libs := $(LibrarySwitch)portaudio +LibPath := $(LibraryPathSwitch). + + +## +## User defined environment variables +## +CodeLiteDir:=C:\Program Files\CodeLite +WXWIN:=C:\bin\wxWidgets-2.9.2 +PATH:=$(WXWIN)\lib\gcc_dll;$(PATH) +WXCFG:=gcc_dll\mswu +UNIT_TEST_PP_SRC_DIR:=C:\bin\UnitTest++-1.3 +Objects=$(IntermediateDirectory)/pa_class$(ObjectSuffix) + +## +## Main Build Targets +## +.PHONY: all clean PreBuild PrePreBuild PostBuild +all: $(OutputFile) + +$(OutputFile): $(IntermediateDirectory)/.d $(Objects) + @$(MakeDirCommand) $(@D) + @echo "" > $(IntermediateDirectory)/.d + @echo $(Objects) > $(ObjectsFileList) + $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) + +$(IntermediateDirectory)/.d: + @$(MakeDirCommand) "./Debug" + +PreBuild: + + +## +## Objects +## +$(IntermediateDirectory)/pa_class$(ObjectSuffix): pa_class.cpp $(IntermediateDirectory)/pa_class$(DependSuffix) + $(CompilerName) $(IncludePCH) $(SourceSwitch) "C:/Users/wittend/Projects/audio/portaudio_test/paEcho/pa_test/pa_class.cpp" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/pa_class$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/pa_class$(DependSuffix): pa_class.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/pa_class$(ObjectSuffix) -MF$(IntermediateDirectory)/pa_class$(DependSuffix) -MM "C:/Users/wittend/Projects/audio/portaudio_test/paEcho/pa_test/pa_class.cpp" + +$(IntermediateDirectory)/pa_class$(PreprocessSuffix): pa_class.cpp + @$(CompilerName) $(CmpOptions) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/pa_class$(PreprocessSuffix) "C:/Users/wittend/Projects/audio/portaudio_test/paEcho/pa_test/pa_class.cpp" + + +-include $(IntermediateDirectory)/*$(DependSuffix) +## +## Clean +## +clean: + $(RM) $(IntermediateDirectory)/pa_class$(ObjectSuffix) + $(RM) $(IntermediateDirectory)/pa_class$(DependSuffix) + $(RM) $(IntermediateDirectory)/pa_class$(PreprocessSuffix) + $(RM) $(OutputFile) + $(RM) $(OutputFile).exe + $(RM) "C:\Users\wittend\Projects\audio\portaudio_test\paEcho\.build-debug\pa_test" + + diff --git a/fdmdv2/pa_test/pa_test.project b/fdmdv2/pa_test/pa_test.project new file mode 100644 index 00000000..16ec14d7 --- /dev/null +++ b/fdmdv2/pa_test/pa_test.project @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None + + + + + + + + + + + + + + diff --git a/fdmdv2/pa_test/pa_test.txt b/fdmdv2/pa_test/pa_test.txt new file mode 100644 index 00000000..7a5e00db --- /dev/null +++ b/fdmdv2/pa_test/pa_test.txt @@ -0,0 +1 @@ +./Debug/pa_class.o diff --git a/fdmdv2/pa_test/portaudio.dll b/fdmdv2/pa_test/portaudio.dll new file mode 100644 index 00000000..9b292864 Binary files /dev/null and b/fdmdv2/pa_test/portaudio.dll differ