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

    METHOD
    Creates a recorder instance.
    Parameters
    NameTypeDefaultDescription
    tempPathconst 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.

    monoboolfalseTrue: mono, false: stereo.
    Returns
    TypeDescription
    Superpowered::RecorderThe constructed instance.
  • addToTracklist

    METHOD
    Each 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.
    Parameters
    NameTypeDefaultDescription
    artistchar *Artist, can be NULL.
    titlechar *Title, can be NULL.
    becameAudibleSecondsint0When the current track begins to be audible in this recording, relative to "now". For example, 0 means "now", -10 means "10 seconds ago".
    takeOwnershipboolfalseIf true, this class will free() artist and title.
    Returns
    None
  • isFinished

    METHOD
    Returns 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.
    Parameters
    None
    Returns
    TypeDescription
    booltrue if the recorder has finished writing.
  • prepare

    METHOD
    Prepares 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.
    Parameters
    NameTypeDefaultDescription
    destinationPathconst char *The full filesystem path of the successfully finished recording. Do not include ".wav" in this, the .wav extension will be automatically appended.
    samplerateunsigned intThe sample rate of the audio input and the recording, in Hz. The input sample rate must remain the same during the entire recording.
    fadeInFadeOutboolIf 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.
    minimumLengthSecondsunsigned intThe minimum length of the recording. If the number of recorded seconds is lower, then a file will not be saved.
    Returns
    TypeDescription
    boolReturns true on success or false if another recording is still active or not finished writing to disk yet.
  • preparefd

    METHOD
    Prepares 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.
    Parameters
    NameTypeDefaultDescription
    audiofdintExisting file descriptor for the audio file. Superpowered will fdopen on this using "w" mode.
    logfdintExisting file descriptor for the .txt file. Can be 0 if addtoTracklist() is not used.
    samplerateunsigned intThe sample rate of the audio input and the recording, in Hz. The input sample rate must remain the same during the entire recording.
    fadeInFadeOutboolIf 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.
    minimumLengthSecondsunsigned intThe minimum length of the recording. If the number of recorded seconds is lower, then a file will not be saved.
    Returns
    TypeDescription
    boolReturns true on success or false if another recording is still active or not finished writing to disk yet.
  • recordInterleaved

    METHOD
    Processes incoming interleaved stereo audio. It's never blocking for real-time usage.
    Parameters
    NameTypeDefaultDescription
    inputfloat *Pointer to floating point numbers. Stereo interleaved audio to record.
    numberOfFramesunsigned intThe number of frames in input.
    Returns
    TypeDescription
    unsigned intSeconds recorded so far.
  • recordMono

    METHOD
    Processes incoming mono audio. It's never blocking for real-time usage.
    Parameters
    NameTypeDefaultDescription
    inputfloat *Pointer to floating point numbers. Mono audio to record.
    numberOfFramesunsigned intThe number of frames in input.
    Returns
    TypeDescription
    unsigned intSeconds recorded so far.
  • recordNonInterleaved

    METHOD
    Processes incoming non-interleaved stereo audio. It's never blocking for real-time usage.
    Parameters
    NameTypeDefaultDescription
    leftfloat *Pointer to floating point numbers. Left input channel.
    rightfloat *Pointer to floating point numbers. Right input channel.
    numberOfFramesunsigned intThe number of frames in input.
    Returns
    TypeDescription
    unsigned intSeconds recorded so far.
  • stop

    METHOD
    Stops 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.
    Parameters
    None
    Returns
    None
Javascript

is not supported here.

v1.0.32