Lines Matching refs:rsrc
92 static int parse_str_rsrc (SF_PRIVATE *psf, SD2_RSRC * rsrc) ;
112 { psf_log_printf (psf, "sd2_open : psf->rsrc.filedes < 0\n") ;
132 { psf->rsrc.mode = psf->file.mode ;
192 { SD2_RSRC rsrc ;
204 memset (&rsrc, 0, sizeof (rsrc)) ;
206 rsrc.sample_rate = psf->sf.samplerate ;
207 rsrc.sample_size = psf->bytewidth ;
208 rsrc.channels = psf->sf.channels ;
210 rsrc.rsrc_data = psf->header.ptr ;
211 rsrc.rsrc_len = psf->header.len ;
212 memset (rsrc.rsrc_data, 0xea, rsrc.rsrc_len) ;
214 snprintf (str_rsrc [0].value, sizeof (str_rsrc [0].value), "_%d", rsrc.sample_size) ;
215 snprintf (str_rsrc [1].value, sizeof (str_rsrc [1].value), "_%d.000000", rsrc.sample_rate) ;
216 snprintf (str_rsrc [2].value, sizeof (str_rsrc [2].value), "_%d", rsrc.channels) ;
228 rsrc.data_offset = 0x100 ;
234 rsrc.data_length = 0 ;
236 rsrc.data_length += str_rsrc [k].value_len + 4 ;
238 rsrc.map_offset = rsrc.data_offset + rsrc.data_length ;
241 psf_binheader_writef (psf, "E444", BHW4 (rsrc.data_offset), BHW4 (rsrc.map_offset), BHW4 (rsrc.data_length)) ;
247 psf_binheader_writef (psf, "E4444", BHW4 (rsrc.map_offset), BHW4 (rsrc.data_offset), BHW4 (rsrc.map_offset), BHW4 (rsrc.data_length)) ;
251 { psf_binheader_writef (psf, "Eo1422", BHWo (rsrc.map_offset + 16), BHW1 (1), BHW4 (0x12345678), BHW2 (0xabcd), BHW2 (0)) ;
255 rsrc.type_offset = rsrc.map_offset + 30 ;
256 psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 24), BHW2 (rsrc.type_offset - rsrc.map_offset - 2)) ;
259 rsrc.type_count = 2 ;
260 psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 28), BHW2 (rsrc.type_count - 1)) ;
262 rsrc.item_offset = rsrc.type_offset + rsrc.type_count * 8 ;
264 rsrc.str_count = ARRAY_LEN (str_rsrc) ;
265 rsrc.string_offset = rsrc.item_offset + (rsrc.str_count + 1) * 12 - rsrc.map_offset ;
266 psf_binheader_writef (psf, "Eo2", BHWo (rsrc.map_offset + 26), BHW2 (rsrc.string_offset)) ;
269 rsrc.str_count = 3 ;
270 psf_binheader_writef (psf, "Eom22", BHWo (rsrc.type_offset), BHWm (STR_MARKER), BHW2 (rsrc.str_count - 1), BHW2 (0x12)) ;
275 str_offset = rsrc.map_offset + rsrc.string_offset ;
277 data_offset = rsrc.data_offset ;
280 psf_binheader_writef (psf, "Eo22", BHWo (rsrc.item_offset + k * 12), BHW2 (str_rsrc [k].id), BHW2 (next_str)) ;
285 psf_binheader_writef (psf, "Eo4", BHWo (rsrc.item_offset + k * 12 + 4), BHW4 (data_offset - rsrc.data_offset)) ;
293 rsrc.map_length = str_offset - rsrc.map_offset ;
294 psf_binheader_writef (psf, "Eo4o4", BHWo (12), BHW4 (rsrc.map_length),
295 BHWo (rsrc.map_offset + 12), BHW4 (rsrc.map_length)) ;
297 psf->header.indx = rsrc.map_offset + rsrc.map_length ;
371 { SD2_RSRC rsrc ;
376 memset (&rsrc, 0, sizeof (rsrc)) ;
378 rsrc.rsrc_len = psf_get_filelen (psf) ;
379 psf_log_printf (psf, "Resource length : %d (0x%04X)\n", rsrc.rsrc_len, rsrc.rsrc_len) ;
381 if (rsrc.rsrc_len > psf->header.len)
382 { rsrc.rsrc_data = calloc (1, rsrc.rsrc_len) ;
383 rsrc.need_to_free_rsrc_data = SF_TRUE ;
387 rsrc.rsrc_data = psf->header.ptr ;
388 // rsrc.rsrc_len > psf->header.len ;
389 rsrc.need_to_free_rsrc_data = SF_FALSE ;
393 psf_fread (rsrc.rsrc_data, rsrc.rsrc_len, 1, psf) ;
396 psf->header.indx = psf->header.end = rsrc.rsrc_len ;
398 rsrc.data_offset = read_rsrc_int (&rsrc, 0) ;
399 rsrc.map_offset = read_rsrc_int (&rsrc, 4) ;
400 rsrc.data_length = read_rsrc_int (&rsrc, 8) ;
401 rsrc.map_length = read_rsrc_int (&rsrc, 12) ;
403 if (rsrc.data_offset == 0x51607 && rsrc.map_offset == 0x20000)
405 rsrc.data_offset = read_rsrc_int (&rsrc, 0x52 + 0) + 0x52 ;
406 rsrc.map_offset = read_rsrc_int (&rsrc, 0x52 + 4) + 0x52 ;
407 rsrc.data_length = read_rsrc_int (&rsrc, 0x52 + 8) ;
408 rsrc.map_length = read_rsrc_int (&rsrc, 0x52 + 12) ;
413 rsrc.data_offset, rsrc.map_offset, rsrc.data_length, rsrc.map_length) ;
415 if (rsrc.data_offset > rsrc.rsrc_len)
416 { psf_log_printf (psf, "Error : rsrc.data_offset (%d, 0x%x) > len\n", rsrc.data_offset, rsrc.data_offset) ;
421 if (rsrc.map_offset > rsrc.rsrc_len)
422 { psf_log_printf (psf, "Error : rsrc.map_offset > len\n") ;
427 if (rsrc.data_length > rsrc.rsrc_len)
428 { psf_log_printf (psf, "Error : rsrc.data_length > len\n") ;
433 if (rsrc.map_length > rsrc.rsrc_len)
434 { psf_log_printf (psf, "Error : rsrc.map_length > len\n") ;
439 if (rsrc.data_offset + rsrc.data_length != rsrc.map_offset || rsrc.map_offset + rsrc.map_length != rsrc.rsrc_len)
445 if (rsrc.map_offset + 28 >= rsrc.rsrc_len)
446 { psf_log_printf (psf, "Bad map offset (%d + 28 > %d).\n", rsrc.map_offset, rsrc.rsrc_len) ;
451 rsrc.string_offset = rsrc.map_offset + read_rsrc_short (&rsrc, rsrc.map_offset + 26) ;
452 if (rsrc.string_offset > rsrc.rsrc_len)
453 { psf_log_printf (psf, "Bad string offset (%d).\n", rsrc.string_offset) ;
458 rsrc.type_offset = rsrc.map_offset + 30 ;
460 if (rsrc.map_offset + 28 > rsrc.rsrc_len)
465 rsrc.type_count = read_rsrc_short (&rsrc, rsrc.map_offset + 28) + 1 ;
466 if (rsrc.type_count < 1)
472 rsrc.item_offset = rsrc.type_offset + rsrc.type_count * 8 ;
473 if (rsrc.item_offset < 0 || rsrc.item_offset > rsrc.rsrc_len)
474 { psf_log_printf (psf, "Bad item offset (%d).\n", rsrc.item_offset) ;
479 rsrc.str_index = -1 ;
480 for (k = 0 ; k < rsrc.type_count ; k ++)
481 { if (rsrc.type_offset + k * 8 > rsrc.rsrc_len)
482 { psf_log_printf (psf, "Bad rsrc marker.\n") ;
486 marker = read_rsrc_marker (&rsrc, rsrc.type_offset + k * 8) ;
489 { rsrc.str_index = k ;
490 rsrc.str_count = read_rsrc_short (&rsrc, rsrc.type_offset + k * 8 + 4) + 1 ;
491 error = parse_str_rsrc (psf, &rsrc) ;
503 if (rsrc.need_to_free_rsrc_data)
504 free (rsrc.rsrc_data) ;
510 parse_str_rsrc (SF_PRIVATE *psf, SD2_RSRC * rsrc)
516 str_offset = rsrc->string_offset ;
520 for (k = 0 ; data_offset + data_len < rsrc->rsrc_len ; k++)
523 slen = read_rsrc_char (rsrc, str_offset) ;
524 read_rsrc_str (rsrc, str_offset + 1, name, SF_MIN (SIGNED_SIZEOF (name), slen + 1)) ;
528 int id_offset = rsrc->item_offset + k * 12 ;
529 if (id_offset < 0 || id_offset + 1 >= rsrc->rsrc_len)
533 rsrc_id = read_rsrc_short (rsrc, id_offset) ;
535 data_offset = rsrc->data_offset + read_rsrc_int (rsrc, rsrc->item_offset + k * 12 + 4) ;
536 if (data_offset < 0 || data_offset > rsrc->rsrc_len)
541 data_len = read_rsrc_int (rsrc, data_offset) ;
542 if (data_len < 0 || data_len > rsrc->rsrc_len)
547 slen = read_rsrc_char (rsrc, data_offset + 4) ;
548 read_rsrc_str (rsrc, data_offset + 5, value, SF_MIN (SIGNED_SIZEOF (value), slen + 1)) ;
557 if (rsrc_id == 1000 && rsrc->sample_size == 0)
558 rsrc->sample_size = strtol (value, NULL, 10) ;
559 else if (rsrc_id == 1001 && rsrc->sample_rate == 0)
560 rsrc->sample_rate = strtol (value, NULL, 10) ;
561 else if (rsrc_id == 1002 && rsrc->channels == 0)
562 rsrc->channels = strtol (value, NULL, 10) ;
566 psf_log_printf (psf, " sample-size : %d\n", rsrc->sample_size) ;
567 psf_log_printf (psf, " sample-rate : %d\n", rsrc->sample_rate) ;
568 psf_log_printf (psf, " channels : %d\n", rsrc->channels) ;
570 if (rsrc->sample_rate <= 4 && rsrc->sample_size > 4)
574 temp = rsrc->sample_rate ;
575 rsrc->sample_rate = rsrc->sample_size ;
576 rsrc->sample_size = temp ;
579 if (rsrc->sample_rate < 0)
580 { psf_log_printf (psf, "Bad sample rate (%d)\n", rsrc->sample_rate) ;
584 if (rsrc->channels < 0)
585 { psf_log_printf (psf, "Bad channel count (%d)\n", rsrc->channels) ;
589 psf->sf.samplerate = rsrc->sample_rate ;
590 psf->sf.channels = rsrc->channels ;
591 psf->bytewidth = rsrc->sample_size ;
593 switch (rsrc->sample_size)
611 psf_log_printf (psf, "Bad sample size (%d)\n", rsrc->sample_size) ;