static GslErrorType wave_handle_open (GslDataHandle *data_handle, GslDataHandleSetup *setup) { WaveHandle *whandle = (WaveHandle*) data_handle; whandle->hfile = gsl_hfile_open (whandle->dhandle.name); if (!whandle->hfile) return gsl_error_from_errno (errno, GSL_ERROR_OPEN_FAILED); else { GslLong l, fwidth = wave_format_byte_width (whandle->format); /* convert size into n_values, i.e. float length */ l = whandle->hfile->n_bytes; l -= MIN (l, whandle->byte_offset); if (l >= fwidth) { l /= fwidth; if (whandle->requested_length < 0) setup->n_values = l; else setup->n_values = MIN (l, whandle->requested_length); } else setup->n_values = 0; setup->n_channels = whandle->n_channels; setup->bit_depth = wave_format_bit_depth (whandle->format); return GSL_ERROR_NONE; } }
BseErrorType gsl_file_check (const gchar *file_name, const gchar *mode) { if (birnet_file_check (file_name, mode)) return BSE_ERROR_NONE; return gsl_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED); }
gint gsl_vorbis1_handle_read (GslVorbis1Handle *v1h, /* returns -errno || length */ guint blength, guint8 *buffer) { if (!v1h->rfile) { v1h->rfile = gsl_rfile_open (v1h->dhandle->name); if (!v1h->rfile) return gsl_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED); v1h->byte_length = gsl_rfile_length (v1h->rfile); if (v1h->rfile_add_zoffset) { v1h->byte_offset = gsl_hfile_zoffset (v1h->rfile->hfile) + 1; v1h->byte_offset += v1h->rfile_byte_offset; v1h->byte_offset = MIN (v1h->byte_offset, v1h->byte_length); v1h->byte_length -= v1h->byte_offset; } else { v1h->byte_offset = MIN (v1h->rfile_byte_offset, v1h->byte_length); v1h->byte_length -= v1h->byte_offset; } if (v1h->rfile_byte_length > 0) v1h->byte_length = MIN (v1h->byte_length, v1h->rfile_byte_length); v1h->vcutter = gsl_vorbis_cutter_new(); gsl_vorbis_cutter_filter_serialno (v1h->vcutter, v1h->bitstream_serialno); gsl_vorbis_cutter_force_serialno (v1h->vcutter, v1h->forced_serialno); } while (1) /* repeats until data is available */ { guint j, n = gsl_vorbis_cutter_read_ogg (v1h->vcutter, blength, buffer); if (n) return n; /* got data */ if (gsl_vorbis_cutter_ogg_eos (v1h->vcutter)) return 0; /* done at end-of-stream */ do /* need to feed data */ j = gsl_rfile_read (v1h->rfile, blength, buffer); while (j < 0 && errno == EINTR); if (j <= 0) /* bail on errors */ return errno ? -errno : -EIO; gsl_vorbis_cutter_write_ogg (v1h->vcutter, j, buffer); } }
static BseErrorType dh_vorbis_open (GslDataHandle *dhandle, GslDataHandleSetup *setup) { VorbisHandle *vhandle = (VorbisHandle*) dhandle; VFile *vfile; vorbis_info *vi; GslLong n, i; gint err; vfile = g_new0 (VFile, 1); vfile->rfile = gsl_rfile_open (vhandle->dhandle.name); if (!vfile->rfile) { g_free (vfile); return gsl_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED); } vfile->byte_length = gsl_rfile_length (vfile->rfile); if (vhandle->rfile_add_zoffset) { vfile->byte_offset = gsl_hfile_zoffset (vfile->rfile->hfile) + 1; vfile->byte_offset += vhandle->rfile_byte_offset; vfile->byte_offset = MIN (vfile->byte_offset, vfile->byte_length); vfile->byte_length -= vfile->byte_offset; } else { vfile->byte_offset = MIN (vhandle->rfile_byte_offset, vfile->byte_length); vfile->byte_length -= vfile->byte_offset; } if (vhandle->rfile_byte_length > 0) vfile->byte_length = MIN (vfile->byte_length, vhandle->rfile_byte_length); err = ov_open_callbacks (vfile, &vhandle->ofile, NULL, 0, vfile_ov_callbacks); if (err < 0) { if (0) g_printerr ("failed to open ogg at offset %d (real offset=%lld) (add-zoffset=%d): %s\n", vhandle->rfile_byte_offset, vfile->byte_offset, vhandle->rfile_add_zoffset, bse_error_blurb (ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED))); vfile_close (vfile); return ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED); } n = ov_streams (&vhandle->ofile); if (n > vhandle->bitstream) { vhandle->bitstream_serialno = ov_serialnumber (&vhandle->ofile, vhandle->bitstream); vhandle->n_bitstreams = n; if (0) g_printerr ("Ogg/Vorbis: opening ogg: bitstream=%d/%d serialno=%d\n", vhandle->bitstream, vhandle->n_bitstreams, vhandle->bitstream_serialno); } else { ov_clear (&vhandle->ofile); /* closes file */ return BSE_ERROR_NO_DATA; /* requested bitstream not available */ } vhandle->soffset = 0; for (i = 0; i < vhandle->bitstream; i++) vhandle->soffset += ov_pcm_total (&vhandle->ofile, i); n = ov_pcm_total (&vhandle->ofile, vhandle->bitstream); vi = ov_info (&vhandle->ofile, vhandle->bitstream); if (n > 0 && vi && vi->channels && ov_pcm_seek (&vhandle->ofile, vhandle->soffset) >= 0) { setup->n_channels = vi->channels; setup->n_values = n * setup->n_channels; } else { ov_clear (&vhandle->ofile); /* closes file */ return BSE_ERROR_NO_DATA; } vhandle->max_block_size = vorbis_info_blocksize (vi, 0); n = vorbis_info_blocksize (vi, 1); vhandle->max_block_size = MAX (vhandle->max_block_size, n); vhandle->pcm_pos = 0; vhandle->pcm_length = 0; setup->bit_depth = 24; setup->mix_freq = vi->rate; setup->needs_cache = TRUE; setup->xinfos = bse_xinfos_add_float (setup->xinfos, "osc-freq", vhandle->osc_freq); return BSE_ERROR_NONE; }