0
0

I’ve run the UserCreatedSound example but there’s something I don’t understand. The pcmreadcallback function is called several times in the beginning, but is never called again during playback. What I need is to be able to continuously synthesize some audio on the fly, but I can’t do that if the function is only called a few times in the beginning of course.

Is there a way to force FModEx to keep running that function? Or is there another way I should be doing this? I like that example as it’s quite straightforward and simple, so it would be nice if this was the way to go about it.

Also, is there a way to get rid of the clicking? What causes that?

Thanks!

  • You must to post comments
0
0

maybe your length is not long enough. Streams are pre-buffered when you create them, that is the reason for the initial read.
If the sound is short enough and not looping, then the pre-buffering is enough to just have the whole sound sit in the stream buffer and never read again.

The user created sound example reads constantly if you select stream mode.

  • You must to post comments
0
0

Stream mode is activated with %FMOD_CREATESTREAM as follows?

[code:3g6ebcwz]mode = %FMOD_2D OR %FMOD_DEFAULT OR %FMOD_OPENUSER OR %FMOD_CREATESTREAM OR %FMOD_LOOP_NORMAL OR %FMOD_HARDWARE

result = FMOD_System_CreateSoundEx(system, "", MODE, ExInfo, sound1)
result = FMOD_System_PlaySound(system, %FMOD_CHANNEL_FREE, sound1, 0, channel)
[/code:3g6ebcwz]

This crashes for some reason. The pcmreadcallback function I’m using is the same one from the usercreatedsound example. What you’re saying is that if I use stream mode then the pcmreadcallback function will continuously be called, correct? That’s exactly what I want…

All code I’m using here is identical to the usercreatedsound example except for the %FMOD_CREATESTREAM flag being added there. No go unfortunately… Any ideas?

Thanks

  • You must to post comments
0
0

The usercreatedsound already has a stream mode, so you mustnt be using the same code, if the usercreatedsound example works in stream mode, and yours doesnt. It could even be something to do with the contents of your callback.

  • You must to post comments
0
0

Hi, Brett. Thanks for your help.

Source code is below. I can post what I’m trying to do with Windows functions too if it would be helpful for illustration of what I’m trying to do here. As far as I can recall this is the same as the example (where pertinent and not a VB/PB translation thing). I do of course hope I’m doing something wrong and it pops right out like a sore thumb, and you’d be gracious enough to take a gander at it. That’s usually the case with my work when something’s wrong of course :)

My thinking was when you said it needs to be in stream mode was to, well, obviously, change the "mode" to include the only thing "streaming" at all about it. Hence the inclusion of %FMOD_CREATESTREAM in FMOD_System_CreateSoundEx. This inclusion, however, appears to crash the system within the function call itself. There is not a chance to get a return error message.

Anyway, if you see something dumb here I did I’d sure love to hear about it. In the mean time I’ll keep checking the forums for answers.

Thanks for a kick ass system here. :)

Thanks!

[code:3drj3ncn]FUNCTION pcmreadcallback(BYVAL Sound AS LONG, BYVAL DataInput AS LONG, BYVAL datalen AS LONG) AS LONG
LOCAL count AS LONG
LOCAL t1, t2 AS SINGLE
LOCAL v1, v2 AS SINGLE
REDIM stereo16bitbuffer(datalen * 2) AS INTEGER
DO WHILE count < (datalen * 2)
stereo16bitbuffer(count) = SIN(t1) * 32767
count = count + 1
stereo16bitbuffer(count) = SIN(t2) * 32767
count = count + 1
t1 = t1 + 0.01 + v2
t2 = t2 + 0.0142 + v2
v1 = v1 + SIN(t1) * 0.002
v2 = v2 + SIN(t2) * 0.002
LOOP
CopyMemory DataInput, VARPTR(stereo16bitbuffer(0)), (datalen)
pcmreadcallback = 0’FMOD_OK
END FUNCTION

FUNCTION pcmsetposcallback AS LONG

END FUNCTION

FUNCTION PBMAIN AS LONG
LOCAL System AS DWORD
LOCAL Version AS LONG
LOCAL sound1 AS LONG
LOCAL sound2 AS LONG
LOCAL channel AS LONG
LOCAL result AS DWORD
LOCAL T0 AS LONG
LOCAL T1 AS LONG
LOCAL ms AS DWORD
LOCAL lenms AS DWORD
LOCAL playing AS LONG
LOCAL paused AS LONG
LOCAL channelsplaying AS LONG
LOCAL currentsound AS DWORD
LOCAL FileHandle AS LONG

DIM channels AS LONG
DIM frequency AS LONG
DIM soundcreated AS LONG
DIM mode AS LONG
channels = 2
frequency = 44100
soundcreated = %False

DIM ExInfo AS FMOD_CREATESOUNDEXINFO
ExInfo.cbsize = SIZEOF(FMOD_CREATESOUNDEXINFO) ‘SIZEOF(ExInfo) <–SET THIS TO 72 !!!!
ExInfo.fileoffset = 0
ExInfo.length = frequency * channels * 2 * 2
ExInfo.numchannels = channels
ExInfo.defaultfrequency = frequency
ExInfo.format = %FMOD_SOUND_FORMAT_PCM16
ExInfo.initialsubsound = 0
ExInfo.numsubsounds = 0
ExInfo.inclusionlist = 0
ExInfo.inclusionlistnum = 0
ExInfo.pcmreadcallback = CODEPTR(pcmreadcallback)
ExInfo.pcmsetposcallback = CODEPTR(pcmsetposcallback)
ExInfo.nonblockcallback = 0
ExInfo.dlsname = 0
ExInfo.encryptionkey = 0
ExInfo.maxpolyphony = 0
ExInfo.userdata = 0

FMOD_System_Create system
FMOD_System_GetVersion system, version
result = FMOD_System_Init(system, 32, %FMOD_INIT_NORMAL, %NULL)

mode = %FMOD_2D OR %FMOD_DEFAULT OR %FMOD_OPENUSER OR %FMOD_CREATESTREAM OR %FMOD_LOOP_NORMAL OR %FMOD_HARDWARE

result = FMOD_System_CreateSoundEx(system, "", MODE, ExInfo, sound1)

‘//Show an error code if there is one.
IF result THEN MSGBOX FORMAT$(result,"#")

result = FMOD_System_PlaySound(system, %FMOD_CHANNEL_FREE, sound1, 0, channel)
‘//Show an error code if there is one.
IF result THEN MSGBOX FORMAT$(result,"#")

DIM SoundPosition AS VECTOR3D
DIM SoundVelocity AS VECTOR3D
DIM SoundForward AS VECTOR3D
DIM SoundUp AS VECTOR3D
SoundForward.z = 1
SoundUp.y = 1

FMOD_Channel_Set3DAttributes channel,SoundPosition,SoundVelocity
FMOD_System_Set3DListenerAttributes system,0,SoundPosition,SoundVelocity,SoundForward,SoundUp

‘//This makes a dialog box and displays it.
DIALOG NEW 0, "", , , xx&, yy&,%WS_SYSMENU TO hDlg
DIALOG SHOW MODAL hDlg

END FUNCTION
[/code:3drj3ncn]

  • You must to post comments
0
0

[quote="brett":kbcbbyow]The usercreatedsound already has a stream mode, so you mustnt be using the same code, if the usercreatedsound example works in stream mode, and yours doesnt. It could even be something to do with the contents of your callback.[/quote:kbcbbyow]

Hi, Brett. Sure hope I can get a hand here. As shown above, the usercreatedsound example doesn’t appear to work in stream mode, unless I’m setting the mode incorrectly. Again, all I’m doing is adding the one mode flag for stream mode. Nothing else relevant is different that I can see. Any thoughts or suggestions from anyone on this? If we can’t create sound live in a stream as described with fmod then we’ll have to switch to something else and not purchase a commercial license. 😥

This is very simple to do with Windows MMI functions. Here’s an example of the beginnings of my live engine system running under that, which I want to get running under fmod:

http://www.performancesimulations.com/f … neSim1.wav

Surely I could do this in fmod too of course, so this could be done in 3D and be hardware accelerated and so on, I just need to know how. Again, there’s no wav files or mixing at all here, it’s calculated on the fly so I suppose it needs to be a stream. So far the suggestions for streaming it haven’t worked or I’m making a mistake in the above code :(

Please help so we can use this wonderful sound engine for our projects in the future :)

  • You must to post comments
0
0

Unfortunately you’re using visual basic, so our support is limited.
All i can say is the shipped example works in C (have you run it from the bin directory?), so the only issue is to do with the VB code, not fmod.

We’re strapped for time at the moment so i don’t think we can look at this until things ease off, but trust me it works, just compare C vs VB if you can.

  • You must to post comments
0
0

Hi Brett. Thanks for the reply. This is actually PowerBasic, but I’ll have another look at the C code anyway. I’m far away from home right now and don’t have Visual Studio set up here, so further checking into the C version will have to wait until October, unfortunately.

Just to verify, what I should indeed be doing is making a stream by adding the %FMOD_CREATESTREAM flag, right? So in principle I’m on the right track, correct? If I at least know this is the right track then I can keep looking and playing with the PB code. Maybe something will turn up…

Also, the shipped example works just fine in PB too. The problem is that when I add the %FMOD_CREATESTREAM flag it crashes on the one fmod function call mentioned earlier. I’ll ask somebody to try the C version with that flag added and see if that works.

Thanks!

  • You must to post comments
0
0

Hi Brett,

A friend just ran the code in C with the flag added and indeed it does work just fine. The callback function is continuously called as long as it’s running as you described. Now to figure out why it’s not working in my PB version…

Thanks again for you help.

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.