001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/**
 * $Id: driff.cpp,v 1.1 2006/09/06 13:01:47 a-gamyl Exp $
 *       RIFF 構造データの再生/表示(AVI/WAVE + MP3)
 *       AVI: codec の使用(divx,xvid etc. に対応)
 *       MP3: <MPEG 1,2,2.5 Layer I,II,III 対応> ACM->PCM
 */
//-----------------------------------------------------------------
#include "driff.h"
//-----------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4996) // Invalid C4996 warning
#pragma warning(disable: 4793) // Invalid C4793 warning
//-----------------------------------------------------------------
// global value
//-----------------------------------------------------------------
DRIFF        dr;
HWND        hAppWnd;
CDG_Global    dggd;
int            draw_flag;
//-----------------------------------------------------------------
// drawing thread function
//-----------------------------------------------------------------
ULONG __stdcall DGThread(void* p_arg)
{
    HWND hWnd    = dr.getCanvas();
    HWND hEditor = dr.getEditor();
    HWND hButton = dr.getButton();
    
    if(dggd.dg_type == DRIFF_WIN || !dggd.dg_type){
        SetWindowText(hButton,"開始");
        return FALSE;
    }
    SetWindowText(hButton,"停止");
        
    HDC hdc = GetDC(hWnd);
    RECT wr,wer,pR,waveR;
    char wbuf[256];

    CImage i_image,o_image;
    int radius=0,old_radius=0;
    POINT cp = {0,0},old_cp = {0,0};
    if(dggd.dg_type == DRIFF_AVI){
        if(i_image.format(dr.getBmpHeader(0))) return FALSE;
        if(o_image.format(dr.getBmpHeader(0))) return FALSE;
    }

    // playing
    draw_flag = 1;
    //DrawDibBegin(dggd.DDib,hdc,-1,-1,orgbi,-1,-1,0); // set dib
    while(dggd.dg_type){
        // set window
        GetClientRect(hWnd,&wr);
        GetClientRect(hWnd,&pR);
        GetWindowRect(hEditor,&wer);
        pR.left  = 0; pR.right = wr.right-(wer.right-wer.left);
        if(pR.right < 0) pR.right = wr.right;
        
        if(dggd.dg_type == DRIFF_AVI) {
            LPVOID a;
            // play sound
            if(dggd.ifilter == IDM_IP_DEFAULT){
                if(dggd.avi_audio){
                    memcpy(&waveR,&pR,sizeof(RECT));
                    waveR.top    = pR.bottom-100;
                    waveR.bottom = pR.bottom;
                    if(waveR.top < 0) pR.top = 0;
                    if(waveR.bottom > pR.bottom) waveR.bottom = pR.bottom;
                
                    int wait = 1;
                    if(dr.getFPS() < 30) wait = 1;
                    else {
                        wait = RI(dr.getFPS()/30.);
                    }
                    if(dr.getVideoCurrent() % wait == 0){
                        if(!dr.WavePlay(DRIFF_AVI,wait*dggd.waittime)){
                            Sleep(RI(1000.*dggd.waittime/2.));
                        }
                        dr.DrawWave(hdc,&waveR);
                        //if(dr.WaveEof()) dr.WaveSeek(0);
                    }
                } else {
                    Sleep(RI(1000.*dggd.waittime/2.)); // wait for play sec.
                }
            } else {
                Sleep(RI(1000.*dggd.waittime/2.)); // wait for play sec.
            }
            // read bmp for avi
            if(!dr.AviRead(&a) || i_image.setImage(a) || o_image.setImage(a)){
                dr.Seek(0); Sleep(1000); continue; // play loop
            }
            // for image processing
            if(dggd.ifilter != IDM_IP_HGTCIRCLE_2){
                ifilter(dggd.ifilter,&i_image);
            } else {
                findCircle(&i_image,&o_image,&radius,&cp);
                sprintf(wbuf,"%d: (t,x,y,r) = (%.2lf,%d,%d,%d) [pixel] (diff: %d)\r\n",
                        dr.getVideoCurrent(),(double)dr.getVideoCurrent()/(double)dr.getFPS(),
                        cp.x,cp.y,radius,abs(radius-old_radius));
                old_cp.x = cp.x; old_cp.y = cp.y;
                old_radius = radius;
                catText(hEditor,wbuf);
            }
            // draw dib
            DrawDibDraw(dggd.DDib,                // handle of DrawDIB
                        hdc,                    // device context
                        0,0,                    // head of drawing
                        pR.right,                // width of drawing
                        pR.bottom-105,            // height of drawing
                        i_image.getBmpHeader(),    // BITMAPINFOHEADER structure
                        i_image.getImage(),        // image data
                        0,0,                    // head of image
                        dggd.ds.x,dggd.ds.y,    // width and height of image
                        DDF_BUFFER                // flag of drawing
                        // | DDF_SAME_HDC | DDF_SAME_DRAW
                );
            dr.setScroll(dr.getVideoCurrent());
        } else {
            if(dggd.dg_type == DRIFF_WAVE || dggd.dg_type == DRIFF_MP3) {
                pR.top    = 0;
                pR.bottom = 100;
                if(pR.top < 0) pR.top = 0;
                if(pR.bottom > wr.bottom) pR.bottom = wr.bottom;
                dr.WavePlay(DRIFF_WAVE,0.1); // set sec
                if(dr.WaveEof()) {
                    dr.WaveSeek(0); Sleep(1000); continue; // play loop
                }
                dr.DrawWave(hdc,&pR);
                dr.setWaveScroll(dr.getAudioCurrent());
            }
        }
        // diplay FPS
        //static char t_str[256];
        //wsprintf(t_str,"%s [%s%s]",dg_fname,dr.getFPSS(),getWaveInfo());
        //catText(hEditor,t_str);

        InvalidateRect(hEditor,NULL,FALSE);
    }
    if(dggd.dg_type == DRIFF_AVI){
        i_image.clear(); o_image.clear();
    }
    draw_flag = 0;
    //DrawDibClose(dggd.DDib);
    ReleaseDC(hWnd,hdc);

    SetWindowText(hButton,"開始");
    dr.DrawGraphic(0);
    
    return TRUE;
}

ULONG DRIFF::DrawGraphic(int mode)
{
    if(dggd.dg_type) return FALSE;
    
    HWND hWnd    = getCanvas();
    HWND hEditor = getEditor();
    RECT wr,wer,pR,waveR;

    GetClientRect(hWnd,&wr);
    GetClientRect(hWnd,&pR);
    GetWindowRect(hEditor,&wer);
    pR.left  = 0;
    pR.right = wr.right-(wer.right-wer.left);

    if(file_type == DRIFF_AVI && mode == 0){
        in_image.clear(); out_image.clear();
        if(in_image.format(dr.getBmpHeader(0))) return FALSE;
        if(out_image.format(dr.getBmpHeader(0))) return FALSE;
    }
    
    HDC hdc = GetDC(hWnd);
    if(file_type == DRIFF_AVI) {
        // draw sound
        if(dggd.avi_audio){
            memcpy(&waveR,&pR,sizeof(RECT));
            waveR.top    = pR.bottom-100;
            waveR.bottom = pR.bottom;
            if(waveR.top < 0) pR.top = 0;
            if(waveR.bottom > pR.bottom) waveR.bottom = pR.bottom;
            SelectObject(hdc,GetStockObject(BLACK_PEN));
            SelectObject(hdc,GetStockObject(BLACK_BRUSH));
            Rectangle(hdc,waveR.left,waveR.top,waveR.right,waveR.bottom);
            DrawWave(hdc,&waveR);
        }
        // draw video
        pR.top    = wr.bottom-100;
        pR.bottom = wr.bottom;
        if(pR.top < 0) pR.top = 0;
        if(pR.bottom > wr.bottom) pR.bottom = wr.bottom;
        // get bmp for avi
        LPVOID a;
        if(!AviRead2(getVideoCurrent(),&a) || in_image.setImage(a) || out_image.setImage(a)){
            return FALSE;
        }

        // for image processing
        if(dggd.ifilter != IDM_IP_HGTCIRCLE_2){
            ifilter(dggd.ifilter,&in_image);
        } else {
            int radius;
            POINT cp;
            findCircle(&in_image,&out_image,&radius,&cp);
        }
        
        // draw dib
        DrawDibDraw(dggd.DDib,                // handle of DrawDIB
                    hdc,                    // device context
                    0,0,                    // head of drawing
                    pR.right,                // width of drawing
                    pR.bottom-105,            // height of drawing
                    in_image.getBmpHeader(),// BITMAPINFOHEADER structure
                    //lpbi,
                    in_image.getImage(),    // image data
                    //start,
                    0,0,                    // head of image
                    dggd.ds.x,dggd.ds.y,    // width and height of image
                    DDF_BUFFER                // flag of drawing
                    // | DDF_SAME_HDC | DDF_SAME_DRAW
                    );
    } else if(file_type == DRIFF_WAVE || file_type == DRIFF_MP3) {
        pR.top    = 0;
        pR.bottom = 100;
        if(pR.top < 0) pR.top = 0;
        if(pR.bottom > wr.bottom) pR.bottom = wr.bottom;
        DrawWave(hdc,&pR);
    }
    ReleaseDC(hWnd,hdc);

    InvalidateRect(hEditor,NULL,FALSE);
    //InvalidateRect(getCanvas(),NULL,TRUE);
    
    return TRUE;
}
//-----------------------------------------------------------------
//
// Class of DRIFF
//          AVI draw graphic and playing wave(PCM) sound
//
//-----------------------------------------------------------------
DRIFF::DRIFF()
{
    file = NULL;
    file_type = 0;
    dggd.dg_type = 0;
    cvideo.setWave(&cwave);
    // find an MP3 codec
    MMRESULT mmr = acmDriverEnum(acmDrvFind,(DWORD)hAppInst,ACM_DRIVERENUMF_NOLOCAL);
    mmerr_check(mmr,"acmDriverEnum");
}

DRIFF::~DRIFF()
{
    DrawClose();
}

int DRIFF::Open(char *filename)
{
    if(file != NULL) DrawClose();
    // open file
    file = fopen(filename,"rb");
    if(file == NULL) return FALSE;
    // file information
    int ret;
    static char buf[256];
    DRIFF_HEAD head[16];
    DWORD type;
    sprintf(buf,"FILE: %s\r\n",filename);
    setText(edHwnd,buf);
    if(check_suffix(filename,"avi") || check_suffix(filename,"wav")){
        fread(&head[0],1,sizeof(DRIFF_HEAD),file); // read RIFF chunk
        if(head[0].ckID == mmioFOURCC('R','I','F','F')) {
            fread(&type,1,sizeof(DWORD),file);
            if(type == DRIFF_WAVE){
                ret = cwave.Open(&file); // WAVE
                dggd.dg_type = DRIFF_WAVE;
                file_type = DRIFF_WAVE;
                setScroll();
            } else if(type == DRIFF_AVI){
                ret = cvideo.Open(filename); // AVI
                dggd.dg_type = DRIFF_AVI;
                file_type = DRIFF_AVI;
                setScroll();
            }
            dggd.dg_type = type;
            file_type = type;
        } else {
            MessageBox(NULL,"RIFF: illegal file format","input file",MB_OK);
            ret = FALSE;
        }
    } else if(check_suffix(filename,"mp3")){ // not [RIFF]
        if(ret = cwave.MP3Open(&file,filename)){
            dggd.dg_type = DRIFF_MP3;
            file_type = DRIFF_MP3;
            setScroll();
        }
    } else {
        ret = FALSE;
        MessageBox(NULL,"FILE: not supported file type","input file",MB_OK);
    }
    if(ret == FALSE) {
        dggd.dg_type = 0;
        file_type = 0;
        DrawClose();
        return FALSE;
    }
    return TRUE;
}

int DRIFF::FileOpen()
{
    static char filename[MAX_PATH];
    dggd.dg_oldtype = dggd.dg_type;
    dggd.dg_type = 0;
    filename[0]  = '\0';
    //--------------------------------------------------
    // format of file open
    //--------------------------------------------------
    OPENFILENAME ifile;
    memset(&ifile,0,sizeof(OPENFILENAME));
    ifile.lStructSize    = sizeof(OPENFILENAME);
    ifile.hwndOwner      = paintHwnd;
    ifile.lpstrFilter    = 
        "AVI ファイル(*.avi)\0*.avi\0""WAVE ファイル(*.wav)\0*.wav\0"
        "MP3 ファイル(*.mp3)\0*.mp3\0""全てのファイル(*.*)\0*.*\0\0";
    ifile.lpstrFile      = filename;
    ifile.lpstrFileTitle = "読み込み";
    ifile.nMaxFile       = sizeof(filename);
    ifile.Flags          = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ifile.lpstrDefExt    = "avi";
    ifile.lpstrTitle     = "開く";
    //--------------------------------------------------
    // open dialog
    //--------------------------------------------------
    if(!GetOpenFileName(&ifile)){
        dggd.dg_type = dggd.dg_oldtype;
        if(dggd.dg_oldtype) DrawStart();
        return FALSE;
    }
    //--------------------------------------------------
    // open file
    //--------------------------------------------------
    if(!FileOpen(filename)){
        return FALSE;
    }
    return TRUE;
}

int DRIFF::FileOpen(char* filename)
{
    if(!Open(filename)) {
        dggd.dg_type = dggd.dg_oldtype;
        if(dggd.dg_oldtype) DrawStart();
        return FALSE;
    }
    //--------------------------------------------------
    // set datas
    //--------------------------------------------------
    cvideo.getSize(&dggd.ds);
    dggd.waittime = 1./cvideo.getFPS();
    strcpy(file_name,filename);
    //--------------------------------------------------
    // play AVI image and WAVE sound
    //--------------------------------------------------
    //DrawStart();
    LPVOID a;
    if(dggd.dg_type == DRIFF_AVI && !AviRead2(0,&a)){
        MessageBox(NULL,"AVI: read image fail",0,0);
        return FALSE;
    }
    InvalidateRect(getCanvas(),NULL,TRUE);
    DrawGraphic(0);
    return TRUE;
}

int DRIFF::Close()
{
    file_type = 0;
    
    if(file != NULL) {
        fclose(file); file = NULL;
    }
    if(cvideo.isActive()) {
        SetScrollPos(scrHwnd,SB_CTL,cvideo.getStartPos(),TRUE);
        cvideo.Close();
    }
    if(cwave.isActive(WAVE_INFILE)) {
        SetScrollPos(scrHwnd,SB_CTL,cwave.getStartPos(),TRUE);
        cwave.Close();   cwave.setState(WAVE_INFILE,FALSE);
    }
    if(cwave.isActive(WAVE_INMIC)) {
        cwave.InClose(); cwave.setState(WAVE_INMIC,FALSE);
    }
    SetScrollPos(scrHwnd,SB_CTL,0,TRUE);
    SetScrollRange(scrHwnd,SB_CTL,0,0,FALSE);
    return TRUE;
}

int DRIFF::Seek(double sec)
{
    cvideo.Seek(sec);
    cwave.Seek(sec);
    return TRUE;
}
void DRIFF::DrawClose()
{
    dggd.dg_type = 0;
    WaitForSingleObject(thread,3000); // wait until thread finished
    //if(draw_flag == 1) DrawClose();
    Close();
    InvalidateRect(paintHwnd,NULL,TRUE);
    PostMessage(paintHwnd,WM_PAINT,(unsigned int)NULL,(long int)NULL);
}

void DRIFF::DrawStart()
{
    if(!dggd.dg_oldtype && (!dggd.dg_type)) return;
    if(!dggd.dg_type) dggd.dg_type = dggd.dg_oldtype;
    // begin thread
    DWORD tid;
    thread = CreateThread(NULL,0,DGThread,NULL,0,&tid);
    SetThreadPriority(thread,THREAD_PRIORITY_ABOVE_NORMAL);
    //THREAD_PRIORITY_ABOVE_NORMAL
    //THREAD_PRIORITY_NORMAL
    //THREAD_PRIORITY_NORMAL
    //THREAD_PRIORITY_LOWEST
    //THREAD_PRIORITY_IDLE
}

void DRIFF::DrawStop()
{
    dggd.dg_oldtype = dggd.dg_type;
    dggd.dg_type = 0;
    WaitForSingleObject(thread,3000); // wait until thread finished
}

void DRIFF::FrameSave()
{
    if(file_type != DRIFF_AVI) return;    
    if(dggd.dg_type != 0) DrawStop();
    //--------------------------------------------------
    // format of file save
    //--------------------------------------------------
    static char filename[MAX_PATH];
    filename[0]  = '\0';
    OPENFILENAME file;
    memset(&file,0,sizeof(OPENFILENAME));
    file.lStructSize    = sizeof(OPENFILENAME);
    file.hwndOwner      = paintHwnd;
    file.lpstrFilter    = "BMP ファイル(*.bmp)\0*.bmp\0""全てのファイル(*.*)\0*.*\0\0";
    file.lpstrFile      = filename;
    file.lpstrFileTitle = "画像保存";
    file.nMaxFile       = sizeof(filename);
    file.Flags          = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
    file.lpstrDefExt    = "bmp";
    file.lpstrTitle     = "保存";
    // open dialog
    if(!GetSaveFileName(&file)) return;
    // save image
    SaveBMP(filename,in_image.getBmpHeader(),(LPBYTE)in_image.getImage());
    InvalidateRect(getCanvas(),NULL,FALSE);
    DrawGraphic(1);
    
    // restart playing
    if(dggd.dg_type) DrawStart();
}
//-----------------------------------------------------------------
void DRIFF::setImageFilter(int ifilter)
{
    dggd.ifilter = ifilter;
}
void DRIFF::setWaveDraw(int dgw)
{
    dggd.dgw_type = dgw;
}
void DRIFF::setWaveInput()
{
    if(dggd.dg_type == DRIFF_WIN) return;
    DrawClose();
    if(!cwave.InOpen()){
        MessageBox(NULL,"WAVEIN: initialize fail","WAVEIN",MB_OK);
    }
    dggd.dg_type = DRIFF_WIN;
    dggd.ds.x = 0; dggd.ds.y = 0;
    // draw text
    static char t_str[256];
    wsprintf(t_str,"WAVE 音声入力%s",getWaveInfo());
    catText(edHwnd,t_str);
    // repaint
    InvalidateRect(edHwnd,NULL,TRUE);
}
void DRIFF::setWindow(HWND mwh,HWND edwh,HWND btwh,HWND scrwh)
{
    paintHwnd = mwh; edHwnd = edwh; BtHwnd = btwh; scrHwnd = scrwh;
    cwave.setWindow(edwh); cvideo.setWindow(edwh);
}
//-----------------------------------------------------------------
int  DRIFF::getVideoCurrent()    { return cvideo.getCurrent(); }
int  DRIFF::getAudioCurrent()    { return cwave.getCurrent();  }
HWND DRIFF::getCanvas()            { return paintHwnd; }
HWND DRIFF::getEditor()            { return edHwnd; }
HWND DRIFF::getButton()            { return BtHwnd; }
DWORD DRIFF::getType()            { return dggd.dg_type; }
double DRIFF::getFPS()            { return cvideo.getFPS(); }

char* DRIFF::getFPSS()
{
    static DWORD last   = 0;
    static DWORD frames = 0;
    static char  buf[256] = "";
    DWORD current = timeGetTime(); // current time
    frames++;
    // update per 0.5 sec
    if(500 <= current - last) {
        double  dt = (double)(current - last) / 1000.0f;
        double fps = (double)frames / dt;
        last = current;
        frames = 0;
        sprintf(buf,"%.02f fps",fps);
    }
    return buf;
}

char* DRIFF::getWaveInfo()
{
    static char buf[256];
    buf[0] = '\0';
    switch(dggd.dg_type){
    case DRIFF_AVI:
        if(!dggd.avi_audio) break;
        wsprintf(buf,": WAVE %dHz %dbit",cwave.getFreq(),cwave.getDBit());
        break;
    default:
        wsprintf(buf,": WAVE %dHz %dbit",cwave.getFreq(),cwave.getDBit());
        break;
    }
    return buf;
}

LPBITMAPINFOHEADER DRIFF::getBmpHeader(int cur)
{
    LPVOID a;
    if(!AviRead2(cur,&a)) return NULL;
    return (LPBITMAPINFOHEADER)a;
}

//-----------------------------------------------------------------
// SCROLL
//-----------------------------------------------------------------
void DRIFF::setScroll()
{
    SCROLLINFO scr;
    scr.cbSize = sizeof(SCROLLINFO);
    scr.fMask = SIF_PAGE | SIF_RANGE;

    int spos=0,epos=0;
    if(file_type == DRIFF_AVI) {
        spos = cvideo.getStartPos();
        epos = cvideo.getEndPos();
    } else if(file_type == DRIFF_WAVE || file_type == DRIFF_MP3){
        spos = cwave.getStartPos();
        epos = cwave.getEndPos();
    } else {
        catText(edHwnd,"  scroll not supported\r\n");
        return;
    }
    scr.nMin = spos; scr.nMax = epos; scr.nPage = 0;
    SetScrollInfo(scrHwnd,SB_CTL,&scr,TRUE);
    scr.fMask = SIF_POS;
    if(!SetScrollRange(scrHwnd,SB_CTL,spos,epos,FALSE)){
        MessageBox(NULL,"SCROLL: initialize fail","SCROLL",MB_OK);
        return;
    }
    setScroll(spos);
}

void DRIFF::setScroll(int spos)
{
    if(file_type == DRIFF_AVI) {
        int scrPos = cvideo.getScrollPos(spos);
        SetScrollPos(scrHwnd,SB_CTL,scrPos,TRUE);
        cvideo.SetPos(scrPos);
    } else if(file_type == DRIFF_WAVE || file_type == DRIFF_MP3){
        int scrPos = cwave.getScrollPos(spos);
        SetScrollPos(scrHwnd,SB_CTL,scrPos,TRUE);
        cwave.SetPos(scrPos);
    }
    DrawGraphic(0);
}

void DRIFF::setWaveScroll(int spos)
{
    if(file_type == DRIFF_WAVE || file_type == DRIFF_MP3){
        int scrPos = cwave.getScrollPos2(spos);
        SetScrollPos(scrHwnd,SB_CTL,scrPos,TRUE);
        DrawGraphic(0);
    }
}
//-----------------------------------------------------------------
// MIC wave input
//-----------------------------------------------------------------
void DRIFF::DrawWaveInput()
{
    if(dggd.dg_type != DRIFF_WIN) return;
    if(!cwave.InPlay()) return;
    // drawing area
    RECT wr,wer,rdr,pR;
    SetRect(&pR,0,0,0,100);
    GetClientRect(paintHwnd,&wr);
    GetWindowRect(edHwnd,&wer);
    pR.right = wr.right-(wer.right-wer.left);
    SetRect(&rdr,0,0,pR.right,wr.bottom);
    // draw
    HDC hdc = GetDC(paintHwnd);
    DrawWave(hdc,&pR);
    ReleaseDC(paintHwnd,hdc);
}
//-----------------------------------------------------------------
// VIDEO
//-----------------------------------------------------------------
int DRIFF::AviRead(void** data) { return cvideo.Read(data); }
int DRIFF::AviRead2(int current,void **data) { return cvideo.Read2(current,data); }
//-----------------------------------------------------------------
// WAVE
//-----------------------------------------------------------------
void DRIFF::volumeUp(){ cwave.volumeUp(); }
void DRIFF::volumeDown(){ cwave.volumeDown(); }
int  DRIFF::WavePlay(int type,double sec)
{
    if(type == DRIFF_AVI) return cvideo.WavePlay(sec); else return cwave.Play(sec,TRUE);
}
void DRIFF::WavePlayDone() { cwave.OutDone(); }
int  DRIFF::WaveEof() { return cwave.isEOF(); }
void DRIFF::WaveSeek(int wpos) { cwave.Seek(wpos); }
BOOL DRIFF::DrawWave(HDC hDC,RECT *pR) { return cwave.DrawWave(hDC,pR); }

#pragma warning(pop)