ofSoundPlayer and RAW files


I’m having problems to get ofSoundPlayer play RAW sound files.
I have tried with different raw files, getting with the most of them no audio and with one of them a distorted output.

I have prepared two application examples:

the first called noise should reproduce a noise sound, but you get the distorted result.

the second called brush should reproduce a rhythmic pattern but you get no sounds.

the code is very simple, I used one example and just modified the sound path and the name of the synth variable into raw.

Anyone has suggestions about where should I look to fix this?

Hi claudio,

I think I understand why you are having this problem.
Unlike a mp3 or wav raw doesn’t store any information that can describe its format. So when you load the sound you need to explicitly state that you are loading a raw file. You could pass the FSOUND_LOADRAW flag - to the Fmod CreateSound function in ofSoundPlayer - but this would most likely mean you wouldn’t be able to load mp3 or wav files in other projects.

If you want I can code a hack for you for ofSoundPlayer - but maybe the easiest is just to convert the files to Wav?

Why in particular do you need them raw?


Ciao Theo,

I need the files to be raw as I’m building an app that takes a picture with a camera, saves it in raw format and then loads it as a sound and play it back.

It’s the same idea of making an image in photoshop, saving it as a raw file, then open audacity, load the image in audacity as raw data and play it back as a sound.


Here is a hacked extra function for ofSoundPlayer

add this to your cpp file:

void ofSoundPlayer::loadSoundRaw(string fileName){  
	fileName = ofToDataPath(fileName);  
	bMultiPlay = false;  
	//we need to specify RAW  
	int fmodFlags =  FMOD_SOFTWARE | FMOD_OPENRAW;  
	//we also need to tell it info about the raw file  
    memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO));  
    info.cbsize						= sizeof(FMOD_CREATESOUNDEXINFO);     
	info.numchannels				= 1;  
	info.defaultfrequency			= 22050;  
	info.format						= FMOD_SOUND_FORMAT_PCM8;  
	result = FMOD_System_CreateSound(sys, fileName.c_str(),  fmodFlags, &info, &sound);  
	if (result != FMOD_OK){  
		bLoadedOk = false;  
		printf("ofSoundPlayer: Could not load sound file %s \n", fileName.c_str() );  
	} else {  
		bLoadedOk = true;  
		FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_RAWBYTES);  

Then add this to you ofSoundPlayer.h file underneath the loadSound function

		void  	loadSoundRaw(string fileName);  

Then you should be able to load a raw sound in and play it back.

Hope that helps,

thank you very much Theo, works like a charm!