Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2022-10-18 14:56:34 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2022-10-18 14:56:34 +0800
Commit
b78bdd9a2e786c3e1c58bd1e9a20c8d1f8222407
b78bdd9a
1 parent
8697a6d9
Fix reading wave files with metadata (#21)
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
20 行增加
和
4 行删除
sherpa-onnx/csrc/wave-reader.cc
sherpa-onnx/csrc/wave-reader.cc
查看文件 @
b78bdd9
...
...
@@ -25,7 +25,6 @@
#include <vector>
namespace
sherpa_onnx
{
namespace
{
// see http://soundfile.sapp.org/doc/WaveFormat/
//
...
...
@@ -47,6 +46,22 @@ struct WaveHeader {
assert
(
bits_per_sample
==
16
);
// we support only 16 bits per sample
}
// See
// https://en.wikipedia.org/wiki/WAV#Metadata
// and
// https://www.robotplanet.dk/audio/wav_meta_data/riff_mci.pdf
void
SeekToDataChunk
(
std
::
istream
&
is
)
{
// a t a d
while
(
subchunk2_id
!=
0x61746164
)
{
// const char *p = reinterpret_cast<const char *>(&subchunk2_id);
// printf("Skip chunk (%x): %c%c%c%c of size: %d\n", subchunk2_id, p[0],
// p[1], p[2], p[3], subchunk2_size);
is
.
seekg
(
subchunk2_size
,
std
::
istream
::
cur
);
is
.
read
(
reinterpret_cast
<
char
*>
(
&
subchunk2_id
),
sizeof
(
int32_t
));
is
.
read
(
reinterpret_cast
<
char
*>
(
&
subchunk2_size
),
sizeof
(
int32_t
));
}
}
int32_t
chunk_id
;
int32_t
chunk_size
;
int32_t
format
;
...
...
@@ -58,8 +73,8 @@ struct WaveHeader {
int32_t
byte_rate
;
int16_t
block_align
;
int16_t
bits_per_sample
;
int32_t
subchunk2_id
;
int32_t
subchunk2_size
;
int32_t
subchunk2_id
;
// a tag of this chunk
int32_t
subchunk2_size
;
// size of subchunk2
};
static_assert
(
sizeof
(
WaveHeader
)
==
44
,
""
);
...
...
@@ -69,9 +84,10 @@ std::vector<float> ReadWaveImpl(std::istream &is, float *sample_rate) {
WaveHeader
header
;
is
.
read
(
reinterpret_cast
<
char
*>
(
&
header
),
sizeof
(
header
));
assert
(
static_cast
<
bool
>
(
is
));
header
.
Validate
();
header
.
SeekToDataChunk
(
is
);
*
sample_rate
=
header
.
sample_rate
;
// header.subchunk2_size contains the number of bytes in the data.
...
...
请
注册
或
登录
后发表评论