Professional Web Applications Themes

Odd Sound Manager/Graphics Problem (Classic) - Mac Programming

Hi all! A few years back I was playing around with the Sound Manager and an oscilloscope routine (from David Philip Oster). Basically, this grabs 512 bytes of data from the default sound input and maps it into a waveform on a 256 high x 512 wide bitmap. I recently tried compiling/running the same code on my PowerBook G3 and, while it works, the mapping isn't happening correctly - I see the first half of the sampled sound squished into the top & bottom 5% of the "scope" screen with nothing in the middle (whereas the waveform should be centered ...

  1. #1

    Default Odd Sound Manager/Graphics Problem (Classic)

    Hi all!

    A few years back I was playing around with the Sound Manager and an
    oscilloscope routine (from David Philip Oster). Basically, this
    grabs 512 bytes of data from the default sound input and maps it
    into a waveform on a 256 high x 512 wide bitmap.

    I recently tried compiling/running the same code on my PowerBook G3
    and, while it works, the mapping isn't happening correctly - I see
    the first half of the sampled sound squished into the top & bottom
    5% of the "scope" screen with nothing in the middle (whereas the
    waveform should be centered vertically), then the second half of the
    "scope" appears to be just random noise.

    I'm compiling using MW Codewarrior pro 4 with identical settings
    on both machines (the original was compiled/run on a Performa 5200CD
    running OS 7.5.5, PPC 603e chip); the PowerBook G3 is running 9.2.2)
    The one difference that stands out is the sound manager version -
    3.7.1 versus 3.4.

    Does anyone know if there is a difference in the way SM 3.7.1 stores
    the waveform data versus SM 3.4? It seems like the problem has got to
    be either this, or some difference in the way the different variables
    etc are packed/sized between the different systems (although all compiler
    flags/options are set identically)

    Part of the code looks like this (error trapping omitted for clarity):

    static Handle scopeSound; /** allocated elsewhere - routine would not be
    called if this was not valid **/
    OSErr myErr = noErr;
    long sndBytes = 0L;
    short headLength = 0;
    short meterLevel = -1;

    sndBytes = scopeBufLen;
    myErr = RecordSndSync(scopeSound, &sndBytes, &headLength, &meterLevel);
    HLock(scopeSound);
    ShowScopeBuffer((unsigned char *)&((*scopeSound)[headLength]), win);
    HUnlock(scopeSound);

    The sndBytes checks out - 512 bytes requested and stuffed into scopeSound.
    The ShowScopeBuffer routine looks like this:

    void ShowScopeBuffer(unsigned char *p, WindowPtr win)
    {
    short height, x, y;
    Fixed increment, i;
    Ptr theByte;
    long *bp, *bend;
    short xMax;

    if(!isScopeBits) return; /** DCS: no valid bitmap!! **/
    if(win == nil) return; /** DCS: no valid window!! **/

    if((bp = (long *) scopeBits.baseAddr) == nil) {
    /** Check if the bitmap is valid **/
    return;
    }

    if (p == nil) p = scopeTest; /** DCS: no input then use test **/

    /** zero the bitmap **/

    bend = (long *) ( ((Ptr) bp) + GetPtrSize((Ptr) bp));
    bend --;
    while(bp < bend){
    *bp ++ = 0L;
    }

    /** calculate the scaling factors for the display **/

    height = (scopeBits.bounds.bottom - scopeBits.bounds.top);
    increment = FixRatio(OSC_SCANSIZE, (scopeBits.bounds.right-1 -
    scopeBits.bounds.left));
    if(increment <= 0){
    increment = 0;
    }
    i = 0;
    xMax = scopeBits.bounds.right-scopeBits.bounds.left;

    /** calculate the pixel to turn on in each row
    notes: i >> 16 gets numerator part (ie short integer) of index only;
    screen vertical coords increase top->bottom so reverse sense of p[];
    avoid fractional horizontal (x) pixel values due to scaling;
    each byte in the bitmap contains 8 bits (x >> 3) and we access each
    one by |='ing the byte with one of the masks stored in the array
    thePix by indexing in turn off the 3 least significant bits of x
    **/
    for(x = 0;x < xMax; x++){
    y = (255 - p[i >> 16]) * height / 256;
    theByte = scopeBits.baseAddr + ((long) y * scopeBits.rowBytes) + (x >> 3);
    if((Ptr)theByte < (Ptr)bend){
    *theByte |= thePix[x & 7];
    }
    i += increment;
    }

    /** all done: blit the bitmap to the screen, in colour!! **/
    RGBBackColor(&scopeScreen);
    RGBForeColor(&scopeTrace);
    CopyBits(&scopeBits, &win->portBits, &scopeBits.bounds, &scopeBits.bounds,
    srcCopy, nil);
    RGBForeColor(&foreColor);
    RGBBackColor(&backColor);
    }
    David Guest

  2. #2

    Default Re: Odd Sound Manager/Graphics Problem (Classic)

    In article <chem.utoronto.ca>,
    invalid (David Stone) wrote:
     

    That sounds very much as if you are using signed integers where signed
    ones are needed or vice versa.

    On the other hand the only thing that smells like a bug is the following:

    theByte = scopeBits.baseAddr
    + ((long) y * scopeBits.rowBytes)
    + (x >> 3);

    rowBytes is not only used to store the number of bytes in a row. See <http://developer.apple.com/technotes/qd/qd_15.html>

    Reinder
    Reinder Guest

  3. #3

    Default Re: Odd Sound Manager/Graphics Problem (Classic)

    In article <wxs.nl>, Reinder
    Verlinde <invalid> wrote:

    [snip] 

    Assume that's a mistype of signed/unsigned (and vice versa) - will
    double-check all the numbers and types.
     

    That rings a bell. I'm not sure if it's strictly applicable in this
    case since all the fields in scopeBits are filled in explicitly in the
    setup code - it's not a BitMap that's created by/extracted from some
    part of the toolbox/os. I will check it out, however. It's been quite
    a while since I last worked with this code!!
     
    David Guest

  4. #4

    Default Re: Odd Sound Manager/Graphics Problem (Classic)

    In article <wxs.nl>,
    Reinder Verlinde <invalid> wrote:
     
    >
    > That sounds very much as if you are using signed integers where signed
    > ones are needed or vice versa.
    >
    > On the other hand the only thing that smells like a bug is the following:
    >
    > theByte = scopeBits.baseAddr
    > + ((long) y * scopeBits.rowBytes)
    > + (x >> 3);
    >
    > rowBytes is not only used to store the number of bytes in a row. See
    > <http://developer.apple.com/technotes/qd/qd_15.html>[/ref]

    You've hit it. The original was ancient code, back from the 1-bit per
    pixel black&white, slow, Mac days. These days, you just use Quickdraw to
    draw a 1x1 rectangle where you want it. (you keep the coordinates of the
    previous trace in an integer array, so for each x, you can draw the
    background y coordinate (to erase the previous trace) before you draw
    the new trace.
    David Guest

  5. #5

    Default Re: Odd Sound Manager/Graphics Problem (Classic)

    In article <sf.sbcglobal.net>, David
    Phillip Oster <org> wrote:
     
    [snip] 
    >
    > You've hit it. The original was ancient code, back from the 1-bit per
    > pixel black&white, slow, Mac days. These days, you just use Quickdraw to
    > draw a 1x1 rectangle where you want it. (you keep the coordinates of the
    > previous trace in an integer array, so for each x, you can draw the
    > background y coordinate (to erase the previous trace) before you draw
    > the new trace.[/ref]

    Ah! So obviously the real difference in the effects between the two
    macs lies in the QuickDraw version.

    I hadn't thought about the speed issue - even the 603 cpu should be
    fast enough to use 1x1 rects instead of the bitmap, and it would make
    it a lot easier to add a "vertical gain" into the code. I could probably
    go further and add separate displays for left and right channels, which
    might be fun to watch! Of course, I'd still want it to run on my Mac SE
    just so I could say that it could be done :)

    Do you think a Move()/LineTo(1,1) would be faster or slower than a
    Rect()?

    I'll try getting the bitmap version running on the powerbook anyway, now
    I know where to look. If i can get this one slight glitch ironed out,
    you'd have code that would run on everything from a MacPlus to what, a
    G4 running OS 9.2.2? That's two decades, or about 2 centuries in
    computer years! I draw the line at carbonizing it, though...*

    *I'd hope there would be a much better way of doing the whole thing
    native in X.
    David Guest

  6. #6

    Default Re: Odd Sound Manager/Graphics Problem (Classic)

    In article <080120040915178163%com>, David C. Stone
    <com> wrote:
     
    > [snip] 
    > >
    > > You've hit it. The original was ancient code, back from the 1-bit per
    > > pixel black&white, slow, Mac days.[/ref][/ref]

    OK, I take it back. It's NOT the value of rowBytes; this is set
    correctly for the bitmap being used as the "scope" screen, and is
    not mysteriously changing. The real problem appears to be with the
    values pulled from the sound recording, which end up in the value of
    y above. I'm going to have to hit the sound manager docs again and
    do some rooting around.
    David Guest

Similar Threads

  1. Problem with Extension Manager in DW 8
    By quintalr in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 2
    Last Post: December 8th, 05:57 PM
  2. Extension manager 1.7 Problem
    By Peaceofmind in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 12
    Last Post: June 9th, 01:46 PM
  3. problem with extenison manager
    By bigbaker in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 3
    Last Post: May 16th, 06:01 PM
  4. Graphics Manager Crashes Publisher
    By JWPlatt in forum Web Design
    Replies: 13
    Last Post: March 9th, 01:24 AM
  5. Graphics Problem on U30.
    By Fredrik Lundholm in forum Sun Solaris
    Replies: 0
    Last Post: July 21st, 01:25 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