1 #include "output-drv.hpp"
9 std::string
expand_options(const std::string
& opts
)
12 std::ostringstream ret
;
13 for(size_t i
= 0; i
< opts
.length(); i
++) {
32 class output_driver_faac
: public output_driver
35 output_driver_faac(const std::string
& _filename
, const std::string
& _options
)
39 set_audio_callback
<output_driver_faac
>(*this, &output_driver_faac::audio_callback
);
49 const audio_settings
& a
= get_audio_settings();
51 std::stringstream commandline
;
52 commandline
<< "faac -P -C 2 -R " << a
.get_rate() << " ";
53 commandline
<< expand_options(options
);
54 commandline
<< "-o " << filename
<< " -";
55 std::string s
= commandline
.str();
56 out
= popen(s
.c_str(), "w");
58 std::stringstream str
;
59 str
<< "Can't run faac (" << s
<< ")";
60 throw std::runtime_error(str
.str());
64 void audio_callback(short left
, short right
)
67 rawdata
[1] = ((unsigned short)left
>> 8) & 0xFF;
68 rawdata
[0] = ((unsigned short)left
) & 0xFF;
69 rawdata
[3] = ((unsigned short)right
>> 8) & 0xFF;
70 rawdata
[2] = ((unsigned short)right
) & 0xFF;
71 if(fwrite(rawdata
, 1, 4, out
) < 4)
72 throw std::runtime_error("Error writing sample to faac");
80 class output_driver_faac_factory
: output_driver_factory
83 output_driver_faac_factory()
84 : output_driver_factory("faac")
88 output_driver
& make(const std::string
& type
, const std::string
& name
, const std::string
& parameters
)
90 return *new output_driver_faac(name
, parameters
);