Skip to content

Commit 782bc2f

Browse files
committed
Progress, slow and steady
1 parent e1ef8d4 commit 782bc2f

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

audio.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void print_level_meter( const float * buffer, const int num_samples, const int n
4949

5050
// Next, output the level of each channel:
5151
int max_space = 60;
52-
printf(" \r");
52+
printf("\r \r");
5353
int level_divisions = max_space/num_channels;
5454

5555
printf("[");
@@ -85,7 +85,7 @@ void print_level_meter( const float * buffer, const int num_samples, const int n
8585
for( int k=0; k<num_channels-1; ++k ) {
8686
printf("%.3f, ", levels[k]);
8787
}
88-
printf("%.3f\r", levels[num_channels-1]);
88+
printf("%.3f", levels[num_channels-1]);
8989
fflush(stdout);
9090
}
9191

@@ -100,10 +100,6 @@ static int pa_callback( const void *inputBuffer, void *outputBuffer, unsigned lo
100100
// If we've got input data, send it out!
101101
if( inputBuffer != NULL ) {
102102
zmq_send(device->raw_audio_in, inputBuffer, framesPerBuffer*device->num_channels*sizeof(float), 0);
103-
104-
if( opts.meter ) {
105-
print_level_meter( (const float *)inputBuffer, framesPerBuffer, device->num_channels);
106-
}
107103
}
108104

109105
if( outputBuffer != NULL ) {
@@ -347,6 +343,17 @@ void * audio_thread(void * device_ptr) {
347343
// Send it the pre-mixed buffer of audio
348344
zmq_send(device->mixed_audio_out, mix_buff, sizeof(float)*mix_buff_len, 0);
349345

346+
int maxsize = 0;
347+
for( auto &kv : clientMixedInAlready ) {
348+
maxsize = fmax(clientChunks[kv.first].size(), maxsize);
349+
}
350+
351+
if( opts.meter ) {
352+
print_level_meter( (const float *)mix_buff, SAMPLES_IN_BUFFER, device->num_channels);
353+
printf(" (%d)", maxsize);
354+
fflush(stdout);
355+
}
356+
350357
if( device->output_log != NULL )
351358
device->output_log->writeData((const float *)mix_buff, SAMPLES_IN_BUFFER);
352359

@@ -358,7 +365,7 @@ void * audio_thread(void * device_ptr) {
358365
if( clientChunks[kv.first].size() > 0 ) {
359366
// Grab the first chunk of audio waiting for me;
360367
float * chunk = clientChunks[kv.first][0];
361-
clientChunks.erase(clientChunks.begin());
368+
clientChunks[kv.first].erase(clientChunks[kv.first].begin());
362369

363370
// Mix it in, and delete the chunk!
364371
for( int i=0; i<device->num_channels*SAMPLES_IN_BUFFER; ++i )
@@ -456,14 +463,13 @@ void * audio_thread(void * device_ptr) {
456463
int dec_len = zmq_msg_size(&msg);
457464
int num_samples = dec_len/(sizeof(float)*device->num_channels);
458465

459-
//printf("[0x%x] Got %d samples of %d channels from device!\n", device, num_samples, device->num_channels);
460-
//print_peak_level((const float *)zmq_msg_data(&msg), num_samples, device->num_channels);
466+
if( opts.meter )
467+
print_level_meter( (const float *)zmq_msg_data(&msg), num_samples, device->num_channels);
461468

462469
if( input_log != NULL )
463470
input_log->writeData((const float *)zmq_msg_data(&msg), num_samples);
464471

465472
// Encode it:
466-
//printf("msg size: %d, num_channels: %d\n", zmq_msg_size(&msg), device->num_channels);
467473
int enc_len = opus_encode_float(device->encoder, (const float *)zmq_msg_data(&msg), num_samples, encoded_data, MAX_DATA_PACKET_LEN );
468474
if( enc_len < 0 ) {
469475
fprintf(stderr, "opus_encode_float() error: %d\n", enc_len);

0 commit comments

Comments
 (0)