static int quicktimedrv_close(screenshot_t *screenshot) { OSStatus theError; finish_video(); if (audio_codec != -1) { soundmovie_stop(); finish_audio(); } //Write movie theError = AddMovieToStorage(movie, dataHandler); if (theError) { log_debug("quicktime: error adding movie to storage!"); } //Close movie file if (dataHandler) { CloseMovieStorage(dataHandler); } if (movie) { DisposeMovie(movie); } movie = NULL; dataHandler = NULL; return 0; }
double sound_save( LVAL snd_expr, long n, unsigned char *filename, long format, long mode, long bits, long swap, double *sr, long *nchans, double *duration, LVAL play) { LVAL result; float *buf; long ntotal; double max_sample; SNDFILE *sndfile = NULL; SF_INFO sf_info; PaStream *audio_stream = NULL; if (SAFE_NYQUIST) play = FALSE; gc(); memset(&sf_info, 0, sizeof(sf_info)); sf_info.format = lookup_format(format, mode, bits, swap); result = xleval(snd_expr); /* BE CAREFUL - DO NOT ALLOW GC TO RUN WHILE RESULT IS UNPROTECTED */ if (vectorp(result)) { /* make sure all elements are of type a_sound */ long i = getsize(result); *nchans = sf_info.channels = i; while (i > 0) { i--; if (!exttypep(getelement(result, i), a_sound)) { xlerror("sound_save: array has non-sound element", result); } } /* assume all are the same: */ *sr = sf_info.samplerate = ROUND(getsound(getelement(result, 0))->sr); /* note: if filename is "", then don't write file; therefore, * write the file if (filename[0]) */ if (filename[0]) { sndfile = NULL; if (ok_to_open((char *) filename, "wb")) sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); if (sndfile) { /* use proper scale factor: 8000 vs 7FFF */ sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE); } } if (play) play = prepare_audio(play, &sf_info, &audio_stream); if ((buf = (float *) malloc(max_sample_block_len * sf_info.channels * sizeof(float))) == NULL) { xlabort("snd_save -- couldn't allocate memory"); } max_sample = sound_save_array(result, n, &sf_info, sndfile, buf, &ntotal, audio_stream); *duration = ntotal / *sr; if (sndfile) sf_close(sndfile); if (play != NIL) finish_audio(audio_stream); } else if (exttypep(result, a_sound)) { *nchans = sf_info.channels = 1; sf_info.samplerate = ROUND((getsound(result))->sr); *sr = sf_info.samplerate; if (filename[0]) { sndfile = NULL; if (ok_to_open((char *) filename, "wb")) { sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); if (sndfile) { /* use proper scale factor: 8000 vs 7FFF */ sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE); } else { char error[240]; sprintf(error, "snd_save -- %s", sf_error_number(sf_error(sndfile))); xlabort(error); } } else { xlabort("snd_save -- write not permitted by -W option"); } } if (play) play = prepare_audio(play, &sf_info, &audio_stream); if ((buf = (float *) malloc(max_sample_block_len * sizeof(float))) == NULL) { xlabort("snd_save -- couldn't allocate memory"); } max_sample = sound_save_sound(result, n, &sf_info, sndfile, buf, &ntotal, audio_stream); *duration = ntotal / *sr; if (sndfile) sf_close(sndfile); if (play != NIL) finish_audio(audio_stream); } else { xlerror("sound_save: expression did not return a sound", result); max_sample = 0.0; } free(buf); return max_sample; }
double sound_save( LVAL snd_expr, long n, unsigned char *filename, long format, long mode, long bits, long swap, double *sr, long *nchans, double *duration, LVAL play) { LVAL result; char *buf; long ntotal; double max_sample; snd_node snd; snd_node player; long flags; snd.device = SND_DEVICE_FILE; snd.write_flag = SND_WRITE; strcpy(snd.u.file.filename, (char *) filename); snd.u.file.file = -1; /* this is a marker that snd is unopened */ snd.u.file.header = format; snd.format.mode = mode; snd.format.bits = bits; snd.u.file.swap = swap; player.device = SND_DEVICE_AUDIO; player.write_flag = SND_WRITE; player.u.audio.devicename[0] = '\0'; player.u.audio.descriptor = NULL; player.u.audio.protocol = SND_COMPUTEAHEAD; player.u.audio.latency = 1.0; player.u.audio.granularity = 0.0; if ((buf = (char *) malloc(max_sample_block_len * MAX_SND_CHANNELS * sizeof(float))) == NULL) { xlabort("snd_save -- couldn't allocate memory"); } result = xleval(snd_expr); /* BE CAREFUL - DO NOT ALLOW GC TO RUN WHILE RESULT IS UNPROTECTED */ if (vectorp(result)) { /* make sure all elements are of type a_sound */ long i = getsize(result); *nchans = snd.format.channels = i; while (i > 0) { i--; if (!exttypep(getelement(result, i), a_sound)) { xlerror("sound_save: array has non-sound element", result); } } /* assume all are the same: */ *sr = snd.format.srate = getsound(getelement(result, 0))->sr; /* note: if filename is "", then don't write file; therefore, * write the file if (filename[0]) */ if (filename[0] && snd_open(&snd, &flags) != SND_SUCCESS) { xlabort("snd_save -- could not open sound file"); } play = prepare_audio(play, &snd, &player); max_sample = sound_save_array(result, n, &snd, buf, &ntotal, (play == NIL ? NULL : &player)); *duration = ntotal / *sr; if (filename[0]) snd_close(&snd); if (play != NIL) finish_audio(&player); } else if (exttypep(result, a_sound)) { *nchans = snd.format.channels = 1; *sr = snd.format.srate = (getsound(result))->sr; if (filename[0] && snd_open(&snd, &flags) != SND_SUCCESS) { xlabort("snd_save -- could not open sound file"); } play = prepare_audio(play, &snd, &player); max_sample = sound_save_sound(result, n, &snd, buf, &ntotal, (play == NIL ? NULL : &player)); *duration = ntotal / *sr; if (filename[0]) snd_close(&snd); if (play != NIL) finish_audio(&player); } else { xlerror("sound_save: expression did not return a sound", result); max_sample = 0.0; } free(buf); return max_sample; }