Commit mods.

git-svn-id: http://op25.osmocom.org/svn/trunk@172 65a5c917-d112-43f1-993d-58c26a4786be
This commit is contained in:
stevie 2009-09-09 12:24:58 +00:00
parent de3c49233c
commit f6fb14a119
1 changed files with 43 additions and 7 deletions

View File

@ -1,27 +1,63 @@
#include <cstdio>
#include <cstdlib>
#include <software_imbe_decoder.h>
#include <boost/scoped_ptr.hpp>
#include <cstdio>
#include <cstdlib>
using namespace boost;
/**
* Insert bits from an octet buffer into a voice_codeword.
*
* \param in The octet buffer to read from.
* \pram begin The first bit position.
* \param end The last bit position.
* \param out A reference to the voice_codeword to write.
* \return The number of octers written.
*/
size_t
extract(const uint8_t *in, size_t begin, size_t end, voice_codeword& out)
{
size_t nof_bits = 0;
if(begin < end) {
nof_bits = end - begin;
out.resize(nof_bits);
for(size_t i = begin; i < end; ++i) {
out[i - begin] = in[i / 8] & (1 << (7 - (i % 8)));
}
}
return nof_bits;
}
/**
* Convert a file created by offline_imbe_decoder into an audio file.
*/
int
main(int ac, char **av)
{
FILE *out = fopen("audio.pcm", "w");
scoped_ptr<software_imbe_decoder> imbe(new software_imbe_decoder());
while(--ac) {
FILE *fp = fopen(*++av, "r");
if(fp) {
FILE *in = fopen(*++av, "r");
if(in) {
uint8_t buf[18];
while(1 == fread(buf, sizeof(buf), 1, fp)) {
imbe->decode(buf);
while(1 == fread(buf, sizeof(buf), 1, in)) {
voice_codeword cw(144);
extract(buf, 0, 144, cw);
imbe->decode(cw);
audio_samples *audio = imbe->audio();
for(audio_samples::iterator i(audio->begin()); i != audio->end(); ++i) {
float f = *i;
fwrite(&f, sizeof(f), 1, out);
}
audio->clear();
}
fclose(fp);
fclose(in);
} else {
perror(*av);
exit(1);
}
}
fclose(out);
return(0);
}