/* cc -g -xF -xsb -DDBXTESTING asmfuncs.c */ main() { int len; struct sample_info s; SAMPLE_INFO ns; FILE *info_file; char info[120]; read_info_file("."); len = entryQ_length(".","GregAutoEntry"); printf("len: %d\n",len); len = entryQ_length(".","/vxwks/greg/inova/nautoproc/GregAutoEntry"); printf("len: %d\n",len); info_file = fopen("./GregAutoEntry","r"); read_sample_info(info_file,&ns); fclose(info_file); info_file = fopen("./tmpentry","w"); write_sample_info(info_file,&ns); fclose(info_file); len = get_sample_info (&ns,"DATA:",info,120,NULL); printf("DATA: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"USERDIR:",info,120,NULL); printf("USERDIR: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"STATUS:",info,120,NULL); printf("STATUS: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"SAMPLE#:",info,120,NULL); printf("SAMPLE: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"EOE:",info,120,NULL); printf("EOE: '%s', len: %d\n",info,len); update_sample_info(".","GregAutoEntry", "DATA:", "/userdir/greg/auto/file1234" , "STATUS:", "Complete" ); update_sample_info(".","GregAutoEntry", "DATA:", "/userdir/greg/auto/file1236" , "STATUS:", "Active" ); getPsgQentry("./psgQ",&ns); deletePsgQentry("./psgQ",&ns); deleteEnterQentry(".","enterQ"); }
static void GetBuffer(demux_res_t *demux_res) { unsigned long destBufferSize = 1024*16; /* 16kb buffer = 4096 frames = 1 alac sample */ void *pDestBuffer = malloc(destBufferSize); int bytes_read = 0; unsigned int buffer_size = 1024*64; void *buffer; unsigned int i; buffer = malloc(buffer_size); for (i = 0; i < demux_res->num_sample_byte_sizes; i++) { uint32_t sample_duration; uint32_t sample_byte_size; int outputBytes; /* just get one sample for now */ if (!get_sample_info(demux_res, i, &sample_duration, &sample_byte_size)) { fprintf(stderr, "sample failed\n"); return; } if (buffer_size < sample_byte_size) { fprintf(stderr, "sorry buffer too small! (is %i want %i)\n", buffer_size, sample_byte_size); return; } stream_read(input_stream, sample_byte_size, buffer); /* now fetch */ outputBytes = destBufferSize; decode_frame(alac, buffer, pDestBuffer, &outputBytes); /* write */ bytes_read += outputBytes; if (verbose) fprintf(stderr, "read %i bytes. total: %i\n", outputBytes, bytes_read); fwrite(pDestBuffer, outputBytes, 1, output_file); } if (verbose) fprintf(stderr, "done reading, read %i frames\n", i); }
deletePsgQentry(char *filename,struct sample_info *s) { char shellcmd[3*MAXPATHL]; char tmp[91]; int entryindex; /* sly way of determining psgQentry length, we know 1 line for psg then sampleinfo size */ get_sample_info(s,"EOE:",tmp,90,&entryindex); /* End-of-Entry index + 1 = size */ /* (tail +(nlines+1)) */ sprintf(shellcmd,"tail +%d %s > /tmp/psgQtmp; mv -f /tmp/psgQtmp %s", entryindex+3,filename,filename); system(shellcmd); /* remove entry from psgQ sent to Acqproc */ }
int main(int argc, char **argv) { demux_res_t demux_res; unsigned int output_size, i; set_endian(); setup_environment(argc, argv); input_stream = stream_create_file(input_file, 1); if (!input_stream) { fprintf(stderr, "failed to create input stream from file\n"); return 0; } /* if qtmovie_read returns successfully, the stream is up to * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(input_stream, &demux_res)) { fprintf(stderr, "failed to load the QuickTime movie headers\n"); return 0; } /* initialise the sound converter */ init_sound_converter(&demux_res); /* write wav output headers */ if (write_wav_format) { /* calculate output size */ output_size = 0; for (i = 0; i < demux_res.num_sample_byte_sizes; i++) { unsigned int thissample_duration; unsigned int thissample_bytesize; get_sample_info(&demux_res, i, &thissample_duration, &thissample_bytesize); output_size += thissample_duration * (demux_res.sample_size / 8) * demux_res.num_channels; } wavwriter_writeheaders(output_file, output_size, demux_res.num_channels, demux_res.sample_rate, demux_res.sample_size); } /* will convert the entire buffer */ GetBuffer(&demux_res); stream_destroy(input_stream); if (output_opened) fclose(output_file); if (input_opened) fclose(input_file); return 0; }
/*--------------------------------------------------------------------------- | update_sample_info()/5 | | update_sample_info - | Takes a automation directory and filename of sample_info structure (e.g., doneQ,enterq,sampleinfo) | Searches through the file for a match between the match_target value | and the match_value; | Upon finding the match it then updates the update_target with the | update_value; | For example: You want to update the doneQ 'STATUS' entry to Complete, | for the experiment inwhich the DATA entry matches with | '/vnmr/auto/greg.1201' (i.e. DATA is a unique identifier). | The call would be: | update_sample_info("systemdir/auto","doneQ", | "DATA:","/vnmr/auto/greg.1201", | "STATUS","Complete"); | | Author: Greg Brissey 1/28/88 +--------------------------------------------------------------------------*/ int update_sample_info(char *autodir, char *filename, char *match_target, char *match_value, char *update_target, char *update_value) { FILE *update_file,*tmp_file; char filepath[128],value[MAX_TEXT_LEN]; struct sample_info sample_entry; int stat,entryline,foundit; strncpy(filepath,autodir,110); strcat(filepath,"/"); strcat(filepath,filename); /* if autoinfo mapping file hase not be read do so now */ if (infomap.mapped != 1) /* true if autoinfo has been read for mapping */ { read_info_file(autodir); } if (lockfile(filepath) == ERROR) /* lock file for excusive use */ { fprintf(stderr,"update_sample_info: could not lock '%s' file.\n",filepath); } update_file = fopen(filepath,"r"); if (update_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fprintf(stderr,"update_sample_info: '%s' file is not present for reading.\n", filepath); return(ERROR); } tmp_file = fopen("/tmp/update_sample_info.tmp","w"); if (tmp_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fclose(update_file); fprintf(stderr, "update_sample_info: temp file '/tmp/update_sample_info.tmp' could not be created.\n"); return(ERROR); } /* read through the the file writing to a tmp file as changes are made */ foundit = 0; while ( (stat = read_sample_info(update_file,&sample_entry)) != ENDOFFILE) { if (stat == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: read error on file '%s'.\n",filepath); return(ERROR); } /* Once found and changed we can skip all this */ if (!foundit) { get_sample_info(&sample_entry,match_target,value,MAX_TEXT_LEN,&entryline); if (strncmp(value,match_value,MAX_TEXT_LEN) == 0) { get_sample_info(&sample_entry,update_target,value,MAX_TEXT_LEN,&entryline); /* If updating STATUS and STATUS: Shimming, then remove this entry */ if ( (strcmp(infomap.status,update_target) == 0) && ( (strcmp(update_value,"Complete") == 0) || (strcmp(update_value,"Error") == 0)) && (strcmp(sample_entry.prompt_entry[entryline].etext,"Shimming") == 0) ) { /* elimenate Shimming Experiment from doneQ */ foundit = 1; continue; /* don't update, don't write it out */ } strncpy(sample_entry.prompt_entry[entryline].etext,update_value,MAX_TEXT_LEN); sample_entry.prompt_entry[entryline].etext[MAX_TEXT_LEN-1] = '\0'; foundit = 1; } } if (write_sample_info(tmp_file,&sample_entry) == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: write error to temp file '/tmp/update_sample_info.tmp'.\n"); return(ERROR); } } fclose(update_file); fclose(tmp_file); /* Changes are complete in the tmp file, now copy the tmp file into the orginal file */ tmp_file = fopen("/tmp/update_sample_info.tmp","r"); if (tmp_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fprintf(stderr, "update_sample_info: temp file '/tmp/update_sample_info.tmp' could not be opened to be read.\n"); return(ERROR); } update_file = fopen(filepath,"w"); if (update_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fclose(tmp_file); fprintf(stderr,"update_sample_info: '%s' file is not present for writing.\n", filepath); return(ERROR); } while ( ( stat = read_sample_info(tmp_file,&sample_entry)) != ENDOFFILE) { if (stat == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: read error on file '/tmp/update_sample_info.tmp'.\n"); return(ERROR); } if (write_sample_info(update_file,&sample_entry) == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: write error to file '%s'.\n",filepath); return(ERROR); } } fclose(update_file); fclose(tmp_file); unlockfile(filepath); /* unlock file */ return(OK); }
/* this is the codec entry point */ enum codec_status codec_main(void) { size_t n; demux_res_t demux_res; stream_t input_stream; uint32_t samplesdone; uint32_t elapsedtime; uint32_t sample_duration; uint32_t sample_byte_size; int samplesdecoded; unsigned int i; unsigned char* buffer; alac_file alac; int retval; /* Generic codec initialisation */ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1); next_track: if (codec_init()) { LOGF("ALAC: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; } while (!*ci->taginfo_ready && !ci->stop_codec) ci->sleep(1); ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); codec_set_replaygain(ci->id3); stream_create(&input_stream,ci); /* Read from ci->id3->offset before calling qtmovie_read. */ samplesdone = (uint32_t)(((uint64_t)(ci->id3->offset) * ci->id3->frequency) / (ci->id3->bitrate*128)); /* if qtmovie_read returns successfully, the stream is up to * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(&input_stream, &demux_res)) { LOGF("ALAC: Error initialising file\n"); retval = CODEC_ERROR; goto done; } /* initialise the sound converter */ create_alac(demux_res.sound_sample_size, demux_res.num_channels,&alac); alac_set_info(&alac, demux_res.codecdata); /* Set i for first frame, seek to desired sample position for resuming. */ i=0; if (samplesdone > 0) { if (alac_seek(&demux_res, &input_stream, samplesdone, &samplesdone, (int*) &i)) { elapsedtime = (samplesdone * 10) / (ci->id3->frequency / 100); ci->set_elapsed(elapsedtime); } else { samplesdone = 0; } } /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { ci->yield(); if (ci->stop_codec || ci->new_track) { break; } /* Deal with any pending seek requests */ if (ci->seek_time) { if (alac_seek(&demux_res, &input_stream, ((ci->seek_time-1)/10) * (ci->id3->frequency/100), &samplesdone, (int *)&i)) { elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); ci->set_elapsed(elapsedtime); } ci->seek_complete(); } /* Lookup the length (in samples and bytes) of block i */ if (!get_sample_info(&demux_res, i, &sample_duration, &sample_byte_size)) { LOGF("ALAC: Error in get_sample_info\n"); retval = CODEC_ERROR; goto done; } /* Request the required number of bytes from the input buffer */ buffer=ci->request_buffer(&n,sample_byte_size); if (n!=sample_byte_size) { retval = CODEC_ERROR; goto done; } /* Decode one block - returned samples will be host-endian */ ci->yield(); samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield); /* Advance codec buffer n bytes */ ci->advance_buffer(n); /* Output the audio */ ci->yield(); ci->pcmbuf_insert(outputbuffer[0], outputbuffer[1], samplesdecoded); /* Update the elapsed-time indicator */ samplesdone+=sample_duration; elapsedtime=(samplesdone*10)/(ci->id3->frequency/100); ci->set_elapsed(elapsedtime); i++; } retval = CODEC_OK; done: LOGF("ALAC: Decoded %ld samples\n",samplesdone); if (ci->request_next_track()) goto next_track; exit: return retval; }