-
Notifications
You must be signed in to change notification settings - Fork 43
/
ExtAudioFileX.h
96 lines (92 loc) · 3.37 KB
/
ExtAudioFileX.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef ExtAudioFileX_H
#define ExtAudioFileX_H
#include "CoreAudio/ExtAudioFile.h"
#include "CoreAudio/AudioConverter.h"
#include "cautil.h"
class ExtAudioFileX {
std::shared_ptr<OpaqueExtAudioFileID> m_file;
public:
ExtAudioFileX() {}
ExtAudioFileX(ExtAudioFileRef file, bool takeOwn)
{
attach(file, takeOwn);
}
void attach(ExtAudioFileRef file, bool takeOwn)
{
if (takeOwn)
m_file.reset(file, ExtAudioFileDispose);
else
m_file.reset(file, [](ExtAudioFileRef){});
}
operator ExtAudioFileRef() { return m_file.get(); }
// property accessors
SInt64 getFileLengthFrames()
{
SInt64 value;
UInt32 size = sizeof value;
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_FileLengthFrames,
&size, &value));
return value;
}
AudioStreamBasicDescription getClientDataFormat()
{
AudioStreamBasicDescription result;
UInt32 size = sizeof(AudioStreamBasicDescription);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_ClientDataFormat,
&size, &result));
return result;
}
void setClientDataFormat(const AudioStreamBasicDescription &desc)
{
CHECKCA(ExtAudioFileSetProperty(m_file.get(),
kExtAudioFileProperty_ClientDataFormat,
sizeof(desc), &desc));
}
AudioStreamBasicDescription getFileDataFormat()
{
AudioStreamBasicDescription result;
UInt32 size = sizeof(AudioStreamBasicDescription);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_FileDataFormat,
&size, &result));
return result;
}
std::shared_ptr<AudioChannelLayout> getClientChannelLayout()
{
UInt32 size;
Boolean writable;
CHECKCA(ExtAudioFileGetPropertyInfo(m_file.get(),
kExtAudioFileProperty_ClientChannelLayout, &size, &writable));
std::shared_ptr<AudioChannelLayout> acl(
static_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_ClientChannelLayout, &size, acl.get()));
return acl;
}
std::shared_ptr<AudioChannelLayout> getFileChannelLayout()
{
UInt32 size;
Boolean writable;
CHECKCA(ExtAudioFileGetPropertyInfo(m_file.get(),
kExtAudioFileProperty_FileChannelLayout, &size, &writable));
std::shared_ptr<AudioChannelLayout> acl(
static_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_FileChannelLayout, &size, acl.get()));
return acl;
}
AudioConverterRef getAudioConverter()
{
AudioConverterRef result;
UInt32 size = sizeof(AudioConverterRef);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_AudioConverter,
&size, &result));
return result;
}
};
#endif