wave 파일 mixing 하기. (웨이브 믹싱)

31437 
Created at 2006-09-29 02:29:09 
408   0   0   0  
용도는.. 배경음에다 목소리 합칠때 사용하는 겁니다.
검증은 좀 덜됐지만, 이런식으로 하면.. 얼마든지 응용이 가능할꺼 같네요.
그럼.. 문제 있으시면 답글 부탁드립니다.
 
 
 
// WAVE 파일을 Mixing 한다. - 배경음 + 목소리용
// [in] pFile1 : 목소리 파일
// [in] pFile2 : 배경음 파일(목소리 파일보다 커야한다.)
// [in]nPreMargineSec : 몇초 후부터 음성을 합칠것인가. (배경음만 출력되는 초기시간)
 
int WavFileMix(char *pFile1, char *pFile2, char *pFileRes, int nPreMargineSec)
{
    int len1, len2, len;
    short *in1, *in2;
    short *out;
    char pWaveHeader[44];
 
    CFile cf1, cf2, cfRes;
 
    if(!cf1.Open(pFile1, CFile::modeRead)) {
        return -1;
    }
 
    if(!cf2.Open(pFile2, CFile::modeRead)) {
        return -1;
    }
 
    DWORD dwFileSize1 = cf1.GetLength();
    len1 = dwFileSize1 - 44;
 
    DWORD dwFileSize2 = cf2.GetLength();
    len2 = dwFileSize2 - 44;
 
    int nRead2 = cf2.Read(pWaveHeader, 44);         // wave 헤더를 읽어온다.
    if(nRead2 <= 0)
        return -1;
 
    int nSamplesPerSec;
    memcpy(&nSamplesPerSec, &pWaveHeader[24], 4);   // 초당 샘플링을 읽어온다.
 
    if(len1 > len2)
        len = len1;
    else
        len = len2;
    
    in1 = (short*)malloc(sizeof(short)*len1);
    in2 = (short*)malloc(sizeof(short)*len2);
    out = (short*)malloc(sizeof(short)*len);
 
    cf1.Read(in1, len1);
    cf1.Close();
    
    cf2.Read(in2, len2);
    cf2.Close();
 
    // wave data mix
    WavMix(in1, in2, out, len1, len2, nPreMargineSec, nSamplesPerSec);
    
    //save output file  
    if(!cfRes.Open(pFileRes, CFile::modeCreate | CFile::modeWrite)) {
        free(in1);
        free(in2);
        free(out);
        return -1;
    }
 
    cfRes.Write(pWaveHeader, 44);                   // wave 헤더를 먼저 기록.
    cfRes.Write(out, len);
    cfRes.Close();
 
    free(in1);
    free(in2);
    free(out);
 
    return 0;
}
 
// Music + Voice 용도로만 사용한다. (목소리 재생시 배경음악은 볼륨을 낮춘다.)
// WAVE 데이터를 합성한다.
void WavMix(short *in1, short *in2, short *out, int nVoiceSize, int nMusicSize, int nPreMargineSec, int nSamplesPerSec)
{
    int i;
    float tmp;
    float nTemp;
 
    int nVoiceMute = nSamplesPerSec * nPreMargineSec/*초*/;
 
    for(i = 0 ;i < nMusicSize; i++)
    {
        if(i < (nVoiceSize/2)+nVoiceMute)
        {
            if( i >= nVoiceMute && i < nVoiceMute+20)
            {
                // 합쳐지는 부분의 순간 잡음을 없애기 위해.
                // 추후 Fade Out , Fade In 사용예정
                out[i] = 0;
            }
            else if(i < nVoiceMute)
            {
                // 앞에 x초는 배경음만
                out[i] = (short)in2[i];
            }
            else
            {
                // 합친다. (합친후 다시 나누기할때의 배율은 입맛에 맞게 조절한다.)
                nTemp = in1[i-nVoiceMute];
                nTemp += (float)(in2[i]*0.7);
                //tmp = (float)(nTemp / 2.0);
                tmp = (float)(nTemp / 1.7);
 
                out[i] = (short)tmp;
            }
        }
        else
        {
            // 배경음 뒷부분은 그대로..
            out[i] = (short)in2[i];
        }
    }
}

Tags: MFC WIN32 wave 윈도우즈 Share on Facebook Share on X

◀ PREVIOUS
ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기
▶ NEXT
File Attribute 바꾸는 방법
  Comments 0
Login for comment
SIMILAR POSTS

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

빈폴더 찾아내기 (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

PC 셧다운 (shutdown) (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

Application defined window call procedure (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

File Search Sample Code (created at 2006-09-29)

OTHER POSTS IN THE SAME CATEGORY

투명 윈도우 구현 방법 (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

PC 셧다운 (shutdown) (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

공유폴더 찾아주기 (created at 2006-09-29)

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

빈폴더 찾아내기 (created at 2006-09-29)

IE 패치에 따른 object, embed, applet 대처 방안 (created at 2006-09-28)

Virtusertable (created at 2006-09-28)

웹서버 및 웹메일 설정 방법 (created at 2006-09-28)

음력-양력 변환기 (created at 2006-09-28)

어떤 파라메터가 넘어왔는지 알아내는 함수 (created at 2006-09-28)

PHP에서 메일 함수가 동작하지 않을때 (created at 2006-09-28)

웹페이지 긁어서 타이틀 뿌려주는 소스 (created at 2006-09-28)

PHP로 객체지향 프로그래밍 하는 방법 (created at 2006-09-28)

파일에서 한줄만 읽어다 return 해주는 소스 (created at 2006-09-28)

UPDATES

햄과 소세지가 우리 몸에 일으키는 부작용 (updated at 2024-04-27)

글루코사민 vs. 콘드로이친: 무엇이 더 나은 관절 건강 보조제일까? (created at 2024-04-22)

광주 5·18 민주화운동 알린 테리 앤더슨 前 AP 기자 (created at 2024-04-22)

콘드로이친의 염증 감소효과 (updated at 2024-04-22)

코사민 DS - 글루코사민+콘드로이친 복합물이 함유된 퇴행성 관절 건강보조제 (updated at 2024-04-22)

삼겹살 먹을때 환상조합 (created at 2024-04-22)

일본 여중생의 특이한 취향 (created at 2024-04-22)

우리가 먹는 약물이 바꿔버린 생태계 (created at 2024-04-21)

일본에서 그린 상상속의 사무직과 현실속의 사무직 (updated at 2024-04-21)

북한 미대생들이 그린 북한 최고존엄 김정은 (created at 2024-04-21)

입사 후 1년도 되지 않은 회사에서 구조조정에 의한 퇴직 불응에 따른 해고 처리시 대응 가능한 방법 (updated at 2024-04-20)

한고은님의 옛날 사진 (updated at 2024-04-20)

소녀대 - Bye Bye Girl (updated at 2024-04-13)

대한민국 날씨 근황 (created at 2024-04-13)

성일종 인재육성 강조하며 이토 히로부미 언급 - 인재 키운 선례? (updated at 2024-04-13)

일제강점기가 더 살기 좋았을지도 모른다는 조수연 국민의힘 후보 - 친일파? (updated at 2024-04-13)

Marshall Ha님의 샤오미 SU7 시승기 - 테슬라의 일론 머스크님이 긴장할만한 느낌 (updated at 2024-04-09)

윙크하는 귀염둥이 반려견들 (created at 2024-04-08)

달콤 살벌한 고백 (created at 2024-04-08)

북한 최정예 공수부대 훈련 모습 (updated at 2024-04-02)

맛있었던 친구 어머니의 주먹밥이 먹고 싶어요 (created at 2024-04-02)

자리 마음에 안든다고 6급 공무원 패는 농협 조합장 (created at 2024-03-26)

85세 딸 짜장면 사주는 102세 어머니 (created at 2024-03-26)

1990년대 감각파 도둑 (created at 2024-03-26)

치매에 걸린 69살의 브루스 윌리스가 전부인 데미무어를 보고 한 말 (updated at 2024-03-22)

경제는 대통령이 살리는 것이 아닙니다 라던 윤석열대통령 - 상황 안좋아지자 여러 전략을 펼쳤지만, 부작용 속출했던 2024년의 봄 (updated at 2024-03-13)

극빈의 생활을 하고 배운것이 없는 사람은 자유가 뭔지도 모를 뿐 아니라 왜 개인에게 필요한지에 대한 필요성을 못느낀다는 윤석열 대통령 (updated at 2024-03-08)

조선일보를 안본다는 사람들이 말하는 그 이유 - 천황폐하, 전두환 각하, 김일성 장군 만세? (created at 2024-03-07)

광폭타이어를 장착하면 성능이 좋아질거라는 착각 (updated at 2024-03-03)

면허시험장에서 면허갱신하면 하루만에 끝나나? (updated at 2024-03-03)