From: wittend99 Date: Fri, 18 May 2012 02:16:32 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@480 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=82508979db794a14b5ac3e34149ef0acc06c2d6b;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@480 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/extern/lib/libcodec2.a b/fdmdv2/extern/lib/libcodec2.a new file mode 100644 index 00000000..51c99726 Binary files /dev/null and b/fdmdv2/extern/lib/libcodec2.a differ diff --git a/fdmdv2/extern/lib/libcodec2.la b/fdmdv2/extern/lib/libcodec2.la new file mode 100644 index 00000000..363a5623 --- /dev/null +++ b/fdmdv2/extern/lib/libcodec2.la @@ -0,0 +1,41 @@ +# libcodec2.la - a libtool library file +# Generated by ltmain.sh (GNU libtool) 2.2.6 Debian-2.2.6a-4 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='' + +# Names of this library. +library_names='' + +# The name of the static archive. +old_library='libcodec2.a' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs='' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for libcodec2. +current=0 +age=0 +revision=0 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=no + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/local/lib' diff --git a/fdmdv2/extern/lib/libctb-0.16.a b/fdmdv2/extern/lib/libctb-0.16.a new file mode 100644 index 00000000..91d32e39 Binary files /dev/null and b/fdmdv2/extern/lib/libctb-0.16.a differ diff --git a/fdmdv2/extern/lib/libportaudio.dll.a b/fdmdv2/extern/lib/libportaudio.dll.a new file mode 100644 index 00000000..c9398213 Binary files /dev/null and b/fdmdv2/extern/lib/libportaudio.dll.a differ diff --git a/fdmdv2/extern/lib/libportaudiocpp.a b/fdmdv2/extern/lib/libportaudiocpp.a new file mode 100644 index 00000000..b2844fb5 Binary files /dev/null and b/fdmdv2/extern/lib/libportaudiocpp.a differ diff --git a/fdmdv2/extern/lib/libportaudiocpp.dll.a b/fdmdv2/extern/lib/libportaudiocpp.dll.a new file mode 100644 index 00000000..49b08056 Binary files /dev/null and b/fdmdv2/extern/lib/libportaudiocpp.dll.a differ diff --git a/fdmdv2/extern/lib/libportaudiocpp.la b/fdmdv2/extern/lib/libportaudiocpp.la new file mode 100644 index 00000000..9414270d --- /dev/null +++ b/fdmdv2/extern/lib/libportaudiocpp.la @@ -0,0 +1,41 @@ +# libportaudiocpp.la - a libtool library file +# Generated by libtool (GNU libtool) 2.4 Debian-2.4-2ubuntu1 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='' + +# Names of this library. +library_names='' + +# The name of the static archive. +old_library='libportaudiocpp.a' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs=' /usr/local/lib/libportaudio.la -lwinmm -lole32 -luuid' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for libportaudiocpp. +current=0 +age=0 +revision=12 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=no + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/local/lib' diff --git a/fdmdv2/extern/lib/libsamplerate.a b/fdmdv2/extern/lib/libsamplerate.a new file mode 100644 index 00000000..ccae4e0e Binary files /dev/null and b/fdmdv2/extern/lib/libsamplerate.a differ diff --git a/fdmdv2/extern/lib/libsamplerate.dll.a b/fdmdv2/extern/lib/libsamplerate.dll.a new file mode 100644 index 00000000..1e1d1f9b Binary files /dev/null and b/fdmdv2/extern/lib/libsamplerate.dll.a differ diff --git a/fdmdv2/extern/lib/libsamplerate.la b/fdmdv2/extern/lib/libsamplerate.la new file mode 100644 index 00000000..c3af45e6 --- /dev/null +++ b/fdmdv2/extern/lib/libsamplerate.la @@ -0,0 +1,41 @@ +# libsamplerate.la - a libtool library file +# Generated by libtool (GNU libtool) 2.4 Debian-2.4-3 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='../bin/libsamplerate-0.dll' + +# Names of this library. +library_names='libsamplerate.dll.a' + +# The name of the static archive. +old_library='libsamplerate.a' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs='' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for libsamplerate. +current=1 +age=1 +revision=8 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=no + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/local/lib' diff --git a/fdmdv2/pa_test/devs.cxx b/fdmdv2/pa_test/devs.cxx new file mode 100644 index 00000000..31a560f8 --- /dev/null +++ b/fdmdv2/pa_test/devs.cxx @@ -0,0 +1,177 @@ +#include +#include "portaudiocpp/PortAudioCpp.hxx" + +#ifdef WIN32 +#include "portaudiocpp/AsioDeviceAdapter.hxx" +#endif + +// --------------------------------------------------------------------------------------- + +void printSupportedStandardSampleRates( + const portaudio::DirectionSpecificStreamParameters &inputParameters, + const portaudio::DirectionSpecificStreamParameters &outputParameters) +{ + static double STANDARD_SAMPLE_RATES[] = { + 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, + 44100.0, 48000.0, 88200.0, 96000.0, -1 }; // negative terminated list + + int printCount = 0; + + for (int i = 0; STANDARD_SAMPLE_RATES[i] > 0; ++i) + { + portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, STANDARD_SAMPLE_RATES[i], 0, paNoFlag); + + if (tmp.isSupported()) + { + if (printCount == 0) + { + std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2 + printCount = 1; + } + else if (printCount == 4) + { + std::cout << "," << std::endl; + std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2 + printCount = 1; + } + else + { + std::cout << ", " << STANDARD_SAMPLE_RATES[i]; // 8.2 + ++printCount; + } + } + } + + if (printCount == 0) + std::cout << "None" << std::endl; + else + std::cout << std::endl; +} + +// --------------------------------------------------------------------------------------- + +int main(int, char*[]); +int main(int, char*[]) +{ + try + { + portaudio::AutoSystem autoSys; + + portaudio::System &sys = portaudio::System::instance(); + + std::cout << "PortAudio version number = " << sys.version() << std::endl; + std::cout << "PortAudio version text = '" << sys.versionText() << "'" << std::endl; + + int numDevices = sys.deviceCount(); + std::cout << "Number of devices = " << numDevices << std::endl; + + for (portaudio::System::DeviceIterator i = sys.devicesBegin(); i != sys.devicesEnd(); ++i) + { + std::cout << "--------------------------------------- device #" << (*i).index() << std::endl; + + // Mark global and API specific default devices: + bool defaultDisplayed = false; + + if ((*i).isSystemDefaultInputDevice()) + { + std::cout << "[ Default Input"; + defaultDisplayed = true; + } + else if ((*i).isHostApiDefaultInputDevice()) + { + std::cout << "[ Default " << (*i).hostApi().name() << " Input"; + defaultDisplayed = true; + } + + if ((*i).isSystemDefaultOutputDevice()) + { + std::cout << (defaultDisplayed ? "," : "["); + std::cout << " Default Output"; + defaultDisplayed = true; + } + else if ((*i).isHostApiDefaultOutputDevice()) + { + std::cout << (defaultDisplayed ? "," : "["); + std::cout << " Default " << (*i).hostApi().name() << " Output"; + defaultDisplayed = true; + } + + if (defaultDisplayed) + std::cout << " ]" << std::endl; + + // Print device info: + std::cout << "Name = " << (*i).name() << std::endl; + std::cout << "Host API = " << (*i).hostApi().name() << std::endl; + std::cout << "Max inputs = " << (*i).maxInputChannels() << ", Max outputs = " << (*i).maxOutputChannels() << std::endl; + + std::cout << "Default low input latency = " << (*i).defaultLowInputLatency() << std::endl; // 8.3 + std::cout << "Default low output latency = " << (*i).defaultLowOutputLatency() << std::endl; // 8.3 + std::cout << "Default high input latency = " << (*i).defaultHighInputLatency() << std::endl; // 8.3 + std::cout << "Default high output latency = " << (*i).defaultHighOutputLatency() << std::endl; // 8.3 + +#ifdef WIN32 + // ASIO specific latency information: + if ((*i).hostApi().typeId() == paASIO) + { + portaudio::AsioDeviceAdapter asioDevice((*i)); + + std::cout << "ASIO minimum buffer size = " << asioDevice.minBufferSize() << std::endl; + std::cout << "ASIO maximum buffer size = " << asioDevice.maxBufferSize() << std::endl; + std::cout << "ASIO preferred buffer size = " << asioDevice.preferredBufferSize() << std::endl; + + if (asioDevice.granularity() == -1) + std::cout << "ASIO buffer granularity = power of 2" << std::endl; + else + std::cout << "ASIO buffer granularity = " << asioDevice.granularity() << std::endl; + } +#endif // WIN32 + + std::cout << "Default sample rate = " << (*i).defaultSampleRate() << std::endl; // 8.2 + + // Poll for standard sample rates: + portaudio::DirectionSpecificStreamParameters inputParameters((*i), (*i).maxInputChannels(), portaudio::INT16, true, 0.0, NULL); + portaudio::DirectionSpecificStreamParameters outputParameters((*i), (*i).maxOutputChannels(), portaudio::INT16, true, 0.0, NULL); + + if (inputParameters.numChannels() > 0) + { + std::cout << "Supported standard sample rates" << std::endl; + std::cout << " for half-duplex 16 bit " << inputParameters.numChannels() << " channel input = " << std::endl; + printSupportedStandardSampleRates(inputParameters, portaudio::DirectionSpecificStreamParameters::null()); + } + + if (outputParameters.numChannels() > 0) + { + std::cout << "Supported standard sample rates" << std::endl; + std::cout << " for half-duplex 16 bit " << outputParameters.numChannels() << " channel output = " << std::endl; + printSupportedStandardSampleRates(portaudio::DirectionSpecificStreamParameters::null(), outputParameters); + } + + if (inputParameters.numChannels() > 0 && outputParameters.numChannels() > 0) + { + std::cout << "Supported standard sample rates" << std::endl; + std::cout << " for full-duplex 16 bit " << inputParameters.numChannels() << " channel input, " << outputParameters.numChannels() << " channel output = " << std::endl; + printSupportedStandardSampleRates(inputParameters, outputParameters); + } + } + + std::cout << "----------------------------------------------" << std::endl; + } + catch (const portaudio::PaException &e) + { + std::cout << "A PortAudio error occured: " << e.paErrorText() << std::endl; + } + catch (const portaudio::PaCppException &e) + { + std::cout << "A PortAudioCpp error occured: " << e.what() << std::endl; + } + catch (const std::exception &e) + { + std::cout << "A generic exception occured: " << e.what() << std::endl; + } + catch (...) + { + std::cout << "An unknown exception occured." << std::endl; + } + + return 0; +} diff --git a/fdmdv2/pa_test/pa_class.h b/fdmdv2/pa_test/pa_class.h new file mode 100644 index 00000000..a1d29597 --- /dev/null +++ b/fdmdv2/pa_test/pa_class.h @@ -0,0 +1,75 @@ +#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); + +class PortAudioWrap +{ + public: + PortAudioWrap(); + ~PortAudioWrap(); + + private: + PaStream *stream; + PaStreamParameters inputBuffer; + PaStreamParameters outputBuffer; + void *userData; + int samplerate; + unsigned long framesPerBuffer; + PaStreamCallbackFlags statusFlags; + PaStreamCallback *streamCallback; + PaStreamFinishedCallback *streamFinishedCallback; + const PaStreamCallbackTimeInfo* timeInfo; + PaDeviceIndex inputDevice; + PaDeviceIndex outputDevice; + + public: + + PaError streamOpen(); + + PaDeviceIndex getDefaultInputDevice(); + PaDeviceIndex getDefaultOutputDevice(); + + PaStreamParameters *getDeviceInfo(PaDeviceIndex idx); + PaError setFramesPerBuffer(unsigned long size); + PaError setSampleRate(unsigned long size); + PaError setStreamFlags(PaStreamFlags flags); + PaError setCallback(PaStreamCallback *streamCallback); + PaError setStreamCallback(PaStream *stream, PaStreamCallback* callback ) { streamCallback = callback; return 0;} + PaError setStreamFinishedCallback(PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback ); + + PaError setInputDevice(PaDeviceIndex dev); + PaError setInputChannelCount(int count); + PaError setInputSampleFormat(PaSampleFormat format); + PaError setInputSampleRate(PaSampleFormat format); + PaError setInputLatency(PaTime latency); + void setInputHostApiStreamInfo(void *info = NULL); + PaTime getInputDefaultLowLatency(); + + PaError setOutputDevice(PaDeviceIndex dev); + PaError setOutputChannelCount(int count); + PaError setOutputSampleFormat(PaSampleFormat format); + PaError setOutputLatency(PaTime latency); + void setOutputHostApiStreamInfo(void *info = NULL); + PaTime getOutputDefaultLowLatency(); + + PaError init(); + PaError streamStart(); + PaError streamClose(); + void terminate(); + bool isOpen() const; + void stop(); + void abort(); + bool isStopped() const; + bool isActive() const; +}; diff --git a/fdmdv2/pa_test/sine.cxx b/fdmdv2/pa_test/sine.cxx new file mode 100644 index 00000000..577a2472 --- /dev/null +++ b/fdmdv2/pa_test/sine.cxx @@ -0,0 +1,137 @@ +// --------------------------------------------------------------------------------------- + +#include +#include +#include +#include +#include "portaudiocpp/PortAudioCpp.hxx" + +// --------------------------------------------------------------------------------------- + +// Some constants: +const int NUM_SECONDS = 5; +const double SAMPLE_RATE = 44100.0; +const int FRAMES_PER_BUFFER = 64; +const int TABLE_SIZE = 200; + +// --------------------------------------------------------------------------------------- + +// SineGenerator class: +class SineGenerator +{ +public: + SineGenerator(int tableSize) : tableSize_(tableSize), leftPhase_(0), rightPhase_(0) + { + const double PI = 3.14159265; + table_ = new float[tableSize]; + for (int i = 0; i < tableSize; ++i) + { + table_[i] = 0.125f * (float)sin(((double)i/(double)tableSize)*PI*2.); + } + } + + ~SineGenerator() + { + delete[] table_; + } + + int generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags) + { + assert(outputBuffer != NULL); + + float **out = static_cast(outputBuffer); + + for (unsigned int i = 0; i < framesPerBuffer; ++i) + { + out[0][i] = table_[leftPhase_]; + out[1][i] = table_[rightPhase_]; + + leftPhase_ += 1; + if (leftPhase_ >= tableSize_) + leftPhase_ -= tableSize_; + + rightPhase_ += 3; + if (rightPhase_ >= tableSize_) + rightPhase_ -= tableSize_; + } + + return paContinue; + } + +private: + float *table_; + int tableSize_; + int leftPhase_; + int rightPhase_; +}; + +// --------------------------------------------------------------------------------------- + +// main: +int main(int, char *[]); +int main(int, char *[]) +{ + try + { + // Create a SineGenerator object: + SineGenerator sineGenerator(TABLE_SIZE); + + std::cout << "Setting up PortAudio..." << std::endl; + + // Set up the System: + portaudio::AutoSystem autoSys; + portaudio::System &sys = portaudio::System::instance(); + + // Set up the parameters required to open a (Callback)Stream: + portaudio::DirectionSpecificStreamParameters outParams(sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false, sys.defaultOutputDevice().defaultLowOutputLatency(), NULL); + portaudio::StreamParameters params(portaudio::DirectionSpecificStreamParameters::null(), outParams, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff); + + std::cout << "Opening stereo output stream..." << std::endl; + + // Create (and open) a new Stream, using the SineGenerator::generate function as a callback: + portaudio::MemFunCallbackStream stream(params, sineGenerator, &SineGenerator::generate); + + std::cout << "Starting playback for " << NUM_SECONDS << " seconds." << std::endl; + + // Start the Stream (audio playback starts): + stream.start(); + + // Wait for 5 seconds: + sys.sleep(NUM_SECONDS * 1000); + + std::cout << "Closing stream..." <