Class: Recorder
Overview
Writes audio into 16-bit WAV file, with an optional track list text file. Use this class in a real-time audio processing thread, where directly writing to a disk is not recommended. For offline processing, instead of this Recorder use the createWAV(), writeWAV() and closeWAV() functions in SuperpoweredSimple.h. One instance allocates around 135k x numChannels memory when recording starts.
How to implement
#include "SuperpoweredRecorder.h"void initRecorder() {// Constructor.recorder = new Superpowered::Recorder("temp.wav", // The full filesystem path of a temporary file. The recorder will create and write into this while recording.false // True: mono, false: stereo.);// Prepares for recording. The actual recording will begin on the first call of the process() method.recorder->prepare("superpowered", // The full filesystem path of the successfully finished recording. Do not include ".wav" in this, the .wav extension will be automatically appended.44100, // The sample rate of the audio input and the recording, in Hz. The input sample rate must remain the same during the entire recording.true, // If true, the recorder applies a fade-in at the beginning and a fade-out at the end of the recording. The fade is 64 frames long.10 // The minimum length of the recording. If the number of recorded seconds is lower, then a file will not be saved.);// Each recording may include a track list, which is a .txt file placed next to the destination audio file. This method adds an entry to the tracklist.recorder->addToTracklist("artist name","title",0, // When the current track begins to be audible in this recording, relative to "now". For example, 0 means "now", -10 means "10 seconds ago".false // If true, this class will free() artist and title.)}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames) {// Processes incoming interleaved stereo audio. This function has non-interleaved stereo and mono versions as well.unsigned int secondsRecordedSoFar = recorder->recordInterleaved(interleavedInput, // Pointer to floating point numbers. Stereo interleaved audio to record.numberOfFrames // The number of frames in input.);...}void stopRecorder() {// Stops recording.recorder->stop();// After calling stop() the recorder needs a little bit more time to write the last pieces of audio to disk. You can periodically call isFinished() to check when it's done.while (!recorder->isFinished()) sleep();}
Methods
constructor
METHODCreates a recorder instance.ParametersReturnsName Type Default Description tempPath const char *
The full filesystem path of a temporary file. The recorder will create and write into this while recording. Can be NULL if only preparefd() is used.
Warning: Filesystem paths in C are different than paths in Java. /sdcard becomes /mnt/sdcard for example.
mono bool
false True: mono, false: stereo. Type Description Superpowered::Recorder
The constructed instance. addToTracklist
METHODEach recording may include a tracklist, which is a .txt file placed next to the destination audio file. This method adds an entry to the tracklist. The tracklist file will not be created if this method is never called. Do not call this in a real-time audio processing thread.ParametersReturnsName Type Default Description artist char *
Artist, can be NULL. title char *
Title, can be NULL. becameAudibleSeconds int
0 When the current track begins to be audible in this recording, relative to "now". For example, 0 means "now", -10 means "10 seconds ago". takeOwnership bool
false If true, this class will free() artist and title. NoneisFinished
METHODReturns true if the recorder has finished writing after stop() was called, so the recording is fully available at the destination path. It's safe to call this method in any thread.ParametersNoneReturnsType Description bool
true if the recorder has finished writing. prepare
METHODPrepares for recording. The actual recording will begin on the first call of the process() method. Do not call this in a real-time audio processing thread.ParametersReturnsName Type Default Description destinationPath const char *
The full filesystem path of the successfully finished recording. Do not include ".wav" in this, the .wav extension will be automatically appended. samplerate unsigned int
The sample rate of the audio input and the recording, in Hz. The input sample rate must remain the same during the entire recording. fadeInFadeOut bool
If true, the recorder applies a fade-in at the beginning and a fade-out at the end of the recording. The fade is 64 frames long. minimumLengthSeconds unsigned int
The minimum length of the recording. If the number of recorded seconds is lower, then a file will not be saved. Type Description bool
Returns true on success or false if another recording is still active or not finished writing to disk yet. preparefd
METHODPrepares for recording. The actual recording will begin on the first call of the process() method. Do not call this in a real-time audio processing thread.ParametersReturnsName Type Default Description audiofd int
Existing file descriptor for the audio file. Superpowered will fdopen on this using "w" mode. logfd int
Existing file descriptor for the .txt file. Can be 0 if addtoTracklist() is not used. samplerate unsigned int
The sample rate of the audio input and the recording, in Hz. The input sample rate must remain the same during the entire recording. fadeInFadeOut bool
If true, the recorder applies a fade-in at the beginning and a fade-out at the end of the recording. The fade is 64 frames long. minimumLengthSeconds unsigned int
The minimum length of the recording. If the number of recorded seconds is lower, then a file will not be saved. Type Description bool
Returns true on success or false if another recording is still active or not finished writing to disk yet. recordInterleaved
METHODProcesses incoming interleaved stereo audio. It's never blocking for real-time usage.ParametersReturnsName Type Default Description input float *
Pointer to floating point numbers. Stereo interleaved audio to record. numberOfFrames unsigned int
The number of frames in input. Type Description unsigned int
Seconds recorded so far. recordMono
METHODProcesses incoming mono audio. It's never blocking for real-time usage.ParametersReturnsName Type Default Description input float *
Pointer to floating point numbers. Mono audio to record. numberOfFrames unsigned int
The number of frames in input. Type Description unsigned int
Seconds recorded so far. recordNonInterleaved
METHODProcesses incoming non-interleaved stereo audio. It's never blocking for real-time usage.ParametersReturnsName Type Default Description left float *
Pointer to floating point numbers. Left input channel. right float *
Pointer to floating point numbers. Right input channel. numberOfFrames unsigned int
The number of frames in input. Type Description unsigned int
Seconds recorded so far. stop
METHODStops recording. After calling stop() the recorder needs a little bit more time to write the last pieces of audio to disk. You can periodically call isFinished() to check when it's done. It's safe to call this method in any thread.ParametersNoneReturnsNone
is not supported here.