int WaylandNativeWindow::setBufferCount(int cnt) { int start = 0; TRACE("cnt:%d", cnt); if (m_bufList.size() == cnt) return NO_ERROR; lock(); if (m_bufList.size() > cnt) { /* Decreasing buffer count, remove from beginning */ std::list<WaylandNativeWindowBuffer*>::iterator it = m_bufList.begin(); for (int i = 0; i <= m_bufList.size() - cnt; i++ ) { destroyBuffer(*it); ++it; m_bufList.pop_front(); } } else { /* Increasing buffer count, start from current size */ for (int i = m_bufList.size(); i < cnt; i++) WaylandNativeWindowBuffer *unused = addBuffer(); } unlock(); return NO_ERROR; }
/** * synthesize is invoked by the Sequencer for rendering a non-sequenced * BaseSynthEvent into a single buffer * * aBufferLength {int} length of the buffer to synthesize */ AudioBuffer* BaseSynthEvent::synthesize( int aBufferLength ) { // in case buffer length is unequal to cached length, create new write buffer if ( aBufferLength != AudioEngineProps::BUFFER_SIZE || _buffer == 0 ) { destroyBuffer(); _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, aBufferLength ); } lock(); // when an event has no fixed length and the decay is short // we deactivate the decay envelope completely (for now) float decay = _synthInstrument->adsr->getDecay(); bool undoDecay = decay < .75; if ( undoDecay ) _synthInstrument->adsr->setDecay( 0 ); _synthInstrument->synthesizer->render( _buffer, this ); if ( undoDecay ) _synthInstrument->adsr->setDecay( decay ); // keep track of the rendered samples, in case of a key up event // we still want to have the sound ring for the minimum period // defined in the constructor instead of cut off immediately if ( _queuedForDeletion && _minLength > 0 ) _minLength -= aBufferLength; if ( _minLength <= 0 ) { _hasMinLength = true; setDeletable( _queuedForDeletion ); // this event is about to be deleted, apply a tiny fadeout if ( _queuedForDeletion ) { int amt = ceil( aBufferLength / 4 ); SAMPLE_TYPE envIncr = MAX_PHASE / amt; SAMPLE_TYPE amp = MAX_PHASE; for ( int i = aBufferLength - amt; i < aBufferLength; ++i ) { for ( int c = 0, nc = _buffer->amountOfChannels; c < nc; ++c ) _buffer->getBufferForChannel( c )[ i ] *= amp; amp -= envIncr; } } } unlock(); return _buffer; }
int duplicateBuffer(GLchar *buffer,int currentSize){ GLchar *expandedBuffer = calloc(currentSize*2,sizeof(GLchar)); if (expandedBuffer){ memcpy(expandedBuffer,buffer,currentSize); destroyBuffer(buffer); buffer = expandedBuffer; return 0; }else{ return -1; } }
void BufferedCellsReader::close() { if (DEBUG) fprintf(stderr, "BufferedCellsReader::close().\n"); if (reader != NULL) { reader->close(); } destroyBuffer(); if (reader != NULL) { reader = NULL; } if (DEBUG) fprintf(stderr, "BufferedCellsReader::close() DONE.\n"); }
void BaseSynthEvent::calculateBuffers() { if ( _locked ) { _updateAfterUnlock = true; return; } int oldLength; if ( isSequenced ) { _cancel = true; oldLength = _sampleLength; _sampleLength = ( int )( length * ( float ) AudioEngine::bytes_per_tick ); _sampleStart = position * AudioEngine::bytes_per_tick; _sampleEnd = _sampleStart + _sampleLength; } else { // quick releases of a noteOn-instruction should ring for at least a 64th note _minLength = AudioEngine::bytes_per_bar / 64; _sampleLength = AudioEngine::bytes_per_bar; // important for amplitude swell in oldLength = AudioEngineProps::BUFFER_SIZE; // buffer is as long as the engine's buffer size _hasMinLength = false; // keeping track if the min length has been rendered } _adsr->setBufferLength( _sampleLength ); // sample length changed (f.i. tempo change) or buffer not yet created ? // create buffer for (new) sample length if ( _sampleLength != oldLength || _buffer == 0 ) { // note that when event caching is enabled, the buffer is as large as // the total event length requires if ( AudioEngineProps::EVENT_CACHING && isSequenced ) { destroyBuffer(); // clear previous buffer contents _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, _sampleLength ); } else _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, AudioEngineProps::BUFFER_SIZE ); } if ( AudioEngineProps::EVENT_CACHING && isSequenced ) { resetCache(); // yes here, not in cache()-invocation as cancels might otherwise remain permanent (see BulkCacher) if ( _autoCache && !_caching ) // re-cache cache( false ); } }
void WaylandNativeWindow::destroyBuffers() { TRACE(""); std::list<WaylandNativeWindowBuffer*>::iterator it = m_bufList.begin(); for (; it!=m_bufList.end(); ++it) { destroyBuffer(*it); } m_bufList.clear(); m_freeBufs = 0; }
Buffer* Group::createBuffer(const std::string& ID,const BufferCreator& creator,unsigned int flag,bool swapEnabled) const { destroyBuffer(ID); Buffer* buffer = creator.createBuffer(pool.getNbReserved(),*this); buffer->flag = flag; buffer->swapEnabled = swapEnabled; additionalBuffers.insert(std::pair<std::string,Buffer*>(ID,buffer)); if (swapEnabled) swappableBuffers.insert(buffer); return buffer; }
Buffer* Group::createBuffer(uint32 ID, const BufferCreator& creator, uint32 flag, bool swapEnabled) const { destroyBuffer(ID); Buffer* buffer = creator.createBuffer(pool.getSizeOfReserved(), *this); buffer->flag = flag; buffer->swapEnabled = swapEnabled; additionalBuffers.set(ID, buffer); if( swapEnabled ) swappableBuffers.add(buffer); return buffer; }
/** * synthesize is invoked by the Sequencer for rendering a non-sequenced * BaseSynthEvent into a single buffer * * aBufferLength {int} length of the buffer to synthesize */ AudioBuffer* BaseSynthEvent::synthesize( int aBufferLength ) { // in case buffer length is unequal to cached length, create new write buffer if ( aBufferLength != AudioEngineProps::BUFFER_SIZE || _buffer == 0 ) { destroyBuffer(); _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, aBufferLength ); } render( _buffer ); // synthesize, also overwrites old buffer contents // keep track of the rendered bytes, in case of a key up event // we still want to have the sound ring for the minimum period // defined in the constructor instead of cut off immediately if ( _queuedForDeletion && _minLength > 0 ) _minLength -= aBufferLength; if ( _minLength <= 0 ) { _hasMinLength = true; setDeletable( _queuedForDeletion ); // this event is about to be deleted, apply a tiny fadeout if ( _queuedForDeletion ) { int amt = ceil( aBufferLength / 4 ); SAMPLE_TYPE envIncr = MAX_PHASE / amt; SAMPLE_TYPE amp = MAX_PHASE; for ( int i = aBufferLength - amt; i < aBufferLength; ++i ) { for ( int c = 0, nc = _buffer->amountOfChannels; c < nc; ++c ) _buffer->getBufferForChannel( c )[ i ] *= amp; amp -= envIncr; } } } return _buffer; }
int main(int argc, char *argv[]) { int bufferSize = DEFAULT_BUFFER_SIZE; if (argc > 1) { bufferSize = atoi(argv[1]); } // Ringpuffer erstellen ringbuffer *buffer = createBuffer(bufferSize); // Testen von Schreiben und Lesen for (int i = 1; i <= 45; i++) { printf("putting %d\n", i); put(buffer, i); if (i % 3 == 0) { printf("got %d\n", get(buffer)); } } // Ringpuffer wieder entfernen destroyBuffer(buffer); return EXIT_SUCCESS; }
int main () { int num = -1234567890; printf("number: %d\n", num); printf("string: %s\n", itos(num)); double real = -25.93333333; printf("number: %f\n", real); printf("string: %s\n", dtos(real)); double zero = 0.0; printf("number: %f\n", zero); printf("string: %s\n", dtos(zero)); OutputBuffer *buf = createBuffer(); append(buf, "number: "); appendi(buf, num); append(buf, "\nfloat: "); appendd(buf, real); append(buf, "\nzero: "); appendd(buf, zero); append(buf, "\n"); printf("buffer:\n\n%s\n", readBuffer(buf, 0)); destroyBuffer(buf); }
void GLES2HardwareIndexBuffer::notifyOnContextLost() { destroyBuffer(); }
GLES2HardwareIndexBuffer::~GLES2HardwareIndexBuffer() { destroyBuffer(); }
void *ioProcessing(void *envByRef, void *apPtr){ // Key variables for DSP void * status = DSP_THREAD_SUCCESS; audio_params *ap = apPtr; // Gets the audio parameters dsp_thread_env *envPtr = envByRef; // Gets the dsp thread environment int err; // for capturing errors int errcnt =0; // for capturing errors int *filter_on = malloc(sizeof(int)); double * volume = malloc(sizeof(double)); int * cnote = malloc(sizeof(int)); short * avgpwr = malloc(sizeof(short)); int i; buffer *xnL = malloc(sizeof(buffer)); // Define circular buffers and allocate memory left channel xn buffer *xnR = malloc(sizeof(buffer)); // Define circular buffers and allocate memory right channel xn buffer *ynL = malloc(sizeof(buffer)); // Define circular buffers and allocate memory left channel yn buffer *ynR = malloc(sizeof(buffer)); // Define circular buffers and allocate memory right channel yn initBuffer(xnL); // Initialize circular buffer initBuffer(xnR); // Initialize circular buffer initBuffer(ynL); // Initialize circular buffer initBuffer(ynR); // Initialize circular buffer *filter_on = (*envPtr).filter_on; *volume = (*envPtr).volume; *cnote = (*envPtr).cnote; *avgpwr = (*envPtr).avgpwr; memset((*ap).outputBuffer, 0, (*ap).blksize); // Clear the output buffer DBG( "Starting IO Processing...\n" ); // Process a block just to start the DSP and skip the first frame dspBlockProcess((short *)(*ap).outputBuffer, (short *)(*ap).outputBuffer, xnL, xnR, (*ap).blksize/2, filter_on, volume, cnote, avgpwr); DBG( "Entering dspThread processing loop...\n" ); // Read capture buffer from ALSA input device (just to get things going) while( snd_pcm_readi((*ap).pcm_capture_handle, (*ap).inputBuffer, (*ap).exact_bufsize) < 0 ){ snd_pcm_prepare((*ap).pcm_capture_handle); ERR( "<<<<<<<<<<<<<<< Buffer Prime Overrun >>>>>>>>>>>>>>>\n"); ERR( "Error reading the data from file descriptor %d\n", (int) (*ap).pcm_capture_handle ); } memset((*ap).outputBuffer, 0, (*ap).blksize); // Clear the output buffer // Write output buffer into ALSA output device (just to get things going) for(i=0; i<2; i++) { while ((err = snd_pcm_writei((*ap).pcm_output_handle, (*ap).outputBuffer, (*ap).exact_bufsize)) < 0){ snd_pcm_prepare((*ap).pcm_output_handle); ERR( "<<<Pre Buffer Underrun >>> err=%d, errcnt=%d\n", err, errcnt); } } // begin DSP main loop while( !(*envPtr).quit ) { // check dynamic DSP parameters *filter_on = (*envPtr).filter_on; *volume = (*envPtr).volume; *cnote = (*envPtr).cnote; *avgpwr = (*envPtr).avgpwr; // Read capture buffer from ALSA input device while( snd_pcm_readi((*ap).pcm_capture_handle, (*ap).inputBuffer, (*ap).exact_bufsize) < 0 ){ snd_pcm_prepare((*ap).pcm_capture_handle); ERR( "<<<<<<<<<<<<<<< Buffer Prime Overrun >>>>>>>>>>>>>>>\n"); ERR( "Error reading the data from file descriptor %d\n", (int) (*ap).pcm_capture_handle ); } // Audio process // passing the data as short since we are processing 16-bit audio. dspBlockProcess((short *)(*ap).outputBuffer, (short *)(*ap).inputBuffer, xnL, xnR, (*ap).blksize/2, filter_on, volume, cnote, avgpwr); //(*envPtr).cnote = *cnote; (*envPtr).avgpwr = *avgpwr; // Write output buffer into ALSA output device errcnt = 0; // The Beagle gets an underrun error the first time it trys to write, // so ignore the first error and it appears to work fine. while ((err = snd_pcm_writei((*ap).pcm_output_handle, (*ap).outputBuffer, (*ap).exact_bufsize)) < 0) { snd_pcm_prepare((*ap).pcm_output_handle); //ERR( "<<<<<<<<<<<<<<< Buffer Underrun >>>>>>>>>>>>>>> err=%d, errcnt=%d\n", err, errcnt); memset((*ap).outputBuffer, 0, (*ap).blksize); // Clear the buffer snd_pcm_writei((*ap).pcm_output_handle, (*ap).outputBuffer, (*ap).exact_bufsize); } } // Free up resources destroyBuffer(xnL); free(xnL); destroyBuffer(xnR); free(xnR); destroyBuffer(ynL); free(ynL); destroyBuffer(ynR); free(ynR); free(filter_on); free(volume); free(cnote); free(avgpwr); DBG( "Exited IO Processing loop\n" ); return status; }
GLES2HardwareVertexBuffer::~GLES2HardwareVertexBuffer() { destroyBuffer(); }
void SynthEvent::calculateBuffers() { if ( _locked ) { _updateAfterUnlock = true; return; } int oldLength; if ( isSequenced ) { if ( _caching ) _cancel = true; oldLength = _sampleLength; _sampleLength = ( int )( length * ( float ) AudioEngine::bytes_per_tick ); _sampleStart = position * AudioEngine::bytes_per_tick; _sampleEnd = _sampleStart + _sampleLength; } else { // quick releases of the key should at least ring for a 32nd note _minLength = AudioEngine::bytes_per_bar / 32; _sampleLength = AudioEngine::bytes_per_bar; // important for amplitude swell in oldLength = AudioEngineProps::BUFFER_SIZE; // buffer is as long as the engine's buffer size _hasMinLength = false; // keeping track if the min length has been rendered } _adsr->setBufferLength( _sampleLength ); // sample length changed (f.i. tempo change) or buffer not yet created ? // create buffer for (new) sample length if ( _sampleLength != oldLength || _buffer == 0 ) { destroyBuffer(); // clear previous buffer contents // OSC2 generates no buffer (writes into parent buffer, saves memory) if ( !hasParent ) { // note that when event caching is enabled, the buffer is as large as // the total event length requires if ( AudioEngineProps::EVENT_CACHING && isSequenced ) _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, _sampleLength ); else _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, AudioEngineProps::BUFFER_SIZE ); } } if ( isSequenced ) { if ( _type == WaveForms::KARPLUS_STRONG ) initKarplusStrong(); if ( AudioEngineProps::EVENT_CACHING ) { resetCache(); // yes here, not in cache()-invocation as cancels might otherwise remain permanent (see BulkCacher) // (re)cache (unless this event is OSC2 as only the parent event can invoke the render) if ( _autoCache && !hasParent ) { if ( !_caching ) cache( false ); else _cancel = true; } } } }
void SynthEvent::calculateBuffers() { // we override the entire function body as we need some // oscillator 2-specific operations in here if ( _locked ) { _updateAfterUnlock = true; return; } int oldLength; if ( isSequenced ) { _cancel = true; oldLength = _sampleLength; _sampleLength = ( int )( length * ( float ) AudioEngine::bytes_per_tick ); _sampleStart = position * AudioEngine::bytes_per_tick; _sampleEnd = _sampleStart + _sampleLength; } else { // quick releases of a noteOn-instruction should ring for at least a 64th note _minLength = AudioEngine::bytes_per_bar / 64; _sampleLength = AudioEngine::bytes_per_bar; // important for amplitude swell in oldLength = AudioEngineProps::BUFFER_SIZE; // buffer is as long as the engine's buffer size _hasMinLength = false; // keeping track if the min length has been rendered } _adsr->setBufferLength( _sampleLength ); // sample length changed (f.i. tempo change) or buffer not yet created ? create buffer for (new) length if ( _sampleLength != oldLength ) { if ( !hasParent ) // OSC2 generates no buffer (writes into parent buffer, saves memory) { // note that when event caching is enabled, the buffer is as large as // the total event length requires if ( AudioEngineProps::EVENT_CACHING && isSequenced ) { destroyBuffer(); // clear previous buffer contents _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, _sampleLength ); } else _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, AudioEngineProps::BUFFER_SIZE ); // though this event manages its child oscillator, the render method needs these properties if ( _osc2 != 0 ) { _osc2->_sampleLength = _sampleLength; _osc2->_sampleStart = _sampleStart; _osc2->_sampleEnd = _sampleEnd; } } } if ( isSequenced ) { if ( _type == WaveForms::KARPLUS_STRONG ) initKarplusStrong(); if ( AudioEngineProps::EVENT_CACHING ) { resetCache(); // yes here, not in cache()-invocation as cancels might otherwise remain permanent (see BulkCacher) if ( _autoCache && !_caching ) // re-cache cache( false ); } } }
BaseAudioEvent::~BaseAudioEvent() { removeFromSequencer(); destroyBuffer(); }
void BaseAudioEvent::setBuffer( AudioBuffer* buffer, bool destroyable ) { _destroyableBuffer = destroyable; destroyBuffer(); // clears existing buffer (if destroyable) _buffer = buffer; }
int main(int argc,char* argv[]) { pathToDir=argv[1]; keyword=argv[2]; line_no=atoi(argv[3]); buffSize=atoi(argv[4]); int i; newBuffer(); int path_len=strlen(pathToDir); if(pathToDir[path_len-1]!='/') { char* newpath=malloc(sizeof(char)*(path_len+1)); strcpy(newpath,pathToDir); strcat(newpath,"/"); pathToDir=newpath; } if (pthread_mutex_init(&buffer_lock, NULL) != 0) { printf("Lock init failed, line number: %d",line_no); return; } if (pthread_mutex_init(&bufferFront_lock, NULL) != 0) { printf("Lock init failed, line number: %d",line_no); return; } if (pthread_mutex_init(&bufferEnd_lock, NULL) != 0) { printf("Lock init failed, line number: %d",line_no); return; } struct dirent *de=NULL; DIR *d=NULL; d=opendir(pathToDir); if(d == NULL) { printf("Couldn't open directory, line number: %d",line_no); return; } int thread_count=0; char a; pthread_t tid; pthread_attr_t attr; pthread_attr_init(&attr); pthread_t worker_tid; // Loop while not NULL while(de = readdir(d)) { if(de->d_name[0]=='.') continue; else { char* filename=(char*)malloc(sizeof(char)*MAXLINESIZE); strcpy(filename,de->d_name); char c; pthread_mutex_lock(&running_mutex); running_threads++; pthread_mutex_unlock(&running_mutex); pthread_create(&worker_tid,&attr,worker,filename); } } pthread_create(&tid,&attr,printer,NULL); while (running_threads > 0) { } pthread_join(tid,NULL); destroyBuffer(); closedir(d); pthread_mutex_destroy(&buffer_lock); pthread_mutex_destroy(&bufferFront_lock); pthread_mutex_destroy(&bufferEnd_lock); }
// Example on how to use the library int main(void) { unsigned int width = 1024; unsigned int height = 768; unsigned int pages = 7; unsigned int pixel_type = CTIFF_PIXEL_UINT16; int pixel_bit_depth = ((pixel_type >> 4) + 0x01) << 3; void* buffer; unsigned int k; int retval = 0; const void *buf; char *output_path = "output.tif"; char *artist = "Artist"; char *copyright = "Copyright"; char *make = "Camera Manufacturer"; char *model = "Camera Model"; char *software = "Software"; char *image_desc = "Created through include statements."; char *meta_ptr; char metadata[][80] = {"{\"key with spaces\": \r\n\t \"data with spaces 1\"}", "{\"numeric_data\": 1337 }", "{\"boolean data\": true}", "{\"array data\": [ [ 1, 2, 3], [4, 5, 6], [7, 8, 9]]}", "{ \"bad json\" 42}", ""}; TRYFUNC(calculateImageArrays(width, height, pages, pixel_bit_depth, &buffer), "Could not calclate buffer.") DEBUGP("Calculated buffer.") CTIFF ctiff = CTIFFNew(output_path); CTIFFWriteEvery(ctiff, 1); CTIFFSetStyle(ctiff, width, height, pixel_type, false); CTIFFSetRes(ctiff, 72, 72); // Not needed, defaults to strict = true CTIFFSetStrict(ctiff,true); CTIFFSetBasicMeta(ctiff, artist, copyright, make, model, software, image_desc); for (k = 0; k < pages; k++){ buf = moveArrayPtr(buffer, k*width*height, pixel_bit_depth); meta_ptr = (k == 0) ? NULL : metadata[k-1]; if ((retval = CTIFFAddNewPage(ctiff, buf, "meta", meta_ptr)) != 0){ printf("Could not add image\n"); CTIFFClose(ctiff); return retval; } // This will return an error because at least one of the pages has already // been written to disk. /* * if (CTIFFSetStrict(ctiff,false) != 0) { * printf("Could not change the strictness of the CTIFF.\n"); * } */ } retval = CTIFFWrite(ctiff); CTIFFClose(ctiff); DEBUGP("Wrote TIFF.") destroyBuffer(buffer); return retval; }
int WaylandNativeWindow::dequeueBuffer(BaseNativeWindowBuffer **buffer, int *fenceFd){ HYBRIS_TRACE_BEGIN("wayland-platform", "dequeueBuffer", ""); WaylandNativeWindowBuffer *wnb=NULL; TRACE("%p", buffer); lock(); HYBRIS_TRACE_BEGIN("wayland-platform", "dequeueBuffer_wait_for_buffer", ""); HYBRIS_TRACE_COUNTER("wayland-platform", "m_freeBufs", "%i", m_freeBufs); while (m_freeBufs==0) { HYBRIS_TRACE_COUNTER("wayland-platform", "m_freeBufs", "%i", m_freeBufs); pthread_cond_wait(&cond,&mutex); } std::list<WaylandNativeWindowBuffer *>::iterator it = m_bufList.begin(); for (; it != m_bufList.end(); it++) { if ((*it)->busy) continue; if ((*it)->youngest == 1) continue; break; } if (it==m_bufList.end()) { HYBRIS_TRACE_BEGIN("wayland-platform", "dequeueBuffer_worst_case_scenario", ""); HYBRIS_TRACE_END("wayland-platform", "dequeueBuffer_worst_case_scenario", ""); it = m_bufList.begin(); for (; it != m_bufList.end() && (*it)->busy; it++) {} } if (it==m_bufList.end()) { unlock(); HYBRIS_TRACE_BEGIN("wayland-platform", "dequeueBuffer_no_free_buffers", ""); HYBRIS_TRACE_END("wayland-platform", "dequeueBuffer_no_free_buffers", ""); TRACE("%p: no free buffers", buffer); return NO_ERROR; } wnb = *it; assert(wnb!=NULL); HYBRIS_TRACE_END("wayland-platform", "dequeueBuffer_wait_for_buffer", ""); /* If the buffer doesn't match the window anymore, re-allocate */ if (wnb->width != m_window->width || wnb->height != m_window->height || wnb->format != m_format || wnb->usage != m_usage) { TRACE("wnb:%p,win:%p %i,%i %i,%i x%x,x%x x%x,x%x", wnb,m_window, wnb->width,m_window->width, wnb->height,m_window->height, wnb->format,m_format, wnb->usage,m_usage); destroyBuffer(wnb); m_bufList.erase(it); wnb = addBuffer(); } wnb->busy = 1; *buffer = wnb; --m_freeBufs; HYBRIS_TRACE_COUNTER("wayland-platform", "m_freeBufs", "%i", m_freeBufs); HYBRIS_TRACE_BEGIN("wayland-platform", "dequeueBuffer_gotBuffer", "-%p", wnb); HYBRIS_TRACE_END("wayland-platform", "dequeueBuffer_gotBuffer", "-%p", wnb); HYBRIS_TRACE_END("wayland-platform", "dequeueBuffer_wait_for_buffer", ""); unlock(); return NO_ERROR; }