public static void wav_close(wav_file wav) { uint32_t total; uint32_t temp32; if (wav == null) { return; } total = (UInt32)wav.file.Length; //ftell(wav.file); /* update the total file size */ wav.writer.Seek((int)wav.total_offs, SeekOrigin.Begin); //fseek(wav.file, wav.total_offs, SEEK_SET); temp32 = total - (wav.total_offs + 4); temp32 = (UInt32)global_object.little_endianize_int32((int)temp32); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); /* update the data size */ wav.writer.Seek((int)wav.data_offs, SeekOrigin.Begin); //fseek(wav.file, wav.data_offs, SEEK_SET); temp32 = total - (wav.data_offs + 4); temp32 = (UInt32)global_object.little_endianize_int32((int)temp32); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); //fclose(wav.file); wav.writer.Close(); wav.file.Close(); wav.writer = null; wav.file = null; //global_free(wav); }
//------------------------------------------------- // stop_recording - end audio recording //------------------------------------------------- void stop_recording(running_machine machine) { // close any open WAV file if (m_wavfile != null) { wavwrite_global.wav_close(m_wavfile); } m_wavfile = null; }
public static void wav_add_data_16(wav_file wav, ListPointer <int16_t> data, int samples) //wav_file *wav, int16_t *data, int samples) { if (wav == null || samples == 0) { return; } throw new emu_unimplemented(); }
// global controls //------------------------------------------------- // start_recording - begin audio recording //------------------------------------------------- public void start_recording() { // open the output WAV file if specified string wavfile = machine().options().wav_write(); if (!string.IsNullOrEmpty(wavfile) && m_wavfile == null) { m_wavfile = wavwrite_global.wav_open(wavfile, machine().sample_rate(), 2); } }
attotime m_last_update; // last update time // construction/destruction //------------------------------------------------- // sound_manager - constructor //------------------------------------------------- public sound_manager(running_machine machine) { m_machine = machine; m_update_timer = null; m_finalmix_leftover = 0; m_finalmix = new std.vector <s16>(machine.sample_rate()); m_leftmix = new std.vector <s32>(machine.sample_rate()); m_rightmix = new std.vector <s32>(machine.sample_rate()); m_nosound_mode = machine.osd().no_sound() ? 1 : 0; m_wavfile = null; m_update_attoseconds = STREAMS_UPDATE_ATTOTIME.attoseconds(); m_last_update = attotime.zero; // get filename for WAV file or AVI file if specified string wavfile = machine.options().wav_write(); string avifile = machine.options().avi_write(); // handle -nosound and lower sample rate if not recording WAV or AVI if (m_nosound_mode != 0 && string.IsNullOrEmpty(wavfile) && string.IsNullOrEmpty(avifile)) { machine.sample_rate_set(11025); } // count the mixers if (sound_global.VERBOSE) { mixer_interface_iterator iter = new mixer_interface_iterator(machine.root_device()); sound_global.VPRINTF("total mixers = {0}\n", iter.count()); } // register callbacks machine.configuration().config_register("mixer", config_load, config_save); machine.add_notifier(machine_notification.MACHINE_NOTIFY_PAUSE, pause); machine.add_notifier(machine_notification.MACHINE_NOTIFY_RESUME, resume); machine.add_notifier(machine_notification.MACHINE_NOTIFY_RESET, reset); machine.add_notifier(machine_notification.MACHINE_NOTIFY_EXIT, stop_recording); // register global states machine.save().save_item(m_last_update, "m_last_update"); // set the starting attenuation set_attenuation(machine.options().volume()); // start the periodic update flushing timer m_update_timer = machine.scheduler().timer_alloc(update, this); m_update_timer.adjust(STREAMS_UPDATE_ATTOTIME, 0, STREAMS_UPDATE_ATTOTIME); }
public static void wav_add_data_16lr(wav_file wav, ListPointer <int16_t> left, ListPointer <int16_t> right, int samples) //wav_file *wav, int16_t *left, int16_t *right, int samples) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples * 2); /* interleave */ for (i = 0; i < samples * 2; i++) { temp[i] = (i & 1) != 0 ? right[i / 2] : left[i / 2]; } throw new emu_unimplemented(); }
public static void wav_add_data_32(wav_file wav, ListPointer <int32_t> data, int samples, int shift) //wav_file *wav, int32_t *data, int samples, int shift) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples); /* clamp */ for (i = 0; i < samples; i++) { int val = data[i] >> shift; temp[i] = (Int16)((val < -32768) ? -32768 : (val > 32767) ? 32767 : val); } throw new emu_unimplemented(); }
public static void wav_add_data_32lr(wav_file wav, ListPointer <int32_t> left, ListPointer <int32_t> right, int samples, int shift) //wav_file *wav, int32_t *left, int32_t *right, int samples, int shift) { std.vector <int16_t> temp = new std.vector <int16_t>(); int i; if (wav == null || samples == 0) { return; } /* resize dynamic array */ temp.resize(samples); /* interleave */ for (i = 0; i < samples * 2; i++) { int val = (i & 1) != 0 ? right[i / 2] : left[i / 2]; val >>= shift; temp[i] = (Int16)((val < -32768) ? -32768 : (val > 32767) ? 32767 : val); } throw new emu_unimplemented(); }
public static wav_file wav_open(string filename, int sample_rate, int channels) { wav_file wav; uint32_t bps; uint32_t temp32; uint16_t align; uint16_t temp16; /* allocate memory for the wav struct */ wav = new wav_file(); // (wav_file *) global_alloc(wav_file); if (wav == null) { return(null); } /* create the file */ //wav.file = fopen(filename, "wb"); //if (!wav.file) //{ // //global_free(wav); // return null; //} wav.file = new FileStream(filename, FileMode.Create); wav.writer = new BinaryWriter(wav.file); /* write the 'RIFF' header */ wav.writer.Write("RIFF".ToCharArray()); //fwrite("RIFF", 1, 4, wav.file); /* write the total size */ temp32 = 0; wav.total_offs = (UInt32)wav.file.Length; // ftell(wav.file); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); /* write the 'WAVE' type */ wav.writer.Write("WAVE".ToCharArray()); //fwrite("WAVE", 1, 4, wav.file); /* write the 'fmt ' tag */ wav.writer.Write("fmt ".ToCharArray()); //fwrite("fmt ", 1, 4, wav.file); /* write the format length */ temp32 = (UInt32)global_object.little_endianize_int32(16); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); /* write the format (PCM) */ temp16 = (UInt16)global_object.little_endianize_int16(1); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); /* write the channels */ temp16 = (UInt16)global_object.little_endianize_int16((Int16)channels); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); /* write the sample rate */ temp32 = (UInt32)global_object.little_endianize_int32(sample_rate); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); /* write the bytes/second */ bps = (UInt32)(sample_rate * 2 * channels); temp32 = (UInt32)global_object.little_endianize_int32((int)bps); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); /* write the block align */ align = (UInt16)(2 * channels); temp16 = (UInt16)global_object.little_endianize_int16((Int16)align); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); /* write the bits/sample */ temp16 = (UInt16)global_object.little_endianize_int16(16); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); /* write the 'data' tag */ wav.writer.Write("data".ToCharArray()); //fwrite("data", 1, 4, wav.file); /* write the data length */ temp32 = 0; wav.data_offs = (UInt32)wav.file.Length; //ftell(wav.file); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); return(wav); }
//struct wav_deleter public static wav_file wav_open(string filename, int sample_rate, int channels) { uint32_t temp32; uint16_t temp16; // allocate memory for the wav struct var wav = new wav_file(); //auto *const wav = new (std::nothrow) wav_file; if (wav == null) { return(null); } // create the file */ //wav.file = fopen(filename, "wb"); //if (!wav.file) //{ // //global_free(wav); // return null; //} wav.file = new FileStream(filename, FileMode.Create); wav.writer = new BinaryWriter(wav.file); // write the 'RIFF' header wav.writer.Write("RIFF".ToCharArray()); //fwrite("RIFF", 1, 4, wav.file); // write the total size temp32 = 0; wav.total_offs = (uint32_t)wav.file.Length; // ftell(wav.file); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); // write the 'WAVE' type wav.writer.Write("WAVE".ToCharArray()); //fwrite("WAVE", 1, 4, wav.file); // write the 'fmt ' tag wav.writer.Write("fmt ".ToCharArray()); //fwrite("fmt ", 1, 4, wav.file); // write the format length temp32 = (uint32_t)little_endianize_int32(16); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); // write the format (PCM) temp16 = (uint16_t)little_endianize_int16(1); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); // write the channels temp16 = (uint16_t)little_endianize_int16((int16_t)channels); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); // write the sample rate temp32 = (uint32_t)little_endianize_int32(sample_rate); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); // write the bytes/second uint32_t bps = (uint32_t)(sample_rate * 2 * channels); temp32 = (uint32_t)little_endianize_int32((int)bps); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); // write the block align uint16_t align = (uint16_t)(2 * channels); temp16 = (uint16_t)little_endianize_int16((int16_t)align); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); // write the bits/sample temp16 = (uint16_t)little_endianize_int16(16); wav.writer.Write(temp16); //fwrite(&temp16, 1, 2, wav.file); // write the 'data' tag wav.writer.Write("data".ToCharArray()); //fwrite("data", 1, 4, wav.file); // write the data length temp32 = 0; wav.data_offs = (uint32_t)wav.file.Length; //ftell(wav.file); wav.writer.Write(temp32); //fwrite(&temp32, 1, 4, wav.file); return(wav); }