Last active
July 18, 2019 11:28
-
-
Save kungfoo/15477ce8d518de94b65aa169736817f9 to your computer and use it in GitHub Desktop.
Rough API for writing pcm data to an opus file using opusenc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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