If you tested other games, please let me know. If you own any games with .dls, .sty and .sgt files in the data folders, and you want to contribute, please contact me as well or open an issue on GitHub.
Here's how you play back a segment. This example works on POSIX only since it uses <sys/stat.h>
for the file resolver. On Windows, you simply need to replace dm_resolve_file with a Windows-compatible implementation.
#include <dmusic.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
static void* dm_resolve_file(void* ctx, char const* name, size_t* len);
int main(int argc, char** argv) {
puts("Creating the loader failed\n");
return rv;
}
puts("Adding the resolver failed\n");
return rv;
}
puts("Getting the segment failed\n");
return rv;
}
puts("Creating the performance failed\n");
return rv;
}
puts("Playing the segment failed\n");
return rv;
}
size_t len = 1000000;
float* pcm = malloc(sizeof *pcm * len);
puts("Playing the PCM failed\n");
return rv;
}
FILE* fp = fopen("output.pcm", "w");
if (fp == NULL) {
puts("Opening the output file failed\n");
return -1;
}
(void) fwrite(pcm, sizeof *pcm, len, fp);
(void) fclose(fp);
free(pcm);
return 0;
}
static void* dm_resolve_file(void* ctx, char const* name, size_t* len) {
char const* root = ctx;
size_t root_len = strlen(root);
size_t name_len = strlen(name);
int miss_sep = root[root_len - 1] != '/';
char* path = malloc(root_len + name_len + 1 + miss_sep);
memcpy(path, root, root_len);
memcpy(path + root_len + miss_sep, name, name_len);
if (miss_sep) {
path[root_len] = '/';
}
path[root_len + name_len + miss_sep] = '\0';
struct stat st;
if (stat(path, &st) != 0) {
free(path);
return NULL;
}
FILE* fp = fopen(path, "re");
if (fp == NULL) {
free(path);
return NULL;
}
void* bytes = malloc((size_t) st.st_size);
*len = fread(bytes, 1, (size_t) st.st_size, fp);
(void) fclose(fp);
free(path);
return bytes;
}
DmResult
Possible operation result values.
void Dm_setLoggerDefault(DmLogLevel lvl)
Set a default logging function.
@ DmResult_SUCCESS
The operation completed successfully.
@ DmLogLevel_INFO
The log message is informational.
struct DmLoader DmLoader
Represents a DirectMusic Loader.
DmResult DmLoader_create(DmLoader **slf, DmLoaderOptions opt)
Create a new DirectMusic Loader object.
DmResult DmLoader_getSegment(DmLoader *slf, char const *name, DmSegment **segment)
Get a segment from the loader's cache or load it by file name.
void DmLoader_release(DmLoader *slf)
Subtract one from the reference count of a loader.
DmResult DmLoader_addResolver(DmLoader *slf, DmLoaderResolverCallback *resolve, void *ctx)
Add a resolver to the loader.
@ DmLoader_DOWNLOAD
Automatically download references.
@ DmLoader_DEFAULT
Default options for loader objects.
struct DmSegment DmSegment
Represents a DirectMusic Segment.
void DmSegment_release(DmSegment *slf)
Subtract one from the reference count of a segment.
If you have any questions, or you just want to say hi, you can reach me via e-mail (me@lmichaelis.de
) or on Discord either via DM but preferably in the Gothic VR and GMC servers (@lmichaelis
).