本文整理汇总了C++中StreamBuffer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ StreamBuffer::size方法的具体用法?C++ StreamBuffer::size怎么用?C++ StreamBuffer::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamBuffer
的用法示例。
在下文中一共展示了StreamBuffer::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteData
void Stream::WriteData(const StreamBuffer& value)
{
if (streamMode == SmMemory)
{
ExpandMemoryStream(value.size());
std::memcpy(buffer.data() + position, value.data(), value.size());
position += value.size();
}
else
fileStream.write(reinterpret_cast<const char*>(value.data()), value.size());
}
示例2: ReadData
void Stream::ReadData(const StreamBuffer& value)
{
if (streamMode == SmMemory)
{
unsigned int size = std::max(static_cast<int>(value.size()), static_cast<int>(value.size() - buffer.size()));
std::memcpy((void*)value.data(), buffer.data() + position, size);
position += value.size();
}
else
fileStream.read(reinterpret_cast<char*>(const_cast<unsigned char*>(value.data())), value.size());
}
示例3: main
int main(int, char const* const*)
{
try
{
using libember::util::StreamBuffer;
StreamBuffer<unsigned short, 256> testStream;
for (unsigned int i = 0; i < 1000; ++i)
{
{
unsigned short writeBuffer[7];
for (unsigned int j = 0; j < 7; ++j)
{
writeBuffer[j] = static_cast<unsigned short>(i * 7 + j);
}
unsigned short const* const begin = writeBuffer;
unsigned short const* const end = writeBuffer + sizeof(writeBuffer) / sizeof(writeBuffer[0]);
testStream.append(begin, end);
}
for (unsigned int j = 0; j < 5; ++j)
{
unsigned short const current = testStream.front();
testStream.consume();
if (current != (i * 5 + j))
{
THROW_TEST_EXCEPTION("Invalid head of buffer! Expected " << (i * 5 + j) << ", found " << current);
}
}
std::size_t const size = testStream.size();
if (size != 2 * (i + 1))
{
THROW_TEST_EXCEPTION("Invalid size of buffer! Expected " << ((i + 1) * 2) << ", found " << size);
}
}
for (unsigned int i = 0; i < 1000; ++i)
{
for (unsigned int j = 0; j < 2; ++j)
{
unsigned short const current = testStream.front();
testStream.consume();
if (current != (5000 + i * 2 + j))
{
THROW_TEST_EXCEPTION("Invalid head of buffer! Expected " << ((i + 1000) * 5 + j) << ", found " << current);
}
}
}
}
catch (std::exception const& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
return 0;
}
示例4: put_chunk
long ClientWriter::put_chunk(StreamBuffer entity){
PROFILE_ME;
if(entity.empty()){
LOG_POSEIDON_ERROR("You are not allowed to send an empty chunk");
DEBUG_THROW(BasicException, sslit("You are not allowed to send an empty chunk"));
}
StreamBuffer chunk;
char temp[64];
unsigned len = (unsigned)std::sprintf(temp, "%llx\r\n", (unsigned long long)entity.size());
chunk.put(temp, len);
chunk.splice(entity);
chunk.put("\r\n");
return on_encoded_data_avail(STD_MOVE(chunk));
}
示例5: main
int main(int argc, char **argv){
const int freq = 16000;
// declare stream buffer ------------------------------------------------------------
StreamBuffer<float> inBuffer;
StreamBuffer<float> Buffer_H_short;
StreamBuffer<float> Buffer_P_short;
StreamBuffer<float> Buffer_H_long;
StreamBuffer<float> Buffer_P_long;
StreamBuffer<float> Buffer_karaoke;
StreamBuffer<float> outBuffer;
// StreamBuffer<float> Buffer_H_long_tmp;
// Audio IO -------------------------------------------------------------------------
AudioDevice* audio_thread = AudioDevice::getInstance();
audio_thread->init(1, freq, 1024, &inBuffer, &outBuffer);
// HPSS short ------------------------------------------------------------------------
// HPSS_pipe HPSS_short(7, 256, 128, 10, 10);
HPSS_pipe HPSS_short(7, 512, 256, 10, 10);
// HPSS_short.setBuffer(&inBuffer, &Buffer_H_short, &Buffer_P_short);
HPSS_short.setBuffer(&Buffer_P_long, &Buffer_H_short, &Buffer_P_short);
// HPSS long --------------------------------------------------------------------------
// HPSS_pipe HPSS_long(10, 4096, 2048, 10, 10);
// HPSS_pipe_long HPSS_long(7, 4096, 2048, 10, 10);
// HPSS_pipe HPSS_long(7, 2048, 1024, 15, 10);
HPSS_pipe HPSS_long(7, 2048, 1024, 10, 10);
// HPSS_long.setBuffer(&Buffer_H_short, &Buffer_H_long, &Buffer_P_long);
HPSS_long.setBuffer(&inBuffer, &Buffer_H_long, &Buffer_P_long);
// HPSS_long.set_filter_a(400);
// GUI --------------------------------------------------------------------------------
GUI panel(argc, argv);
// Timbre changer ---------------------------------------------------------------------
// too heavy
/*
Filter equalizer_H(256, 128);
equalizer_H.setBuffer(&Buffer_H_long, &Buffer_H_long_tmp);
equalizer_H.set_filter_a(300.);
equalizer_H.set_filter_b(500.);
*/
// Adder ------------------------------------------------------------------------------
StreamAdder adder(2048, &panel); // GUIはパラメータではなくて逆にする。
adder.add_input_stream(&Buffer_P_short); adder.set_multiply(0, 1.0);
adder.add_input_stream(&Buffer_H_long); adder.set_multiply(1, 1.0);
// adder.add_input_stream(&Buffer_P_long); adder.set_multiply(2, 0.0); // control through GUI (todo)
adder.add_input_stream(&Buffer_H_short); adder.set_multiply(2, 0.0); // control through GUI (todo)
adder.set_output_stream(&Buffer_karaoke);
// PitchConversion ---------------------------------------------------------------------
TempoPitch converter;
// converter.init(1024, 128, 1, 7, 10, freq, &panel);//パラメータは?
// converter.init(1024, 128, 1 /* channel */, 7 /* block */, 12 /* coeff */, freq, &panel);//
converter.init(1024 * 2, 128 * 2, 1 /* channel */, 7 /* block */, 15 /* coeff */, freq, &panel);//param? // frame should be very long
// converter.init(1024 * 4, 128 * 4, 1 /* channel */, 7 /* block */, 12 /* coeff */, freq, &panel);//
//coeff 5, 7 change timbre. 12 OK. 40 too large
converter.setBuffer(&Buffer_karaoke, &outBuffer);
// start ---------------------------------------------------------------------------
// equalizer_H.start();
audio_thread->start();
HPSS_short.start();
HPSS_long.start();
adder.start();
converter.start();
panel.start();
// display something every 1[s] -----------------------------------------------------------------
int sec = 0;
while(1){
sec++;
usleep(1000000);
fprintf(stderr, "%3d[ms] %3d[ms] %3d[ms] \t HPSS: short %d[times/s] long %d[times/s] phase %d[times/s] audio trial %d \n",
(int)((double)inBuffer.size() / freq * 1000),
(int)((double)Buffer_karaoke.size() / freq * 1000),
(int)((double)outBuffer.size() / freq * 1000),
HPSS_short.get_exec_count_diff(),
HPSS_long. get_exec_count_diff(),
converter. get_exec_count_diff(),
audio_thread->get_exec_count()
);
fprintf(stderr, "sec: %d min %d sec \t ave: short %d[times/s] long %d[times/s] phase %d[times/s] \n\n",
sec / 60,
sec % 60,
HPSS_short.get_exec_count_ave(),
HPSS_long. get_exec_count_ave(),
converter. get_exec_count_ave()
);
if(panel.getstop()){audio_thread->stop();}
if(panel.getquit()){break;}
//.........这里部分代码省略.........
示例6: put_request
long ClientWriter::put_request(RequestHeaders request_headers, StreamBuffer entity){
PROFILE_ME;
StreamBuffer data;
data.put(get_string_from_verb(request_headers.verb));
data.put(' ');
data.put(request_headers.uri);
if(!request_headers.get_params.empty()){
data.put('?');
data.put(url_encoded_from_optional_map(request_headers.get_params));
}
char temp[64];
const unsigned ver_major = request_headers.version / 10000, ver_minor = request_headers.version % 10000;
unsigned len = (unsigned)std::sprintf(temp, " HTTP/%u.%u\r\n", ver_major, ver_minor);
data.put(temp, len);
AUTO_REF(headers, request_headers.headers);
if(entity.empty()){
headers.erase("Content-Type");
headers.erase("Transfer-Encoding");
if((request_headers.verb == V_POST) || (request_headers.verb == V_PUT)){
headers.set(sslit("Content-Length"), STR_0);
} else {
headers.erase("Content-Length");
}
} else {
if(!headers.has("Content-Type")){
headers.set(sslit("Content-Type"), "application/x-www-form-urlencoded; charset=utf-8");
}
AUTO(transfer_encoding, headers.get("Transfer-Encoding"));
AUTO(pos, transfer_encoding.find(';'));
if(pos != std::string::npos){
transfer_encoding.erase(pos);
}
transfer_encoding = to_lower_case(trim(STD_MOVE(transfer_encoding)));
if(transfer_encoding.empty() || (transfer_encoding == STR_IDENTITY)){
headers.set(sslit("Content-Length"), boost::lexical_cast<std::string>(entity.size()));
} else {
// 只有一个 chunk。
StreamBuffer chunk;
len = (unsigned)std::sprintf(temp, "%llx\r\n", (unsigned long long)entity.size());
chunk.put(temp, len);
chunk.splice(entity);
chunk.put("\r\n0\r\n\r\n");
entity.swap(chunk);
}
}
for(AUTO(it, headers.begin()); it != headers.end(); ++it){
data.put(it->first.get());
data.put(": ");
data.put(it->second);
data.put("\r\n");
}
data.put("\r\n");
data.splice(entity);
return on_encoded_data_avail(STD_MOVE(data));
}