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:
exinfo = new CREATESOUNDEXINFO();
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.
/* Get audio source stream */
sourceStream = AudioSystem.getAudioInputStream(stream);
/* Get source format and set target format. */
sourceFormat = sourceStream.getFormat();
targetFormat = new AudioFormat(
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
- wiguy asked 7 years ago
[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.
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?
Please login first to submit.