int file32_write(const string& name, const void* s, int cb_s) { Cfile32 f; if (int error = f.open_write(name)) return error; return f.write(s, cb_s); }
int Caud_file::extract_as_wav(const string& name) { Cvirtual_binary d = decode(); if (!d.data()) return 1; Cfile32 f; int error = f.open(name, GENERIC_WRITE); if (error) return error; int cb_sample = get_cb_sample(); int cs_remaining = get_c_samples(); t_wav_header header; memset(&header, 0, sizeof(t_wav_header)); header.file_header.id = wav_file_id; header.file_header.size = sizeof(header) - sizeof(header.file_header) + (cs_remaining << 1); header.form_type = wav_form_id; header.format_chunk.header.id = wav_format_id; header.format_chunk.header.size = sizeof(header.format_chunk) - sizeof(header.format_chunk.header); header.format_chunk.formattag = 1; header.format_chunk.c_channels = 1; header.format_chunk.samplerate = get_samplerate(); header.format_chunk.byterate = cb_sample * get_samplerate(); header.format_chunk.blockalign = cb_sample; header.format_chunk.cbits_sample = cb_sample << 3; header.data_chunk_header.id = wav_data_id; header.data_chunk_header.size = cb_sample * cs_remaining; error = f.write(&header, sizeof(t_wav_header)); return error ? error : f.write(d); }
int Cvirtual_file::save(const string& fname) const { Cfile32 f; int error = f.open_write(fname); if (!error) { for (auto& i : m_data) error = f.write(i); } return error; }
static int copy_block(Cfile32& s, int s_p, Cfile32& d, int d_p, int size) { Cvirtual_binary buffer; while (size) { int cb_buffer = min(size, 4 << 20); s.seek(s_p); if (int e = s.read(buffer.write_start(cb_buffer), cb_buffer)) return e; d.seek(d_p); if (int e = d.write(buffer.data(), cb_buffer)) return e; s_p += cb_buffer; d_p += cb_buffer; size -= cb_buffer; } return 0; }
Cvirtual_binary file32_read(const string& name) { Cfile32 f; return f.open_read(name) ? Cvirtual_binary() : f.get_mm(); }