Skip to content

Commit 31b6d48

Browse files
committed
* fix record bug
1 parent 77f4664 commit 31b6d48

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

components/voice/port/maixcam/maix_audio_mmf.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,13 @@ namespace maix::audio
432432
record_size = remaining_bytes;
433433
} else {
434434
if (!param->block) {
435-
if (record_size < remaining_bytes) {
435+
if ((uint32_t)record_size > remaining_bytes) {
436436
record_size = remaining_bytes;
437437
}
438+
439+
if (record_size == 0) {
440+
return new Bytes();
441+
}
438442
}
439443
}
440444

examples/audio_demo/main/src/main.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ int _main(int argc, char* argv[])
526526
}
527527

528528
log::info("Ready to record %ld ms, and save to %s\r\n", record_ms, path.c_str());
529-
audio::Recorder r = audio::Recorder(path, sample_rate, format, channel, true);
529+
audio::Recorder r = audio::Recorder(path, sample_rate, format, channel, block);
530530
r.reset();
531531
err::check_bool_raise(r.sample_rate() == sample_rate);
532532
err::check_bool_raise(r.format() == format);
@@ -540,33 +540,24 @@ int _main(int argc, char* argv[])
540540
if (block) {
541541
if (record_ms < 0) {
542542
record_bytes = record_ms;
543-
auto data = r.record_bytes(record_bytes);
543+
auto data = r.record(record_ms);
544544
log::info("Record %ld ms, bytes:%d, used %lld ms", record_ms, data->size(), time::ticks_ms() - t);
545545
time::sleep_ms(100);
546546
} else {
547-
auto data = r.record_bytes(record_bytes);
547+
auto data = r.record(record_ms);
548548
err::check_bool_raise(data->data_len == (size_t)record_bytes, "Record bytes error");
549549
log::info("Record %ld ms, bytes:%d, used %lld ms", record_ms, data->size(), time::ticks_ms() - t);
550550
}
551551
} else {
552552
if (record_ms < 0) {
553553
record_bytes = record_ms;
554-
auto data = r.record_bytes(record_bytes);
554+
auto data = r.record(record_ms);
555555
log::info("Record %ld ms, bytes:%d, used %lld ms", record_ms, data->size(), time::ticks_ms() - t);
556-
time::sleep_ms(100);
556+
time::sleep_ms(record_ms);
557557
} else {
558-
auto remain_bytes = r.get_remaining_frames() * bytes_per_frame;
559-
record_bytes = (record_bytes + 1023) & ~1023;
560-
if (record_bytes > remain_bytes) {
561-
record_bytes = remain_bytes;
562-
}
563-
564-
if (record_bytes != 0) {
565-
log::info("remain bytes: %d, record bytes: %d", remain_bytes, record_bytes);
566-
auto data = r.record_bytes(record_bytes);
567-
err::check_bool_raise(data->data_len == (size_t)record_bytes, "Record bytes error");
568-
log::info("Record %ld ms, bytes:%d, used %lld ms", record_ms, data->size(), time::ticks_ms() - t);
569-
}
558+
auto data = r.record(record_ms);
559+
log::info("Record %ld ms, bytes:%d, used %lld ms", record_ms, data->size(), time::ticks_ms() - t);
560+
time::sleep_ms(record_ms);
570561
}
571562
}
572563
}
@@ -674,7 +665,7 @@ int _main(int argc, char* argv[])
674665
log::info("Play bytes:%d, used %lld ms", data.size(), time::ticks_ms() - t);
675666
} else {
676667
auto bytes_per_frames = p.frame_size();
677-
while (p.get_remaining_frames() * bytes_per_frames < data.size() && !app::need_exit()) {
668+
while ((size_t)(p.get_remaining_frames() * bytes_per_frames) < data.size() && !app::need_exit()) {
678669
time::sleep_ms(1);
679670
}
680671

0 commit comments

Comments
 (0)