| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2158 人关注过本帖
标题:C语言读取wav文件的问题,请大侠,编译问题。
只看楼主 加入收藏
鬼鬼千年
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:140
注 册:2010-4-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
C语言读取wav文件的问题,请大侠,编译问题。
代码如下:#include <windows.h>
        
#include <math.h>
        
        
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                   PSTR szCmdLine, int iCmdShow)
        
{
        
    static TCHAR szAppName[] = TEXT ("SineWave") ;
        
    HWND          hwnd ;
        
    MSG           msg ;
        
    WNDCLASS      wndclass ;
        
   
        
    wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
        
    wndclass.lpfnWndProc= WndProc ;
        
    wndclass.cbClsExtra   = 0 ;
        
    wndclass.cbWndExtra   = 0 ;
        
    wndclass.hInstance    = hInstance ;
        
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
        
    wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW) ;
        
    wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
    wndclass.lpszMenuName  = NULL ;
        
    wndclass.lpszClassName = szAppName ;
        
        
        
    if (!RegisterClass (&wndclass))
        
    {
        
            MessageBox (  NULL, TEXT ("Program requires Windows NT!"),
        
                   szAppName, MB_ICONERROR) ;
        
                   return 0 ;
        
    }
        
   
        
    hwnd = CreateWindow ( szAppName, TEXT ("Wave  13061128 李新"),
        
                          WS_OVERLAPPEDWINDOW,
        
                           CW_USEDEFAULT, CW_USEDEFAULT,
        
                           CW_USEDEFAULT, CW_USEDEFAULT,
        
                           NULL, NULL, hInstance, NULL) ;
        
    ShowWindow (hwnd, iCmdShow) ;
        
    UpdateWindow (hwnd) ;
        
   
        
    while (GetMessage (&msg, NULL, 0, 0))
        
    {
        
            TranslateMessage (&msg) ;
        
                  DispatchMessage (&msg) ;
        
    }
        
            return msg.wParam ;
        
}
        

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        
{
        
    static int  cxClient, cyClient ;
        
    HDC         hdc ;
        
    PAINTSTRUCT ps ;
        
    static int    i=1;
        
    TEXTMETRIC    tm ;
  
    static WORD    Channels;      //声道数目,1--单声道;2--双声道
     
    static DWORD      SamplesPerSec ;//采样频率
        
    static WORD    wBitsPerSample;      //每个采样需要的bit数  

    static DWORD   dwDataSize;  //去除ID和Size所占的字节数后剩下的其他字节数目

    static long    size;

    static    int    numbit;//一个样本的字节数;
         
    static    int    num;//样本数

    static  BYTE   *pData;
        
    switch (message)
        
    {
    case WM_CREATE:

        static HMMIO   file1;//定义HMMIO文件句柄;   

        file1=mmioOpen("13061128.wav",NULL,MMIO_READWRITE);//以读写模式打开所给的WAVE文件;   
        if(file1==NULL)   
        {   
            MessageBox(hwnd,"WAVE文件打开失败!","13061128",0);   
            return   NULL;   
        }   

            
            char   style[3];
            while(mmioSeek(file1,i++,SEEK_SET)&&i<200)
            {
               
                mmioRead(file1,style,3);
                if(style[0]=='f'&&style[1]=='m'&&style[2]=='t')
                    break;
            }
//////////////////////////////
            mmioSeek(file1,i+9,SEEK_SET);

            mmioRead(file1,style,2);

            memcpy(&Channels,style,2);//声道
            if(Channels==1)
                MessageBox(hwnd,"单声道","13061128",0);
            if(Channels==2)
                MessageBox(hwnd,"双声道","13061128",0);
/////////////////////////
            mmioSeek(file1,i+11,SEEK_SET);

            mmioRead(file1,style,4);

            memcpy(&SamplesPerSec,style,4);//采样频率
            
////////////////////////
            mmioSeek(file1,i+21,SEEK_SET);

            mmioRead(file1,style,2);

            memcpy(&wBitsPerSample,style,2);//每个采样需要的bit数  
            if(wBitsPerSample==8)
                MessageBox(hwnd,"8位量化","13061128",0);/////////
            if(wBitsPerSample==16)
                MessageBox(hwnd,"16位量化","13061128",0);
////////////////////////////

            char   style2[4];
            while(mmioSeek(file1,i++,SEEK_SET)&&i<500)
            {   
                mmioRead(file1,style2,4);
                if(style2[0]=='d'&&style2[1]=='a'&&style2[2]=='t'&&style2[3]=='a')
                {
            //        MessageBox(hwnd,"data","13061128",0);
                    break;
                }
            }
  
////////////////
            
            mmioSeek(file1,i+3,SEEK_SET);  
   
            mmioRead(file1,(char*)&size,4);   

    //        if(size%560256==0)
       //           MessageBox(hwnd,"qwwqeweq","46ty",0);

            

/////////////////////
            i=i+7;
            
            numbit=(wBitsPerSample/8);//一个样本的字节数;   

            num=size/numbit;//样本数

    //        if(560256==num)
    //            MessageBox(hwnd,"qwwqeweq","46ty",0);
   
            pData=(BYTE*)new   char[size];//

            mmioSeek(file1,i,SEEK_SET);//对文件重新定位;   

            mmioRead(file1,(char*)pData,size);//
   
            


            ReleaseDC (hwnd, hdc) ;
            return 0 ;
        
    case   WM_SIZE:
        
            cxClient = LOWORD (lParam) ;
        
            cyClient = HIWORD (lParam) ;
        
            return 0 ;
        
        
        
    case   WM_PAINT:
        
        hdc = BeginPaint (hwnd, &ps) ;
        

        if(Channels==1)
        {
            if(wBitsPerSample==8)
            {
                for(int k=0;k<size;k=k+size/50)//调节这里控制播放
                {
                for(int j=0;j<size;j++)
                {
                    SetPixel(hdc,j-k,(WORD)*(pData+j),0) ;
                }
                PatBlt(hdc,0,0,50000,50000,WHITENESS);
                }
                MessageBox(hwnd,"播放完毕","13061128",0);
            }
            if(wBitsPerSample==16)
            {
                for(int k=0;k<size/2;k=k+size/100)//调节这里控制播放
                {
                for(int j=0;j<size/2;j++)
                {
                    SetPixel(hdc,j-k,(WORD)*(pData+j*2),0) ;
                }
                PatBlt(hdc,0,0,50000,50000,WHITENESS);
                }
                MessageBox(hwnd,"播放完毕","13061128",0);
            }
        }
        else if(Channels==2)
        {
            if(wBitsPerSample==8)
            {
                for(int k=0;k<size/2;k=k+size/100)//调节这里控制播放
                {
                for(int j=0;j<size/2;j++)
                {
                    SetPixel(hdc,j-k,(WORD)*(pData+j*2),0) ;
                }
                for(j=0;j<size/2;j++)
                {
                    SetPixel(hdc,j-k,(WORD)*(pData+1+j*2)+100,0) ;
                }
                PatBlt(hdc,0,0,50000,50000,WHITENESS);
                }
                MessageBox(hwnd,"播放完毕","13061128",0);   
            }
            if(wBitsPerSample==16)
            {

                for(int k=0;k<size/4;k=k+size/200)//调节这里控制播放
                {
                for(int j=0;j<size/4;j++)
                {
                    WORD w;
                    memcpy(&w,pData+j*4,2);
                    
                //    SetPixel(hdc,j-k,w%1000-400,0) ;
                    SetPixel(hdc,j-k,w/50+100,0) ;
                }
                for(j=0;j<size/4;j++)
                {
                    WORD w;
                    memcpy(&w,pData+2+j*4,2);
                //    SetPixel(hdc,j-k,w%1000-200,0) ;
                    SetPixel(hdc,j-k,w/50+350,0) ;
                }   
                PatBlt(hdc,0,0,50000,50000,WHITENESS);
                }
                MessageBox(hwnd,"播放完毕","13061128",0);
            }
        }
        
        return 0 ;
        
        
        
    case   WM_DESTROY:
        
            PostQuitMessage (0) ;
        
            return 0 ;
        
    }
        
    return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}
问题:编译时过不了啊。VC6.0编译器。
Linking...
wav.obj : error LNK2001: unresolved external symbol __imp__mmioRead@12
wav.obj : error LNK2001: unresolved external symbol __imp__mmioSeek@12
wav.obj : error LNK2001: unresolved external symbol __imp__mmioOpenA@12
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/wav.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错.
搜索更多相关主题的帖子: C语言 
2010-12-29 12:30
鬼鬼千年
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:140
注 册:2010-4-9
收藏
得分:0 
在下也希望大侠能给出一些关于wav文件读写操作的资料,拜谢!

活了千年的鬼鬼,突然想当个人,看看人和鬼哪个好?
2010-12-29 12:31
megadeath
Rank: 4
等 级:业余侠客
帖 子:24
专家分:260
注 册:2008-8-29
收藏
得分:20 
没有添加库文件,在代码中加入如下:
#pragma comment(lib, "winmm.lib")
祝好运~
2010-12-30 00:09
鬼鬼千年
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:140
注 册:2010-4-9
收藏
得分:0 
疏忽!!拜谢!

活了千年的鬼鬼,突然想当个人,看看人和鬼哪个好?
2010-12-30 15:18
format123
Rank: 2
等 级:论坛游民
帖 子:35
专家分:60
注 册:2010-11-26
收藏
得分:0 
学习中
2010-12-31 00:38
cguy
Rank: 1
等 级:新手上路
帖 子:3
专家分:1
注 册:2011-1-1
收藏
得分:0 
现在各种不懂啊
2011-01-01 15:28
快速回复:C语言读取wav文件的问题,请大侠,编译问题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.110734 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved