ITAPortaudioInterfaceRecorder.cpp 1.56 KB
Newer Older
1
2
#include <ITAPortaudioInterface.h>
#include <ITADataSource.h>
3
#include <ITADataSourceUtils.h>
4
5
#include <ITABufferDataSink.h>
#include <ITASampleFrame.h>
Jonas Stienen's avatar
Jonas Stienen committed
6
7
8

#include <iostream>
#include <string>
9
10
11
12
13
14
#include <vector>

static double g_dSampleRate = 44.1e3;
static int g_iBlockSize = 512;
static std::string g_sOutputFileName = "ITAPA_Record.wav";
float g_fRecordingTime = 5; // Seconds
Jonas Stienen's avatar
Jonas Stienen committed
15

16
17
void record()
{
Jonas Stienen's avatar
Jonas Stienen committed
18

19
	ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBlockSize );
Jonas Stienen's avatar
Jonas Stienen committed
20
21

	int iInputDevice = ITAPA.GetDefaultInputDevice();
22
	//iInputDevice = 4;
23

Jonas Stienen's avatar
Jonas Stienen committed
24
	ITAPortaudioInterface::ITA_PA_ERRORCODE err;
25
26
27
	err = ITAPA.Initialize( iInputDevice );
	ITAPA.SetPlaybackEnabled( false );
	ITAPA.SetRecordEnabled( true );
Jonas Stienen's avatar
Jonas Stienen committed
28
29
	ITADatasource* pdsRecordDatasource = ITAPA.GetRecordDatasource();
	ITAPA.Open();
30
31
32
33
34
35
36
37

	unsigned int nRecordSamples = ( unsigned int ) ( 5 * g_dSampleRate );
	ITASampleFrame sfRecordData( pdsRecordDatasource->GetNumberOfChannels(), nRecordSamples, true );

	std::vector< float* > vpfRecordData( sfRecordData.channels() );
	for( int i = 0; i < sfRecordData.channels(); i++ )
		vpfRecordData[ i ] = sfRecordData[ i ].data();

Jonas Stienen's avatar
Jonas Stienen committed
38
	ITAPA.Start();
39
40
41
	//ITABufferDataSink oBufferRec( pdsRecordDatasource, vpfRecordData, g_iBlockSize );
	//oBufferRec.Transfer( nRecordSamples );
	WriteFromDatasourceToFile( pdsRecordDatasource, g_sOutputFileName, (unsigned int)(5*g_dSampleRate), 1.0, true, true );
Jonas Stienen's avatar
Jonas Stienen committed
42
43
44
45
	ITAPA.Stop();

	ITAPA.Close();
	ITAPA.Finalize();
46
47
	
	sfRecordData.Store( g_sOutputFileName, g_dSampleRate );
Jonas Stienen's avatar
Jonas Stienen committed
48
49
50
51

	return;
}

52
53
int main( int , char** )
{
Jonas Stienen's avatar
Jonas Stienen committed
54
55
56
57
58
	std::cout << "Starting recording ..." << std::endl;
	record();

	return 0;
}