当前位置:网站首页>Write two channel (stereo) immediately Wav file
Write two channel (stereo) immediately Wav file
2022-07-25 09:16:00 【Obsessive coding】
Recently completed dual channel ( Stereo is also called dual track ) Voice file recording , I will write my experience here . The format of the two channel file I recorded is PCM,16K,16Bit Of ,blockAlign Set up 2. Stereo voice adopts 0 channel ( Left ) 1 channel ( Right ) 0 channel ( Left ) 1 channel ( Right ). The specific Settings are as follows :
audioCodec by 1,channels by 2,samplesPerSec by 8000( It's very important ).samplesPerSec Set to 8000 The reason for this is to use 16000/2, That is, divide the sampling rate by the number of channels . The reason for this is that when setting the voice content in stereo, the voice data of the left and right channels will be scattered and placed in the content .
void TWavMediaFile::Close()
{
/* write wav head */
if(m_fp && m_modified)
{
m_modified = false;
rewind(m_fp);
LOG(DETAIL, "m_fp postion:%d", ftell(m_fp));
char buffer[44], *p = buffer;
int32_t a;
int16_t b;
sprintf(p, "RIFF");
p+=4;
a = htolel(m_length + 44 - 8);
memcpy(p, &a, 4);
p+=4;
sprintf(p, "WAVEfmt ");
p+=8;
a = htolel(16);
memcpy(p, &a, 4);
p+=4;
LOG(DETAIL, "m_audioCodec: %d", m_audioCodec);
b = htoles((int16_t)m_audioCodec);
memcpy(p, &b, 2);
p+=2;
LOG(DETAIL, "m_channels: %d", m_channels);
b = htoles((int16_t)m_channels);
memcpy(p, &b, 2);
p+=2;
LOG(DETAIL, "m_samplesPerSec: %d", m_samplesPerSec);
a = htolel((int32_t)m_samplesPerSec/2);
memcpy(p, &a, 4);
p+=4;
LOG(DETAIL, "m_avgBytesPerSec: %d", m_avgBytesPerSec);
a = ((int32_t)m_avgBytesPerSec*m_channels);
memcpy(p, &a, 4);
p+=4;
LOG(DETAIL, "m_blockAlign: %d", m_blockAlign);
b = htoles((int16_t)m_blockAlign * m_channels );
memcpy(p, &b, 2);
p+=2;
LOG(DETAIL, "m_bitsPerSample: %d", m_bitsPerSample);
b = htoles((int16_t)m_bitsPerSample);
memcpy(p, &b, 2);
p+=2;
sprintf(p, "data");
p+=4;
LOG(DETAIL, "m_length: %d", m_length);
a = htolel(m_length);
memcpy(p, &a, 4);
fwrite(buffer, 1, 44, m_fp);
}
if(m_fp)
fclose(m_fp);
m_fp = 0;
m_length = 0;
}Set the speech synthesis of two channels to one BUFFER The code of the implementation in is as follows :
void TRecord::feedG711Stero(const char* buffer1, int length1, const char *buffer2, int length2 )
{
char *p = (char*)buffer1;
char twoChannelBuffer[MAXAUDIOBUFFERSIZE] = {0};
/* this only for 8bit per sample */
int i = 0;
int j = 0;
for ( j = 0, j = 0; i != PCMFRAMELEN; i++ )
{
twoChannelBuffer[j++] = m_buffer[i];
twoChannelBuffer[j++] = m_buffer2[i];
}
m_mediaFile->putAudioData(twoChannelBuffer, j );
}
边栏推荐
- How to realize the drop-down option box of wechat applet
- 2022-7-14 JMeter simulates the login of different users for pressure test
- 51单片机内部外设:定时器和计数器
- Redis-哨兵,主从部署详细篇
- flink sql怎么持久化?
- 附加:中半部分sql语句 区/县(数据表)
- 360 degree drag panorama plug-in tpanorama.js
- (self drawn ugly picture) simple understanding tcp/ip three handshakes and four waves
- Disable module (attribute node) in LabVIEW
- Read and write models and organize notes
猜你喜欢

Dependency conflict resolution under idea

51 single chip microcomputer key control LED light status

How to avoid duplicate data when the database is high and distributed

LabVIEW experiment - temperature detection system (experimental learning version)

51单片机内部外设:定时器和计数器

Solve the syntaxerror: unexpected end of JSON input

神经网络学习(1)前言介绍

Cool canvas animation shock wave JS special effect

Druid 查询超时配置的探究 → DataSource 和 JdbcTemplate 的 queryTimeout 到底谁生效?

2022-7-14 JMeter pressure test
随机推荐
flink sql怎么持久化?
sql注入
[deep learning] overview | the latest progress of deep learning
[STL]stack&queue模拟实现
[stl]stack & queue simulation implementation
CIR industrial automation radar
A picture to quickly understand envoyfilter in istio
Anti shake and throttling
[learn rust together] a preliminary understanding of rust package management tool cargo
Additional: SQL statement area / county in the lower half (data table)
This is the worst controller layer code I've ever seen
The operation cannot be completed because a folder or file in it is already open in another program
Overview of redis/mysql knowledge
[hero planet July training leetcode problem solving daily] 19th binary tree
附加:下半部分sql语句 区/县(数据表)
Leetcode · 83 biweekly race · 6129. Number of all 0 subarrays · mathematics
Programmers can't SQL? Ashes Engineer: all waiting to be eliminated! This is a must skill!
How does Youxuan database encrypt data?
Silicon Valley classroom lesson 12 - official account on demand course and live broadcast management module
51 MCU internal peripherals: timer and counter