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

Function SoundLoadWaveFile

sndlib/ddsoundload.cpp:109–499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107#define SND_LOAD_ERROR_INVALID 1
108
109char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_file_index, bool f_high_quality,
110 bool f_load_sample_data, int *e_type) {
111
112 // File pointer to sound file
113 CFILE *cfptr;
114
115 char format_type[80]; // ASCII name of format type
116 uint16_t fmttag = 0; // Numerical format type
117 uint32_t ckid; // Current chunk's ID
118 uint32_t cksize; // Current chunk's size in bytes
119 uint32_t filesize; // Size of the sound file
120 uint32_t nextseek = 0; // Location of the next seek
121
122 uint32_t aligned_size; // Sound files are aligned to SOUND_FILE_SAMPLE_ALIGNMENT samples
123
124 // Sound format information
125 int samples_per_second;
126 int16_t bits_per_sample;
127 int16_t number_channels;
128
129 // Used to read temporary long values
130 uint32_t temp_long;
131
132 // Flags for if we previously read data or a format
133 char f_data, f_fmt = 0;
134
135 // Loop counter
136 int count;
137
138 // If there is an error assume it would be because of an invalid file
139 if (e_type)
140 *e_type = SND_LOAD_ERROR_INVALID;
141
142 // Setup the initial sound_file state
143 SoundFiles[sound_file_index].sample_8bit = NULL;
144 SoundFiles[sound_file_index].sample_16bit = NULL;
145 SoundFiles[sound_file_index].sample_length = 0;
146
147 // Open the wave file
148 if ((cfptr = cfopen(filename, "rb")) == NULL) {
149 if (e_type)
150 *e_type = SND_LOAD_ERROR_NO_FILE;
151
152 mprintf(0, "SOUND LOADER: %s not found\n", filename);
153 goto error_state;
154 }
155
156 if (!f_load_sample_data) {
157 cfclose(cfptr);
158 return 1;
159 }
160 // Used for progress bar when loading the level
161 paged_in_count += cfilelength(cfptr);
162 paged_in_num++;
163 // Make sure that it is a RIFF format
164 temp_long = (uint32_t)cf_ReadInt(cfptr);
165 if (temp_long != 0x46464952) {
166 mprintf(0, "SOUND LOADER: %s is not a RIFF format file\n", filename);

Callers 2

LoadSoundFileFunction · 0.85

Calls 8

cfopenFunction · 0.85
cfcloseFunction · 0.85
cfilelengthFunction · 0.85
cf_ReadIntFunction · 0.85
cftellFunction · 0.85
cfseekFunction · 0.85
cf_ReadShortFunction · 0.85
cf_ReadBytesFunction · 0.85

Tested by

no test coverage detected