_Bool audio_frame(int16_t *buffer) { //HRESULT hr; UINT32 numFramesAvailable; UINT32 packetLength = 0; BYTE *pData; DWORD flags; pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); //hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); //EXIT_ON_ERROR(hr) while (packetLength != 0) { // Get the available data in the shared buffer. pCaptureClient->lpVtbl->GetBuffer(pCaptureClient, &pData, &numFramesAvailable, &flags, NULL, NULL); //hr = pCaptureClient->lpVtbl->GetBuffer(pCaptureClient, &pData, &numFramesAvailable, &flags, NULL, NULL); //EXIT_ON_ERROR(hr) if (flags & AUDCLNT_BUFFERFLAGS_SILENT) { pData = NULL; // Tell CopyData to write silence. } if(numFramesAvailable != 480) { printf("ERROR\n"); } static _Bool frame = 1; convertsamples(&buffer[frame ? 0 : 480], (void*)pData, 480); frame = !frame; // Copy the available capture data to the audio sink. //printf("%u\n", numFramesAvailable); //hr = pMySink->CopyData(pData, numFramesAvailable, &bDone); //EXIT_ON_ERROR(hr) pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable); //hr = pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable); //EXIT_ON_ERROR(hr) if(frame) { return 1; } pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); //hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); //EXIT_ON_ERROR(hr) } return 0; }
int main (int argc, char **argv) { MSRecord *msr = 0; MSTraceGroup *mstg = 0; MSTrace *mst; int retcode; int64_t packedsamples; int64_t packedrecords; int lastrecord; int iseqnum = 1; #ifndef WIN32 /* Signal handling, use POSIX calls with standardized semantics */ struct sigaction sa; sa.sa_flags = SA_RESTART; sigemptyset (&sa.sa_mask); sa.sa_handler = term_handler; sigaction (SIGINT, &sa, NULL); sigaction (SIGQUIT, &sa, NULL); sigaction (SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); #endif /* Process given parameters (command line and parameter file) */ if (parameter_proc (argc, argv) < 0) return -1; /* Setup input encoding format if specified */ if ( encodingstr ) { int inputencoding = strtoul (encodingstr, NULL, 10); if ( inputencoding == 0 && errno == EINVAL ) { ms_log (2, "Error parsing input encoding format: %s\n", encodingstr); return -1; } MS_UNPACKENCODINGFORMAT (inputencoding); } /* Init MSTraceGroup */ mstg = mst_initgroup (mstg); /* Loop over the input file */ while ( (retcode = ms_readmsr (&msr, inputfile, reclen, NULL, &lastrecord, 1, 1, verbose)) == MS_NOERROR ) { msr_print (msr, ppackets); /* Convert sample type as needed for packencoding */ if ( packencoding >= 0 && packencoding != msr->encoding ) { if ( convertsamples (msr, packencoding) ) { ms_log (2, "Error converting samples for encoding %d\n", packencoding); break; } } if ( packreclen >= 0 ) msr->reclen = packreclen; else packreclen = msr->reclen; if ( packencoding >= 0 ) msr->encoding = packencoding; else packencoding = msr->encoding; if ( byteorder >= 0 ) msr->byteorder = byteorder; else byteorder = msr->byteorder; /* After unpacking the record, the start time in msr->starttime is a potentially corrected start time, if correction has been applied make sure the correction bit flag is set as it will be used as a packing template. */ if ( msr->fsdh->time_correct && ! (msr->fsdh->act_flags & 0x02) ) { ms_log (1, "Setting time correction applied flag for %s_%s_%s_%s\n", msr->network, msr->station, msr->location, msr->channel); msr->fsdh->act_flags |= 0x02; } /* Replace network code */ if ( netcode ) strncpy (msr->network, netcode, sizeof(msr->network)); /* If no samples in the record just pack the header */ if ( outfile && msr->numsamples == 0 ) { msr_pack_header (msr, 1, verbose); record_handler (msr->record, msr->reclen, NULL); } /* Pack each record individually */ else if ( outfile && ! tracepack ) { msr->sequence_number = iseqnum; packedrecords = msr_pack (msr, &record_handler, NULL, &packedsamples, 1, verbose); if ( packedrecords == -1 ) ms_log (2, "Cannot pack records\n"); else ms_log (1, "Packed %d records\n", packedrecords); iseqnum = msr->sequence_number; } /* Pack records from a MSTraceGroup */ else if ( outfile && tracepack ) { mst = mst_addmsrtogroup (mstg, msr, 0, -1.0, -1.0); if ( ! mst ) { ms_log (2, "Error adding MSRecord to MStrace!\n"); break; } /* Reset sequence number and free previous template */ if ( mst->prvtptr ) { MSRecord *tmsr = (MSRecord *) mst->prvtptr; /* Retain sequence number from previous template */ msr->sequence_number = tmsr->sequence_number; msr_free (&tmsr); } else { msr->sequence_number = 1; } /* Copy MSRecord and store as template */ mst->prvtptr = msr_duplicate (msr, 0); if ( ! mst->prvtptr ) { ms_log (2, "Error duplicating MSRecord for template!\n"); break; } /* Pack traces based on selected method */ packedrecords = 0; if ( tracepack == 1 ) { mst = mstg->traces; while ( mst ) { packedrecords += mst_pack (mst, &record_handler, NULL, packreclen, packencoding, byteorder, &packedsamples, 0, verbose, (MSRecord *)mst->prvtptr); mst = mst->next; } ms_log (1, "Packed %d records\n", packedrecords); } if ( tracepack == 2 && lastrecord ) { mst = mstg->traces; while ( mst ) { packedrecords += mst_pack (mst, &record_handler, NULL, packreclen, packencoding, byteorder, &packedsamples, 1, verbose, (MSRecord *)mst->prvtptr); mst = mst->next; } ms_log (1, "Packed %d records\n", packedrecords); } } } /* Make sure buffer of input data is flushed */ packedrecords = 0; if ( tracepack ) { mst = mstg->traces; while ( mst ) { packedrecords += mst_pack (mst, &record_handler, NULL, packreclen, packencoding, byteorder, &packedsamples, 1, verbose, (MSRecord *)mst->prvtptr); mst = mst->next; } if ( packedrecords ) ms_log (1, "Packed %d records\n", packedrecords); } if ( retcode != MS_ENDOFFILE ) ms_log (2, "Error reading %s: %s\n", inputfile, ms_errorstr(retcode)); /* Make sure everything is cleaned up */ ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0, 0); mst_freegroup (&mstg); if ( outfile ) fclose (outfile); return 0; } /* End of main() */