Author |
Topic: Multiple WAV playback (Read 1434 times) |
|
5against4
New Member
member is offline


Posts: 16
|
 |
Re: Multiple WAV playback
« Reply #2 on: Oct 28th, 2013, 3:38pm » |
|
Many thanks for the quick reply Richard. Sorry for not including the whole program - see below.
Using the Trace function it's clearly the monitoring of how far through the WAVs that's taking up most of the processing. Do you think this would be reduced at all by reading the WAVs from memory instead of from disk?
Thanks for the tip off about FMOD - i'll investigate right away.
Code:
10 REM http://bb4w.wikispaces.com/Playing+multiple+WAV+files
20 ON ERROR ON:COLOUR9:OSCLI "FONT "+"Consolas"+","+"14":PRINTTAB(0,5):REPORT:PRINT" at line ";ERL:END
30 MODE 30:OFF
40 SYS "ShowWindow", @hwnd%, 3 : REM. SW_MAXIMIZE
50 COLOUR15:OSCLI "FONT Myriad Pro,20"
60 PRINT"Display on?";:REPEAT:disp$=GET$:UNTIL disp$="Y" OR disp$="y" OR disp$="N" OR disp$="n":CLS
70 display=TRUE:IF disp$="N" OR disp$="n" THEN display=FALSE
80 layers=8
90 DIM layer$(layers,12),reply$(layers,2),wavperc$(layers),start(layers),currentwav(layers),begun(layers)
100 url$=""
110 RESTORE 180
120 FOR loop=1 TO layers
130 READ start(loop),layer$(loop,0)
140 FOR loop2=1 TO VAL(layer$(loop,0))
150 READ filename$:layer$(loop,loop2)=url$+filename$+".wav"
160 NEXT
170 NEXT
180 DATA 0,11,h1,h2,h3,h4,h5,h6,t20,t20,t30,t30,t60
190 DATA 1500,12,h1,h2,h3,h4,h5,h6,t20,t20,t30,t30,t45,t60
200 DATA 4000,11,h1,h2,h3,h4,h5,h6,t20,t30,t30,t45,t60
210 DATA 10500,9,b1,b2,b3,b4,b5,b6,t20,t30,t30
220 DATA 12000,9,b1,b2,b3,b4,b5,b6,t20,t20,t30
230 DATA 15000,10,b1,b2,b3,b4,b5,b6,t20,t30,t30,t45
240 DATA 18000,11,n1x,n2x,n3x,n4x,n5x,n6x,n7x,t45,t45,t60,t60
250 DATA 20000,11,w1,w2,w3,w4,w5,w6,w7,w8,t45,t60,t120
260 a=0
270 FOR loop=1 TO layers:reply$(loop,1)="_":reply$(loop,2)="-":NEXT
280
290 REPEAT
300 FOR check=1 TO layers:REM This check is for whether a new sound should begin
310 IF a=0 THEN TIME=0
320 flag=FALSE:IF TIME<start(check) THEN reply$(check,1)="_":reply$(check,2)="-":GOTO 410
330 begun(check)=1
340 IF a=start(check) OR reply$(check,1)=reply$(check,2) THEN flag=TRUE
350 IF flag=TRUE THEN n=VAL(layer$(check,0)):n_wav=RND(n):currentwav(check)=n_wav
360 IF flag=TRUE THEN SYS "mciSendString", "close wav"+STR$(check), 0, 0, 0
370 IF flag=TRUE THEN SYS "mciSendString", "open """ + layer$(check,currentwav(check)) + """ alias wav"+STR$(check), 0, 0, 0
380 IF flag=TRUE THEN SYS "mciSendString", "play wav"+STR$(check), 0, 0, 0
390 REMIF flag=TRUE THEN PRINTTAB(5,check);"Playing layer ";check
400 REMpause=GET
410 NEXT
420
430 a=a+1
440 FOR calc=1 TO layers:REM This calculates how far each layer is through each sound & displays the results (omitted if display not required)
450 reply$(calc,1) = STRING$(16, CHR$(0))
460 reply$(calc,2) = STRING$(16, CHR$(0))
470 SYS "mciSendString", "status wav"+STR$(calc)+" length", reply$(calc,1), LEN(reply$(calc,1)), 0
480 SYS "mciSendString", "status wav"+STR$(calc)+" position", reply$(calc,2), LEN(reply$(calc,2)), 0
490 IF display=FALSE THEN 570
500 IF begun(calc)=1 THEN wavperc=INT((VAL(reply$(calc,2))/VAL(reply$(calc,1)))*100) ELSE wavperc=0
510 wavperc$(calc)=LEFT$(STR$(wavperc),4)
520 COLOUR15:PRINTTAB(3,1);INT((TIME/100)/60);"’";INT(TIME/100) MOD 60;"”";SPC(10);TAB(10,1);TIME
530 PRINTTAB((calc-1)*15+3,4);calc;" (";start(calc);")"
540 IF begun(calc)=1 THEN PRINTTAB((calc-1)*15+3,5);LEFT$(layer$(calc,currentwav(calc)),LEN(layer$(calc,currentwav(calc)))-4);SPC(10)
550 VDU19,calc,16,INT(VAL(wavperc$(calc))*2.55),INT(((VAL(wavperc$(calc)))-100)*-2.55),0:COLOURcalc:PRINTTAB((calc-1)*15+3,6);wavperc$(calc);"%";SPC(10)
560 REMPRINTTAB((calc-1)*15+2,4);calc;" (";start(calc);")";TAB((calc-1)*15+2,5);reply$(calc,1);" : ";reply$(calc,2);SPC(10)
570 NEXT
580 REMPRINT"";a;"|";SPC(5);reply$(1,1);" : ";reply$(1,2);SPC(10);reply$(2,1);" : ";reply$(2,2);SPC(10);reply$(3,1);" : ";reply$(3,2)
590
600
610 UNTIL FALSE
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Multiple WAV playback
« Reply #3 on: Oct 28th, 2013, 4:01pm » |
|
on Oct 28th, 2013, 3:38pm, 5against4 wrote:| Many thanks for the quick reply Richard. Sorry for not including the whole program - see below. |
|
At a quick glance I can't see a WAIT (or other delay statement) anywhere in your program. If that's right it would imply that you have inadvertently coded an 'infinite loop' - i.e. a program which needlessly uses up 100% CPU time chasing around a loop. See this recent thread which discusses the issue:
http://bb4w.conforums.com/index.cgi?action=display&board=communication&num=1382121935&start=0#1382128956
If that's what is happening it could easily explain the symptoms you described.
We have moved on from the days of the BBC Micro, when it was reasonable for a program to keep the CPU fully occupied, despite not doing anything useful. Now, multi-tasking is the norm and every program needs to be written with due consideration for other programs and processes that share the CPU, memory etc.
Richard.
|
|
Logged
|
|
|
|
5against4
New Member
member is offline


Posts: 16
|
 |
Re: Multiple WAV playback
« Reply #4 on: Nov 5th, 2013, 10:48am » |
|
Thanks for this Richard. i confess i hadn't realised about the WAIT command, & it certainly makes a huge difference in terms of CPU drain.
Regarding the FLAC codec you mentioned, FMOD, can that be called/used from within a BASIC program? Looking at their website hasn't quite left me much the wiser...
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Multiple WAV playback
« Reply #5 on: Nov 5th, 2013, 11:28am » |
|
on Nov 5th, 2013, 10:48am, 5against4 wrote:| Regarding the FLAC codec you mentioned, FMOD, can that be called/used from within a BASIC program? |
|
Oh yes, absolutely. I've not used it myself, but I know several people have, particularly in games.
I would have hoped that at least one of said people would have written a Wiki article describing how to do it, but having just looked there's nothing. I'm actually rather saddened by that.
Richard.
|
|
Logged
|
|
|
|
|