-
-
Save iddoeldor/ec4c1128677aa58db4f2d7efe8616bf3 to your computer and use it in GitHub Desktop.
This file contains 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 <speex/speex.h> | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <iterator> | |
#include <cassert> | |
int main(int argc, char const *argv[]) | |
{ | |
if (argc < 2) | |
{ | |
std::cerr << "usage: " << argv[0] << " <encoded-file>\n"; | |
return EXIT_FAILURE; | |
} | |
SpeexBits bits; | |
void *dec_state; | |
dec_state = speex_decoder_init(&speex_nb_mode); | |
spx_int32_t enh = 1; | |
speex_decoder_ctl(dec_state, SPEEX_SET_ENH, &enh); | |
spx_int32_t frame_size; | |
speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size); | |
speex_bits_init(&bits); | |
std::ifstream in(argv[1], std::ios::binary); | |
std::vector<char> encoded_data{ | |
std::istream_iterator<char>{in}, std::istream_iterator<char>{} | |
}; | |
speex_bits_read_from(&bits, encoded_data.data(), encoded_data.size()); | |
// From WebRTC: | |
static const int kMaxFrameSize = 2880; // 60 ms @ 48 kHz. | |
std::int16_t raw_data[kMaxFrameSize]; | |
std::size_t raw_data_offset= 0; | |
while (speex_decode_int(dec_state, &bits, raw_data + raw_data_offset) == 0) | |
{ | |
raw_data_offset += frame_size; | |
} | |
assert(raw_data_offset <= sizeof(raw_data)); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment