forked from uliwitness/stackimport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSndResource.cpp
139 lines (101 loc) · 3.79 KB
/
CSndResource.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// CSndResource.cpp
// stackimport
//
// Created by Uli Kusterer on 2013-12-30.
//
//
#include "CSndResource.h"
// No-op for now, as the Resource Manager pre-swaps the 'snd ' resource for us:
// But once we're using our own res-fork-reading code, map these to BIG_ENDIAN_xx.
#define BE16(n) n
#define BE32(n) n
CSoundCommand::CSoundCommand( uint16_t inCommandType, uint16_t inParam1, uint32_t inParam2, const char* inData, size_t inDataLen )
: commandType(inCommandType), param1(inParam1), param2(inParam2)
{
mResData = inData;
mResDataLen = inDataLen;
}
size_t CSoundCommand::GetSoundHeaderOffset()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
return param2;
}
uint32_t CSoundCommand::GetNumBytesInSample()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4; // Sound data, then skip pointer for use in RAM.
return BE32( (*(uint32_t*)theData) );
}
uint32_t CSoundCommand::GetSampleRate()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4 +4; // Sound data, then skip pointer for use in RAM, then bytes in sample.
return BE32( (*(uint32_t*)theData) );
}
uint32_t CSoundCommand::GetLoopPointStart()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4 +4 +4; // Sound data, then skip pointer for use in RAM, bytes in sample, sample rate.
return BE32( (*(uint32_t*)theData) );
}
uint32_t CSoundCommand::GetLoopPointEnd()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4 +4 +4 +4; // Sound data, then skip pointer for use in RAM, bytes in sample, sample rate, loop point start.
return BE32( (*(uint32_t*)theData) );
}
uint8_t CSoundCommand::GetStandardSampleEncoding()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4 +4 +4 +4 +4; // Sound data, then skip pointer for use in RAM, bytes in sample, sample rate, loop point start/end.
return BE32( (*(uint8_t*)theData) );
}
uint8_t CSoundCommand::GetBaseFrequency()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return 0;
const char* theData = mResData +param2 +4 +4 +4 +4 +4 +1; // Sound data, then skip pointer for use in RAM, bytes in sample, sample rate, loop point start/end, standard sample encoding.
return BE32( (*(uint8_t*)theData) );
}
const char* CSoundCommand::GetSampleData()
{
if( commandType != 0x8050 && commandType != 0x8051 ) // Neither soundCmd nor bufferCmd?
return NULL;
const char* theData = mResData +param2 +4 +4 +4 +4 +4 +1 +1; // Sound data, then skip pointer for use in RAM, bytes in sample, sample rate, loop point start/end, standard sample encoding, base frequency.
return theData;
}
CSndResource::CSndResource( const char* inData, size_t dataLen )
: mResData(inData), mResDataLen(dataLen)
{
}
uint16_t CSndResource::GetFormat()
{
return BE16((*(uint16_t*)mResData));
}
uint16_t CSndResource::GetNumSoundCommands()
{
switch( GetFormat() )
{
case 2:
{
const char* theData = mResData +2 +2; // Skip type & refCount.
return BE16((*(uint16_t*)theData));
break;
}
}
return 0;
}
CSoundCommand CSndResource::GetSoundCommandAtIndex( size_t inIndex )
{
const char* theData = mResData +2 +2 +2; // Skip type, refCount & number of commands.
theData += inIndex * 8;
CSoundCommand theCmd( BE16((*(uint16_t*)theData)), BE16((*(uint16_t*)(theData +2))), BE16((*(uint32_t*)(theData +2 +2))), mResData, mResDataLen );
return theCmd;
}