Thao tác với RAW AUDIO
Các AudioTrack và AudioRecord lớp cho phép bạn ghi lại âm thanh trực tiếp từ các phần cứng âm thanh đầu vào và dòng đệm âm thanh PCM trực tiếp đến phần cứng âm thanh để phát lại.
Sử dụng Audio Track trực tuyến, bạn có thể xử lý và phát lại âm thanh đến gần thời gian thực, cho phép bạn thao tác âm thanh đến hoặc đi và thực hiện xử lý tín hiệu về âm thanh thô.
Mặc dù một tài khoản chi tiết về xử lý âm thanh thô và thao tác là vượt ra ngoài phạm vi của cuốn sách này, các phần sau đây cung cấp một giới thiệu về ghi âm và phát lại dữ liệu PCM thô.
Recording Sound với audio Record
Sử dụng lớp AudioRecord để ghi lại âm thanh trực tiếp từ bộ đệm cứng. Tạo Audio Record đối tượng mới, xác định nguồn, tần số, cấu hình kênh, mã hóa âm thanh, kích thước buffer:
int BUFFERSIZE = AudioRecord.getMinBufferSize (tần số,
channelConfiguration,
audioEncoding);
AudioRecord audioRecord = new AudioRecord (MediaRecorder.AudioSource.MIC,
tần số , channelConfiguration, audioEncoding, BUFFERSIZE);
các tần số, mã hóa âm thanh, và các giá trị cấu hình kênh sẽ ảnh hưởng đến kích thước và chất lượng của âm thanh ghi lại. Không có dữ liệu meta này là liên kết với các tập tin ghi lại.
Vì lý do riêng tư, Android yêu cầu sự cho phép record_audio được bao gồm trong biểu hiện của bạn:
Khi Audio Record đối tượng của bạn được khởi tạo, chạy các phương pháp startRecording để bắt đầu ghi âm không đồng bộ, và sử dụng các phương pháp đọc để thêm dữ liệu audio thô thành các bộ đệm ghi:
audioRecord.startRecording (); while (isRecording) {
[... cư đệm ...]
int bufferReadResult = audioRecord.read (buffer, 0, BUFFERSIZE);
}
Liệt 15-18 ghi lại âm thanh thô từ một micro vào một tập tin được lưu trữ trên một thẻ SD. Phần tiếp theo sẽ cho bạn thấy làm thế nào để sử dụng Bản nhạc âm thanh để chơi âm thanh này.
đang được dịch, vui lòng đợi..