I am trying to get FMOD to work as I wish.
I have an OGG stream of bytes which I would like to play back as they are coming in. They are from a network stream if that is of relevance.

As my subject title hints at, I am using C#.

This is what I have at the moment:
System system;
Result r;
Sound sound;
Channel channel;

In init:
exinfo.cbsize = Marshal.SizeOf(exinfo);
exinfo.numchannels = 2;
exinfo.defaultfrequency = 44100;
exinfo.format = SOUND_FORMAT.PCM16;
exinfo.suggestedsoundtype = SOUND_TYPE.OGGVORBIS;
r = Factory.System_Create(ref system);
r = system.init(32, INITFLAGS.NORMAL, (IntPtr)null);

In data call back method:
exinfo.length = (uint)rawdata.Length;
r = system.createStream(rawdata, (MODE.OPENMEMORY | MODE.OPENRAW), ref exinfo, ref sound);

ERRCHECK writes out: FMOD error! ERR_FORMAT – Unsupported file or audio format.

I have taken some of this from various examples in the csharp examples directory. This is also from the manual as good as I could do.
I know that my stream can be played correctly as I can play the stream in java (using code below). The stream is actually coming from a java-converted library (using ikvm).
The code below starts with a InputStream called stream. This is exactly the same stream I am using in my C# application.

Java code:
/* Get audio source stream */
sourceStream = AudioSystem.getAudioInputStream(stream);

/* Get source format and set target format. */
sourceFormat = sourceStream.getFormat();
targetFormat = new AudioFormat(
sourceFormat.getSampleRate(), 16,
sourceFormat.getChannels(), true, false
this.audioFormat = targetFormat;

/* Get target audio stream */
this.audioStream = AudioSystem.getAudioInputStream(targetFormat, sourceStream);

/* Get line info for target format. */
DataLine.Info info = new DataLine.Info(SourceDataLine.class, targetFormat);

/* Get line for obtained line info. */
this.audioLine = SourceDataLine)AudioSystem.getLine(info);

/* Finally open line for playback. */

/* Start audio. */

System.out.println(targetFormat); prints out the following line
PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
… and as I wrote above, this plays fine.

Now, this is the only thing I would be using FMOD for. If anyone knows if I could achieve this in a simpler way, please let me know :) I am fairly sure I have missed something basic though, given that I’ve never used FMOD before.

Can anyone help me out? :)
Thanks in advance

  • You must to post comments

A possible alternative is to decode the ogg data yourself and pass the raw PCM data to FMOD.

  • You must to post comments

wiguy, I actually abandoned FDMOD and started using Un4seen Bass and its .NET libraries. It was amazingly easy to play streamed ogg from a byte[].

  • You must to post comments

[quote:1pgfvd12]r = system.createStream(rawdata, (MODE.OPENMEMORY | MODE.OPENRAW), ref exinfo, ref sound); [/quote:1pgfvd12]
‘Raw’ is for raw PCM data only.

I would reccomend you play net streams directly through FMOD, take a look at the C# netstream example.


  • You must to post comments

I have the same problem as wiguy. In my case the network protocol is not HTTP or any of the other standards, which makes it impossible to use out of the box FMOD netstreaming.

I have tried using a workaround. Basically I download the data my way and store it in a byte[]. I provide the data to FMOD using the FMOD_FILE_*CALLBACKs in the FMOD_CREATESOUNDEXINFO struct that is passed to the createStream method. This approach works, but only when all the audio data has been retrieved before the playSound method is called. Also the length of the stream must be known beforehand.

The important question here is: Does FMOD even support "netstreaming" where the user provides the data or does it entirely rely on its own download/buffering mechanisms?

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.