MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / Open

Method Open

stream_audio/osfarchive.cpp:76–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76bool OSFArchive::Open(const char *filename, bool write) {
77 char tag[8];
78
79 ASSERT(!m_fp);
80
81 try {
82 if (write)
83 m_fp = cfopen(filename, "wb");
84 else
85 m_fp = cfopen(filename, "rb");
86
87 if (!m_fp)
88 return false;
89
90 m_writemode = write;
91
92 if (m_writemode)
93 return true;
94
95 // okay, if we are in read mode, then we read in the header NOW
96 memset(tag, 0, sizeof(tag));
97 cfseek(m_fp, -OSF_HDR_SIZE, SEEK_END);
98 cf_ReadBytes((uint8_t *)tag, strlen(OSF_TAG), m_fp);
99 if (strcmp(OSF_TAG, tag) != 0) {
100 mprintf(0, "Illegal OSF file format for %s.\n", filename);
101 cfclose(m_fp);
102 m_fp = NULL;
103 return false;
104 }
105
106 // read in rest of header.
107 m_type = (uint8_t)cf_ReadByte(m_fp);
108 m_comp = (uint8_t)cf_ReadByte(m_fp);
109 m_flags = (uint8_t)cf_ReadByte(m_fp);
110 m_rate = (uint32_t)cf_ReadByte(m_fp);
111
112 if (m_type == OSF_DIGITAL_STRM) {
113 if (m_rate == 11)
114 m_rate = 11025;
115 else if (m_rate == 22)
116 m_rate = 22050;
117 else if (m_rate == 44)
118 m_rate = 44100;
119
120 // read in aux header based off of type.
121 m_hdr.digi.measure = (uint32_t)cf_ReadInt(m_fp);
122 } else {
123 mprintf(0, "Unsupported OSF file type in %s!\n", filename);
124 cfclose(m_fp);
125 m_fp = NULL;
126 return false;
127 }
128
129 // read length.
130 m_length = (uint32_t)cf_ReadInt(m_fp);
131
132 cfseek(m_fp, -OSF_HDR_TITLE_OFS, SEEK_END);
133 if (!cf_ReadBytes((uint8_t *)m_name, OSF_HDR_TITLE_LEN, m_fp)) {

Callers

nothing calls this directly

Calls 6

cfopenFunction · 0.85
cfseekFunction · 0.85
cf_ReadBytesFunction · 0.85
cfcloseFunction · 0.85
cf_ReadByteFunction · 0.85
cf_ReadIntFunction · 0.85

Tested by

no test coverage detected