Skip to content

Instantly share code, notes, and snippets.

@kungfoo
Last active July 18, 2019 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kungfoo/15477ce8d518de94b65aa169736817f9 to your computer and use it in GitHub Desktop.
Save kungfoo/15477ce8d518de94b65aa169736817f9 to your computer and use it in GitHub Desktop.
Rough API for writing pcm data to an opus file using opusenc
/* as an implementation note, we should stick to the same interface between
platforms. An interface we can 'share' should look something like this:
*/
#include "libopusenc/include/opusenc.h"
OggOpusEnc* get_encoder() {
// TODO: get encoder that was previously instantiated.
}
// returns an opus error code, if the encoder fails to initialize
int init(char* file_path, int sample_rate, int channels, int application_type, int bitrate) {
int error = 0;
// needs at least empty comments to work
OggOpusComments *comments = ope_comments_create();
// TODO: somehow remember the memory address/pointer to the encoder for later use...
OggOpusEnc *oggOpusEnc = ope_encoder_create_file(file_path, comments, sample_rate, channels, 0, &error);
ope_encoder_ctl(oggOpusEnc, OPUS_SET_BITRATE(bitrate), OPUS_SET_APPLICATION(application_type));
ope_comments_destroy(comments);
return error;
}
int write_data_to_recorder(byte* pcm_data, int number_of_bytes) {
return ope_encoder_write(get_encoder(), pcm_data, number_of_bytes);
}
int releae() {
OggOpusEnc *oggOpusEnc = get_encoder();
int error = ope_encoder_drain(oggOpusEnc);
if (error) {
return error;
}
ope_encoder_destroy(oggOpusEnc);
return OPE_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment