summaryrefslogtreecommitdiff
path: root/orkbasecxx/audiofile/AudioFile.h
blob: cc37e4cafb9d269eefe867754769d5b5aa9a3188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

#ifndef __AUDIOFILE_H__
#define __AUDIOFILE_H__

#include "boost/shared_ptr.hpp"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_sys_stat.h"

#include "StdString.h"
#include "AudioCapture.h"


/** Base class for all file accessor classes. */
class DLL_IMPORT_EXPORT_ORKBASE AudioFile
{
public:
	typedef enum {READ = 0, WRITE = 1} fileOpenModeEnum;

	/** Open audio file for reading or writing.
		Filename should include path information but not extension (which is automatically appended)
		If the underlying format does not support stereo, data is transparently read from two files in read mode 
		or two files are transparently written to in write mode */
	virtual void Open(CStdString& filename, fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000) = 0;
	/** Same as above but uses the intenal filename */
	void Open(fileOpenModeEnum mode, bool stereo = false, int sampleRate = 8000);
	/** Explicitely close the underlying file(s). This is also done automatically by the destructor */
	virtual void Close() = 0;

	/** Writes a chunk of audio to disk.
		If stereo capture, this represents the local party */
	virtual void WriteChunk(AudioChunkRef chunkRef) = 0;
	/** Writes a chunk of audio from the remote pary to disk (if stereo capture)
	//virtual bool WriteRemoteChunk(AudioChunkRef chunkRef) = 0;
	/** Reads a chunk of audio stereo-wise 
		If underlying storage is mono, remoteChunk will be NULL 
		ReadChunkStereo guarantees that local and remote chunks returned are in sync */
	//virtual bool ReadChunkStereo(AudioChunkRef& chunk, AudioChunkRef& remoteChunk) = 0;
	/** Reads a chunk of audio mono-wise
		If underlying file is stereo, ReadChunkMono merges the two streams in a synchronized manner and returns the result */
	virtual int ReadChunkMono(AudioChunkRef& chunk) = 0;

	/** Move the file to a new name including ".orig" suffix */
	void MoveOrig();
	void SetFilename(CStdString&);
	void Delete();
	virtual CStdString GetExtension() = 0;
	virtual int GetSampleRate();

protected:
	CStdString m_filename;
	fileOpenModeEnum m_mode;
	int m_numChunksWritten;
	int m_sampleRate;
};

typedef boost::shared_ptr<AudioFile> AudioFileRef;

#endif