Skip to content

Commit

Permalink
rewrite, v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Nov 18, 2013
1 parent fed272e commit b37089a
Show file tree
Hide file tree
Showing 46 changed files with 1,677 additions and 1,099 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wmp.pro.*
500 changes: 337 additions & 163 deletions RtAudio.cpp

Large diffs are not rendered by default.

112 changes: 79 additions & 33 deletions RtAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/
RtAudio: realtime audio i/o C++ classes
Copyright (c) 2001-2012 Gary P. Scavone
Copyright (c) 2001-2013 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
Expand Down Expand Up @@ -42,15 +42,16 @@
\file RtAudio.h
*/

// RtAudio: Version 4.0.11

#ifndef __RTAUDIO_H
#define __RTAUDIO_H

#include <string>
#include <vector>
#include "RtError.h"

// RtAudio version
static const std::string VERSION( "4.0.12" );

/*! \typedef typedef unsigned long RtAudioFormat;
\brief RtAudio data format type.
Expand All @@ -59,20 +60,18 @@
internal routines will automatically take care of any necessary
byte-swapping between the host format and the soundcard. Thus,
endian-ness is not a concern in the following format definitions.
Note that 24-bit data is expected to be encapsulated in a 32-bit
format.
- \e RTAUDIO_SINT8: 8-bit signed integer.
- \e RTAUDIO_SINT16: 16-bit signed integer.
- \e RTAUDIO_SINT24: Lower 3 bytes of 32-bit signed integer.
- \e RTAUDIO_SINT24: 24-bit signed integer.
- \e RTAUDIO_SINT32: 32-bit signed integer.
- \e RTAUDIO_FLOAT32: Normalized between plus/minus 1.0.
- \e RTAUDIO_FLOAT64: Normalized between plus/minus 1.0.
*/
typedef unsigned long RtAudioFormat;
static const RtAudioFormat RTAUDIO_SINT8 = 0x1; // 8-bit signed integer.
static const RtAudioFormat RTAUDIO_SINT16 = 0x2; // 16-bit signed integer.
static const RtAudioFormat RTAUDIO_SINT24 = 0x4; // Lower 3 bytes of 32-bit signed integer.
static const RtAudioFormat RTAUDIO_SINT24 = 0x4; // 24-bit signed integer.
static const RtAudioFormat RTAUDIO_SINT32 = 0x8; // 32-bit signed integer.
static const RtAudioFormat RTAUDIO_FLOAT32 = 0x10; // Normalized between plus/minus 1.0.
static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; // Normalized between plus/minus 1.0.
Expand Down Expand Up @@ -186,6 +185,12 @@ typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
RtAudioStreamStatus status,
void *userData );

//! RtAudio error callback function prototype.
/*!
\param type Type of error.
\param errorText Error description.
*/
typedef void (*RtAudioErrorCallback)( RtError::Type type, const std::string &errorText );

// **************************************************************** //
//
Expand Down Expand Up @@ -316,6 +321,9 @@ class RtAudio
: flags(0), numberOfBuffers(0), priority(0) {}
};

//! A static function to determine the current RtAudio version.
static std::string getVersion( void ) { return VERSION; }

//! A static function to determine the available compiled audio APIs.
/*!
The values returned in the std::vector can be compared against
Expand Down Expand Up @@ -423,12 +431,14 @@ class RtAudio
chosen. If the RTAUDIO_MINIMIZE_LATENCY flag bit is set, the
lowest allowable value is used. The actual value used is
returned via the structure argument. The parameter is API dependent.
\param errorCallback A client-defined function that will be invoked
when an error has occured.
*/
void openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData = NULL, RtAudio::StreamOptions *options = NULL );
void *userData = NULL, RtAudio::StreamOptions *options = NULL, RtAudioErrorCallback errorCallback = NULL );

//! A function that closes a stream and frees any associated stream memory.
/*!
Expand Down Expand Up @@ -535,12 +545,15 @@ struct CallbackInfo {
ThreadHandle thread;
void *callback;
void *userData;
void *errorCallback;
void *apiInfo; // void pointer for API specific callback information
bool isRunning;
bool doRealtime;
int priority;

// Default constructor.
CallbackInfo()
:object(0), callback(0), userData(0), apiInfo(0), isRunning(false) {}
:object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false) {}
};

// **************************************************************** //
Expand All @@ -557,6 +570,36 @@ struct CallbackInfo {
//
// **************************************************************** //

#pragma pack(push, 1)
class S24 {

protected:
unsigned char c3[3];

public:
S24() {}

S24& operator = ( const int& i ) {
c3[0] = (i & 0x000000ff);
c3[1] = (i & 0x0000ff00) >> 8;
c3[2] = (i & 0x00ff0000) >> 16;
return *this;
}

S24( const S24& v ) { *this = v; }
S24( const double& d ) { *this = (int) d; }
S24( const float& f ) { *this = (int) f; }
S24( const signed short& s ) { *this = (int) s; }
S24( const char& c ) { *this = (int) c; }

int asInt() {
int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
if (i & 0x800000) i |= ~0xffffff;
return i;
}
};
#pragma pack(pop)

#if defined( HAVE_GETTIMEOFDAY )
#include <sys/time.h>
#endif
Expand All @@ -578,17 +621,18 @@ class RtApi
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData, RtAudio::StreamOptions *options );
void *userData, RtAudio::StreamOptions *options,
RtAudioErrorCallback errorCallback );
virtual void closeStream( void );
virtual void startStream( void ) = 0;
virtual void stopStream( void ) = 0;
virtual void abortStream( void ) = 0;
long getStreamLatency( void );
unsigned int getStreamSampleRate( void );
virtual double getStreamTime( void );
bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; };
bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; };
void showWarnings( bool value ) { showWarnings_ = value; };
bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; }
void showWarnings( bool value ) { showWarnings_ = value; }


protected:
Expand Down Expand Up @@ -655,6 +699,7 @@ class RtApi
:apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
};

typedef S24 Int24;
typedef signed short Int16;
typedef signed int Int32;
typedef float Float32;
Expand Down Expand Up @@ -726,7 +771,7 @@ inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
inline bool RtAudio :: isStreamOpen( void ) const throw() { return rtapi_->isStreamOpen(); }
inline bool RtAudio :: isStreamRunning( void ) const throw() { return rtapi_->isStreamRunning(); }
inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); };
inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); }
inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
inline void RtAudio :: showWarnings( bool value ) throw() { rtapi_->showWarnings( value ); }

Expand All @@ -742,7 +787,7 @@ class RtApiCore: public RtApi

RtApiCore();
~RtApiCore();
RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; };
RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
unsigned int getDefaultOutputDevice( void );
Expand Down Expand Up @@ -780,7 +825,7 @@ class RtApiJack: public RtApi

RtApiJack();
~RtApiJack();
RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; };
RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
void closeStream( void );
Expand Down Expand Up @@ -813,7 +858,7 @@ class RtApiAsio: public RtApi

RtApiAsio();
~RtApiAsio();
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; };
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
void closeStream( void );
Expand Down Expand Up @@ -849,7 +894,7 @@ class RtApiDs: public RtApi

RtApiDs();
~RtApiDs();
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; };
RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; }
unsigned int getDeviceCount( void );
unsigned int getDefaultOutputDevice( void );
unsigned int getDefaultInputDevice( void );
Expand All @@ -871,6 +916,7 @@ class RtApiDs: public RtApi
bool coInitialized_;
bool buffersRolling;
long duplexPrerollBytes;
std::vector<struct DsDevice> dsDevices;
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
Expand All @@ -887,7 +933,7 @@ class RtApiAlsa: public RtApi

RtApiAlsa();
~RtApiAlsa();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; };
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
void closeStream( void );
Expand Down Expand Up @@ -919,7 +965,7 @@ class RtApiPulse: public RtApi
{
public:
~RtApiPulse();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; };
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
void closeStream( void );
Expand Down Expand Up @@ -953,7 +999,7 @@ class RtApiOss: public RtApi

RtApiOss();
~RtApiOss();
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; };
RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; }
unsigned int getDeviceCount( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
void closeStream( void );
Expand Down Expand Up @@ -983,21 +1029,21 @@ class RtApiDummy: public RtApi
{
public:

RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtError::WARNING ); };
RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; };
unsigned int getDeviceCount( void ) { return 0; };
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) { RtAudio::DeviceInfo info; return info; };
void closeStream( void ) {};
void startStream( void ) {};
void stopStream( void ) {};
void abortStream( void ) {};
RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtError::WARNING ); }
RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; }
unsigned int getDeviceCount( void ) { return 0; }
RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) { RtAudio::DeviceInfo info; return info; }
void closeStream( void ) {}
void startStream( void ) {}
void stopStream( void ) {}
void abortStream( void ) {}

private:

bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) { return false; };
bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
RtAudio::StreamOptions * /*options*/ ) { return false; }
};

#endif
Expand Down
50 changes: 0 additions & 50 deletions application.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions application.h

This file was deleted.

2 changes: 1 addition & 1 deletion avcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AVCondition::AVCondition() :
AVMutex(), condition()
{
pthread_cond_init(&condition, NULL);
pthread_cond_init(&condition, 0);
}

AVCondition::~AVCondition()
Expand Down
6 changes: 6 additions & 0 deletions avconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdint.h>
#include <string>

typedef float av_sample_t;
typedef size_t av_sample_rate_t;
typedef size_t av_channels_t;
Loading

0 comments on commit b37089a

Please sign in to comment.