I have been trying to use FMODex with C# to write a simple program that rips a CD to WAV files. I have tried to modify the recording and recordtodisk examples in examples_csharp to accomplish this and I get wav files of the correct size that are completely silent (yes I’ve checked the WAV headers and they appear to be fine, I can even check them with codec verifying apps and they look valid). The next thing that I tried was to take the c++ source for cddarip from FMOD 3.74 and modify that to do what I want. There are too many differences between the API’s and I cannot get the callbacks working so I figured that it was time to post to the forum. I need to know how to rip CDDA tracks to WAV files with callbacks (so that I can handle my own status bar display for example) with FMODex and C#. I have been working with FMODex in C# and feel pretty comfortable with the various pieces but this issue has stumped me, my first attempt at a solution came the closest but I was still getting silent WAV files. Every subsequent test I have made has been unsuccessful so it’s time to ask for some help. I can provide sample source if necessary but I probably just need to be pointed in the right direction. Thanks in advance for any help.
- uberweasel asked 11 years ago
Based on the offlinedecoding example I tried the following:
const int chunkSize = 64;
uint totalRead = 0;
uint lastRead = 0;
IntPtr data = Marshal.AllocHGlobal(chunkSize);
byte buffer = new byte[chunkSize];
// Read chunkSize bytes of PCM data from the sound
currentResult = FMOD_Sound_ReadData(soundHandle, ref data, chunkSize, ref lastRead);
Marshal.Copy(data, buffer, 0, chunkSize); fs.Write(buffer, 0, (int)lastRead); // Increment totalRead totalRead += lastRead;
while(currentResult == FMOD.RESULT.OK && lastRead == chunkSize);
And I still have the problem where after calling FMOD_Sound_ReadData() data is pointing to 0 (I can check it right before the call and it is a valid pointer) which causes the an exception when fs.Write is invoked because the source (data) is null. Also if I try the above code with a chunkSize greater than 64 it crashes. Is there something else that I am missing? Thanks for the help.
The most obvious thing I can see from your code is that you are calling FMOD_Sound_ReadData directly, i’m not even sure how you got a raw soundHandle as that isn’t exposed through the c# wrapper.
You need to go through the c# wrapper functions, ie Sound::readData.
I’m suprised your code compiles since FMOD_Sound_ReadData has been declared private in the wrapper.
Thanks for the suggestion. When I call FMOD_Sound_ReadData() I am getting strange results:
IntPtr buffer = new IntPtr();
uint lastRead = 0;
currentResult = FMOD_Sound_ReadData(soundHandle, ref buffer, 128, ref lastRead);
At this point soundHandle – which was previously a valid Sound pointer to the desired SubSound, is now pointing to 0 and buffer is empty, yet lastRead indicates that 128 bytes where read. I have played around with different modes (forcing ASPI for example) but that doesn’t make a difference. What else am I missing. Thanks for helping a newb.
DISCLAIMER: Please forgive my ignorance, multimedia programming is new to me.
I have tried to allocate space for a buffer using Marshal.AllocHGlobal like so:
IntPtr bufferPtr = Marshal.AllocHGlobal(bufferSize)
but this is not working. I’ve got a byte that is the length of the sound in PCM bytes but I’m not sure if I can just use it as the buffer, it seems like this would be too big and I might need to grab the data in smaller chunks but I am unsure. If this will work I am not sure how to get an IntPtr pointed to the address of that byte using managed code (I’m assuming this is what ReadData wants).
Can anyone provide me with the necessary code to create a buffer and a valid IntPtr to that buffer so that I can get FMOD_Sound_ReadData() working? Thanks for all of the help, and my apologies for the stupid questions, I just need some help on the basics so that I can get up to speed.
Please login first to submit.