사운드 프로그래밍

s97083의 이미지

요즘 마이크로 입력을 받아서 그것을 전송하는 프로그램을 하고 있습니다.

쉽게 말해서 음성채팅이져... 영상 전송 부분은 다른 분이 구현을 했는데여

제가 다음과 같이 코딩을 해서 마이크로 데이터 입력을 받았습니다.

#ifdef SNDCTL_DSP_GETERROR
  audio_errinfo errinfo;
  if(m_audioSrcFrameNumber == 0) {
   ioctl(m_audioDevice, SNDCTL_DSP_GETERROR, &errinfo);
 } else {
   ioctl(m_audioDevice, SNDCTL_DSP_GETERROR, &errinfo);
   if(errinfo.rec_overruns > 0) {
    close(m_audioDevice);
    InitDevice();
   m_audioSrcSampleNumber = 0;
  }
}
#endif

if(m_audioSrcFrameNumber ==0) {
   int enablebits;
  ioctl(m_audioDevice, SNDCTL_DSP_GETTRIGGER, &enablebits);
  enablebits |= PCM_ENABLE_INPUT;
  ioctl(m_audioDevice, SNDCTL_DSP_SETTRIGGER, &enablebits);
}
m_maxPasses = 10000;

for (int pass = 0; pass < m_maxPasses; pass++)
{
u_int32_t bytesRead = read(m_audioDevice, m_pcmFrameBuffer, m_pcmFrameSize);
fprintf(stderr,"%d: buffer %d: %d\n",pass, bytesRead, (unsigned char) *m_pcmFrameBuffer);

m_pcmFrameBuffer,pass,NULL,SDL_MIX_MAXVOLUME);
write(m_audioDevice, m_pcmFrameBuffer, bytesRead);

}

close(m_audioDevice);

이러니까 m_pcmFrameBuffer에 마이크로 말하는게 들어가는거 같더군여

pcm 데이터로 문제는 이게 raw 형식이라 이것을 wave나 ogg 같은

다른 포맷으로 바꾸는 법을 모르겠어여 실은 소스도 많이 밧는데

너무 복잡해서 이해가 안가더군요 고수분들 버퍼에 들어온 자료를

wave나 ogg 같은 포맷으로 바꾸는 법좀 알려주세요
(버퍼에는 백단위 숫자가 계속해서 들어오더군여 111, 124 같은)

dreamer의 이미지

pcm데이타를 .wav나 mp3같은 형식으로 만드는 것이 encode잔아요, 그 반대가 decode이고 이걸 합해서 codec이라고 부르는 것이고요.
적절한 codec을 구해서 혹은 만들어도 되겠지만 시간이 많이 필요하고 불필요한 작업이겠죠. 이미 나와 있는 것들이 있으니까...^^
http://sox.sourceforge.net/
여기서 sox를 다운 받아서 소스 코드들 살펴보면 많은 도움일 될것 같군요..

saxboy의 이미지

ogg나 mp3같은 복잡한 코덱이면 모르겠지만, wav는 굉장히 간단한 포맷이기 때문에 직접 만들기도 어렵지 않습니다. 하지만 다른 포맷들은 직접 구현하기가 꽤 힘들고 이미 라이브러리가 많기 때문에 그럴 필요도 없습니다. 그래픽 라이브러리를 만들면서 jpg나 png 같은 파일포맷의 로더를 직접 구현한다면 바보같은 짓이 되겠지요.
사운드와 관련해서는 sox 만큼 풍부한 기능을 가진 프로그램이 드물기 때문에 한번 코드를 읽어보시는 것이 좋을 것 같다는 생각이 드는군요.

indizarm의 이미지

wav = wav header + pcm data

wav header - 보통은 44바이트의 헤더 (사실은
X대로 쓰기 때문에 그럴수도 있고 아닐 수도 있다.
보통은 44바이트)

검색어: wave header format. riff file format ... etc

http://www.ringthis.com/dev/wave_format.htm

다음은 MSDN에서 복사한 것.

Quote:
typedef struct {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
} WAVEFORMAT;

wFormatTag
Format type. The following type is defined:
WAVE_FORMAT_PCM
Waveform-audio data is PCM.
nChannels
Number of channels in the waveform-audio data. Mono data uses one channel and stereo data uses two channels.
nSamplesPerSec Sample rate, in samples per second.
nAvgBytesPerSec
Required average data transfer rate, in bytes per second. For example, 16-bit stereo at 44.1 kHz has an average data rate of 176,400 bytes per second (2 channels — 2 bytes per sample per channel — 44,100 samples per second).
nBlockAlign
Block alignment, in bytes. The block alignment is the minimum atomic unit of data. For PCM data, the block alignment is the number of bytes used by a single sample, including data for both channels if the data is stereo. For example, the block alignment for 16-bit stereo PCM is 4 bytes (2 channels — 2 bytes per sample).
Remarks
For formats that require additional information, this structure is included as a member in another structure along with the additional information.

What a Cool Days!!!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.