int main() { struct ringbuffer * rb = ringbuffer_new(128); test(rb); ringbuffer_delete(rb); return 0; }
static struct ringbuffer * _create_rb(int size) { size = (size + 3) & ~3; if (size < READBLOCKSIZE * 2) { size = READBLOCKSIZE * 2; } struct ringbuffer * rb = ringbuffer_new(size); return rb; }
static bool soundcard_init() { sampleram = malloc(SAMPLETOTAL); if (sampleram == NULL) { log_println(LEVEL_DEBUG, TAG, "sample ram malloc failed"); return false; } audiobuffer = ringbuffer_new(BUFFER); channelregisterbase = utils_nextpow(SAMPLETOTAL); log_println(LEVEL_DEBUG, TAG, "registers start at 0x%08x", channelregisterbase); soundcard_channelbases(channelbases, channelregisterbase); for (int i = 1; i < TOTALCHANNELS; i++) { log_println(LEVEL_INFO, TAG, "Channel %d is at 0x%08x", i - 1, channelbases[i]); } SDL_AudioSpec fmt; fmt.freq = RATE; fmt.format = AUDIO_S16SYS; // BE samples will get converted to the local format fmt.channels = OUTPUTCHANNELS; fmt.samples = 512; fmt.callback = soundcard_sdlcallback; fmt.userdata = audiobuffer; if (SDL_OpenAudio(&fmt, NULL) == 0) { if (!disabled) { SDL_PauseAudio(0); log_println(LEVEL_DEBUG, TAG, "SDL output is now active"); active = true; } } else log_println(LEVEL_INFO, TAG, "Failed to open sound"); return true; }
void benchmark_ringbuffer( void ) { unsigned int loop, thread_count, cpu_count; struct ringbuffer_state *rs; struct ringbuffer_benchmark *rb; thread_state_t *thread_handles; atom_t total_operations_for_full_test_for_all_cpus, total_operations_for_full_test_for_all_cpus_for_one_cpu = 0; double mean_operations_per_second_per_cpu, difference_per_second_per_cpu, total_difference_per_second_per_cpu, std_dev_per_second_per_cpu, scalability; /* TRD : here we benchmark the ringbuffer the benchmark is to have a single ringbuffer where a worker thread busy-works writing and then reading */ cpu_count = abstraction_cpu_count(); thread_handles = (thread_state_t *) malloc( sizeof(thread_state_t) * cpu_count ); rb = (struct ringbuffer_benchmark *) malloc( sizeof(struct ringbuffer_benchmark) * cpu_count ); // TRD : print the benchmark ID and CSV header printf( "\n" "Release %d Ringbuffer Benchmark #1\n" "CPUs,total ops,mean ops/sec per CPU,standard deviation,scalability\n", LIBLFDS_RELEASE_NUMBER ); // TRD : we run CPU count times for scalability for( thread_count = 1 ; thread_count <= cpu_count ; thread_count++ ) { // TRD : initialisation ringbuffer_new( &rs, 1000, NULL, NULL ); for( loop = 0 ; loop < cpu_count ; loop++ ) { (rb+loop)->rs = rs; (rb+loop)->operation_count = 0; } // TRD : main test for( loop = 0 ; loop < thread_count ; loop++ ) abstraction_thread_start( &thread_handles[loop], loop, benchmark_ringbuffer_thread_write_and_read, rb+loop ); for( loop = 0 ; loop < thread_count ; loop++ ) abstraction_thread_wait( thread_handles[loop] ); // TRD : post test math total_operations_for_full_test_for_all_cpus = 0; total_difference_per_second_per_cpu = 0; for( loop = 0 ; loop < thread_count ; loop++ ) total_operations_for_full_test_for_all_cpus += (rb+loop)->operation_count; mean_operations_per_second_per_cpu = ((double) total_operations_for_full_test_for_all_cpus / (double) thread_count) / (double) 10; if( thread_count == 1 ) total_operations_for_full_test_for_all_cpus_for_one_cpu = total_operations_for_full_test_for_all_cpus; for( loop = 0 ; loop < thread_count ; loop++ ) { difference_per_second_per_cpu = ((double) (rb+loop)->operation_count / (double) 10) - mean_operations_per_second_per_cpu; total_difference_per_second_per_cpu += difference_per_second_per_cpu * difference_per_second_per_cpu; } std_dev_per_second_per_cpu = sqrt( (double) total_difference_per_second_per_cpu ); scalability = (double) total_operations_for_full_test_for_all_cpus / (double) (total_operations_for_full_test_for_all_cpus_for_one_cpu * thread_count); printf( "%u,%u,%.0f,%.0f,%0.2f\n", thread_count, (unsigned int) total_operations_for_full_test_for_all_cpus, mean_operations_per_second_per_cpu, std_dev_per_second_per_cpu, scalability ); // TRD : cleanup ringbuffer_delete( rs, NULL, NULL ); } free( rb ); free( thread_handles ); return; }
APULSE_EXPORT pa_stream * pa_stream_new_extended(pa_context *c, const char *name, pa_format_info *const *formats, unsigned int n_formats, pa_proplist *p) { trace_info_f("P %s c=%p, name=%s, formats=%p, n_formats=%u, p=%p\n", __func__, c, name, formats, n_formats, p); // TODO: multiple formats? // take first format if (n_formats < 1) { trace_error("%s, no formats\n", __func__); return NULL; } pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 48000, .channels = 2, }; const char *val; val = pa_proplist_gets(formats[0]->plist, PA_PROP_FORMAT_SAMPLE_FORMAT); if (val) ss.format = pa_sample_format_from_string(val); val = pa_proplist_gets(formats[0]->plist, PA_PROP_FORMAT_RATE); if (val) ss.rate = atoi(val); val = pa_proplist_gets(formats[0]->plist, PA_PROP_FORMAT_CHANNELS); if (val) ss.channels = atoi(val); return pa_stream_new_with_proplist(c, name, &ss, NULL, p); } APULSE_EXPORT pa_stream * pa_stream_new_with_proplist(pa_context *c, const char *name, const pa_sample_spec *ss, const pa_channel_map *map, pa_proplist *p) { trace_info_f("F %s c=%p, name=%s, ss={.format=%d, .rate=%u, .channels=%u}, map=%p, p=%p\n", __func__, c, name, ss->format, ss->rate, ss->channels, map, p); pa_stream *s = calloc(1, sizeof(pa_stream)); s->c = c; s->ref_cnt = 1; s->state = PA_STREAM_UNCONNECTED; s->ss = *ss; s->idx = c->next_stream_idx ++; g_hash_table_insert(c->streams_ht, GINT_TO_POINTER(s->idx), s); // fill initial values of s->timing_info gettimeofday(&s->timing_info.timestamp, NULL); s->timing_info.synchronized_clocks = 1; s->timing_info.sink_usec = 0; s->timing_info.source_usec = 0; s->timing_info.transport_usec = 0; s->timing_info.playing = 1; s->timing_info.write_index_corrupt = 0; s->timing_info.write_index = 0; s->timing_info.read_index_corrupt = 0; s->timing_info.read_index = 0; s->timing_info.configured_sink_usec = 0; s->timing_info.configured_source_usec = 0; s->timing_info.since_underrun = 0; s->rb = ringbuffer_new(72 * 1024); // TODO: figure out size s->peek_buffer = malloc(s->rb->end - s->rb->start); return s; }