rec = remote = false;
}
-void CMT::write_buffer(uint8 value, int samples)
+void CMT::write_buffer(uint8_t value, int samples)
{
if(is_wav) {
for(int i = 0; i < samples; i++) {
void CMT::put_signal()
{
if(rec && remote) {
- uint32 clock = passed_clock(prev_clock);
+ uint32_t clock = get_passed_clock(prev_clock);
if(prev_signal == 1) {
// 2400Hz
int count = (int)(1200.0 * (double)clock / (double)CPU_CLOCKS + 0.5) * 2;
}
}
-void CMT::write_signal(int id, uint32 data, uint32 mask)
+void CMT::write_signal(int id, uint32_t data, uint32_t mask)
{
bool next = ((data & mask) != 0);
if(!remote && next) {
// start
prev_signal = 0;
- prev_clock = current_clock();
+ prev_clock = get_current_clock();
} else if(remote && !next) {
// stop
put_signal();
put_signal();
}
prev_signal = next ? 1 : -1;
- prev_clock = current_clock();
+ prev_clock = get_current_clock();
}
}
if(fio->Fopen(file_path, FILEIO_WRITE_BINARY)) {
my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
if(check_file_extension(file_path, _T(".wav"))) {
- uint8 dummy[sizeof(wav_header_t) + sizeof(wav_chunk_t)];
- memset(dummy, 0, sizeof(dummy));
- fio->Fwrite(dummy, sizeof(dummy), 1);
+ write_dummy_wav_header((void *)fio);
is_wav = true;
}
bufcnt = 0;
fio->Fwrite(buffer, bufcnt, 1);
}
if(is_wav) {
- uint32 length = fio->Ftell();
-
+ uint32_t length = fio->Ftell();
wav_header_t wav_header;
wav_chunk_t wav_chunk;
+#if 0
+ pair_t __riff_chunk_size;
+ pair_t __fmt_chunk_size;
+ pair_t __wav_chunk_size;
+ pair16_t __fmt_id;
+ pair16_t __channels;
+ pair_t __sample_rate;
+ pair16_t __block_size;
+ pair16_t __sample_bits;
+
+ __riff_chunk_size.d = length - 8;
+ __fmt_chunk_size.d = 16;
+ __fmt_id.w = 1;
+ __channels.w = 1;
+ __sample_rate.d = SAMPLE_RATE;
+ __block_size.w = 1;
+ __sample_bits.w = 8;
+
memcpy(wav_header.riff_chunk.id, "RIFF", 4);
- wav_header.riff_chunk.size = length - 8;
+ wav_header.riff_chunk.size = __riff_chunk_size.get_4bytes_le_to();
+
memcpy(wav_header.wave, "WAVE", 4);
memcpy(wav_header.fmt_chunk.id, "fmt ", 4);
- wav_header.fmt_chunk.size = 16;
- wav_header.format_id = 1;
- wav_header.channels = 1;
- wav_header.sample_rate = SAMPLE_RATE;
- wav_header.data_speed = SAMPLE_RATE;
- wav_header.block_size = 1;
- wav_header.sample_bits = 8;
-
+ wav_header.fmt_chunk.size = __riff_chunk_size.get_4bytes_le_to();
+ wav_header.format_id = __fmt_id.get_2bytes_le_to();
+ wav_header.channels = __channels.get_2byte_le_to();
+ wav_header.sample_rate = __sample_rate.get_4bytes_le_to();
+ wav_header.data_speed = __sample_rate.get_4bytes_le_to();
+ wav_header.block_size = __block_size.get_2bytes_le_to();
+ wav_header.sample_bits = __sample_bits_get_2bytes_le_to();
+
memcpy(wav_chunk.id, "data", 4);
- wav_chunk.size = length - sizeof(wav_header) - sizeof(wav_chunk);
+ __wav_chunk_size.d = length - sizeof(wav_header) - sizeof(wav_chunk);
+ wav_chunk.size = __wav_chunk_size.get_4bytes_le_to();
+
fio->Fseek(0, FILEIO_SEEK_SET);
fio->Fwrite(&wav_header, sizeof(wav_header), 1);
fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
+#else
+ if(set_wav_header(&wav_header, &wav_chunk, 1, SAMPLE_RATE, 8, length)) {
+ fio->Fseek(0, FILEIO_SEEK_SET);
+ fio->Fwrite(&wav_header, sizeof(wav_header), 1);
+ fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
+ }
+#endif
}
fio->Fclose();
}
#define STATE_VERSION 1
-void CMT::save_state(FILEIO* state_fio)
+#include "../../statesub.h"
+
+void CMT::decl_state()
{
- state_fio->FputUint32(STATE_VERSION);
- state_fio->FputInt32(this_device_id);
+ enter_decl_state(STATE_VERSION);
+
+ DECL_STATE_ENTRY_BOOL(is_wav);
+ DECL_STATE_ENTRY_BOOL(rec);
+ DECL_STATE_ENTRY_BOOL(remote);
+ DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
+ DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
- state_fio->FputBool(is_wav);
- state_fio->FputBool(rec);
- state_fio->FputBool(remote);
- state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
- if(rec && fio->IsOpened()) {
- int length_tmp = (int)fio->Ftell();
- fio->Fseek(0, FILEIO_SEEK_SET);
- state_fio->FputInt32(length_tmp);
- while(length_tmp != 0) {
- uint8 buffer_tmp[1024];
- int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
- fio->Fread(buffer_tmp, length_rw, 1);
- state_fio->Fwrite(buffer_tmp, length_rw, 1);
- length_tmp -= length_rw;
- }
- } else {
- state_fio->FputInt32(0);
+ DECL_STATE_ENTRY_INT32(bufcnt);
+ DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+ DECL_STATE_ENTRY_INT32(prev_signal);
+ DECL_STATE_ENTRY_UINT32(prev_clock);
+
+ leave_decl_state();
+}
+
+void CMT::save_state(FILEIO* state_fio)
+{
+ if(state_entry != NULL) {
+ state_entry->save_state(state_fio);
}
- state_fio->FputInt32(bufcnt);
- state_fio->Fwrite(buffer, sizeof(buffer), 1);
- state_fio->FputInt32(prev_signal);
- state_fio->FputUint32(prev_clock);
+// state_fio->FputUint32(STATE_VERSION);
+// state_fio->FputInt32(this_device_id);
+//
+// state_fio->FputBool(is_wav);
+// state_fio->FputBool(rec);
+// state_fio->FputBool(remote);
+// state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
+// if(rec && fio->IsOpened()) {
+// int length_tmp = (int)fio->Ftell();
+// fio->Fseek(0, FILEIO_SEEK_SET);
+// state_fio->FputInt32(length_tmp);
+// while(length_tmp != 0) {
+// uint8_t buffer_tmp[1024];
+// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+// fio->Fread(buffer_tmp, length_rw, 1);
+// state_fio->Fwrite(buffer_tmp, length_rw, 1);
+// length_tmp -= length_rw;
+// }
+// } else {
+// state_fio->FputInt32(0);
+// }
+// state_fio->FputInt32(bufcnt);
+// state_fio->Fwrite(buffer, sizeof(buffer), 1);
+// state_fio->FputInt32(prev_signal);
+// state_fio->FputUint32(prev_clock);
}
bool CMT::load_state(FILEIO* state_fio)
{
close_tape();
- if(state_fio->FgetUint32() != STATE_VERSION) {
+ bool mb = false;
+ if(state_entry != NULL) {
+ mb = state_entry->load_state(state_fio);
+ }
+ if(!mb) {
return false;
}
- if(state_fio->FgetInt32() != this_device_id) {
+// if(state_fio->FgetUint32() != STATE_VERSION) {
+// return false;
+// }
+// if(state_fio->FgetInt32() != this_device_id) {
+// return false;
+// }
+// is_wav = state_fio->FgetBool();
+// rec = state_fio->FgetBool();
+// remote = state_fio->FgetBool();
+// state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
+// int length_tmp = state_fio->FgetInt32();
+// if(rec) {
+// fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+// while(length_tmp != 0) {
+// uint8_t buffer_tmp[1024];
+// int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+// state_fio->Fread(buffer_tmp, length_rw, 1);
+// if(fio->IsOpened()) {
+// fio->Fwrite(buffer_tmp, length_rw, 1);
+// }
+// length_tmp -= length_rw;
+// }
+// }
+// bufcnt = state_fio->FgetInt32();
+// state_fio->Fread(buffer, sizeof(buffer), 1);
+// prev_signal = state_fio->FgetInt32();
+// prev_clock = state_fio->FgetUint32();
+ return true;
+}
+
+bool CMT::process_state(FILEIO* state_fio, bool loading)
+{
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
return false;
}
- is_wav = state_fio->FgetBool();
- rec = state_fio->FgetBool();
- remote = state_fio->FgetBool();
- state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
- int length_tmp = state_fio->FgetInt32();
- if(rec) {
- fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
- while(length_tmp != 0) {
- uint8 buffer_tmp[1024];
- int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
- state_fio->Fread(buffer_tmp, length_rw, 1);
- if(fio->IsOpened()) {
- fio->Fwrite(buffer_tmp, length_rw, 1);
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ state_fio->StateBool(is_wav);
+ state_fio->StateBool(rec);
+ state_fio->StateBool(remote);
+ state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+ if(loading) {
+ int length_tmp = state_fio->FgetInt32_LE();
+ if(rec) {
+ fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+ while(length_tmp != 0) {
+ uint8_t buffer_tmp[1024];
+ int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+ state_fio->Fread(buffer_tmp, length_rw, 1);
+ if(fio->IsOpened()) {
+ fio->Fwrite(buffer_tmp, length_rw, 1);
+ }
+ length_tmp -= length_rw;
+ }
+ }
+ } else {
+ if(rec && fio->IsOpened()) {
+ int length_tmp = (int)fio->Ftell();
+ fio->Fseek(0, FILEIO_SEEK_SET);
+ state_fio->FputInt32_LE(length_tmp);
+ while(length_tmp != 0) {
+ uint8_t buffer_tmp[1024];
+ int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+ fio->Fread(buffer_tmp, length_rw, 1);
+ state_fio->Fwrite(buffer_tmp, length_rw, 1);
+ length_tmp -= length_rw;
}
- length_tmp -= length_rw;
+ } else {
+ state_fio->FputInt32_LE(0);
}
}
- bufcnt = state_fio->FgetInt32();
- state_fio->Fread(buffer, sizeof(buffer), 1);
- prev_signal = state_fio->FgetInt32();
- prev_clock = state_fio->FgetUint32();
+ state_fio->StateInt32(bufcnt);
+ state_fio->StateBuffer(buffer, sizeof(buffer), 1);
+ state_fio->StateInt32(prev_signal);
+ state_fio->StateUint32(prev_clock);
return true;
}
-