Introduction

This sample implements a simple OpenAL-based audio recorder.

Controls

Ensure the correct recording device is selected in the drop-down list (e.g. "Microphone"), then click on the "Start recording" and talk to the parrot. Click on "Stop recording" when done.

Sample rate (Hz): indicates he sample rate of the recording. Typical sound cards support the following values: 8000, 16000, 22050, 32000, 44100 and 48000Hz but some sound cards may support higher values. A value of 8000Hz is considered adequate for voice reproduction, while a value of 44100Hz is considered adequate for music reproduction.

Buffer length (ms): indicates how much data will be buffered before playback starts. Higher values may decrease CPU usage at the cost of higher latency between recording and playback. Lower values will decrease latency but may increase CPU usage and introduce noise if the CPU cannot respond fast enough. Values between 10-200ms are considered adequate for real-time audio conferencing. On the other hand, the buffer shouldn't exceed 10ms for real-time recording & playback of musical instruments.

Playback gain (dB): specifies the amount of gain (amplification) when playing back the recorded signal. High values may introduce noise.

Implementation

The application enumerates available recording devices and awaits for the user to click on the "Start recording" button. When the button is clicked, the application constructs an AudioContext and an AudioCapture object using the parameters specified by the user.

A timer fires periodically to check whether the capture buffer is full, in which case it copies its data to an audio buffer and enqueues it to the AudioContext for playback.