Last active
December 11, 2015 08:38
-
-
Save mtgrosser/4574227 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
#include <shine/layer3.h> | |
#define SAMPLES_PER_FRAME 1152 | |
typedef struct { | |
shine_config_t shine_config; | |
shine_t shine; | |
int16_t pcm_buffer[65537]; /* 128k of PCM data */ | |
size_t pcm_buffer_length; | |
int16_t working_buffer[2][samp_per_frame]; | |
size_t working_buffer_length; | |
unsigned char mpeg_buffer[32768]; | |
size_t mpeg_buffer_length; | |
} shine_encoder_t; | |
int main(int argc, char **argv) | |
{ | |
shine_encoder_t _encoder; | |
shine_encoder_t *encoder = &_encoder; | |
int16_t working_buffer[2][samp_per_frame]; | |
int i; | |
// shine_config_t shine_config; | |
// shine_t shine; | |
long written; | |
unsigned char *data; | |
unsigned char actual_data[120000]; | |
long encoded_length; | |
unsigned char *encoded_data; | |
L3_set_config_mpeg_defaults(&encoder->shine_config.mpeg); | |
encoder->shine_config.wave.channels = 2; /* encoder->audio_format.channels; */ | |
encoder->shine_config.wave.samplerate = 44100; /* (long)encoder_>audio_format.sample_rate:*/ | |
encoder->shine_config.mpeg.mode = STEREO; | |
/* shine_config.mpeg.bitr = 128; */ | |
/* See if samplerate is valid */ | |
if (L3_find_samplerate_index(encoder->shine_config.wave.samplerate) < 0) printf("%s", "invalid samplerate"); | |
/* See if bitrate is valid */ | |
if (L3_find_bitrate_index(encoder->shine_config.mpeg.bitr) < 0) printf("%s", "invalid bitrate"); | |
encoder->shine = L3_initialise(&encoder->shine_config); | |
if (encoder->shine == NULL) { | |
printf("%s", "init failed\n"); | |
} | |
for (i=0; i < samp_per_frame; i++) { | |
encoder->working_buffer[0][i] = i * 10; | |
encoder->working_buffer[1][i] = i * 8; | |
} | |
for (i=0; i < 200; i++) { | |
encoded_data = L3_encode_frame(encoder->shine, encoder->working_buffer, &encoded_length); | |
if (encoded_data == NULL) { | |
printf("Shine encoder failed %u\n", encoded_length); | |
/* L3_close(shine); | |
return 1; */ | |
} else { | |
printf("encoded length: %u\n", encoded_length); | |
} | |
} | |
L3_close(encoder->shine); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment