Professional Web Applications Themes

ASynch read questions? - Mac Programming

Hello, Is there any important difference between PBReadForkAsync and PBReadAsync, other than the fact you're addressing the fork directly. I'm not sure why you would use one over the other? I'm using PBReadForkAsync to load sound file data, but just wondered if I was missing something. Is there any way, with either, to find out how much of the data has been read before it completes? I'm loading long tracks off a CD which takes about 15 sec, and wanted to gradually draw the waveform as portions of the data have become read. At the moment I'm just re-drawing the ...

  1. #1

    Default ASynch read questions?

    Hello,

    Is there any important difference between PBReadForkAsync and
    PBReadAsync, other than the fact you're addressing the fork directly.
    I'm not sure why you would use one over the other?
    I'm using PBReadForkAsync to load sound file data, but just wondered if
    I was missing something.
    Is there any way, with either, to find out how much of the data has been
    read before it completes?
    I'm loading long tracks off a CD which takes about 15 sec, and wanted to
    gradually draw the waveform as portions of the data have become read.
    At the moment I'm just re-drawing the whole buffer every couple of
    seconds. Which begs another question; is it safe to use this buffer data
    while the async read is still in progress.


    Failing that, how do various apps manage to draw data as it is being
    read. Any suggestions welcome.

    Finally, although I can't change tack in the middle of this project, is
    there a more modern OSX way to be doing asynchronous file access that I
    should study?

    Thanks

    Steve

    CW 8.3
    OS 10.2.8

    Steve Guest

  2. #2

    Default Re: ASynch read questions?

    On Sun, 23 Nov 2003, Steve James wrote:
     
    The fork one is part of the new apis that use fsrefs and can handle more
    than 2 gigs in a single fork, they are only available from OS 9 onwards.
    PBReadSync is the older API
     
    don't think so 
    No, while the read is happening, it might (and probably will) be changed
    under your feet. 
    Have 2 buffers. Read into 1, then start drawing buffer 1 while starting to
    read into buffer 2, draw buffer 2 while read into buffer 1...
     
    Do your i/o from a separate preemptive thread (that's all asynchronous i/o
    actually does in OS X anyway.

    Fred
     

    Frederick Guest

  3. #3

    Default Re: ASynch read questions?

    Thanks for the double buffer solution.

    Frederick Cheung wrote:
     
    >
    > No, while the read is happening, it might (and probably will) be changed
    > under your feet.[/ref]



    OK, it's not relevant if I double buffer, but out of interest; if all
    I'm doing is _reading_ values, is it actually dangerous to the IO procs?
    The values I display might be garbage, but could it actually cause a crash?

    Thanks

    Steve

    Steve Guest

  4. #4

    Default Re: ASynch read questions?

    In article
    <srcf.societies.cam.ac.uk>
    ,
    Frederick Cheung <DUH.ucam.org> wrote:
     
    > The fork one is part of the new apis that use fsrefs and can handle more
    > than 2 gigs in a single fork, they are only available from OS 9 onwards.
    > PBReadSync is the older API

    > don't think so 
    > No, while the read is happening, it might (and probably will) be changed
    > under your feet. 
    > Have 2 buffers. Read into 1, then start drawing buffer 1 while starting to
    > read into buffer 2, draw buffer 2 while read into buffer 1...

    > Do your i/o from a separate preemptive thread (that's all asynchronous i/o
    > actually does in OS X anyway.[/ref]

    If that is the case, th prameter block won't be updated until the read
    completes. However, you could pre-clear the buffer, do the read, and
    while the read is happening, 5 times a second, do a binary search in the
    tail of the buffer since last time, for the last trio of non-zero
    samples. That would let you know how much of the buffer has been written
    to, so you know how much to draw.
    David Guest

  5. #5

    Default Re: ASynch read questions?

    Thanks, I'm going to time the search method (on one whole file),
    compared to double buffering in chunks.
    I'm intrigued why you suggested 3 samples though? ... I would have
    thought a hundred or so was necesssary to ensure you haven't just landed
    upon a bit of silence.

    Steve

    (Sorry for splitting this off from c.s.m.o.pp, but it seemed way
    off-topic)



    David Phillip Oster wrote:
     

    Steve Guest

  6. Moderated Post

    Default Re: ASynch read questions?

    Removed by Administrator
    David Guest
    Moderated Post

  7. #7

    Default Re: ASynch read questions?

    In Article bpquqh$5up$btinternet.com, Steve James wrote:
     
    >>
    >> No, while the read is happening, it might (and probably will) be changed
    >> under your feet.[/ref]
    >
    > OK, it's not relevant if I double buffer, but out of interest; if all
    > I'm doing is _reading_ values, is it actually dangerous to the IO procs?
    > The values I display might be garbage, but could it actually cause a crash?[/ref]

    I don't think it will crash. Even if you write it will not.
     

    I guess that search suggested by David will be faster than double
    buffering. Although it is not 100% reliable - certain patterns in
    data might cause short circuting in search blocking your redrawing.

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Guest

  8. #8

    Default Re: ASynch read questions?

    In article <BBE9B614.16914%-DELETE-.org>,
    Mike Kluev <-DELETE-.org> wrote:
     

    Another technique is to allocate 10 buffers, each 1/10th the length of
    the file, and have the completion routine of the first read enqueue the
    async read of the next. (You may need to have the completion routine
    start a time manager task, which starts the next read just to make
    certain that if the read is actually done synchronously by the o.s., you
    don't overflow the stack.)

    (This extends to many buffers)
    David Guest

Similar Threads

  1. Please Read: Illustrator CS Crashing Issues - Questions From Adobe
    By ShaneAdobeTS@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 81
    Last Post: September 2nd, 03:13 AM
  2. Calling an Asynch web service within a web service.
    By Tony T. in forum ASP.NET Web Services
    Replies: 0
    Last Post: April 25th, 11:46 PM
  3. File system get auto change from read-write to read-oly
    By RC in forum Linux / Unix Administration
    Replies: 1
    Last Post: October 23rd, 10:51 PM
  4. ** READ THIS BEFORE POSTING - answers to frequently asked questions
    By Karl Levinson [x y] mvp in forum Windows Setup, Administration & Security
    Replies: 5
    Last Post: July 23rd, 09:54 AM
  5. Read & Read/Write Groups
    By Damien Harrod in forum Sun Solaris
    Replies: 1
    Last Post: July 22nd, 01:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139