wave progress
[1/7] from: rcm:formix:au at: 10-Oct-2008 17:25
Hello list,
I want to include a progress bar on a wave player, but can't get it to go
beyond one iteration of
prog/data: prog/data + step
The outcome of the above looks correct for differing file sizes. I
calculate the step value as follows:
step: (prog/size/x / (max 1 fileSize))
I will send the script, but I suspect someone out there has already done
this, however, I can't see anything in the Library or through Googling.
Regards, Rosemary
--
message ends
[2/7] from: henrikmk::gmail::com at: 10-Oct-2008 13:56
On Fri, Oct 10, 2008 at 9:25 AM, Rosemary de Dear <rcm-formix.com.au> wrote:
> Hello list,
> I want to include a progress bar on a wave player, but can't get it to go
<<quoted lines omitted: 5>>
> I will send the script, but I suspect someone out there has already done
> this, however, I can't see anything in the Library or through Googling.
I can't tell much from this, so my suggestion may be off course, but
the progress should be set using SET-FACE to a decimal value between 0
and 1. It's better to calculate the absolute value, rather than using
a step value. To calculate the value, you should not refer to the
progress bar size itself, but the size of the wave file (as you are
doing correctly) and the point at which you are reading the wave file.
I assume you know how much of the wave file you are reading at a time
and how you play it.
set-face prog wave-size / point-in-wave-file
And that's it. Again, sorry, if I'm way off course.
--
Regards,
Henrik Mikael Kristensen
[3/7] from: anton:wilddsl:au at: 11-Oct-2008 1:21
Hi Rosemary,
Henrik Mikael Kristensen wrote:
> set-face prog wave-size / point-in-wave-file
>
> And that's it. Again, sorry, if I'm way off course.
Henrik was right in his comments, but I think made a
slight error. It should be:
set-face prog point-in-wave-file / wave-size
where POINT-IN-WAVE-FILE is the current play position,
and WAVE-SIZE is the total size of the data.
It's very simple, really. No need to worry about
the size of the progress bar face, or STEP.
Let us know how it goes,
Regards,
Anton.
[4/7] from: rcm:formix:au at: 11-Oct-2008 17:59
Thank you Henrik and Anton.
I can't make the progress bar synchronise with the wave file as it's
playing. I realise I need to make a loop, but don't know how to read each
part of the wave. This is the script that gives a "correct" step for one
interation.
rebol []
wave: %any.wav
play: func [audio] [
fileSize: to-integer ((size? wave) / 1024)
sound-port: open sound://
insert sound-port load audio
step: (prog/size/x / (max 1 fileSize))
wait 0.1
prog/data: prog/data + step
show prog
wait sound-port
close sound-port
]
view layout [
prog: progress
btn "Play" [play wave]
]
Regards, Rosemary
On Sat, 11 Oct 2008 00:21:11 +1000, Anton Rolls <anton-wilddsl.net.au>
wrote:
> Hi Rosemary,
> Henrik Mikael Kristensen wrote:
<<quoted lines omitted: 11>>
> Regards,
> Anton.
--
message ends
[5/7] from: anton::wilddsl::net::au at: 11-Oct-2008 19:42
Rosemary,
I see better what you're trying to do, now.
If all you want to do is show progress while
the sound is playing, then see the code at bottom.
The code just calculates where the progress
should be, judging by how much time has elapsed
since the beginning. After inserting the sound
into the sound port, there's no buffer management
that we can do that I'm aware of.
(See code at bottom.)
Regards,
Anton.
Rosemary de Dear wrote:
> Thank you Henrik and Anton.
> I can't make the progress bar synchronise with the wave file as it's
<<quoted lines omitted: 19>>
> ]
> Regards, Rosemary
rebol [
Date: 11-Oct-2008
Author: "Anton Rolls"
Purpose: {Demonstrate updating a progress bar while playing a sound.}
Status: {Working. Tested on 2.7.6.3.1 in Wine on Linux.}
Note: "Rebol's sound port is still buggy."
]
;wavefile: %../local/audio/music/samples/loop-db-4bars.wav
;wavefile: %../local/audio/music/samples/robot1-infiltrate.wav
;wavefile: %../local/audio/music/samples/robot2-suspect.wav
wavefile: %../local/audio/music/samples/robot3-abort.wav
play: func [wavefile][
wave: load wavefile
total-time: 1000 * (length? wave/data) / (
(wave/bits / 8) * wave/channels) / wave/rate
playing?: true
insert sound-port wave
]
window: center-face layout [
button "play" [
set-face my-progress 0
play wavefile
]
button "stop" [
playing?: false
start-time: none
clear sound-port
]
my-progress: progress
; Set face/rate so that timer events
; will start flowing into this window.
box rate 1
]
view/new window
playing?: none
start-time: none
my-event-func: insert-event-func func [face event][
if event/type = 'time [
if playing? [
either none? start-time [
; This is the first event,
; so just record the time.
start-time: event/time
][
; How much time has elapsed
; since the start ?
elapsed: event/time - start-time
; Convert elapsed time
; to range [0.0, 1.0],
; good for the progress bar.
tp: min 1.0 elapsed / total-time
if tp <= 1.0 [
; Update progress bar
set-face my-progress tp
]
if tp >= 1.0 [
playing?: false
start-time: none
]
]
]
]
event
]
sound-port: open sound://
if error? set/any 'err try [
do-events
][
print mold disarm err
]
close sound-port
remove-event-func :my-event-func
()
[6/7] from: rcm:formix:au at: 12-Oct-2008 14:27
Dear Anton,
It worked fine for smaller files, but crashed with those over 1 minute.
Adding additional parentheses, as follows, works:
total-time: 1000 * ((length? wave/data) / ((wave/bits / 8) *
wave/channels) / wave/rate)
Thank you very much, I appreciate the time you took and for showing me the
time formula and using it via the feel function.
Regards, Rosemary
--
message ends
[7/7] from: anton::wilddsl::net::au at: 12-Oct-2008 15:10
Rosemary,
I'm glad to be of assistance.
Thanks for pointing out the total-time overflow.
I did that calculation mathematically correctly,
but without considering limits of precision.
Hope it works out well,
Anton.
Rosemary de Dear wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted