디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

잘 생긴 횽들아! 내 글 좀 봐죠.

문맥(210.95) 2009.08.06 17:07:35
조회 106 추천 0 댓글 6

.wav파일을 읽어서 data를 decode하기전에 audio play하는 코드데,
소리에서 잡음이 섞어 나오네, 왜 그러는지 좀 봐죠.

 

static int
get_audio(lame_global_flags * const gfp, int buffer[2][1152])
{
    int     num_channels = lame_get_num_channels(gfp);
    int     insamp[2 * 1152];
    int     samples_read;
    int     framesize;
    int     samples_to_read;
    unsigned int remaining, tmp_num_samples;
    int     i;
    int    *p;

    /*
     * NOTE: LAME can now handle arbritray size input data packets,
     * so there is no reason to read the input data in chuncks of
     * size "framesize".  EXCEPT:  the LAME graphical frame analyzer
     * will get out of sync if we read more than framesize worth of data.
     */

    samples_to_read = framesize = lame_get_framesize(gfp);
    assert(framesize <= 1152);

    /* get num_samples */
    tmp_num_samples = lame_get_num_samples(gfp);

    /* if this flag has been set, then we are carefull to read
     * exactly num_samples and no more.  This is useful for .wav and .aiff
     * files which have id3 or other tags at the end.  Note that if you
     * are using LIBSNDFILE, this is not necessary
     */
    if (global.count_samples_carefully) {
        remaining = tmp_num_samples - Min(tmp_num_samples, global.num_samples_read);
        if (remaining < (unsigned int) framesize && 0 != tmp_num_samples)
            /* in case the input is a FIFO (at least it\'s reproducible with
               a FIFO) tmp_num_samples may be 0 and therefore remaining
               would be 0, but we need to read some samples, so don\'t
               change samples_to_read to the wrong value in this case */
            samples_to_read = remaining;
    }

    if (is_mpeg_file_format(input_format)) {
        if (buffer != NULL)
            samples_read = read_samples_mp3(gfp, global.musicin, buf_tmp16);
        else
            samples_read = read_samples_mp3(gfp, global.musicin, buffer16);
        if (samples_read < 0) {
            return samples_read;
        }
    }
    else {
        samples_read = read_samples_pcm(global.musicin, insamp, num_channels * samples_to_read);
        if (samples_read < 0) {
            return samples_read;
        }
        p = insamp + samples_read;
        samples_read /= num_channels;
        if (buffer != NULL) { /* output to int buffer */
            if (num_channels == 2) {
                for (i = samples_read; --i >= 0;) {
                    buffer[1][i] = *--p;
                    buffer[0][i] = *--p;
                }
            }
            else if (num_channels == 1) {
                memset(buffer[1], 0, samples_read * sizeof(int));
                for (i = samples_read; --i >= 0;) {
                    buffer[0][i] = *--p;
                }
            }
            else
                assert(0);
        }
        else {          /* convert from int; output to 16-bit buffer */
            if (num_channels == 2) {
                for (i = samples_read; --i >= 0;) {
                    buffer16[1][i] = *--p >> (8 * sizeof(int) - 16);
                    buffer16[0][i] = *--p >> (8 * sizeof(int) - 16);
                }
            }
        }
    }

  


    /* if num_samples = MAX_U_32_NUM, then it is considered infinitely long.
       Don\'t count the samples */
    if (tmp_num_samples != MAX_U_32_NUM)
        global. num_samples_read += samples_read;

    return samples_read;
}

-----------------------------------------------------------------------
static int
lame_encoder(lame_global_flags * gf, FILE * outf, int nogap, char *inPath, char *outPath)
{
    unsigned char mp3buffer[LAME_MAXMP3BUFFER];
    int     Buffer[2][1152];
    int     iread, imp3, owrite, id3v2_size;

 


    static HWAVEOUT     hWaveOut ;
    static PBYTE        pBuffer ;
    static PWAVEHDR     pWaveHdr ;
    static WAVEFORMATEX waveformat ;
    MMRESULT     rc;                                               
    char         sError[129];

 

 


    encoder_progress_begin(gf, inPath, outPath);

    imp3 = lame_get_id3v2_tag(gf, mp3buffer, sizeof(mp3buffer));
    if ((size_t)imp3 > sizeof(mp3buffer)) {
        encoder_progress_end(gf);
        error_printf("Error writing ID3v2 tag: buffer too small: buffer size=%d  ID3v2 size=%d\\n"
                , sizeof(mp3buffer)
                , imp3
                    );
        return 1;
    }
    owrite = (int) fwrite(mp3buffer, 1, imp3, outf);
    if (owrite != imp3) {
        encoder_progress_end(gf);
        error_printf("Error writing ID3v2 tag \\n");
        return 1;
    }
    if (flush_write == 1) {
        fflush(outf);
    }   
    id3v2_size = imp3;

 

 

    do {
        /* read in \'iread\' samples */
        iread = get_audio(gf, Buffer);

  pWaveHdr = malloc (sizeof (WAVEHDR)) ;
  pBuffer  = malloc (4096) ;

  if (!pWaveHdr || !pBuffer)
  {
   if (!pWaveHdr) free (pWaveHdr) ;
            if (!pBuffer)  free (pBuffer) ;

            return TRUE ;
  }
   
        waveformat.wFormatTag      = WAVE_FORMAT_PCM ;
        waveformat.nChannels       = 2 ;
        waveformat.nSamplesPerSec  = 44100 ;
        waveformat.nAvgBytesPerSec = 176400 ;
        waveformat.nBlockAlign     = 4 ;
        waveformat.wBitsPerSample  = 16 ;
        waveformat.cbSize          = 0 ;
                        
        if (waveOutOpen (&hWaveOut, WAVE_MAPPER, &waveformat,
                                     0, 0, WAVE_ALLOWSYNC) != MMSYSERR_NOERROR)
        {
            free (pWaveHdr) ;
            free (pBuffer) ;

            hWaveOut = NULL ;
            return TRUE ;
        }
        pWaveHdr->lpData          = (LPSTR) Buffer;
        pWaveHdr->dwBufferLength  = 4096 ;
        pWaveHdr->dwBytesRecorded = 0 ;
        pWaveHdr->dwUser          = 0 ;
        pWaveHdr->dwFlags         = 0 ;
        pWaveHdr->dwLoops         = 1 ;
        pWaveHdr->lpNext          = NULL ;
        pWaveHdr->reserved        = 0 ;
                   
        waveOutPrepareHeader (hWaveOut, pWaveHdr,
                                          sizeof (WAVEHDR)) ;

        rc = waveOutWrite (hWaveOut, pWaveHdr, sizeof (WAVEHDR)) ;
        waveOutClose (hWaveOut) ;
        waveOutGetErrorText(rc, sError, 128);   
        error_printf("mp3 internal error:  error code=%s\\n", sError);

 } while (iread > 0);
return 0;
}

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 주위 눈치 안 보고(어쩌면 눈치 없이) MZ식 '직설 화법' 날릴 것 같은 스타는? 운영자 24/04/29 - -
147312 오퍼레이션7 좃네 [3] 분당살람갤로그로 이동합니다. 09.09.11 91 0
147311 http://en.akinator.com/ 이겨따 [1] prismatic갤로그로 이동합니다. 09.09.11 88 0
147309 오늘도 큰웃음 [17] ㅇㅇㅃ갤로그로 이동합니다. 09.09.11 237 0
147308 요즘 일하면서 많은걸 생각한다. [6] yundream(211.189) 09.09.11 171 0
147307 임진강 참사 당당 프로그래머 3명 구속 [16] 오라클설치갤로그로 이동합니다. 09.09.11 326 0
147306 비교체험 극과 극 [1] 유리한갤로그로 이동합니다. 09.09.11 110 0
147305 왜 이사람들은 오래 살아서 욕을 먹는가 [2] ㅇㅇㅃ갤로그로 이동합니다. 09.09.11 112 0
147304 삼성전자 주식 [2] Vita500갤로그로 이동합니다. 09.09.11 138 0
147303 허경영 아저씨를 만나다. [1] 물속의다이아갤로그로 이동합니다. 09.09.11 130 0
147302 BANDIVIDEO 예제소스 하잉(219.241) 09.09.11 60 0
147301 국비과정에 대해 궁금한게있는데... [7] 맥콜(125.188) 09.09.11 178 0
147299 회사 사람들한테 http://en.akinator.com/ 퍼트렸는데.. 물속의다이아갤로그로 이동합니다. 09.09.11 125 0
147298 할렐루야~!! [3] 맥콜(125.188) 09.09.11 107 0
147297 밑에 Introduction to algorithms 관한 글이 있길래요 [2] 성대아싸(115.145) 09.09.11 123 0
147295 아... 드디어.... 후로젝트 끝났엉...... [2] 아..(122.44) 09.09.11 98 0
147294 세상이 점점 바람지케지고 있다 [5] 분당살람갤로그로 이동합니다. 09.09.11 120 0
147293 직장동료에게 매력을 느낀 적이 있나? [4] 개쉛기갤로그로 이동합니다. 09.09.11 147 0
147292 Python으로 짠 간단한 A* 길찾기 알고리즘 [5] P(125.188) 09.09.11 1228 0
147291 MFC사용 좀 질문할께요 [16] Ejr(115.161) 09.09.11 146 0
147290 최강희를 틀리다.. Vita500갤로그로 이동합니다. 09.09.11 104 0
147289 은지원 “박근혜, 고모라 부르지 못하고…” [3] Vita500갤로그로 이동합니다. 09.09.11 157 0
147287 jsp에서 [3] 응아(165.132) 09.09.11 57 0
147286 [MFC] 횽들 간단한거 질문좀 젭라 ㅠ.ㅠ [14] 혀배터갤로그로 이동합니다. 09.09.10 85 0
147284 비스타 마이크로소프트워드에서 행간어딨나요..; [6] ㅈㅁㄴㅇ(211.54) 09.09.10 203 0
147282 하얀모코나님 보세염 [1] ㅇ.ㅇ(58.239) 09.09.10 50 0
147280 충격적인 짤방 [5] Q Lazzarus갤로그로 이동합니다. 09.09.10 194 0
147279 답답해서 집을 확 나왔는데... [4] 첫가출(61.32) 09.09.10 78 0
147278 c언어 좀 도와주세요 ㅜㅜ [7] 안녕하십니까(118.128) 09.09.10 85 0
147277 내가 자세히 질문 좀 드릴께요 ㅜ [14] 하얀모코나(58.127) 09.09.10 100 0
147275 늅이의 마지막질문 ㅋ_ㅋ int가 오버플로가 되면 int 대신에 멀 써야 [6] 하얀모코나갤로그로 이동합니다. 09.09.10 99 0
147274 프로그래밍이 programming? [31] 좃프로그래머(124.53) 09.09.10 177 0
147273 비주얼 베이직 잘아는분 이것좀 도와주세요 ㅜㅜ 부탁 [2] djpqjdpjdp(124.111) 09.09.10 30 0
147272 비주얼 베이직 잘아는분 이것좀 도와주세요 ㅜㅜ 부탁 [4] djpqjdpjdp(124.111) 09.09.10 76 0
147269 vkcode가 뭔가여? [3] (210.124) 09.09.10 35 0
147268 저도 리눅스를 깔았습니다. [4] 구루구루(115.145) 09.09.10 63 0
147265 프로그래밍=c언어 일케아는데 [12] (210.124) 09.09.10 120 0
147264 인트로두션 투 알고리즘 너무 토나온다.. 다른거 없나요? [11] 구루구루(115.145) 09.09.10 118 0
147263 형들아 c++ 문제 힌트좀 줘 [12] 호호아줌마(116.39) 09.09.10 90 0
147262 대학1학년인데 C로 구성된 자료구조 자습 책좀 추천해주세여 ㅠㅠ [2] 눈팅만1년갤로그로 이동합니다. 09.09.10 107 0
147261 ccna시험보는거 정말 돈낭비임? [2] 사성천갤로그로 이동합니다. 09.09.10 96 0
147260 슈발 한듣보는 한번에 맞춰놓고 유리한갤로그로 이동합니다. 09.09.10 42 0
147259 GetAsyncKeyState 이프로그램이아는사람? [5] (210.124) 09.09.10 52 0
147258 lI <짝대기님 ㅋㅋ 고미뉴(121.140) 09.09.10 58 0
147256 오늘 디씨 왜이러냐. IT대학갤로그로 이동합니다. 09.09.10 53 0
147253 지분을 확인해야 하는데 횽아들 도와줌메~ [1] Q Lazzarus갤로그로 이동합니다. 09.09.10 65 0
147249 좃프로그래머님. [1] 씬입사원갤로그로 이동합니다. 09.09.10 104 0
147248 앜ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [3] 아주아슬갤로그로 이동합니다. 09.09.10 71 0
147247 뜨악 무서움;; [2] 위위(124.61) 09.09.10 75 0
147246 소라 아오이를 맞추다 [2] 물속의다이아갤로그로 이동합니다. 09.09.10 135 0
147245 T스토어 나왔는데... 프로그래머들 관심이 별루 없네.. [6] 좃프로그래머(124.53) 09.09.10 187 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2