Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Created July 30, 2012 14:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moligaloo/3207213 to your computer and use it in GitHub Desktop.
Save Moligaloo/3207213 to your computer and use it in GitHub Desktop.
Using fmod play files in the memory
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fmod.h>
int main(void)
{
FILE *fp = fopen("win-cc.ogg", "rb");
fseek(fp, 0, SEEK_END);
int length = ftell(fp);
rewind(fp);
void *buffer = malloc(length);
fread(buffer, length, 1, fp);
fclose(fp);
FMOD_SYSTEM *system;
FMOD_System_Create(&system);
FMOD_System_Init(system, 2, 0, NULL);
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(info));
info.length = length;
info.cbsize = sizeof(info);
FMOD_SOUND *sound;
FMOD_System_CreateSound(system, (const char *)buffer, FMOD_OPENMEMORY , &info, &sound );
FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, NULL);
getchar();
FMOD_System_Release(system);
free(buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment