2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2008-08-10 10:14:30 +02:00
|
|
|
* Copyright (c) 2004-2008
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( AFX_SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define AFX_SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include <string>
|
2008-11-01 12:48:17 +01:00
|
|
|
#include <qmessagebox.h>
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "../src/util.h"
|
|
|
|
#include "../src/global.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Definitions ****************************************************************/
|
2007-12-17 22:28:40 +01:00
|
|
|
// switch here between ASIO (Steinberg) or native Windows(TM) sound interface
|
2008-04-08 20:38:55 +02:00
|
|
|
//#undef USE_ASIO_SND_INTERFACE
|
|
|
|
#define USE_ASIO_SND_INTERFACE
|
2007-12-17 22:28:40 +01:00
|
|
|
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
#define NUM_IN_OUT_CHANNELS 2 /* Stereo recording (but we only
|
|
|
|
use one channel for recording) */
|
2007-09-08 12:45:14 +02:00
|
|
|
#define BITS_PER_SAMPLE 16 // use all bits of the D/A-converter
|
|
|
|
#define BYTES_PER_SAMPLE 2 // number of bytes per sample
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-07-13 19:55:14 +02:00
|
|
|
#define MAX_SND_BUF_IN 100
|
|
|
|
#define MAX_SND_BUF_OUT 100
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-07-17 20:39:24 +02:00
|
|
|
#define NUM_SOUND_BUFFERS_IN 4
|
|
|
|
#define NUM_SOUND_BUFFERS_OUT 4
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
2007-12-17 22:28:40 +01:00
|
|
|
#ifdef USE_ASIO_SND_INTERFACE
|
|
|
|
|
|
|
|
// copy the ASIO SDK in the llcon/windows directory: "llcon/windows/ASIOSDK2" to
|
|
|
|
// get it work
|
|
|
|
|
|
|
|
#include "asiosys.h"
|
|
|
|
#include "asio.h"
|
|
|
|
#include "asiodrivers.h"
|
|
|
|
|
2007-12-18 21:52:48 +01:00
|
|
|
|
2007-12-17 22:28:40 +01:00
|
|
|
class CSound
|
|
|
|
{
|
|
|
|
public:
|
2008-10-31 21:27:55 +01:00
|
|
|
CSound ( const int iNewBufferSizeStereo );
|
2007-12-17 22:28:40 +01:00
|
|
|
virtual ~CSound();
|
|
|
|
|
2008-10-31 21:27:55 +01:00
|
|
|
void InitRecording ( const bool bNewBlocking = true )
|
2008-10-31 00:23:26 +01:00
|
|
|
{
|
|
|
|
bBlockingRec = bNewBlocking;
|
2008-10-31 21:27:55 +01:00
|
|
|
InitRecordingAndPlayback();
|
2008-10-31 00:23:26 +01:00
|
|
|
}
|
2008-10-31 21:27:55 +01:00
|
|
|
void InitPlayback ( const bool bNewBlocking = false )
|
2008-10-31 00:23:26 +01:00
|
|
|
{
|
|
|
|
bBlockingPlay = bNewBlocking;
|
2008-10-31 21:27:55 +01:00
|
|
|
InitRecordingAndPlayback();
|
2008-10-31 00:23:26 +01:00
|
|
|
}
|
2007-12-17 22:28:40 +01:00
|
|
|
bool Read ( CVector<short>& psData );
|
|
|
|
bool Write ( CVector<short>& psData );
|
|
|
|
|
2008-10-31 00:23:26 +01:00
|
|
|
int GetNumDev() { return lNumDevs; }
|
|
|
|
std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; }
|
|
|
|
|
|
|
|
void SetDev ( const int iNewDev );
|
|
|
|
int GetDev() { return lCurDev; }
|
|
|
|
|
|
|
|
void SetOutNumBuf ( const int iNewNum );
|
2008-07-12 13:48:51 +02:00
|
|
|
int GetOutNumBuf();
|
2008-10-31 00:23:26 +01:00
|
|
|
void SetInNumBuf ( const int iNewNum );
|
2008-07-12 13:48:51 +02:00
|
|
|
int GetInNumBuf();
|
2007-12-17 22:28:40 +01:00
|
|
|
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
protected:
|
2008-10-31 00:23:26 +01:00
|
|
|
bool LoadAndInitializeFirstValidDriver();
|
2008-10-31 21:27:55 +01:00
|
|
|
std::string LoadAndInitializeDriver ( int iIdx );
|
2008-11-01 09:47:31 +01:00
|
|
|
std::string PrepareDriver();
|
2008-10-31 21:27:55 +01:00
|
|
|
void InitRecordingAndPlayback();
|
2007-12-17 22:28:40 +01:00
|
|
|
|
2008-04-13 18:43:21 +02:00
|
|
|
// audio hardware buffer info
|
|
|
|
struct sHWBufferInfo
|
|
|
|
{
|
|
|
|
long lMinSize;
|
|
|
|
long lMaxSize;
|
|
|
|
long lPreferredSize;
|
|
|
|
long lGranularity;
|
|
|
|
} HWBufferInfo;
|
|
|
|
|
2007-12-19 21:16:50 +01:00
|
|
|
// callbacks
|
2008-03-16 14:10:46 +01:00
|
|
|
static void bufferSwitch ( long index, ASIOBool processNow );
|
2007-12-19 21:16:50 +01:00
|
|
|
static ASIOTime* bufferSwitchTimeInfo ( ASIOTime *timeInfo, long index, ASIOBool processNow );
|
2008-03-16 14:10:46 +01:00
|
|
|
static void sampleRateChanged ( ASIOSampleRate sRate ) {}
|
|
|
|
static long asioMessages ( long selector, long value, void* message, double* opt );
|
2007-12-17 22:28:40 +01:00
|
|
|
|
2008-10-31 00:23:26 +01:00
|
|
|
long lNumDevs;
|
|
|
|
long lCurDev;
|
|
|
|
char* cDriverNames[MAX_NUMBER_SOUND_CARDS];
|
|
|
|
|
2008-03-16 14:10:46 +01:00
|
|
|
bool bChangParamIn;
|
|
|
|
bool bChangParamOut;
|
2007-12-17 22:28:40 +01:00
|
|
|
|
2008-07-12 13:48:51 +02:00
|
|
|
bool bBlockingRec;
|
|
|
|
bool bBlockingPlay;
|
2007-12-17 22:28:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#else // USE_ASIO_SND_INTERFACE
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
class CSound
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSound();
|
|
|
|
virtual ~CSound();
|
|
|
|
|
2008-01-27 11:05:15 +01:00
|
|
|
void InitRecording ( int iNewBufferSize, bool bNewBlocking = true );
|
|
|
|
void InitPlayback ( int iNewBufferSize, bool bNewBlocking = false );
|
2007-09-08 12:45:14 +02:00
|
|
|
bool Read ( CVector<short>& psData );
|
|
|
|
bool Write ( CVector<short>& psData );
|
|
|
|
|
|
|
|
int GetNumDev() { return iNumDevs; }
|
|
|
|
std::string GetDeviceName ( int iDiD ) { return pstrDevices[iDiD]; }
|
2008-10-31 00:23:26 +01:00
|
|
|
|
|
|
|
// dummy functions
|
|
|
|
int SetDev ( const int iNewDev ) {}
|
|
|
|
int GetDev() { return 0; }
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
void SetOutDev ( int iNewDev );
|
|
|
|
int GetOutDev() { return iCurOutDev; }
|
|
|
|
void SetInDev ( int iNewDev );
|
|
|
|
int GetInDev() { return iCurInDev; }
|
|
|
|
void SetOutNumBuf ( int iNewNum );
|
|
|
|
int GetOutNumBuf() { return iCurNumSndBufOut; }
|
|
|
|
void SetInNumBuf ( int iNewNum );
|
|
|
|
int GetInNumBuf() { return iCurNumSndBufIn; }
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void OpenInDevice();
|
|
|
|
void OpenOutDevice();
|
2007-09-08 12:45:14 +02:00
|
|
|
void PrepareInBuffer ( int iBufNum );
|
|
|
|
void PrepareOutBuffer ( int iBufNum );
|
2006-12-18 15:39:33 +01:00
|
|
|
void AddInBuffer();
|
2007-09-08 12:45:14 +02:00
|
|
|
void AddOutBuffer ( int iBufNum );
|
|
|
|
void GetDoneBuffer ( int& iCntPrepBuf, int& iIndexDoneBuf );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
WAVEFORMATEX sWaveFormatEx;
|
|
|
|
UINT iNumDevs;
|
|
|
|
std::string pstrDevices[MAX_NUMBER_SOUND_CARDS];
|
|
|
|
UINT iCurInDev;
|
|
|
|
UINT iCurOutDev;
|
|
|
|
bool bChangParamIn;
|
|
|
|
bool bChangParamOut;
|
|
|
|
int iCurNumSndBufIn;
|
|
|
|
int iCurNumSndBufOut;
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
// wave in
|
2006-12-18 15:39:33 +01:00
|
|
|
WAVEINCAPS m_WaveInDevCaps;
|
|
|
|
HWAVEIN m_WaveIn;
|
|
|
|
HANDLE m_WaveInEvent;
|
|
|
|
WAVEHDR m_WaveInHeader[MAX_SND_BUF_IN];
|
|
|
|
int iBufferSizeIn;
|
|
|
|
int iWhichBufferIn;
|
|
|
|
short* psSoundcardBuffer[MAX_SND_BUF_IN];
|
|
|
|
bool bBlockingRec;
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
// wave out
|
2006-12-18 15:39:33 +01:00
|
|
|
int iBufferSizeOut;
|
|
|
|
HWAVEOUT m_WaveOut;
|
|
|
|
short* psPlaybackBuffer[MAX_SND_BUF_OUT];
|
|
|
|
WAVEHDR m_WaveOutHeader[MAX_SND_BUF_OUT];
|
|
|
|
HANDLE m_WaveOutEvent;
|
|
|
|
bool bBlockingPlay;
|
|
|
|
};
|
|
|
|
|
2007-12-17 22:28:40 +01:00
|
|
|
#endif // USE_ASIO_SND_INTERFACE
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif // !defined ( AFX_SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_ )
|