Csound Csound-dev Csound-tekno Search About

Cue points

Date1999-01-21 05:34
From"Vadim V. Sytnikov"
SubjectCue points
Richard Dobson wrote:
> 
> There is provision for loops in WAV files; there is a  chunk
> (vintage 1993 originated by Digidesign, Sonic Foundry and Turtle Beach)
> carrying most of the needed information, with a secondary chunk optional
> for textual data   ...

Never ever read MS specs -- just see what people are actually reading and
writing. A widely accepted way of using loops with .wavs are cue points.

What follows is an excerpt from the utils3/qdata/video.c -- a part of the
source code archive that came with Quake II. It is pretty self-explanatory
and contains a [little] hack to deal with loops made with cooledit.

You may also want to check ftp.idsoftware.com/idstuff/ yourself.

/*
============
GetWavinfo
============
*/
wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength)
{
    wavinfo_t   info;
    int     i;
    int     format;
    int     samples;

    memset (&info, 0, sizeof(info));

    if (!wav)
        return info;
        
    iff_data = wav;
    iff_end = wav + wavlength;

// find "RIFF" chunk
    FindChunk("RIFF");
    if (!(data_p && !strncmp(data_p+8, "WAVE", 4)))
    {
        printf("Missing RIFF/WAVE chunks\n");
        return info;
    }

// get "fmt " chunk
    iff_data = data_p + 12;
// DumpChunks ();

    FindChunk("fmt ");
    if (!data_p)
    {
        printf("Missing fmt chunk\n");
        return info;
    }
    data_p += 8;
    format = GetLittleShort();
    if (format != 1)
    {
        printf("Microsoft PCM format only\n");
        return info;
    }

    info.channels = GetLittleShort();
    info.rate = GetLittleLong();
    data_p += 4+2;
    info.width = GetLittleShort() / 8;

// get cue chunk
    FindChunk("cue ");
    if (data_p)
    {
        data_p += 32;
        info.loopstart = GetLittleLong();
//      Com_Printf("loopstart=%d\n", sfx->loopstart);

    // if the next chunk is a LIST chunk, look for a cue length marker
        FindNextChunk ("LIST");
        if (data_p)
        {
            if (!strncmp (data_p + 28, "mark", 4))
            {   // this is not a proper parse, but it works with cooledit...
                data_p += 24;
                i = GetLittleLong ();   // samples in loop
                info.samples = info.loopstart + i;
            }
        }
    }
    else
        info.loopstart = -1;

// find data chunk
    FindChunk("data");
    if (!data_p)
    {
        printf("Missing data chunk\n");
        return info;
    }

    data_p += 4;
    samples = GetLittleLong ();

    if (info.samples)
    {
        if (samples < info.samples)
            Error ("Sound %s has a bad loop length", name);
    }
    else
        info.samples = samples;

    info.dataofs = data_p - wav;

    return info;
}

-- 
Vadim Sytnikov,
Gamos JSC, Moscow, Russia:
Entertainment Software Development.

mailto:sytnikov@gamos.ru
mailto:sytnikov@gamos.msk.su
mailto:vadims@mlt.dnepr.net
http://www.gamos.ru