void sense(int aud_fd, struct spsv_commobj* sc) { short mic_buf[WINDOW_SIZE]; /* mic output */ double* sound; /* fft input */ double* freq; /* fft output */ fftw_plan p; /* fftw data to turn sound into freq */ FILE* file; /* fft input */ sound = (double*) fftw_malloc( sizeof(double) * WINDOW_SIZE); /* fft output */ freq = (double*) fftw_malloc( sizeof(double) * WINDOW_SIZE); p = fftw_plan_r2r_1d(WINDOW_SIZE, sound, freq, FFTW_R2HC, FFTW_FORWARD); printf("Set up, about to process sound\n"); char erg[256]; sprintf(erg, "data.dat"); file = fopen(erg, "w"); fill_buf(aud_fd, mic_buf, WINDOW_SIZE); printf("About to loop.\n"); int cycle = 0; while(1) { do_window(mic_buf, sound); /* convert input to doubles and * window it */ fftw_execute(p); send_data(sc, WINDOW_SIZE/2-1, freq); advance_buf(mic_buf, WINDOW_SIZE >> FRAC_READ); fill_buf(aud_fd, mic_buf, WINDOW_SIZE>>FRAC_READ); cycle ++; } printf("Done with sound, about to close up\n"); fclose(file); fftw_destroy_plan(p); fftw_free(sound); fftw_free(freq); }
ssize_t get_key (const char* keyfile, char* keybuf, size_t size) { int fd = 0; size_t count = 0, this_read = 0; if ((fd = open (keyfile, O_RDONLY)) == -1) { fprintf (stderr, "Unable to open keyfile: %s\n", keyfile); return -1; } return fill_buf (keybuf, size, fd); }
int read_byte(struct userdata *u) { int ret; pa_assert(u); if (u->buf_fill < 1) if (fill_buf(u) < 0) return -1; ret = u->buf[0]; pa_assert(u->buf_fill > 0); u->buf_fill--; memmove(u->buf, u->buf+1, u->buf_fill); return ret; }
int main(void) { uint8_t command; serial_init(); trigger_setup(); aes_setup(); #ifdef DELAYS random_setup(); #endif while(1) { command = usart_recv_byte(); switch(command) { case 'e': fill_buf(); random_setup(); encrypt(); send_buf(); break; case 'd': fill_buf(); random_setup(); decrypt(); send_buf(); break; default: continue; } } return 0; }
ssize_t iv_read (crypt_data_t* crypt_data, int fd_in) { ssize_t count = 0; count = fill_buf (crypt_data->ivbuf, crypt_data->ivsize, fd_in); if (count == -1) return -1; if (count != crypt_data->ivsize) { fprintf (stderr, "Error: Unable to read IV from input stream.\n"); return -1; } return crypt_data->ivsize; }
int get_int(Sock *sock) { int val = -1, len; len = fill_buf(sock, (char *)&val, sizeof(int), "integer"); if (len != sizeof(int)) { #ifdef DEBUG fprintf(stderr,"get_int: caught error\n",val); #endif return -1; } #ifdef DEBUG fprintf(stderr,"get_int: received %d\n",val); #endif return val; }
char *read_string(struct userdata *u) { pa_assert(u); for (;;) { char *e; if ((e = memchr(u->buf, 0, u->buf_fill))) { char *ret = pa_xstrdup(u->buf); u->buf_fill -= (size_t) (e - u->buf +1); memmove(u->buf, e+1, u->buf_fill); return ret; } if (fill_buf(u) < 0) return NULL; } }
void fill_send_write(struct ctx *p_ctx, __u64 vlba, __u64 data, __u64 stride, __u32 flags) { __u64 *p_u64; __u32 *p_u32; __u64 plba; int i; for(i = 0 ; i < NUM_CMDS; i++) { vlba = i * stride; fill_buf((__u64*)&p_ctx->wbuf[i][0], sizeof(p_ctx->wbuf[i])/sizeof(__u64),data); memset(&p_ctx->cmd[i].rcb.cdb[0], 0, sizeof(p_ctx->cmd[i].rcb.cdb)); p_u64 = (__u64*)&p_ctx->cmd[i].rcb.cdb[2]; if(flags & VLBA){ p_ctx->cmd[i].rcb.res_hndl = p_ctx->res_hndl; p_ctx->cmd[i].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL; p_ctx->cmd[i].rcb.req_flags |= SISL_REQ_FLAGS_HOST_WRITE; write_64(p_u64, vlba); // write(16) Virtual LBA }else { p_ctx->cmd[i].rcb.lun_id = lun_id; p_ctx->cmd[i].rcb.port_sel = fc_port; // either FC port p_ctx->cmd[i].rcb.req_flags = SISL_REQ_FLAGS_HOST_WRITE; if(flags & NO_XLATE){ plba = vlba; } else { (void)mc_xlate_lba(p_ctx->mc_hndl, p_ctx->res_hndl, vlba, &plba); } write_64(p_u64, plba); // physical LBA# } p_ctx->cmd[i].rcb.data_ea = (__u64) &p_ctx->wbuf[0][0]; p_ctx->cmd[i].rcb.data_len = sizeof(p_ctx->wbuf[0]); p_ctx->cmd[i].rcb.cdb[0] = 0x8A; p_u32 = (__u32*)&p_ctx->cmd[i].rcb.cdb[10]; write_32(p_u32, LBA_BLK); p_ctx->cmd[i].sa.host_use[0] = 0; // 0 means active p_ctx->cmd[i].sa.ioasc = 0; } }
static int fill_file(int fd) { struct msg *m = malloc(msg_size); unsigned long long fs = (unsigned long long) file_size * 1024 * 1024ULL; while (fs) { if (fs < msg_size) break; fill_buf(m, msg_size); write(fd, m, msg_size); fs -= msg_size; } close(fd); return 0; }
ssize_t proc_loop (crypt_data_t* crypt_data, crypt_update_t crypt_update, crypt_final_t crypt_final) { ssize_t count_crypt = 0, count_read = 0, count_write = 0; int tmp = 0; do { count_crypt = 0; count_read = fill_buf (crypt_data->in_buf, crypt_data->buf_size, STDIN_FILENO); if (count_read == -1) exit (EXIT_FAILURE); if (verbose) fprintf (stderr, "crypting %d bytes\n", count_read); if (count_read > 0) { if (!crypt_update (&crypt_data->ctx, crypt_data->out_buf, &tmp, crypt_data->in_buf, count_read)) { fprintf (stderr, "crypt_update failed\n"); return -1; } count_crypt += tmp; } if (count_read < crypt_data->buf_size) { if (!crypt_final (&crypt_data->ctx, &crypt_data->out_buf[count_crypt], &tmp)) { fprintf (stderr, "crypt_final failed\n"); return -1; } count_crypt += tmp; } if (verbose) fprintf (stderr, "crypted %d bytes\n"); count_write += drain_buf (crypt_data->out_buf, count_crypt, STDOUT_FILENO); if (count_write == -1) exit (EXIT_FAILURE); if (verbose) fprintf (stderr, "wrote %d bytes\n", count_write); if (count_write < count_crypt) { fprintf (stderr, "short write!\n"); exit (EXIT_FAILURE); } } while (count_read == crypt_data->buf_size); return count_write; }
char * get_string(Sock *sock) { int val, len; char *buf; len = get_int(sock); if (len <0) return NULL; buf = malloc(len*sizeof(char)); val = fill_buf(sock, buf, len, "string"); if (val == -1){ free(buf); return NULL; } #ifdef DEBUG fprintf(stderr,"get_string: received \"%s\" \n",buf); #endif return buf; }
void zmq::swap_t::rollback () { if (commit_pos == write_pos || read_pos == write_pos) return; if (write_pos > read_pos) zmq_assert (read_pos <= commit_pos && commit_pos <= write_pos); else zmq_assert (read_pos <= commit_pos || commit_pos <= write_pos); if (commit_pos / block_size == read_pos / block_size) { write_buf_start_addr = commit_pos % block_size; write_buf = read_buf; } else if (commit_pos / block_size != write_pos / block_size) { write_buf_start_addr = commit_pos % block_size; fill_buf (write_buf, write_buf_start_addr); } write_pos = commit_pos; }
int bam_rmdupse(int argc, char *argv[]) { samfile_t *in, *out; buffer_t *buf; if (argc < 3) { fprintf(stderr, "Usage: samtools rmdupse <in.bam> <out.bam>\n\n"); fprintf(stderr, "Note: Picard is recommended for this task.\n"); return 1; } buf = calloc(1, sizeof(buffer_t)); in = samopen(argv[1], "rb", 0); out = samopen(argv[2], "wb", in->header); while (fill_buf(in, buf)) { rmdupse_buf(buf); dump_buf(buf, out); } samclose(in); samclose(out); free(buf->buf); free(buf); return 0; }
int main(int argc, char **argv) { char buf[BUFSIZE]; char *pass; int i, ret; if (-1 == pledge("exec getpw proc rpath stdio", NULL)) err(5, "pledge"); explicit_bzero(buf, sizeof(buf)); /* Read the username and password from stdin */ if (4 > fill_buf(buf, sizeof(buf))) errx(2, "not enough input data"); /* Make sure buffer is null-terminated */ if ('\0' != buf[sizeof(buf)-1]) errx(3, "not enough buffer space"); /* Find password */ pass = NULL; for (i = 0; i < sizeof(buf)-1; ++i) { if ('\0' == buf[i]) { pass = buf+i+1; break; } } if (NULL == pass) errx(4, "password not found"); /* Check password */ ret = auth_userokay(buf, NULL, NULL, pass); explicit_bzero(buf, sizeof(buf)); if (0 != ret) { printf("Ok.\n"); return 0; } printf("Fail.\n"); return 4; }
ssize_t iv_write (crypt_data_t* crypt_data, int fd_out) { int fd = 0, count = 0; if ((fd = open (RANDFILE, O_RDONLY)) == -1) { fprintf (stderr, "Unable to open file %s\n", RANDFILE); return -1; } crypt_data->ivsize = fill_buf (crypt_data->ivbuf, crypt_data->ivsize, fd); if (crypt_data->ivsize == -1) return -1; count = drain_buf (crypt_data->ivbuf, crypt_data->ivsize, fd_out); if (count == -1) return -1; if (count != crypt_data->ivsize) { fprintf (stderr, "Error: Didn't write full IV."); return -1; } return crypt_data->ivsize; }
void zmq::swap_t::copy_from_file (void *buffer_, size_t count_) { char *dest_ptr = (char *) buffer_; size_t chunk_size, remainder = count_; while (remainder > 0) { chunk_size = std::min (remainder, std::min ((size_t) (filesize - read_pos), (size_t) (block_size - read_pos % block_size))); memcpy (dest_ptr, &read_buf [read_pos % block_size], chunk_size); dest_ptr += chunk_size; read_pos = (read_pos + chunk_size) % filesize; if (read_pos % block_size == 0) { if (read_pos / block_size == write_pos / block_size) read_buf = write_buf; else fill_buf (read_buf, read_pos); } remainder -= chunk_size; } }
void fill_send_write(struct ctx *p_ctx, __u64 vlba, __u64 data, __u64 stride) { __u64 *p_u64; __u32 *p_u32; __u64 lba; int i; for (i = 0 ; i < NUM_CMDS; i++) { lba = i * stride; fill_buf((__u64*)&p_ctx->wbuf[i][0], sizeof(p_ctx->wbuf[i])/sizeof(__u64),data); memset((void *)&p_ctx->cmd[i].rcb.cdb[0], 0, sizeof(p_ctx->cmd[i].rcb.cdb)); p_u64 = (__u64*)&p_ctx->cmd[i].rcb.cdb[2]; p_ctx->cmd[i].rcb.res_hndl = p_ctx->res_hndl; p_ctx->cmd[i].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL; p_ctx->cmd[i].rcb.req_flags |= SISL_REQ_FLAGS_HOST_WRITE; write_lba(p_u64, lba); p_ctx->cmd[i].rcb.data_ea = (__u64) &p_ctx->wbuf[0][0]; p_ctx->cmd[i].rcb.data_len = sizeof(p_ctx->wbuf[0]); p_ctx->cmd[i].rcb.cdb[0] = 0x8A; p_u32 = (__u32*)&p_ctx->cmd[i].rcb.cdb[10]; write_32(p_u32, p_ctx->blk_len); p_ctx->cmd[i].sa.host_use[0] = 0; // 0 means active p_ctx->cmd[i].sa.ioasc = 0; } }
void menu_char(int x_adjust, int menu_wid, int odd, register unsigned char *menu_border) { register int i, j, k; int embold = 1; int base; int totwid = font.width; /* Read in the character bit map, with two blank lines on each end. */ for (i = 0; i < 2; i++) clear_buf (totwid, filterbuf[i]); for (i = font.height + 1; i >= 2; i--) fill_buf (font.width, filterbuf[i]); for (i = font.height + 2; i < font.height + 4; i++) clear_buf (totwid, filterbuf[i]); for (k=0; k<embold; k++) for (i=2; i<font.height+2; i++) for (j=totwid+1; j>=2; j--) filterbuf[i][j+1] |= filterbuf[i][j]; /* Initial base line for filtering depends on odd flag. */ base = (odd ? 1 : 2); /* Change bits in menu that correspond to character bitmap. */ for (i = font.height + base, k = 0; i >= base; i--, k++) { register RGBpixel *menu; menu = menu_addr + k * menu_wid + x_adjust; for (j = 0; j < (totwid + 3) - 1; j++, menu++ ) if ( filterbuf[i][j] ) { COPYRGB(*menu, menu_border); } } return; }
static void test_simple_streaming(IXAudio2 *xa) { HRESULT hr; IXAudio2MasteringVoice *master; IXAudio2SourceVoice *src, *src2; IUnknown *vumeter; WAVEFORMATEX fmt; XAUDIO2_BUFFER buf, buf2; XAUDIO2_VOICE_STATE state; XAUDIO2_EFFECT_DESCRIPTOR effect; XAUDIO2_EFFECT_CHAIN chain; memset(&ecb_state, 0, sizeof(ecb_state)); memset(&src1_state, 0, sizeof(src1_state)); memset(&src2_state, 0, sizeof(src2_state)); XA2CALL_0V(StopEngine); /* Tests show in native XA2.8, ECB is called from a mixer thread, but VCBs * may be called from other threads in any order. So we can't rely on any * sequencing between VCB calls. * * XA2.7 does all mixing from a single thread, so call sequence can be * tested. */ XA2CALL(RegisterForCallbacks, &ecb); ok(hr == S_OK, "RegisterForCallbacks failed: %08x\n", hr); if(xaudio27) hr = IXAudio27_CreateMasteringVoice((IXAudio27*)xa, &master, 2, 44100, 0, 0, NULL); else hr = IXAudio2_CreateMasteringVoice(xa, &master, 2, 44100, 0, NULL, NULL, AudioCategory_GameEffects); ok(hr == S_OK, "CreateMasteringVoice failed: %08x\n", hr); /* create first source voice */ fmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; fmt.nChannels = 2; fmt.nSamplesPerSec = 44100; fmt.wBitsPerSample = 32; fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; fmt.cbSize = 0; XA2CALL(CreateSourceVoice, &src, &fmt, 0, 1.f, &vcb1, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); memset(&buf, 0, sizeof(buf)); buf.AudioBytes = 22050 * fmt.nBlockAlign; buf.pAudioData = HeapAlloc(GetProcessHeap(), 0, buf.AudioBytes); fill_buf((float*)buf.pAudioData, &fmt, 440, 22050); hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); hr = IXAudio2SourceVoice_Start(src, 0, XAUDIO2_COMMIT_NOW); ok(hr == S_OK, "Start failed: %08x\n", hr); /* create second source voice */ XA2CALL(CreateSourceVoice, &src2, &fmt, 0, 1.f, &vcb2, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); memset(&buf2, 0, sizeof(buf2)); buf2.AudioBytes = 22050 * fmt.nBlockAlign; buf2.pAudioData = HeapAlloc(GetProcessHeap(), 0, buf2.AudioBytes); fill_buf((float*)buf2.pAudioData, &fmt, 220, 22050); hr = IXAudio2SourceVoice_SubmitSourceBuffer(src2, &buf2, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); hr = IXAudio2SourceVoice_Start(src2, 0, XAUDIO2_COMMIT_NOW); ok(hr == S_OK, "Start failed: %08x\n", hr); XA2CALL_0(StartEngine); ok(hr == S_OK, "StartEngine failed: %08x\n", hr); /* hook up volume meter */ if(xaudio27){ hr = CoCreateInstance(&CLSID_AudioVolumeMeter, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&vumeter); ok(hr == S_OK, "CoCreateInstance(AudioVolumeMeter) failed: %08x\n", hr); }else{ hr = pCreateAudioVolumeMeter(&vumeter); ok(hr == S_OK, "CreateAudioVolumeMeter failed: %08x\n", hr); } effect.InitialState = TRUE; effect.OutputChannels = 2; effect.pEffect = vumeter; chain.EffectCount = 1; chain.pEffectDescriptors = &effect; hr = IXAudio2MasteringVoice_SetEffectChain(master, &chain); ok(hr == S_OK, "SetEffectchain failed: %08x\n", hr); IUnknown_Release(vumeter); while(1){ if(xaudio27) IXAudio27SourceVoice_GetState((IXAudio27SourceVoice*)src, &state); else IXAudio2SourceVoice_GetState(src, &state, 0); if(state.SamplesPlayed >= 22050) break; Sleep(100); } ok(state.SamplesPlayed == 22050, "Got wrong samples played\n"); HeapFree(GetProcessHeap(), 0, (void*)buf.pAudioData); HeapFree(GetProcessHeap(), 0, (void*)buf2.pAudioData); if(xaudio27){ IXAudio27SourceVoice_DestroyVoice((IXAudio27SourceVoice*)src); IXAudio27SourceVoice_DestroyVoice((IXAudio27SourceVoice*)src2); }else{ IXAudio2SourceVoice_DestroyVoice(src); IXAudio2SourceVoice_DestroyVoice(src2); } IXAudio2MasteringVoice_DestroyVoice(master); XA2CALL_V(UnregisterForCallbacks, &ecb); }
/* Copies all the text selected to the selection buffer. Whitespace at * end of lines is trimmed. */ static void selarea_copy_text(void) { char *ptr, *str; size_t l, r; ptr = NULL; /* XXXGCC -Wuninitialized */ if (Selarea.sa_y1 == Selarea.sa_y2) { /* Selection is one row */ l = row_length(Selarea.sa_y1); if (Selarea.sa_x1 > l) /* Selection is after last character, * therefore it is empty */ str = NULL; else { if (Selarea.sa_x2 > l) Selarea.sa_x2 = l; ptr = str = alloc_sel(Selarea.sa_x2 - Selarea.sa_x1 + 1); if (ptr == NULL) return; ptr = fill_buf(ptr, Selarea.sa_y1, Selarea.sa_x1, Selarea.sa_x2); *ptr = '\0'; } } else { /* Selection is multiple rows */ ptr = str = alloc_sel(Selarea.sa_endoff - Selarea.sa_startoff + 1); if (ptr == NULL) return; /* Calculate and copy first line */ l = row_length(Selarea.sa_y1); if (Selarea.sa_x1 < l) { ptr = fill_buf(ptr, Selarea.sa_y1, Selarea.sa_x1, l); *ptr++ = '\r'; } /* Copy mid lines if there are any */ if ((Selarea.sa_y2 - Selarea.sa_y1) > 1) { for (r = Selarea.sa_y1 + 1; r <= Selarea.sa_y2 - 1; r++) { ptr = fill_buf(ptr, r, 0, row_length(r)); *ptr++ = '\r'; } } /* Calculate and copy end line */ l = row_length(Selarea.sa_y2); if (Selarea.sa_x2 < l) l = Selarea.sa_x2; ptr = fill_buf(ptr, Selarea.sa_y2, 0, l); *ptr = '\0'; } if (Selarea.sa_buf != NULL) { free(Selarea.sa_buf); Selarea.sa_buf = NULL; } if (str != NULL) { Selarea.sa_buf = str; Selarea.sa_buflen = ptr - str; } }
static void test_buffer_callbacks(IXAudio2 *xa) { HRESULT hr; IXAudio2MasteringVoice *master; IXAudio2SourceVoice *src; WAVEFORMATEX fmt; XAUDIO2_BUFFER buf; XAUDIO2_VOICE_STATE state; struct vcb_buf_testdata testdata[5]; int i, timeout; obs_calls = 0; obe_calls = 0; XA2CALL_0V(StopEngine); if(xaudio27) hr = IXAudio27_CreateMasteringVoice((IXAudio27*)xa, &master, 2, 44100, 0, 0, NULL); else hr = IXAudio2_CreateMasteringVoice(xa, &master, 2, 44100, 0, NULL, NULL, AudioCategory_GameEffects); ok(hr == S_OK, "CreateMasteringVoice failed: %08x\n", hr); /* test OnBufferStart/End callbacks */ fmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; fmt.nChannels = 2; fmt.nSamplesPerSec = 44100; fmt.wBitsPerSample = 32; fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; fmt.cbSize = 0; XA2CALL(CreateSourceVoice, &src, &fmt, 0, 1.f, &vcb_buf, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); memset(&buf, 0, sizeof(buf)); buf.AudioBytes = 4410 * fmt.nBlockAlign; buf.pAudioData = HeapAlloc(GetProcessHeap(), 0, buf.AudioBytes); fill_buf((float*)buf.pAudioData, &fmt, 440, 4410); /* submit same buffer fragment 5 times */ for(i = 0; i < 5; ++i){ testdata[i].idx = i; testdata[i].src = src; buf.pContext = &testdata[i]; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); } hr = IXAudio2SourceVoice_Start(src, 0, XAUDIO2_COMMIT_NOW); ok(hr == S_OK, "Start failed: %08x\n", hr); XA2CALL_0(StartEngine); ok(hr == S_OK, "StartEngine failed: %08x\n", hr); if(xaudio27){ hr = IXAudio27SourceVoice_SetSourceSampleRate((IXAudio27SourceVoice*)src, 48000); todo_wine ok(hr == S_OK, "SetSourceSampleRate failed: %08x\n", hr); }else{ hr = IXAudio2SourceVoice_SetSourceSampleRate(src, 48000); ok(hr == XAUDIO2_E_INVALID_CALL, "SetSourceSampleRate should have failed: %08x\n", hr); } while(1){ if(xaudio27) IXAudio27SourceVoice_GetState((IXAudio27SourceVoice*)src, &state); else IXAudio2SourceVoice_GetState(src, &state, 0); if(state.SamplesPlayed >= 4410 * 5) break; Sleep(100); } ok(state.SamplesPlayed == 4410 * 5, "Got wrong samples played\n"); if(xaudio27) IXAudio27SourceVoice_DestroyVoice((IXAudio27SourceVoice*)src); else IXAudio2SourceVoice_DestroyVoice(src); /* test OnStreamEnd callback */ XA2CALL(CreateSourceVoice, &src, &fmt, 0, 1.f, &loop_buf, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); buf.Flags = XAUDIO2_END_OF_STREAM; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); hr = IXAudio2SourceVoice_Start(src, 0, XAUDIO2_COMMIT_NOW); ok(hr == S_OK, "Start failed: %08x\n", hr); timeout = 0; while(nstreamends == 0 && timeout < 1000){ Sleep(100); timeout += 100; } ok(nstreamends == 1, "Got wrong number of OnStreamEnd calls: %u\n", nstreamends); /* xaudio resets SamplesPlayed after processing an end-of-stream buffer */ if(xaudio27) IXAudio27SourceVoice_GetState((IXAudio27SourceVoice*)src, &state); else IXAudio2SourceVoice_GetState(src, &state, 0); ok(state.SamplesPlayed == 0, "Got wrong samples played\n"); if(xaudio27) IXAudio27SourceVoice_DestroyVoice((IXAudio27SourceVoice*)src); else IXAudio2SourceVoice_DestroyVoice(src); IXAudio2MasteringVoice_DestroyVoice(master); HeapFree(GetProcessHeap(), 0, (void*)buf.pAudioData); }
static void test_looping(IXAudio2 *xa) { HRESULT hr; IXAudio2MasteringVoice *master; IXAudio2SourceVoice *src; WAVEFORMATEX fmt; XAUDIO2_BUFFER buf; UINT32 played, running_total = 0; XA2CALL_0V(StopEngine); if(xaudio27) hr = IXAudio27_CreateMasteringVoice((IXAudio27*)xa, &master, 2, 44100, 0, 0, NULL); else hr = IXAudio2_CreateMasteringVoice(xa, &master, 2, 44100, 0, NULL, NULL, AudioCategory_GameEffects); ok(hr == S_OK, "CreateMasteringVoice failed: %08x\n", hr); fmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; fmt.nChannels = 2; fmt.nSamplesPerSec = 44100; fmt.wBitsPerSample = 32; fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; fmt.cbSize = 0; XA2CALL(CreateSourceVoice, &src, &fmt, 0, 1.f, &loop_buf, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); memset(&buf, 0, sizeof(buf)); buf.AudioBytes = 44100 * fmt.nBlockAlign; buf.pAudioData = HeapAlloc(GetProcessHeap(), 0, buf.AudioBytes); fill_buf((float*)buf.pAudioData, &fmt, 440, 44100); XA2CALL_0(StartEngine); ok(hr == S_OK, "StartEngine failed: %08x\n", hr); /* play from middle to end */ buf.PlayBegin = 22050; buf.PlayLength = 0; buf.LoopBegin = 0; buf.LoopLength = 0; buf.LoopCount = 0; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 22050, "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 0, "Got wrong OnLoopEnd calls: %u\n", nloopends); /* play 4410 samples from middle */ buf.PlayBegin = 22050; buf.PlayLength = 4410; buf.LoopBegin = 0; buf.LoopLength = 0; buf.LoopCount = 0; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 4410, "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 0, "Got wrong OnLoopEnd calls: %u\n", nloopends); /* loop 4410 samples in middle */ buf.PlayBegin = 0; buf.PlayLength = 0; buf.LoopBegin = 22050; buf.LoopLength = 4410; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 44100 + 4410, "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 1, "Got wrong OnLoopEnd calls: %u\n", nloopends); /* play last half, then loop the whole buffer */ buf.PlayBegin = 22050; buf.PlayLength = 0; buf.LoopBegin = 0; buf.LoopLength = 0; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 22050 + 44100, "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 1, "Got wrong OnLoopEnd calls: %u\n", nloopends); /* play short segment from middle, loop to the beginning, and end at PlayEnd */ buf.PlayBegin = 22050; buf.PlayLength = 4410; buf.LoopBegin = 0; buf.LoopLength = 0; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 4410 + (22050 + 4410), "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 1, "Got wrong OnLoopEnd calls: %u\n", nloopends); /* invalid: LoopEnd must be <= PlayEnd * xaudio27: play until LoopEnd, loop to beginning, play until PlayEnd */ buf.PlayBegin = 22050; buf.PlayLength = 4410; buf.LoopBegin = 0; buf.LoopLength = 22050 + 4410 * 2; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); if(xaudio27){ ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 4410 + (22050 + 4410 * 2), "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 1, "Got wrong OnLoopEnd calls: %u\n", nloopends); }else ok(hr == XAUDIO2_E_INVALID_CALL, "SubmitSourceBuffer should have failed: %08x\n", hr); /* invalid: LoopEnd must be within play range * xaudio27: plays only play range */ buf.PlayBegin = 22050; buf.PlayLength = 0; /* == until end of buffer */ buf.LoopBegin = 0; buf.LoopLength = 22050; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); if(xaudio27){ ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, -1); ok(played - running_total == 22050, "Got wrong samples played: %u\n", played - running_total); running_total = played; ok(nloopends == 0, "Got wrong OnLoopEnd calls: %u\n", nloopends); }else ok(hr == XAUDIO2_E_INVALID_CALL, "SubmitSourceBuffer should have failed: %08x\n", hr); /* invalid: LoopBegin must be before PlayEnd * xaudio27: crashes */ if(!xaudio27){ buf.PlayBegin = 0; buf.PlayLength = 4410; buf.LoopBegin = 22050; buf.LoopLength = 4410; buf.LoopCount = 1; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == XAUDIO2_E_INVALID_CALL, "SubmitSourceBuffer should have failed: %08x\n", hr); } /* infinite looping buffer */ buf.PlayBegin = 22050; buf.PlayLength = 0; buf.LoopBegin = 0; buf.LoopLength = 0; buf.LoopCount = 255; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); played = play_to_completion(src, running_total + 88200); ok(played - running_total == 22050 + 44100 * 2, "Got wrong samples played: %u\n", played - running_total); ok(nloopends == (played - running_total) / 88200 + 1, "Got wrong OnLoopEnd calls: %u\n", nloopends); running_total = played; }
int test_mc_invalid_opcode() { int rc; struct ctx myctx; struct ctx *p_ctx = &myctx; __u64 chunks=10; __u64 actual_size=0; __u64 vlba =0; __u64 *p_u64; __u32 *p_u32; mc_stat_t l_mc_stat; pthread_t thread; if (mc_init() !=0 ) { fprintf(stderr, "mc_init failed.\n"); return -1; } debug("mc_init success.\n"); rc = ctx_init(p_ctx); if (rc != 0) { fprintf(stderr, "Context init failed, errno %d\n", errno); return -1; } pthread_create(&thread,NULL,ctx_rrq_rx, p_ctx); /*rc = mc_register(master_dev_path, p_ctx->ctx_hndl, (volatile __u64 *)p_ctx->p_host_map,&p_ctx->mc_hndl); if(rc != 0) { fprintf(stderr, "ctx _reg failed, ctx_hndl %d,rc %d\n",p_ctx->ctx_hndl, rc ); return -1; }*/ rc = create_res(p_ctx); if (rc != 0) { fprintf(stderr, "error opening res_hndl rc %d\n", rc); return -1; } rc = mc_size1(p_ctx,chunks, &actual_size); CHECK_RC(rc, "mc_size"); rc = mc_stat1(p_ctx, &l_mc_stat); CHECK_RC(rc, "mc_stat"); pid = getpid(); vlba = (actual_size * (1 << l_mc_stat.nmask))-1; fill_buf((__u64*)&p_ctx->wbuf[0][0], sizeof(p_ctx->wbuf[0])/sizeof(__u64),pid); memset((void *)&p_ctx->cmd[0].rcb.cdb[0], 0, sizeof(p_ctx->cmd[0].rcb.cdb)); p_u64 = (__u64*)&p_ctx->cmd[0].rcb.cdb[2]; p_ctx->cmd[0].rcb.res_hndl = p_ctx->res_hndl; p_ctx->cmd[0].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL; p_ctx->cmd[0].rcb.req_flags |= SISL_REQ_FLAGS_HOST_WRITE; write_lba(p_u64, vlba); p_ctx->cmd[0].rcb.data_ea = (__u64) &p_ctx->wbuf[0][0]; p_ctx->cmd[0].rcb.data_len = sizeof(p_ctx->wbuf[0]); p_ctx->cmd[0].rcb.cdb[0] = 0xFA; // invalid opcode p_u32 = (__u32*)&p_ctx->cmd[0].rcb.cdb[10]; write_32(p_u32, 8); // 8 LBAs for 4K p_ctx->cmd[0].sa.host_use[0] = 0; // 0 means active p_ctx->cmd[0].sa.ioasc = 0; send_single_cmd(p_ctx); rc = wait_single_resp(p_ctx); return rc; }
HIDDEN void do_Char(int c, int xpos, int ypos, int odd) { register int i, j; int base; int totwid = font.width; int down; static float resbuf[FONTBUFSZ]; static RGBpixel fbline[FONTBUFSZ]; #if DEBUG_STRINGS fb_log( "do_Char: c='%c' xpos=%d ypos=%d odd=%d\n", c, xpos, ypos, odd ); #endif /* read in character bit map, with two blank lines on each end */ for (i = 0; i < 2; i++) clear_buf (totwid, filterbuf[i]); for (i = font.height + 1; i >= 2; i--) fill_buf (font.width, filterbuf[i]); for (i = font.height + 2; i < font.height + 4; i++) clear_buf (totwid, filterbuf[i]); (void)SignedChar( font.dir[c].up ); down = SignedChar( font.dir[c].down ); /* Initial base line for filtering depends on odd flag. */ base = (odd ? 1 : 2); /* Produce a RGBpixel buffer from a description of the character and the read back data from the frame buffer for anti-aliasing. */ for (i = font.height + base; i >= base; i--) { squash( filterbuf[i - 1], /* filter info */ filterbuf[i], filterbuf[i + 1], resbuf, totwid + 4 ); fb_read( fbp, xpos, ypos - down + i, (unsigned char *)fbline, totwid+3); for (j = 0; j < (totwid + 3) - 1; j++) { register int tmp; /* EDITOR'S NOTE : do not rearrange this code, the SUN compiler can't handle more complex expressions. */ tmp = fbline[j][RED] & 0377; fbline[j][RED] = (int)(paint[RED]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][RED] &= 0377; tmp = fbline[j][GRN] & 0377; fbline[j][GRN] = (int)(paint[GRN]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][GRN] &= 0377; tmp = fbline[j][BLU] & 0377; fbline[j][BLU] = (int)(paint[BLU]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][BLU] &= 0377; } fb_write( fbp, xpos, ypos - down + i, (unsigned char *)fbline, totwid+3 ); } return; }
void do_char(struct vfont *vfp, struct vfont_dispatch *vdp, int x, int y) { int i, j; int base; int totwid = width; int ln; static float resbuf[FONTBUFSZ]; static RGBpixel fbline[FONTBUFSZ]; int bytes_wide; /* # bytes/row in bitmap */ bytes_wide = (width+7)>>3; /* Read in the character bit map, with two blank lines on each end. */ for (i = 0; i < 2; i++) memset((char *)&filterbuf[i][0], 0, (totwid+4)*sizeof(int)); for (ln=0, i = height + 1; i >= 2; i--, ln++) fill_buf (width, &filterbuf[i][0], &vfp->vf_bits[vdp->vd_addr + bytes_wide*ln]); for (i = height + 2; i < height + 4; i++) memset((char *)&filterbuf[i][0], 0, (totwid+4)*sizeof(int)); /* Initial base line for filtering depends on odd flag. */ if (vdp->vd_down % 2) base = 1; else base = 2; /* Produce a RGBpixel buffer from a description of the character * and the read back data from the frame buffer for anti-aliasing. */ for (i = height + base; i >= base; i--) { squash(filterbuf[i - 1], /* filter info */ filterbuf[i], filterbuf[i + 1], resbuf, totwid + 4 ); fb_read(fbp, x, y - vdp->vd_down + i, (unsigned char *)fbline, totwid+3); for (j = 0; j < (totwid + 3) - 1; j++) { int tmp; /* EDITOR'S NOTE : do not rearrange this code, the SUN * compiler can't handle more complex expressions. */ tmp = fbline[j][RED] & 0377; fbline[j][RED] = (int)(pixcolor[RED]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][RED] &= 0377; tmp = fbline[j][GRN] & 0377; fbline[j][GRN] = (int)(pixcolor[GRN]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][GRN] &= 0377; tmp = fbline[j][BLU] & 0377; fbline[j][BLU] = (int)(pixcolor[BLU]*resbuf[j]+(1-resbuf[j])*tmp); fbline[j][BLU] &= 0377; } if (fb_write(fbp, x, y-vdp->vd_down+i, (unsigned char *)fbline, totwid+3) < totwid+3) { fprintf(stderr, "fblabel: pixel write error\n"); bu_exit(1, NULL); } } }
blargg_err_t Zlib_Inflater::read( void* out, int* count_io ) { int remain = *count_io; if ( remain && zbuf.next_in ) { if ( deflated_ ) { zbuf.next_out = (Bytef*) out; zbuf.avail_out = remain; while ( 1 ) { uInt old_avail_in = zbuf.avail_in; int err = inflate( &zbuf, Z_NO_FLUSH ); if ( err == Z_STREAM_END ) { remain = zbuf.avail_out; end(); break; // no more data to inflate } if ( err && (err != Z_BUF_ERROR || old_avail_in) ) return get_zlib_err( err ); if ( !zbuf.avail_out ) { remain = 0; break; // requested number of bytes inflated } if ( zbuf.avail_in ) { // inflate() should never leave input if there's still space for output check( false ); return blargg_err_file_corrupt; } RETURN_ERR( fill_buf( buf.size() ) ); if ( !zbuf.avail_in ) return blargg_err_file_corrupt; // stream didn't end but there's no more data } } else { while ( 1 ) { // copy buffered data if ( zbuf.avail_in ) { long count = zbuf.avail_in; if ( count > remain ) count = remain; memcpy( out, zbuf.next_in, count ); zbuf.total_out += count; out = (char*) out + count; remain -= count; zbuf.next_in += count; zbuf.avail_in -= count; } if ( !zbuf.avail_in && zbuf.next_in < buf.end() ) { end(); break; } // read large request directly if ( remain + zbuf.total_out % block_size >= buf.size() ) { int count = remain; RETURN_ERR( callback( user_data, out, &count ) ); zbuf.total_out += count; out = (char*) out + count; remain -= count; if ( remain ) { end(); break; } } if ( !remain ) break; RETURN_ERR( fill_buf( buf.size() - zbuf.total_out % block_size ) ); } } } *count_io -= remain; return blargg_ok; }
static void test_buffer_callbacks(IXAudio2 *xa) { HRESULT hr; IXAudio2MasteringVoice *master; IXAudio2SourceVoice *src; WAVEFORMATEX fmt; XAUDIO2_BUFFER buf; XAUDIO2_VOICE_STATE state; struct vcb_buf_testdata testdata[5]; int i; obs_calls = 0; obe_calls = 0; XA2CALL_0V(StopEngine); if(xaudio27) hr = IXAudio27_CreateMasteringVoice((IXAudio27*)xa, &master, 2, 44100, 0, 0, NULL); else hr = IXAudio2_CreateMasteringVoice(xa, &master, 2, 44100, 0, NULL, NULL, AudioCategory_GameEffects); ok(hr == S_OK, "CreateMasteringVoice failed: %08x\n", hr); fmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; fmt.nChannels = 2; fmt.nSamplesPerSec = 44100; fmt.wBitsPerSample = 32; fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; fmt.cbSize = 0; XA2CALL(CreateSourceVoice, &src, &fmt, 0, 1.f, &vcb_buf, NULL, NULL); ok(hr == S_OK, "CreateSourceVoice failed: %08x\n", hr); memset(&buf, 0, sizeof(buf)); buf.AudioBytes = 4410 * fmt.nBlockAlign; buf.pAudioData = HeapAlloc(GetProcessHeap(), 0, buf.AudioBytes); fill_buf((float*)buf.pAudioData, &fmt, 440, 4410); /* submit same buffer fragment 5 times */ for(i = 0; i < 5; ++i){ testdata[i].idx = i; testdata[i].src = src; buf.pContext = &testdata[i]; hr = IXAudio2SourceVoice_SubmitSourceBuffer(src, &buf, NULL); ok(hr == S_OK, "SubmitSourceBuffer failed: %08x\n", hr); } hr = IXAudio2SourceVoice_Start(src, 0, XAUDIO2_COMMIT_NOW); ok(hr == S_OK, "Start failed: %08x\n", hr); XA2CALL_0(StartEngine); ok(hr == S_OK, "StartEngine failed: %08x\n", hr); while(1){ if(xaudio27) IXAudio27SourceVoice_GetState((IXAudio27SourceVoice*)src, &state); else IXAudio2SourceVoice_GetState(src, &state, 0); if(state.SamplesPlayed >= 4410 * 5) break; Sleep(100); } ok(state.SamplesPlayed == 4410 * 5, "Got wrong samples played\n"); HeapFree(GetProcessHeap(), 0, (void*)buf.pAudioData); if(xaudio27) IXAudio27SourceVoice_DestroyVoice((IXAudio27SourceVoice*)src); else IXAudio2SourceVoice_DestroyVoice(src); IXAudio2MasteringVoice_DestroyVoice(master); }
/* Format of data: 8 hexadecimal numbers with spaces */ int dbus_decomp(const char *filename, int resync) { char src_name[1024]; char dst_name[1024]; FILE *fi, *fo; long file_size; struct stat st; unsigned char *buffer; int i; unsigned int j; int num_bytes; char str[256]; unsigned char mid, cid; unsigned int length; int idx; int ret = 0; // build filenames strcpy(src_name, filename); strcat(src_name, ".hex"); strcpy(dst_name, filename); strcat(dst_name, ".pkt"); stat(src_name, &st); file_size = st.st_size; // allocate buffer buffer = (unsigned char*)calloc(file_size/2, 1); memset(buffer, 0xff, file_size/2); if(buffer == NULL) { fprintf(stderr, "calloc error.\n"); exit(-1); } // open files fi = fopen(src_name, "rt"); fo = fopen(dst_name, "wt"); if(fi == NULL) { fprintf(stderr, "Unable to open this file: %s\n", src_name); return -1; } fprintf(fo, "TI packet decompiler for D-BUS, version 1.2\n"); // skip comments fgets(str, sizeof(str), fi); fgets(str, sizeof(str), fi); fgets(str, sizeof(str), fi); // read source file for(i = 0; !feof(fi);) { for(j = 0; j < 16 && !feof(fi); j++) { fscanf(fi, "%02X", &(buffer[i+j])); fgetc(fi); } i += j; for(j=0; j<18 && !feof(fi); j++) fgetc(fi); } num_bytes = i-1; // -1 due to EOF char fprintf(stdout, "%i bytes read.\n", num_bytes); // process data for(i = 0; i < num_bytes;) { restart: mid = buffer[i+0]; cid = buffer[i+1]; length = buffer[i+2]; length |= buffer[i+3] << 8; // check for valid packet if(is_a_machine_id(mid) == -1) { ret = -1; goto exit; } // check for valid packet idx = is_a_command_id(cid); if(idx == -1) { ret = -2; goto exit; } fprintf(fo, "%02X %02X %02X %02X", mid, cid, length >> 8, length & 0xff); for(j = 4; j <= WIDTH; j++) fprintf(fo, " "); fprintf(fo, " | "); fprintf(fo, "%s: %s\n", machine_way[is_a_machine_id(mid)], command_name[is_a_command_id(cid)]); i += 4; // get data & checksum if(cmd_with_data[idx] && length > 0) { // data for(j = 0; j < length; j++, i++) { if(resync && buffer[i] == 0x98 && (buffer[i+1] == 0x15 || buffer[i+1] == 0x56)) { fprintf(stdout, "Warning: there is packets in data !\n"); fprintf(fo, "Beware : length of previous packet is wrong !\n"); goto restart; } fill_buf(fo, buffer[i], 0); } fill_buf(fo, 0, !0); //fprintf(fo, "\n"); // write checksum fprintf(fo, " "); fprintf(fo, "%02X ", buffer[i++]); fprintf(fo, "%02X ", buffer[i++]); fprintf(fo, "\n"); } } exit: if(ret < 0) fprintf(stdout, "Error %i\n", -ret); free(buffer); fclose(fi); fclose(fo); return ret; }