i used the following function to play any audio file in my player
[code:8lpfeil0]Public Sub fmod_play(ByVal filename As String)
Dim Version As Long 'creating system object for fmod engine result = FMOD_System_Create(system) ERRCHECK (result) 'checking for version history result = FMOD_System_GetVersion(system, Version) ERRCHECK (result) 'giving information about fmodex version If Version <> FMOD_VERSION Then MsgBox "Error! You are using an old version of FMOD " & Hex$(Version) & ". " & _ "This program requires " & Hex$(FMOD_VERSION) End If 'Setting speaker mode result = FMOD_System_SetSpeakerMode(system, FMOD_SPEAKERMODE_PROLOGIC) ERRCHECK (result) 'initializing the fmod engine result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, 0) ERRCHECK (result)
fmod_playflag = False
‘checking for file opened and the selected file
If fmod_fileflag = 1 Then 'Creating the stream result = FMOD_System_CreateStream(system, filename, (FMOD_SOFTWARE), sound) ERRCHECK (result) fmod_fileflag = 0 End If 'playing the file If sound Then result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, channel) ERRCHECK (result) If result = 0 Then fmod_playflag = True fmod_file = filename End If If Frm_Main.PicVolIn.Top = 88 Then fmod_volume = 0# Else fmod_volume = 1# - Val(Frm_Main.PicVolIn.Top / 100) End If result = FMOD_Channel_SetVolume(channel, fmod_volume) ERRCHECK (result) Exit Sub End If
While i play any file by using the above function the cpu usage is very high .it sometimes reaches 100% also mostly on an average it is between 85%-99%.i would like to know is there is any problem with my code or fmodex .I have a PC wit P4 and 256MB DDR ram.With almost 60GB harddisk free.
Then i also have another problem i use vb for my player and when i move the form in run time the volume of the currntly playing song gets hiked automatically this happens until Full(1.0) volume is reached.
- prabeesh asked 12 years ago
[list:1os95fcu]Yes what you said is correct i create system and sound everytime i play as song. i will clear my doubt and my use of fmod .Actually i am doing a mediaplayer which has both audio and video support.i use mcisendstring api for video works and fmod for audio works.intially as you have said i created the system when the application starts and released it when application ends.But even after i release the sound and switch to some other like video the cpu usage was as high as 95% so then i decided to create system each time the audio is played and released when audio is stopped.when i did this and when player is switched to video the cpu usage is as low as just 10-20% only when the player switchs to audio part the cpu usage increases.please help me do i want to post my mediaplayer as whole (because that is done in vb and its huge and i can’t take to any single exact position were the problem is but if needed i will post it)
Please help me about this issue .[/list:u:1os95fcu]
[list:1os95fcu]Sir please also give me a solution to another problem specified in it.(i.e) when ever i play the song and move the form in which i play the song the volume gets hiked automatically.(i checked with a break statements at the point i call setvolume but while i am moving the form none of the break is executed)
Please give me a solution for this problem also[/list:u:1os95fcu]
Having already gone through this the first time I wrote a media app in VB, I can tell you that any extended looping will trigger high CPU usage. It is common for programmers to use Do/Loop as a way to monitor statistics and other info (such as media position) during playback. Perhaps you are using the same approach? If so, the following points might help you to improve your app’s behavior.
Inserting DoEvents in such a loop doesn’t help. Inserting Sleep can help, but it can be tricky to find a good balance between acceptable CPU usage and smooth execution. In my opinion, the best alternative to CPU-unfriendly looping is VB’s timer control (or one of the high resolution variants).
Again, I’m only suggesting that you are using a loop somewhere, and it is the looping that is hiking up the CPU usage.
thanks for the help in cpu usage.But the other problem is with the volume.
i pay the song and when i move my form anywhere using mouse the voume gets hiked to the maximum .i tried using the timer to getvolume and setvolume to normal but the getvolume return the low value(original value which i have set) even if i set some low value the sound remains same.please help me about this
Do you have volume controls on your media player’s GUI (e.g., slider controls) ? If so, do they also change?
It could be that your program suffers from recursive coding–which means you are allowing operations to trigger themselves as a consequence of their own execution. For instance, it is possible for the slider control to fire three events when the value changes: Click, Change, and Scroll. Programmers sometimes unwittingly force one event to trigger another, not knowing that it happens anyway, and in a fixed order. A Form has similar events (e.g., Activate, Click, GetFocus, MouseMove, etc) that can give rise to the same problem.
Maybe open the Windows Volume Control and make sure those slider controls are not changing, too.
Hi stdev and brett,
Thanks for helping me sort that issue ,,,you both where right in your point…..
i was actually having a built in usercontrol which caused internal trigger to the change event function of the user control.
This event was called n number of times since i was using the loop within a timer event,,,Hence causing the usage of CPU
I am posting it because if someone else have similar problem then they can reffer to it 😀
- prabeesh answered 11 years ago
Please login first to submit.