public static void load_translation(emu_options m_options) { g_translation.Clear(); emu_file file = new emu_file(m_options.language_path(), global_object.OPEN_FLAG_READ); var name = m_options.language(); name = name.Replace(" ", "_"); name = name.Replace("(", ""); name = name.Replace(")", ""); if (file.open(name, global_object.PATH_SEPARATOR + "strings.mo") == osd_file.error.NONE) { uint64_t size = file.size(); RawBuffer buffer = new RawBuffer(4 * (int)size / 4 + 1); //uint32_t *buffer = global_alloc_array(uint32_t, size / 4 + 1); file.read(new ListBytesPointer(buffer), (UInt32)size); file.close(); if (buffer.get_uint32(0) != MO_MAGIC && buffer.get_uint32(0) != MO_MAGIC_REVERSED) { buffer = null; //global_free_array(buffer); return; } if (buffer.get_uint32(0) == MO_MAGIC_REVERSED) { for (var i = 0; i < ((int)size / 4) + 1; ++i) { buffer.set_uint32(i, endianchange(buffer[i])); } } uint32_t number_of_strings = buffer.get_uint32(2); uint32_t original_table_offset = buffer.get_uint32(3) >> 2; uint32_t translation_table_offset = buffer.get_uint32(4) >> 2; RawBuffer data = buffer; //const char *data = reinterpret_cast<const char*>(buffer); for (var i = 1; i < number_of_strings; ++i) { string original = "TODO original"; //(const char *)data + buffer[original_table_offset + 2 * i + 1]; string translation = "TODO translation"; //(const char *)data + buffer[translation_table_offset + 2 * i + 1]; g_translation.emplace(original, translation); } buffer = null; //global_free_array(buffer); } }
// moved to device_sound_interface_samples // device_sound_interface overrides //virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); // internal helpers //------------------------------------------------- // read_wav_sample - read a WAV file as a sample //------------------------------------------------- static bool read_wav_sample(emu_file file, sample_t sample) { // we already read the opening 'RIFF' tag uint32_t offset = 4; // get the total size uint32_t filesize; RawBuffer filesizeBuffer = new RawBuffer(4); offset += file.read(new ListBytesPointer(filesizeBuffer), 4); if (offset < 8) { osd_printf_warning("Unexpected size offset {0} ({1})\n", offset, file.filename()); return(false); } filesize = filesizeBuffer.get_uint32(); filesize = little_endianize_int32(filesize); // read the RIFF file type and make sure it's a WAVE file RawBuffer buf = new RawBuffer(32); //char [] buf = new char[32]; offset += file.read(new ListBytesPointer(buf), 4); if (offset < 12) { osd_printf_warning("Unexpected WAVE offset {0} ({1})\n", offset, file.filename()); return(false); } if (!(buf[0] == 'W' && buf[1] == 'A' && buf[2] == 'V' && buf[3] == 'E')) // memcmp(&buf[0], "WAVE", 4) != 0) { osd_printf_warning("Could not find WAVE header ({0})\n", file.filename()); return(false); } // seek until we find a format tag uint32_t length; RawBuffer lengthBuffer = new RawBuffer(4); while (true) { offset += file.read(new ListBytesPointer(buf), 4); offset += file.read(new ListBytesPointer(lengthBuffer), 4); length = lengthBuffer.get_uint32(); length = little_endianize_int32(length); if (buf[0] == 'f' && buf[1] == 'm' && buf[2] == 't' && buf[3] == ' ') //if (memcmp(&buf[0], "fmt ", 4) == 0) { break; } // seek to the next block file.seek(length, emu_file.SEEK_CUR); offset += length; if (offset >= filesize) { osd_printf_warning("Could not find fmt tag ({0})\n", file.filename()); return(false); } } // read the format -- make sure it is PCM uint16_t temp16; RawBuffer temp16Buffer = new RawBuffer(2); offset += file.read(new ListBytesPointer(temp16Buffer), 2); temp16 = temp16Buffer.get_uint16(); temp16 = little_endianize_int16(temp16); if (temp16 != 1) { osd_printf_warning("unsupported format {0} - only PCM is supported ({1})\n", temp16, file.filename()); return(false); } // number of channels -- only mono is supported offset += file.read(new ListBytesPointer(temp16Buffer), 2); temp16 = temp16Buffer.get_uint16(); temp16 = little_endianize_int16(temp16); if (temp16 != 1) { osd_printf_warning("unsupported number of channels {0} - only mono is supported ({1})\n", temp16, file.filename()); return(false); } // sample rate uint32_t rate; RawBuffer rateBuffer = new RawBuffer(4); offset += file.read(new ListBytesPointer(rateBuffer), 4); rate = rateBuffer.get_uint32(); rate = little_endianize_int32(rate); // bytes/second and block alignment are ignored offset += file.read(new ListBytesPointer(buf), 6); // bits/sample uint16_t bits; RawBuffer bitsBuffer = new RawBuffer(2); offset += file.read(new ListBytesPointer(bitsBuffer), 2); bits = bitsBuffer.get_uint16(); bits = little_endianize_int16(bits); if (bits != 8 && bits != 16) { osd_printf_warning("unsupported bits/sample {0} - only 8 and 16 are supported ({1})\n", bits, file.filename()); return(false); } // seek past any extra data file.seek(length - 16, emu_file.SEEK_CUR); offset += length - 16; // seek until we find a data tag while (true) { offset += file.read(new ListBytesPointer(buf), 4); offset += file.read(new ListBytesPointer(lengthBuffer), 4); length = lengthBuffer.get_uint32(); length = little_endianize_int32(length); if (buf[0] == 'd' && buf[1] == 'a' && buf[2] == 't' && buf[3] == 'a') //if (memcmp(&buf[0], "data", 4) == 0) { break; } // seek to the next block file.seek(length, emu_file.SEEK_CUR); offset += length; if (offset >= filesize) { osd_printf_warning("Could not find data tag ({0})\n", file.filename()); return(false); } } // if there was a 0 length data block, we're done if (length == 0) { osd_printf_warning("empty data block ({0})\n", file.filename()); return(false); } // fill in the sample data sample.frequency = rate; // read the data in if (bits == 8) { sample.data.resize((int)length); RawBuffer sample_data_8bit = new RawBuffer(length); file.read(new ListBytesPointer(sample_data_8bit), length); // convert 8-bit data to signed samples ListBytesPointer tempptr = new ListBytesPointer(sample_data_8bit); //uint8_t *tempptr = reinterpret_cast<uint8_t *>(&sample.data[0]); for (int sindex = (int)length - 1; sindex >= 0; sindex--) { sample.data[sindex] = (Int16)((sbyte)(tempptr[sindex] ^ 0x80) * 256); } } else { // 16-bit data is fine as-is sample.data.resize((int)length / 2); RawBuffer sample_data_8bit = new RawBuffer(length); file.read(new ListBytesPointer(sample_data_8bit), length); // swap high/low on big-endian systems if (ENDIANNESS_NATIVE != endianness_t.ENDIANNESS_LITTLE) { for (UInt32 sindex = 0; sindex < length / 2; sindex++) { sample.data[sindex] = (Int16)little_endianize_int16(sample_data_8bit.get_uint16((int)sindex)); //sample.data[sindex]); } } } return(true); }