void close_network_speaker() { // Tell the audio system not to get our data anymore Mixer::instance()->StopNetworkAudio(); // Bleed the queue dry of any leftover data NetworkSpeakerSoundBufferDescriptor* theDesc; while((theDesc = dequeue_network_speaker_data()) != NULL) { if(is_sound_data_disposable(theDesc)) release_network_speaker_buffer(theDesc->mData); } // Free the sound data buffers while(sSoundDataBuffers.getCountOfElements() > 0) { byte* theBuffer = sSoundDataBuffers.peek(); delete [] theBuffer; sSoundDataBuffers.dequeue(); } // Free the noise buffer and restore some values if(sNoiseBufferStorage != NULL) { delete [] sNoiseBufferStorage; sNoiseBufferStorage = NULL; } sDryDequeues = 0; sSpeakerIsOn = false; #ifdef SPEEX destroy_speex_decoder(); #endif }
void queue_network_speaker_data(byte* inData, short inLength) { if(inLength > 0) { if(sSoundDataBuffers.getCountOfElements() > 0) { // Fill out a descriptor for a new chunk of storage NetworkSpeakerSoundBufferDescriptor theBufferDesc; theBufferDesc.mData = sSoundDataBuffers.peek(); sSoundDataBuffers.dequeue(); theBufferDesc.mLength = inLength; theBufferDesc.mFlags = kSoundDataIsDisposable; // and copy the data memcpy(theBufferDesc.mData, inData, inLength); // If we're just turning on, prime the queue with a few buffers of noise. if(!sSpeakerIsOn) { for(int i = 0; i < kNumPumpPrimes; i++) { sSoundBuffers.enqueue(sNoiseBufferDesc); } sSpeakerIsOn = true; } // Enqueue the actual sound data. sSoundBuffers.enqueue(theBufferDesc); } else { fdprintf("No sound data buffer space available - audio discarded"); } } }
void beginflush() { if(writing)return; write_n=sendbuffer.BeginDequeue(); if(write_n==-1) return; writing=true; st.BeginWrite(sendbuffer.GetPointer(write_n), Stream::Callback([this](void* v, Stream* s) { sendbuffer.EndDequeue(write_n); writing=false; beginflush(); })); }
void send(const BufferRef& buf) { if(buf.Length<=0)return; int tmp=sendbuffer.BeginAppend(); if(tmp<0) { WARN(2,"buffer overrun"); return; } Buffer& b=sendbuffer.GetPointer(tmp); b=Buffer(buf.Length); memcpy(b.Data, buf.Data, buf.Length); sendbuffer.EndAppend(tmp); beginflush(); }
OSErr open_network_speaker() { // Allocate storage for noise data - assume if pointer not NULL, already have storage. if(sNoiseBufferStorage == NULL) { assert(kNoiseBufferSize % 2 == 0); uint16* theBuffer = new uint16[kNoiseBufferSize / 2]; // Fill in noise data (use whole width of local_random()) for(int i = 0; i < kNoiseBufferSize / 2; i++) theBuffer[i] = local_random() / 4; sNoiseBufferStorage = (byte*) theBuffer; } // Fill out the noise-buffer descriptor sNoiseBufferDesc.mData = sNoiseBufferStorage; sNoiseBufferDesc.mLength = kNoiseBufferSize; sNoiseBufferDesc.mFlags = 0; // Reset the buffer descriptor queue sSoundBuffers.reset(); // Reset the data buffer queue sSoundDataBuffers.reset(); // Allocate storage for audio data buffers for(int i = 0; i < kNumSoundDataBuffers; i++) { byte* theBuffer = new byte[kSoundDataBufferSize]; sSoundDataBuffers.enqueue(theBuffer); } // Reset a couple others to sane values sDryDequeues = 0; sSpeakerIsOn = false; #ifdef SPEEX init_speex_decoder(); #endif return 0; }
int main() { CircularQueue* qlist = new CircularQueue; qlist->add(5, 2); qlist->display(); qlist->add(5, 2); qlist->display(); *qlist - (2); qlist->display(); return 0; }
// The read-eval-execute loop of the shell. void RunShell(v8::Handle<v8::Context> context) { printf("djondb shell version %s\n", VERSION); printf("Welcome to djondb shell.\n"); printf("Use help(); to get the commands available. \n(hint: The first command should be \"connect\" to playing with a server)\n"); static const int kBufferSize = 256; // Enter the execution environment before evaluating any code. v8::Context::Scope context_scope(context); v8::Local<v8::String> name(v8::String::New("(shell)")); #ifndef WINDOWS char* file = getHistoryFilename(); linenoiseHistoryLoad(file); free(file); linenoiseSetCompletionCallback(completion); #endif std::stringstream ss; bool line = false; const char* lastCmd = ""; while (true) { char buffer[kBufferSize]; char* prompt; if (!line) { prompt = "> "; } else { prompt = ". "; } line = false; std::string str = readLine(prompt); if (str.length() > 0) { //char* str = fgets(buffer, kBufferSize, stdin); if (str[0] == '~') { system("vi .tmp.js"); lastCmd = getFile(".tmp.js"); printf("Buffer loaded.\n"); continue; } else if (str[0] == '.') { if ((lastCmd == NULL) || (strlen(lastCmd) == 0)) { lastCmd = getFile(".tmp.js"); printf("Buffer loaded.\n"); } str = const_cast<char*>(lastCmd); } else if ((str.length() >= 2) && (str[str.length() - 2] == '\\')) { str[str.length() - 2] = ' '; line = true; } ss << str; if (!line) { v8::HandleScope handle_scope; std::string sCmd = ss.str(); const char* cmd = sCmd.c_str(); ss.str(""); lastCmd = cmd; _commands.push_back(std::string(cmd)); if ((startsWith(cmd, "exit") == 0) || (startsWith(cmd, "quit") == 0)) { if (strlen(cmd) < 5) cmd = "quit();"; } ExecuteString(v8::String::New(cmd), name, true, true); } } } printf("\n"); }
iterator& operator ++ () { //posi = (posi+1)&q->m_mask; q->inc(posi); return *this; }
int main( int argc, char *argv[] ) { CircularQueue< int, 4 > q; q.ReplaceBackOfQueueOrPush(1); q.ReplaceBackOfQueueOrPush(2); q.ReplaceBackOfQueueOrPush(3); q.ReplaceBackOfQueueOrPush(4); q.ReplaceBackOfQueueOrPush(5); std::vector< int > prior2 = q.PopNOrLess( 2 ); // 2, 3 std::vector< int > last2 = q.PopNOrLess( 2 ); // 4, 5 q.ReplaceBackOfQueueOrPush(6); q.ReplaceBackOfQueueOrPush(7); q.ReplaceBackOfQueueOrPush(8); q.ReplaceBackOfQueueOrPush(9); q.ReplaceBackOfQueueOrPush(10); q.ReplaceBackOfQueueOrPush(11); q.ReplaceBackOfQueueOrPush(12); std::vector< int > final6 = q.PopNOrLess( 6 ); // Will only get => 9, 10, 11, 12 std::vector< int > none = q.PopNOrLess( 1 ); // There will be nothing in this return 0; }
void release_network_speaker_buffer(byte* inBuffer) { sSoundDataBuffers.enqueue(inBuffer); }
int main() { CircularQueue q; q.enqueue(1); q.enqueue(2); q.enqueue(3); q.enqueue(4); q.enqueue(5); q.display(); q.dequeue(); q.display(); q.enqueue(6); q.display(); q.dequeue(); q.dequeue(); q.dequeue(); q.dequeue(); q.dequeue(); return 0; }
void pushLocalTraceOnto(CircularQueue &queue, const long envId) { givenStackTrace(envId); CHECK(queue.push(trace)); }