Created
July 30, 2012 14:17
-
-
Save Moligaloo/3207213 to your computer and use it in GitHub Desktop.
Using fmod play files in the memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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