-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi Hiromasa,
I'm trying to use your FFI wrapper to simply replay a YM registers dump file (captured every 50Hz) but the result is not good at all. I guess I don't use your wrapper correctly, can you tell me what is wrong ? I guess this is due to the frequency I call ymfm_generate but I don't undertstand why.
Here is the principle (in Zig but not really different from Rust):
(if not clear in the comments)
- I call
ymfm_add_chipto set up a YM2149 at2000000Hz and get the sampling rate:31250 - I loop over the blocks of
14YM2149 registers contained in my YM dump file- I write the
14registers usingymfm_write - I generate
31250/50ticks withymfm_generate- I write the first
i32of the buffer (mono channel) in a file for each tick
- I write the first
- I write the
- Done!
pub fn main() !void {
// YM2149 clock: 2MHz
const YM2149_clock: u32 = 2e6;
const fYM2149_clock: f32 = @intToFloat(f32, YM2149_clock);
// Get YM2149 enum value, basically 0
const ym2149: u16 = @enumToInt(ChipType.CHIP_YM2149);
// create wav file
const file = try std.fs.cwd().createFile(
"sound.wav",
.{ .read = true },
);
defer file.close();
// Get a buffered writer to write in this file
var buf_writer = std.io.bufferedWriter(file.writer());
const writer = buf_writer.writer();
// add a YM2149, YM2149_clock ==
var sampling_rate: u32 = ymfm.ymfm_add_chip(ym2149, YM2149_clock);
std.debug.print("Sampling Rate: {} for master clock: {}\n", .{ sampling_rate, YM2149_clock });
std.debug.print("Dump length: {} frames = {} seconds\n", .{ dump_b.len / 14, dump_b.len / 14 / 50 });
std.debug.print("Tick per frame: {}\n", .{ sampling_rate / 50 });
// counters for the YM dump file
var counter: u64 = 0;
var dump_loop: u32 = 0;
// the YM dump file is composed of 50Hz frames capturing the first 14 YM2149 registers
// loop on those frames
while(dump_loop < dump_b.len / 14) : (dump_loop += 1) {
// write the 14 registers
var i: u32 = 0;
while( i < 14) : ( i += 1) {
ymfm.ymfm_write(ym2149, 0, i, dump_b[counter]);
counter += 1;
}
// generate some sound for 50 Hz, so tick the YM (sampling_rate / 50) times
// write every sample output to the file
var tick: u32 = 0;
var buffer: [2]i32 = undefined;
while (tick < sampling_rate / 50) : ( tick += 1) {
ymfm.ymfm_generate(ym2149, 0, &buffer);
// store only left channel
const slice = buffer[0];
try writer.writeAll(std.mem.asBytes(&slice));
}
// std.debug.print("Frame {} done\n", .{ dump_loop } );
}
try buf_writer.flush();
}Sampling Rate: 31250 for master clock: 2000000
Dump length: 8833 frames = 176 seconds
Tick per frame: 625Any idea what I did wrong ?
Metadata
Metadata
Assignees
Labels
No labels